Bug 1484640 - Enable ESLint for mobile/android/chrome/content/browser.js (Manual Changes). r=snorp
authorchampionshuttler <shivams2799@gmail.com>
Mon, 29 Apr 2019 14:17:13 +0000
changeset 471763 8f826767d3d6d122f40011901c6e28ad60035354
parent 471762 4ad266f5412e40c438b572e8e414c3a468bb9776
child 471764 55c8e6f3e522adf4db6a3a6f9cec450ab8ff8926
push id112948
push usershindli@mozilla.com
push dateMon, 29 Apr 2019 21:58:23 +0000
treeherdermozilla-inbound@49514be011ca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1484640
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1484640 - Enable ESLint for mobile/android/chrome/content/browser.js (Manual Changes). r=snorp Differential Revision: https://phabricator.services.mozilla.com/D22891
.eslintignore
mobile/android/chrome/content/browser.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -258,19 +258,16 @@ mobile/android/app/geckoview-prefs.js
 
 # Uses `#expand`
 mobile/android/chrome/content/about.js
 
 # Not much JS to lint and non-standard at that
 mobile/android/installer/
 mobile/android/locales/
 
-# Non-standard `(catch ex if ...)`
-mobile/android/chrome/content/browser.js
-
 # Pre-processed/pref files
 modules/libpref/greprefs.js
 modules/libpref/init/all.js
 modules/libpref/test/unit/*data/**
 
 # Only contains non-standard test files.
 python/**
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -279,17 +279,17 @@ XPCOMUtils.defineLazyGetter(this, "Conte
   return ContentAreaUtils;
 });
 
 ChromeUtils.defineModuleGetter(this, "Rect", "resource://gre/modules/Geometry.jsm");
 ChromeUtils.defineModuleGetter(this, "Point", "resource://gre/modules/Geometry.jsm");
 
 function resolveGeckoURI(aURI) {
   if (!aURI)
-    throw "Can't resolve an empty uri";
+    throw new Error("Can't resolve an empty uri");
 
   if (aURI.startsWith("chrome://")) {
     let registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
     return registry.convertChromeURL(Services.io.newURI(aURI)).spec;
   } else if (aURI.startsWith("resource://")) {
     let handler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
     return handler.resolveURI(Services.io.newURI(aURI));
   }
@@ -1310,18 +1310,18 @@ var BrowserApp = {
     this._tabs.splice(tabIndex, 1);
   },
 
   _handleTabMove(fromTabId, fromPosition, toTabId, toPosition) {
     let movedTab = this._tabs[fromPosition];
     if (movedTab.id != fromTabId || this._tabs[toPosition].id != toTabId) {
       // The gecko and/or java Tabs tabs lists changed sometime between when the Tabs list was
       // updated and when news of the update arrived here.
-      throw "Moved tab mismatch: (" + fromTabId + ", " + movedTab.id + "), " +
-            "(" + toTabId + ", " + this._tabs[toPosition].id + ")";
+      throw new Error("Moved tab mismatch: (" + fromTabId + ", " + movedTab.id + "), " +
+            "(" + toTabId + ", " + this._tabs[toPosition].id + ")");
     }
 
     let step = (fromPosition < toPosition) ? 1 : -1;
     for (let i = fromPosition; i != toPosition; i += step) {
       this._tabs[i] = this._tabs[i + step];
     }
     this._tabs[toPosition] = movedTab;
 
@@ -1495,17 +1495,17 @@ var BrowserApp = {
 
     // Tell session store to forget about this window
     if (aClear.dontSaveSession) {
       let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
       ss.removeWindow(window);
     }
 
     BrowserApp.sanitize(aClear.sanitize, function() {
-      let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
+      let appStartup = Services.startup;
       appStartup.quit(Ci.nsIAppStartup.eForceQuit);
     }, true);
   },
 
   saveAsPDF: function saveAsPDF(aBrowser) {
     RuntimePermissions.waitForPermissions(RuntimePermissions.WRITE_EXTERNAL_STORAGE).then(function(permissionGranted) {
       if (!permissionGranted) {
         return;
@@ -1717,16 +1717,17 @@ var BrowserApp = {
 
   setLocalizedPref: function(pref, value) {
     let pls = Cc["@mozilla.org/pref-localizedstring;1"]
                 .createInstance(Ci.nsIPrefLocalizedString);
     pls.data = value;
     Services.prefs.setComplexValue(pref, Ci.nsIPrefLocalizedString, pls);
   },
 
+  // eslint-disable-next-line complexity
   onEvent: function(event, data, callback) {
     let browser = this.selectedBrowser;
 
     switch (event) {
       case "Browser:LoadManifest": {
         installManifest(browser, data);
         break;
       }
@@ -1787,22 +1788,17 @@ var BrowserApp = {
         }
 
         console.log("Gecko display locale: " + this.getUALocalePref());
 
         // Rebuild strings to reflect the new locale.
         Strings.flush();
 
         // Make sure we use the right Accept-Language header.
-        let osLocale;
-        try {
-          // This should never not be set at this point, but better safe than sorry.
-          osLocale = Services.prefs.getCharPref("intl.locale.os");
-        } catch (e) {
-        }
+        let osLocale = Services.prefs.getCharPref("intl.locale.os");
 
         this.computeAcceptLanguages(osLocale, data && data.languageTag);
         break;
       }
 
       case "Passwords:Init": {
         let storage = Cc["@mozilla.org/login-manager/storage/mozStorage;1"].
                       getService(Ci.nsILoginManagerStorage);
@@ -1886,16 +1882,17 @@ var BrowserApp = {
               } else {
                 Services.perms.add(normalizedUrl, "trackingprotection", Services.perms.ALLOW_ACTION);
                 Telemetry.addData("TRACKING_PROTECTION_EVENTS", 1);
               }
             } else {
               // Remove the current host from the 'trackingprotection' consumer
               // of the permission manager. This effectively removes this host
               // from the tracking protection white list (any list actually).
+              // eslint-disable-next-line no-lonely-if
               if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
                 PrivateBrowsingUtils.removeFromTrackingAllowlist(normalizedUrl);
               } else {
                 Services.perms.remove(normalizedUrl, "trackingprotection");
                 Telemetry.addData("TRACKING_PROTECTION_EVENTS", 2);
               }
             }
           }
@@ -2347,17 +2344,17 @@ var NativeWindow = {
         options = arguments[0];
       } else if (arguments.length == 3) {
           Log.w("Browser", "This menu addon API has been deprecated. Instead, use the options object API.");
           options = {
             name: arguments[0],
             callback: arguments[2],
           };
       } else {
-         throw "Incorrect number of parameters";
+         throw new Error("Incorrect number of parameters");
       }
 
       options.type = "Menu:Add";
       options.uuid = uuidgen.generateUUID().toString();
 
       GlobalEventDispatcher.sendRequest(options);
       this._callbacks[options.uuid] = options.callback;
       return options.uuid;
@@ -2505,21 +2502,21 @@ var NativeWindow = {
         args = arguments[0];
       } else if (arguments.length == 3) {
         args = {
           label: arguments[0],
           selector: arguments[1],
           callback: arguments[2],
         };
       } else {
-        throw "Incorrect number of parameters";
+        throw new Error("Incorrect number of parameters");
       }
 
       if (!args.label)
-        throw "Menu items must have a name";
+        throw new Error("Menu items must have a name");
 
       let cmItem = new ContextMenuItem(args);
       this.items[cmItem.id] = cmItem;
       return cmItem.id;
     },
 
     remove: function(aId) {
       delete this.items[aId];
@@ -3221,17 +3218,17 @@ var NativeWindow = {
         return this.makeURI(href).displaySpec;
       }
 
       href = aLink.getAttribute("href") ||
              aLink.getAttributeNS(kXLinkNamespace, "href");
       if (!href || !href.match(/\S/)) {
         // Without this we try to save as the current doc,
         // for example, HTML case also throws if empty
-        throw "Empty href";
+        throw new Error("Empty href");
       }
 
       return this.makeURLAbsolute(aLink.baseURI, href);
     },
 
     _copyStringToDefaultClipboard: function(aString) {
       let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
       clipboard.copyString(aString);
@@ -3384,16 +3381,17 @@ var DesktopUserAgent = {
 
 
 function nsBrowserAccess() {
 }
 
 nsBrowserAccess.prototype = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIBrowserDOMWindow]),
 
+  // eslint-disable-next-line complexity
   _getBrowser: function _getBrowser(aURI, aOpener, aWhere, aFlags, aTriggeringPrincipal, aCsp) {
     let isExternal = !!(aFlags & Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
     if (isExternal && aURI && aURI.schemeIs("chrome"))
       return null;
 
     let loadflags = isExternal ?
                       Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
                       Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
@@ -3477,17 +3475,17 @@ nsBrowserAccess.prototype = {
     }
 
     return browser;
   },
 
   openURI: function browser_openURI(aURI, aOpener, aWhere, aFlags,
                                     aTriggeringPrincipal, aCsp) {
     if (!aURI) {
-      throw "Can't open an empty uri";
+      throw new Error("Can't open an empty uri");
     }
     let browser = this._getBrowser(aURI, aOpener, aWhere, aFlags,
                                    aTriggeringPrincipal, aCsp);
     return browser && browser.contentWindow;
   },
 
   createContentWindow: function browser_createContentWindow(
                                 aURI, aOpener, aWhere, aFlags,
@@ -3589,16 +3587,17 @@ function getBaseDomain(aURI) {
         baseDomain = IDNService.convertACEtoUTF8(baseDomain);
       }
     } catch (e) {}
   }
   return baseDomain;
 }
 
 Tab.prototype = {
+  // eslint-disable-next-line complexity
   create: function(aURL, aParams) {
     if (this.browser)
       return;
 
     aParams = aParams || {};
 
     this.browser = document.createElement("browser");
     this.browser.setAttribute("type", "content");
@@ -4124,16 +4123,17 @@ Tab.prototype = {
       return this.browser.currentURI;
     }
       // For zombie tabs we need to fall back to the session store data.
       let data = this.browser.__SS_data;
       let url = data.entries[data.index - 1].url;
       return Services.io.newURI(url);
   },
 
+  // eslint-disable-next-line complexity
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "DOMContentLoaded": {
         let target = aEvent.originalTarget;
 
         // ignore on frames and other documents
         if (target != this.browser.contentDocument)
           return;
@@ -4504,16 +4504,17 @@ Tab.prototype = {
         state: aStateFlags,
         restoring: restoring,
         success: success,
       };
       GlobalEventDispatcher.sendRequest(message);
     }
   },
 
+  // eslint-disable-next-line complexity
   onLocationChange: function(aWebProgress, aRequest, aLocationURI, aFlags) {
     let contentWin = aWebProgress.DOMWindow;
     let webNav = contentWin.docShell.QueryInterface(Ci.nsIWebNavigation);
 
     // Browser webapps may load content inside iframes that can not reach across the app/frame boundary
     // i.e. even though the page is loaded in an iframe window.top != webapp
     // Make cure this window is a top level tab before moving on.
     if (BrowserApp.getBrowserForWindow(contentWin) == null) {
@@ -4914,16 +4915,17 @@ var BrowserEventHandler = {
     if (!this._highlightElement)
       return;
 
     this._highlightElement = null;
   },
 };
 
 var ErrorPageEventHandler = {
+  // eslint-disable-next-line complexity
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "click": {
         // Don't trust synthetic events
         if (!aEvent.isTrusted)
           return;
 
         let target = aEvent.originalTarget;
@@ -4980,17 +4982,17 @@ var ErrorPageEventHandler = {
           } else if (errorDoc.documentURI.includes("e=harmfulBlocked")) {
             sendTelemetry = true;
             bucketName = "WARNING_HARMFUL_PAGE_";
           }
           let nsISecTel = Ci.nsISecurityUITelemetry;
           let isIframe = (errorDoc.defaultView.parent === errorDoc.defaultView);
           bucketName += isIframe ? "TOP_" : "FRAME_";
 
-          let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
+          let formatter = Services.urlFormatter;
 
           if (target == errorDoc.getElementById("getMeOutButton")) {
             if (sendTelemetry) {
               Telemetry.addData(probe, nsISecTel[bucketName + "GET_ME_OUT_OF_HERE"]);
             }
             errorDoc.location = "about:home";
           } else if (target == errorDoc.getElementById("reportButton")) {
             // We log even if malware/phishing info URL couldn't be found:
@@ -5209,30 +5211,28 @@ var XPInstallObserver = {
     let needsRestart = false;
     if (aInstall.existingAddon && (aInstall.existingAddon.pendingOperations & AddonManager.PENDING_UPGRADE))
       needsRestart = true;
     else if (aAddon.pendingOperations & AddonManager.PENDING_INSTALL)
       needsRestart = true;
 
     if (needsRestart) {
       this.showRestartPrompt();
-    } else {
+    } else if (!aInstall.existingAddon || !AddonManager.shouldAutoUpdate(aInstall.existingAddon)) {
       // Display completion message for new installs or updates not done Automatically
-      if (!aInstall.existingAddon || !AddonManager.shouldAutoUpdate(aInstall.existingAddon)) {
-        let message = Strings.browser.GetStringFromName("alertAddonsInstalledNoRestart.message");
-        Snackbars.show(message, Snackbars.LENGTH_LONG, {
-          action: {
-            label: Strings.browser.GetStringFromName("alertAddonsInstalledNoRestart.action2"),
-            callback: () => {
-              UITelemetry.addEvent("show.1", "toast", null, "addons");
-              BrowserApp.selectOrAddTab("about:addons", { parentId: BrowserApp.selectedTab.id });
-            },
+      let message = Strings.browser.GetStringFromName("alertAddonsInstalledNoRestart.message");
+      Snackbars.show(message, Snackbars.LENGTH_LONG, {
+        action: {
+          label: Strings.browser.GetStringFromName("alertAddonsInstalledNoRestart.action2"),
+          callback: () => {
+            UITelemetry.addEvent("show.1", "toast", null, "addons");
+            BrowserApp.selectOrAddTab("about:addons", { parentId: BrowserApp.selectedTab.id });
           },
-        });
-      }
+        },
+      });
     }
   },
 
   onInstallFailed: function(aInstall) {
     this._showErrorMessage(aInstall);
   },
 
   onDownloadProgress: function(aInstall) {},
@@ -5295,20 +5295,20 @@ var XPInstallObserver = {
     let buttons = [{
       label: Strings.browser.GetStringFromName("notificationRestart.button"),
       callback: function() {
         // Notify all windows that an application quit has been requested
         let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
         Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
         // If nothing aborted, quit the app
-        if (cancelQuit.data == false) {
+        if (!cancelQuit.data) {
           Services.obs.notifyObservers(null, "quit-application-proceeding");
           SharedPreferences.forApp().setBoolPref("browser.sessionstore.resume_session_once", true);
-          let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
+          let appStartup = Services.startup;
           appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
         }
       },
       positive: true,
     }];
 
     let message = Strings.browser.GetStringFromName("notificationRestart.normal");
     NativeWindow.doorhanger.show(message, "addon-app-restart", buttons, BrowserApp.selectedTab.id, { persistence: -1 }, "ADDON");