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: Rebased Created May 10, 2018, 2:35 p.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 | « dependencies ('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,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.
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 rewritten;
+
+ if (filter instanceof BlockingFilter)
+ {
+ if (filter.rewrite)
+ {
+ rewritten = filter.rewriteUrl(details.url);
+ // If no rewrite happened (error, diff origin), we'll
+ // return undefined in order to avoid an "infinite" loop.
+ if (rewritten != details.url)
+ result = {redirectUrl: rewritten};
+ }
+ 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: rewritten
Sebastian Noack 2018/05/10 15:09:52 Nit: How about just calling the variable rewritteT
hub 2018/05/10 16:08:48 Done.
+ },
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;
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld