mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Firefox: implement vAPI.app.restart
This commit is contained in:
parent
5e55ba772d
commit
fbd2f74eb5
2 changed files with 63 additions and 19 deletions
77
platform/firefox/bootstrap.js
vendored
77
platform/firefox/bootstrap.js
vendored
|
|
@ -26,36 +26,72 @@
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
let bgProcess = function(e) {
|
let bgProcess;
|
||||||
if ( e ) {
|
const hostName = 'ublock';
|
||||||
this.removeEventListener('DOMContentLoaded', bgProcess);
|
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||||
|
const restartObserver = {
|
||||||
|
get observer() {
|
||||||
|
return Cc["@mozilla.org/observer-service;1"]
|
||||||
|
.getService(Ci.nsIObserverService);
|
||||||
|
},
|
||||||
|
|
||||||
|
QueryInterface: (function() {
|
||||||
|
let {XPCOMUtils} = Cu['import']('resource://gre/modules/XPCOMUtils.jsm', {});
|
||||||
|
|
||||||
|
return XPCOMUtils.generateQI([
|
||||||
|
Ci.nsIObserver,
|
||||||
|
Ci.nsISupportsWeakReference
|
||||||
|
]);
|
||||||
|
})(),
|
||||||
|
|
||||||
|
register: function() {
|
||||||
|
this.observer.addObserver(this, hostName + '-restart', true);
|
||||||
|
},
|
||||||
|
|
||||||
|
unregister: function() {
|
||||||
|
this.observer.removeObserver(this, hostName + '-restart');
|
||||||
|
},
|
||||||
|
|
||||||
|
observe: function() {
|
||||||
|
shutdown();
|
||||||
|
startup();
|
||||||
}
|
}
|
||||||
|
|
||||||
let hDoc = Components.classes['@mozilla.org/appshell/appShellService;1']
|
|
||||||
.getService(Components.interfaces.nsIAppShellService)
|
|
||||||
.hiddenDOMWindow.document;
|
|
||||||
|
|
||||||
bgProcess = hDoc.documentElement.appendChild(
|
|
||||||
hDoc.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
|
||||||
);
|
|
||||||
bgProcess.setAttribute('src', 'chrome://ublock/content/background.html');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function startup(data, reason) {
|
function startup(data, reason) {
|
||||||
|
let onReady = function(e) {
|
||||||
|
if ( e ) {
|
||||||
|
this.removeEventListener(e.type, onReady);
|
||||||
|
}
|
||||||
|
|
||||||
|
let hDoc = Cc['@mozilla.org/appshell/appShellService;1']
|
||||||
|
.getService(Ci.nsIAppShellService)
|
||||||
|
.hiddenDOMWindow.document;
|
||||||
|
|
||||||
|
bgProcess = hDoc.documentElement.appendChild(
|
||||||
|
hDoc.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
||||||
|
);
|
||||||
|
bgProcess.setAttribute(
|
||||||
|
'src',
|
||||||
|
'chrome://' + hostName + '/content/background.html'
|
||||||
|
);
|
||||||
|
restartObserver.register();
|
||||||
|
};
|
||||||
|
|
||||||
if ( reason !== APP_STARTUP ) {
|
if ( reason !== APP_STARTUP ) {
|
||||||
bgProcess();
|
onReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ww = Components.classes['@mozilla.org/embedcomp/window-watcher;1']
|
let ww = Cc['@mozilla.org/embedcomp/window-watcher;1']
|
||||||
.getService(Components.interfaces.nsIWindowWatcher);
|
.getService(Ci.nsIWindowWatcher);
|
||||||
|
|
||||||
ww.registerNotification({
|
ww.registerNotification({
|
||||||
observe: function(win) {
|
observe: function(win) {
|
||||||
ww.unregisterNotification(this);
|
ww.unregisterNotification(this);
|
||||||
win.addEventListener('DOMContentLoaded', bgProcess);
|
win.addEventListener('DOMContentLoaded', onReady);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -68,14 +104,19 @@ function shutdown(data, reason) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bgProcess.parentNode.removeChild(bgProcess);
|
bgProcess.parentNode.removeChild(bgProcess);
|
||||||
|
|
||||||
|
// remove the restartObserver only when the extension is being disabled
|
||||||
|
if ( data !== undefined ) {
|
||||||
|
restartObserver.unregister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function install() {
|
function install() {
|
||||||
// https://bugzil.la/719376
|
// https://bugzil.la/719376
|
||||||
Components.classes['@mozilla.org/intl/stringbundle;1']
|
Cc['@mozilla.org/intl/stringbundle;1']
|
||||||
.getService(Components.interfaces.nsIStringBundleService).flushBundles();
|
.getService(Ci.nsIStringBundleService).flushBundles();
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,10 @@ vAPI.app = {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.app.restart = function() {};
|
vAPI.app.restart = function() {
|
||||||
|
// Observing in bootstrap.js
|
||||||
|
Services.obs.notifyObservers(null, location.host + '-restart', null);
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue