Bug 1443849 - Part 4: Call gBrowser.init from gBrowserInit and prevent early access to gBrowser. r=Gijs a=jcristau
authorDão Gottwald <dao@mozilla.com>
Tue, 13 Mar 2018 14:44:16 +0100
changeset 462704 155f119ae3f78c9c1ad7b33eed3420922cb4d837
parent 462703 25f97bdd1f86844800ee51683d2336bb56b28efa
child 462705 45de508fe6578a2835ac311c32ac47b91511dc01
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, jcristau
bugs1443849
milestone60.0
Bug 1443849 - Part 4: Call gBrowser.init from gBrowserInit and prevent early access to gBrowser. r=Gijs a=jcristau
browser/base/content/browser.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -135,35 +135,16 @@ XPCOMUtils.defineLazyServiceGetters(this
 });
 
 if (AppConstants.MOZ_CRASHREPORTER) {
   XPCOMUtils.defineLazyServiceGetter(this, "gCrashReporter",
                                      "@mozilla.org/xre/app-info;1",
                                      "nsICrashReporter");
 }
 
-Object.defineProperty(this, "gBrowser", {
-  configurable: true,
-  enumerable: true,
-  get() {
-    delete window.gBrowser;
-
-    // The tabbed browser only exists in proper browser windows, but on Mac we
-    // load browser.js in other windows and might try to access gBrowser.
-    if (!window._gBrowser) {
-      return window.gBrowser = null;
-    }
-
-    window.gBrowser = window._gBrowser;
-    delete window._gBrowser;
-    gBrowser.init();
-    return gBrowser;
-  },
-});
-
 XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
   return Services.strings.createBundle("chrome://browser/locale/browser.properties");
 });
 XPCOMUtils.defineLazyGetter(this, "gNavigatorBundle", function() {
   // This is a stringbundle-like interface to gBrowserBundle, formerly a getter for
   // the "bundle_browser" element.
   return {
     getString(key) {
@@ -237,16 +218,17 @@ XPCOMUtils.defineLazyGetter(this, "Win7F
       }
     };
   }
   return null;
 });
 
 const nsIWebNavigation = Ci.nsIWebNavigation;
 
+var gBrowser;
 var gLastValidURLStr = "";
 var gInPrintPreviewMode = false;
 var gContextMenu = null; // nsContextMenu instance
 var gMultiProcessBrowser =
   window.QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIWebNavigation)
         .QueryInterface(Ci.nsILoadContext)
         .useRemoteTabs;
@@ -1202,16 +1184,20 @@ let _resolveDelayedStartup;
 var delayedStartupPromise = new Promise(resolve => {
   _resolveDelayedStartup = resolve;
 });
 
 var gBrowserInit = {
   delayedStartupFinished: false,
 
   onDOMContentLoaded() {
+    gBrowser = window._gBrowser;
+    delete window._gBrowser;
+    gBrowser.init();
+
     window.QueryInterface(Ci.nsIInterfaceRequestor)
           .getInterface(nsIWebNavigation)
           .QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
           .QueryInterface(Ci.nsIInterfaceRequestor)
           .getInterface(Ci.nsIXULWindow)
           .XULBrowserWindow = window.XULBrowserWindow;
     window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow =
       new nsBrowserAccess();