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: Minimally invasive approach Created May 6, 2015, 12:12 a.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
@@ -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 location = Services.io.newURI(url, null, null);
+ try
+ {
+ return defaultMatcher.whitelist.matchesAny(
+ location.spec, "DOCUMENT", location.host, false, null);
+ }
+ catch (e)
+ {
+ return null;
+ }
+}
+
var AdblockPlusApi =
{
get filtersLoaded()
@@ -90,6 +106,43 @@
FilterStorage.removeSubscription(
FilterStorage.knownSubscriptions[url]);
},
+ isLocal: function(url)
+ {
+ let location = Services.io.newURI(url, null, null);
+ return !location.schemeIs("http") && !location.schemeIs("https");
+ },
+ isPageWhitelisted: function(url)
+ {
+ return !!getWhitelistingFilter(url);
+ },
+ whitelistSite: function(url, whitelisted)
+ {
+ let location = Services.io.newURI(url, null, null);
+ 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 = 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"] == "true");
René Jeschke 2015/05/06 10:56:33 Wouldn't it be better to use a 'boolean' here (dat
Felix Dahlke 2015/05/06 16:42:50 Done.
+ 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') | mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java » ('J')

Powered by Google App Engine
This is Rietveld