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: Fix a linting error. Created May 4, 2018, 6:27 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 | « 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,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 [
@@ -118,25 +118,25 @@
// an origin (proto + host).
else
return Promise.resolve([]);
return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id));
}
function logRequest(tabIds, url, type, docDomain, thirdParty,
- sitekey, specificOnly, filter)
+ sitekey, specificOnly, filter, rewrittenTo)
{
if (filter)
FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds);
devtools.logRequest(
tabIds, url, type, docDomain,
thirdParty, sitekey,
- specificOnly, filter
+ specificOnly, filter, rewrittenTo
);
}
browser.webRequest.onBeforeRequest.addListener(details =>
{
// Never block top-level documents.
if (details.type == "main_frame")
return;
@@ -189,24 +189,42 @@
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;
+ let rewrittenTo;
+
+ if (filter instanceof BlockingFilter)
+ {
+ if (filter.rewrite)
+ {
+ let rewritten = filter.rewriteUrl(urlString);
Manish Jethani 2018/05/04 20:49:47 We don't need rewritten, we can just assign rewrit
hub 2018/05/04 20:51:49 already done
+ if (rewritten == urlString)
Manish Jethani 2018/05/04 20:49:47 Nit: since the if block spans multiple lines, we s
hub 2018/05/04 20:51:49 Acknowledged.
+ // we couldn't do the rewrite, so just let it through.
Sebastian Noack 2018/05/04 19:46:36 The request should still be logged. Just for clar
Manish Jethani 2018/05/04 20:06:12 Agreed.
Manish Jethani 2018/05/04 20:27:24 To be clear, I'm OK with the check here even thoug
hub 2018/05/04 20:48:08 Ok, I'll log.
hub 2018/05/04 20:48:08 Last time I checked, Chrome (66) did that too.
hub 2018/05/04 20:48:08 Done this.
+ return;
+
+ rewrittenTo = rewritten;
+ result = {redirectUrl: rewritten};
+ }
+ else
+ result = {cancel: true};
+ }
+
getRelatedTabIds(details).then(tabIds =>
{
logRequest(tabIds, urlString, type, docDomain,
- thirdParty, sitekey, specificOnly, filter);
+ thirdParty, sitekey, specificOnly, filter, rewrittenTo);
});
- 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 | « lib/devtools.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld