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 * | 7 * |
8 * It2MeHelpeeChannel relays messages between the Hangouts web page (Hangouts) | 8 * It2MeHelpeeChannel relays messages between the Hangouts web page (Hangouts) |
9 * and the It2Me Native Messaging Host (It2MeHost) for the helpee (the Hangouts | 9 * and the It2Me Native Messaging Host (It2MeHost) for the helpee (the Hangouts |
10 * participant who is receiving remoting assistance). | 10 * participant who is receiving remoting assistance). |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (host.initialized()) { | 347 if (host.initialized()) { |
348 resolve(true); | 348 resolve(true); |
349 } else { | 349 } else { |
350 host.initialize(/** @type {function(*=):void} */ (resolve), | 350 host.initialize(/** @type {function(*=):void} */ (resolve), |
351 /** @type {function(*=):void} */ (reject)); | 351 /** @type {function(*=):void} */ (reject)); |
352 } | 352 } |
353 }); | 353 }); |
354 }; | 354 }; |
355 | 355 |
356 /** | 356 /** |
357 * @return {Promise<string>} Promise that resolves with the OAuth token as the | 357 * @return {!Promise<string>} Promise that resolves with the OAuth token as the |
358 * value. | 358 * value. |
359 */ | 359 */ |
360 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { | 360 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { |
361 if (base.isAppsV2()) { | 361 if (base.isAppsV2()) { |
362 /** | 362 return remoting.identity.getToken(); |
363 * @param {function(*=):void} resolve | |
364 * @param {function(*=):void} reject | |
365 */ | |
366 return new Promise(function(resolve, reject){ | |
367 remoting.identity.callWithToken(resolve, reject); | |
368 }); | |
369 } else { | 363 } else { |
370 /** | 364 var onError = function(/** * */ error) { |
371 * @param {function(*=):void} resolve | |
372 * @param {function(*=):void} reject | |
373 */ | |
374 return new Promise(function(resolve, reject) { | |
375 /** @param {remoting.Error} error */ | |
376 var onError = function(error) { | |
377 if (error === remoting.Error.NOT_AUTHENTICATED) { | 365 if (error === remoting.Error.NOT_AUTHENTICATED) { |
378 remoting.oauth2.doAuthRedirect(function() { | 366 return new Promise(function(resolve, reject) { |
379 remoting.identity.callWithToken(resolve, reject); | 367 remoting.oauth2.doAuthRedirect(function() { |
| 368 remoting.identity.getToken().then(resolve); |
| 369 }); |
380 }); | 370 }); |
381 return; | |
382 } | 371 } |
383 reject(new Error(remoting.Error.NOT_AUTHENTICATED)); | 372 throw Error(remoting.Error.NOT_AUTHENTICATED); |
384 }; | 373 }; |
385 remoting.identity.callWithToken(resolve, onError); | 374 return /** @type {!Promise<string>} */ ( |
386 }); | 375 remoting.identity.getToken().catch(onError)); |
387 } | 376 } |
388 }; | 377 }; |
389 | 378 |
390 /** | 379 /** |
391 * @param {string|Promise} token | 380 * @param {string|Promise} token |
392 * @return {Promise} Promise that resolves with the access token and the email | 381 * @return {Promise} Promise that resolves with the access token and the email |
393 * of the user. | 382 * of the user. |
394 */ | 383 */ |
395 remoting.It2MeHelpeeChannel.prototype.fetchEmail_ = function(token) { | 384 remoting.It2MeHelpeeChannel.prototype.fetchEmail_ = function(token) { |
396 /** | 385 /** @param {string} email */ |
397 * @param {function(*=):void} resolve | 386 function onEmail (email) { |
398 * @param {function(*=):void} reject | 387 return { email: email, token: token }; |
399 */ | 388 } |
400 return new Promise(function(resolve, reject){ | 389 return remoting.identity.getEmail().then(onEmail); |
401 /** @param {string} email */ | |
402 function onEmail (email) { | |
403 resolve({ email: email, token: token }); | |
404 } | |
405 remoting.identity.getEmail(onEmail, reject); | |
406 }); | |
407 }; | 390 }; |
408 | 391 |
409 /** | 392 /** |
410 * Connects to the It2Me Native Messaging Host and retrieves the access code | 393 * Connects to the It2Me Native Messaging Host and retrieves the access code |
411 * in the |onHostStateChanged_| callback. | 394 * in the |onHostStateChanged_| callback. |
412 * | 395 * |
413 * @param {string} email | 396 * @param {string} email |
414 * @param {string} accessToken | 397 * @param {string} accessToken |
415 * @private | 398 * @private |
416 */ | 399 */ |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 468 |
486 console.error('Error responding to message method:' + | 469 console.error('Error responding to message method:' + |
487 (incomingMessage ? incomingMessage.method : 'null') + | 470 (incomingMessage ? incomingMessage.method : 'null') + |
488 ' error:' + error); | 471 ' error:' + error); |
489 this.hangoutPort_.postMessage({ | 472 this.hangoutPort_.postMessage({ |
490 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, | 473 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, |
491 message: error, | 474 message: error, |
492 request: incomingMessage | 475 request: incomingMessage |
493 }); | 476 }); |
494 }; | 477 }; |
OLD | NEW |