Index: lib/requestBlocker.js |
=================================================================== |
--- a/lib/requestBlocker.js |
+++ b/lib/requestBlocker.js |
@@ -65,17 +65,17 @@ |
for (let type in browser.webRequest.ResourceType) |
yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; |
// WEBRTC gets addressed through a workaround, even if the webRequest API is |
// lacking support to block this kind of a request. |
yield "WEBRTC"; |
- // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types. |
+ // These filter types aren't mapped to resource types. |
kzar
2018/05/15 14:30:29
Nit: Mind removing this unrelated change?
hub
2018/05/15 16:31:26
Done.
|
yield "POPUP"; |
yield "ELEMHIDE"; |
yield "CSP"; |
}()); |
function getDocumentInfo(page, frame, originUrl) |
{ |
return [ |
@@ -180,27 +180,46 @@ |
return; |
let type = resourceTypes.get(details.type) || "OTHER"; |
let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, |
originUrl); |
let [filter, thirdParty] = matchRequest(url, type, docDomain, |
sitekey, specificOnly); |
+ let result; |
+ let rewrittenTo; |
kzar
2018/05/15 14:30:29
Nit: I think rewrittenUrl would be a nicer name.
Manish Jethani
2018/05/15 14:44:23
I'll second that.
Sebastian Noack
2018/05/15 14:44:36
Note that the varialbe name here is consistent wit
hub
2018/05/15 16:31:26
I'll do that.
|
+ |
+ if (filter instanceof BlockingFilter) |
+ { |
+ if (filter.rewrite) |
+ { |
+ rewrittenTo = filter.rewriteUrl(details.url); |
+ // If no rewrite happened (error, different origin), we'll |
+ // return undefined in order to avoid an "infinite" loop. |
+ if (rewrittenTo != details.url) |
+ result = {redirectUrl: rewrittenTo}; |
+ } |
+ else |
+ result = {cancel: true}; |
+ } |
+ |
getRelatedTabIds(details).then(tabIds => |
{ |
logRequest( |
tabIds, |
- {url: details.url, type, docDomain, thirdParty, sitekey, specificOnly}, |
+ { |
+ url: details.url, type, docDomain, thirdParty, |
+ sitekey, specificOnly, rewrittenTo |
+ }, |
filter |
); |
}); |
- if (filter instanceof BlockingFilter) |
- return {cancel: true}; |
+ return result; |
}, {urls: ["<all_urls>"]}, ["blocking"]); |
port.on("filters.collapse", (message, sender) => |
{ |
let {page, frame} = sender; |
if (checkWhitelisted(page, frame)) |
return false; |