Bug 1303595 - Add inner browser to browser -> tab map. r=ochameau draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Tue, 04 Oct 2016 17:33:14 -0500
changeset 420883 712b447f7e8c21386614d306bbe0a66fbcd3238d
parent 420882 60cbbd23ad055263196e7166fe78bbf9743f1d44
child 532931 f8832a42ddc22e769d74c386e920e39d52f7c00b
push id31333
push userbmo:jryans@gmail.com
push dateTue, 04 Oct 2016 22:37:35 +0000
reviewersochameau
bugs1303595, 1279086
milestone52.0a1
Bug 1303595 - Add inner browser to browser -> tab map. r=ochameau Assist tabbrowser.xml with processing some events such as MozLayerTreeReady which bubble up from the remote content frame by adding the inner browser to the WeakMap from browser to tab. Most likely this should have been in place all along, but a change from bug 1279086 made it more apparent that it was missing because an error is now thrown when no tab is found for a browser. MozReview-Commit-ID: 9wYAOcySkN
devtools/client/responsive.html/browser/tunnel.js
--- a/devtools/client/responsive.html/browser/tunnel.js
+++ b/devtools/client/responsive.html/browser/tunnel.js
@@ -141,16 +141,22 @@ function tunnelToInnerBrowser(outer, inn
       // when it creates a new browser, etc.  Since we manually changed the XBL binding
       // above, it caused a fresh webProgress object to be created which does not have any
       // listeners added.  So, we get the listener that gBrowser is using for the tab and
       // reattach it here.
       let tab = gBrowser.getTabForBrowser(outer);
       let filteredProgressListener = gBrowser._tabFilters.get(tab);
       outer.webProgress.addProgressListener(filteredProgressListener);
 
+      // Add the inner browser to tabbrowser's WeakMap from browser to tab.  This assists
+      // with tabbrowser's processing of some events such as MozLayerTreeReady which
+      // bubble up from the remote content frame and trigger tabbrowser to lookup the tab
+      // associated with the browser that triggered the event.
+      gBrowser._tabForBrowser.set(inner, tab);
+
       // All of the browser state from content was swapped onto the inner browser.  Pull
       // this state up to the outer browser.
       for (let property of SWAPPED_BROWSER_STATE) {
         outer[property] = inner[property];
       }
 
       // Wants to access the content's `frameLoader`, so we'll redirect it to
       // inner browser.
@@ -190,26 +196,27 @@ function tunnelToInnerBrowser(outer, inn
         configurable: true,
         enumerable: true,
       });
     }),
 
     stop() {
       let tab = gBrowser.getTabForBrowser(outer);
       let filteredProgressListener = gBrowser._tabFilters.get(tab);
-      browserWindow = null;
-      gBrowser = null;
 
       // The browser's state has changed over time while the tunnel was active.  Push the
       // the current state down to the inner browser, so that it follows the content in
       // case that browser will be swapped elsewhere.
       for (let property of SWAPPED_BROWSER_STATE) {
         inner[property] = outer[property];
       }
 
+      // Remove the inner browser from the WeakMap from browser to tab.
+      gBrowser._tabForBrowser.delete(inner);
+
       // Remove the progress listener we added manually.
       outer.webProgress.removeProgressListener(filteredProgressListener);
 
       // Reset the XBL binding back to the default.
       outer.destroy();
       outer.style.MozBinding = "";
 
       // Reset overridden XBL properties and methods.  Deleting the override
@@ -225,16 +232,19 @@ function tunnelToInnerBrowser(outer, inn
 
       mmTunnel.destroy();
       mmTunnel = null;
 
       // Invalidate outer's permanentKey so that SessionStore stops associating
       // things that happen to the outer browser with the content inside in the
       // inner browser.
       outer.permanentKey = { id: "zombie" };
+
+      browserWindow = null;
+      gBrowser = null;
     },
 
   };
 }
 
 exports.tunnelToInnerBrowser = tunnelToInnerBrowser;
 
 function copyPermanentKey(outer, inner) {