Left: | ||
Right: |
OLD | NEW |
---|---|
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, |
Sebastian Noack
2017/04/29 23:07:59
It seems the newly imported function (i.e. getDeco
Jon Sonesen
2017/05/04 10:26:05
Done.
| |
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 = null; |
55 return true; | 56 let sitekey = null; |
56 | 57 |
58 let specificOnly = false; | |
59 let thirdParty = false; | |
57 let urlString = stringifyURL(url); | 60 let urlString = stringifyURL(url); |
58 let docDomain = extractHostFromFrame(frame); | |
59 let thirdParty = isThirdParty(url, docDomain); | |
60 let sitekey = getKey(page, frame); | |
61 | 61 |
62 let specificOnly = !!checkWhitelisted( | 62 if (frame && page) |
63 page, frame, RegExpFilter.typeMap.GENERICBLOCK | 63 { |
64 if (checkWhitelisted(page, frame)) | |
65 return true; | |
Sebastian Noack
2017/04/29 23:08:00
Nit: I'd always add a blank line when returning be
Jon Sonesen
2017/05/04 10:26:06
Done.
| |
66 docDomain = extractHostFromFrame(frame); | |
67 sitekey = getKey(page, frame); | |
68 isThirdParty(url, docDomain); | |
Sebastian Noack
2017/04/29 23:07:59
As this code stands, this call is redundant. Did y
Jon Sonesen
2017/05/04 10:26:05
Yeah that's what happened there.
Thanks.
Done.
| |
69 specificOnly = !!checkWhitelisted( | |
70 page, frame, RegExpFilter.typeMap.GENERICBLOCK | |
64 ); | 71 ); |
72 } | |
73 | |
74 | |
65 | 75 |
66 let filter = defaultMatcher.matchesAny( | 76 let filter = defaultMatcher.matchesAny( |
67 urlString, RegExpFilter.typeMap[type], | 77 urlString, RegExpFilter.typeMap[type], |
68 docDomain, thirdParty, sitekey, specificOnly | 78 docDomain, thirdParty, sitekey, specificOnly |
69 ); | 79 ); |
70 | 80 |
71 setTimeout(onBeforeRequestAsync, 0, page, urlString, | 81 setTimeout(onBeforeRequestAsync, 0, page, urlString, |
72 type, docDomain, | 82 type, docDomain, |
73 thirdParty, sitekey, | 83 thirdParty, sitekey, |
74 specificOnly, filter); | 84 specificOnly, filter); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 if (msg.requestType in chrome.webRequest.ResourceType) | 172 if (msg.requestType in chrome.webRequest.ResourceType) |
163 return false; | 173 return false; |
164 | 174 |
165 return ext.webRequest.onBeforeRequest._dispatch( | 175 return ext.webRequest.onBeforeRequest._dispatch( |
166 new URL(msg.url), | 176 new URL(msg.url), |
167 msg.requestType, | 177 msg.requestType, |
168 sender.page, | 178 sender.page, |
169 sender.frame | 179 sender.frame |
170 ).includes(false); | 180 ).includes(false); |
171 }); | 181 }); |
OLD | NEW |