Index: lib/contentPolicy.js |
=================================================================== |
--- a/lib/contentPolicy.js |
+++ b/lib/contentPolicy.js |
@@ -117,16 +117,20 @@ var Policy = exports.Policy = |
* @return {Boolean} false if the node should be blocked |
*/ |
processNode: function(wnd, node, contentType, location, collapse) |
{ |
let topWnd = wnd.top; |
if (!topWnd || !topWnd.location || !topWnd.location.href) |
return true; |
+ // Ignore whitelisted schemes |
+ if (!this.isBlockableScheme(location)) |
+ return true; |
+ |
// Interpret unknown types as "other" |
if (!this.contentTypes.has(contentType)) |
contentType = "OTHER"; |
let originWindow = Utils.getOriginWindow(wnd); |
let wndLocation = originWindow.location.href; |
let docDomain = getHostname(wndLocation); |
let match = null; |
@@ -250,39 +254,46 @@ var Policy = exports.Policy = |
if (match) |
addHit(match); |
return !match || match instanceof WhitelistFilter; |
}, |
/** |
* Checks whether the location's scheme is blockable. |
- * @param location {nsIURI} |
+ * @param location {nsIURI|String} |
* @return {Boolean} |
*/ |
isBlockableScheme: function(location) |
{ |
- return !this.whitelistSchemes.has(location.scheme); |
+ let scheme; |
+ if (typeof location == "string") |
+ { |
+ let match = /^([\w\-]+):/.exec(location); |
+ scheme = match ? match[1] : null; |
+ } |
+ else |
+ scheme = location.scheme; |
+ return !this.whitelistSchemes.has(scheme); |
}, |
/** |
* Checks whether a page is whitelisted. |
* @param {String} url |
* @param {String} [parentUrl] location of the parent page |
* @param {String} [sitekey] public key provided on the page |
* @return {Filter} filter that matched the URL or null if not whitelisted |
*/ |
isWhitelisted: function(url, parentUrl, sitekey) |
{ |
if (!url) |
return null; |
// Do not apply exception rules to schemes on our whitelistschemes list. |
- let match = /^([\w\-]+):/.exec(url); |
- if (match && this.whitelistSchemes.has(match[1])) |
+ if (!this.isBlockableScheme(url)) |
return null; |
if (!parentUrl) |
parentUrl = url; |
// Ignore fragment identifier |
let index = url.indexOf("#"); |
if (index >= 0) |
@@ -375,21 +386,17 @@ var PolicyImplementation = |
// Ignore standalone objects |
if (contentType == Ci.nsIContentPolicy.TYPE_OBJECT && node.ownerDocument && !/^text\/|[+\/]xml$/.test(node.ownerDocument.contentType)) |
return Ci.nsIContentPolicy.ACCEPT; |
let wnd = Utils.getWindow(node); |
if (!wnd) |
return Ci.nsIContentPolicy.ACCEPT; |
- // Ignore whitelisted schemes |
let location = Utils.unwrapURL(contentLocation); |
- if (!Policy.isBlockableScheme(location)) |
- return Ci.nsIContentPolicy.ACCEPT; |
- |
let result = Policy.processNode(wnd, node, types.get(contentType), location.spec, false); |
return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQUEST); |
}, |
shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) |
{ |
return Ci.nsIContentPolicy.ACCEPT; |
}, |