Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: remoting/webapp/crd/js/it2me_helpee_channel.js

Issue 687873003: Allow the background page to get an OAuth token for apps v1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return new Promise(function(resolve, reject) { 367 return new Promise(function(resolve, reject) {
368 if (host.initialized()) { 368 if (host.initialized()) {
369 resolve(); 369 resolve();
370 } else { 370 } else {
371 host.initialize(resolve, reject); 371 host.initialize(resolve, reject);
372 } 372 }
373 }); 373 });
374 }; 374 };
375 375
376 /** 376 /**
377 * TODO(kelvinp): The existing implementation only works in the v2 app
378 * We need to implement token fetching for the v1 app using remoting.OAuth2
379 * before launch (crbug.com/405130).
380 *
381 * @return {Promise} Promise that resolves with the OAuth token as the value. 377 * @return {Promise} Promise that resolves with the OAuth token as the value.
382 */ 378 */
383 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { 379 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() {
384 if (!base.isAppsV2()) { 380 if (base.isAppsV2()) {
385 throw new Error('fetchOAuthToken_ is not implemented in the v1 app.'); 381 /**
382 * @param {function(*=):void} resolve
383 */
384 return new Promise(function(resolve){
385 // TODO(jamiewalch): Make this work with {interactive: true} as well.
386 chrome.identity.getAuthToken({ 'interactive': false }, resolve);
387 });
388 } else {
389 /**
390 * @param {function(*=):void} resolve
391 */
392 return new Promise(function(resolve) {
393 /** @type {remoting.OAuth2} */
394 var oauth2 = new remoting.OAuth2();
395 var onAuthenticated = function() {
396 oauth2.callWithToken(
397 resolve,
398 function() { throw new Error('Authentication failed.'); });
399 };
400 /** @param {remoting.Error} error */
401 var onError = function(error) {
402 if (error != remoting.Error.NOT_AUTHENTICATED) {
403 throw new Error('Unexpected error fetch auth token: ' + error);
404 }
405 oauth2.doAuthRedirect(onAuthenticated);
406 };
407 oauth2.callWithToken(resolve, onError);
408 });
386 } 409 }
387
388 /**
389 * @param {function(*=):void} resolve
390 */
391 return new Promise(function(resolve){
392 chrome.identity.getAuthToken({ 'interactive': false }, resolve);
393 });
394 }; 410 };
395 411
396 /** 412 /**
397 * Connects to the It2Me Native Messaging Host and retrieves the access code 413 * Connects to the It2Me Native Messaging Host and retrieves the access code
398 * in the |onHostStateChanged_| callback. 414 * in the |onHostStateChanged_| callback.
399 * 415 *
400 * @param {string} email 416 * @param {string} email
401 * @param {string} accessToken 417 * @param {string} accessToken
402 * @private 418 * @private
403 */ 419 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 488
473 console.error('Error responding to message method:' + 489 console.error('Error responding to message method:' +
474 (incomingMessage ? incomingMessage.method : 'null') + 490 (incomingMessage ? incomingMessage.method : 'null') +
475 ' error:' + error); 491 ' error:' + error);
476 this.hangoutPort_.postMessage({ 492 this.hangoutPort_.postMessage({
477 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, 493 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR,
478 message: error, 494 message: error,
479 request: incomingMessage 495 request: incomingMessage
480 }); 496 });
481 }; 497 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698