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'; | 10 'use strict'; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 /** | 61 /** |
62 * Called if Native Messaging host has failed to start. | 62 * Called if Native Messaging host has failed to start. |
63 * @private | 63 * @private |
64 * */ | 64 * */ |
65 this.onInitializationFailed_ = function() {}; | 65 this.onInitializationFailed_ = function() {}; |
66 | 66 |
67 /** | 67 /** |
68 * Called if the It2Me Native Messaging host sends a malformed message: | 68 * Called if the It2Me Native Messaging host sends a malformed message: |
69 * missing required attributes, attributes with incorrect types, etc. | 69 * missing required attributes, attributes with incorrect types, etc. |
70 * @param {remoting.Error} error | 70 * @type {?function(remoting.Error):void} |
71 * @private | 71 * @private |
72 */ | 72 */ |
73 this.onError_ = function(error) {}; | 73 this.onError_ = function(error) {}; |
74 | 74 |
75 /** | 75 /** |
76 * @type {?function(remoting.HostSession.State):void} | 76 * @type {?function(remoting.HostSession.State):void} |
77 * @private | 77 * @private |
78 */ | 78 */ |
79 this.onStateChanged_ = function() {}; | 79 this.onStateChanged_ = function() {}; |
80 | 80 |
81 /** | 81 /** |
82 * @type {?function(boolean):void} | 82 * @type {?function(boolean):void} |
83 * @private | 83 * @private |
84 */ | 84 */ |
85 this.onNatPolicyChanged_ = function() {}; | 85 this.onNatPolicyChanged_ = function() {}; |
86 }; | 86 }; |
87 | 87 |
88 /** | 88 /** |
89 * Sets up connection to the Native Messaging host process and exchanges | 89 * Sets up connection to the Native Messaging host process and exchanges |
90 * 'hello' messages. If Native Messaging is not supported or if the it2me | 90 * 'hello' messages. If Native Messaging is not supported or if the it2me |
91 * native messaging host is not installed, onInitializationFailed is invoked. | 91 * native messaging host is not installed, onInitializationFailed is invoked. |
92 * Otherwise, onInitialized is invoked. | 92 * Otherwise, onInitialized is invoked. |
93 * | 93 * |
94 * @param {function():void} onInitialized Called after successful | 94 * @param {function(*=):void} onInitialized Called after successful |
95 * initialization. | 95 * initialization. |
96 * @param {function():void} onInitializationFailed Called if cannot connect to | 96 * @param {function(*=):void} onInitializationFailed Called if cannot connect to |
97 * the native messaging host. | 97 * the native messaging host. |
98 * @return {void} | 98 * @return {void} |
99 */ | 99 */ |
100 remoting.It2MeHostFacade.prototype.initialize = | 100 remoting.It2MeHostFacade.prototype.initialize = |
101 function(onInitialized, onInitializationFailed) { | 101 function(onInitialized, onInitializationFailed) { |
102 this.onInitialized_ = onInitialized; | 102 this.onInitialized_ = onInitialized; |
103 this.onInitializationFailed_ = onInitializationFailed; | 103 this.onInitializationFailed_ = onInitializationFailed; |
104 | 104 |
105 try { | 105 try { |
106 this.port_ = chrome.runtime.connectNative( | 106 this.port_ = chrome.runtime.connectNative( |
107 'com.google.chrome.remote_assistance'); | 107 'com.google.chrome.remote_assistance'); |
108 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); | 108 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); |
109 this.port_.onDisconnect.addListener(this.onHostDisconnect_.bind(this)); | 109 this.port_.onDisconnect.addListener(this.onHostDisconnect_.bind(this)); |
110 this.port_.postMessage({type: 'hello'}); | 110 this.port_.postMessage({type: 'hello'}); |
111 } catch (err) { | 111 } catch (/** @type {*} */ err) { |
112 console.log('Native Messaging initialization failed: ', | 112 console.log('Native Messaging initialization failed: ', err); |
113 /** @type {*} */ (err)); | |
114 onInitializationFailed(); | 113 onInitializationFailed(); |
115 return; | 114 return; |
116 } | 115 } |
117 }; | 116 }; |
118 | 117 |
119 /** | 118 /** |
120 * @param {string} email The user's email address. | 119 * @param {string} email The user's email address. |
121 * @param {string} authServiceWithToken Concatenation of the auth service | 120 * @param {string} authServiceWithToken Concatenation of the auth service |
122 * (e.g. oauth2) and the access token. | 121 * (e.g. oauth2) and the access token. |
123 * @param {function(remoting.HostSession.State):void} onStateChanged Callback to | 122 * @param {function(remoting.HostSession.State):void} onStateChanged Callback to |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // error. | 322 // error. |
324 console.log('Native Messaging initialization failed: ' + | 323 console.log('Native Messaging initialization failed: ' + |
325 chrome.runtime.lastError.message); | 324 chrome.runtime.lastError.message); |
326 this.onInitializationFailed_(); | 325 this.onInitializationFailed_(); |
327 } else { | 326 } else { |
328 console.error('Native Messaging port disconnected.'); | 327 console.error('Native Messaging port disconnected.'); |
329 this.port_ = null; | 328 this.port_ = null; |
330 this.onError_(remoting.Error.UNEXPECTED); | 329 this.onError_(remoting.Error.UNEXPECTED); |
331 } | 330 } |
332 } | 331 } |
OLD | NEW |