Bug 888972 - part 2 - Load pending frame scripts and discard browser after swapping; r=gavin

This commit is contained in:
Tim Taubert 2013-08-09 04:37:03 +02:00
Родитель 11522940ba
Коммит 9784f43b73
1 изменённых файлов: 28 добавлений и 12 удалений

Просмотреть файл

@ -290,14 +290,7 @@ let HiddenBrowsers = {
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 = {
@ -317,7 +310,9 @@ HiddenBrowser.prototype = {
return false;
}
let tabbrowser = aTab.ownerDocument.defaultView.gBrowser;
let win = aTab.ownerDocument.defaultView;
let tabbrowser = win.gBrowser;
if (!tabbrowser) {
return false;
}
@ -325,6 +320,14 @@ HiddenBrowser.prototype = {
// 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);
@ -336,7 +339,7 @@ HiddenBrowser.prototype = {
this._timer = null;
// Start pre-loading the new tab page.
this._browser.loadURI(NEWTAB_URL);
this._createBrowser();
},
resize: function (width, height) {
@ -350,12 +353,25 @@ HiddenBrowser.prototype = {
},
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);
}
};