From 28923771dc48d532045ebb2b58bc57e8e77adba8 Mon Sep 17 00:00:00 2001 From: AlexVallat Date: Tue, 17 Mar 2015 18:08:29 +0000 Subject: [PATCH] Robustness changes from watching logs in Fennec --- platform/firefox/vapi-background.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index def0e09..7520aec 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -371,6 +371,9 @@ var getTabBrowser = function(win) { /******************************************************************************/ var getBrowserForTab = function(tab) { + if ( !tab ) { + return null; + } return vAPI.fennec && tab.browser || tab.linkedBrowser || null; }; @@ -457,6 +460,9 @@ vAPI.tabs.stackId = 1; /******************************************************************************/ vAPI.tabs.getTabId = function(target) { + if ( !target ) { + return vAPI.noTabId; + } if ( vAPI.fennec ) { if ( target.browser ) { // target is a tab @@ -1010,6 +1016,15 @@ var httpObserver = { Services.obs.addObserver(this, 'http-on-opening-request', true); Services.obs.addObserver(this, 'http-on-examine-response', true); + // Guard against stale instances not having been unregistered + if ( this.componentRegistrar.isCIDRegistered(this.classID) ) { + 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); + } + } + this.componentRegistrar.registerFactory( this.classID, this.classDescription, @@ -1813,10 +1828,9 @@ var optionsObserver = { cleanupTasks.push(this.unregister.bind(this)); var browser = getBrowserForTab(vAPI.tabs.get(null)); - if ( browser.currentURI.spec !== 'about:addons' ) { - return; + if ( browser && browser.currentURI && browser.currentURI.spec === 'about:addons' ) { + this.observe(browser.contentDocument, 'addon-enabled', this.addonId); } - this.observe(browser.contentDocument, 'addon-enabled', this.addonId); }, unregister: function() {