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

Unified Diff: adblockplus/Api.jsm

Issue 4920541991403520: Create a minimal settings UI (Closed)
Patch Set: Hopefully removed wrong files Created March 20, 2015, 11:21 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/moz.build » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: adblockplus/Api.jsm
diff --git a/adblockplus/Api.jsm b/adblockplus/Api.jsm
index d87c428db1072eacdb8f8ba52a97a52879b1992c..9c3fba85b554ef34fcf2bc55b6edd30e48e9250a 100644
--- a/adblockplus/Api.jsm
+++ b/adblockplus/Api.jsm
@@ -23,6 +23,7 @@ const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Messaging.jsm");
function require(module)
{
@@ -32,12 +33,19 @@ function require(module)
return result.exports;
}
+let {FilterNotifier} = require("filterNotifier");
let {FilterStorage} = require("filterStorage");
let {Prefs} = require("prefs");
let {UI} = require("ui");
+let {FilterNotifier} = require("filterNotifier");
+
var AdblockPlusApi =
{
+ get filtersLoaded()
+ {
+ return filtersLoaded;
+ },
get acceptableAdsEnabled()
{
return FilterStorage.subscriptions.some(
@@ -49,3 +57,41 @@ var AdblockPlusApi =
UI.toggleAcceptableAds();
}
};
+
+
+FilterNotifier.addListener(function filterListener(action)
+{
+ if (action != "load")
+ return;
+
+ filtersLoaded = true;
+ FilterNotifier.removeListener(filterListener);
+});
+
+RequestService.addListener(function(data)
+{
+ if (!data)
+ return {"success" : false, "error" : "misformed request"};
+
+ if (data["action"] == "query_ready_state")
+ return {"success" : true, "value" : AdblockPlusApi.filtersLoaded};
+
+ if (!AdblockPlusApi.filtersLoaded)
+ return {"success" : false, "error" : "filters not loaded"};
+
+ switch (data["action"])
+ {
+ case "query_acceptable_ads_state":
+ return {"success" : true, "value" : AdblockPlusApi.acceptableAdsEnabled};
+ case "change_acceptable_ads_state":
+ if ("enable" in data)
+ {
+ AdblockPlusApi.acceptableAdsEnabled = !!data["enable"];
+ return {"success" : true};
+ }
+ return {"success" : false, "error" : "misformed request"};
+ default:
+ return {"success" : false, "error" : "unknown action '" + data["action"] + "'"};
+ }
+ return {"success" : false, "error" : "misformed request"};
+}, "AdblockPlus:Api");
« no previous file with comments | « no previous file | mobile/android/base/moz.build » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld