| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Channel to the background script. | 6 * Channel to the background script. |
| 7 */ | 7 */ |
| 8 function Channel() { | 8 function Channel() { |
| 9 this.messageCallbacks_ = {}; |
| 10 this.internalRequestCallbacks_ = {}; |
| 9 } | 11 } |
| 10 | 12 |
| 11 /** @const */ | 13 /** @const */ |
| 12 Channel.INTERNAL_REQUEST_MESSAGE = 'internal-request-message'; | 14 Channel.INTERNAL_REQUEST_MESSAGE = 'internal-request-message'; |
| 13 | 15 |
| 14 /** @const */ | 16 /** @const */ |
| 15 Channel.INTERNAL_REPLY_MESSAGE = 'internal-reply-message'; | 17 Channel.INTERNAL_REPLY_MESSAGE = 'internal-reply-message'; |
| 16 | 18 |
| 17 Channel.prototype = { | 19 Channel.prototype = { |
| 18 // Message port to use to communicate with background script. | 20 // Message port to use to communicate with background script. |
| 19 port_: null, | 21 port_: null, |
| 20 | 22 |
| 21 // Registered message callbacks. | 23 // Registered message callbacks. |
| 22 messageCallbacks_: {}, | 24 messageCallbacks_: null, |
| 23 | 25 |
| 24 // Internal request id to track pending requests. | 26 // Internal request id to track pending requests. |
| 25 nextInternalRequestId_: 0, | 27 nextInternalRequestId_: 0, |
| 26 | 28 |
| 27 // Pending internal request callbacks. | 29 // Pending internal request callbacks. |
| 28 internalRequestCallbacks_: {}, | 30 internalRequestCallbacks_: null, |
| 29 | 31 |
| 30 /** | 32 /** |
| 31 * Initialize the channel with given port for the background script. | 33 * Initialize the channel with given port for the background script. |
| 32 */ | 34 */ |
| 33 init: function(port) { | 35 init: function(port) { |
| 34 this.port_ = port; | 36 this.port_ = port; |
| 35 this.port_.onMessage.addListener(this.onMessage_.bind(this)); | 37 this.port_.onMessage.addListener(this.onMessage_.bind(this)); |
| 36 }, | 38 }, |
| 37 | 39 |
| 38 /** | 40 /** |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 112 } |
| 111 }; | 113 }; |
| 112 | 114 |
| 113 /** | 115 /** |
| 114 * Class factory. | 116 * Class factory. |
| 115 * @return {Channel} | 117 * @return {Channel} |
| 116 */ | 118 */ |
| 117 Channel.create = function() { | 119 Channel.create = function() { |
| 118 return new Channel(); | 120 return new Channel(); |
| 119 }; | 121 }; |
| OLD | NEW |