aboutsummaryrefslogtreecommitdiffstats
path: root/platform/firefox/frameScript.js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/firefox/frameScript.js')
-rw-r--r--platform/firefox/frameScript.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/platform/firefox/frameScript.js b/platform/firefox/frameScript.js
index fdee50c..17cd84f 100644
--- a/platform/firefox/frameScript.js
+++ b/platform/firefox/frameScript.js
@@ -19,13 +19,11 @@
Home: https://github.com/gorhill/uBlock
*/
-/* global addMessageListener, removeMessageListener, docShell */
-
/******************************************************************************/
-var locationChangeListener; // Keep alive while frameScript is alive
+// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment
-(function() {
+(function(context) {
'use strict';
@@ -52,25 +50,36 @@ let injectContentScripts = function(win) {
};
let onLoadCompleted = function() {
- removeMessageListener('ublock0-load-completed', onLoadCompleted);
- injectContentScripts(content);
+ context.removeMessageListener('ublock0-load-completed', onLoadCompleted);
+ injectContentScripts(context.content);
};
+context.addMessageListener('ublock0-load-completed', onLoadCompleted);
-addMessageListener('ublock0-load-completed', onLoadCompleted);
+let shutdown = function(ev) {
+ if ( ev.target !== context ) {
+ return;
+ }
+ context.removeMessageListener('ublock0-load-completed', onLoadCompleted);
+ context.removeEventListener('unload', shutdown);
+ context.locationChangeListener = null;
+ LocationChangeListener = null;
+ contentObserver = null;
+};
+context.addEventListener('unload', shutdown);
-if ( docShell ) {
+if ( context.docShell ) {
let Ci = Components.interfaces;
- let wp = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebProgress);
+ let wp = context.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebProgress);
let dw = wp.DOMWindow;
if ( dw === dw.top ) {
- locationChangeListener = new LocationChangeListener(docShell);
+ context.locationChangeListener = new LocationChangeListener(context.docShell);
}
}
/******************************************************************************/
-})();
+})(this);
/******************************************************************************/