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: Remove uneeded check Created May 3, 2018, 6:42 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 | « 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 // These filter types 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 let result;
199
200 if (filter instanceof BlockingFilter)
201 {
202 if (filter.rewrite)
203 {
204 let rewritten = filter.rewriteUrl(urlString);
205 if (rewritten == urlString)
Manish Jethani 2018/05/04 15:37:47 Do we still need this check? If the filter matched
hub 2018/05/04 18:27:58 definitely. a redirectUrl will cause onBeforeReque
206 // we couldn't do the rewrite, so just let it through.
207 return;
208
209 type = "REWRITE";
Manish Jethani 2018/05/04 15:37:47 Also I'm wondering if it makes sense to set the ty
Sebastian Noack 2018/05/04 15:46:49 I already thought the same, and tend to agree to n
hub 2018/05/04 18:27:58 I have a solution to indicate the rewrite in the d
210 result = {redirectUrl: rewritten};
211 }
212 else
213 result = {cancel: true};
214 }
215
197 getRelatedTabIds(details).then(tabIds => 216 getRelatedTabIds(details).then(tabIds =>
198 { 217 {
199 logRequest(tabIds, urlString, type, docDomain, 218 logRequest(tabIds, urlString, type, docDomain,
200 thirdParty, sitekey, specificOnly, filter); 219 thirdParty, sitekey, specificOnly, filter);
201 }); 220 });
202 221
203 if (filter instanceof BlockingFilter) 222 return result;
204 return {cancel: true};
205 }, {urls: ["<all_urls>"]}, ["blocking"]); 223 }, {urls: ["<all_urls>"]}, ["blocking"]);
206 224
207 port.on("filters.collapse", (message, sender) => 225 port.on("filters.collapse", (message, sender) =>
208 { 226 {
209 let {page, frame} = sender; 227 let {page, frame} = sender;
210 228
211 if (checkWhitelisted(page, frame)) 229 if (checkWhitelisted(page, frame))
212 return false; 230 return false;
213 231
214 let blocked = false; 232 let blocked = false;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 327 }
310 328
311 FilterNotifier.on("subscription.added", onFilterChange); 329 FilterNotifier.on("subscription.added", onFilterChange);
312 FilterNotifier.on("subscription.removed", onFilterChange); 330 FilterNotifier.on("subscription.removed", onFilterChange);
313 FilterNotifier.on("subscription.updated", onFilterChange); 331 FilterNotifier.on("subscription.updated", onFilterChange);
314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 332 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
315 FilterNotifier.on("filter.added", onFilterChange); 333 FilterNotifier.on("filter.added", onFilterChange);
316 FilterNotifier.on("filter.removed", onFilterChange); 334 FilterNotifier.on("filter.removed", onFilterChange);
317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 335 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
318 FilterNotifier.on("load", onFilterChange); 336 FilterNotifier.on("load", onFilterChange);
OLDNEW
« 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