Firefox: simplify vAPI.app.restart

pull/2/head
Deathamns 10 years ago committed by gorhill
parent bc9c9ca2d9
commit 648e5e2d67

@ -19,8 +19,6 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global Services, XPCOMUtils, CustomizableUI */
// For background page // For background page
/******************************************************************************/ /******************************************************************************/
@ -33,9 +31,7 @@
const {classes: Cc, interfaces: Ci, utils: Cu} = Components; const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu['import']('resource://gre/modules/Services.jsm'); Cu.import('resource://gre/modules/Services.jsm');
Cu['import']('resource://gre/modules/XPCOMUtils.jsm');
Cu['import']('resource:///modules/CustomizableUI.jsm');
/******************************************************************************/ /******************************************************************************/
@ -53,8 +49,10 @@ vAPI.app = {
/******************************************************************************/ /******************************************************************************/
vAPI.app.restart = function() { vAPI.app.restart = function() {
// Observing in bootstrap.js // Listening in bootstrap.js
Services.obs.notifyObservers(null, location.host + '-restart', null); Cc['@mozilla.org/childprocessmessagemanager;1']
.getService(Ci.nsIMessageSender)
.sendAsyncMessage(location.host + '-restart');
}; };
/******************************************************************************/ /******************************************************************************/
@ -641,6 +639,8 @@ vAPI.toolbarButton = {
/******************************************************************************/ /******************************************************************************/
vAPI.toolbarButton.init = function() { vAPI.toolbarButton.init = function() {
const {CustomizableUI} = Cu.import('resource:///modules/CustomizableUI.jsm', {});
CustomizableUI.createWidget({ CustomizableUI.createWidget({
id: this.widgetId, id: this.widgetId,
type: 'view', type: 'view',
@ -936,12 +936,16 @@ var httpObserver = {
.getService(Ci.nsICategoryManager); .getService(Ci.nsICategoryManager);
}, },
QueryInterface: XPCOMUtils.generateQI([ QueryInterface: (function() {
Ci.nsIFactory, var {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', {});
Ci.nsIObserver,
Ci.nsIChannelEventSink, return XPCOMUtils.generateQI([
Ci.nsISupportsWeakReference Ci.nsIFactory,
]), Ci.nsIObserver,
Ci.nsIChannelEventSink,
Ci.nsISupportsWeakReference
]);
})(),
createInstance: function(outer, iid) { createInstance: function(outer, iid) {
if ( outer ) { if ( outer ) {
@ -1048,12 +1052,12 @@ var httpObserver = {
} }
try { try {
// [tabId, type, sourceTabId - given if it was a popup]
channelData = channel.getProperty(location.host + 'reqdata'); channelData = channel.getProperty(location.host + 'reqdata');
} catch (ex) { } catch (ex) {
return; return;
} }
// [tabId, type, sourceTabId - given if it was a popup]
if ( !channelData || channelData[0] !== this.MAIN_FRAME ) { if ( !channelData || channelData[0] !== this.MAIN_FRAME ) {
return; return;
} }
@ -1402,7 +1406,7 @@ window.addEventListener('unload', function() {
// frameModule needs to be cleared too // frameModule needs to be cleared too
var frameModule = {}; var frameModule = {};
Cu['import'](vAPI.getURL('frameModule.js'), frameModule); Cu.import(vAPI.getURL('frameModule.js'), frameModule);
frameModule.contentObserver.unregister(); frameModule.contentObserver.unregister();
Cu.unload(vAPI.getURL('frameModule.js')); Cu.unload(vAPI.getURL('frameModule.js'));
}); });

Loading…
Cancel
Save