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

Side by Side Diff: lib/requestBlocker.js

Issue 29772555: Issue 6647 - Stop converting domains from punycode to unicode (Closed)
Patch Set: Created May 6, 2018, 2: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
« lib/options.js ('K') | « lib/punycode.js ('k') | lib/url.js » ('j') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module requestBlocker */ 18 /** @module requestBlocker */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {Filter, RegExpFilter, BlockingFilter} = 22 const {Filter, RegExpFilter, BlockingFilter} =
23 require("../adblockpluscore/lib/filterClasses"); 23 require("../adblockpluscore/lib/filterClasses");
24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses"); 24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses");
25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); 25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
27 const {Prefs} = require("./prefs"); 27 const {Prefs} = require("./prefs");
28 const {checkWhitelisted, getKey} = require("./whitelisting"); 28 const {checkWhitelisted, getKey} = require("./whitelisting");
29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url"); 29 const {extractHostFromFrame, isThirdParty} = require("./url");
30 const {port} = require("./messaging"); 30 const {port} = require("./messaging");
31 const devtools = require("./devtools"); 31 const devtools = require("./devtools");
32 32
33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; 33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol;
34 34
35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
36 if (!browser.webRequest.ResourceType || 36 if (!browser.webRequest.ResourceType ||
37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) 37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
38 { 38 {
39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return [ 81 return [
82 extractHostFromFrame(frame, originUrl), 82 extractHostFromFrame(frame, originUrl),
83 getKey(page, frame, originUrl), 83 getKey(page, frame, originUrl),
84 !!checkWhitelisted(page, frame, originUrl, 84 !!checkWhitelisted(page, frame, originUrl,
85 RegExpFilter.typeMap.GENERICBLOCK) 85 RegExpFilter.typeMap.GENERICBLOCK)
86 ]; 86 ];
87 } 87 }
88 88
89 function matchRequest(url, type, docDomain, sitekey, specificOnly) 89 function matchRequest(url, type, docDomain, sitekey, specificOnly)
90 { 90 {
91 let urlString = stringifyURL(url);
92 let thirdParty = isThirdParty(url, docDomain); 91 let thirdParty = isThirdParty(url, docDomain);
93 92 let filter = defaultMatcher.matchesAny(url.href, RegExpFilter.typeMap[type],
94 return [ 93 docDomain, thirdParty,
95 defaultMatcher.matchesAny(urlString, RegExpFilter.typeMap[type], 94 sitekey, specificOnly);
96 docDomain, thirdParty, sitekey, specificOnly), 95 return [filter, thirdParty];
97 urlString,
98 thirdParty
99 ];
100 } 96 }
101 97
102 function getRelatedTabIds(details) 98 function getRelatedTabIds(details)
103 { 99 {
104 // This is the common case, the request is associated with a single tab. 100 // This is the common case, the request is associated with a single tab.
105 // If tabId is -1, its not (e.g. the request was sent by 101 // If tabId is -1, its not (e.g. the request was sent by
106 // a Service/Shared Worker) and we have to identify the related tabs. 102 // a Service/Shared Worker) and we have to identify the related tabs.
107 if (details.tabId != -1) 103 if (details.tabId != -1)
108 return Promise.resolve([details.tabId]); 104 return Promise.resolve([details.tabId]);
109 105
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // this can also indicate a request sent by a Shared/Service Worker). 180 // this can also indicate a request sent by a Shared/Service Worker).
185 if (!frame && !originUrl) 181 if (!frame && !originUrl)
186 return; 182 return;
187 183
188 if (checkWhitelisted(page, frame, originUrl)) 184 if (checkWhitelisted(page, frame, originUrl))
189 return; 185 return;
190 186
191 let type = resourceTypes.get(details.type) || "OTHER"; 187 let type = resourceTypes.get(details.type) || "OTHER";
192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 188 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
193 originUrl); 189 originUrl);
194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, 190 let [filter, thirdParty] = matchRequest(url, type, docDomain,
195 sitekey, specificOnly); 191 sitekey, specificOnly);
196 192
197 getRelatedTabIds(details).then(tabIds => 193 getRelatedTabIds(details).then(tabIds =>
198 { 194 {
199 logRequest(tabIds, urlString, type, docDomain, 195 logRequest(tabIds, details.url, type, docDomain,
200 thirdParty, sitekey, specificOnly, filter); 196 thirdParty, sitekey, specificOnly, filter);
201 }); 197 });
202 198
203 if (filter instanceof BlockingFilter) 199 if (filter instanceof BlockingFilter)
204 return {cancel: true}; 200 return {cancel: true};
205 }, {urls: ["<all_urls>"]}, ["blocking"]); 201 }, {urls: ["<all_urls>"]}, ["blocking"]);
206 202
207 port.on("filters.collapse", (message, sender) => 203 port.on("filters.collapse", (message, sender) =>
208 { 204 {
209 let {page, frame} = sender; 205 let {page, frame} = sender;
(...skipping 22 matching lines...) Expand all
232 }); 228 });
233 229
234 port.on("request.blockedByRTCWrapper", (msg, sender) => 230 port.on("request.blockedByRTCWrapper", (msg, sender) =>
235 { 231 {
236 let {page, frame} = sender; 232 let {page, frame} = sender;
237 233
238 if (checkWhitelisted(page, frame)) 234 if (checkWhitelisted(page, frame))
239 return false; 235 return false;
240 236
241 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); 237 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
242 let [filter, url, thirdParty] = matchRequest(new URL(msg.url), 238 let [filter, thirdParty] = matchRequest(new URL(msg.url),
243 "WEBRTC", docDomain, 239 "WEBRTC", docDomain,
244 sitekey, specificOnly); 240 sitekey, specificOnly);
245 241
246 logRequest([sender.page.id], url, "WEBRTC", docDomain, 242 logRequest([sender.page.id], msg.url, "WEBRTC", docDomain,
247 thirdParty, sitekey, specificOnly, filter); 243 thirdParty, sitekey, specificOnly, filter);
248 244
249 return filter instanceof BlockingFilter; 245 return filter instanceof BlockingFilter;
250 }); 246 });
251 247
252 let ignoreFilterNotifications = false; 248 let ignoreFilterNotifications = false;
253 let handlerBehaviorChangedQuota = 249 let handlerBehaviorChangedQuota =
254 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; 250 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
255 251
256 function propagateHandlerBehaviorChange() 252 function propagateHandlerBehaviorChange()
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 305 }
310 306
311 FilterNotifier.on("subscription.added", onFilterChange); 307 FilterNotifier.on("subscription.added", onFilterChange);
312 FilterNotifier.on("subscription.removed", onFilterChange); 308 FilterNotifier.on("subscription.removed", onFilterChange);
313 FilterNotifier.on("subscription.updated", onFilterChange); 309 FilterNotifier.on("subscription.updated", onFilterChange);
314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 310 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
315 FilterNotifier.on("filter.added", onFilterChange); 311 FilterNotifier.on("filter.added", onFilterChange);
316 FilterNotifier.on("filter.removed", onFilterChange); 312 FilterNotifier.on("filter.removed", onFilterChange);
317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 313 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
318 FilterNotifier.on("load", onFilterChange); 314 FilterNotifier.on("load", onFilterChange);
OLDNEW
« lib/options.js ('K') | « lib/punycode.js ('k') | lib/url.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld