Index: lib/requestBlocker.js |
=================================================================== |
--- a/lib/requestBlocker.js |
+++ b/lib/requestBlocker.js |
@@ -65,20 +65,21 @@ |
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. |
yield "POPUP"; |
yield "ELEMHIDE"; |
yield "CSP"; |
+ yield "REWRITE"; |
}()); |
function getDocumentInfo(page, frame, originUrl) |
{ |
return [ |
extractHostFromFrame(frame, originUrl), |
getKey(page, frame, originUrl), |
!!checkWhitelisted(page, frame, originUrl, |
@@ -189,24 +190,41 @@ |
return; |
let type = resourceTypes.get(details.type) || "OTHER"; |
let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, |
originUrl); |
let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, |
sitekey, specificOnly); |
+ let result; |
+ |
+ if (filter instanceof BlockingFilter) |
+ { |
+ if (filter.rewrite) |
+ { |
+ let rewritten = filter.rewriteUrl(urlString); |
+ if (!rewritten || rewritten == urlString) |
Manish Jethani
2018/05/03 02:51:16
This should probably be updated now, since rewrite
hub
2018/05/03 18:43:48
Done.
|
+ // we couldn't do the rewrite, so just let it through. |
+ return; |
+ |
+ type = "REWRITE"; |
+ result = {redirectUrl: rewritten}; |
+ } |
+ else |
+ result = {cancel: true}; |
+ } |
+ |
getRelatedTabIds(details).then(tabIds => |
{ |
logRequest(tabIds, urlString, type, docDomain, |
thirdParty, sitekey, specificOnly, 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; |