Chromium Code Reviews| 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 An UI component to authenciate to Chrome. The component hosts | 6 * @fileoverview An UI component to authenciate to Chrome. The component hosts |
| 7 * IdP web pages in a webview. A client who is interested in monitoring | 7 * IdP web pages in a webview. A client who is interested in monitoring |
| 8 * authentication events should pass a listener object of type | 8 * authentication events should pass a listener object of type |
| 9 * cr.login.GaiaAuthHost.Listener as defined in this file. After initialization, | 9 * cr.login.GaiaAuthHost.Listener as defined in this file. After initialization, |
| 10 * call {@code load} to start the authentication flow. | 10 * call {@code load} to start the authentication flow. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 'focus', this.onFocus_.bind(this), false); | 118 'focus', this.onFocus_.bind(this), false); |
| 119 window.addEventListener( | 119 window.addEventListener( |
| 120 'popstate', this.onPopState_.bind(this), false); | 120 'popstate', this.onPopState_.bind(this), false); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the | 123 // TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the |
| 124 // old event-based signin flow. | 124 // old event-based signin flow. |
| 125 Authenticator.prototype = Object.create(cr.EventTarget.prototype); | 125 Authenticator.prototype = Object.create(cr.EventTarget.prototype); |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Reinitializes authentication parameters so that a failed login attempt | |
| 129 * would not result in an infinite loop. | |
| 130 */ | |
| 131 Authenticator.prototype.clearCredentials_ = function() { | |
|
Roman Sorokin (ftl)
2015/03/17 17:00:41
Could we call this function in the constructor? We
Ivan Podogov
2015/03/18 07:36:20
That was my initial thought, but Dmitry asked me t
| |
| 132 this.email_ = null; | |
| 133 this.gaiaId_ = null; | |
| 134 this.password_ = null; | |
| 135 this.oauth_code_ = null; | |
| 136 this.chooseWhatToSync_ = false; | |
| 137 this.skipForNow_ = false; | |
| 138 this.sessionIndex_ = null; | |
| 139 this.trusted_ = true; | |
| 140 this.authFlow_ = AuthFlow.DEFAULT; | |
| 141 this.loaded_ = false; | |
| 142 }; | |
| 143 | |
| 144 /** | |
| 128 * Loads the authenticator component with the given parameters. | 145 * Loads the authenticator component with the given parameters. |
| 129 * @param {AuthMode} authMode Authorization mode. | 146 * @param {AuthMode} authMode Authorization mode. |
| 130 * @param {Object} data Parameters for the authorization flow. | 147 * @param {Object} data Parameters for the authorization flow. |
| 131 */ | 148 */ |
| 132 Authenticator.prototype.load = function(authMode, data) { | 149 Authenticator.prototype.load = function(authMode, data) { |
| 150 this.clearCredentials_(); | |
| 133 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; | 151 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; |
| 134 this.continueUrl_ = data.continueUrl || CONTINUE_URL; | 152 this.continueUrl_ = data.continueUrl || CONTINUE_URL; |
| 135 this.continueUrlWithoutParams_ = | 153 this.continueUrlWithoutParams_ = |
| 136 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || | 154 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || |
| 137 this.continueUrl_; | 155 this.continueUrl_; |
| 138 this.isConstrainedWindow_ = data.constrained == '1'; | 156 this.isConstrainedWindow_ = data.constrained == '1'; |
| 139 this.isMinuteMaidChromeOS = data.isMinuteMaidChromeOS; | 157 this.isMinuteMaidChromeOS = data.isMinuteMaidChromeOS; |
| 140 | 158 |
| 141 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); | 159 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); |
| 142 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; | 160 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; |
| 143 this.authFlow_ = AuthFlow.DEFAULT; | |
| 144 | 161 |
| 145 this.webview_.src = this.reloadUrl_; | 162 this.webview_.src = this.reloadUrl_; |
| 146 | |
| 147 this.loaded_ = false; | |
| 148 }; | 163 }; |
| 149 | 164 |
| 150 /** | 165 /** |
| 151 * Reloads the authenticator component. | 166 * Reloads the authenticator component. |
| 152 */ | 167 */ |
| 153 Authenticator.prototype.reload = function() { | 168 Authenticator.prototype.reload = function() { |
| 169 this.clearCredentials_(); | |
| 154 this.webview_.src = this.reloadUrl_; | 170 this.webview_.src = this.reloadUrl_; |
| 155 this.authFlow_ = AuthFlow.DEFAULT; | |
| 156 this.loaded_ = false; | |
| 157 }; | 171 }; |
| 158 | 172 |
| 159 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { | 173 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { |
| 160 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); | 174 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); |
| 161 | 175 |
| 162 if (this.isMinuteMaidChromeOS) { | 176 if (this.isMinuteMaidChromeOS) { |
| 163 if (data.chromeType) | 177 if (data.chromeType) |
| 164 url = appendParam(url, 'chrometype', data.chromeType); | 178 url = appendParam(url, 'chrometype', data.chromeType); |
| 165 if (data.clientId) | 179 if (data.clientId) |
| 166 url = appendParam(url, 'client_id', data.clientId); | 180 url = appendParam(url, 'client_id', data.clientId); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 Authenticator.AuthFlow = AuthFlow; | 417 Authenticator.AuthFlow = AuthFlow; |
| 404 Authenticator.AuthMode = AuthMode; | 418 Authenticator.AuthMode = AuthMode; |
| 405 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 419 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
| 406 | 420 |
| 407 return { | 421 return { |
| 408 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old | 422 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old |
| 409 // iframe-based flow is deprecated. | 423 // iframe-based flow is deprecated. |
| 410 GaiaAuthHost: Authenticator | 424 GaiaAuthHost: Authenticator |
| 411 }; | 425 }; |
| 412 }); | 426 }); |
| OLD | NEW |