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

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

Issue 896003002: Use the local user's email when connecting to It2MeHelpeeChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@HRD_V2Auth
Patch Set: Created 5 years, 10 months 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 }; 242 };
243 243
244 /** 244 /**
245 * Connects to the It2Me Native messaging Host and retrieves the access code. 245 * Connects to the It2Me Native messaging Host and retrieves the access code.
246 * 246 *
247 * @param {{method:string, data:Object.<string,*>}} message 247 * @param {{method:string, data:Object.<string,*>}} message
248 * @private 248 * @private
249 */ 249 */
250 remoting.It2MeHelpeeChannel.prototype.handleConnect_ = 250 remoting.It2MeHelpeeChannel.prototype.handleConnect_ =
251 function(message) { 251 function(message) {
252 var email = getStringAttr(message, 'email');
253 var bounds = 252 var bounds =
254 /** @type {Bounds} */ (getObjectAttr(message, 'hangoutBounds', null)); 253 /** @type {Bounds} */ (getObjectAttr(message, 'hangoutBounds', null));
255 254
256 if (!email) {
257 throw new Error('Missing required parameter: email');
258 }
259
260 if (this.hostState_ !== remoting.HostSession.State.UNKNOWN) { 255 if (this.hostState_ !== remoting.HostSession.State.UNKNOWN) {
261 throw new Error('An existing connection is in progress.'); 256 throw new Error('An existing connection is in progress.');
262 } 257 }
263 258
264 var that = this; 259 var that = this;
265 this.showConfirmDialog_(bounds).then( 260 this.showConfirmDialog_(bounds)
266 this.initializeHost_.bind(this) 261 .then(this.initializeHost_.bind(this))
267 ).then( 262 .then(this.fetchOAuthToken_.bind(this))
268 this.fetchOAuthToken_.bind(this) 263 .then(this.fetchEmail_.bind(this))
269 ).then( 264 /** @param {{email:string, token:string}|Promise} result */
kelvinp 2015/02/03 23:11:09 (| Promise) is there to make JSCompile happy as it
270 /** @type {function(*):void} */(this.connectToHost_.bind(this, email)) 265 .then(function(result) {
271 ).catch( 266 return that.connectToHost_(result.email, result.token);
dcaiafa 2015/02/04 00:12:35 I'm confused. connectToHost_ doesn't return anythi
kelvinp 2015/02/04 00:38:14 Done.
272 /** @param {*} reason */ 267 /** @param {*} reason */
273 function(reason) { 268 }).catch(function(reason) {
274 var error = /** @type {Error} */ (reason); 269 that.sendErrorResponse_(message, /** @type {Error} */ (reason));
275 that.sendErrorResponse_(message, error); 270 that.dispose();
276 that.dispose(); 271 });
277 }
278 );
279 }; 272 };
280 273
281 /** 274 /**
282 * Prompts the user before starting the It2Me Native Messaging Host. This 275 * Prompts the user before starting the It2Me Native Messaging Host. This
283 * ensures that even if Hangouts is compromised, an attacker cannot start the 276 * ensures that even if Hangouts is compromised, an attacker cannot start the
284 * host without explicit user confirmation. 277 * host without explicit user confirmation.
285 * 278 *
286 * @param {Bounds} bounds Bounds of the hangout window 279 * @param {Bounds} bounds Bounds of the hangout window
287 * @return {Promise} A promise that will resolve if the user accepts remote 280 * @return {Promise} A promise that will resolve if the user accepts remote
288 * assistance or reject otherwise. 281 * assistance or reject otherwise.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 }; 354 };
362 355
363 /** 356 /**
364 * @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
365 * value. 358 * value.
366 */ 359 */
367 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { 360 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() {
368 if (base.isAppsV2()) { 361 if (base.isAppsV2()) {
369 /** 362 /**
370 * @param {function(*=):void} resolve 363 * @param {function(*=):void} resolve
364 * @param {function(*=):void} reject
371 */ 365 */
372 return new Promise(function(resolve){ 366 return new Promise(function(resolve, reject){
373 chrome.identity.getAuthToken({'interactive': true}, resolve); 367 remoting.identity.callWithToken(resolve, reject);
374 }); 368 });
375 } else { 369 } else {
376 /** 370 /**
377 * @param {function(*=):void} resolve 371 * @param {function(*=):void} resolve
378 * @param {function(*=):void} reject 372 * @param {function(*=):void} reject
379 */ 373 */
380 return new Promise(function(resolve, reject) { 374 return new Promise(function(resolve, reject) {
381 /** @type {remoting.OAuth2} */
382 var oauth2 = new remoting.OAuth2();
383 /** @param {remoting.Error} error */ 375 /** @param {remoting.Error} error */
384 var onError = function(error) { 376 var onError = function(error) {
385 if (error === remoting.Error.NOT_AUTHENTICATED) { 377 if (error === remoting.Error.NOT_AUTHENTICATED) {
386 oauth2.doAuthRedirect(function() { 378 remoting.oauth2.doAuthRedirect(function() {
387 oauth2.callWithToken(resolve, reject); 379 remoting.identity.callWithToken(resolve, reject);
388 }); 380 });
389 return; 381 return;
390 } 382 }
391 reject(new Error(remoting.Error.NOT_AUTHENTICATED)); 383 reject(new Error(remoting.Error.NOT_AUTHENTICATED));
392 }; 384 };
393 oauth2.callWithToken(resolve, onError); 385 remoting.identity.callWithToken(resolve, onError);
394 }); 386 });
395 } 387 }
396 }; 388 };
397 389
398 /** 390 /**
391 * @param {string|Promise} token
kelvinp 2015/02/03 23:11:09 (| Promise) is there to make JSCompile happy as it
392 * @return {Promise} Promise that resolves with the access token and the email
393 * of the user.
394 */
395 remoting.It2MeHelpeeChannel.prototype.fetchEmail_ = function(token) {
396 /**
397 * @param {function(*=):void} resolve
398 * @param {function(*=):void} reject
399 */
400 return new Promise(function(resolve, reject){
401 /** @param {string} email */
402 function onEmail (email) {
403 resolve({ email: email, token: token });
404 }
405 remoting.identity.getEmail(onEmail, reject);
406 });
407 };
408
409 /**
399 * Connects to the It2Me Native Messaging Host and retrieves the access code 410 * Connects to the It2Me Native Messaging Host and retrieves the access code
400 * in the |onHostStateChanged_| callback. 411 * in the |onHostStateChanged_| callback.
401 * 412 *
402 * @param {string} email 413 * @param {string} email
403 * @param {string} accessToken 414 * @param {string} accessToken
404 * @private 415 * @private
405 */ 416 */
406 remoting.It2MeHelpeeChannel.prototype.connectToHost_ = 417 remoting.It2MeHelpeeChannel.prototype.connectToHost_ =
407 function(email, accessToken) { 418 function(email, accessToken) {
408 base.debug.assert(this.host_.initialized()); 419 base.debug.assert(this.host_.initialized());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 485
475 console.error('Error responding to message method:' + 486 console.error('Error responding to message method:' +
476 (incomingMessage ? incomingMessage.method : 'null') + 487 (incomingMessage ? incomingMessage.method : 'null') +
477 ' error:' + error); 488 ' error:' + error);
478 this.hangoutPort_.postMessage({ 489 this.hangoutPort_.postMessage({
479 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, 490 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR,
480 message: error, 491 message: error,
481 request: incomingMessage 492 request: incomingMessage
482 }); 493 });
483 }; 494 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698