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"); |