Index: adblockplus/Api.jsm |
=================================================================== |
--- a/adblockplus/Api.jsm |
+++ b/adblockplus/Api.jsm |
@@ -55,26 +55,26 @@ function initFilterListeners() |
function onFiltersLoad() |
{ |
let {addonVersion} = require("info"); |
if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPref)) |
{ |
UI.addSubscription(UI.currentWindow, Prefs.currentVersion); |
} |
- Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); |
+ EventDispatcher.instance.sendRequest({type: "Abb:OnFiltersLoad"}); |
} |
function onFiltersSave() |
{ |
if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl)) |
{ |
setBoolPref(subscriptionsSavedPref, true); |
} |
- Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); |
+ EventDispatcher.instance.sendRequest({type: "Abb:OnFiltersSave"}); |
} |
function getBoolPref(name) |
{ |
let branch = getPrefsBranch(); |
try |
{ |
return branch.getBoolPref(name); |
@@ -222,83 +222,100 @@ var AdblockPlusApi = |
filter = getWhitelistingFilter(url); |
} |
} |
}, |
initCommunication: function() |
{ |
initFilterListeners(); |
- Messaging.addListener((function(data) |
+ EventDispatcher.instance.registerListener((event, data, callback) => |
{ |
if (!data) |
- return {"success": false, "error": "malformed request"}; |
+ { |
+ callback.onError("malformed request"); |
anton
2017/10/30 13:16:55
should not `return` be added here?
diegocarloslima
2017/10/30 13:40:11
Acknowledged.
|
+ } |
if (!this.filtersLoaded) |
- return {"success": false, "error": "filters not loaded"}; |
+ { |
+ callback.onError("filters not loaded"); |
anton
2017/10/30 13:16:55
should not `return` be added here?
diegocarloslima
2017/10/30 13:40:11
Acknowledged.
|
+ } |
switch (data["action"]) |
{ |
case "getAdblockPlusEnabled": |
- return {"success": true, "value": this.adblockPlusEnabled}; |
+ callback.onSuccess({"value": this.adblockPlusEnabled}); |
+ return; |
case "setAdblockPlusEnabled": |
if ("enable" in data) |
{ |
this.adblockPlusEnabled = !!data["enable"]; |
- return {"success": true}; |
+ callback.onSuccess({}); |
+ return; |
} |
break; |
case "getAcceptableAdsEnabled": |
- return {"success": true, "value": this.acceptableAdsEnabled}; |
+ callback.onSuccess({"value": this.acceptableAdsEnabled}); |
+ return; |
case "setAcceptableAdsEnabled": |
if ("enable" in data) |
{ |
this.acceptableAdsEnabled = !!data["enable"]; |
- return {"success": true}; |
+ callback.onSuccess({}); |
+ return; |
} |
break; |
case "getSubscriptionsXml": |
- return {"success": true, "value": this.subscriptionsXml}; |
+ callback.onSuccess({"value": this.subscriptionsXml}); |
+ return; |
case "getActiveSubscriptions": |
- return {"success": true, "value": this.getActiveSubscriptions()}; |
+ callback.onSuccess({"value": this.getActiveSubscriptions()}); |
+ return; |
case "isSubscriptionListed": |
if ("url" in data) |
{ |
- return {"success": true, |
- "value": this.isSubscriptionListed(data["url"])}; |
+ callback.onSuccess({"value": this.isSubscriptionListed(data["url"])}); |
+ return; |
} |
break; |
case "addSubscription": |
if ("url" in data) |
{ |
this.addSubscription(data["url"], data["title"]); |
- return {"success": true}; |
+ callback.onSuccess({}); |
+ return; |
} |
break; |
case "removeSubscription": |
if ("url" in data) |
{ |
this.removeSubscription(data["url"]); |
- return {"success": true}; |
+ callback.onSuccess({}); |
+ return; |
} |
break; |
case "isLocal": |
if ("url" in data) |
- return {"success": true, |
- "value": this.isLocal(data["url"])}; |
+ { |
+ callback.onSuccess({"value": this.isLocal(data["url"])}); |
+ return; |
+ } |
break; |
case "isPageWhitelisted": |
if ("url" in data) |
- return {"success": true, |
- "value": this.isPageWhitelisted(data["url"])}; |
+ { |
+ callback.onSuccess({"value": this.isPageWhitelisted(data["url"])}); |
+ return; |
+ } |
break; |
case "whitelistSite": |
if ("url" in data && "whitelisted" in data) |
{ |
this.whitelistSite(data["url"], data["whitelisted"]); |
- return {"success": true}; |
+ callback.onSuccess({}); |
+ return; |
} |
break; |
} |
- return {"success": false, "error": "malformed request"}; |
- }).bind(this), "AdblockPlus:Api"); |
+ callback.onError("malformed request"); |
+ }, "AdblockPlus:Api"); |
} |
}; |