Bug 888972 - part 2 - Load pending frame scripts and discard browser after swapping; r=gavin
authorTim Taubert <ttaubert@mozilla.com>
Fri, 09 Aug 2013 04:37:03 +0200
changeset 154750 0b4c32636de7294f69b5dfbd67b83c53a3873005
parent 154749 c2b4541bd6d3611aaf05ca85cb47b72344a9d4b6
child 154751 631aa79fb6490655b15ee4e4f9cd39dd8e30bf36
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs888972
milestone26.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 888972 - part 2 - Load pending frame scripts and discard browser after swapping; r=gavin
browser/modules/BrowserNewTabPreloader.jsm
--- a/browser/modules/BrowserNewTabPreloader.jsm
+++ b/browser/modules/BrowserNewTabPreloader.jsm
@@ -285,24 +285,17 @@ let HiddenBrowsers = {
     }
 
     return sizes;
   }
 };
 
 function HiddenBrowser(width, height) {
   this.resize(width, height);
-
-  HostFrame.get().then(aFrame => {
-    let doc = aFrame.document;
-    this._browser = doc.createElementNS(XUL_NS, "browser");
-    this._browser.setAttribute("type", "content");
-    this._browser.setAttribute("src", NEWTAB_URL);
-    doc.getElementById("win").appendChild(this._browser);
-  });
+  this._createBrowser();
 }
 
 HiddenBrowser.prototype = {
   _width: null,
   _height: null,
   _timer: null,
 
   get isPreloaded() {
@@ -312,55 +305,78 @@ HiddenBrowser.prototype = {
            this._browser.currentURI.spec === NEWTAB_URL;
   },
 
   swapWithNewTab: function (aTab) {
     if (!this.isPreloaded || this._timer) {
       return false;
     }
 
-    let tabbrowser = aTab.ownerDocument.defaultView.gBrowser;
+    let win = aTab.ownerDocument.defaultView;
+    let tabbrowser = win.gBrowser;
+
     if (!tabbrowser) {
       return false;
     }
 
     // Swap docShells.
     tabbrowser.swapNewTabWithBrowser(aTab, this._browser);
 
+    // Load all default frame scripts attached to the target window.
+    let mm = aTab.linkedBrowser.messageManager;
+    let scripts = win.messageManager.getDelayedFrameScripts();
+    Array.forEach(scripts, script => mm.loadFrameScript(script, true));
+
+    // Remove the browser, it will be recreated by a timer.
+    this._removeBrowser();
+
     // Start a timer that will kick off preloading the next newtab page.
     this._timer = createTimer(this, PRELOADER_INTERVAL_MS);
 
     // Signal that we swapped docShells.
     return true;
   },
 
   observe: function () {
     this._timer = null;
 
     // Start pre-loading the new tab page.
-    this._browser.loadURI(NEWTAB_URL);
+    this._createBrowser();
   },
 
   resize: function (width, height) {
     if (this._browser) {
       this._browser.style.width = width + "px";
       this._browser.style.height = height + "px";
     } else {
       this._width = width;
       this._height = height;
     }
   },
 
   destroy: function () {
+    this._removeBrowser();
+    this._timer = clearTimer(this._timer);
+  },
+
+  _createBrowser: function () {
+    HostFrame.get().then(aFrame => {
+      let doc = aFrame.document;
+      this._browser = doc.createElementNS(XUL_NS, "browser");
+      this._browser.setAttribute("type", "content");
+      this._browser.setAttribute("src", NEWTAB_URL);
+      doc.getElementById("win").appendChild(this._browser);
+    });
+  },
+
+  _removeBrowser: function () {
     if (this._browser) {
       this._browser.remove();
       this._browser = null;
     }
-
-    this._timer = clearTimer(this._timer);
   }
 };
 
 let HostFrame = {
   _frame: null,
   _deferred: null,
 
   get hiddenDOMDocument() {