Index: adblockplus/Api.jsm |
diff --git a/adblockplus/Api.jsm b/adblockplus/Api.jsm |
index d87c428db1072eacdb8f8ba52a97a52879b1992c..b893b4e599697059e1886ef6230f55980137d0f6 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) |
{ |
@@ -38,6 +39,10 @@ let {UI} = require("ui"); |
var AdblockPlusApi = |
{ |
+ get filtersLoaded() |
+ { |
+ return !FilterStorage._loading; |
+ }, |
get acceptableAdsEnabled() |
{ |
return FilterStorage.subscriptions.some( |
@@ -47,5 +52,36 @@ var AdblockPlusApi = |
{ |
if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) |
UI.toggleAcceptableAds(); |
+ }, |
+ initCommunication : function() |
+ { |
+ RequestService.addListener((function(data) |
+ { |
+ if (!data) |
+ return {"success" : false, "error" : "malformed request"}; |
+ |
+ if (data["action"] == "getFiltersLoaded") |
+ return {"success" : true, "value" : this.filtersLoaded}; |
+ |
+ if (!this.filtersLoaded) |
+ return {"success" : false, "error" : "filters not loaded"}; |
+ |
+ switch (data["action"]) |
+ { |
+ case "getAcceptableAdsEnabled": |
+ return {"success" : true, "value" : this.acceptableAdsEnabled}; |
+ case "setAcceptableAdsEnabled": |
+ if ("enable" in data) |
+ { |
+ this.acceptableAdsEnabled = !!data["enable"]; |
+ return {"success" : true}; |
+ } |
+ return {"success" : false, "error" : "malformed request"}; |
+ default: |
+ return {"success" : false, "error" : "unknown action '" + data["action"] + "'"}; |
+ } |
+ return {"success" : false, "error" : "misformed request"}; |
Felix Dahlke
2015/03/22 15:51:45
Also "malformed" then? :)
|
+ }).bind(this), "AdblockPlus:Api"); |
} |
}; |
+ |