OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Authenticator class wraps the communications between Gaia and its host. | 6 * Authenticator class wraps the communications between Gaia and its host. |
7 */ | 7 */ |
8 function Authenticator() { | 8 function Authenticator() { |
9 } | 9 } |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 'newwindow', this.onWebviewNewWindow_.bind(this, gaiaFrame)); | 175 'newwindow', this.onWebviewNewWindow_.bind(this, gaiaFrame)); |
176 } | 176 } |
177 if (this.constrained_) { | 177 if (this.constrained_) { |
178 gaiaFrame.request.onCompleted.addListener( | 178 gaiaFrame.request.onCompleted.addListener( |
179 this.onWebviewRequestCompleted_.bind(this), | 179 this.onWebviewRequestCompleted_.bind(this), |
180 {urls: ['<all_urls>'], types: ['main_frame']}, | 180 {urls: ['<all_urls>'], types: ['main_frame']}, |
181 ['responseHeaders']); | 181 ['responseHeaders']); |
182 } | 182 } |
183 }, | 183 }, |
184 | 184 |
185 completeLogin: function(username, password) { | 185 completeLogin: function() { |
186 var msg = { | 186 var msg = { |
187 'method': 'completeLogin', | 187 'method': 'completeLogin', |
188 'email': username, | 188 'email': this.email_, |
189 'password': password | 189 'password': this.password_, |
| 190 'usingSAML': this.isSAMLFlow_ |
190 }; | 191 }; |
191 window.parent.postMessage(msg, this.parentPage_); | 192 window.parent.postMessage(msg, this.parentPage_); |
192 if (this.samlSupportChannel_) | 193 if (this.samlSupportChannel_) |
193 this.samlSupportChannel_.send({name: 'resetAuth'}); | 194 this.samlSupportChannel_.send({name: 'resetAuth'}); |
194 }, | 195 }, |
195 | 196 |
196 onPageLoad: function(e) { | 197 onPageLoad: function(e) { |
197 window.addEventListener('message', this.onMessage.bind(this), false); | 198 window.addEventListener('message', this.onMessage.bind(this), false); |
198 this.loadFrame_(); | 199 this.loadFrame_(); |
199 }, | 200 }, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 gaiaFrame.focus(); | 271 gaiaFrame.focus(); |
271 gaiaFrame.onblur = function() { | 272 gaiaFrame.onblur = function() { |
272 gaiaFrame.focus(); | 273 gaiaFrame.focus(); |
273 }; | 274 }; |
274 } | 275 } |
275 this.loaded_ = true; | 276 this.loaded_ = true; |
276 }, | 277 }, |
277 | 278 |
278 onConfirmLogin_: function() { | 279 onConfirmLogin_: function() { |
279 if (!this.isSAMLFlow_) { | 280 if (!this.isSAMLFlow_) { |
280 this.completeLogin(this.email_, this.password_); | 281 this.completeLogin(); |
281 return; | 282 return; |
282 } | 283 } |
283 | 284 |
284 // Retrieve the e-mail address of the user who just authenticated from GAIA. | 285 // Retrieve the e-mail address of the user who just authenticated from GAIA. |
285 window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', | 286 window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', |
286 attemptToken: this.attemptToken_}, | 287 attemptToken: this.attemptToken_}, |
287 this.parentPage_); | 288 this.parentPage_); |
288 | 289 |
289 if (!this.password_) { | 290 if (!this.password_) { |
290 this.samlSupportChannel_.sendWithCallback( | 291 this.samlSupportChannel_.sendWithCallback( |
291 {name: 'getScrapedPasswords'}, | 292 {name: 'getScrapedPasswords'}, |
292 function(passwords) { | 293 function(passwords) { |
293 if (passwords.length == 0) { | 294 if (passwords.length == 0) { |
294 window.parent.postMessage( | 295 window.parent.postMessage( |
295 {method: 'noPassword', email: this.email_}, | 296 {method: 'noPassword', email: this.email_}, |
296 this.parentPage_); | 297 this.parentPage_); |
297 } else { | 298 } else { |
298 window.parent.postMessage( | 299 window.parent.postMessage( |
299 {method: 'confirmPassword', email: this.email_}, | 300 {method: 'confirmPassword', email: this.email_}, |
300 this.parentPage_); | 301 this.parentPage_); |
301 } | 302 } |
302 }.bind(this)); | 303 }.bind(this)); |
303 } | 304 } |
304 }, | 305 }, |
305 | 306 |
306 maybeCompleteSAMLLogin_: function() { | 307 maybeCompleteSAMLLogin_: function() { |
307 // SAML login is complete when the user's e-mail address has been retrieved | 308 // SAML login is complete when the user's e-mail address has been retrieved |
308 // from GAIA and the user has successfully confirmed the password. | 309 // from GAIA and the user has successfully confirmed the password. |
309 if (this.email_ !== null && this.password_ !== null) | 310 if (this.email_ !== null && this.password_ !== null) |
310 this.completeLogin(this.email_, this.password_); | 311 this.completeLogin(); |
311 }, | 312 }, |
312 | 313 |
313 onVerifyConfirmedPassword_: function(password) { | 314 onVerifyConfirmedPassword_: function(password) { |
314 this.samlSupportChannel_.sendWithCallback( | 315 this.samlSupportChannel_.sendWithCallback( |
315 {name: 'getScrapedPasswords'}, | 316 {name: 'getScrapedPasswords'}, |
316 function(passwords) { | 317 function(passwords) { |
317 for (var i = 0; i < passwords.length; ++i) { | 318 for (var i = 0; i < passwords.length; ++i) { |
318 if (passwords[i] == password) { | 319 if (passwords[i] == password) { |
319 this.password_ = passwords[i]; | 320 this.password_ = passwords[i]; |
320 this.maybeCompleteSAMLLogin_(); | 321 this.maybeCompleteSAMLLogin_(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } else if (msg.method == 'redirectToSignin' && | 365 } else if (msg.method == 'redirectToSignin' && |
365 this.isParentMessage_(e)) { | 366 this.isParentMessage_(e)) { |
366 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 367 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
367 } else { | 368 } else { |
368 console.error('Authenticator.onMessage: unknown message + origin!?'); | 369 console.error('Authenticator.onMessage: unknown message + origin!?'); |
369 } | 370 } |
370 } | 371 } |
371 }; | 372 }; |
372 | 373 |
373 Authenticator.getInstance().initialize(); | 374 Authenticator.getInstance().initialize(); |
OLD | NEW |