Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 const {checkWhitelisted} = require("whitelisting"); | 24 const {checkWhitelisted} = require("whitelisting"); |
25 const {FilterNotifier} = require("filterNotifier"); | 25 const {FilterNotifier} = require("filterNotifier"); |
26 const devtools = require("devtools"); | 26 const devtools = require("devtools"); |
27 | 27 |
28 const {typeMap} = RegExpFilter; | 28 const {typeMap} = RegExpFilter; |
29 | 29 |
30 browser.webRequest.onHeadersReceived.addListener(details => | 30 browser.webRequest.onHeadersReceived.addListener(details => |
31 { | 31 { |
32 let url = new URL(details.url); | 32 let url = new URL(details.url); |
33 let urlString = stringifyURL(url); | 33 let urlString = stringifyURL(url); |
34 let parentFrame = details.parentFrameId != -1 && | 34 let parentFrame = ext.getFrame(details.tabId, details.parentFrameId); |
Sebastian Noack
2018/03/19 22:25:12
Nit: ext.getFrame(details.tabId, -1) just returns
kzar
2018/03/20 09:02:31
Done.
| |
35 ext.getFrame(details.tabId, details.parentFrameId); | |
36 let hostname = extractHostFromFrame(parentFrame) || getDecodedHostname(url); | 35 let hostname = extractHostFromFrame(parentFrame) || getDecodedHostname(url); |
37 let thirdParty = isThirdParty(url, hostname); | 36 let thirdParty = isThirdParty(url, hostname); |
38 | 37 |
39 let cspMatch = defaultMatcher.matchesAny(urlString, typeMap.CSP, hostname, | 38 let cspMatch = defaultMatcher.matchesAny(urlString, typeMap.CSP, hostname, |
40 thirdParty, null, false); | 39 thirdParty, null, false); |
41 if (cspMatch) | 40 if (cspMatch) |
42 { | 41 { |
43 let page = new ext.Page({id: details.tabId, url: details.url}); | 42 let page = new ext.Page({id: details.tabId, url: details.url}); |
44 let frame = ext.getFrame(details.tabId, details.frameId); | 43 let frame = ext.getFrame(details.tabId, details.frameId); |
45 | 44 |
46 if (checkWhitelisted(page, frame)) | 45 if (checkWhitelisted(page, frame)) |
47 return; | 46 return; |
48 | 47 |
49 // To avoid an extra matchesAny for the common case we assumed no | 48 // To avoid an extra matchesAny for the common case we assumed no |
50 // $genericblock filters applied when searching for a matching $csp filter. | 49 // $genericblock filters applied when searching for a matching $csp filter. |
51 // We must now pay the price by first checking for a $genericblock filter | 50 // We must now pay the price by first checking for a $genericblock filter |
52 // and if necessary that our $csp filter is specific. | 51 // and if necessary that our $csp filter is specific. |
53 let specificOnly = checkWhitelisted(page, frame, typeMap.GENERICBLOCK); | 52 let specificOnly = !!checkWhitelisted(page, frame, typeMap.GENERICBLOCK); |
Sebastian Noack
2018/03/19 22:25:12
checkWhitelisted() returns a filter object (or nul
kzar
2018/03/20 09:02:31
Done.
| |
54 if (specificOnly) | 53 if (specificOnly) |
55 { | 54 { |
56 cspMatch = defaultMatcher.matchesAny(urlString, typeMap.CSP, hostname, | 55 cspMatch = defaultMatcher.matchesAny(urlString, typeMap.CSP, hostname, |
57 thirdParty, null, specificOnly); | 56 thirdParty, null, specificOnly); |
58 if (!cspMatch) | 57 if (!cspMatch) |
59 return; | 58 return; |
60 } | 59 } |
61 | 60 |
62 devtools.logRequest(page, urlString, "CSP", hostname, thirdParty, null, | 61 devtools.logRequest(page, urlString, "CSP", hostname, thirdParty, null, |
63 specificOnly, cspMatch); | 62 specificOnly, cspMatch); |
63 FilterNotifier.emit("filter.hitCount", cspMatch, 0, 0, page); | |
64 | 64 |
65 if (cspMatch instanceof WhitelistFilter) | 65 if (cspMatch instanceof WhitelistFilter) |
66 return; | 66 return; |
67 | 67 |
68 FilterNotifier.emit("filter.hitCount", cspMatch, 0, 0, page); | |
Sebastian Noack
2018/03/19 22:25:12
This seems inconsistent. For requests, we emit fil
kzar
2018/03/20 09:02:31
Done.
| |
69 details.responseHeaders.push({ | 68 details.responseHeaders.push({ |
70 name: "Content-Security-Policy", | 69 name: "Content-Security-Policy", |
71 value: cspMatch.csp | 70 value: cspMatch.csp |
72 }); | 71 }); |
73 | 72 |
74 return {responseHeaders: details.responseHeaders}; | 73 return {responseHeaders: details.responseHeaders}; |
75 } | 74 } |
76 }, { | 75 }, { |
77 urls: ["http://*/*", "https://*/*"], | 76 urls: ["http://*/*", "https://*/*"], |
78 types: ["main_frame", "sub_frame"] | 77 types: ["main_frame", "sub_frame"] |
79 }, ["blocking", "responseHeaders"]); | 78 }, ["blocking", "responseHeaders"]); |
LEFT | RIGHT |