diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index 6b23501..42ee8fb 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -72,6 +72,7 @@ const contentObserver = { contentBaseURI: 'chrome://' + hostName + '/content/js/', cpMessageName: hostName + ':shouldLoad', uniqueSandboxId: 1, + firefoxPost34: Services.vc.compare(Services.appinfo.platformVersion, '35.0') >= 0, get componentRegistrar() { return Components.manager.QueryInterface(Ci.nsIComponentRegistrar); @@ -126,13 +127,10 @@ const contentObserver = { ); }, + // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy // https://bugzil.la/612921 shouldLoad: function(type, location, origin, context) { - if ( Services === undefined ) { - return this.ACCEPT; - } - - if ( !context ) { + if ( this.firefoxPost34 || Services === undefined || !context ) { return this.ACCEPT; } diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index af42b7c..d1b74fd 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -46,6 +46,7 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null); var vAPI = self.vAPI = self.vAPI || {}; vAPI.firefox = true; +vAPI.firefoxPre35 = Services.vc.compare(Services.appinfo.platformVersion, '35.0') < 0; /******************************************************************************/ @@ -1883,18 +1884,25 @@ vAPI.net.registerListeners = function() { pendingReq.tabId = tabWatcher.tabIdFromTarget(e.target); }; - vAPI.messaging.globalMessageManager.addMessageListener( - shouldLoadListenerMessageName, - shouldLoadListener - ); + // https://github.com/gorhill/uMatrix/issues/200 + // We need this only for Firefox 34 and less: the tab id is derived from + // the origin of the message. + if ( vAPI.firefoxPre35 ) { + vAPI.messaging.globalMessageManager.addMessageListener( + shouldLoadListenerMessageName, + shouldLoadListener + ); + } httpObserver.register(); cleanupTasks.push(function() { - vAPI.messaging.globalMessageManager.removeMessageListener( - shouldLoadListenerMessageName, - shouldLoadListener - ); + if ( vAPI.firefoxPre35 ) { + vAPI.messaging.globalMessageManager.removeMessageListener( + shouldLoadListenerMessageName, + shouldLoadListener + ); + } httpObserver.unregister(); }); };