Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplus/Api.jsm

Issue 29588596: Issue 5919 - Adjust our code to the new messaging system (Closed)
Patch Set: Created Oct. 25, 2017, 11:39 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
+ }
if (!this.filtersLoaded)
- return {"success": false, "error": "filters not loaded"};
+ {
+ callback.onError("filters not loaded");
+ }
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");
}
};
« no previous file with comments | « no previous file | mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld