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: comment fixes Created May 11, 2018, 3:58 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
« no previous file with comments | « dependencies ('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 // These filter types aren't mapped to resource types.
kzar 2018/05/15 14:30:29 Nit: Mind removing this unrelated change?
hub 2018/05/15 16:31:26 Done.
74 yield "POPUP"; 74 yield "POPUP";
75 yield "ELEMHIDE"; 75 yield "ELEMHIDE";
76 yield "CSP"; 76 yield "CSP";
77 }()); 77 }());
78 78
79 function getDocumentInfo(page, frame, originUrl) 79 function getDocumentInfo(page, frame, originUrl)
80 { 80 {
81 return [ 81 return [
82 extractHostFromFrame(frame, originUrl), 82 extractHostFromFrame(frame, originUrl),
83 getKey(page, frame, originUrl), 83 getKey(page, frame, originUrl),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 if (checkWhitelisted(page, frame, originUrl)) 179 if (checkWhitelisted(page, frame, originUrl))
180 return; 180 return;
181 181
182 let type = resourceTypes.get(details.type) || "OTHER"; 182 let type = resourceTypes.get(details.type) || "OTHER";
183 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 183 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
184 originUrl); 184 originUrl);
185 let [filter, thirdParty] = matchRequest(url, type, docDomain, 185 let [filter, thirdParty] = matchRequest(url, type, docDomain,
186 sitekey, specificOnly); 186 sitekey, specificOnly);
187 187
188 let result;
189 let rewrittenTo;
kzar 2018/05/15 14:30:29 Nit: I think rewrittenUrl would be a nicer name.
Manish Jethani 2018/05/15 14:44:23 I'll second that.
Sebastian Noack 2018/05/15 14:44:36 Note that the varialbe name here is consistent wit
hub 2018/05/15 16:31:26 I'll do that.
190
191 if (filter instanceof BlockingFilter)
192 {
193 if (filter.rewrite)
194 {
195 rewrittenTo = filter.rewriteUrl(details.url);
196 // If no rewrite happened (error, different origin), we'll
197 // return undefined in order to avoid an "infinite" loop.
198 if (rewrittenTo != details.url)
199 result = {redirectUrl: rewrittenTo};
200 }
201 else
202 result = {cancel: true};
203 }
204
188 getRelatedTabIds(details).then(tabIds => 205 getRelatedTabIds(details).then(tabIds =>
189 { 206 {
190 logRequest( 207 logRequest(
191 tabIds, 208 tabIds,
192 {url: details.url, type, docDomain, thirdParty, sitekey, specificOnly}, 209 {
210 url: details.url, type, docDomain, thirdParty,
211 sitekey, specificOnly, rewrittenTo
212 },
193 filter 213 filter
194 ); 214 );
195 }); 215 });
196 216
197 if (filter instanceof BlockingFilter) 217 return result;
198 return {cancel: true};
199 }, {urls: ["<all_urls>"]}, ["blocking"]); 218 }, {urls: ["<all_urls>"]}, ["blocking"]);
200 219
201 port.on("filters.collapse", (message, sender) => 220 port.on("filters.collapse", (message, sender) =>
202 { 221 {
203 let {page, frame} = sender; 222 let {page, frame} = sender;
204 223
205 if (checkWhitelisted(page, frame)) 224 if (checkWhitelisted(page, frame))
206 return false; 225 return false;
207 226
208 let blocked = false; 227 let blocked = false;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 324 }
306 325
307 FilterNotifier.on("subscription.added", onFilterChange); 326 FilterNotifier.on("subscription.added", onFilterChange);
308 FilterNotifier.on("subscription.removed", onFilterChange); 327 FilterNotifier.on("subscription.removed", onFilterChange);
309 FilterNotifier.on("subscription.updated", onFilterChange); 328 FilterNotifier.on("subscription.updated", onFilterChange);
310 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 329 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
311 FilterNotifier.on("filter.added", onFilterChange); 330 FilterNotifier.on("filter.added", onFilterChange);
312 FilterNotifier.on("filter.removed", onFilterChange); 331 FilterNotifier.on("filter.removed", onFilterChange);
313 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 332 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
314 FilterNotifier.on("load", onFilterChange); 333 FilterNotifier.on("load", onFilterChange);
OLDNEW
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld