Bug 1338215 - use a windowless browser for thumbnail hosting, r=markh

MozReview-Commit-ID: LWzMDHu0N8H

--HG--
extra : rebase_source : faa8b821a46a164d3426f2551fd6f704deef41eb
This commit is contained in:
Gijs Kruitbosch 2017-02-27 19:58:55 +00:00
Родитель 9d62e57333
Коммит 375ee5a24a
4 изменённых файлов: 49 добавлений и 17 удалений

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

@ -160,20 +160,31 @@ const BackgroundPageThumbs = {
this._startedParentWinInit = true;
// Create an html:iframe, stick it in the parent document, and
// use it to host the browser. about:blank will not have the system
// principal, so it can't host, but a document with a chrome URI will.
let hostWindow = Services.appShell.hiddenDOMWindow;
let iframe = hostWindow.document.createElementNS(HTML_NS, "iframe");
iframe.setAttribute("src", "chrome://global/content/mozilla.xhtml");
let onLoad = function onLoadFn() {
iframe.removeEventListener("load", onLoad, true);
this._parentWin = iframe.contentWindow;
this._processCaptureQueue();
}.bind(this);
iframe.addEventListener("load", onLoad, true);
hostWindow.document.documentElement.appendChild(iframe);
this._hostIframe = iframe;
// Create a windowless browser and load our hosting
// (privileged) document in it.
let wlBrowser = Services.appShell.createWindowlessBrowser(true);
wlBrowser.QueryInterface(Ci.nsIInterfaceRequestor);
let webProgress = wlBrowser.getInterface(Ci.nsIWebProgress);
let listener = {
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIWebProgressListener, Ci.nsIWebProgressListener2,
Ci.nsISupportsWeakReference]),
};
listener.onStateChange = (wbp, request, stateFlags, status) => {
if (!request) {
return;
}
if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
webProgress.removeProgressListener(listener);
// Get the window reference via the document.
this._parentWin = wlBrowser.document.defaultView;
this._processCaptureQueue();
}
};
webProgress.addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_STATE_ALL);
wlBrowser.loadURI("chrome://global/content/backgroundPageThumbs.xhtml", 0, null, null, null);
this._windowlessContainer = wlBrowser;
return false;
},
@ -186,10 +197,10 @@ const BackgroundPageThumbs = {
if (this._captureQueue)
this._captureQueue.forEach(cap => cap.destroy());
this._destroyBrowser();
if (this._hostIframe)
this._hostIframe.remove();
if (this._windowlessContainer)
this._windowlessContainer.close();
delete this._captureQueue;
delete this._hostIframe;
delete this._windowlessContainer;
delete this._startedParentWinInit;
delete this._parentWin;
},

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

@ -0,0 +1,16 @@
<!DOCTYPE html>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!-- This page is used to host a (remote) browser for background page
thumbnailing purposes. It's always loaded as chrome:// . -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset='utf-8' />
<title>backgroundPageThumbs.html</title>
</head>
<body></body>
</html>

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

@ -189,6 +189,10 @@ const backgroundPageThumbsContent = {
// reasons: GC the captured page, and ensure it can't possibly load any more
// resources.
_loadAboutBlank: function _loadAboutBlank() {
// It's possible we've been destroyed by now, if so don't do anything:
if (!docShell) {
return;
}
this._webNav.loadURI("about:blank",
Ci.nsIWebNavigation.LOAD_FLAGS_STOP_CONTENT,
null, null, null);

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

@ -3,4 +3,5 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
toolkit.jar:
content/global/backgroundPageThumbs.xhtml (content/backgroundPageThumbs.xhtml)
content/global/backgroundPageThumbsContent.js (content/backgroundPageThumbsContent.js)