Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 var changeListeners = new global.ext.PageMap(); | 55 var changeListeners = new global.ext.PageMap(); |
56 var listenedPreferences = []; | 56 var listenedPreferences = []; |
57 var listenedFilterChanges = []; | 57 var listenedFilterChanges = []; |
58 var messageTypes = { | 58 var messageTypes = { |
59 "app": "app.listen", | 59 "app": "app.listen", |
60 "filter": "filters.listen", | 60 "filter": "filters.listen", |
61 "pref": "prefs.listen", | 61 "pref": "prefs.listen", |
62 "subscription": "subscriptions.listen" | 62 "subscription": "subscriptions.listen" |
63 }; | 63 }; |
64 | 64 |
65 function sendMessage(type, action) | 65 function sendMessage(type, action) |
Sebastian Noack
2016/03/23 23:15:51
Sorry for refactoring sendMessage() again, but wit
| |
66 { | 66 { |
67 var pages = changeListeners.keys(); | 67 var pages = changeListeners.keys(); |
68 if (pages.length == 0) | 68 if (pages.length == 0) |
69 return; | 69 return; |
70 | 70 |
71 var args = []; | 71 var args = []; |
72 for (var i = 2; i < arguments.length; i++) | 72 for (var i = 2; i < arguments.length; i++) |
73 { | 73 { |
74 var arg = arguments[i]; | 74 var arg = arguments[i]; |
75 if (arg instanceof Subscription) | 75 if (arg instanceof Subscription) |
(...skipping 13 matching lines...) Expand all Loading... | |
89 { | 89 { |
90 page.sendMessage({ | 90 page.sendMessage({ |
91 type: messageTypes[type], | 91 type: messageTypes[type], |
92 action: action, | 92 action: action, |
93 args: args | 93 args: args |
94 }); | 94 }); |
95 } | 95 } |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 function addFilterListeners(type, actions) | 99 function addFilterListeners(type, actions) |
Sebastian Noack
2016/03/23 23:15:51
Same pattern as for Prefs.on(), the first UI that
| |
100 { | 100 { |
101 actions.forEach(function(action) | 101 actions.forEach(function(action) |
102 { | 102 { |
103 var name; | 103 var name; |
104 if (type == "filter" && action == "loaded") | 104 if (type == "filter" && action == "loaded") |
105 name = "load"; | 105 name = "load"; |
106 else | 106 else |
107 name = type + "." + action; | 107 name = type + "." + action; |
108 | 108 |
109 if (listenedFilterChanges.indexOf(name) == -1) | 109 if (listenedFilterChanges.indexOf(name) == -1) |
110 { | 110 { |
111 listenedFilterChanges.push(name); | 111 listenedFilterChanges.push(name); |
112 FilterNotifier.on(name, function() | 112 FilterNotifier.on(name, function() |
113 { | 113 { |
114 var args = [type, action]; | 114 var args = [type, action]; |
115 for (var i = 0; i < arguments.length; i++) | 115 for (var i = 0; i < arguments.length; i++) |
Sebastian Noack
2016/03/23 23:15:51
For the record, simply passing the arguments objec
| |
116 args.push(arguments[i]); | 116 args.push(arguments[i]); |
117 sendMessage.apply(null, args); | 117 sendMessage.apply(null, args); |
118 }); | 118 }); |
119 } | 119 } |
120 }); | 120 }); |
121 } | 121 } |
122 | 122 |
123 function getListenerFilters(page) | 123 function getListenerFilters(page) |
124 { | 124 { |
125 var listenerFilters = changeListeners.get(page); | 125 var listenerFilters = changeListeners.get(page); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 devToolsPanel: info.platform == "chromium", | 178 devToolsPanel: info.platform == "chromium", |
179 safariContentBlocker: "safari" in global | 179 safariContentBlocker: "safari" in global |
180 && "extension" in global.safari | 180 && "extension" in global.safari |
181 && "setContentBlocker" in global.safari.extension | 181 && "setContentBlocker" in global.safari.extension |
182 }); | 182 }); |
183 } | 183 } |
184 else | 184 else |
185 callback(null); | 185 callback(null); |
186 break; | 186 break; |
187 case "app.listen": | 187 case "app.listen": |
188 var listenerFilters = getListenerFilters(sender.page); | 188 getListenerFilters(sender.page).app = message.filter; |
189 if (message.filter) | |
190 listenerFilters.app = message.filter; | |
191 else | |
192 delete listenerFilters.app; | |
193 break; | 189 break; |
194 case "app.open": | 190 case "app.open": |
195 if (message.what == "options") | 191 if (message.what == "options") |
196 ext.showOptions(); | 192 ext.showOptions(); |
197 break; | 193 break; |
198 case "filters.add": | 194 case "filters.add": |
199 var result = require("filterValidation").parseFilter(message.text); | 195 var result = require("filterValidation").parseFilter(message.text); |
200 var errors = []; | 196 var errors = []; |
201 if (result.error) | 197 if (result.error) |
202 errors.push(result.error.toString()); | 198 errors.push(result.error.toString()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 var filter = subscription.filters[j]; | 275 var filter = subscription.filters[j]; |
280 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) | 276 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
281 continue; | 277 continue; |
282 | 278 |
283 if (!(filter.text in seenFilter)) | 279 if (!(filter.text in seenFilter)) |
284 FilterStorage.removeFilter(filter); | 280 FilterStorage.removeFilter(filter); |
285 } | 281 } |
286 } | 282 } |
287 break; | 283 break; |
288 case "filters.listen": | 284 case "filters.listen": |
289 var listenerFilters = getListenerFilters(sender.page); | 285 getListenerFilters(sender.page).filter = message.filter; |
290 if (message.filter) | 286 addFilterListeners("filter", message.filter); |
291 { | |
292 addFilterListeners("filter", message.filter); | |
293 listenerFilters.filter = message.filter; | |
294 } | |
295 else | |
296 delete listenerFilters.filter; | |
297 break; | 287 break; |
298 case "filters.remove": | 288 case "filters.remove": |
299 var filter = Filter.fromText(message.text); | 289 var filter = Filter.fromText(message.text); |
300 var subscription = null; | 290 var subscription = null; |
301 if (message.subscriptionUrl) | 291 if (message.subscriptionUrl) |
302 subscription = Subscription.fromURL(message.subscriptionUrl); | 292 subscription = Subscription.fromURL(message.subscriptionUrl); |
303 | 293 |
304 if (!subscription) | 294 if (!subscription) |
305 FilterStorage.removeFilter(filter); | 295 FilterStorage.removeFilter(filter); |
306 else | 296 else |
307 FilterStorage.removeFilter(filter, subscription, message.index); | 297 FilterStorage.removeFilter(filter, subscription, message.index); |
308 break; | 298 break; |
309 case "prefs.get": | 299 case "prefs.get": |
310 callback(Prefs[message.key]); | 300 callback(Prefs[message.key]); |
311 break; | 301 break; |
312 case "prefs.listen": | 302 case "prefs.listen": |
313 var listenerFilters = getListenerFilters(sender.page); | 303 getListenerFilters(sender.page).pref = message.filter; |
314 if (message.filter) | 304 message.filter.forEach(function(preference) |
315 { | 305 { |
316 message.filter.forEach(function(preference) | 306 if (listenedPreferences.indexOf(preference) == -1) |
317 { | 307 { |
318 if (listenedPreferences.indexOf(preference) == -1) | 308 listenedPreferences.push(preference); |
309 Prefs.on(preference, function() | |
319 { | 310 { |
320 listenedPreferences.push(preference); | 311 sendMessage("pref", preference, Prefs[preference]); |
321 Prefs.on(preference, function() | 312 }); |
322 { | 313 } |
323 sendMessage("pref", preference, Prefs[preference]); | 314 }); |
324 }); | |
325 } | |
326 }); | |
327 listenerFilters.pref = message.filter; | |
328 } | |
329 else | |
330 delete listenerFilters.pref; | |
331 break; | 315 break; |
332 case "prefs.toggle": | 316 case "prefs.toggle": |
333 if (message.key == "notifications_ignoredcategories") | 317 if (message.key == "notifications_ignoredcategories") |
334 NotificationStorage.toggleIgnoreCategory("*"); | 318 NotificationStorage.toggleIgnoreCategory("*"); |
335 else | 319 else |
336 Prefs[message.key] = !Prefs[message.key]; | 320 Prefs[message.key] = !Prefs[message.key]; |
337 break; | 321 break; |
338 case "subscriptions.add": | 322 case "subscriptions.add": |
339 var subscription = Subscription.fromURL(message.url); | 323 var subscription = Subscription.fromURL(message.url); |
340 if ("title" in message) | 324 if ("title" in message) |
(...skipping 24 matching lines...) Expand all Loading... | |
365 return false; | 349 return false; |
366 if (s instanceof DownloadableSubscription && message.downloadable) | 350 if (s instanceof DownloadableSubscription && message.downloadable) |
367 return true; | 351 return true; |
368 if (s instanceof SpecialSubscription && message.special) | 352 if (s instanceof SpecialSubscription && message.special) |
369 return true; | 353 return true; |
370 return false; | 354 return false; |
371 }); | 355 }); |
372 callback(subscriptions.map(convertSubscription)); | 356 callback(subscriptions.map(convertSubscription)); |
373 break; | 357 break; |
374 case "subscriptions.listen": | 358 case "subscriptions.listen": |
375 var listenerFilters = getListenerFilters(sender.page); | 359 getListenerFilters(sender.page).subscription = message.filter; |
376 if (message.filter) | 360 addFilterListeners("subscription", message.filter); |
377 { | |
378 addFilterListeners("subscription", message.filter); | |
379 listenerFilters.subscription = message.filter; | |
380 } | |
381 else | |
382 delete listenerFilters.subscription; | |
383 break; | 361 break; |
384 case "subscriptions.remove": | 362 case "subscriptions.remove": |
385 var subscription = Subscription.fromURL(message.url); | 363 var subscription = Subscription.fromURL(message.url); |
386 if (subscription.url in FilterStorage.knownSubscriptions) | 364 if (subscription.url in FilterStorage.knownSubscriptions) |
387 FilterStorage.removeSubscription(subscription); | 365 FilterStorage.removeSubscription(subscription); |
388 break; | 366 break; |
389 case "subscriptions.toggle": | 367 case "subscriptions.toggle": |
390 var subscription = Subscription.fromURL(message.url); | 368 var subscription = Subscription.fromURL(message.url); |
391 if (subscription.url in FilterStorage.knownSubscriptions) | 369 if (subscription.url in FilterStorage.knownSubscriptions) |
392 { | 370 { |
(...skipping 21 matching lines...) Expand all Loading... | |
414 if (subscription instanceof DownloadableSubscription) | 392 if (subscription instanceof DownloadableSubscription) |
415 Synchronizer.execute(subscription, true); | 393 Synchronizer.execute(subscription, true); |
416 } | 394 } |
417 break; | 395 break; |
418 case "subscriptions.isDownloading": | 396 case "subscriptions.isDownloading": |
419 callback(Synchronizer.isExecuting(message.url)); | 397 callback(Synchronizer.isExecuting(message.url)); |
420 break; | 398 break; |
421 } | 399 } |
422 }); | 400 }); |
423 })(this); | 401 })(this); |
LEFT | RIGHT |