Index: lib/whitelisting.js |
=================================================================== |
--- a/lib/whitelisting.js |
+++ b/lib/whitelisting.js |
@@ -15,18 +15,19 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
/** @module whitelisting */ |
"use strict"; |
const {defaultMatcher} = require("matcher"); |
-const {RegExpFilter} = require("filterClasses"); |
+const {Filter, RegExpFilter} = require("filterClasses"); |
const {FilterNotifier} = require("filterNotifier"); |
+const {FilterStorage} = require("filterStorage"); |
const {stringifyURL, getDecodedHostname, |
extractHostFromFrame, isThirdParty} = require("url"); |
const {port} = require("messaging"); |
const devtools = require("devtools"); |
const {verifySignature} = require("rsa"); |
let sitekeys = new ext.PageMap(); |
@@ -82,16 +83,51 @@ |
} |
return filter; |
} |
return match(page, page.url, typeMask); |
}; |
+port.on("filters.isWhitelisted", message => |
+{ |
+ return !!checkWhitelisted(new ext.Page(message.tab)); |
+}); |
+ |
+port.on("filters.whitelist", message => |
+{ |
+ let page = new ext.Page(message.tab); |
+ let host = getDecodedHostname(page.url).replace(/^www\./, ""); |
+ let filter = Filter.fromText("@@||" + host + "^$document"); |
+ if (filter.subscriptions.length && filter.disabled) |
+ { |
+ filter.disabled = false; |
+ } |
+ else |
+ { |
+ filter.disabled = false; |
+ FilterStorage.addFilter(filter); |
+ } |
+}); |
+ |
+port.on("filters.unwhitelist", message => |
+{ |
+ let page = new ext.Page(message.tab); |
+ // Remove any exception rules applying to this URL |
+ let filter = checkWhitelisted(page); |
+ while (filter) |
+ { |
+ FilterStorage.removeFilter(filter); |
+ if (filter.subscriptions.length) |
+ filter.disabled = true; |
+ filter = checkWhitelisted(page); |
+ } |
+}); |
+ |
function revalidateWhitelistingState(page) |
{ |
FilterNotifier.emit( |
"page.WhitelistingStateRevalidate", |
page, checkWhitelisted(page) |
); |
} |