Left: | ||
Right: |
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-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 modules.messaging = { | |
341 port: { | |
342 _eventEmitter: new EventEmitter(), | |
Sebastian Noack
2017/01/16 15:00:03
Couldn't you do it like that:
modules.messaging
kzar
2017/01/16 15:16:31
Done.
| |
343 on(name, callback) { this._eventEmitter.on(name, callback); }, | |
344 off(name, callback) { this._eventEmitter.off(name, callback); }, | |
345 _onMessage(event) | |
346 { | |
347 if (event.data.type != "message") | |
348 return; | |
349 let message = event.data.payload; | |
350 let messageId = event.data.messageId; | |
351 let sender = { | |
352 page: new ext.Page(event.source) | |
353 }; | |
354 | |
355 function reply(message) | |
356 { | |
357 event.source.postMessage({ | |
358 type: "response", | |
359 messageId: messageId, | |
360 payload: message | |
361 }, "*"); | |
362 } | |
363 | |
364 let port = modules.messaging.port; | |
365 let listeners = port._eventEmitter._listeners[message.type]; | |
366 if (!listeners) | |
367 return; | |
368 | |
369 for (let listener of listeners) | |
370 { | |
371 let response = listener(message, sender); | |
372 if (response && typeof response.then == "function") | |
373 { | |
374 response.then( | |
375 reply, | |
376 reason => { | |
377 console.error(reason); | |
378 reply(undefined); | |
379 } | |
380 ); | |
381 } | |
382 else if (typeof response != "undefined") | |
383 { | |
384 reply(response); | |
385 } | |
386 } | |
387 } | |
388 } | |
389 }; | |
390 window.addEventListener("message", modules.messaging.port._onMessage); | |
391 | |
340 global.Services = { | 392 global.Services = { |
341 vc: { | 393 vc: { |
342 compare: function(v1, v2) | 394 compare: function(v1, v2) |
343 { | 395 { |
344 return parseFloat(v1) - parseFloat(v2); | 396 return parseFloat(v1) - parseFloat(v2); |
345 } | 397 } |
346 } | 398 } |
347 }; | 399 }; |
348 | 400 |
349 var filters = [ | 401 var filters = [ |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 | 530 |
479 if (params.safariContentBlocker) | 531 if (params.safariContentBlocker) |
480 { | 532 { |
481 global.safari = { | 533 global.safari = { |
482 extension: { | 534 extension: { |
483 setContentBlocker: function() {} | 535 setContentBlocker: function() {} |
484 } | 536 } |
485 }; | 537 }; |
486 } | 538 } |
487 })(this); | 539 })(this); |
OLD | NEW |