Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/requestBlocker.js

Issue 29760707: Issue 6622 - Implement $rewrite filter option (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Refactor the notification code. Created April 27, 2018, 12:33 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/devtools.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
Sebastian Noack 2018/05/02 15:04:59 Nit: As this list growth, listing those filter opt
hub 2018/05/03 01:18:02 Done.
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,22 +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);
- getRelatedTabIds(details).then(tabIds =>
+ let log = logType => getRelatedTabIds(details).then(tabIds =>
{
- logRequest(tabIds, urlString, type, docDomain,
+ logRequest(tabIds, urlString, logType, docDomain,
thirdParty, sitekey, specificOnly, filter);
});
+ if (filter instanceof BlockingFilter && filter.rewrite)
Manish Jethani 2018/04/30 20:24:58 I think maybe rewrite should be a separate module
hub 2018/05/01 18:32:36 This is a blocking filter with the rewrite option.
Sebastian Noack 2018/05/02 15:04:59 I agree that having the logic here is fine. Otherw
Manish Jethani 2018/05/02 16:13:45 Suppose there are two filters: /([^/]+\/)?bar$/
Sebastian Noack 2018/05/02 16:40:09 If we want to give precedence to blocking filters
Manish Jethani 2018/05/02 17:45:50 Yeah, I think that's fair. I think defaultMatcher
hub 2018/05/03 01:18:02 I'm trying to actually keep it simple here.
Manish Jethani 2018/05/03 02:51:16 I'm OK with letting the filters with a rewrite opt
Sebastian Noack 2018/05/03 15:55:47 I don't quite get what we need another argument fo
Manish Jethani 2018/05/04 10:01:59 If the typeMask doesn't contain REWRITE it'll stil
Sebastian Noack 2018/05/04 15:17:16 Gotya. In fact REWRITE isn't even a flag in the ty
Manish Jethani 2018/05/04 15:37:47 Makes sense.
+ {
+ let rewritten = filter.doRewrite(urlString);
+ if (rewritten && rewritten != urlString)
+ {
+ log("REWRITE");
+
+ return {redirectUrl: rewritten};
+ }
+ // we couldn't do the rewrite, so just let it through.
+ return;
+ }
+
+ log(type);
Sebastian Noack 2018/05/02 15:04:59 I'd rather move the logic around so that we don't
hub 2018/05/03 01:18:03 Done in a different way.
+
if (filter instanceof BlockingFilter)
return {cancel: true};
}, {urls: ["<all_urls>"]}, ["blocking"]);
port.on("filters.collapse", (message, sender) =>
{
let {page, frame} = sender;
« no previous file with comments | « lib/devtools.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld