Bug 1645541, remove uncommonly used outerid to browser map and just iterate over the tabs instead, r=mconley
authorNeil Deakin <neil@mozilla.com>
Wed, 17 Jun 2020 15:00:50 +0000
changeset 536126 758831c2e0976b544eb4ecdd04262c115f10cf17
parent 536125 36790714faf25ec3d846485ef046e0efbe9e6c87
child 536127 660432a1429dd333d2cf4bdde6c025a140051118
push id119251
push userneil@mozilla.com
push dateWed, 17 Jun 2020 16:06:24 +0000
treeherderautoland@660432a1429d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1645541
milestone79.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 1645541, remove uncommonly used outerid to browser map and just iterate over the tabs instead, r=mconley The map is only used by payments and about:devtools. Differential Revision: https://phabricator.services.mozilla.com/D79608
browser/base/content/tabbrowser.js
browser/modules/NewTabPagePreloading.jsm
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -50,21 +50,16 @@
           "browser.display.background_color"
         );
       }
 
       let messageManager = window.getGroupMessageManager("browsers");
 
       if (gMultiProcessBrowser) {
         messageManager.addMessageListener("Browser:Init", this);
-      } else {
-        this._outerWindowIDBrowserMap.set(
-          this.selectedBrowser.outerWindowID,
-          this.selectedBrowser
-        );
       }
       messageManager.addMessageListener("RefreshBlocker:Blocked", this);
 
       this._setFindbarData();
 
       XPCOMUtils.defineLazyModuleGetters(this, {
         E10SUtils: "resource://gre/modules/E10SUtils.jsm",
       });
@@ -96,18 +91,16 @@
     mTabsProgressListeners: [],
 
     _tabListeners: new Map(),
 
     _tabFilters: new Map(),
 
     _isBusy: false,
 
-    _outerWindowIDBrowserMap: new Map(),
-
     arrowKeysShouldWrap: AppConstants == "macosx",
 
     _dateTimePicker: null,
 
     _previewMode: false,
 
     _lastFindValue: "",
 
@@ -758,17 +751,23 @@
       });
     },
 
     getBrowserAtIndex(aIndex) {
       return this.browsers[aIndex];
     },
 
     getBrowserForOuterWindowID(aID) {
-      return this._outerWindowIDBrowserMap.get(aID);
+      for (let b of this.browsers) {
+        if (b.outerWindowID == aID) {
+          return b;
+        }
+      }
+
+      return null;
     },
 
     getTabForBrowser(aBrowser) {
       return this._tabForBrowser.get(aBrowser);
     },
 
     getPanel(aBrowser) {
       return this.getBrowserContainer(aBrowser).parentNode;
@@ -1804,19 +1803,16 @@
       this._insertBrowser(tab);
 
       let evt = document.createEvent("Events");
       evt.initEvent("BeforeTabRemotenessChange", true, false);
       tab.dispatchEvent(evt);
 
       let wasActive = document.activeElement == aBrowser;
 
-      // Unmap the old outerWindowID.
-      this._outerWindowIDBrowserMap.delete(aBrowser.outerWindowID);
-
       // Unhook our progress listener.
       let filter = this._tabFilters.get(tab);
       let listener = this._tabListeners.get(tab);
       aBrowser.webProgress.removeProgressListener(filter);
       filter.removeProgressListener(listener);
 
       // We'll be creating a new listener, so destroy the old one.
       listener.destroy();
@@ -1912,19 +1908,16 @@
         // crashed.
         tab.removeAttribute("crashed");
       } else {
         aBrowser.sendMessageToActor(
           "Browser:AppTab",
           { isAppTab: tab.pinned },
           "BrowserTab"
         );
-
-        // Register the new outerWindowID.
-        this._outerWindowIDBrowserMap.set(aBrowser.outerWindowID, aBrowser);
       }
 
       if (wasActive) {
         aBrowser.focus();
       }
 
       // If the findbar has been initialised, reset its browser reference.
       if (this.isFindBarInitialized(tab)) {
@@ -2208,21 +2201,17 @@
 
       // If browser is a lazy browser, delete the substitute properties.
       if (this._browserBindingProperties[0] in browser) {
         for (let name of this._browserBindingProperties) {
           delete browser[name];
         }
       }
 
-      let {
-        uriIsAboutBlank,
-        remoteType,
-        usingPreloadedContent,
-      } = aTab._browserParams;
+      let { uriIsAboutBlank, usingPreloadedContent } = aTab._browserParams;
       delete aTab._browserParams;
       delete aTab._cachedCurrentURI;
 
       let panel = this.getPanel(browser);
       let uniqueId = this._generateUniquePanelID();
       panel.id = uniqueId;
       aTab.linkedPanel = uniqueId;
 
@@ -2266,25 +2255,16 @@
       // of empty content instead.
       //
       // So for all browsers except for the preloaded case, we set the browser
       // docShell to inactive.
       if (!usingPreloadedContent) {
         browser.docShellIsActive = false;
       }
 
-      // When addTab() is called with an URL that is not "about:blank" we
-      // set the "nodefaultsrc" attribute that prevents a frameLoader
-      // from being created as soon as the linked <browser> is inserted
-      // into the DOM. We thus have to register the new outerWindowID
-      // for non-remote browsers after we have called browser.loadURI().
-      if (remoteType == E10SUtils.NOT_REMOTE) {
-        this._outerWindowIDBrowserMap.set(browser.outerWindowID, browser);
-      }
-
       // If we transitioned from one browser to two browsers, we need to set
       // hasSiblings=false on both the existing browser and the new browser.
       if (this.tabs.length == 2) {
         this.tabs[0].linkedBrowser.sendMessageToActor(
           "Browser:HasSiblings",
           true,
           "BrowserTab"
         );
@@ -2353,18 +2333,16 @@
       aTab._browserParams = {
         uriIsAboutBlank: browser.currentURI.spec == "about:blank",
         remoteType: browser.remoteType,
         usingPreloadedContent: false,
       };
 
       SessionStore.resetBrowserToLazyState(aTab);
 
-      this._outerWindowIDBrowserMap.delete(browser.outerWindowID);
-
       // Remove the tab's filter and progress listener.
       let filter = this._tabFilters.get(aTab);
       let listener = this._tabListeners.get(aTab);
       browser.webProgress.removeProgressListener(filter);
       filter.removeProgressListener(listener);
       listener.destroy();
 
       this._tabListeners.delete(aTab);
@@ -3647,18 +3625,16 @@
 
       // We're going to remove the tab and the browser now.
       this._tabFilters.delete(aTab);
       this._tabListeners.delete(aTab);
 
       var browser = this.getBrowserForTab(aTab);
 
       if (aTab.linkedPanel) {
-        this._outerWindowIDBrowserMap.delete(browser.outerWindowID);
-
         // Because of the fact that we are setting JS properties on
         // the browser elements, and we have code in place
         // to preserve the JS objects for any elements that have
         // JS properties set on them, the browser element won't be
         // destroyed until the document goes away.  So we force a
         // cleanup ourselves.
         // This has to happen before we remove the child since functions
         // like `getBrowserContainer` expect the browser to be parented.
@@ -4028,24 +4004,17 @@
       let tabListener = this._tabListeners.get(aOurTab);
       let ourBrowser = this.getBrowserForTab(aOurTab);
       ourBrowser.webProgress.removeProgressListener(filter);
       filter.removeProgressListener(tabListener);
 
       // Make sure to unregister any open URIs.
       this._swapRegisteredOpenURIs(ourBrowser, aOtherBrowser);
 
-      // Unmap old outerWindowIDs.
-      this._outerWindowIDBrowserMap.delete(ourBrowser.outerWindowID);
       let remoteBrowser = aOtherBrowser.ownerGlobal.gBrowser;
-      if (remoteBrowser) {
-        remoteBrowser._outerWindowIDBrowserMap.delete(
-          aOtherBrowser.outerWindowID
-        );
-      }
 
       // If switcher is active, it will intercept swap events and
       // react as needed.
       if (!this._switcher) {
         aOtherBrowser.docShellIsActive = this.shouldActivateDocShell(
           ourBrowser
         );
       }
@@ -4055,25 +4024,16 @@
 
       if (ourBrowser.isRemoteBrowser) {
         // Switch outerWindowIDs for remote browsers.
         let ourOuterWindowID = ourBrowser._outerWindowID;
         ourBrowser._outerWindowID = aOtherBrowser._outerWindowID;
         aOtherBrowser._outerWindowID = ourOuterWindowID;
       }
 
-      // Register new outerWindowIDs.
-      this._outerWindowIDBrowserMap.set(ourBrowser.outerWindowID, ourBrowser);
-      if (remoteBrowser) {
-        remoteBrowser._outerWindowIDBrowserMap.set(
-          aOtherBrowser.outerWindowID,
-          aOtherBrowser
-        );
-      }
-
       // Swap permanentKey properties.
       let ourPermanentKey = ourBrowser.permanentKey;
       ourBrowser.permanentKey = aOtherBrowser.permanentKey;
       aOtherBrowser.permanentKey = ourPermanentKey;
       aOurTab.permanentKey = ourBrowser.permanentKey;
       if (remoteBrowser) {
         let otherTab = remoteBrowser.getTabForBrowser(aOtherBrowser);
         if (otherTab) {
@@ -5155,17 +5115,16 @@
 
       switch (aMessage.name) {
         case "Browser:Init": {
           let tab = this.getTabForBrowser(browser);
           if (!tab) {
             return undefined;
           }
 
-          this._outerWindowIDBrowserMap.set(browser.outerWindowID, browser);
           browser.sendMessageToActor(
             "Browser:AppTab",
             { isAppTab: tab.pinned },
             "BrowserTab"
           );
           break;
         }
         case "RefreshBlocker:Blocked": {
@@ -5661,19 +5620,16 @@
         // Dispatch the `BeforeTabRemotenessChange` event, allowing other code
         // to react to this tab's process switch.
         let evt = document.createEvent("Events");
         evt.initEvent("BeforeTabRemotenessChange", true, false);
         tab.dispatchEvent(evt);
 
         let wasActive = document.activeElement == browser;
 
-        // Unmap the old outerWindowId
-        this._outerWindowIDBrowserMap.delete(browser.outerWindowID);
-
         // Unhook our progress listener.
         let filter = this._tabFilters.get(tab);
         let oldListener = this._tabListeners.get(tab);
         browser.webProgress.removeProgressListener(filter);
         filter.removeProgressListener(oldListener);
         let stateFlags = oldListener.mStateFlags;
         let requestCount = oldListener.mRequestCount;
 
@@ -5747,19 +5703,16 @@
             // crashed.
             tab.removeAttribute("crashed");
           } else {
             browser.sendMessageToActor(
               "Browser:AppTab",
               { isAppTab: tab.pinned },
               "BrowserTab"
             );
-
-            // Register the new outerWindowID.
-            this._outerWindowIDBrowserMap.set(browser.outerWindowID, browser);
           }
 
           if (wasActive) {
             browser.focus();
           }
 
           if (this.isFindBarInitialized(tab)) {
             this.getCachedFindBar(tab).browser = browser;
--- a/browser/modules/NewTabPagePreloading.jsm
+++ b/browser/modules/NewTabPagePreloading.jsm
@@ -87,30 +87,22 @@ let NewTabPagePreloading = {
       return null;
     }
     // Don't call getPreloadedBrowser because it'll consume the browser:
     let oldBrowser = oldWin.gBrowser.preloadedBrowser;
     oldWin.gBrowser.preloadedBrowser = null;
 
     let newBrowser = this._createBrowser(window);
 
-    oldWin.gBrowser._outerWindowIDBrowserMap.delete(oldBrowser.outerWindowID);
-    window.gBrowser._outerWindowIDBrowserMap.delete(newBrowser.outerWindowID);
-
     oldBrowser.swapBrowsers(newBrowser);
 
     // Switch outerWindowIDs for remote browsers.
     if (newBrowser.isRemoteBrowser) {
       newBrowser._outerWindowID = oldBrowser._outerWindowID;
     }
-
-    window.gBrowser._outerWindowIDBrowserMap.set(
-      newBrowser.outerWindowID,
-      newBrowser
-    );
     newBrowser.permanentKey = oldBrowser.permanentKey;
 
     oldWin.gBrowser.getPanel(oldBrowser).remove();
     return newBrowser;
   },
 
   maybeCreatePreloadedBrowser(window) {
     // If we're not enabled, have already got one, or are in a popup window,