| 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 'use strict'; | |
| 11 | |
| 12 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 11 var remoting = remoting || {}; |
| 14 | 12 |
| 13 (function() { |
| 14 |
| 15 'use strict'; |
| 16 |
| 15 /** | 17 /** |
| 16 * @constructor | 18 * @constructor |
| 19 * @implements {base.Disposable} |
| 17 */ | 20 */ |
| 18 remoting.It2MeHostFacade = function() { | 21 remoting.It2MeHostFacade = function() { |
| 19 /** | 22 /** @private {number} */ |
| 20 * @type {number} | |
| 21 * @private | |
| 22 */ | |
| 23 this.nextId_ = 0; | 23 this.nextId_ = 0; |
| 24 | 24 |
| 25 /** | 25 /** @private {?chrome.runtime.Port} */ |
| 26 * @type {?chrome.runtime.Port} | |
| 27 * @private | |
| 28 */ | |
| 29 this.port_ = null; | 26 this.port_ = null; |
| 30 | 27 |
| 31 /** | 28 /** @private {string} */ |
| 32 * @type {string} | |
| 33 * @private | |
| 34 */ | |
| 35 this.accessCode_ = ''; | 29 this.accessCode_ = ''; |
| 36 | 30 |
| 37 /** | 31 /** @private {number} */ |
| 38 * @type {number} | |
| 39 * @private | |
| 40 */ | |
| 41 this.accessCodeLifetime_ = 0; | 32 this.accessCodeLifetime_ = 0; |
| 42 | 33 |
| 43 /** | 34 /** @private {string} */ |
| 44 * @type {string} | |
| 45 * @private | |
| 46 */ | |
| 47 this.clientId_ = ''; | 35 this.clientId_ = ''; |
| 48 | 36 |
| 49 /** | 37 /** @private {boolean} */ |
| 50 * @type {boolean} | |
| 51 * @private | |
| 52 */ | |
| 53 this.initialized_ = false; | 38 this.initialized_ = false; |
| 54 | 39 |
| 40 /** @private {base.Disposables} */ |
| 41 this.eventHooks_ = null; |
| 42 |
| 55 /** | 43 /** |
| 56 * @type {?function():void} | 44 * @type {?function():void} |
| 57 * @private | 45 * @private |
| 58 */ | 46 */ |
| 59 this.onInitialized_ = function() {}; | 47 this.onInitialized_ = function() {}; |
| 60 | 48 |
| 61 /** | 49 /** |
| 62 * Called if Native Messaging host has failed to start. | 50 * Called if Native Messaging host has failed to start. |
| 63 * @private | 51 * @private |
| 64 * */ | 52 * */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 */ | 66 */ |
| 79 this.onStateChanged_ = function() {}; | 67 this.onStateChanged_ = function() {}; |
| 80 | 68 |
| 81 /** | 69 /** |
| 82 * @type {?function(boolean):void} | 70 * @type {?function(boolean):void} |
| 83 * @private | 71 * @private |
| 84 */ | 72 */ |
| 85 this.onNatPolicyChanged_ = function() {}; | 73 this.onNatPolicyChanged_ = function() {}; |
| 86 }; | 74 }; |
| 87 | 75 |
| 76 remoting.It2MeHostFacade.prototype.dispose = function() { |
| 77 base.dispose(this.eventHooks_); |
| 78 this.eventHooks_ = null; |
| 79 if (this.port_) { |
| 80 this.port_.disconnect(); |
| 81 this.port_ = null; |
| 82 } |
| 83 }; |
| 84 |
| 88 /** | 85 /** |
| 89 * Sets up connection to the Native Messaging host process and exchanges | 86 * Sets up connection to the Native Messaging host process and exchanges |
| 90 * 'hello' messages. If Native Messaging is not supported or if the it2me | 87 * 'hello' messages. If Native Messaging is not supported or if the it2me |
| 91 * native messaging host is not installed, onInitializationFailed is invoked. | 88 * native messaging host is not installed, onInitializationFailed is invoked. |
| 92 * Otherwise, onInitialized is invoked. | 89 * Otherwise, onInitialized is invoked. |
| 93 * | 90 * |
| 94 * @param {function(*=):void} onInitialized Called after successful | 91 * @param {function(*=):void} onInitialized Called after successful |
| 95 * initialization. | 92 * initialization. |
| 96 * @param {function(*=):void} onInitializationFailed Called if cannot connect to | 93 * @param {function(*=):void} onInitializationFailed Called if cannot connect to |
| 97 * the native messaging host. | 94 * the native messaging host. |
| 98 * @return {void} | 95 * @return {void} |
| 99 */ | 96 */ |
| 100 remoting.It2MeHostFacade.prototype.initialize = | 97 remoting.It2MeHostFacade.prototype.initialize = |
| 101 function(onInitialized, onInitializationFailed) { | 98 function(onInitialized, onInitializationFailed) { |
| 102 this.onInitialized_ = onInitialized; | 99 this.onInitialized_ = onInitialized; |
| 103 this.onInitializationFailed_ = onInitializationFailed; | 100 this.onInitializationFailed_ = onInitializationFailed; |
| 104 | 101 |
| 105 try { | 102 try { |
| 106 this.port_ = chrome.runtime.connectNative( | 103 this.port_ = chrome.runtime.connectNative( |
| 107 'com.google.chrome.remote_assistance'); | 104 'com.google.chrome.remote_assistance'); |
| 108 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); | 105 this.eventHooks_ = new base.Disposables( |
| 109 this.port_.onDisconnect.addListener(this.onHostDisconnect_.bind(this)); | 106 new base.ChromeEventHook(this.port_.onMessage, |
| 107 this.onIncomingMessage_.bind(this)), |
| 108 new base.ChromeEventHook(this.port_.onDisconnect, |
| 109 this.onHostDisconnect_.bind(this))); |
| 110 this.port_.postMessage({type: 'hello'}); | 110 this.port_.postMessage({type: 'hello'}); |
| 111 } catch (/** @type {*} */ err) { | 111 } catch (/** @type {*} */ err) { |
| 112 console.log('Native Messaging initialization failed: ', err); | 112 console.log('Native Messaging initialization failed: ', err); |
| 113 onInitializationFailed(); | 113 onInitializationFailed(); |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * @param {string} email The user's email address. | 119 * @param {string} email The user's email address. |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // the host binary cannot be found we get the "Native host has exited" | 321 // the host binary cannot be found we get the "Native host has exited" |
| 322 // error. | 322 // error. |
| 323 console.log('Native Messaging initialization failed: ' + | 323 console.log('Native Messaging initialization failed: ' + |
| 324 chrome.runtime.lastError.message); | 324 chrome.runtime.lastError.message); |
| 325 this.onInitializationFailed_(); | 325 this.onInitializationFailed_(); |
| 326 } else { | 326 } else { |
| 327 console.error('Native Messaging port disconnected.'); | 327 console.error('Native Messaging port disconnected.'); |
| 328 this.port_ = null; | 328 this.port_ = null; |
| 329 this.onError_(remoting.Error.UNEXPECTED); | 329 this.onError_(remoting.Error.UNEXPECTED); |
| 330 } | 330 } |
| 331 } | 331 }; |
| 332 |
| 333 })(); |
| OLD | NEW |