| 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. |
| + // POPUP, CSP, REWRITE and ELEMHIDE filters 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,16 +190,37 @@ |
| 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); |
| + if (filter instanceof RegExpFilter && filter.rewrite) |
| + { |
| + let matches = filter.regexp.exec(urlString); |
| + if (matches) |
| + { |
| + let rewritten = filter.rewrite.replace("%1", matches[0]); |
|
hub
2018/04/24 20:39:05
I actually wonder if we should move the rewrite pa
hub
2018/04/25 03:39:08
moved this to core in the end.
|
| + if (rewritten != urlString) |
| + { |
| + getRelatedTabIds(details).then(tabIds => |
| + { |
| + logRequest(tabIds, urlString, "REWRITE", docDomain, |
| + thirdParty, sitekey, specificOnly, filter); |
| + }); |
| + |
| + return {redirectUrl: rewritten}; |
| + } |
| + } |
| + // we couldn't do the rewrite, so just let it through. |
| + return; |
| + } |
| + |
| getRelatedTabIds(details).then(tabIds => |
| { |
| logRequest(tabIds, urlString, type, docDomain, |
| thirdParty, sitekey, specificOnly, filter); |
| }); |
| if (filter instanceof BlockingFilter) |
| return {cancel: true}; |