| Index: adblockplus/Api.jsm |
| =================================================================== |
| --- a/adblockplus/Api.jsm |
| +++ b/adblockplus/Api.jsm |
| @@ -33,7 +33,9 @@ |
| return result.exports; |
| } |
| +let {Filter} = require("filterClasses"); |
| let {FilterStorage} = require("filterStorage"); |
| +let {defaultMatcher} = require("matcher"); |
| let {Prefs} = require("prefs"); |
| let {UI} = require("ui"); |
| @@ -80,6 +82,42 @@ |
| } |
| return {"success": false, "error": "malformed request"}; |
| }).bind(this), "AdblockPlus:Api"); |
| + }, |
| + isLocal: function(location) |
| + { |
| + return !location.schemeIs("http") && !location.schemeIs("https"); |
| + }, |
| + isPageWhitelisted: function(location) |
| + { |
| + return defaultMatcher.whitelist.matchesAny( |
| + location.spec, "DOCUMENT", location.host, false, null); |
| + }, |
| + whitelistSite: function(location, whitelisted) |
| + { |
| + if (whitelisted) |
| + { |
| + var host = location.host.replace(/^www\./, ""); |
| + var filter = Filter.fromText("@@||" + host + "^$document"); |
| + if (filter.subscriptions.length && filter.disabled) |
| + filter.disabled = false; |
| + else |
| + { |
| + filter.disabled = false; |
| + FilterStorage.addFilter(filter); |
| + } |
| + } |
| + else |
| + { |
| + // Remove any exception rules applying to this URL |
| + var filter = AdblockPlusApi.isPageWhitelisted(location); |
| + while (filter) |
| + { |
| + FilterStorage.removeFilter(filter); |
| + if (filter.subscriptions.length) |
| + filter.disabled = true; |
| + filter = AdblockPlusApi.isPageWhitelisted(location); |
| + } |
| + } |
| } |
| }; |