Index: adblockplus/Api.jsm |
=================================================================== |
--- a/adblockplus/Api.jsm |
+++ b/adblockplus/Api.jsm |
@@ -94,23 +94,22 @@ function setBoolPref(name, value) |
function getPrefsBranch() |
{ |
let {addonRoot, addonName} = require("info"); |
let branchName = "extensions." + addonName + "."; |
return Services.prefs.getBranch(branchName); |
} |
-function getWhitelistingFilter(url) |
+function getWhitelistingFilter(url, host) |
{ |
- let uriObject = Services.io.newURI(url, null, null); |
Thomas Greiner
2017/09/15 15:08:06
It's not a big deal whether or not we're extractin
diegocarloslima
2017/09/18 14:16:36
I do agree with you, the intention of the formatUr
|
try |
{ |
return defaultMatcher.whitelist.matchesAny( |
- uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null, false); |
+ url, RegExpFilter.typeMap.DOCUMENT, host, false, null, false); |
} |
catch (e) |
{ |
return null; |
} |
} |
var AdblockPlusApi = |
@@ -181,44 +180,58 @@ var AdblockPlusApi = |
for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
{ |
let subscription = FilterStorage.subscriptions[i]; |
if (!subscription.disabled) |
subscriptions.push({"title": subscription.title, "url": subscription.url}); |
} |
return subscriptions; |
}, |
- isLocal: function(url) |
+ get whitelistedWebsites() |
{ |
- let uriObject = Services.io.newURI(url, null, null); |
- return !uriObject.schemeIs("http") && !uriObject.schemeIs("https"); |
+ let whitelistedWebsites = []; |
+ for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
+ { |
+ let subscription = FilterStorage.subscriptions[i]; |
+ if (subscription.url && subscription.url.startsWith("~user~") && subscription.filters) |
+ { |
+ for (let j = 0; j < subscription.filters.length; j++) |
+ { |
+ let filter = subscription.filters[j]; |
+ let whitelistMatch = filter.text ? filter.text.match(/@@\|\|(.*)\^\$document/) : null; |
Thomas Greiner
2017/09/15 15:08:06
We're using a slightly different regular expressio
diegocarloslima
2017/09/18 14:16:36
Acknowledged.
|
+ if(whitelistMatch) |
+ { |
+ whitelistedWebsites.push({"url": whitelistMatch[1]}) |
+ } |
+ } |
+ } |
+ } |
+ return whitelistedWebsites; |
}, |
- isPageWhitelisted: function(url) |
+ isWebsiteWhitelisted: function(url, host) |
{ |
- return AdblockPlusApi.isLocal(url) || !!getWhitelistingFilter(url); |
+ return !!getWhitelistingFilter(url, host); |
}, |
- whitelistSite: function(url, whitelisted) |
+ whitelistWebsite: function(url, host, 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); |
+ var filter = getWhitelistingFilter(url, host); |
while (filter) |
{ |
FilterStorage.removeFilter(filter); |
if (filter.subscriptions.length) |
filter.disabled = true; |
filter = getWhitelistingFilter(url); |
} |
} |
@@ -275,30 +288,29 @@ var AdblockPlusApi = |
break; |
case "removeSubscription": |
if ("url" in data) |
{ |
this.removeSubscription(data["url"]); |
return {"success": true}; |
} |
break; |
- case "isLocal": |
- if ("url" in data) |
+ case "getWhitelistedWebsites": |
+ return {"success": true, "value": this.whitelistedWebsites}; |
+ case "isWebsiteWhitelisted": |
+ if ("url" in data && "host" in data) |
+ { |
return {"success": true, |
- "value": this.isLocal(data["url"])}; |
+ "value": this.isWebsiteWhitelisted(data["url"], data["host"])}; |
+ } |
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) |
+ case "whitelistWebsite": |
+ if ("url" in data && "host" in data && "whitelisted" in data) |
{ |
- this.whitelistSite(data["url"], data["whitelisted"]); |
+ this.whitelistWebsite(data["url"], data["host"], data["whitelisted"]); |
return {"success": true}; |
} |
break; |
} |
return {"success": false, "error": "malformed request"}; |
}).bind(this), "AdblockPlus:Api"); |
} |
}; |