OLD | NEW |
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 Loading... |
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 Loading... |
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 return; |
| 236 } |
234 | 237 |
235 if (!this.filtersLoaded) | 238 if (!this.filtersLoaded) |
236 return {"success": false, "error": "filters not loaded"}; | 239 { |
| 240 callback.onError("filters not loaded"); |
| 241 return; |
| 242 } |
237 | 243 |
238 switch (data["action"]) | 244 switch (data["action"]) |
239 { | 245 { |
240 case "getAdblockPlusEnabled": | 246 case "getAdblockPlusEnabled": |
241 return {"success": true, "value": this.adblockPlusEnabled}; | 247 callback.onSuccess({"value": this.adblockPlusEnabled}); |
| 248 return; |
242 case "setAdblockPlusEnabled": | 249 case "setAdblockPlusEnabled": |
243 if ("enable" in data) | 250 if ("enable" in data) |
244 { | 251 { |
245 this.adblockPlusEnabled = !!data["enable"]; | 252 this.adblockPlusEnabled = !!data["enable"]; |
246 return {"success": true}; | 253 callback.onSuccess({}); |
| 254 return; |
247 } | 255 } |
248 break; | 256 break; |
249 case "getAcceptableAdsEnabled": | 257 case "getAcceptableAdsEnabled": |
250 return {"success": true, "value": this.acceptableAdsEnabled}; | 258 callback.onSuccess({"value": this.acceptableAdsEnabled}); |
| 259 return; |
251 case "setAcceptableAdsEnabled": | 260 case "setAcceptableAdsEnabled": |
252 if ("enable" in data) | 261 if ("enable" in data) |
253 { | 262 { |
254 this.acceptableAdsEnabled = !!data["enable"]; | 263 this.acceptableAdsEnabled = !!data["enable"]; |
255 return {"success": true}; | 264 callback.onSuccess({}); |
| 265 return; |
256 } | 266 } |
257 break; | 267 break; |
258 case "getSubscriptionsXml": | 268 case "getSubscriptionsXml": |
259 return {"success": true, "value": this.subscriptionsXml}; | 269 callback.onSuccess({"value": this.subscriptionsXml}); |
| 270 return; |
260 case "getActiveSubscriptions": | 271 case "getActiveSubscriptions": |
261 return {"success": true, "value": this.getActiveSubscriptions()}; | 272 callback.onSuccess({"value": this.getActiveSubscriptions()}); |
| 273 return; |
262 case "isSubscriptionListed": | 274 case "isSubscriptionListed": |
263 if ("url" in data) | 275 if ("url" in data) |
264 { | 276 { |
265 return {"success": true, | 277 callback.onSuccess({"value": this.isSubscriptionListed(data["url"])}
); |
266 "value": this.isSubscriptionListed(data["url"])}; | 278 return; |
267 } | 279 } |
268 break; | 280 break; |
269 case "addSubscription": | 281 case "addSubscription": |
270 if ("url" in data) | 282 if ("url" in data) |
271 { | 283 { |
272 this.addSubscription(data["url"], data["title"]); | 284 this.addSubscription(data["url"], data["title"]); |
273 return {"success": true}; | 285 callback.onSuccess({}); |
| 286 return; |
274 } | 287 } |
275 break; | 288 break; |
276 case "removeSubscription": | 289 case "removeSubscription": |
277 if ("url" in data) | 290 if ("url" in data) |
278 { | 291 { |
279 this.removeSubscription(data["url"]); | 292 this.removeSubscription(data["url"]); |
280 return {"success": true}; | 293 callback.onSuccess({}); |
| 294 return; |
281 } | 295 } |
282 break; | 296 break; |
283 case "isLocal": | 297 case "isLocal": |
284 if ("url" in data) | 298 if ("url" in data) |
285 return {"success": true, | 299 { |
286 "value": this.isLocal(data["url"])}; | 300 callback.onSuccess({"value": this.isLocal(data["url"])}); |
| 301 return; |
| 302 } |
287 break; | 303 break; |
288 case "isPageWhitelisted": | 304 case "isPageWhitelisted": |
289 if ("url" in data) | 305 if ("url" in data) |
290 return {"success": true, | 306 { |
291 "value": this.isPageWhitelisted(data["url"])}; | 307 callback.onSuccess({"value": this.isPageWhitelisted(data["url"])}); |
| 308 return; |
| 309 } |
292 break; | 310 break; |
293 case "whitelistSite": | 311 case "whitelistSite": |
294 if ("url" in data && "whitelisted" in data) | 312 if ("url" in data && "whitelisted" in data) |
295 { | 313 { |
296 this.whitelistSite(data["url"], data["whitelisted"]); | 314 this.whitelistSite(data["url"], data["whitelisted"]); |
297 return {"success": true}; | 315 callback.onSuccess({}); |
| 316 return; |
298 } | 317 } |
299 break; | 318 break; |
300 } | 319 } |
301 return {"success": false, "error": "malformed request"}; | 320 callback.onError("malformed request"); |
302 }).bind(this), "AdblockPlus:Api"); | 321 }, "AdblockPlus:Api"); |
303 } | 322 } |
304 }; | 323 }; |
OLD | NEW |