Bug 1343945 - Fix lint errors from browser-social.js, remove from ignore list r=jaws
authorSam Foster <sfoster@mozilla.com>
Fri, 03 Mar 2017 08:57:20 -0800
changeset 374897 15f2040d22ff7cfbc4724cd5a446a03e7398f813
parent 374896 2bf7fb2523c3e118d1f11bb87e48d4b5bb1b49d0
child 374898 6fcffb34361d5f7e8a912d291f1d2893e2921cd5
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1343945
milestone54.0a1
Bug 1343945 - Fix lint errors from browser-social.js, remove from ignore list r=jaws * Added no-undef rule locally as we're not ready to turn on for the whole directory MozReview-Commit-ID: JpD4KXvvqOn
.eslintignore
browser/base/content/browser-social.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -50,17 +50,16 @@ xulrunner/**
 # b2g exclusions (pref files).
 b2g/app/b2g.js
 b2g/graphene/graphene.js
 b2g/locales/en-US/b2g-l10n.js
 
 # browser/ exclusions
 browser/app/**
 browser/branding/**/firefox-branding.js
-browser/base/content/browser-social.js
 browser/base/content/nsContextMenu.js
 browser/base/content/sanitizeDialog.js
 browser/base/content/test/general/file_csp_block_all_mixedcontent.html
 browser/base/content/test/urlbar/file_blank_but_not_blank.html
 browser/base/content/newtab/**
 browser/components/downloads/**
 browser/components/sessionstore/**
 browser/components/tabview/**
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -1,31 +1,39 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* eslint-env mozilla/browser-window */
+/* eslint no-undef: "error" */
+/* global OpenGraphBuilder:false, DynamicResizeWatcher:false */
+
 // the "exported" symbols
 var SocialUI,
     SocialShare,
     SocialActivationListener;
 
 (function() {
+"use strict";
 
 XPCOMUtils.defineLazyGetter(this, "OpenGraphBuilder", function() {
   let tmp = {};
   Cu.import("resource:///modules/Social.jsm", tmp);
   return tmp.OpenGraphBuilder;
 });
 
 XPCOMUtils.defineLazyGetter(this, "DynamicResizeWatcher", function() {
   let tmp = {};
   Cu.import("resource:///modules/Social.jsm", tmp);
   return tmp.DynamicResizeWatcher;
 });
 
+let messageManager = window.messageManager;
+let openUILinkIn = window.openUILinkIn;
+
 SocialUI = {
   _initialized: false,
 
   // Called on delayed startup to initialize the UI
   init: function SocialUI_init() {
     if (this._initialized) {
       return;
     }
@@ -62,26 +70,26 @@ SocialUI = {
   observe: function SocialUI_observe(subject, topic, data) {
     switch (topic) {
       case "social:providers-changed":
         this._providersChanged();
         break;
     }
   },
 
-  _providersChanged: function() {
+  _providersChanged() {
     SocialShare.populateProviderMenu();
   },
 
-  showLearnMore: function() {
+  showLearnMore() {
     let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "social-api";
     openUILinkIn(url, "tab");
   },
 
-  closeSocialPanelForLinkTraversal: function (target, linkNode) {
+  closeSocialPanelForLinkTraversal(target, linkNode) {
     // No need to close the panel if this traversal was not retargeted
     if (target == "" || target == "_self")
       return;
 
     // Check to see whether this link traversal was in a social panel
     let win = linkNode.ownerGlobal;
     let container = win.QueryInterface(Ci.nsIInterfaceRequestor)
                                   .getInterface(Ci.nsIWebNavigation)
@@ -98,36 +106,36 @@ SocialUI = {
   },
 
   get _chromeless() {
     // Is this a popup window that doesn't want chrome shown?
     let docElem = document.documentElement;
     // extrachrome is not restored during session restore, so we need
     // to check for the toolbar as well.
     let chromeless = docElem.getAttribute("chromehidden").includes("extrachrome") ||
-                     docElem.getAttribute('chromehidden').includes("toolbar");
+                     docElem.getAttribute("chromehidden").includes("toolbar");
     // This property is "fixed" for a window, so avoid doing the check above
     // multiple times...
     delete this._chromeless;
     this._chromeless = chromeless;
     return chromeless;
   },
 
   get enabled() {
     // Returns whether social is enabled *for this window*.
     if (this._chromeless)
       return false;
     return Social.providers.length > 0;
   },
 
-  canSharePage: function(aURI) {
-    return (aURI && (aURI.schemeIs('http') || aURI.schemeIs('https')));
+  canSharePage(aURI) {
+    return (aURI && (aURI.schemeIs("http") || aURI.schemeIs("https")));
   },
 
-  onCustomizeEnd: function(aWindow) {
+  onCustomizeEnd(aWindow) {
     if (aWindow != window)
       return;
     // customization mode gets buttons out of sync with command updating, fix
     // the disabled state
     let canShare = this.canSharePage(gBrowser.currentURI);
     let shareButton = SocialShare.shareButton;
     if (shareButton) {
       if (canShare) {
@@ -135,30 +143,30 @@ SocialUI = {
       } else {
         shareButton.setAttribute("disabled", "true")
       }
     }
   },
 
   // called on tab/urlbar/location changes and after customization. Update
   // anything that is tab specific.
-  updateState: function() {
+  updateState() {
     goSetCommandEnabled("Social:PageShareable", this.canSharePage(gBrowser.currentURI));
   }
 }
 
 // message manager handlers
 SocialActivationListener = {
-  init: function() {
+  init() {
     messageManager.addMessageListener("Social:Activation", this);
   },
-  uninit: function() {
+  uninit() {
     messageManager.removeMessageListener("Social:Activation", this);
   },
-  receiveMessage: function(aMessage) {
+  receiveMessage(aMessage) {
     let data = aMessage.json;
     let browser = aMessage.target;
     data.window = window;
     // if the source if the message is the share panel, we do a one-click
     // installation. The source of activations is controlled by the
     // social.directories preference
     let options;
     if (browser == SocialShare.iframe && Services.prefs.getBoolPref("social.share.activationPanelEnabled")) {
@@ -180,18 +188,18 @@ SocialActivationListener = {
             CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
             // Ensure correct state.
             SocialUI.onCustomizeEnd(window);
           }
 
           // make this new provider the selected provider. If the panel hasn't
           // been opened, we need to make the frame first.
           SocialShare._createFrame();
-          SocialShare.iframe.setAttribute('src', 'data:text/plain;charset=utf8,');
-          SocialShare.iframe.setAttribute('origin', provider.origin);
+          SocialShare.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
+          SocialShare.iframe.setAttribute("origin", provider.origin);
           // get the right button selected
           SocialShare.populateProviderMenu();
           if (SocialShare.panel.state == "open") {
             SocialShare.sharePage(provider.origin);
           }
         }
         if (provider.postActivationURL) {
           // if activated from an open share panel, we load the landing page in
@@ -224,28 +232,28 @@ SocialShare = {
   },
 
   get iframe() {
     // panel.firstChild is our toolbar hbox, panel.lastChild is the iframe
     // container hbox used for an interstitial "loading" graphic
     return this.panel.lastChild.firstChild;
   },
 
-  uninit: function () {
+  uninit() {
     if (this.iframe) {
       let mm = this.messageManager;
       mm.removeMessageListener("PageVisibility:Show", this);
       mm.removeMessageListener("PageVisibility:Hide", this);
       mm.removeMessageListener("Social:DOMWindowClose", this);
       this.iframe.removeEventListener("load", this);
       this.iframe.remove();
     }
   },
 
-  _createFrame: function() {
+  _createFrame() {
     let panel = this.panel;
     if (this.iframe)
       return;
     this.panel.hidden = false;
     // create and initialize the panel for this window
     let iframe = document.createElement("browser");
     iframe.setAttribute("type", "content");
     iframe.setAttribute("class", "social-share-frame");
@@ -268,58 +276,58 @@ SocialShare = {
   },
 
   get messageManager() {
     // The xbl bindings for the iframe may not exist yet, so we can't
     // access iframe.messageManager directly - but can get at it with this dance.
     return this.iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
   },
 
-  receiveMessage: function(aMessage) {
+  receiveMessage(aMessage) {
     let iframe = this.iframe;
-    switch(aMessage.name) {
+    switch (aMessage.name) {
       case "PageVisibility:Show":
         SocialShare._dynamicResizer.start(iframe.parentNode, iframe);
         break;
       case "PageVisibility:Hide":
         SocialShare._dynamicResizer.stop();
         break;
       case "Social:DOMWindowClose":
         this.panel.hidePopup();
         break;
     }
   },
 
-  handleEvent: function(event) {
+  handleEvent(event) {
     switch (event.type) {
       case "load": {
         this.iframe.parentNode.removeAttribute("loading");
         if (this.currentShare)
           SocialShare.messageManager.sendAsyncMessage("Social:OpenGraphData", this.currentShare);
       }
     }
   },
 
-  getSelectedProvider: function() {
+  getSelectedProvider() {
     let provider;
     let lastProviderOrigin = this.iframe && this.iframe.getAttribute("origin");
     if (lastProviderOrigin) {
       provider = Social._getProviderFromOrigin(lastProviderOrigin);
     }
     return provider;
   },
 
-  createTooltip: function(event) {
+  createTooltip(event) {
     let tt = event.target;
     let provider = Social._getProviderFromOrigin(tt.triggerNode.getAttribute("origin"));
     tt.firstChild.setAttribute("value", provider.name);
     tt.lastChild.setAttribute("value", provider.origin);
   },
 
-  populateProviderMenu: function() {
+  populateProviderMenu() {
     if (!this.iframe)
       return;
     let providers = Social.providers.filter(p => p.shareURL);
     let hbox = document.getElementById("social-share-provider-buttons");
     // remove everything before the add-share-provider button (which should also
     // be lastChild if any share providers were added)
     let addButton = document.getElementById("add-share-provider");
     while (hbox.lastChild != addButton) {
@@ -354,106 +362,106 @@ SocialShare = {
     if (!window.CustomizableUI)
       return null;
     let widget = CustomizableUI.getWidget("social-share-button");
     if (!widget || !widget.areaType)
       return null;
     return widget.forWindow(window).node;
   },
 
-  _onclick: function() {
+  _onclick() {
     Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(0);
   },
 
-  onShowing: function() {
+  onShowing() {
     (this._currentAnchor || this.anchor).setAttribute("open", "true");
     this.iframe.addEventListener("click", this._onclick, true);
   },
 
-  onHidden: function() {
+  onHidden() {
     (this._currentAnchor || this.anchor).removeAttribute("open");
     this._currentAnchor = null;
     this.iframe.docShellIsActive = false;
     this.iframe.removeEventListener("click", this._onclick, true);
     this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
     // make sure that the frame is unloaded after it is hidden
     this.messageManager.sendAsyncMessage("Social:ClearFrame");
     this.currentShare = null;
     // share panel use is over, purge any history
     this.iframe.purgeSessionHistory();
   },
 
-  sharePage: function(providerOrigin, graphData, target, anchor) {
+  sharePage(providerOrigin, graphData, target, anchor) {
     // if providerOrigin is undefined, we use the last-used provider, or the
     // current/default provider.  The provider selection in the share panel
     // will call sharePage with an origin for us to switch to.
     this._createFrame();
     let iframe = this.iframe;
 
     // graphData is an optional param that either defines the full set of data
     // to be shared, or partial data about the current page. It is set by a call
     // in mozSocial API, or via nsContentMenu calls. If it is present, it MUST
     // define at least url. If it is undefined, we're sharing the current url in
     // the browser tab.
-    let pageData = graphData ? graphData : this.currentShare;
-    let sharedURI = pageData ? Services.io.newURI(pageData.url) :
+    let sharedPageData = graphData || this.currentShare;
+    let sharedURI = sharedPageData ? Services.io.newURI(sharedPageData.url) :
                                 gBrowser.currentURI;
     if (!SocialUI.canSharePage(sharedURI))
       return;
 
     let browserMM = gBrowser.selectedBrowser.messageManager;
 
     // the point of this action type is that we can use existing share
     // endpoints (e.g. oexchange) that do not support additional
     // socialapi functionality.  One tweak is that we shoot an event
     // containing the open graph data.
     let _dataFn;
-    if (!pageData || sharedURI == gBrowser.currentURI) {
+    if (!sharedPageData || sharedURI == gBrowser.currentURI) {
       browserMM.addMessageListener("PageMetadata:PageDataResult", _dataFn = (msg) => {
         browserMM.removeMessageListener("PageMetadata:PageDataResult", _dataFn);
         let pageData = msg.json;
         if (graphData) {
           // overwrite data retreived from page with data given to us as a param
           for (let p in graphData) {
             pageData[p] = graphData[p];
           }
         }
         this.sharePage(providerOrigin, pageData, target, anchor);
       });
       browserMM.sendAsyncMessage("PageMetadata:GetPageData", null, { target });
       return;
     }
     // if this is a share of a selected item, get any microformats
-    if (!pageData.microformats && target) {
+    if (!sharedPageData.microformats && target) {
       browserMM.addMessageListener("PageMetadata:MicroformatsResult", _dataFn = (msg) => {
         browserMM.removeMessageListener("PageMetadata:MicroformatsResult", _dataFn);
-        pageData.microformats = msg.data;
-        this.sharePage(providerOrigin, pageData, target, anchor);
+        sharedPageData.microformats = msg.data;
+        this.sharePage(providerOrigin, sharedPageData, target, anchor);
       });
       browserMM.sendAsyncMessage("PageMetadata:GetMicroformats", null, { target });
       return;
     }
-    this.currentShare = pageData;
+    this.currentShare = sharedPageData;
 
     let provider;
     if (providerOrigin)
       provider = Social._getProviderFromOrigin(providerOrigin);
     else
       provider = this.getSelectedProvider();
     if (!provider || !provider.shareURL) {
       this.showDirectory(anchor);
       return;
     }
     // check the menu button
     let hbox = document.getElementById("social-share-provider-buttons");
     let btn = hbox.querySelector("[origin='" + provider.origin + "']");
     if (btn)
       btn.checked = true;
 
-    let shareEndpoint = OpenGraphBuilder.generateEndpointURL(provider.shareURL, pageData);
+    let shareEndpoint = OpenGraphBuilder.generateEndpointURL(provider.shareURL, sharedPageData);
 
     this._dynamicResizer.stop();
     let size = provider.getPageSize("share");
     if (size) {
       // let the css on the share panel define width, but height
       // calculations dont work on all sites, so we allow that to be
       // defined.
       delete size.width;
@@ -469,35 +477,34 @@ SocialShare = {
     } else {
       iframe.parentNode.setAttribute("loading", "true");
     }
     // if the user switched between share providers we do not want that history
     // available.
     iframe.purgeSessionHistory();
 
     // always ensure that origin belongs to the endpoint
-    let uri = Services.io.newURI(shareEndpoint);
     iframe.setAttribute("origin", provider.origin);
     iframe.setAttribute("src", shareEndpoint);
     this._openPanel(anchor);
   },
 
-  showDirectory: function(anchor) {
+  showDirectory(anchor) {
     this._createFrame();
     let iframe = this.iframe;
     if (iframe.getAttribute("src") == "about:providerdirectory")
       return;
     iframe.removeAttribute("origin");
     iframe.parentNode.setAttribute("loading", "true");
 
     iframe.setAttribute("src", "about:providerdirectory");
     this._openPanel(anchor);
   },
 
-  _openPanel: function(anchor) {
+  _openPanel(anchor) {
     this._currentAnchor = anchor || this.anchor;
     anchor = document.getAnonymousElementByAttribute(this._currentAnchor, "class", "toolbarbutton-icon");
     this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
     Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(0);
   }
 };
 
-})();
+}).call(this);