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-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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); | 20 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); |
21 const {RegExpFilter, WhitelistFilter} = | 21 const {RegExpFilter, WhitelistFilter} = |
22 require("../adblockpluscore/lib/filterClasses"); | 22 require("../adblockpluscore/lib/filterClasses"); |
23 const {extractHostFromFrame, isThirdParty} = require("./url"); | 23 const {isThirdParty} = require("../adblockpluscore/lib/domain"); |
24 const {extractHostFromFrame} = require("./url"); | |
24 const {checkWhitelisted} = require("./whitelisting"); | 25 const {checkWhitelisted} = require("./whitelisting"); |
25 const {filterNotifier} = require("filterNotifier"); | 26 const {filterNotifier} = require("filterNotifier"); |
26 const {logRequest} = require("./hitLogger"); | 27 const {logRequest} = require("./hitLogger"); |
27 | 28 |
28 const {typeMap} = RegExpFilter; | 29 const {typeMap} = RegExpFilter; |
29 | 30 |
30 browser.webRequest.onHeadersReceived.addListener(details => | 31 browser.webRequest.onHeadersReceived.addListener(details => |
31 { | 32 { |
32 let url = new URL(details.url); | 33 let url = new URL(details.url); |
33 let parentFrame = ext.getFrame(details.tabId, details.parentFrameId); | 34 let parentFrame = ext.getFrame(details.tabId, details.parentFrameId); |
(...skipping 17 matching lines...) Expand all Loading... | |
51 let specificOnly = !!checkWhitelisted(page, frame, null, | 52 let specificOnly = !!checkWhitelisted(page, frame, null, |
52 typeMap.GENERICBLOCK); | 53 typeMap.GENERICBLOCK); |
53 if (specificOnly && !(cspMatch instanceof WhitelistFilter)) | 54 if (specificOnly && !(cspMatch instanceof WhitelistFilter)) |
54 { | 55 { |
55 cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname, | 56 cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname, |
56 thirdParty, null, specificOnly); | 57 thirdParty, null, specificOnly); |
57 if (!cspMatch) | 58 if (!cspMatch) |
58 return; | 59 return; |
59 } | 60 } |
60 | 61 |
61 logRequest([details.tabId], { | 62 if (cspMatch instanceof WhitelistFilter) |
Sebastian Noack
2019/01/30 19:54:25
Why not calling search() with "all" instead?
Or i
Manish Jethani
2019/01/31 01:04:14
That would look for all blocking and whitelist fil
Sebastian Noack
2019/01/31 01:12:24
I don't think that the whitelisted scenario is one
| |
62 url: details.url, type: "CSP", docDomain: hostname, | 63 { |
63 thirdParty, specificOnly | 64 logRequest([details.tabId], { |
64 }, cspMatch); | 65 url: details.url, type: "CSP", docDomain: hostname, |
65 filterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); | 66 thirdParty, specificOnly |
67 }, cspMatch); | |
68 filterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); | |
69 return; | |
70 } | |
66 | 71 |
67 if (cspMatch instanceof WhitelistFilter) | 72 let {blocking} = defaultMatcher.search(details.url, typeMap.CSP, hostname, |
68 return; | 73 thirdParty, null, specificOnly, |
74 "blocking"); | |
75 for (cspMatch of blocking) | |
76 { | |
77 logRequest([details.tabId], { | |
78 url: details.url, type: "CSP", docDomain: hostname, | |
79 thirdParty, specificOnly | |
80 }, cspMatch); | |
81 filterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); | |
69 | 82 |
70 details.responseHeaders.push({ | 83 details.responseHeaders.push({ |
71 name: "Content-Security-Policy", | 84 name: "Content-Security-Policy", |
72 value: cspMatch.csp | 85 value: cspMatch.csp |
73 }); | 86 }); |
87 } | |
74 | 88 |
75 return {responseHeaders: details.responseHeaders}; | 89 return {responseHeaders: details.responseHeaders}; |
76 } | 90 } |
77 }, { | 91 }, { |
78 urls: ["http://*/*", "https://*/*"], | 92 urls: ["http://*/*", "https://*/*"], |
79 types: ["main_frame", "sub_frame"] | 93 types: ["main_frame", "sub_frame"] |
80 }, ["blocking", "responseHeaders"]); | 94 }, ["blocking", "responseHeaders"]); |
OLD | NEW |