Index: lib/contentPolicy.js |
=================================================================== |
--- a/lib/contentPolicy.js |
+++ b/lib/contentPolicy.js |
@@ -382,36 +382,26 @@ var PolicyImplementation = |
{ |
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
registrar.registerFactory(this.classID, this.classDescription, this.contractID, this); |
let catMan = Utils.categoryManager; |
for (let category of this.xpcom_categories) |
catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true); |
- // http-on-opening-request is new in Gecko 18, http-on-modify-request can |
- // be used in earlier releases. |
- let httpTopic = "http-on-opening-request"; |
- if (Services.vc.compare(Utils.platformVersion, "18.0") < 0) |
- httpTopic = "http-on-modify-request"; |
- |
- Services.obs.addObserver(this, httpTopic, true); |
Services.obs.addObserver(this, "content-document-global-created", true); |
onShutdown.add(function() |
{ |
- Services.obs.removeObserver(this, httpTopic); |
Services.obs.removeObserver(this, "content-document-global-created"); |
for (let category of this.xpcom_categories) |
catMan.deleteCategoryEntry(category, this.contractID, false); |
registrar.unregisterFactory(this.classID, this); |
- |
- this.previousRequest = null; |
}.bind(this)); |
}, |
// |
// nsISupports interface implementation |
// |
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver, |
@@ -440,23 +430,16 @@ var PolicyImplementation = |
if (!Policy.isBlockableScheme(location)) |
return Ci.nsIContentPolicy.ACCEPT; |
// Interpret unknown types as "other" |
if (!(contentType in Policy.typeDescr)) |
contentType = Policy.type.OTHER; |
let result = Policy.processNode(wnd, node, contentType, location, false); |
- if (result) |
- { |
- // We didn't block this request so we will probably see it again in |
- // http-on-opening-request. Keep it so that we can associate it with the |
- // channel there - will be needed in case of redirect. |
- this.previousRequest = [location, contentType]; |
- } |
return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQUEST); |
}, |
shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) |
{ |
return Ci.nsIContentPolicy.ACCEPT; |
}, |
@@ -489,58 +472,35 @@ var PolicyImplementation = |
.QueryInterface(Ci.nsIDocumentLoader) |
.documentChannel; |
if (channel) |
this.observe(subject, topic, data, channel.URI); |
}); |
} |
break; |
} |
- case "http-on-opening-request": |
- case "http-on-modify-request": |
- { |
- if (!(subject instanceof Ci.nsIHttpChannel)) |
- return; |
- |
- if (this.previousRequest && subject.URI == this.previousRequest[0] && |
- subject instanceof Ci.nsIWritablePropertyBag) |
- { |
- // We just handled a content policy call for this request - associate |
- // the data with the channel so that we can find it in case of a redirect. |
- subject.setProperty("abpRequestType", this.previousRequest[1]); |
- this.previousRequest = null; |
- } |
- break; |
- } |
} |
}, |
// |
// nsIChannelEventSink interface implementation |
// |
asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback) |
{ |
let result = Cr.NS_OK; |
try |
{ |
- // Try to retrieve previously stored request data from the channel |
- let contentType; |
- if (oldChannel instanceof Ci.nsIWritablePropertyBag) |
- { |
- try |
- { |
- contentType = oldChannel.getProperty("abpRequestType"); |
- } |
- catch(e) |
- { |
- // No data attached, ignore this redirect |
- return; |
- } |
- } |
+ // nsILoadInfo.contentPolicyType was introduced in Gecko 35, then |
+ // renamed to nsILoadInfo.externalContentPolicyType in Gecko 44. |
+ let loadInfo = oldChannel.loadInfo; |
+ let contentType = ("externalContentPolicyType" in loadInfo ? |
+ loadInfo.externalContentPolicyType : loadInfo.contentPolicyType); |
+ if (!contentType) |
+ return; |
let newLocation = null; |
try |
{ |
newLocation = newChannel.URI; |
} catch(e2) {} |
if (!newLocation) |
return; |