| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview | 6 * @fileoverview |
| 7 * Class to communicate with the It2me Host component via Native Messaging. | 7 * Class to communicate with the It2me Host component via Native Messaging. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 */ | 56 */ |
| 57 this.onError_ = function(error) {}; | 57 this.onError_ = function(error) {}; |
| 58 | 58 |
| 59 /** @private {?function(remoting.HostSession.State):void} */ | 59 /** @private {?function(remoting.HostSession.State):void} */ |
| 60 this.onStateChanged_ = function() {}; | 60 this.onStateChanged_ = function() {}; |
| 61 | 61 |
| 62 /** @private {?function(boolean):void} */ | 62 /** @private {?function(boolean):void} */ |
| 63 this.onNatPolicyChanged_ = function() {}; | 63 this.onNatPolicyChanged_ = function() {}; |
| 64 | 64 |
| 65 /** @private */ | 65 /** @private */ |
| 66 this.hostVersion_ = ''; |
| 67 |
| 68 /** @private */ |
| 66 this.debugMessageHandler_ = | 69 this.debugMessageHandler_ = |
| 67 new remoting.NativeMessageHostDebugMessageHandler(); | 70 new remoting.NativeMessageHostDebugMessageHandler(); |
| 68 | 71 |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 remoting.It2MeHostFacade.prototype.dispose = function() { | 74 remoting.It2MeHostFacade.prototype.dispose = function() { |
| 72 base.dispose(this.eventHooks_); | 75 base.dispose(this.eventHooks_); |
| 73 this.eventHooks_ = null; | 76 this.eventHooks_ = null; |
| 74 if (this.port_) { | 77 if (this.port_) { |
| 75 this.port_.disconnect(); | 78 this.port_.disconnect(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 }; | 201 }; |
| 199 | 202 |
| 200 /** | 203 /** |
| 201 * @return {string} | 204 * @return {string} |
| 202 */ | 205 */ |
| 203 remoting.It2MeHostFacade.prototype.getClient = function() { | 206 remoting.It2MeHostFacade.prototype.getClient = function() { |
| 204 return this.clientId_; | 207 return this.clientId_; |
| 205 }; | 208 }; |
| 206 | 209 |
| 207 /** | 210 /** |
| 211 * @return {string} |
| 212 */ |
| 213 remoting.It2MeHostFacade.prototype.getHostVersion = function() { |
| 214 return this.hostVersion_; |
| 215 }; |
| 216 |
| 217 |
| 218 /** |
| 208 * Handler for incoming messages. | 219 * Handler for incoming messages. |
| 209 * | 220 * |
| 210 * @param {Object} message The received message. | 221 * @param {Object} message The received message. |
| 211 * @return {void} | 222 * @return {void} |
| 212 * @private | 223 * @private |
| 213 */ | 224 */ |
| 214 remoting.It2MeHostFacade.prototype.onIncomingMessage_ = | 225 remoting.It2MeHostFacade.prototype.onIncomingMessage_ = |
| 215 function(message) { | 226 function(message) { |
| 216 if (this.debugMessageHandler_.handleMessage(message)) { | 227 if (this.debugMessageHandler_.handleMessage(message)) { |
| 217 return; | 228 return; |
| 218 } | 229 } |
| 219 | 230 |
| 220 var type = base.getStringAttr(message, 'type'); | 231 var type = base.getStringAttr(message, 'type'); |
| 221 | 232 |
| 222 switch (type) { | 233 switch (type) { |
| 223 case 'helloResponse': | 234 case 'helloResponse': |
| 224 var version = base.getStringAttr(message, 'version'); | 235 this.hostVersion_ = base.getStringAttr(message, 'version'); |
| 225 console.log('Host version: ', version); | 236 console.log('Host version: ', this.hostVersion_); |
| 226 this.initialized_ = true; | 237 this.initialized_ = true; |
| 227 // A "hello" request is sent immediately after the native messaging host | 238 // A "hello" request is sent immediately after the native messaging host |
| 228 // is started. We can proceed to the next task once we receive the | 239 // is started. We can proceed to the next task once we receive the |
| 229 // "helloReponse". | 240 // "helloReponse". |
| 230 if (this.onInitialized_) { | 241 if (this.onInitialized_) { |
| 231 this.onInitialized_(); | 242 this.onInitialized_(); |
| 232 } | 243 } |
| 233 break; | 244 break; |
| 234 | 245 |
| 235 case 'connectResponse': | 246 case 'connectResponse': |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 chrome.runtime.lastError.message); | 336 chrome.runtime.lastError.message); |
| 326 this.onInitializationFailed_(); | 337 this.onInitializationFailed_(); |
| 327 } else { | 338 } else { |
| 328 console.error('Native Messaging port disconnected.'); | 339 console.error('Native Messaging port disconnected.'); |
| 329 this.port_ = null; | 340 this.port_ = null; |
| 330 this.onError_(remoting.Error.unexpected()); | 341 this.onError_(remoting.Error.unexpected()); |
| 331 } | 342 } |
| 332 }; | 343 }; |
| 333 | 344 |
| 334 })(); | 345 })(); |
| OLD | NEW |