Bug 1109875 - Make browser.permanentKey a property of the XUL element instead of a property of the XUL binding r=billm
authorTim Taubert <ttaubert@mozilla.com>
Tue, 28 Apr 2015 18:55:43 +0200
changeset 242373 5dd3334019f5a472f52eca4ef364db81da725593
parent 242372 2b0b00fb6411dc51de2b146591254d79b15bafa5
child 242374 3168f0bf439e75ca21f0ce34f3f86e2fd5dda32c
push id28691
push userkwierso@gmail.com
push dateTue, 05 May 2015 21:46:00 +0000
treeherdermozilla-central@be81549901e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1109875
milestone40.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 1109875 - Make browser.permanentKey a property of the XUL element instead of a property of the XUL binding r=billm
browser/base/content/tabbrowser.xml
browser/modules/CustomizationTabPreloader.jsm
toolkit/content/widgets/browser.xml
toolkit/modules/tests/browser/browser_RemotePageManager.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1499,22 +1499,18 @@
             let index = tab._tPos;
             let filter = this.mTabFilters[index];
             aBrowser.webProgress.removeProgressListener(filter);
             // Make sure the browser is destroyed so it unregisters from observer notifications
             aBrowser.destroy();
 
             // Change the "remote" attribute.
             let parent = aBrowser.parentNode;
-            let permanentKey = aBrowser.permanentKey;
             parent.removeChild(aBrowser);
             aBrowser.setAttribute("remote", aShouldBeRemote ? "true" : "false");
-            // Tearing down the browser gives a new permanentKey but we want to
-            // keep the old one. Re-set it explicitly after unbinding from DOM.
-            aBrowser._permanentKey = permanentKey;
             parent.appendChild(aBrowser);
 
             // Restore the progress listener.
             aBrowser.webProgress.addProgressListener(filter, Ci.nsIWebProgress.NOTIFY_ALL);
 
             if (aShouldBeRemote) {
               // Switching the browser to be remote will connect to a new child
               // process so the browser can no longer be considered to be
@@ -1623,16 +1619,17 @@
           <![CDATA[
             const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
             let remote = aParams && aParams.remote;
             let uriIsAboutBlank = aParams && aParams.uriIsAboutBlank;
             let isPreloadBrowser = aParams && aParams.isPreloadBrowser;
 
             let b = document.createElementNS(NS_XUL, "browser");
+            b.permanentKey = {};
             b.setAttribute("type", "content-targetable");
             b.setAttribute("message", "true");
             b.setAttribute("messagemanagergroup", "browsers");
             b.setAttribute("contextmenu", this.getAttribute("contentcontextmenu"));
             b.setAttribute("tooltip", this.getAttribute("contenttooltip"));
 
             if (remote)
               b.setAttribute("remote", "true");
@@ -2486,16 +2483,21 @@
             filter.removeProgressListener(tabListener);
 
             // Make sure to unregister any open URIs.
             this._swapRegisteredOpenURIs(ourBrowser, aOtherBrowser);
 
             // Swap the docshells
             ourBrowser.swapDocShells(aOtherBrowser);
 
+            // Swap permanentKey properties.
+            let ourPermanentKey = ourBrowser.permanentKey;
+            ourBrowser.permanentKey = aOtherBrowser.permanentKey;
+            aOtherBrowser.permanentKey = ourPermanentKey;
+
             // Restore the progress listener
             this.mTabListeners[index] = tabListener =
               this.mTabProgressListener(aOurTab, ourBrowser, false);
 
             const notifyAll = Ci.nsIWebProgress.NOTIFY_ALL;
             filter.addProgressListener(tabListener, notifyAll);
             ourBrowser.webProgress.addProgressListener(filter, notifyAll);
           ]]>
@@ -3871,16 +3873,17 @@
           }
         ]]></body>
       </method>
 
       <constructor>
         <![CDATA[
           let browserStack = document.getAnonymousElementByAttribute(this, "anonid", "browserStack");
           this.mCurrentBrowser = document.getAnonymousElementByAttribute(this, "anonid", "initialBrowser");
+          this.mCurrentBrowser.permanentKey = {};
 
           this.mCurrentTab = this.tabContainer.firstChild;
           const nsIEventListenerService =
             Components.interfaces.nsIEventListenerService;
           let els = Components.classes["@mozilla.org/eventlistenerservice;1"]
                               .getService(nsIEventListenerService);
           els.addSystemEventListener(document, "keydown", this, false);
           if (this.AppConstants.platform == "macosx") {
--- a/browser/modules/CustomizationTabPreloader.jsm
+++ b/browser/modules/CustomizationTabPreloader.jsm
@@ -150,16 +150,17 @@ HiddenBrowser.prototype = {
   _createBrowser: function () {
     if (!this._hiddenFrame) {
       this._hiddenFrame = new HiddenFrame();
     }
 
     this._hiddenFrame.get().then(aFrame => {
       let doc = aFrame.document;
       this._browser = doc.createElementNS(XUL_NS, "browser");
+      this._browser.permanentKey = {};
       this._browser.setAttribute("type", "content");
       this._browser.setAttribute("src", CUSTOMIZATION_URL);
       this._browser.style.width = "400px";
       this._browser.style.height = "400px";
       doc.getElementById("win").appendChild(this._browser);
     });
   },
 
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -397,21 +397,16 @@
             this._fastFind = Components.classes["@mozilla.org/typeaheadfind;1"]
                                        .createInstance(Components.interfaces.nsITypeAheadFind);
             this._fastFind.init(this.docShell);
           }
           return this._fastFind;
         ]]></getter>
       </property>
 
-      <field name="_permanentKey">({})</field>
-
-      <property name="permanentKey" readonly="true"
-                onget="return this._permanentKey;"/>
-
       <property name="outerWindowID" readonly="true">
         <getter><![CDATA[
           return this.contentWindow
                      .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                      .getInterface(Components.interfaces.nsIDOMWindowUtils)
                      .outerWindowID;
         ]]></getter>
       </property>
@@ -1091,18 +1086,17 @@
           // Fields which are built as a result of notifactions (pageshow/hide,
           // DOMLinkAdded/Removed, onStateChange) should not be swapped here,
           // because these notifications are dispatched again once the docshells
           // are swapped.
           var fieldsToSwap = [
             "_docShell",
             "_webBrowserFind",
             "_contentWindow",
-            "_webNavigation",
-            "_permanentKey"
+            "_webNavigation"
           ];
 
           if (this.isRemoteBrowser) {
             fieldsToSwap.push(...[
               "_remoteWebNavigation",
               "_remoteWebProgressManager",
               "_remoteWebProgress",
               "_remoteFinder",
--- a/toolkit/modules/tests/browser/browser_RemotePageManager.js
+++ b/toolkit/modules/tests/browser/browser_RemotePageManager.js
@@ -44,16 +44,26 @@ function waitForPage(pages) {
       waitForMessage(target, "RemotePage:Load").then(() => resolve(target));
     }
 
     pages.addMessageListener("RemotePage:Init", listener);
     gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
   });
 }
 
+function swapDocShells(browser1, browser2) {
+  // Swap frameLoaders.
+  browser1.swapDocShells(browser2);
+
+  // Swap permanentKeys.
+  let tmp = browser1.permanentKey;
+  browser1.permanentKey = browser2.permanentKey;
+  browser2.permanentKey = tmp;
+}
+
 // Test that opening a page creates a port, sends the load event and then
 // navigating to a new page sends the unload event. Going back should create a
 // new port
 add_task(function* init_navigate() {
   let port = yield waitForPort(TEST_URL);
   is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");
 
   let loaded = new Promise(resolve => {
@@ -188,34 +198,34 @@ add_task(function* browser_switch() {
   is(message.data.value, "om nom", "Should have the right cookie");
 
   port1.addMessageListener("Cookie", failOnMessage);
   port2.sendAsyncMessage("GetCookie", { str: "foobaz", counter: 5 });
   message = yield waitForMessage(port2, "Cookie");
   port1.removeMessageListener("Cookie", failOnMessage);
   is(message.data.value, "om nom nom", "Should have the right cookie");
 
-  browser1.swapDocShells(browser2);
+  swapDocShells(browser1, browser2);
   is(port1.browser, browser2, "Should have noticed the swap");
   is(port2.browser, browser1, "Should have noticed the swap");
 
   // Cookies should have stayed the same
   port2.addMessageListener("Cookie", failOnMessage);
   port1.sendAsyncMessage("GetCookie");
   message = yield waitForMessage(port1, "Cookie");
   port2.removeMessageListener("Cookie", failOnMessage);
   is(message.data.value, "om nom", "Should have the right cookie");
 
   port1.addMessageListener("Cookie", failOnMessage);
   port2.sendAsyncMessage("GetCookie", { str: "foobaz", counter: 5 });
   message = yield waitForMessage(port2, "Cookie");
   port1.removeMessageListener("Cookie", failOnMessage);
   is(message.data.value, "om nom nom", "Should have the right cookie");
 
-  browser1.swapDocShells(browser2);
+  swapDocShells(browser1, browser2);
   is(port1.browser, browser1, "Should have noticed the swap");
   is(port2.browser, browser2, "Should have noticed the swap");
 
   // Cookies should have stayed the same
   port2.addMessageListener("Cookie", failOnMessage);
   port1.sendAsyncMessage("GetCookie");
   message = yield waitForMessage(port1, "Cookie");
   port2.removeMessageListener("Cookie", failOnMessage);