Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplus/Api.jsm

Issue 29543774: Issue 2801 - Create 'Whitelisted websites' screen and add link to 'Ad blocking' screen (Closed)
Patch Set: Adjustments accordingly to Thomas's comments. Also, adjusting strings for multilocale build Created Sept. 19, 2017, 3:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
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;
+ 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");
}
};

Powered by Google App Engine
This is Rietveld