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: Created Jan. 11, 2017, 8:38 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:
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
(no file at all)
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 application: "firefox", 329 application: "firefox",
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
340 modules.messaging = {
341 port: new EventEmitter()
342 };
343
344 window.addEventListener("message", event =>
345 {
346 if (event.data.type != "message")
347 return;
348 let message = event.data.payload;
349 let messageId = event.data.messageId;
350 let sender = {
351 page: new ext.Page(event.source)
352 };
353
354 let listeners = modules.messaging.port._listeners[message.type];
355 if (!listeners)
356 return;
357
358 function reply(message)
359 {
360 event.source.postMessage({
361 type: "response",
362 messageId: messageId,
363 payload: message
364 }, "*");
365 }
366
367 for (let listener of listeners)
368 {
369 let response = listener(message, sender);
370 if (response && typeof response.then == "function")
371 {
372 response.then(
373 reply,
374 reason => {
375 console.error(reason);
376 reply(undefined);
377 }
378 );
379 }
380 else if (typeof response != "undefined")
381 {
382 reply(response);
383 }
384 }
385 });
339 386
340 global.Services = { 387 global.Services = {
341 vc: { 388 vc: {
342 compare: function(v1, v2) 389 compare: function(v1, v2)
343 { 390 {
344 return parseFloat(v1) - parseFloat(v2); 391 return parseFloat(v1) - parseFloat(v2);
345 } 392 }
346 } 393 }
347 }; 394 };
348 395
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 525
479 if (params.safariContentBlocker) 526 if (params.safariContentBlocker)
480 { 527 {
481 global.safari = { 528 global.safari = {
482 extension: { 529 extension: {
483 setContentBlocker: function() {} 530 setContentBlocker: function() {}
484 } 531 }
485 }; 532 };
486 } 533 }
487 })(this); 534 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld