mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-01 16:49:39 +02:00
Fix #2493 by using the createWindowlessBrowser API when available
This commit is contained in:
parent
d7c8588c16
commit
dc06d5fa0c
78
platform/firefox/bootstrap.js
vendored
78
platform/firefox/bootstrap.js
vendored
@ -61,6 +61,60 @@ function startup(data/*, reason*/) {
|
|||||||
let appShell = Cc['@mozilla.org/appshell/appShellService;1']
|
let appShell = Cc['@mozilla.org/appshell/appShellService;1']
|
||||||
.getService(Ci.nsIAppShellService);
|
.getService(Ci.nsIAppShellService);
|
||||||
|
|
||||||
|
if ( appShell.createWindowlessBrowser ) {
|
||||||
|
getWindowlessBrowserFrame(appShell);
|
||||||
|
} else {
|
||||||
|
getHiddenWindowBrowserFrame(appShell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBgProcess(parentDocument) {
|
||||||
|
bgProcess = parentDocument.documentElement.appendChild(
|
||||||
|
parentDocument.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
||||||
|
);
|
||||||
|
bgProcess.setAttribute(
|
||||||
|
'src',
|
||||||
|
'chrome://' + hostName + '/content/background.html#' + version
|
||||||
|
);
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener%28%29
|
||||||
|
// "If the same listener registers twice for the same message, the
|
||||||
|
// "second registration is ignored."
|
||||||
|
restartListener.messageManager.addMessageListener(
|
||||||
|
hostName + '-restart',
|
||||||
|
restartListener
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let windowlessBrowser;
|
||||||
|
let windowlessBrowserPL;
|
||||||
|
|
||||||
|
function getWindowlessBrowserFrame(appShell) {
|
||||||
|
windowlessBrowser = appShell.createWindowlessBrowser(true);
|
||||||
|
windowlessBrowser.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||||
|
let webProgress = windowlessBrowser.getInterface(Ci.nsIWebProgress);
|
||||||
|
let XPCOMUtils = Components.utils.import('resource://gre/modules/XPCOMUtils.jsm', null).XPCOMUtils;
|
||||||
|
windowlessBrowserPL = {
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([
|
||||||
|
Ci.nsIWebProgressListener, Ci.nsIWebProgressListener2,
|
||||||
|
Ci.nsISupportsWeakReference]),
|
||||||
|
onStateChange(wbp, request, stateFlags, status) {
|
||||||
|
if ( !request ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( stateFlags & Ci.nsIWebProgressListener.STATE_STOP ) {
|
||||||
|
webProgress.removeProgressListener(windowlessBrowserPL);
|
||||||
|
windowlessBrowserPL = null;
|
||||||
|
createBgProcess(windowlessBrowser.document);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
webProgress.addProgressListener(windowlessBrowserPL, Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
|
||||||
|
windowlessBrowser.document.location = "data:application/vnd.mozilla.xul+xml;charset=utf-8,<window%20id='" + hostName + "-win'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getHiddenWindowBrowserFrame(appShell) {
|
||||||
let isReady = function() {
|
let isReady = function() {
|
||||||
var hiddenDoc;
|
var hiddenDoc;
|
||||||
|
|
||||||
@ -75,23 +129,7 @@ function startup(data/*, reason*/) {
|
|||||||
if ( !hiddenDoc || hiddenDoc.readyState !== 'complete' ) {
|
if ( !hiddenDoc || hiddenDoc.readyState !== 'complete' ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
createBgProcess(hiddenDoc);
|
||||||
bgProcess = hiddenDoc.documentElement.appendChild(
|
|
||||||
hiddenDoc.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
|
||||||
);
|
|
||||||
bgProcess.setAttribute(
|
|
||||||
'src',
|
|
||||||
'chrome://' + hostName + '/content/background.html#' + version
|
|
||||||
);
|
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener%28%29
|
|
||||||
// "If the same listener registers twice for the same message, the
|
|
||||||
// "second registration is ignored."
|
|
||||||
restartListener.messageManager.addMessageListener(
|
|
||||||
hostName + '-restart',
|
|
||||||
restartListener
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -150,6 +188,12 @@ function shutdown(data, reason) {
|
|||||||
bgProcess = null;
|
bgProcess = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( windowlessBrowser !== null ) {
|
||||||
|
windowlessBrowser.close();
|
||||||
|
windowlessBrowser = null;
|
||||||
|
windowlessBrowserPL = null;
|
||||||
|
}
|
||||||
|
|
||||||
if ( data === undefined ) {
|
if ( data === undefined ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user