Index: adblockplus/Api.jsm |
=================================================================== |
--- a/adblockplus/Api.jsm |
+++ b/adblockplus/Api.jsm |
@@ -36,12 +36,28 @@ |
return result.exports; |
} |
+let {Filter} = require("filterClasses"); |
let {FilterStorage} = require("filterStorage"); |
+let {defaultMatcher} = require("matcher"); |
let {Prefs} = require("prefs"); |
let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscription, ExternalSubscription} = require("subscriptionClasses"); |
let {Synchronizer} = require("synchronizer"); |
let {UI} = require("ui"); |
+function getWhitelistingFilter(url) |
+{ |
+ let uriObject = Services.io.newURI(url, null, null); |
+ try |
+ { |
+ return defaultMatcher.whitelist.matchesAny( |
+ uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
+ } |
+ catch (e) |
+ { |
+ return null; |
+ } |
+} |
+ |
var AdblockPlusApi = |
{ |
get filtersLoaded() |
@@ -90,6 +106,43 @@ |
FilterStorage.removeSubscription( |
FilterStorage.knownSubscriptions[url]); |
}, |
+ isLocal: function(url) |
+ { |
+ let uriObject = Services.io.newURI(url, null, null); |
+ return !uriObject.schemeIs("http") && !uriObject.schemeIs("https"); |
+ }, |
+ isPageWhitelisted: function(url) |
+ { |
+ return AdblockPlusApi.isLocal(url) || !!getWhitelistingFilter(url); |
+ }, |
+ whitelistSite: function(url, whitelisted) |
+ { |
+ let uriObject = Services.io.newURI(url, null, null); |
+ if (whitelisted) |
+ { |
+ var host = uriObject.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 = getWhitelistingFilter(url); |
+ while (filter) |
+ { |
+ FilterStorage.removeFilter(filter); |
+ if (filter.subscriptions.length) |
+ filter.disabled = true; |
+ filter = getWhitelistingFilter(url); |
+ } |
+ } |
+ }, |
initCommunication: function() |
{ |
RequestService.addListener((function(data) |
@@ -137,9 +190,25 @@ |
return {"success": true}; |
} |
break; |
+ case "isLocal": |
+ if ("url" in data) |
+ return {"success": true, |
+ "value": this.isLocal(data["url"])}; |
+ break; |
+ case "isPageWhitelisted": |
+ if ("url" in data) |
+ return {"success": true, |
+ "value": this.isPageWhitelisted(data["url"])}; |
+ break; |
+ case "whitelistSite": |
+ if ("url" in data && "whitelisted" in data) |
+ { |
+ this.whitelistSite(data["url"], data["whitelisted"]); |
+ return {"success": true}; |
+ } |
+ break; |
} |
return {"success": false, "error": "malformed request"}; |
}).bind(this), "AdblockPlus:Api"); |
} |
}; |
- |