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

Side by Side Diff: chrome/browser/resources/gaia_auth_host/authenticator.js

Issue 789353004: Host Chrome OS GAIA signin page in webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + switch to messages instead of listener interface Created 5 years, 11 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 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 // TODO(rogerta): should use gaia URL from GaiaUrls::gaia_url() instead 15 // TODO(rogerta): should use gaia URL from GaiaUrls::gaia_url() instead
16 // of hardcoding the prod URL here. As is, this does not work with staging 16 // of hardcoding the prod URL here. As is, this does not work with staging
17 // environments. 17 // environments.
18 var IDP_ORIGIN = 'https://accounts.google.com/'; 18 var IDP_ORIGIN = 'https://accounts.google.com/';
19 var IDP_PATH = 'ServiceLogin?skipvpage=true&sarp=1&rm=hide'; 19 var IDP_PATH = 'ServiceLogin?skipvpage=true&sarp=1&rm=hide';
20 var CONTINUE_URL = 20 var CONTINUE_URL =
21 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/success.html'; 21 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/success.html';
22 var SIGN_IN_HEADER = 'google-accounts-signin'; 22 var SIGN_IN_HEADER = 'google-accounts-signin';
23 var EMBEDDED_FORM_HEADER = 'google-accounts-embedded'; 23 var EMBEDDED_FORM_HEADER = 'google-accounts-embedded';
24 var SAML_HEADER = 'google-accounts-saml'; 24 var SAML_HEADER = 'google-accounts-saml';
25 var SERVICE_ID = 'chromeoslogin';
25 26
26 /** 27 /**
27 * The source URL parameter for the constrained signin flow. 28 * The source URL parameter for the constrained signin flow.
28 */ 29 */
29 var CONSTRAINED_FLOW_SOURCE = 'chrome'; 30 var CONSTRAINED_FLOW_SOURCE = 'chrome';
30 31
31 /** 32 /**
32 * Enum for the authorization mode, must match AuthMode defined in 33 * Enum for the authorization mode, must match AuthMode defined in
33 * chrome/browser/ui/webui/inline_login_ui.cc. 34 * chrome/browser/ui/webui/inline_login_ui.cc.
34 * @enum {number} 35 * @enum {number}
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 types: ['main_frame']}, 107 types: ['main_frame']},
107 ['responseHeaders']); 108 ['responseHeaders']);
108 this.webview_.request.onHeadersReceived.addListener( 109 this.webview_.request.onHeadersReceived.addListener(
109 this.onHeadersReceived_.bind(this), 110 this.onHeadersReceived_.bind(this),
110 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']}, 111 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']},
111 ['responseHeaders']); 112 ['responseHeaders']);
112 window.addEventListener( 113 window.addEventListener(
113 'message', this.onMessageFromWebview_.bind(this), false); 114 'message', this.onMessageFromWebview_.bind(this), false);
114 window.addEventListener( 115 window.addEventListener(
115 'popstate', this.onPopState_.bind(this), false); 116 'popstate', this.onPopState_.bind(this), false);
117
118 this.loaded_ = false;
116 }; 119 };
117 120
118 /** 121 /**
119 * Reloads the authenticator component. 122 * Reloads the authenticator component.
120 */ 123 */
121 Authenticator.prototype.reload = function() { 124 Authenticator.prototype.reload = function() {
122 this.webview_.src = this.reloadUrl_; 125 this.webview_.src = this.reloadUrl_;
123 this.authFlow_ = AuthFlow.DEFAULT; 126 this.authFlow_ = AuthFlow.DEFAULT;
127 this.loaded_ = false;
124 }; 128 };
125 129
126 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { 130 Authenticator.prototype.constructInitialFrameUrl_ = function(data) {
127 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); 131 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH);
128 132
129 url = appendParam(url, 'continue', this.continueUrl_); 133 url = appendParam(url, 'continue', this.continueUrl_);
130 url = appendParam(url, 'service', data.service); 134 url = appendParam(url, 'service', data.service || SERVICE_ID);
131 if (data.hl) 135 if (data.hl)
132 url = appendParam(url, 'hl', data.hl); 136 url = appendParam(url, 'hl', data.hl);
133 if (data.email) 137 if (data.email)
134 url = appendParam(url, 'Email', data.email); 138 url = appendParam(url, 'Email', data.email);
135 if (this.isConstrainedWindow_) 139 if (this.isConstrainedWindow_)
136 url = appendParam(url, 'source', CONSTRAINED_FLOW_SOURCE); 140 url = appendParam(url, 'source', CONSTRAINED_FLOW_SOURCE);
137 return url; 141 return url;
138 }; 142 };
139 143
140 /** 144 /**
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 Authenticator.prototype.onAuthCompleted_ = function() { 267 Authenticator.prototype.onAuthCompleted_ = function() {
264 if (!this.email_ && !this.skipForNow_) { 268 if (!this.email_ && !this.skipForNow_) {
265 this.webview_.src = this.initialFrameUrl_; 269 this.webview_.src = this.initialFrameUrl_;
266 return; 270 return;
267 } 271 }
268 272
269 this.dispatchEvent( 273 this.dispatchEvent(
270 new CustomEvent('authCompleted', 274 new CustomEvent('authCompleted',
271 {detail: {email: this.email_, 275 {detail: {email: this.email_,
272 gaiaId: this.gaiaId_, 276 gaiaId: this.gaiaId_,
273 password: this.password_, 277 password: this.password_ || '',
274 usingSAML: this.authFlow_ == AuthFlow.SAML, 278 usingSAML: this.authFlow_ == AuthFlow.SAML,
275 chooseWhatToSync: this.chooseWhatToSync_, 279 chooseWhatToSync: this.chooseWhatToSync_,
276 skipForNow: this.skipForNow_, 280 skipForNow: this.skipForNow_,
277 sessionIndex: this.sessionIndex_ || '', 281 sessionIndex: this.sessionIndex_ || '',
278 trusted: this.trusted_}})); 282 trusted: this.trusted_}}));
279 }; 283 };
280 284
281 /** 285 /**
282 * Invoked when the webview attempts to open a new window. 286 * Invoked when the webview attempts to open a new window.
283 * @private 287 * @private
(...skipping 16 matching lines...) Expand all
300 304
301 Authenticator.AuthFlow = AuthFlow; 305 Authenticator.AuthFlow = AuthFlow;
302 Authenticator.AuthMode = AuthMode; 306 Authenticator.AuthMode = AuthMode;
303 307
304 return { 308 return {
305 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old 309 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old
306 // iframe-based flow is deprecated. 310 // iframe-based flow is deprecated.
307 GaiaAuthHost: Authenticator 311 GaiaAuthHost: Authenticator
308 }; 312 };
309 }); 313 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698