Chromium Code Reviews| Index: chrome/browser/resources/gaia_auth_host/authenticator.js |
| diff --git a/chrome/browser/resources/gaia_auth_host/authenticator.js b/chrome/browser/resources/gaia_auth_host/authenticator.js |
| index 43bf4fa93b3d6d3ec6f667e3f13e64a62724f327..4d35580a4ce9fac5f0c6ad6adf0cfaef56bf4cca 100644 |
| --- a/chrome/browser/resources/gaia_auth_host/authenticator.js |
| +++ b/chrome/browser/resources/gaia_auth_host/authenticator.js |
| @@ -76,6 +76,7 @@ cr.define('cr.login', function() { |
| 'constrained', // Whether the extension is loaded in a constrained |
| // window. |
| 'clientId', // Chrome client id. |
| + 'useEafe', // Whether to use EAFE. |
| 'needPassword', // Whether the host is interested in getting a password. |
| // If this set to |false|, |confirmPasswordCallback| is |
| // not called before dispatching |authCopleted|. |
| @@ -118,6 +119,9 @@ cr.define('cr.login', function() { |
| this.sessionIsEphemeral_ = null; |
| this.onBeforeSetHeadersSet_ = false; |
| + this.useEafe_ = false; |
| + this.clientId_ = null; |
| + |
| this.samlHandler_ = new cr.login.SamlHandler(this.webview_); |
| this.confirmPasswordCallback = null; |
| this.noPasswordCallback = null; |
| @@ -193,6 +197,8 @@ cr.define('cr.login', function() { |
| this.continueUrl_; |
| this.isConstrainedWindow_ = data.constrained == '1'; |
| this.isNewGaiaFlowChromeOS = data.isNewGaiaFlowChromeOS; |
| + this.useEafe_ = data.useEafe || false; |
| + this.clientId_ = data.clientId; |
| this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); |
| this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; |
| @@ -432,6 +438,23 @@ cr.define('cr.login', function() { |
| return; |
| } |
| + // EAFE passes back auth code via message. |
| + if (this.useEafe_ && |
| + typeof e.data == 'object' && |
| + e.data.hasOwnProperty('authorizationCode')) { |
| + assert(!this.oauth_code_); |
| + this.oauth_code_ = e.data.authorizationCode; |
| + this.dispatchEvent( |
| + new CustomEvent('authCompleted', |
| + { |
| + detail: { |
| + authCodeOnly: true, |
| + authCode: this.oauth_code_ |
| + } |
| + })); |
| + return; |
| + } |
| + |
| // Gaia messages must be an object with 'method' property. |
| if (typeof e.data != 'object' || !e.data.hasOwnProperty('method')) { |
| return; |
| @@ -630,6 +653,19 @@ cr.define('cr.login', function() { |
| // Focus webview after dispatching event when webview is already visible. |
| this.webview_.focus(); |
| } |
| + |
| + // Sends client id to EAFE on every loadstop after a small timeout. This is |
| + // needed because EAFE sits behind SSO and initialize asynchrounouly |
| + // and we don't know for sure when it is loaded and ready to listen |
| + // for message. The postMessage is guarded by EAFE's origin. |
| + if (this.useEafe_) { |
| + window.setTimeout((function() { |
|
Nikita (slow)
2015/04/23 21:14:02
nit: I suppose you can drop window here.
xiyuan
2015/04/23 21:30:48
Both styles (w/ or w/o window) are used in chromiu
|
| + var msg = { |
| + 'clientId': this.clientId_ |
| + }; |
| + this.webview_.contentWindow.postMessage(msg, this.idpOrigin_); |
| + }).bind(this), 500); |
|
Nikita (slow)
2015/04/23 21:14:01
nit: extract constant.
Are you sure that 500 ms is
xiyuan
2015/04/23 21:30:48
Constact extracted and added comment.
500ms is an
|
| + } |
| }; |
| /** |