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 /** @module whitelisting */ | 18 /** @module whitelisting */ |
19 | 19 |
20 "use strict"; | 20 import {defaultMatcher} from "matcher"; |
21 | 21 import {Filter, RegExpFilter} from "filterClasses"; |
22 const {defaultMatcher} = require("matcher"); | 22 import {FilterNotifier} from "filterNotifier"; |
23 const {Filter, RegExpFilter} = require("filterClasses"); | 23 import {FilterStorage} from "filterStorage"; |
24 const {FilterNotifier} = require("filterNotifier"); | 24 import {stringifyURL, getDecodedHostname, |
25 const {FilterStorage} = require("filterStorage"); | 25 extractHostFromFrame, isThirdParty} from "url"; |
26 const {stringifyURL, getDecodedHostname, | 26 import {port} from "messaging"; |
27 extractHostFromFrame, isThirdParty} = require("url"); | 27 import devtools from "devtools"; |
28 const {port} = require("messaging"); | 28 import {verifySignature} from "rsa"; |
29 const devtools = require("devtools"); | |
30 const {verifySignature} = require("rsa"); | |
31 | 29 |
32 let sitekeys = new ext.PageMap(); | 30 let sitekeys = new ext.PageMap(); |
33 | 31 |
34 function match(page, url, typeMask, docDomain, sitekey) | 32 function match(page, url, typeMask, docDomain, sitekey) |
35 { | 33 { |
36 let thirdParty = !!docDomain && isThirdParty(url, docDomain); | 34 let thirdParty = !!docDomain && isThirdParty(url, docDomain); |
37 let urlString = stringifyURL(url); | 35 let urlString = stringifyURL(url); |
38 | 36 |
39 if (!docDomain) | 37 if (!docDomain) |
40 docDomain = getDecodedHostname(url); | 38 docDomain = getDecodedHostname(url); |
41 | 39 |
42 let filter = defaultMatcher.whitelist.matchesAny( | 40 let filter = defaultMatcher.whitelist.matchesAny( |
43 urlString, typeMask, docDomain, thirdParty, sitekey | 41 urlString, typeMask, docDomain, thirdParty, sitekey |
44 ); | 42 ); |
45 | 43 |
46 if (filter && devtools) | 44 if (filter && devtools) |
47 { | 45 { |
48 devtools.logWhitelistedDocument( | 46 devtools.logWhitelistedDocument( |
49 page, urlString, typeMask, docDomain, filter | 47 page, urlString, typeMask, docDomain, filter |
50 ); | 48 ); |
51 } | 49 } |
52 | 50 |
53 return filter; | 51 return filter; |
54 } | 52 } |
55 | 53 |
56 let checkWhitelisted = | |
57 /** | 54 /** |
58 * Gets the active whitelisting filter for the document associated | 55 * Gets the active whitelisting filter for the document associated |
59 * with the given page/frame, or null if it's not whitelisted. | 56 * with the given page/frame, or null if it's not whitelisted. |
60 * | 57 * |
61 * @param {Page} page | 58 * @param {Page} page |
62 * @param {Frame} [frame] | 59 * @param {Frame} [frame] |
63 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] | 60 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] |
64 * @return {?WhitelistFilter} | 61 * @return {?WhitelistFilter} |
65 */ | 62 */ |
66 exports.checkWhitelisted = (page, frame, typeMask) => | 63 export const checkWhitelisted = (page, frame, typeMask) => |
67 { | 64 { |
68 if (typeof typeMask == "undefined") | 65 if (typeof typeMask == "undefined") |
69 typeMask = RegExpFilter.typeMap.DOCUMENT; | 66 typeMask = RegExpFilter.typeMap.DOCUMENT; |
70 | 67 |
71 if (frame) | 68 if (frame) |
72 { | 69 { |
73 let filter = null; | 70 let filter = null; |
74 | 71 |
75 while (frame && !filter) | 72 while (frame && !filter) |
76 { | 73 { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 132 { |
136 browser.tabs.query({}, tabs => | 133 browser.tabs.query({}, tabs => |
137 { | 134 { |
138 for (let tab of tabs) | 135 for (let tab of tabs) |
139 revalidateWhitelistingState(new ext.Page(tab)); | 136 revalidateWhitelistingState(new ext.Page(tab)); |
140 }); | 137 }); |
141 }); | 138 }); |
142 | 139 |
143 ext.pages.onLoading.addListener(revalidateWhitelistingState); | 140 ext.pages.onLoading.addListener(revalidateWhitelistingState); |
144 | 141 |
145 let getKey = | |
146 /** | 142 /** |
147 * Gets the public key, previously recorded for the given page | 143 * Gets the public key, previously recorded for the given page |
148 * and frame, to be considered for the $sitekey filter option. | 144 * and frame, to be considered for the $sitekey filter option. |
149 * | 145 * |
150 * @param {Page} page | 146 * @param {Page} page |
151 * @param {Frame} frame | 147 * @param {Frame} frame |
152 * @return {string} | 148 * @return {string} |
153 */ | 149 */ |
154 exports.getKey = (page, frame) => | 150 export const getKey = (page, frame) => |
155 { | 151 { |
156 let keys = sitekeys.get(page); | 152 let keys = sitekeys.get(page); |
157 if (!keys) | 153 if (!keys) |
158 return null; | 154 return null; |
159 | 155 |
160 for (; frame != null; frame = frame.parent) | 156 for (; frame != null; frame = frame.parent) |
161 { | 157 { |
162 let key = keys.get(stringifyURL(frame.url)); | 158 let key = keys.get(stringifyURL(frame.url)); |
163 if (key) | 159 if (key) |
164 return key; | 160 return key; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 { | 221 { |
226 browser.webRequest.onHeadersReceived.addListener( | 222 browser.webRequest.onHeadersReceived.addListener( |
227 onHeadersReceived, | 223 onHeadersReceived, |
228 { | 224 { |
229 urls: ["http://*/*", "https://*/*"], | 225 urls: ["http://*/*", "https://*/*"], |
230 types: ["main_frame", "sub_frame"] | 226 types: ["main_frame", "sub_frame"] |
231 }, | 227 }, |
232 ["responseHeaders"] | 228 ["responseHeaders"] |
233 ); | 229 ); |
234 } | 230 } |
OLD | NEW |