| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 host gaia auth extension in an iframe. | 6 * @fileoverview An UI component to host gaia auth extension in an iframe. |
| 7 * After the component binds with an iframe, call its {@code load} to start the | 7 * After the component binds with an iframe, call its {@code load} to start the |
| 8 * authentication flow. There are two events would be raised after this point: | 8 * authentication flow. There are two events would be raised after this point: |
| 9 * a 'ready' event when the authentication UI is ready to use and a 'completed' | 9 * a 'ready' event when the authentication UI is ready to use and a 'completed' |
| 10 * event when the authentication is completed successfully. If caller is | 10 * event when the authentication is completed successfully. If caller is |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 this.frame_ = typeof container == 'string' ? $(container) : container; | 103 this.frame_ = typeof container == 'string' ? $(container) : container; |
| 104 assert(this.frame_); | 104 assert(this.frame_); |
| 105 window.addEventListener('message', | 105 window.addEventListener('message', |
| 106 this.onMessage_.bind(this), false); | 106 this.onMessage_.bind(this), false); |
| 107 } | 107 } |
| 108 | 108 |
| 109 GaiaAuthHost.prototype = { | 109 GaiaAuthHost.prototype = { |
| 110 __proto__: cr.EventTarget.prototype, | 110 __proto__: cr.EventTarget.prototype, |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * Auth extension params |
| 114 * @type {Object} |
| 115 */ |
| 116 authParams_: {}, |
| 117 |
| 118 /** |
| 113 * An url to use with {@code reload}. | 119 * An url to use with {@code reload}. |
| 114 * @type {?string} | 120 * @type {?string} |
| 115 * @private | 121 * @private |
| 116 */ | 122 */ |
| 117 reloadUrl_: null, | 123 reloadUrl_: null, |
| 118 | 124 |
| 119 /** | 125 /** |
| 120 * The domain name of the current auth page. | 126 * The domain name of the current auth page. |
| 121 * @type {string} | 127 * @type {string} |
| 122 */ | 128 */ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 /** | 236 /** |
| 231 * Loads the auth extension. | 237 * Loads the auth extension. |
| 232 * @param {AuthMode} authMode Authorization mode. | 238 * @param {AuthMode} authMode Authorization mode. |
| 233 * @param {Object} data Parameters for the auth extension. See the auth | 239 * @param {Object} data Parameters for the auth extension. See the auth |
| 234 * extension's main.js for all supported params and their defaults. | 240 * extension's main.js for all supported params and their defaults. |
| 235 * @param {function(Object)} successCallback A function to be called when | 241 * @param {function(Object)} successCallback A function to be called when |
| 236 * the authentication is completed successfully. The callback is | 242 * the authentication is completed successfully. The callback is |
| 237 * invoked with a credential object. | 243 * invoked with a credential object. |
| 238 */ | 244 */ |
| 239 load: function(authMode, data, successCallback) { | 245 load: function(authMode, data, successCallback) { |
| 240 var params = []; | 246 var params = {}; |
| 241 | 247 |
| 242 var populateParams = function(nameList, values) { | 248 var populateParams = function(nameList, values) { |
| 243 if (!values) | 249 if (!values) |
| 244 return; | 250 return; |
| 245 | 251 |
| 246 for (var i in nameList) { | 252 for (var i in nameList) { |
| 247 var name = nameList[i]; | 253 var name = nameList[i]; |
| 248 if (values[name]) | 254 if (values[name]) |
| 249 params.push(name + '=' + encodeURIComponent(values[name])); | 255 params[name] = values[name]; |
| 250 } | 256 } |
| 251 }; | 257 }; |
| 252 | 258 |
| 253 populateParams(SUPPORTED_PARAMS, data); | 259 populateParams(SUPPORTED_PARAMS, data); |
| 254 populateParams(LOCALIZED_STRING_PARAMS, data.localizedStrings); | 260 populateParams(LOCALIZED_STRING_PARAMS, data.localizedStrings); |
| 255 params.push('parentPage=' + encodeURIComponent(window.location.origin)); | 261 params['needPassword'] = true; |
| 256 params.push('needPassword=1'); | |
| 257 | 262 |
| 258 var url; | 263 var url; |
| 259 switch (authMode) { | 264 switch (authMode) { |
| 260 case AuthMode.OFFLINE: | 265 case AuthMode.OFFLINE: |
| 261 url = OFFLINE_AUTH_URL; | 266 url = OFFLINE_AUTH_URL; |
| 262 break; | 267 break; |
| 263 case AuthMode.DESKTOP: | 268 case AuthMode.DESKTOP: |
| 264 url = AUTH_URL; | 269 url = AUTH_URL; |
| 265 params.push('desktopMode=1'); | 270 params['desktopMode'] = true; |
| 266 break; | 271 break; |
| 267 default: | 272 default: |
| 268 url = AUTH_URL; | 273 url = AUTH_URL; |
| 269 } | 274 } |
| 270 url += '?' + params.join('&'); | |
| 271 | 275 |
| 272 this.frame_.src = url; | 276 this.authParams_ = params; |
| 273 this.reloadUrl_ = url; | 277 this.reloadUrl_ = url; |
| 274 this.successCallback_ = successCallback; | 278 this.successCallback_ = successCallback; |
| 275 this.authFlow = AuthFlow.GAIA; | 279 |
| 280 this.reload(); |
| 276 }, | 281 }, |
| 277 | 282 |
| 278 /** | 283 /** |
| 279 * Reloads the auth extension. | 284 * Reloads the auth extension. |
| 280 */ | 285 */ |
| 281 reload: function() { | 286 reload: function() { |
| 287 var sendParamsOnLoad = function() { |
| 288 this.frame_.removeEventListener('load', sendParamsOnLoad); |
| 289 this.frame_.contentWindow.postMessage(this.authParams_, AUTH_URL_BASE); |
| 290 }.bind(this); |
| 291 |
| 292 this.frame_.addEventListener('load', sendParamsOnLoad); |
| 282 this.frame_.src = this.reloadUrl_; | 293 this.frame_.src = this.reloadUrl_; |
| 283 this.authFlow = AuthFlow.GAIA; | 294 this.authFlow = AuthFlow.GAIA; |
| 284 }, | 295 }, |
| 285 | 296 |
| 286 /** | 297 /** |
| 287 * Verifies the supplied password by sending it to the auth extension, | 298 * Verifies the supplied password by sending it to the auth extension, |
| 288 * which will then check if it matches the scraped passwords. | 299 * which will then check if it matches the scraped passwords. |
| 289 * @param {string} password The confirmed password that needs verification. | 300 * @param {string} password The confirmed password that needs verification. |
| 290 */ | 301 */ |
| 291 verifyConfirmedPassword: function(password) { | 302 verifyConfirmedPassword: function(password) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 434 |
| 424 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 435 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
| 425 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; | 436 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; |
| 426 GaiaAuthHost.AuthMode = AuthMode; | 437 GaiaAuthHost.AuthMode = AuthMode; |
| 427 GaiaAuthHost.AuthFlow = AuthFlow; | 438 GaiaAuthHost.AuthFlow = AuthFlow; |
| 428 | 439 |
| 429 return { | 440 return { |
| 430 GaiaAuthHost: GaiaAuthHost | 441 GaiaAuthHost: GaiaAuthHost |
| 431 }; | 442 }; |
| 432 }); | 443 }); |
| OLD | NEW |