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 host daemon via Native Messaging. | 7 * Class to communicate with the host daemon via Native Messaging. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 }; | 77 }; |
78 | 78 |
79 /** | 79 /** |
80 * Connects to the native messaging host and sends a hello message. | 80 * Connects to the native messaging host and sends a hello message. |
81 * | 81 * |
82 * @return {Promise} A promise that fulfills when the connection attempt | 82 * @return {Promise} A promise that fulfills when the connection attempt |
83 * succeeds or fails. | 83 * succeeds or fails. |
84 * @private | 84 * @private |
85 */ | 85 */ |
86 remoting.HostDaemonFacade.prototype.connectNative_ = function() { | 86 remoting.HostDaemonFacade.prototype.connectNative_ = function() { |
87 var that = this; | |
87 try { | 88 try { |
88 this.port_ = chrome.runtime.connectNative( | 89 this.port_ = chrome.runtime.connectNative( |
89 'com.google.chrome.remote_desktop'); | 90 'com.google.chrome.remote_desktop'); |
90 this.port_.onMessage.addListener(this.onIncomingMessageCallback_); | 91 this.port_.onMessage.addListener(this.onIncomingMessageCallback_); |
91 this.port_.onDisconnect.addListener(this.onDisconnectCallback_); | 92 this.port_.onDisconnect.addListener(this.onDisconnectCallback_); |
92 return this.postMessageInternal_({type: 'hello'}); | 93 return this.postMessageInternal_({type: 'hello'}).then(function(reply) { |
94 that.version_ = base.getStringAttr(reply, 'version'); | |
95 // Old versions of the native messaging host do not return this list. | |
96 // Those versions default to the empty list of supported features. | |
97 that.supportedFeatures_ = | |
98 base.getArrayAttr(reply, 'supportedFeatures', []); | |
99 return null; | |
kelvinp
2015/04/24 21:59:27
nit s/return null/return
for consistency within th
| |
100 }); | |
93 } catch (/** @type {*} */ err) { | 101 } catch (/** @type {*} */ err) { |
94 console.log('Native Messaging initialization failed: ', err); | 102 console.log('Native Messaging initialization failed: ', err); |
95 throw remoting.Error.unexpected(); | 103 throw remoting.Error.unexpected(); |
96 } | 104 } |
97 }; | 105 }; |
98 | 106 |
99 /** | 107 /** |
100 * Type used for entries of |pendingReplies_| list. | 108 * Type used for entries of |pendingReplies_| list. |
101 * | 109 * |
102 * @param {string} type Type of the originating request. | 110 * @param {string} type Type of the originating request. |
(...skipping 21 matching lines...) Expand all Loading... | |
124 return that.supportedFeatures_.indexOf(feature) >= 0; | 132 return that.supportedFeatures_.indexOf(feature) >= 0; |
125 }, function () { | 133 }, function () { |
126 return false; | 134 return false; |
127 }); | 135 }); |
128 }; | 136 }; |
129 | 137 |
130 /** | 138 /** |
131 * Initializes that the Daemon if necessary and posts the supplied message. | 139 * Initializes that the Daemon if necessary and posts the supplied message. |
132 * | 140 * |
133 * @param {{type: string}} message The message to post. | 141 * @param {{type: string}} message The message to post. |
134 * @return {!Promise} | 142 * @return {!Promise<!Object>} |
135 * @private | 143 * @private |
136 */ | 144 */ |
137 remoting.HostDaemonFacade.prototype.postMessage_ = | 145 remoting.HostDaemonFacade.prototype.postMessage_ = |
138 function(message) { | 146 function(message) { |
139 /** @type {remoting.HostDaemonFacade} */ | 147 /** @type {remoting.HostDaemonFacade} */ |
140 var that = this; | 148 var that = this; |
141 return this.initialize_().then(function() { | 149 return this.initialize_().then(function() { |
142 return that.postMessageInternal_(message); | 150 return that.postMessageInternal_(message); |
143 }, function() { | 151 }, function() { |
144 throw that.error_; | 152 throw that.error_; |
145 }); | 153 }); |
146 }; | 154 }; |
147 | 155 |
148 /** | 156 /** |
149 * Attaches a new ID to the supplied message, and posts it to the | 157 * Attaches a new ID to the supplied message, and posts it to the |
150 * Native Messaging port, adding a Deferred object to the list of | 158 * Native Messaging port, adding a Deferred object to the list of |
151 * pending replies. |message| should have its 'type' field set, and | 159 * pending replies. |message| should have its 'type' field set, and |
152 * any other fields set depending on the message type. | 160 * any other fields set depending on the message type. |
153 * | 161 * |
154 * @param {{type: string}} message The message to post. | 162 * @param {{type: string}} message The message to post. |
155 * @return {!Promise} | 163 * @return {!Promise<!Object>} |
156 * @private | 164 * @private |
157 */ | 165 */ |
158 remoting.HostDaemonFacade.prototype.postMessageInternal_ = function(message) { | 166 remoting.HostDaemonFacade.prototype.postMessageInternal_ = function(message) { |
159 var id = this.nextId_++; | 167 var id = this.nextId_++; |
160 message['id'] = id; | 168 message['id'] = id; |
161 var deferred = new base.Deferred(); | 169 var deferred = new base.Deferred(); |
162 this.pendingReplies_[id] = new remoting.HostDaemonFacade.PendingReply( | 170 this.pendingReplies_[id] = new remoting.HostDaemonFacade.PendingReply( |
163 message.type + 'Response', deferred); | 171 message.type + 'Response', deferred); |
164 this.port_.postMessage(message); | 172 this.port_.postMessage(message); |
165 return deferred.promise(); | 173 return deferred.promise(); |
(...skipping 18 matching lines...) Expand all Loading... | |
184 console.error('NativeMessaging: unexpected id: ', id); | 192 console.error('NativeMessaging: unexpected id: ', id); |
185 return; | 193 return; |
186 } | 194 } |
187 delete this.pendingReplies_[id]; | 195 delete this.pendingReplies_[id]; |
188 | 196 |
189 try { | 197 try { |
190 var type = base.getStringAttr(message, 'type'); | 198 var type = base.getStringAttr(message, 'type'); |
191 if (type != reply.type) { | 199 if (type != reply.type) { |
192 throw 'Expected reply type: ' + reply.type + ', got: ' + type; | 200 throw 'Expected reply type: ' + reply.type + ', got: ' + type; |
193 } | 201 } |
194 | 202 reply.deferred.resolve(message); |
195 reply.deferred.resolve(this.handleIncomingMessage_(message)); | |
196 } catch (/** @type {*} */ e) { | 203 } catch (/** @type {*} */ e) { |
197 console.error('Error while processing native message', e); | 204 console.error('Error while processing native message', e); |
198 reply.deferred.reject(remoting.Error.unexpected()); | 205 reply.deferred.reject(remoting.Error.unexpected()); |
199 } | 206 } |
200 }; | 207 }; |
201 | 208 |
202 /** | 209 /** |
203 * Handler for incoming Native Messages. | |
204 * | |
205 * TODO(jrw) Consider refactoring so each method handles its own | |
206 * response, e.g.: | |
207 * | |
208 * remoting.HostDaemonFacade.prototype.generateKeyPair = function() { | |
209 * this.postMessage_({type: 'generateKeyPair'}).then(function(message) { | |
210 * return { | |
211 * privateKey: base.getStringAttr(message, 'privateKey'), | |
212 * publicKey: base.getStringAttr(message, 'publicKey') | |
213 * } | |
214 * }); | |
215 * }; | |
216 * | |
217 * @param {Object} message The received message. | |
218 * @return {*} | |
219 * @private | |
220 */ | |
221 remoting.HostDaemonFacade.prototype.handleIncomingMessage_ = | |
222 function(message) { | |
223 var type = base.getStringAttr(message, 'type'); | |
224 | |
225 switch (type) { | |
226 case 'helloResponse': | |
227 this.version_ = base.getStringAttr(message, 'version'); | |
228 // Old versions of the native messaging host do not return this list. | |
229 // Those versions default to the empty list of supported features. | |
230 this.supportedFeatures_ = | |
231 base.getArrayAttr(message, 'supportedFeatures', []); | |
232 return null; | |
233 | |
234 case 'getHostNameResponse': | |
235 return base.getStringAttr(message, 'hostname'); | |
236 | |
237 case 'getPinHashResponse': | |
238 return base.getStringAttr(message, 'hash'); | |
239 | |
240 case 'generateKeyPairResponse': | |
241 return { | |
242 privateKey: base.getStringAttr(message, 'privateKey'), | |
243 publicKey: base.getStringAttr(message, 'publicKey') | |
244 }; | |
245 | |
246 case 'updateDaemonConfigResponse': | |
247 return remoting.HostController.AsyncResult.fromString( | |
248 base.getStringAttr(message, 'result')); | |
249 | |
250 case 'getDaemonConfigResponse': | |
251 return base.getObjectAttr(message, 'config'); | |
252 | |
253 case 'getUsageStatsConsentResponse': | |
254 return { | |
255 supported: base.getBooleanAttr(message, 'supported'), | |
256 allowed: base.getBooleanAttr(message, 'allowed'), | |
257 setByPolicy: base.getBooleanAttr(message, 'setByPolicy') | |
258 }; | |
259 | |
260 case 'startDaemonResponse': | |
261 case 'stopDaemonResponse': | |
262 return remoting.HostController.AsyncResult.fromString( | |
263 base.getStringAttr(message, 'result')); | |
264 | |
265 case 'getDaemonStateResponse': | |
266 return remoting.HostController.State.fromString( | |
267 base.getStringAttr(message, 'state')); | |
268 | |
269 case 'getPairedClientsResponse': | |
270 var pairedClients = remoting.PairedClient.convertToPairedClientArray( | |
271 message['pairedClients']); | |
272 if (pairedClients != null) { | |
273 return pairedClients; | |
274 } else { | |
275 throw 'No paired clients!'; | |
276 } | |
277 | |
278 case 'clearPairedClientsResponse': | |
279 case 'deletePairedClientResponse': | |
280 return base.getBooleanAttr(message, 'result'); | |
281 | |
282 case 'getHostClientIdResponse': | |
283 return base.getStringAttr(message, 'clientId'); | |
284 | |
285 case 'getCredentialsFromAuthCodeResponse': | |
286 var userEmail = base.getStringAttr(message, 'userEmail'); | |
287 var refreshToken = base.getStringAttr(message, 'refreshToken'); | |
288 if (userEmail && refreshToken) { | |
289 return { | |
290 userEmail: userEmail, | |
291 refreshToken: refreshToken | |
292 }; | |
293 } else { | |
294 throw 'Missing userEmail or refreshToken'; | |
295 } | |
296 | |
297 default: | |
298 throw 'Unexpected native message: ' + message; | |
299 } | |
300 }; | |
301 | |
302 /** | |
303 * @return {void} Nothing. | 210 * @return {void} Nothing. |
304 * @private | 211 * @private |
305 */ | 212 */ |
306 remoting.HostDaemonFacade.prototype.onDisconnect_ = function() { | 213 remoting.HostDaemonFacade.prototype.onDisconnect_ = function() { |
307 console.error('Native Message port disconnected'); | 214 console.error('Native Message port disconnected'); |
308 | 215 |
309 this.port_.onDisconnect.removeListener(this.onDisconnectCallback_); | 216 this.port_.onDisconnect.removeListener(this.onDisconnectCallback_); |
310 this.port_.onMessage.removeListener(this.onIncomingMessageCallback_); | 217 this.port_.onMessage.removeListener(this.onIncomingMessageCallback_); |
311 this.port_ = null; | 218 this.port_ = null; |
312 | 219 |
(...skipping 11 matching lines...) Expand all Loading... | |
324 pendingReplies[num_id].deferred.reject(this.error_); | 231 pendingReplies[num_id].deferred.reject(this.error_); |
325 } | 232 } |
326 } | 233 } |
327 | 234 |
328 /** | 235 /** |
329 * Gets local hostname. | 236 * Gets local hostname. |
330 * | 237 * |
331 * @return {!Promise<string>} | 238 * @return {!Promise<string>} |
332 */ | 239 */ |
333 remoting.HostDaemonFacade.prototype.getHostName = function() { | 240 remoting.HostDaemonFacade.prototype.getHostName = function() { |
334 return this.postMessage_({type: 'getHostName'}); | 241 return this.postMessage_({type: 'getHostName'}).then(function(reply) { |
242 return base.getStringAttr(reply, 'hostname'); | |
243 }); | |
335 }; | 244 }; |
336 | 245 |
337 /** | 246 /** |
338 * Calculates PIN hash value to be stored in the config, passing the resulting | 247 * Calculates PIN hash value to be stored in the config, passing the resulting |
339 * hash value base64-encoded to the callback. | 248 * hash value base64-encoded to the callback. |
340 * | 249 * |
341 * @param {string} hostId The host ID. | 250 * @param {string} hostId The host ID. |
342 * @param {string} pin The PIN. | 251 * @param {string} pin The PIN. |
343 * @return {!Promise<string>} | 252 * @return {!Promise<string>} |
344 */ | 253 */ |
345 remoting.HostDaemonFacade.prototype.getPinHash = function(hostId, pin) { | 254 remoting.HostDaemonFacade.prototype.getPinHash = function(hostId, pin) { |
346 return this.postMessage_({ | 255 return this.postMessage_({ |
347 type: 'getPinHash', | 256 type: 'getPinHash', |
348 hostId: hostId, | 257 hostId: hostId, |
349 pin: pin | 258 pin: pin |
259 }).then(function(reply) { | |
260 return base.getStringAttr(reply, 'hash'); | |
350 }); | 261 }); |
351 }; | 262 }; |
352 | 263 |
353 /** | 264 /** |
354 * Generates new key pair to use for the host. The specified callback is called | 265 * Generates new key pair to use for the host. The specified callback is called |
355 * when the key is generated. The key is returned in format understood by the | 266 * when the key is generated. The key is returned in format understood by the |
356 * host (PublicKeyInfo structure encoded with ASN.1 DER, and then BASE64). | 267 * host (PublicKeyInfo structure encoded with ASN.1 DER, and then BASE64). |
357 * | 268 * |
358 * @return {!Promise<remoting.KeyPair>} | 269 * @return {!Promise<remoting.KeyPair>} |
359 */ | 270 */ |
360 remoting.HostDaemonFacade.prototype.generateKeyPair = function() { | 271 remoting.HostDaemonFacade.prototype.generateKeyPair = function() { |
361 return this.postMessage_({type: 'generateKeyPair'}); | 272 return this.postMessage_({type: 'generateKeyPair'}).then(function(reply) { |
273 return { | |
274 privateKey: base.getStringAttr(reply, 'privateKey'), | |
275 publicKey: base.getStringAttr(reply, 'publicKey') | |
276 }; | |
277 }); | |
362 }; | 278 }; |
363 | 279 |
364 /** | 280 /** |
365 * Updates host config with the values specified in |config|. All | 281 * Updates host config with the values specified in |config|. All |
366 * fields that are not specified in |config| remain | 282 * fields that are not specified in |config| remain |
367 * unchanged. Following parameters cannot be changed using this | 283 * unchanged. Following parameters cannot be changed using this |
368 * function: host_id, xmpp_login. Error is returned if |config| | 284 * function: host_id, xmpp_login. Error is returned if |config| |
369 * includes these parameters. Changes take effect before the callback | 285 * includes these parameters. Changes take effect before the callback |
370 * is called. | 286 * is called. |
371 * | 287 * |
372 * TODO(jrw): Consider conversion exceptions to AsyncResult values. | 288 * TODO(jrw): Consider conversion exceptions to AsyncResult values. |
373 * | 289 * |
374 * @param {Object} config The new config parameters. | 290 * @param {Object} config The new config parameters. |
375 * @return {!Promise<remoting.HostController.AsyncResult>} | 291 * @return {!Promise<remoting.HostController.AsyncResult>} |
376 */ | 292 */ |
377 remoting.HostDaemonFacade.prototype.updateDaemonConfig = function(config) { | 293 remoting.HostDaemonFacade.prototype.updateDaemonConfig = function(config) { |
378 return this.postMessage_({ | 294 return this.postMessage_({ |
379 type: 'updateDaemonConfig', | 295 type: 'updateDaemonConfig', |
380 config: config | 296 config: config |
297 }).then(function(reply) { | |
298 return remoting.HostController.AsyncResult.fromString( | |
299 base.getStringAttr(reply, 'result')); | |
381 }); | 300 }); |
382 }; | 301 }; |
383 | 302 |
384 /** | 303 /** |
385 * Loads daemon config. The config is passed as a JSON formatted string to the | 304 * Loads daemon config. The config is passed as a JSON formatted string to the |
386 * callback. | 305 * callback. |
387 * @return {!Promise<Object>} | 306 * @return {!Promise<Object>} |
388 */ | 307 */ |
389 remoting.HostDaemonFacade.prototype.getDaemonConfig = function() { | 308 remoting.HostDaemonFacade.prototype.getDaemonConfig = function() { |
390 return this.postMessage_({type: 'getDaemonConfig'}); | 309 return this.postMessage_({type: 'getDaemonConfig'}).then(function(reply) { |
310 return base.getObjectAttr(reply, 'config'); | |
311 }); | |
391 }; | 312 }; |
392 | 313 |
393 /** | 314 /** |
394 * Retrieves daemon version. The version is returned as a dotted decimal | 315 * Retrieves daemon version. The version is returned as a dotted decimal |
395 * string of the form major.minor.build.patch. | 316 * string of the form major.minor.build.patch. |
396 * | 317 * |
397 * @return {!Promise<string>} | 318 * @return {!Promise<string>} |
398 */ | 319 */ |
399 remoting.HostDaemonFacade.prototype.getDaemonVersion = function() { | 320 remoting.HostDaemonFacade.prototype.getDaemonVersion = function() { |
400 /** @type {remoting.HostDaemonFacade} */ | 321 /** @type {remoting.HostDaemonFacade} */ |
401 var that = this; | 322 var that = this; |
402 return this.initialize_().then(function() { | 323 return this.initialize_().then(function() { |
403 return that.version_; | 324 return that.version_; |
404 }, function() { | 325 }, function() { |
405 throw that.error_; | 326 throw that.error_; |
406 }); | 327 }); |
407 }; | 328 }; |
408 | 329 |
409 /** | 330 /** |
410 * Get the user's consent to crash reporting. The consent flags are passed to | 331 * Get the user's consent to crash reporting. The consent flags are passed to |
411 * the callback as booleans: supported, allowed, set-by-policy. | 332 * the callback as booleans: supported, allowed, set-by-policy. |
412 * | 333 * |
413 * @return {!Promise<remoting.UsageStatsConsent>} | 334 * @return {!Promise<remoting.UsageStatsConsent>} |
414 */ | 335 */ |
415 remoting.HostDaemonFacade.prototype.getUsageStatsConsent = function() { | 336 remoting.HostDaemonFacade.prototype.getUsageStatsConsent = function() { |
416 return this.postMessage_({type: 'getUsageStatsConsent'}); | 337 return this.postMessage_({type: 'getUsageStatsConsent'}). |
338 then(function(reply) { | |
339 return { | |
340 supported: base.getBooleanAttr(reply, 'supported'), | |
341 allowed: base.getBooleanAttr(reply, 'allowed'), | |
342 setByPolicy: base.getBooleanAttr(reply, 'setByPolicy') | |
343 }; | |
344 }); | |
417 }; | 345 }; |
418 | 346 |
419 /** | 347 /** |
420 * Starts the daemon process with the specified configuration. | 348 * Starts the daemon process with the specified configuration. |
421 * | 349 * |
422 * TODO(jrw): Consider conversion exceptions to AsyncResult values. | 350 * TODO(jrw): Consider conversion exceptions to AsyncResult values. |
423 * | 351 * |
424 * @param {Object} config Host configuration. | 352 * @param {Object} config Host configuration. |
425 * @param {boolean} consent Consent to report crash dumps. | 353 * @param {boolean} consent Consent to report crash dumps. |
426 * @return {!Promise<remoting.HostController.AsyncResult>} | 354 * @return {!Promise<remoting.HostController.AsyncResult>} |
427 */ | 355 */ |
428 remoting.HostDaemonFacade.prototype.startDaemon = function(config, consent) { | 356 remoting.HostDaemonFacade.prototype.startDaemon = function(config, consent) { |
429 return this.postMessage_({ | 357 return this.postMessage_({ |
430 type: 'startDaemon', | 358 type: 'startDaemon', |
431 config: config, | 359 config: config, |
432 consent: consent | 360 consent: consent |
361 }).then(function(reply) { | |
362 return remoting.HostController.AsyncResult.fromString( | |
363 base.getStringAttr(reply, 'result')); | |
433 }); | 364 }); |
434 }; | 365 }; |
435 | 366 |
436 /** | 367 /** |
437 * Stops the daemon process. | 368 * Stops the daemon process. |
438 * | 369 * |
439 * TODO(jrw): Consider conversion exceptions to AsyncResult values. | 370 * TODO(jrw): Consider conversion exceptions to AsyncResult values. |
440 * | 371 * |
441 * @return {!Promise<remoting.HostController.AsyncResult>} | 372 * @return {!Promise<remoting.HostController.AsyncResult>} |
442 */ | 373 */ |
443 remoting.HostDaemonFacade.prototype.stopDaemon = | 374 remoting.HostDaemonFacade.prototype.stopDaemon = |
444 function() { | 375 function() { |
445 return this.postMessage_({type: 'stopDaemon'}); | 376 return this.postMessage_({type: 'stopDaemon'}).then(function(reply) { |
377 return remoting.HostController.AsyncResult.fromString( | |
378 base.getStringAttr(reply, 'result')); | |
379 }); | |
446 }; | 380 }; |
447 | 381 |
448 /** | 382 /** |
449 * Gets the installed/running state of the Host process. | 383 * Gets the installed/running state of the Host process. |
450 * | 384 * |
451 * @return {!Promise<remoting.HostController.State>} | 385 * @return {!Promise<remoting.HostController.State>} |
452 */ | 386 */ |
453 remoting.HostDaemonFacade.prototype.getDaemonState = function() { | 387 remoting.HostDaemonFacade.prototype.getDaemonState = function() { |
454 return this.postMessage_({type: 'getDaemonState'}); | 388 return this.postMessage_({type: 'getDaemonState'}).then(function(reply) { |
389 return remoting.HostController.State.fromString( | |
390 base.getStringAttr(reply, 'state')); | |
391 }); | |
455 }; | 392 }; |
456 | 393 |
457 /** | 394 /** |
458 * Retrieves the list of paired clients. | 395 * Retrieves the list of paired clients. |
459 * | 396 * |
460 * @return {!Promise<Array<remoting.PairedClient>>} | 397 * @return {!Promise<Array<remoting.PairedClient>>} |
461 */ | 398 */ |
462 remoting.HostDaemonFacade.prototype.getPairedClients = function() { | 399 remoting.HostDaemonFacade.prototype.getPairedClients = function() { |
463 return this.postMessage_({type: 'getPairedClients'}); | 400 return this.postMessage_({type: 'getPairedClients'}).then(function(reply) { |
401 var pairedClients = remoting.PairedClient.convertToPairedClientArray( | |
kelvinp
2015/04/24 21:59:27
Indent should be 2 spaces instead of 4
| |
402 reply['pairedClients']); | |
403 if (pairedClients != null) { | |
404 return pairedClients; | |
405 } else { | |
406 throw remoting.Error.unexpected('No paired clients!'); | |
407 } | |
408 }); | |
464 }; | 409 }; |
465 | 410 |
466 /** | 411 /** |
467 * Clears all paired clients from the registry. | 412 * Clears all paired clients from the registry. |
468 * | 413 * |
469 * @return {!Promise<boolean>} | 414 * @return {!Promise<boolean>} |
470 */ | 415 */ |
471 remoting.HostDaemonFacade.prototype.clearPairedClients = function() { | 416 remoting.HostDaemonFacade.prototype.clearPairedClients = function() { |
472 return this.postMessage_({type: 'clearPairedClients'}); | 417 return this.postMessage_({type: 'clearPairedClients'}).then(function(reply) { |
418 return base.getBooleanAttr(reply, 'result'); | |
419 }); | |
473 }; | 420 }; |
474 | 421 |
475 /** | 422 /** |
476 * Deletes a paired client referenced by client id. | 423 * Deletes a paired client referenced by client id. |
477 * | 424 * |
478 * @param {string} client Client to delete. | 425 * @param {string} client Client to delete. |
479 * @return {!Promise<boolean>} | 426 * @return {!Promise<boolean>} |
480 */ | 427 */ |
481 remoting.HostDaemonFacade.prototype.deletePairedClient = function(client) { | 428 remoting.HostDaemonFacade.prototype.deletePairedClient = function(client) { |
482 return this.postMessage_({ | 429 return this.postMessage_({ |
483 type: 'deletePairedClient', | 430 type: 'deletePairedClient', |
484 clientId: client | 431 clientId: client |
432 }).then(function(reply) { | |
433 return base.getBooleanAttr(reply, 'result'); | |
485 }); | 434 }); |
486 }; | 435 }; |
487 | 436 |
488 /** | 437 /** |
489 * Gets the API keys to obtain/use service account credentials. | 438 * Gets the API keys to obtain/use service account credentials. |
490 * | 439 * |
491 * @return {!Promise<string>} | 440 * @return {!Promise<string>} |
492 */ | 441 */ |
493 remoting.HostDaemonFacade.prototype.getHostClientId = function() { | 442 remoting.HostDaemonFacade.prototype.getHostClientId = function() { |
494 return this.postMessage_({type: 'getHostClientId'}); | 443 return this.postMessage_({type: 'getHostClientId'}).then(function(reply) { |
444 return base.getStringAttr(reply, 'clientId'); | |
445 }); | |
495 }; | 446 }; |
496 | 447 |
497 /** | 448 /** |
498 * | 449 * |
499 * @param {string} authorizationCode OAuth authorization code. | 450 * @param {string} authorizationCode OAuth authorization code. |
500 * @return {!Promise<{remoting.XmppCredentials}>} | 451 * @return {!Promise<{remoting.XmppCredentials}>} |
501 */ | 452 */ |
502 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode = | 453 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode = |
503 function(authorizationCode) { | 454 function(authorizationCode) { |
504 return this.postMessage_({ | 455 return this.postMessage_({ |
505 type: 'getCredentialsFromAuthCode', | 456 type: 'getCredentialsFromAuthCode', |
506 authorizationCode: authorizationCode | 457 authorizationCode: authorizationCode |
458 }).then(function(reply) { | |
459 var userEmail = base.getStringAttr(reply, 'userEmail'); | |
460 var refreshToken = base.getStringAttr(reply, 'refreshToken'); | |
461 if (userEmail && refreshToken) { | |
462 return { | |
463 userEmail: userEmail, | |
464 refreshToken: refreshToken | |
465 }; | |
466 } else { | |
467 throw remoting.Error.unexpected('Missing userEmail or refreshToken'); | |
468 } | |
507 }); | 469 }); |
508 }; | 470 }; |
OLD | NEW |