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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 this.isConstrainedWindow_ = data.constrained == '1'; | 109 this.isConstrainedWindow_ = data.constrained == '1'; |
110 | 110 |
111 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); | 111 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); |
112 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; | 112 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; |
113 this.authFlow_ = AuthFlow.DEFAULT; | 113 this.authFlow_ = AuthFlow.DEFAULT; |
114 | 114 |
115 this.webview_.src = this.reloadUrl_; | 115 this.webview_.src = this.reloadUrl_; |
116 this.webview_.addEventListener( | 116 this.webview_.addEventListener( |
117 'newwindow', this.onNewWindow_.bind(this)); | 117 'newwindow', this.onNewWindow_.bind(this)); |
118 this.webview_.addEventListener( | 118 this.webview_.addEventListener( |
119 'contentload', this.onContentLoad_.bind(this)); | |
120 this.webview_.addEventListener( | |
119 'loadstop', this.onLoadStop_.bind(this)); | 121 'loadstop', this.onLoadStop_.bind(this)); |
120 this.webview_.request.onCompleted.addListener( | 122 this.webview_.request.onCompleted.addListener( |
121 this.onRequestCompleted_.bind(this), | 123 this.onRequestCompleted_.bind(this), |
122 {urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'], | 124 {urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'], |
123 types: ['main_frame']}, | 125 types: ['main_frame']}, |
124 ['responseHeaders']); | 126 ['responseHeaders']); |
125 this.webview_.request.onHeadersReceived.addListener( | 127 this.webview_.request.onHeadersReceived.addListener( |
126 this.onHeadersReceived_.bind(this), | 128 this.onHeadersReceived_.bind(this), |
127 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']}, | 129 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']}, |
128 ['responseHeaders']); | 130 ['responseHeaders']); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 } | 191 } |
190 } | 192 } |
191 if (!isEmbeddedPage) { | 193 if (!isEmbeddedPage) { |
192 this.dispatchEvent(new CustomEvent('resize', {detail: currentUrl})); | 194 this.dispatchEvent(new CustomEvent('resize', {detail: currentUrl})); |
193 return; | 195 return; |
194 } | 196 } |
195 } | 197 } |
196 | 198 |
197 this.updateHistoryState_(currentUrl); | 199 this.updateHistoryState_(currentUrl); |
198 | 200 |
199 // Posts a message to IdP pages to initiate communication. | |
200 if (currentUrl.lastIndexOf(this.idpOrigin_) == 0) | |
201 this.webview_.contentWindow.postMessage({}, currentUrl); | |
202 }; | 201 }; |
203 | 202 |
204 /** | 203 /** |
205 * Manually updates the history. Invoked upon completion of a webview | 204 * Manually updates the history. Invoked upon completion of a webview |
206 * navigation. | 205 * navigation. |
207 * @param {string} url Request URL. | 206 * @param {string} url Request URL. |
208 * @private | 207 * @private |
209 */ | 208 */ |
210 Authenticator.prototype.updateHistoryState_ = function(url) { | 209 Authenticator.prototype.updateHistoryState_ = function(url) { |
211 if (history.state && history.state.url != url) | 210 if (history.state && history.state.url != url) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 var header = headers[i]; | 246 var header = headers[i]; |
248 var headerName = header.name.toLowerCase(); | 247 var headerName = header.name.toLowerCase(); |
249 if (headerName == SIGN_IN_HEADER) { | 248 if (headerName == SIGN_IN_HEADER) { |
250 var headerValues = header.value.toLowerCase().split(','); | 249 var headerValues = header.value.toLowerCase().split(','); |
251 var signinDetails = {}; | 250 var signinDetails = {}; |
252 headerValues.forEach(function(e) { | 251 headerValues.forEach(function(e) { |
253 var pair = e.split('='); | 252 var pair = e.split('='); |
254 signinDetails[pair[0].trim()] = pair[1].trim(); | 253 signinDetails[pair[0].trim()] = pair[1].trim(); |
255 }); | 254 }); |
256 // Removes "" around. | 255 // Removes "" around. |
257 var email = signinDetails['email'].slice(1, -1); | 256 this.email_ = signinDetails['email'].slice(1, -1); |
258 if (this.email_ != email) { | |
259 this.email_ = email; | |
260 // Clears the scraped password if the email has changed. | |
261 this.password_ = null; | |
262 } | |
263 this.gaiaId_ = signinDetails['obfuscatedid'].slice(1, -1); | 257 this.gaiaId_ = signinDetails['obfuscatedid'].slice(1, -1); |
264 this.sessionIndex_ = signinDetails['sessionindex']; | 258 this.sessionIndex_ = signinDetails['sessionindex']; |
265 } else if (headerName == SAML_HEADER) { | 259 } else if (headerName == SAML_HEADER) { |
266 this.authFlow_ = AuthFlow.SAML; | 260 this.authFlow_ = AuthFlow.SAML; |
267 } | 261 } |
268 } | 262 } |
269 }; | 263 }; |
270 | 264 |
271 /** | 265 /** |
272 * Invoked when an HTML5 message is received from the webview element. | 266 * Invoked when an HTML5 message is received from the webview element. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 }; | 304 }; |
311 | 305 |
312 /** | 306 /** |
313 * Invoked when the webview attempts to open a new window. | 307 * Invoked when the webview attempts to open a new window. |
314 * @private | 308 * @private |
315 */ | 309 */ |
316 Authenticator.prototype.onNewWindow_ = function(e) { | 310 Authenticator.prototype.onNewWindow_ = function(e) { |
317 this.dispatchEvent(new CustomEvent('newWindow', {detail: e})); | 311 this.dispatchEvent(new CustomEvent('newWindow', {detail: e})); |
318 }; | 312 }; |
319 | 313 |
314 Authenticator.prototype.onContentLoad_ = function(e) { | |
315 // Posts a message to IdP pages to initiate communication. | |
316 var currentUrl = this.webview_.src; | |
317 if (currentUrl.lastIndexOf(this.idpOrigin_) == 0) { | |
318 this.webview_.contentWindow.postMessage({}, currentUrl); | |
319 } | |
320 }; | |
xiyuan
2015/01/30 18:19:51
nit: insert a blank line after
Roman Sorokin (ftl)
2015/02/02 08:55:54
Done.
| |
320 /** | 321 /** |
321 * Invoked when the webview finishes loading a page. | 322 * Invoked when the webview finishes loading a page. |
322 * @private | 323 * @private |
323 */ | 324 */ |
324 Authenticator.prototype.onLoadStop_ = function(e) { | 325 Authenticator.prototype.onLoadStop_ = function(e) { |
325 if (!this.loaded_) { | 326 if (!this.loaded_) { |
326 this.loaded_ = true; | 327 this.loaded_ = true; |
327 this.webview_.focus(); | 328 this.webview_.focus(); |
328 this.dispatchEvent(new Event('ready')); | 329 this.dispatchEvent(new Event('ready')); |
329 } | 330 } |
330 }; | 331 }; |
331 | 332 |
332 Authenticator.AuthFlow = AuthFlow; | 333 Authenticator.AuthFlow = AuthFlow; |
333 Authenticator.AuthMode = AuthMode; | 334 Authenticator.AuthMode = AuthMode; |
334 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 335 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
335 | 336 |
336 return { | 337 return { |
337 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old | 338 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old |
338 // iframe-based flow is deprecated. | 339 // iframe-based flow is deprecated. |
339 GaiaAuthHost: Authenticator | 340 GaiaAuthHost: Authenticator |
340 }; | 341 }; |
341 }); | 342 }); |
OLD | NEW |