mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-06-01 18:10:17 +12:00
parent
15dc2dc1e9
commit
d5e7bc8800
|
@ -73,7 +73,8 @@ var contentObserver = {
|
|||
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
||||
cpMessageName: hostName + ':shouldLoad',
|
||||
uniqueSandboxId: 1,
|
||||
firefoxPre35: Services.vc.compare(Services.appinfo.platformVersion, '35.0') < 0,
|
||||
modernFirefox: Services.appinfo.ID === '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}' &&
|
||||
Services.vc.compare(Services.appinfo.platformVersion, '45.0') >= 0,
|
||||
|
||||
get componentRegistrar() {
|
||||
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
|
@ -102,33 +103,37 @@ var contentObserver = {
|
|||
register: function() {
|
||||
Services.obs.addObserver(this, 'document-element-inserted', true);
|
||||
|
||||
this.componentRegistrar.registerFactory(
|
||||
this.classID,
|
||||
this.classDescription,
|
||||
this.contractID,
|
||||
this
|
||||
);
|
||||
this.categoryManager.addCategoryEntry(
|
||||
'content-policy',
|
||||
this.contractID,
|
||||
this.contractID,
|
||||
false,
|
||||
true
|
||||
);
|
||||
if ( !this.modernFirefox ) {
|
||||
this.componentRegistrar.registerFactory(
|
||||
this.classID,
|
||||
this.classDescription,
|
||||
this.contractID,
|
||||
this
|
||||
);
|
||||
this.categoryManager.addCategoryEntry(
|
||||
'content-policy',
|
||||
this.contractID,
|
||||
this.contractID,
|
||||
false,
|
||||
true
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
unregister: function() {
|
||||
Services.obs.removeObserver(this, 'document-element-inserted');
|
||||
|
||||
this.componentRegistrar.unregisterFactory(
|
||||
this.classID,
|
||||
this
|
||||
);
|
||||
this.categoryManager.deleteCategoryEntry(
|
||||
'content-policy',
|
||||
this.contractID,
|
||||
false
|
||||
);
|
||||
if ( !this.modernFirefox ) {
|
||||
this.componentRegistrar.unregisterFactory(
|
||||
this.classID,
|
||||
this
|
||||
);
|
||||
this.categoryManager.deleteCategoryEntry(
|
||||
'content-policy',
|
||||
this.contractID,
|
||||
false
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy
|
||||
|
|
|
@ -46,7 +46,8 @@ 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;
|
||||
vAPI.modernFirefox = Services.appinfo.ID === '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}' &&
|
||||
Services.vc.compare(Services.appinfo.platformVersion, '45.0') >= 0;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -1819,7 +1820,18 @@ var httpObserver = {
|
|||
// http-on-opening-request
|
||||
var tabId;
|
||||
var pendingRequest = this.lookupPendingRequest(URI.asciiSpec);
|
||||
var rawType = channel.loadInfo && channel.loadInfo.contentPolicyType || 1;
|
||||
var rawType = 1;
|
||||
var loadInfo = channel.loadInfo;
|
||||
|
||||
// https://github.com/gorhill/uMatrix/issues/390#issuecomment-155717004
|
||||
if ( loadInfo ) {
|
||||
rawType = loadInfo.externalContentPolicyType !== undefined ?
|
||||
loadInfo.externalContentPolicyType :
|
||||
loadInfo.contentPolicyType;
|
||||
if ( !rawType ) {
|
||||
rawType = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pendingRequest !== null ) {
|
||||
tabId = pendingRequest.tabId;
|
||||
|
@ -1903,18 +1915,26 @@ 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.modernFirefox ) {
|
||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||
shouldLoadListenerMessageName,
|
||||
shouldLoadListener
|
||||
);
|
||||
}
|
||||
|
||||
httpObserver.register();
|
||||
|
||||
cleanupTasks.push(function() {
|
||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||
shouldLoadListenerMessageName,
|
||||
shouldLoadListener
|
||||
);
|
||||
if ( !vAPI.modernFirefox ) {
|
||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||
shouldLoadListenerMessageName,
|
||||
shouldLoadListener
|
||||
);
|
||||
}
|
||||
|
||||
httpObserver.unregister();
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue