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: Created April 25, 2015, 9:45 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
@@ -33,7 +33,9 @@
return result.exports;
}
+let {Filter} = require("filterClasses");
let {FilterStorage} = require("filterStorage");
+let {defaultMatcher} = require("matcher");
let {Prefs} = require("prefs");
let {UI} = require("ui");
@@ -80,6 +82,42 @@
}
return {"success": false, "error": "malformed request"};
}).bind(this), "AdblockPlus:Api");
+ },
+ isLocal: function(location)
+ {
+ return !location.schemeIs("http") && !location.schemeIs("https");
+ },
+ isPageWhitelisted: function(location)
+ {
+ return defaultMatcher.whitelist.matchesAny(
+ location.spec, "DOCUMENT", location.host, false, null);
+ },
+ whitelistSite: function(location, whitelisted)
+ {
+ 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 = AdblockPlusApi.isPageWhitelisted(location);
+ while (filter)
+ {
+ FilterStorage.removeFilter(filter);
+ if (filter.subscriptions.length)
+ filter.disabled = true;
+ filter = AdblockPlusApi.isPageWhitelisted(location);
+ }
+ }
}
};
« 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