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

Delta Between Two Patch Sets: background.js

Issue 29370996: Issue 4783 - Use Port API for the messageResponder (Closed)
Left Patch Set: Add polyfilly for messaging API to background.js Created Jan. 13, 2017, 8 a.m.
Right Patch Set: Improve messaging implementation in background.js Created Jan. 16, 2017, 3:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | messageResponder.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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
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);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld