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

Side by Side Diff: lib/utils.js

Issue 29338425: Issue 3499 - Remove old messaging API (Closed)
Patch Set: Created March 16, 2016, 12:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/main.js ('K') | « lib/main.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 if (label != origLabel) 506 if (label != origLabel)
507 element.setAttribute(attr, label); 507 element.setAttribute(attr, label);
508 if (accesskey != "") 508 if (accesskey != "")
509 element.setAttribute("accesskey", accesskey); 509 element.setAttribute("accesskey", accesskey);
510 510
511 // Labels forward changes of the accessKey property to their control, only 511 // Labels forward changes of the accessKey property to their control, only
512 // set it for actual controls. 512 // set it for actual controls.
513 if (element.localName != "label") 513 if (element.localName != "label")
514 element.accessKey = accesskey; 514 element.accessKey = accesskey;
515 } 515 }
516 },
517
518 /**
519 * Adds a message handler that will respond to both synchronous and
520 * asynchonous messages.
521 * @param {string} messageName name of the message to listen to
522 * @param {Function} handler handler to be called with the message data. The
523 * return value will be sent back to the child.
524 */
525 addChildMessageListener: function(messageName, handler)
526 {
527 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
528 .getService(Ci.nsIMessageListenerManager);
529 let wrapper = (message) => {
530 let {callbackID, data} = message.data;
531 let response = undefined;
532 try
533 {
534 response = handler(data);
535 }
536 catch (e)
537 {
538 Cu.reportError(e);
539 }
540
541 if (callbackID)
542 {
543 let target = message.target.QueryInterface(Ci.nsIMessageSender);
544 target.sendAsyncMessage("AdblockPlus:Response", {
545 callbackID,
546 response
547 });
548 }
549 else
550 return response;
551 };
552 messageManager.addMessageListener(messageName, wrapper);
553 onShutdown.add(() => messageManager.removeMessageListener(messageName, wrapp er));
554 } 516 }
555 }; 517 };
556 518
557 /** 519 /**
558 * A cache with a fixed capacity, newer entries replace entries that have been 520 * A cache with a fixed capacity, newer entries replace entries that have been
559 * stored first. 521 * stored first.
560 * @constructor 522 * @constructor
561 */ 523 */
562 function Cache(/**Integer*/ size) 524 function Cache(/**Integer*/ size)
563 { 525 {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 Cu.reportError(e); 766 Cu.reportError(e);
805 // Expected, ctypes isn't supported in Gecko 1.9.2 767 // Expected, ctypes isn't supported in Gecko 1.9.2
806 return null; 768 return null;
807 } 769 }
808 }); 770 });
809 771
810 if ("@mozilla.org/messenger/headerparser;1" in Cc) 772 if ("@mozilla.org/messenger/headerparser;1" in Cc)
811 XPCOMUtils.defineLazyServiceGetter(Utils, "headerParser", "@mozilla.org/messen ger/headerparser;1", "nsIMsgHeaderParser"); 773 XPCOMUtils.defineLazyServiceGetter(Utils, "headerParser", "@mozilla.org/messen ger/headerparser;1", "nsIMsgHeaderParser");
812 else 774 else
813 Utils.headerParser = null; 775 Utils.headerParser = null;
OLDNEW
« lib/main.js ('K') | « lib/main.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld