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. |
11 */ | 11 */ |
12 cr.define('cr.login', function() { | 12 cr.define('cr.login', function() { |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 var IDP_ORIGIN = 'https://accounts.google.com/'; | 15 var IDP_ORIGIN = 'https://accounts.google.com/'; |
16 var IDP_PATH = 'ServiceLogin?skipvpage=true&sarp=1&rm=hide'; | 16 var IDP_PATH = 'ServiceLogin?skipvpage=true&sarp=1&rm=hide'; |
17 var CONTINUE_URL = | 17 var CONTINUE_URL = |
18 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/success.html'; | 18 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/success.html'; |
19 var SIGN_IN_HEADER = 'google-accounts-signin'; | 19 var SIGN_IN_HEADER = 'google-accounts-signin'; |
20 var EMBEDDED_FORM_HEADER = 'google-accounts-embedded'; | 20 var EMBEDDED_FORM_HEADER = 'google-accounts-embedded'; |
21 var SAML_HEADER = 'google-accounts-saml'; | 21 var SAML_HEADER = 'google-accounts-saml'; |
| 22 var SERVICE_ID = 'chromeoslogin'; |
22 | 23 |
23 /** | 24 /** |
24 * The source URL parameter for the constrained signin flow. | 25 * The source URL parameter for the constrained signin flow. |
25 */ | 26 */ |
26 var CONSTRAINED_FLOW_SOURCE = 'chrome'; | 27 var CONSTRAINED_FLOW_SOURCE = 'chrome'; |
27 | 28 |
28 /** | 29 /** |
29 * Enum for the authorization mode, must match AuthMode defined in | 30 * Enum for the authorization mode, must match AuthMode defined in |
30 * chrome/browser/ui/webui/inline_login_ui.cc. | 31 * chrome/browser/ui/webui/inline_login_ui.cc. |
31 * @enum {number} | 32 * @enum {number} |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 this.onRequestCompleted_.bind(this), | 146 this.onRequestCompleted_.bind(this), |
146 {urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'], | 147 {urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'], |
147 types: ['main_frame']}, | 148 types: ['main_frame']}, |
148 ['responseHeaders']); | 149 ['responseHeaders']); |
149 this.webview_.request.onHeadersReceived.addListener( | 150 this.webview_.request.onHeadersReceived.addListener( |
150 this.onHeadersReceived_.bind(this), | 151 this.onHeadersReceived_.bind(this), |
151 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']}, | 152 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']}, |
152 ['responseHeaders']); | 153 ['responseHeaders']); |
153 window.addEventListener( | 154 window.addEventListener( |
154 'message', this.onMessage_.bind(this), false); | 155 'message', this.onMessage_.bind(this), false); |
| 156 |
| 157 this.loaded_ = false; |
155 }; | 158 }; |
156 | 159 |
157 /** | 160 /** |
158 * Reloads the authenticator component. | 161 * Reloads the authenticator component. |
159 */ | 162 */ |
160 Authenticator.prototype.reload = function() { | 163 Authenticator.prototype.reload = function() { |
161 this.webview_.src = this.reloadUrl_; | 164 this.webview_.src = this.reloadUrl_; |
162 this.authFlow_ = AuthFlow.DEFAULT; | 165 this.authFlow_ = AuthFlow.DEFAULT; |
| 166 this.loaded_ = false; |
163 }; | 167 }; |
164 | 168 |
165 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { | 169 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { |
166 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); | 170 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); |
167 | 171 |
168 url = appendParam(url, 'continue', this.continueUrl_); | 172 url = appendParam(url, 'continue', this.continueUrl_); |
169 url = appendParam(url, 'service', data.service); | 173 url = appendParam(url, 'service', data.service || SERVICE_ID); |
170 if (data.hl) | 174 if (data.hl) |
171 url = appendParam(url, 'hl', data.hl); | 175 url = appendParam(url, 'hl', data.hl); |
172 if (data.email) | 176 if (data.email) |
173 url = appendParam(url, 'Email', data.email); | 177 url = appendParam(url, 'Email', data.email); |
174 if (this.isConstrainedWindow_) | 178 if (this.isConstrainedWindow_) |
175 url = appendParam(url, 'source', CONSTRAINED_FLOW_SOURCE); | 179 url = appendParam(url, 'source', CONSTRAINED_FLOW_SOURCE); |
176 return url; | 180 return url; |
177 }; | 181 }; |
178 | 182 |
179 /** | 183 /** |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return; | 285 return; |
282 } | 286 } |
283 | 287 |
284 if (!this.email_ && !this.skipForNow_) { | 288 if (!this.email_ && !this.skipForNow_) { |
285 this.webview_.src = this.initialFrameUrl_; | 289 this.webview_.src = this.initialFrameUrl_; |
286 return; | 290 return; |
287 } | 291 } |
288 | 292 |
289 this.listener_.onSuccess({email: this.email_, | 293 this.listener_.onSuccess({email: this.email_, |
290 gaiaId: this.gaiaId_, | 294 gaiaId: this.gaiaId_, |
291 password: this.password_, | 295 password: this.password_ || '', |
292 usingSAML: this.authFlow_ == AuthFlow.SAML, | 296 usingSAML: this.authFlow_ == AuthFlow.SAML, |
293 chooseWhatToSync: this.chooseWhatToSync_, | 297 chooseWhatToSync: this.chooseWhatToSync_, |
294 skipForNow: this.skipForNow_, | 298 skipForNow: this.skipForNow_, |
295 sessionIndex: this.sessionIndex_ || ''}); | 299 sessionIndex: this.sessionIndex_ || ''}); |
296 }; | 300 }; |
297 | 301 |
298 /** | 302 /** |
299 * Invoked when the webview attempts to open a new window. | 303 * Invoked when the webview attempts to open a new window. |
300 * @private | 304 * @private |
301 */ | 305 */ |
302 Authenticator.prototype.onNewWindow_ = function(e) { | 306 Authenticator.prototype.onNewWindow_ = function(e) { |
303 if (!this.listener_) { | 307 if (!this.listener_) { |
304 return; | 308 return; |
305 } | 309 } |
306 | 310 |
307 this.listener_.onNewWindow(e); | 311 this.listener_.onNewWindow(e); |
308 }; | 312 }; |
309 | 313 |
310 Authenticator.AuthFlow = AuthFlow; | 314 Authenticator.AuthFlow = AuthFlow; |
311 Authenticator.AuthMode = AuthMode; | 315 Authenticator.AuthMode = AuthMode; |
312 | 316 |
313 return { | 317 return { |
314 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old | 318 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old |
315 // iframe-based flow is deprecated. | 319 // iframe-based flow is deprecated. |
316 GaiaAuthHost: Authenticator | 320 GaiaAuthHost: Authenticator |
317 }; | 321 }; |
318 }); | 322 }); |
OLD | NEW |