| LEFT | RIGHT |
| (no file at all) | |
| 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 "use strict"; |
| 21 | 21 |
| 22 const {defaultMatcher} = require("matcher"); | 22 const {defaultMatcher} = require("matcher"); |
| 23 const {RegExpFilter} = require("filterClasses"); | 23 const {Filter, RegExpFilter} = require("filterClasses"); |
| 24 const {FilterNotifier} = require("filterNotifier"); | 24 const {FilterNotifier} = require("filterNotifier"); |
| 25 const {FilterStorage} = require("filterStorage"); |
| 25 const {stringifyURL, getDecodedHostname, | 26 const {stringifyURL, getDecodedHostname, |
| 26 extractHostFromFrame, isThirdParty} = require("url"); | 27 extractHostFromFrame, isThirdParty} = require("url"); |
| 27 const {port} = require("messaging"); | 28 const {port} = require("messaging"); |
| 28 const devtools = require("devtools"); | 29 const devtools = require("devtools"); |
| 29 const {verifySignature} = require("rsa"); | 30 const {verifySignature} = require("rsa"); |
| 30 | 31 |
| 31 let sitekeys = new ext.PageMap(); | 32 let sitekeys = new ext.PageMap(); |
| 32 | 33 |
| 33 function match(page, url, typeMask, docDomain, sitekey) | 34 function match(page, url, typeMask, docDomain, sitekey) |
| 34 { | 35 { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 80 |
| 80 filter = match(page, frame.url, typeMask, docDomain, sitekey); | 81 filter = match(page, frame.url, typeMask, docDomain, sitekey); |
| 81 frame = parent; | 82 frame = parent; |
| 82 } | 83 } |
| 83 | 84 |
| 84 return filter; | 85 return filter; |
| 85 } | 86 } |
| 86 | 87 |
| 87 return match(page, page.url, typeMask); | 88 return match(page, page.url, typeMask); |
| 88 }; | 89 }; |
| 90 |
| 91 port.on("filters.isWhitelisted", message => |
| 92 { |
| 93 return !!checkWhitelisted(new ext.Page(message.tab)); |
| 94 }); |
| 95 |
| 96 port.on("filters.whitelist", message => |
| 97 { |
| 98 let page = new ext.Page(message.tab); |
| 99 let host = getDecodedHostname(page.url).replace(/^www\./, ""); |
| 100 let filter = Filter.fromText("@@||" + host + "^$document"); |
| 101 if (filter.subscriptions.length && filter.disabled) |
| 102 { |
| 103 filter.disabled = false; |
| 104 } |
| 105 else |
| 106 { |
| 107 filter.disabled = false; |
| 108 FilterStorage.addFilter(filter); |
| 109 } |
| 110 }); |
| 111 |
| 112 port.on("filters.unwhitelist", message => |
| 113 { |
| 114 let page = new ext.Page(message.tab); |
| 115 // Remove any exception rules applying to this URL |
| 116 let filter = checkWhitelisted(page); |
| 117 while (filter) |
| 118 { |
| 119 FilterStorage.removeFilter(filter); |
| 120 if (filter.subscriptions.length) |
| 121 filter.disabled = true; |
| 122 filter = checkWhitelisted(page); |
| 123 } |
| 124 }); |
| 89 | 125 |
| 90 function revalidateWhitelistingState(page) | 126 function revalidateWhitelistingState(page) |
| 91 { | 127 { |
| 92 FilterNotifier.emit( | 128 FilterNotifier.emit( |
| 93 "page.WhitelistingStateRevalidate", | 129 "page.WhitelistingStateRevalidate", |
| 94 page, checkWhitelisted(page) | 130 page, checkWhitelisted(page) |
| 95 ); | 131 ); |
| 96 } | 132 } |
| 97 | 133 |
| 98 FilterNotifier.on("filter.behaviorChanged", () => | 134 FilterNotifier.on("filter.behaviorChanged", () => |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 { | 225 { |
| 190 chrome.webRequest.onHeadersReceived.addListener( | 226 chrome.webRequest.onHeadersReceived.addListener( |
| 191 onHeadersReceived, | 227 onHeadersReceived, |
| 192 { | 228 { |
| 193 urls: ["http://*/*", "https://*/*"], | 229 urls: ["http://*/*", "https://*/*"], |
| 194 types: ["main_frame", "sub_frame"] | 230 types: ["main_frame", "sub_frame"] |
| 195 }, | 231 }, |
| 196 ["responseHeaders"] | 232 ["responseHeaders"] |
| 197 ); | 233 ); |
| 198 } | 234 } |
| LEFT | RIGHT |