| Index: adblockplus/Api.jsm |
| diff --git a/adblockplus/Api.jsm b/adblockplus/Api.jsm |
| index d87c428db1072eacdb8f8ba52a97a52879b1992c..a6699a515e26ff6d8066e82f8c6acb4fc654cf8b 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() |
|
Felix Dahlke
2015/03/22 21:05:09
Nit: No space before :. Also below.
René Jeschke
2015/03/22 21:18:15
Done.
|
| + { |
| + 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" : "malformed request"}; |
|
Felix Dahlke
2015/03/22 21:05:09
We can't really reach this with the default case a
René Jeschke
2015/03/22 21:18:15
But is 'missing action' the same as 'no such actio
|
| + }).bind(this), "AdblockPlus:Api"); |
| } |
| }; |
| + |