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

Unified Diff: adblockplus/Api.jsm

Issue 5365916275572736: Issue 2351 - Add a custom menu item for whitelisting the current site (Closed)
Patch Set: Address comments, rename location, change item label Created May 6, 2015, 4:41 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
« no previous file with comments | « no previous file | mobile/android/base/BrowserApp.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
}
};
-
« no previous file with comments | « no previous file | mobile/android/base/BrowserApp.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld