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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 "use strict"; |
21 | 21 |
22 let {defaultMatcher} = require("matcher"); | 22 let {defaultMatcher} = require("matcher"); |
23 let {RegExpFilter} = require("filterClasses"); | 23 let {RegExpFilter} = require("filterClasses"); |
| 24 let {DownloadableSubscription} = require("subscriptionClasses"); |
| 25 let {FilterNotifier} = require("filterNotifier"); |
24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req
uire("url"); | 26 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req
uire("url"); |
25 let {port} = require("messaging"); | 27 let {port} = require("messaging"); |
26 let devtools = require("devtools"); | 28 let devtools = require("devtools"); |
27 | 29 |
28 let pagesWithKey = new ext.PageMap(); | 30 let pagesWithKey = new ext.PageMap(); |
29 | 31 |
30 function match(page, url, typeMask, docDomain, sitekey) | 32 function match(page, url, typeMask, docDomain, sitekey) |
31 { | 33 { |
32 let thirdParty = !!docDomain && isThirdParty(url, docDomain); | 34 let thirdParty = !!docDomain && isThirdParty(url, docDomain); |
33 let urlString = stringifyURL(url); | 35 let urlString = stringifyURL(url); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 filter = match(page, frame.url, typeMask, docDomain, sitekey); | 76 filter = match(page, frame.url, typeMask, docDomain, sitekey); |
75 frame = parent; | 77 frame = parent; |
76 } | 78 } |
77 | 79 |
78 return filter; | 80 return filter; |
79 } | 81 } |
80 | 82 |
81 return match(page, page.url, typeMask); | 83 return match(page, page.url, typeMask); |
82 }; | 84 }; |
83 | 85 |
| 86 function revalidateWhitelistingState(page) |
| 87 { |
| 88 FilterNotifier.triggerListeners( |
| 89 "page.WhitelistingStateRevalidate", page, |
| 90 match(page, page.url, RegExpFilter.typeMap.DOCUMENT) |
| 91 ); |
| 92 } |
| 93 |
| 94 let revalidating = false; |
| 95 FilterNotifier.addListener((action, arg) => |
| 96 { |
| 97 switch (action) |
| 98 { |
| 99 case "subscription.added": |
| 100 if (arg instanceof DownloadableSubscription && !arg.lastDownload) |
| 101 break; |
| 102 case "subscription.removed": |
| 103 case "subscription.disabled": |
| 104 case "subscription.updated": |
| 105 case "filter.added": |
| 106 case "filter.removed": |
| 107 case "filter.disabled": |
| 108 case "load": |
| 109 if (!revalidating) |
| 110 { |
| 111 revalidating = true; |
| 112 ext.pages.query({}, pages => |
| 113 { |
| 114 revalidating = false; |
| 115 for (let page of pages) |
| 116 revalidateWhitelistingState(page); |
| 117 }); |
| 118 } |
| 119 } |
| 120 }); |
| 121 |
| 122 ext.pages.onLoading.addListener(revalidateWhitelistingState); |
| 123 |
84 let getKey = | 124 let getKey = |
85 /** | 125 /** |
86 * Gets the public key, previously recorded for the given page | 126 * Gets the public key, previously recorded for the given page |
87 * and frame, to be considered for the $sitekey filter option. | 127 * and frame, to be considered for the $sitekey filter option. |
88 * | 128 * |
89 * @param {Page} page | 129 * @param {Page} page |
90 * @param {Frame} frame | 130 * @param {Frame} frame |
91 * @return {string} | 131 * @return {string} |
92 */ | 132 */ |
93 exports.getKey = function(page, frame) | 133 exports.getKey = function(page, frame) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 key = key.replace(/=/g, ""); | 191 key = key.replace(/=/g, ""); |
152 | 192 |
153 if (verifyKey(key, signature, frame.url)) | 193 if (verifyKey(key, signature, frame.url)) |
154 recordKey(page, frame.url, key); | 194 recordKey(page, frame.url, key); |
155 }; | 195 }; |
156 | 196 |
157 port.on("filters.addKey", (message, sender) => | 197 port.on("filters.addKey", (message, sender) => |
158 { | 198 { |
159 processKey(message.token, sender.page, sender.frame); | 199 processKey(message.token, sender.page, sender.frame); |
160 }); | 200 }); |
OLD | NEW |