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() |
René Jeschke
2015/03/22 15:32:59
Done.
|
+ { |
+ 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) |
Felix Dahlke
2015/03/22 13:52:34
IMHO it would be cleaner to move this to a dedicat
|
+{ |
+ if (!data) |
+ return {"success" : false, "error" : "misformed request"}; |
+ |
+ if (data["action"] == "query_ready_state") |
René Jeschke
2015/03/22 15:32:59
As you suggest ( \/ ) that we should use 'get' and
|
+ return {"success" : true, "value" : AdblockPlusApi.filtersLoaded}; |
+ |
+ if (!AdblockPlusApi.filtersLoaded) |
+ return {"success" : false, "error" : "filters not loaded"}; |
+ |
+ switch (data["action"]) |
+ { |
+ case "query_acceptable_ads_state": |
René Jeschke
2015/03/22 15:32:59
Well, I could rename this, doesn't make such a dif
|
+ return {"success" : true, "value" : AdblockPlusApi.acceptableAdsEnabled}; |
+ case "change_acceptable_ads_state": |
Felix Dahlke
2015/03/22 13:52:34
Likewise - setAcceptableAdsEnabled"?
René Jeschke
2015/03/22 15:32:59
Well, ok.
|
+ 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"); |