| 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 {FilterNotifier} = require("filterNotifier"); |
| 24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req
uire("url"); | 25 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req
uire("url"); |
| 25 let {port} = require("messaging"); | 26 let {port} = require("messaging"); |
| 26 let devtools = require("devtools"); | 27 let devtools = require("devtools"); |
| 27 | 28 |
| 28 let pagesWithKey = new ext.PageMap(); | 29 let pagesWithKey = new ext.PageMap(); |
| 29 | 30 |
| 30 function match(page, url, typeMask, docDomain, sitekey) | 31 function match(page, url, typeMask, docDomain, sitekey) |
| 31 { | 32 { |
| 32 let thirdParty = !!docDomain && isThirdParty(url, docDomain); | 33 let thirdParty = !!docDomain && isThirdParty(url, docDomain); |
| 33 let urlString = stringifyURL(url); | 34 let urlString = stringifyURL(url); |
| 34 | 35 |
| 35 if (!docDomain) | 36 if (!docDomain) |
| 36 docDomain = getDecodedHostname(url); | 37 docDomain = getDecodedHostname(url); |
| 37 | 38 |
| 38 let filter = defaultMatcher.whitelist.matchesAny( | 39 let filter = defaultMatcher.whitelist.matchesAny( |
| 39 urlString, typeMask, docDomain, thirdParty, sitekey | 40 urlString, typeMask, docDomain, thirdParty, sitekey |
| 40 ); | 41 ); |
| 41 | 42 |
| 42 if (filter && devtools) | 43 if (filter && devtools) |
| 43 devtools.logWhitelistedDocument( | 44 devtools.logWhitelistedDocument( |
| 44 page, urlString, typeMask, docDomain, filter | 45 page, urlString, typeMask, docDomain, filter |
| 45 ); | 46 ); |
| 46 | 47 |
| 47 return filter; | 48 return filter; |
| 48 } | 49 } |
| 49 | 50 |
| 51 let checkWhitelisted = |
| 50 /** | 52 /** |
| 51 * Gets the active whitelisting filter for the document associated | 53 * Gets the active whitelisting filter for the document associated |
| 52 * with the given page/frame, or null if it's not whitelisted. | 54 * with the given page/frame, or null if it's not whitelisted. |
| 53 * | 55 * |
| 54 * @param {Page} page | 56 * @param {Page} page |
| 55 * @param {Frame} [frame] | 57 * @param {Frame} [frame] |
| 56 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] | 58 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] |
| 57 * @return {?WhitelistFilter} | 59 * @return {?WhitelistFilter} |
| 58 */ | 60 */ |
| 59 exports.checkWhitelisted = function(page, frame, typeMask) | 61 exports.checkWhitelisted = function(page, frame, typeMask) |
| (...skipping 14 matching lines...) Expand all 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 FilterNotifier.addListener(action => |
| 87 { |
| 88 if (action == "load" || action == "save") |
| 89 ext.pages.query({}, pages => |
| 90 { |
| 91 for (let page of pages) |
| 92 FilterNotifier.triggerListeners( |
| 93 "page.WhitelistingStateRevalidate", |
| 94 page, checkWhitelisted(page) |
| 95 ); |
| 96 }); |
| 97 }); |
| 98 |
| 99 ext.pages.onLoading.addListener(page => |
| 100 { |
| 101 FilterNotifier.triggerListeners( |
| 102 "page.WhitelistingStateRevalidate", |
| 103 page, checkWhitelisted(page) |
| 104 ); |
| 105 }); |
| 106 |
| 84 let getKey = | 107 let getKey = |
| 85 /** | 108 /** |
| 86 * Gets the public key, previously recorded for the given page | 109 * Gets the public key, previously recorded for the given page |
| 87 * and frame, to be considered for the $sitekey filter option. | 110 * and frame, to be considered for the $sitekey filter option. |
| 88 * | 111 * |
| 89 * @param {Page} page | 112 * @param {Page} page |
| 90 * @param {Frame} frame | 113 * @param {Frame} frame |
| 91 * @return {string} | 114 * @return {string} |
| 92 */ | 115 */ |
| 93 exports.getKey = function(page, frame) | 116 exports.getKey = function(page, frame) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 key = key.replace(/=/g, ""); | 174 key = key.replace(/=/g, ""); |
| 152 | 175 |
| 153 if (verifyKey(key, signature, frame.url)) | 176 if (verifyKey(key, signature, frame.url)) |
| 154 recordKey(page, frame.url, key); | 177 recordKey(page, frame.url, key); |
| 155 }; | 178 }; |
| 156 | 179 |
| 157 port.on("filters.addKey", (message, sender) => | 180 port.on("filters.addKey", (message, sender) => |
| 158 { | 181 { |
| 159 processKey(message.token, sender.page, sender.frame); | 182 processKey(message.token, sender.page, sender.frame); |
| 160 }); | 183 }); |
| OLD | NEW |