From 288df6a7bf8b933e2dc499e38f4915fcf974c14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Mon, 30 Dec 2019 15:55:13 -0500 Subject: backport - Flush caches on upgrade - Properly handle FrameModule's unloading - Use the new module and remove the old implementation --- frameScript.js | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'frameScript.js') diff --git a/frameScript.js b/frameScript.js index e4b2dbe..cc1a564 100644 --- a/frameScript.js +++ b/frameScript.js @@ -21,54 +21,43 @@ uMatrix Home: https://github.com/gorhill/uMatrix */ -/******************************************************************************/ +'use strict'; -var locationChangeListener; // Keep alive while frameScript is alive - -(function() { - - 'use strict'; +Components.utils.import('chrome://ematrix/content/lib/FrameModule.jsm'); - /******************************************************************************/ - - let {contentObserver, LocationChangeListener} = Components.utils.import( - Components.stack.filename.replace('Script', 'Module'), - null - ); +var locationChangeListener; // Keep alive while frameScript is alive - let injectContentScripts = function(win) { - if ( !win || !win.document ) { +(function () { + let injectContentScripts = function (win) { + if (!win || !win.document) { return; } contentObserver.observe(win.document); - if ( win.frames && win.frames.length ) { - let i = win.frames.length; - while ( i-- ) { + if (win.frames && win.frames.length) { + for (let i = win.frames.length; i>0; --i) { injectContentScripts(win.frames[i]); } } }; - let onLoadCompleted = function() { + let onLoadCompleted = function () { removeMessageListener('ematrix-load-completed', onLoadCompleted); injectContentScripts(content); }; addMessageListener('ematrix-load-completed', onLoadCompleted); - if ( docShell ) { + if (docShell) { let Ci = Components.interfaces; - let wp = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress); + let wp = docShell + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebProgress); let dw = wp.DOMWindow; - if ( dw === dw.top ) { + + if (dw === dw.top) { locationChangeListener = new LocationChangeListener(docShell); } - }; - - /******************************************************************************/ - + } })(); - -/******************************************************************************/ -- cgit v1.2.3