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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 FilterNotifier.on("save", onFiltersSave); 53 FilterNotifier.on("save", onFiltersSave);
54 } 54 }
55 55
56 function onFiltersLoad() 56 function onFiltersLoad()
57 { 57 {
58 let {addonVersion} = require("info"); 58 let {addonVersion} = require("info");
59 if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPre f)) 59 if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPre f))
60 { 60 {
61 UI.addSubscription(UI.currentWindow, Prefs.currentVersion); 61 UI.addSubscription(UI.currentWindow, Prefs.currentVersion);
62 } 62 }
63 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); 63 EventDispatcher.instance.sendRequest({type: "Abb:OnFiltersLoad"});
64 } 64 }
65 65
66 function onFiltersSave() 66 function onFiltersSave()
67 { 67 {
68 if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsu rl)) 68 if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsu rl))
69 { 69 {
70 setBoolPref(subscriptionsSavedPref, true); 70 setBoolPref(subscriptionsSavedPref, true);
71 } 71 }
72 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); 72 EventDispatcher.instance.sendRequest({type: "Abb:OnFiltersSave"});
73 } 73 }
74 74
75 function getBoolPref(name) 75 function getBoolPref(name)
76 { 76 {
77 let branch = getPrefsBranch(); 77 let branch = getPrefsBranch();
78 try 78 try
79 { 79 {
80 return branch.getBoolPref(name); 80 return branch.getBoolPref(name);
81 } 81 }
82 catch (e) 82 catch (e)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if (filter.subscriptions.length) 220 if (filter.subscriptions.length)
221 filter.disabled = true; 221 filter.disabled = true;
222 filter = getWhitelistingFilter(url); 222 filter = getWhitelistingFilter(url);
223 } 223 }
224 } 224 }
225 }, 225 },
226 initCommunication: function() 226 initCommunication: function()
227 { 227 {
228 initFilterListeners(); 228 initFilterListeners();
229 229
230 Messaging.addListener((function(data) 230 EventDispatcher.instance.registerListener((event, data, callback) =>
231 { 231 {
232 if (!data) 232 if (!data)
233 return {"success": false, "error": "malformed request"}; 233 {
234 callback.onError("malformed request");
235 }
234 236
235 if (!this.filtersLoaded) 237 if (!this.filtersLoaded)
236 return {"success": false, "error": "filters not loaded"}; 238 {
239 callback.onError("filters not loaded");
240 }
237 241
238 switch (data["action"]) 242 switch (data["action"])
239 { 243 {
240 case "getAdblockPlusEnabled": 244 case "getAdblockPlusEnabled":
241 return {"success": true, "value": this.adblockPlusEnabled}; 245 callback.onSuccess({"value": this.adblockPlusEnabled});
246 return;
242 case "setAdblockPlusEnabled": 247 case "setAdblockPlusEnabled":
243 if ("enable" in data) 248 if ("enable" in data)
244 { 249 {
245 this.adblockPlusEnabled = !!data["enable"]; 250 this.adblockPlusEnabled = !!data["enable"];
246 return {"success": true}; 251 callback.onSuccess({});
252 return;
247 } 253 }
248 break; 254 break;
249 case "getAcceptableAdsEnabled": 255 case "getAcceptableAdsEnabled":
250 return {"success": true, "value": this.acceptableAdsEnabled}; 256 callback.onSuccess({"value": this.acceptableAdsEnabled});
257 return;
251 case "setAcceptableAdsEnabled": 258 case "setAcceptableAdsEnabled":
252 if ("enable" in data) 259 if ("enable" in data)
253 { 260 {
254 this.acceptableAdsEnabled = !!data["enable"]; 261 this.acceptableAdsEnabled = !!data["enable"];
255 return {"success": true}; 262 callback.onSuccess({});
263 return;
256 } 264 }
257 break; 265 break;
258 case "getSubscriptionsXml": 266 case "getSubscriptionsXml":
259 return {"success": true, "value": this.subscriptionsXml}; 267 callback.onSuccess({"value": this.subscriptionsXml});
268 return;
260 case "getActiveSubscriptions": 269 case "getActiveSubscriptions":
261 return {"success": true, "value": this.getActiveSubscriptions()}; 270 callback.onSuccess({"value": this.getActiveSubscriptions()});
271 return;
262 case "isSubscriptionListed": 272 case "isSubscriptionListed":
263 if ("url" in data) 273 if ("url" in data)
264 { 274 {
265 return {"success": true, 275 callback.onSuccess({"value": this.isSubscriptionListed(data["url"])} );
266 "value": this.isSubscriptionListed(data["url"])}; 276 return;
267 } 277 }
268 break; 278 break;
269 case "addSubscription": 279 case "addSubscription":
270 if ("url" in data) 280 if ("url" in data)
271 { 281 {
272 this.addSubscription(data["url"], data["title"]); 282 this.addSubscription(data["url"], data["title"]);
273 return {"success": true}; 283 callback.onSuccess({});
284 return;
274 } 285 }
275 break; 286 break;
276 case "removeSubscription": 287 case "removeSubscription":
277 if ("url" in data) 288 if ("url" in data)
278 { 289 {
279 this.removeSubscription(data["url"]); 290 this.removeSubscription(data["url"]);
280 return {"success": true}; 291 callback.onSuccess({});
292 return;
281 } 293 }
282 break; 294 break;
283 case "isLocal": 295 case "isLocal":
284 if ("url" in data) 296 if ("url" in data)
285 return {"success": true, 297 {
286 "value": this.isLocal(data["url"])}; 298 callback.onSuccess({"value": this.isLocal(data["url"])});
299 return;
300 }
287 break; 301 break;
288 case "isPageWhitelisted": 302 case "isPageWhitelisted":
289 if ("url" in data) 303 if ("url" in data)
290 return {"success": true, 304 {
291 "value": this.isPageWhitelisted(data["url"])}; 305 callback.onSuccess({"value": this.isPageWhitelisted(data["url"])});
306 return;
307 }
292 break; 308 break;
293 case "whitelistSite": 309 case "whitelistSite":
294 if ("url" in data && "whitelisted" in data) 310 if ("url" in data && "whitelisted" in data)
295 { 311 {
296 this.whitelistSite(data["url"], data["whitelisted"]); 312 this.whitelistSite(data["url"], data["whitelisted"]);
297 return {"success": true}; 313 callback.onSuccess({});
314 return;
298 } 315 }
299 break; 316 break;
300 } 317 }
301 return {"success": false, "error": "malformed request"}; 318 callback.onError("malformed request");
302 }).bind(this), "AdblockPlus:Api"); 319 }, "AdblockPlus:Api");
303 } 320 }
304 }; 321 };
OLDNEW
« 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