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

Side by Side Diff: lib/requestBlocker.js

Issue 29998582: Issue [TBD] - Update adblockpluscore dependency to [TBD] Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Feb. 5, 2019, 4:07 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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 {isThirdParty} = require("../adblockpluscore/lib/domain");
28 const {Prefs} = require("./prefs"); 27 const {Prefs} = require("./prefs");
29 const {checkWhitelisted, getKey} = require("./whitelisting"); 28 const {checkWhitelisted, getKey} = require("./whitelisting");
30 const {extractHostFromFrame} = require("./url"); 29 const {extractHostFromFrame} = require("./url");
31 const {port} = require("./messaging"); 30 const {port} = require("./messaging");
32 const {logRequest: hitLoggerLogRequest} = require("./hitLogger"); 31 const {logRequest: hitLoggerLogRequest} = require("./hitLogger");
33 32
34 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; 33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol;
35 34
36 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
37 if (!browser.webRequest.ResourceType || 36 if (!browser.webRequest.ResourceType ||
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 function getDocumentInfo(page, frame, originUrl) 80 function getDocumentInfo(page, frame, originUrl)
82 { 81 {
83 return [ 82 return [
84 extractHostFromFrame(frame, originUrl), 83 extractHostFromFrame(frame, originUrl),
85 getKey(page, frame, originUrl), 84 getKey(page, frame, originUrl),
86 !!checkWhitelisted(page, frame, originUrl, 85 !!checkWhitelisted(page, frame, originUrl,
87 RegExpFilter.typeMap.GENERICBLOCK) 86 RegExpFilter.typeMap.GENERICBLOCK)
88 ]; 87 ];
89 } 88 }
90 89
91 function matchRequest(url, type, docDomain, sitekey, specificOnly) 90 function matchRequest(url, type, docDomain, sitekey, specificOnly)
Sebastian Noack 2019/02/05 04:41:43 With the third-party check removed, keeping this h
Manish Jethani 2019/02/05 05:16:20 Done.
92 { 91 {
93 let thirdParty = isThirdParty(url, docDomain); 92 return defaultMatcher.matchesAny(url, RegExpFilter.typeMap[type],
94 let filter = defaultMatcher.matchesAny(url.href, RegExpFilter.typeMap[type], 93 docDomain, sitekey, specificOnly);
95 docDomain, thirdParty,
96 sitekey, specificOnly);
97 return [filter, thirdParty];
98 } 94 }
99 95
100 function getRelatedTabIds(details) 96 function getRelatedTabIds(details)
101 { 97 {
102 // This is the common case, the request is associated with a single tab. 98 // This is the common case, the request is associated with a single tab.
103 // If tabId is -1, its not (e.g. the request was sent by 99 // If tabId is -1, its not (e.g. the request was sent by
104 // a Service/Shared Worker) and we have to identify the related tabs. 100 // a Service/Shared Worker) and we have to identify the related tabs.
105 if (details.tabId != -1) 101 if (details.tabId != -1)
106 return Promise.resolve([details.tabId]); 102 return Promise.resolve([details.tabId]);
107 103
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // this can also indicate a request sent by a Shared/Service Worker). 177 // this can also indicate a request sent by a Shared/Service Worker).
182 if (!frame && !originUrl) 178 if (!frame && !originUrl)
183 return; 179 return;
184 180
185 if (checkWhitelisted(page, frame, originUrl)) 181 if (checkWhitelisted(page, frame, originUrl))
186 return; 182 return;
187 183
188 let type = resourceTypes.get(details.type) || "OTHER"; 184 let type = resourceTypes.get(details.type) || "OTHER";
189 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 185 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
190 originUrl); 186 originUrl);
191 let [filter, thirdParty] = matchRequest(url, type, docDomain, 187 let filter = matchRequest(url, type, docDomain, sitekey, specificOnly);
192 sitekey, specificOnly);
193 188
194 let result; 189 let result;
195 let rewrittenUrl; 190 let rewrittenUrl;
196 191
197 if (filter instanceof BlockingFilter) 192 if (filter instanceof BlockingFilter)
198 { 193 {
199 if (typeof filter.rewrite == "string") 194 if (typeof filter.rewrite == "string")
200 { 195 {
201 rewrittenUrl = filter.rewriteUrl(details.url); 196 rewrittenUrl = filter.rewriteUrl(details.url);
202 // If no rewrite happened (error, different origin), we'll 197 // If no rewrite happened (error, different origin), we'll
203 // return undefined in order to avoid an "infinite" loop. 198 // return undefined in order to avoid an "infinite" loop.
204 if (rewrittenUrl != details.url) 199 if (rewrittenUrl != details.url)
205 result = {redirectUrl: rewrittenUrl}; 200 result = {redirectUrl: rewrittenUrl};
206 } 201 }
207 else 202 else
208 result = {cancel: true}; 203 result = {cancel: true};
209 } 204 }
210 205
211 getRelatedTabIds(details).then(tabIds => 206 getRelatedTabIds(details).then(tabIds =>
212 { 207 {
213 logRequest( 208 logRequest(
214 tabIds, 209 tabIds,
215 { 210 {
216 url: details.url, type, docDomain, thirdParty, 211 url: details.url, type, docDomain,
217 sitekey, specificOnly, rewrittenUrl 212 sitekey, specificOnly, rewrittenUrl
218 }, 213 },
219 filter 214 filter
220 ); 215 );
221 }); 216 });
222 217
223 return result; 218 return result;
224 }, {urls: ["<all_urls>"]}, ["blocking"]); 219 }, {urls: ["<all_urls>"]}, ["blocking"]);
225 220
226 port.on("filters.collapse", (message, sender) => 221 port.on("filters.collapse", (message, sender) =>
227 { 222 {
228 let {page, frame} = sender; 223 let {page, frame} = sender;
229 224
230 if (checkWhitelisted(page, frame)) 225 if (checkWhitelisted(page, frame))
231 return false; 226 return false;
232 227
233 let blocked = false; 228 let blocked = false;
234 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); 229 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
235 230
236 for (let url of message.urls) 231 for (let url of message.urls)
237 { 232 {
238 let [filter] = matchRequest(new URL(url, message.baseURL), 233 let filter = matchRequest(new URL(url, message.baseURL),
239 message.mediatype, docDomain, 234 message.mediatype, docDomain,
240 sitekey, specificOnly); 235 sitekey, specificOnly);
241 236
242 if (filter instanceof BlockingFilter) 237 if (filter instanceof BlockingFilter)
243 { 238 {
244 if (filter.collapse != null) 239 if (filter.collapse != null)
245 return filter.collapse; 240 return filter.collapse;
246 blocked = true; 241 blocked = true;
247 } 242 }
248 } 243 }
249 244
250 return blocked && Prefs.hidePlaceholders; 245 return blocked && Prefs.hidePlaceholders;
251 }); 246 });
252 247
253 port.on("request.blockedByRTCWrapper", (msg, sender) => 248 port.on("request.blockedByRTCWrapper", (msg, sender) =>
254 { 249 {
255 let {page, frame} = sender; 250 let {page, frame} = sender;
256 251
257 if (checkWhitelisted(page, frame)) 252 if (checkWhitelisted(page, frame))
258 return false; 253 return false;
259 254
260 let {url} = msg; 255 let {url} = msg;
261 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); 256 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
262 let [filter, thirdParty] = matchRequest(new URL(url), "WEBRTC", docDomain, 257 let filter = matchRequest(new URL(url), "WEBRTC", docDomain, sitekey,
263 sitekey, specificOnly); 258 specificOnly);
264 logRequest( 259 logRequest(
265 [sender.page.id], 260 [sender.page.id],
266 {url, type: "WEBRTC", docDomain, thirdParty, sitekey, specificOnly}, 261 {url, type: "WEBRTC", docDomain, sitekey, specificOnly},
267 filter 262 filter
268 ); 263 );
269 264
270 return filter instanceof BlockingFilter; 265 return filter instanceof BlockingFilter;
271 }); 266 });
272 267
273 let ignoreFilterNotifications = false; 268 let ignoreFilterNotifications = false;
274 let handlerBehaviorChangedQuota = 269 let handlerBehaviorChangedQuota =
275 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; 270 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
276 271
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 325 }
331 326
332 filterNotifier.on("subscription.added", onFilterChange); 327 filterNotifier.on("subscription.added", onFilterChange);
333 filterNotifier.on("subscription.removed", arg => onFilterChange(arg, false)); 328 filterNotifier.on("subscription.removed", arg => onFilterChange(arg, false));
334 filterNotifier.on("subscription.updated", onFilterChange); 329 filterNotifier.on("subscription.updated", onFilterChange);
335 filterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 330 filterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
336 filterNotifier.on("filter.added", onFilterChange); 331 filterNotifier.on("filter.added", onFilterChange);
337 filterNotifier.on("filter.removed", onFilterChange); 332 filterNotifier.on("filter.removed", onFilterChange);
338 filterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 333 filterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
339 filterNotifier.on("load", onFilterChange); 334 filterNotifier.on("load", onFilterChange);
OLDNEW
« lib/csp.js ('K') | « lib/popupBlocker.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld