From 51532fc74e1a6c2a3914b0e4adfa1235dbe3cee6 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Wed, 18 Mar 2015 12:47:07 +0100 Subject: [PATCH] Firefox: register unload event sooner --- platform/firefox/vapi-background.js | 46 ++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 870ad7f96..6bba48999 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -64,6 +64,29 @@ vAPI.app.restart = function() { var cleanupTasks = []; +// This must be updated manually, every time a new task is added/removed +var expectedNumberOfCleanups = 7; + +window.addEventListener('unload', function() { + for ( var cleanup of cleanupTasks ) { + cleanup(); + } + + if ( cleanupTasks.length < expectedNumberOfCleanups ) { + console.error( + 'uBlock> Cleanup tasks performed: %s (out of %s)', + cleanupTasks.length, + expectedNumberOfCleanups + ); + } + + // frameModule needs to be cleared too + var frameModule = {}; + Cu.import(vAPI.getURL('frameModule.js'), frameModule); + frameModule.contentObserver.unregister(); + Cu.unload(vAPI.getURL('frameModule.js')); +}); + /******************************************************************************/ var SQLite = { @@ -495,8 +518,7 @@ vAPI.tabs.getTabsForIds = function(tabIds) { tabIds = [tabIds]; } for ( var tab of this.getAll() ) { - var browser = getBrowserForTab(tab); - var tabId = this.stack.get(browser); + var tabId = this.stack.get(getBrowserForTab(tab)); if ( !tabId ) { continue; } @@ -846,7 +868,7 @@ vAPI.messaging.onMessage = function({target, data}) { return; } - console.error('µBlock> messaging > unknown request: %o', data); + console.error('uBlock> messaging > unknown request: %o', data); // Unhandled: // Need to callback anyways in case caller expected an answer, or @@ -1021,7 +1043,7 @@ var httpObserver = { try { this.componentRegistrar.unregisterFactory(this.classID, Components.manager.getClassObject(this.classID, Ci.nsIFactory)); } catch (ex) { - console.error('µBlock> httpObserver > unable to unregister stale instance: ', ex); + console.error('uBlock> httpObserver > unable to unregister stale instance: ', ex); } } @@ -1911,22 +1933,6 @@ vAPI.punycodeURL = function(url) { /******************************************************************************/ -// clean up when the extension is disabled - -window.addEventListener('unload', function() { - for ( var cleanup of cleanupTasks ) { - cleanup(); - } - - // frameModule needs to be cleared too - var frameModule = {}; - Cu.import(vAPI.getURL('frameModule.js'), frameModule); - frameModule.contentObserver.unregister(); - Cu.unload(vAPI.getURL('frameModule.js')); -}); - -/******************************************************************************/ - })(); /******************************************************************************/