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

Side by Side Diff: lib/requestBlocker.js

Issue 29418679: Issue 5042 - Adds handling for requests which are not associated with browser tab (Closed)
Patch Set: Created April 20, 2017, 9:43 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/devtools.js ('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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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} = require("filterClasses"); 22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses");
23 const {Subscription} = require("subscriptionClasses"); 23 const {Subscription} = require("subscriptionClasses");
24 const {defaultMatcher} = require("matcher"); 24 const {defaultMatcher} = require("matcher");
25 const {FilterNotifier} = require("filterNotifier"); 25 const {FilterNotifier} = require("filterNotifier");
26 const {Prefs} = require("prefs"); 26 const {Prefs} = require("prefs");
27 const {checkWhitelisted, getKey} = require("whitelisting"); 27 const {checkWhitelisted, getKey} = require("whitelisting");
28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); 28 const {stringifyURL, getDecodedHostname,
29 extractHostFromFrame, isThirdParty} = require("url");
29 const {port} = require("messaging"); 30 const {port} = require("messaging");
30 const devtools = require("devtools"); 31 const devtools = require("devtools");
31 32
32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 33 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
33 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 34 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
34 35
35 function onBeforeRequestAsync(page, url, type, docDomain, 36 function onBeforeRequestAsync(page, url, type, docDomain,
36 thirdParty, sitekey, 37 thirdParty, sitekey,
37 specificOnly, filter) 38 specificOnly, filter)
38 { 39 {
39 if (filter) 40 if (filter)
40 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); 41 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page);
41 42
42 if (devtools) 43 if (devtools)
43 { 44 {
44 devtools.logRequest( 45 devtools.logRequest(
45 page, url, type, docDomain, 46 page, url, type, docDomain,
46 thirdParty, sitekey, 47 thirdParty, sitekey,
47 specificOnly, filter 48 specificOnly, filter
48 ); 49 );
49 } 50 }
50 } 51 }
51 52
52 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => 53 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) =>
53 { 54 {
54 if (checkWhitelisted(page, frame)) 55 let docDomain = getDecodedHostname(url);
Sebastian Noack 2017/04/21 08:39:53 Is there a reason you derive the parent document's
Jon Sonesen 2017/04/24 08:40:56 I see, I misunderstood what I was doing here. I ju
55 return true; 56 let sitekey = null;
57 if (frame && page)
58 {
59 if (checkWhitelisted(page, frame))
60 return true;
61 docDomain = extractHostFromFrame(frame);
62 sitekey = getKey(page, frame);
63 }
56 64
57 let urlString = stringifyURL(url); 65 let urlString = stringifyURL(url);
58 let docDomain = extractHostFromFrame(frame);
59 let thirdParty = isThirdParty(url, docDomain); 66 let thirdParty = isThirdParty(url, docDomain);
60 let sitekey = getKey(page, frame);
61 67
62 let specificOnly = !!checkWhitelisted( 68 let specificOnly = !!checkWhitelisted(
63 page, frame, RegExpFilter.typeMap.GENERICBLOCK 69 page, frame, RegExpFilter.typeMap.GENERICBLOCK
64 ); 70 );
65 71
66 let filter = defaultMatcher.matchesAny( 72 let filter = defaultMatcher.matchesAny(
67 urlString, RegExpFilter.typeMap[type], 73 urlString, RegExpFilter.typeMap[type],
68 docDomain, thirdParty, sitekey, specificOnly 74 docDomain, thirdParty, sitekey, specificOnly
69 ); 75 );
70 76
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (msg.requestType in chrome.webRequest.ResourceType) 168 if (msg.requestType in chrome.webRequest.ResourceType)
163 return false; 169 return false;
164 170
165 return ext.webRequest.onBeforeRequest._dispatch( 171 return ext.webRequest.onBeforeRequest._dispatch(
166 new URL(msg.url), 172 new URL(msg.url),
167 msg.requestType, 173 msg.requestType,
168 sender.page, 174 sender.page,
169 sender.frame 175 sender.frame
170 ).includes(false); 176 ).includes(false);
171 }); 177 });
OLDNEW
« lib/devtools.js ('K') | « lib/devtools.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld