From 51d18b4c4753df4d309c4143da30eb9c0488f3b9 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 22 Jul 2015 09:41:20 -0400 Subject: [PATCH] shouldLoad needed only for FF34 and less (no need for sync messaging with e10s) --- platform/firefox/frameModule.js | 8 +++----- platform/firefox/vapi-background.js | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) 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(); }); };