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 <include src="saml_handler.js"> | 5 <include src="saml_handler.js"> |
6 | 6 |
7 /** | 7 /** |
8 * @fileoverview An UI component to authenciate to Chrome. The component hosts | 8 * @fileoverview An UI component to authenciate to Chrome. The component hosts |
9 * IdP web pages in a webview. A client who is interested in monitoring | 9 * IdP web pages in a webview. A client who is interested in monitoring |
10 * authentication events should pass a listener object of type | 10 * authentication events should pass a listener object of type |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 details.requestHeaders.push( | 417 details.requestHeaders.push( |
418 {name: X_DEVICE_ID_HEADER, value: deviceId}); | 418 {name: X_DEVICE_ID_HEADER, value: deviceId}); |
419 } | 419 } |
420 } | 420 } |
421 return { | 421 return { |
422 requestHeaders: details.requestHeaders | 422 requestHeaders: details.requestHeaders |
423 }; | 423 }; |
424 }; | 424 }; |
425 | 425 |
426 /** | 426 /** |
427 * Returns true if given HTML5 message is received from the webview element. | |
428 * @param {object} e Payload of the received HTML5 message. | |
429 */ | |
430 Authenticator.prototype.isGaiaMessage = function(e) { | |
431 if (!this.isWebviewEvent_(e)) | |
432 return false; | |
433 | |
434 // The event origin does not have a trailing slash. | |
435 if (e.origin != this.idpOrigin_.substring(0, this.idpOrigin_.length - 1)) { | |
436 return false; | |
437 } | |
438 | |
439 // Gaia messages must be an object with 'method' property. | |
440 if (typeof e.data != 'object' || !e.data.hasOwnProperty('method')) { | |
441 return false; | |
442 } | |
443 return true; | |
444 }; | |
445 | |
446 /** | |
427 * Invoked when an HTML5 message is received from the webview element. | 447 * Invoked when an HTML5 message is received from the webview element. |
428 * @param {object} e Payload of the received HTML5 message. | 448 * @param {object} e Payload of the received HTML5 message. |
429 * @private | 449 * @private |
430 */ | 450 */ |
431 Authenticator.prototype.onMessageFromWebview_ = function(e) { | 451 Authenticator.prototype.onMessageFromWebview_ = function(e) { |
432 if (!this.isWebviewEvent_(e)) | 452 if (!this.isGaiaMessage(e)) |
433 return; | 453 return; |
434 | 454 |
435 // The event origin does not have a trailing slash. | |
436 if (e.origin != this.idpOrigin_.substring(0, this.idpOrigin_.length - 1)) { | |
437 return; | |
438 } | |
439 | |
440 // Gaia messages must be an object with 'method' property. | |
441 if (typeof e.data != 'object' || !e.data.hasOwnProperty('method')) { | |
442 return; | |
443 } | |
444 | |
445 var msg = e.data; | 455 var msg = e.data; |
446 if (msg.method == 'attemptLogin') { | 456 if (msg.method == 'attemptLogin') { |
447 this.email_ = msg.email; | 457 this.email_ = msg.email; |
448 this.password_ = msg.password; | 458 this.password_ = msg.password; |
449 this.chooseWhatToSync_ = msg.chooseWhatToSync; | 459 this.chooseWhatToSync_ = msg.chooseWhatToSync; |
460 this.dispatchEvent(new CustomEvent('attemptLogin', {detail: msg.email})); | |
Nikita (slow)
2015/04/22 16:51:52
As discussed, we should only process 'attemptLogin
Alexander Alekseev
2015/04/22 17:58:07
Done.
| |
450 } else if (msg.method == 'dialogShown') { | 461 } else if (msg.method == 'dialogShown') { |
451 this.dispatchEvent(new Event('dialogShown')); | 462 this.dispatchEvent(new Event('dialogShown')); |
452 } else if (msg.method == 'dialogHidden') { | 463 } else if (msg.method == 'dialogHidden') { |
453 this.dispatchEvent(new Event('dialogHidden')); | 464 this.dispatchEvent(new Event('dialogHidden')); |
454 } else if (msg.method == 'backButton') { | 465 } else if (msg.method == 'backButton') { |
455 this.dispatchEvent(new CustomEvent('backButton', {detail: msg.show})); | 466 this.dispatchEvent(new CustomEvent('backButton', {detail: msg.show})); |
456 } else if (msg.method == 'showView') { | 467 } else if (msg.method == 'showView') { |
457 this.dispatchEvent(new Event('showView')); | 468 this.dispatchEvent(new Event('showView')); |
458 } else { | 469 } else { |
459 console.warn('Unrecognized message from GAIA: ' + msg.method); | 470 console.warn('Unrecognized message from GAIA: ' + msg.method); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 */ | 669 */ |
659 Authenticator.prototype.isWebviewEvent_ = function(e) { | 670 Authenticator.prototype.isWebviewEvent_ = function(e) { |
660 // Note: <webview> prints error message to console if |contentWindow| is not | 671 // Note: <webview> prints error message to console if |contentWindow| is not |
661 // defined. | 672 // defined. |
662 // TODO(dzhioev): remove the message. http://crbug.com/469522 | 673 // TODO(dzhioev): remove the message. http://crbug.com/469522 |
663 var webviewWindow = this.webview_.contentWindow; | 674 var webviewWindow = this.webview_.contentWindow; |
664 return !!webviewWindow && webviewWindow === e.source; | 675 return !!webviewWindow && webviewWindow === e.source; |
665 }; | 676 }; |
666 | 677 |
667 /** | 678 /** |
679 * Informs Gaia of new deviceId to be used. | |
680 */ | |
681 Authenticator.prototype.updateDeviceId = function(deviceId) { | |
682 var msg = { | |
683 'method': 'updateDeviceId', | |
684 'deviceId': deviceId, | |
685 }; | |
686 | |
687 var currentUrl = this.webview_.src; | |
688 this.webview_.contentWindow.postMessage(msg, currentUrl); | |
689 }; | |
690 | |
691 /** | |
668 * The current auth flow of the hosted auth page. | 692 * The current auth flow of the hosted auth page. |
669 * @type {AuthFlow} | 693 * @type {AuthFlow} |
670 */ | 694 */ |
671 cr.defineProperty(Authenticator, 'authFlow'); | 695 cr.defineProperty(Authenticator, 'authFlow'); |
672 | 696 |
673 Authenticator.AuthFlow = AuthFlow; | 697 Authenticator.AuthFlow = AuthFlow; |
674 Authenticator.AuthMode = AuthMode; | 698 Authenticator.AuthMode = AuthMode; |
675 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 699 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
676 | 700 |
677 return { | 701 return { |
678 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old | 702 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old |
679 // iframe-based flow is deprecated. | 703 // iframe-based flow is deprecated. |
680 GaiaAuthHost: Authenticator, | 704 GaiaAuthHost: Authenticator, |
681 Authenticator: Authenticator | 705 Authenticator: Authenticator |
682 }; | 706 }; |
683 }); | 707 }); |
OLD | NEW |