Bug 1450242 - Remove useless constants at the top of nsBrowserContentHandler.js, r=Standard8.
authorFlorian Quèze <florian@queze.net>
Tue, 03 Apr 2018 15:44:05 +0200
changeset 776634 fe0e01b08506fe803fa12aa8b84fff9a5c59d1e8
parent 776633 d6bc182977b453cf4b1a5d4f94e34744c0c7db75
child 776635 a51cb0bc55c3dab5e250a3f3fd332bb57b8af112
push id104931
push userbmo:dharvey@mozilla.com
push dateTue, 03 Apr 2018 14:20:56 +0000
reviewersStandard8
bugs1450242
milestone61.0a1
Bug 1450242 - Remove useless constants at the top of nsBrowserContentHandler.js, r=Standard8.
browser/components/nsBrowserContentHandler.js
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -16,55 +16,30 @@ ChromeUtils.defineModuleGetter(this, "Re
                                "resource:///modules/RecentWindow.jsm");
 ChromeUtils.defineModuleGetter(this, "ShellService",
                                "resource:///modules/ShellService.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils",
                                    "@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
 ChromeUtils.defineModuleGetter(this, "UpdatePing",
                                "resource://gre/modules/UpdatePing.jsm");
 
-const nsISupports            = Ci.nsISupports;
-
-const nsIBrowserDOMWindow    = Ci.nsIBrowserDOMWindow;
-const nsIBrowserHandler      = Ci.nsIBrowserHandler;
-const nsIBrowserHistory      = Ci.nsIBrowserHistory;
-const nsIChannel             = Ci.nsIChannel;
-const nsICommandLine         = Ci.nsICommandLine;
-const nsICommandLineHandler  = Ci.nsICommandLineHandler;
-const nsIContentHandler      = Ci.nsIContentHandler;
-const nsIDocShellTreeItem    = Ci.nsIDocShellTreeItem;
-const nsIDOMChromeWindow     = Ci.nsIDOMChromeWindow;
-const nsIDOMWindow           = Ci.nsIDOMWindow;
-const nsIFileURL             = Ci.nsIFileURL;
-const nsIInterfaceRequestor  = Ci.nsIInterfaceRequestor;
-const nsINetUtil             = Ci.nsINetUtil;
-const nsIPrefLocalizedString = Ci.nsIPrefLocalizedString;
-const nsISupportsString      = Ci.nsISupportsString;
-const nsIWebNavigation       = Ci.nsIWebNavigation;
-const nsIWebNavigationInfo   = Ci.nsIWebNavigationInfo;
-const nsICommandLineValidator = Ci.nsICommandLineValidator;
-
-const NS_BINDING_ABORTED = Cr.NS_BINDING_ABORTED;
-const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
-const NS_ERROR_ABORT = Cr.NS_ERROR_ABORT;
-
 function shouldLoadURI(aURI) {
   if (aURI && !aURI.schemeIs("chrome"))
     return true;
 
   dump("*** Preventing external load of chrome: URI into browser window\n");
   dump("    Use --chrome <uri> instead\n");
   return false;
 }
 
 function resolveURIInternal(aCmdLine, aArgument) {
   var uri = aCmdLine.resolveURI(aArgument);
   var uriFixup = Services.uriFixup;
 
-  if (!(uri instanceof nsIFileURL)) {
+  if (!(uri instanceof Ci.nsIFileURL)) {
     return uriFixup.createFixupURI(aArgument,
                                    uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS);
   }
 
   try {
     if (uri.file.exists())
       return uri;
   } catch (e) {
@@ -204,31 +179,31 @@ function openBrowserWindow(cmdLine, urlO
     // Just pass in the defaultArgs directly
     args = [gBrowserContentHandler.defaultArgs];
   } else if (Array.isArray(urlOrUrlList)) {
     // Passing an nsIArray for the url disables the "|"-splitting behavior.
     let uriArray = Cc["@mozilla.org/array;1"]
                      .createInstance(Ci.nsIMutableArray);
     urlOrUrlList.forEach(function(uri) {
       var sstring = Cc["@mozilla.org/supports-string;1"]
-                      .createInstance(nsISupportsString);
+                      .createInstance(Ci.nsISupportsString);
       sstring.data = uri;
       uriArray.appendElement(sstring);
     });
     args = [uriArray];
   } else {
     // Always pass at least 3 arguments to avoid the "|"-splitting behavior,
     // ie. avoid the loadOneOrMoreURIs function.
     args = [urlOrUrlList,
             null, // charset
             null, // referer
             postData];
   }
 
-  if (cmdLine.state == nsICommandLine.STATE_INITIAL_LAUNCH) {
+  if (cmdLine.state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
     let win = Services.wm.getMostRecentWindow("navigator:blank");
     if (win) {
       // Remove the windowtype of our blank window so that we don't close it
       // later on when seeing cmdLine.preventDefault is true.
       win.document.documentElement.removeAttribute("windowtype");
 
       if (forcePrivate) {
         // This causes a "Only internal code is allowed to set the
@@ -248,17 +223,17 @@ function openBrowserWindow(cmdLine, urlO
   }
 
   // We can't provide arguments to openWindow as a JS array.
   if (!urlOrUrlList) {
     // If we have a single string guaranteed to not contain '|' we can simply
     // wrap it in an nsISupportsString object.
     let [url] = args;
     args = Cc["@mozilla.org/supports-string;1"]
-             .createInstance(nsISupportsString);
+             .createInstance(Ci.nsISupportsString);
     args.data = url;
   } else {
     // Otherwise, pass an nsIArray.
     if (args.length > 1) {
       let string = Cc["@mozilla.org/supports-string;1"]
                      .createInstance(Ci.nsISupportsString);
       string.data = args[0];
       args[0] = string;
@@ -279,25 +254,21 @@ function openPreferences(cmdLine, extraA
   if (extraArgs && extraArgs.origin) {
     Services.telemetry.getHistogramById("FX_PREFERENCES_OPENED_VIA").add(extraArgs.origin);
   } else {
     Services.telemetry.getHistogramById("FX_PREFERENCES_OPENED_VIA").add("other");
   }
   openBrowserWindow(cmdLine, "about:preferences");
 }
 
-function logSystemBasedSearch(engine) {
+function doSearch(searchTerm, cmdLine) {
+  var engine = Services.search.defaultEngine;
   var countId = (engine.identifier || ("other-" + engine.name)) + ".system";
   var count = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
   count.add(countId);
-}
-
-function doSearch(searchTerm, cmdLine) {
-  var engine = Services.search.defaultEngine;
-  logSystemBasedSearch(engine);
 
   var submission = engine.getSubmission(searchTerm, null, "system");
 
   // XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
   // preferences, but need nsIBrowserDOMWindow extensions
   openBrowserWindow(cmdLine, submission.uri.spec, submission.postData);
 }
 
@@ -310,37 +281,37 @@ nsBrowserContentHandler.prototype = {
     createInstance: function bch_factory_ci(outer, iid) {
       if (outer)
         throw Cr.NS_ERROR_NO_AGGREGATION;
       return gBrowserContentHandler.QueryInterface(iid);
     }
   },
 
   /* nsISupports */
-  QueryInterface: XPCOMUtils.generateQI([nsICommandLineHandler,
-                                         nsIBrowserHandler,
-                                         nsIContentHandler,
-                                         nsICommandLineValidator]),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler,
+                                         Ci.nsIBrowserHandler,
+                                         Ci.nsIContentHandler,
+                                         Ci.nsICommandLineValidator]),
 
   /* nsICommandLineHandler */
   handle: function bch_handle(cmdLine) {
     if (cmdLine.handleFlag("browser", false)) {
       openBrowserWindow(cmdLine);
       cmdLine.preventDefault = true;
     }
 
     // In the past, when an instance was not already running, the -remote
     // option returned an error code. Any script or application invoking the
     // -remote option is expected to be handling this case, otherwise they
     // wouldn't be doing anything when there is no Firefox already running.
     // Making the -remote option always return an error code makes those
     // scripts or applications handle the situation as if Firefox was not
     // already running.
     if (cmdLine.handleFlag("remote", true)) {
-      throw NS_ERROR_ABORT;
+      throw Cr.NS_ERROR_ABORT;
     }
 
     var uriparam;
     try {
       while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
         let uri = resolveURIInternal(cmdLine, uriparam);
         if (!shouldLoadURI(uri))
           continue;
@@ -349,17 +320,18 @@ nsBrowserContentHandler.prototype = {
       }
     } catch (e) {
       Cu.reportError(e);
     }
 
     try {
       while ((uriparam = cmdLine.handleFlagWithParam("new-tab", false))) {
         let uri = resolveURIInternal(cmdLine, uriparam);
-        handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine, false,
+        handURIToExistingBrowser(uri, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
+                                 cmdLine, false,
                                  Services.scriptSecurityManager.getSystemPrincipal());
         cmdLine.preventDefault = true;
       }
     } catch (e) {
       Cu.reportError(e);
     }
 
     var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
@@ -407,17 +379,18 @@ nsBrowserContentHandler.prototype = {
         if (!PrivateBrowsingUtils.enabled) {
           // Load about:privatebrowsing in a normal tab, which will display an error indicating
           // access to private browsing has been disabled.
           forcePrivate = false;
           resolvedURI = Services.io.newURI("about:privatebrowsing");
         } else {
           resolvedURI = resolveURIInternal(cmdLine, privateWindowParam);
         }
-        handURIToExistingBrowser(resolvedURI, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine, forcePrivate,
+        handURIToExistingBrowser(resolvedURI, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
+                                 cmdLine, forcePrivate,
                                  Services.scriptSecurityManager.getSystemPrincipal());
         cmdLine.preventDefault = true;
       }
     } catch (e) {
       if (e.result != Cr.NS_ERROR_INVALID_ARG) {
         throw e;
       }
       // NS_ERROR_INVALID_ARG is thrown when flag exists, but has no param.
@@ -578,21 +551,21 @@ nsBrowserContentHandler.prototype = {
     if (overridePage && startPage && !willRestoreSession && !skipStartPage)
       return overridePage + "|" + startPage;
 
     return overridePage || startPage || "about:blank";
   },
 
   get startPage() {
     var uri = Services.prefs.getComplexValue("browser.startup.homepage",
-                                             nsIPrefLocalizedString).data;
+                                             Ci.nsIPrefLocalizedString).data;
     if (!uri) {
       Services.prefs.clearUserPref("browser.startup.homepage");
       uri = Services.prefs.getComplexValue("browser.startup.homepage",
-                                           nsIPrefLocalizedString).data;
+                                           Ci.nsIPrefLocalizedString).data;
     }
     return uri;
   },
 
   mFeatures: null,
 
   getFeatures: function bch_features(cmdLine) {
     if (this.mFeatures === null) {
@@ -622,55 +595,57 @@ nsBrowserContentHandler.prototype = {
     }
 
     return this.mFeatures;
   },
 
   /* nsIContentHandler */
 
   handleContent: function bch_handleContent(contentType, context, request) {
+    const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
+
     try {
       var webNavInfo = Cc["@mozilla.org/webnavigation-info;1"]
-                         .getService(nsIWebNavigationInfo);
+                         .getService(Ci.nsIWebNavigationInfo);
       if (!webNavInfo.isTypeSupported(contentType, null)) {
         throw NS_ERROR_WONT_HANDLE_CONTENT;
       }
     } catch (e) {
       throw NS_ERROR_WONT_HANDLE_CONTENT;
     }
 
-    request.QueryInterface(nsIChannel);
-    handURIToExistingBrowser(request.URI, nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, null, false,
-                             request.loadInfo.triggeringPrincipal);
-    request.cancel(NS_BINDING_ABORTED);
+    request.QueryInterface(Ci.nsIChannel);
+    handURIToExistingBrowser(request.URI, Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
+                             null, false, request.loadInfo.triggeringPrincipal);
+    request.cancel(Cr.NS_BINDING_ABORTED);
   },
 
   /* nsICommandLineValidator */
   validate: function bch_validate(cmdLine) {
     // Other handlers may use osint so only handle the osint flag if the url
     // flag is also present and the command line is valid.
     var osintFlagIdx = cmdLine.findFlag("osint", false);
     var urlFlagIdx = cmdLine.findFlag("url", false);
     if (urlFlagIdx > -1 && (osintFlagIdx > -1 ||
-        cmdLine.state == nsICommandLine.STATE_REMOTE_EXPLICIT)) {
+        cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_EXPLICIT)) {
       var urlParam = cmdLine.getArgument(urlFlagIdx + 1);
       if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/i.test(urlParam))
-        throw NS_ERROR_ABORT;
+        throw Cr.NS_ERROR_ABORT;
       var isDefault = false;
       try {
         var url = Services.urlFormatter.formatURLPref("app.support.baseURL") +
                   "win10-default-browser";
         if (urlParam == url) {
           isDefault = ShellService.isDefaultBrowser(false, false);
         }
       } catch (ex) {}
       if (isDefault) {
         // Firefox is already the default HTTP handler.
         // We don't have to show the instruction page.
-        throw NS_ERROR_ABORT;
+        throw Cr.NS_ERROR_ABORT;
       }
       cmdLine.handleFlag("osint", false);
     }
   },
 };
 var gBrowserContentHandler = new nsBrowserContentHandler();
 
 function handURIToExistingBrowser(uri, location, cmdLine, forcePrivate, triggeringPrincipal) {
@@ -682,36 +657,36 @@ function handURIToExistingBrowser(uri, l
   var allowPrivate = forcePrivate || PrivateBrowsingUtils.permanentPrivateBrowsing;
   var navWin = RecentWindow.getMostRecentBrowserWindow({private: allowPrivate});
   if (!navWin) {
     // if we couldn't load it in an existing window, open a new one
     openBrowserWindow(cmdLine, uri.spec, null, forcePrivate);
     return;
   }
 
-  var navNav = navWin.QueryInterface(nsIInterfaceRequestor)
-                     .getInterface(nsIWebNavigation);
-  var rootItem = navNav.QueryInterface(nsIDocShellTreeItem).rootTreeItem;
-  var rootWin = rootItem.QueryInterface(nsIInterfaceRequestor)
-                        .getInterface(nsIDOMWindow);
-  var bwin = rootWin.QueryInterface(nsIDOMChromeWindow).browserDOMWindow;
+  var navNav = navWin.QueryInterface(Ci.nsIInterfaceRequestor)
+                     .getInterface(Ci.nsIWebNavigation);
+  var rootItem = navNav.QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem;
+  var rootWin = rootItem.QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIDOMWindow);
+  var bwin = rootWin.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow;
   bwin.openURI(uri, null, location,
-               nsIBrowserDOMWindow.OPEN_EXTERNAL, triggeringPrincipal);
+               Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL, triggeringPrincipal);
 }
 
 function nsDefaultCommandLineHandler() {
 }
 
 nsDefaultCommandLineHandler.prototype = {
   classID: Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}"),
 
   /* nsISupports */
   QueryInterface: function dch_QI(iid) {
-    if (!iid.equals(nsISupports) &&
-        !iid.equals(nsICommandLineHandler))
+    if (!iid.equals(Ci.nsISupports) &&
+        !iid.equals(Ci.nsICommandLineHandler))
       throw Cr.NS_ERROR_NO_INTERFACE;
 
     return this;
   },
 
   _haveProfile: false,
 
   /* nsICommandLineHandler */
@@ -764,36 +739,37 @@ nsDefaultCommandLineHandler.prototype = 
           urilist.push(resolveURIInternal(cmdLine, curarg));
         } catch (e) {
           Cu.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
         }
       }
     }
 
     if (urilist.length) {
-      if (cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
+      if (cmdLine.state != Ci.nsICommandLine.STATE_INITIAL_LAUNCH &&
           urilist.length == 1) {
         // Try to find an existing window and load our URI into the
         // current tab, new tab, or new window as prefs determine.
         try {
-          handURIToExistingBrowser(urilist[0], nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, cmdLine, false,
+          handURIToExistingBrowser(urilist[0], Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
+                                   cmdLine, false,
                                    Services.scriptSecurityManager.getSystemPrincipal());
           return;
         } catch (e) {
         }
       }
 
       var URLlist = urilist.filter(shouldLoadURI).map(u => u.spec);
       if (URLlist.length) {
         openBrowserWindow(cmdLine, URLlist);
       }
 
     } else if (!cmdLine.preventDefault) {
       if (AppConstants.isPlatformAndVersionAtLeast("win", "10") &&
-          cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
+          cmdLine.state != Ci.nsICommandLine.STATE_INITIAL_LAUNCH &&
           WindowsUIUtils.inTabletMode) {
         // In windows 10 tablet mode, do not create a new window, but reuse the existing one.
         let win = RecentWindow.getMostRecentBrowserWindow();
         if (win) {
           win.focus();
           return;
         }
       }