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

Side by Side Diff: lib/requestBlocker.js

Issue 29760707: Issue 6622 - Implement $rewrite filter option (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created April 24, 2018, 8:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« dependencies ('K') | « lib/devtools.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (!(browser.webRequest.ResourceType)) 63 if (!(browser.webRequest.ResourceType))
64 return; 64 return;
65 65
66 for (let type in browser.webRequest.ResourceType) 66 for (let type in browser.webRequest.ResourceType)
67 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; 67 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER";
68 68
69 // WEBRTC gets addressed through a workaround, even if the webRequest API is 69 // WEBRTC gets addressed through a workaround, even if the webRequest API is
70 // lacking support to block this kind of a request. 70 // lacking support to block this kind of a request.
71 yield "WEBRTC"; 71 yield "WEBRTC";
72 72
73 // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types. 73 // POPUP, CSP, REWRITE and ELEMHIDE filters aren't mapped to resource types.
74 yield "POPUP"; 74 yield "POPUP";
75 yield "ELEMHIDE"; 75 yield "ELEMHIDE";
76 yield "CSP"; 76 yield "CSP";
77 yield "REWRITE";
77 }()); 78 }());
78 79
79 function getDocumentInfo(page, frame, originUrl) 80 function getDocumentInfo(page, frame, originUrl)
80 { 81 {
81 return [ 82 return [
82 extractHostFromFrame(frame, originUrl), 83 extractHostFromFrame(frame, originUrl),
83 getKey(page, frame, originUrl), 84 getKey(page, frame, originUrl),
84 !!checkWhitelisted(page, frame, originUrl, 85 !!checkWhitelisted(page, frame, originUrl,
85 RegExpFilter.typeMap.GENERICBLOCK) 86 RegExpFilter.typeMap.GENERICBLOCK)
86 ]; 87 ];
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 188
188 if (checkWhitelisted(page, frame, originUrl)) 189 if (checkWhitelisted(page, frame, originUrl))
189 return; 190 return;
190 191
191 let type = resourceTypes.get(details.type) || "OTHER"; 192 let type = resourceTypes.get(details.type) || "OTHER";
192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 193 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
193 originUrl); 194 originUrl);
194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, 195 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain,
195 sitekey, specificOnly); 196 sitekey, specificOnly);
196 197
198 if (filter instanceof RegExpFilter && filter.rewrite)
199 {
200 let matches = filter.regexp.exec(urlString);
201 if (matches)
202 {
203 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.
204 if (rewritten != urlString)
205 {
206 getRelatedTabIds(details).then(tabIds =>
207 {
208 logRequest(tabIds, urlString, "REWRITE", docDomain,
209 thirdParty, sitekey, specificOnly, filter);
210 });
211
212 return {redirectUrl: rewritten};
213 }
214 }
215 // we couldn't do the rewrite, so just let it through.
216 return;
217 }
218
197 getRelatedTabIds(details).then(tabIds => 219 getRelatedTabIds(details).then(tabIds =>
198 { 220 {
199 logRequest(tabIds, urlString, type, docDomain, 221 logRequest(tabIds, urlString, type, docDomain,
200 thirdParty, sitekey, specificOnly, filter); 222 thirdParty, sitekey, specificOnly, filter);
201 }); 223 });
202 224
203 if (filter instanceof BlockingFilter) 225 if (filter instanceof BlockingFilter)
204 return {cancel: true}; 226 return {cancel: true};
205 }, {urls: ["<all_urls>"]}, ["blocking"]); 227 }, {urls: ["<all_urls>"]}, ["blocking"]);
206 228
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 331 }
310 332
311 FilterNotifier.on("subscription.added", onFilterChange); 333 FilterNotifier.on("subscription.added", onFilterChange);
312 FilterNotifier.on("subscription.removed", onFilterChange); 334 FilterNotifier.on("subscription.removed", onFilterChange);
313 FilterNotifier.on("subscription.updated", onFilterChange); 335 FilterNotifier.on("subscription.updated", onFilterChange);
314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 336 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
315 FilterNotifier.on("filter.added", onFilterChange); 337 FilterNotifier.on("filter.added", onFilterChange);
316 FilterNotifier.on("filter.removed", onFilterChange); 338 FilterNotifier.on("filter.removed", onFilterChange);
317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 339 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
318 FilterNotifier.on("load", onFilterChange); 340 FilterNotifier.on("load", onFilterChange);
OLDNEW
« dependencies ('K') | « lib/devtools.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld