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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 applicationVersion: "34.0", | 330 applicationVersion: "34.0", |
331 addonName: "adblockplus", | 331 addonName: "adblockplus", |
332 addonVersion: "2.6.7" | 332 addonVersion: "2.6.7" |
333 }; | 333 }; |
334 updateFromURL(modules.info); | 334 updateFromURL(modules.info); |
335 | 335 |
336 modules.subscriptionInit = { | 336 modules.subscriptionInit = { |
337 reinitialized: params.filterlistsReinitialized | 337 reinitialized: params.filterlistsReinitialized |
338 }; | 338 }; |
339 | 339 |
340 let messageListeners = {}; | |
341 modules.messaging = { | 340 modules.messaging = { |
Sebastian Noack
2017/01/13 12:12:10
Can you please just use the EventEmitter class her
kzar
2017/01/16 04:27:02
Well I'm not sure I can since the EventEmitter cla
Sebastian Noack
2017/01/16 13:46:38
See line 20 in this file. There is a class called
kzar
2017/01/16 14:25:56
Oh yea, sorry I missed that. Done.
| |
342 port: { | 341 port: new EventEmitter() |
343 on: (name, callback) => | 342 }; |
344 { | 343 |
345 if (!(name in messageListeners)) | |
346 messageListeners[name] = []; | |
347 messageListeners[name].push(callback); | |
348 }, | |
349 off: (name, callback) => | |
350 { | |
351 if (!(name in messageListeners)) | |
352 return; | |
353 | |
354 let index = messageListeners[name].indexOf(callback); | |
355 if (index == -1) | |
356 return; | |
357 | |
358 if (messageListeners[name].length == 1) | |
359 delete messageListeners[name]; | |
360 else | |
361 messageListeners[name].splice(index, 1); | |
362 } | |
363 } | |
364 }; | |
365 window.addEventListener("message", event => | 344 window.addEventListener("message", event => |
366 { | 345 { |
367 if (event.data.type != "message") | 346 if (event.data.type != "message") |
368 return; | 347 return; |
369 let message = event.data.payload; | 348 let message = event.data.payload; |
370 let messageId = event.data.messageId; | 349 let messageId = event.data.messageId; |
371 let sender = { | 350 let sender = { |
372 page: new ext.Page(event.source) | 351 page: new ext.Page(event.source) |
373 }; | 352 }; |
374 | 353 |
375 let listeners = messageListeners[message.type]; | 354 let listeners = modules.messaging.port._listeners[message.type]; |
376 if (!listeners) | 355 if (!listeners) |
377 return; | 356 return; |
378 | 357 |
379 function reply(message) | 358 function reply(message) |
380 { | 359 { |
381 event.source.postMessage({ | 360 event.source.postMessage({ |
382 type: "response", | 361 type: "response", |
383 messageId: messageId, | 362 messageId: messageId, |
384 payload: message | 363 payload: message |
385 }, "*"); | 364 }, "*"); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 | 525 |
547 if (params.safariContentBlocker) | 526 if (params.safariContentBlocker) |
548 { | 527 { |
549 global.safari = { | 528 global.safari = { |
550 extension: { | 529 extension: { |
551 setContentBlocker: function() {} | 530 setContentBlocker: function() {} |
552 } | 531 } |
553 }; | 532 }; |
554 } | 533 } |
555 })(this); | 534 })(this); |
LEFT | RIGHT |