mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
code review re 029bc946ad
- fix error message when disabling extension - properly cleanup when disabling extension
This commit is contained in:
parent
c538b260de
commit
69a76109c8
@ -88,18 +88,6 @@ var scriptTagFilterer = (function() {
|
|||||||
if ( cpmm ) { return cpmm.getService(Ci.nsISyncMessageSender); }
|
if ( cpmm ) { return cpmm.getService(Ci.nsISyncMessageSender); }
|
||||||
};
|
};
|
||||||
|
|
||||||
var listener = function(message) {
|
|
||||||
var details;
|
|
||||||
try {
|
|
||||||
details = JSON.parse(message.data);
|
|
||||||
} catch (ex) {
|
|
||||||
}
|
|
||||||
if ( !details || !details.msg ) { return; }
|
|
||||||
if (details.msg.what === 'staticFilteringDataChanged' ) {
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var getScriptTagHostnames = function() {
|
var getScriptTagHostnames = function() {
|
||||||
if ( scriptTagHostnames ) {
|
if ( scriptTagHostnames ) {
|
||||||
return scriptTagHostnames;
|
return scriptTagHostnames;
|
||||||
@ -154,7 +142,6 @@ var scriptTagFilterer = (function() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
get: regexFromHostname,
|
get: regexFromHostname,
|
||||||
listener: listener,
|
|
||||||
reset: reset
|
reset: reset
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
@ -417,6 +404,7 @@ var contentObserver = {
|
|||||||
|
|
||||||
sandbox.topContentScript = win === win.top;
|
sandbox.topContentScript = win === win.top;
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_loading_and_lifetime#Unloading_frame_scripts
|
||||||
// The goal is to have content scripts removed from web pages. This
|
// The goal is to have content scripts removed from web pages. This
|
||||||
// helps remove traces of uBlock from memory when disabling/removing
|
// helps remove traces of uBlock from memory when disabling/removing
|
||||||
// the addon.
|
// the addon.
|
||||||
@ -434,7 +422,11 @@ var contentObserver = {
|
|||||||
sandbox.removeMessageListener =
|
sandbox.removeMessageListener =
|
||||||
sandbox.sendAsyncMessage = function(){};
|
sandbox.sendAsyncMessage = function(){};
|
||||||
sandbox.vAPI = {};
|
sandbox.vAPI = {};
|
||||||
messager = sandbox = null;
|
if ( messager && messager.ublock0LocationChangeListener ) {
|
||||||
|
messager.ublock0LocationChangeListener.stop();
|
||||||
|
delete messager.ublock0LocationChangeListener;
|
||||||
|
}
|
||||||
|
messager = null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -456,7 +448,14 @@ var contentObserver = {
|
|||||||
sandbox._broadcastListener_ = function(message) {
|
sandbox._broadcastListener_ = function(message) {
|
||||||
// https://github.com/gorhill/uBlock/issues/2014
|
// https://github.com/gorhill/uBlock/issues/2014
|
||||||
if ( sandbox.topContentScript ) {
|
if ( sandbox.topContentScript ) {
|
||||||
scriptTagFilterer.listener(message);
|
let details;
|
||||||
|
try { details = JSON.parse(message.data); } catch (ex) {}
|
||||||
|
let msg = details && details.msg || {};
|
||||||
|
if ( msg.what === 'staticFilteringDataChanged' ) {
|
||||||
|
if ( scriptTagFilterer ) {
|
||||||
|
scriptTagFilterer.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
callback(message.data);
|
callback(message.data);
|
||||||
};
|
};
|
||||||
@ -475,17 +474,20 @@ var contentObserver = {
|
|||||||
if ( !sandbox._messageListener_ ) {
|
if ( !sandbox._messageListener_ ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// It throws sometimes, mostly when the popup closes
|
||||||
try {
|
try {
|
||||||
messager.removeMessageListener(
|
messager.removeMessageListener(
|
||||||
sandbox._sandboxId_,
|
sandbox._sandboxId_,
|
||||||
sandbox._messageListener_
|
sandbox._messageListener_
|
||||||
);
|
);
|
||||||
|
} catch (ex) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
messager.removeMessageListener(
|
messager.removeMessageListener(
|
||||||
hostName + ':broadcast',
|
hostName + ':broadcast',
|
||||||
sandbox._broadcastListener_
|
sandbox._broadcastListener_
|
||||||
);
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// It throws sometimes, mostly when the popup closes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox._messageListener_ = sandbox._broadcastListener_ = null;
|
sandbox._messageListener_ = sandbox._broadcastListener_ = null;
|
||||||
@ -594,6 +596,7 @@ var LocationChangeListener = function(docShell, webProgress) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.messageManager = mm;
|
this.messageManager = mm;
|
||||||
|
this.webProgress = webProgress;
|
||||||
webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_LOCATION);
|
webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_LOCATION);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -614,6 +617,13 @@ LocationChangeListener.prototype.onLocationChange = function(webProgress, reques
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LocationChangeListener.prototype.stop = function() {
|
||||||
|
if ( this.webProgress ) {
|
||||||
|
this.webProgress.removeProgressListener(this);
|
||||||
|
}
|
||||||
|
this.messageManager = this.webProgress = null;
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
contentObserver.register();
|
contentObserver.register();
|
||||||
|
Loading…
Reference in New Issue
Block a user