| 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 * @fileoverview Oobe signin screen implementation. | 6 * @fileoverview Oobe signin screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('login', function() { | 9 cr.define('login', function() { |
| 10 // Gaia loading time after which portal check should be fired. | 10 // Gaia loading time after which portal check should be fired. |
| 11 const GAIA_LOADING_PORTAL_SUSSPECT_TIME_SEC = 5; | 11 /** @const */ var GAIA_LOADING_PORTAL_SUSSPECT_TIME_SEC = 5; |
| 12 | 12 |
| 13 // Maximum Gaia loading time in seconds. | 13 // Maximum Gaia loading time in seconds. |
| 14 const MAX_GAIA_LOADING_TIME_SEC = 60; | 14 /** @const */ var MAX_GAIA_LOADING_TIME_SEC = 60; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Creates a new sign in screen div. | 17 * Creates a new sign in screen div. |
| 18 * @constructor | 18 * @constructor |
| 19 * @extends {HTMLDivElement} | 19 * @extends {HTMLDivElement} |
| 20 */ | 20 */ |
| 21 var GaiaSigninScreen = cr.ui.define('div'); | 21 var GaiaSigninScreen = cr.ui.define('div'); |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Registers with Oobe. | 24 * Registers with Oobe. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 52 // Whether local version of Gaia page is used. | 52 // Whether local version of Gaia page is used. |
| 53 // @type {boolean} | 53 // @type {boolean} |
| 54 isLocal: false, | 54 isLocal: false, |
| 55 | 55 |
| 56 // Whether offline login is allowed. | 56 // Whether offline login is allowed. |
| 57 // @type {boolean} | 57 // @type {boolean} |
| 58 isOfflineAllowed: false, | 58 isOfflineAllowed: false, |
| 59 | 59 |
| 60 // Email of the user, which is logging in using offline mode. | 60 // Email of the user, which is logging in using offline mode. |
| 61 // @type {string} | 61 // @type {string} |
| 62 email: "", | 62 email: '', |
| 63 | 63 |
| 64 // Timer id of pending load. | 64 // Timer id of pending load. |
| 65 loadingTimer_: undefined, | 65 loadingTimer_: undefined, |
| 66 | 66 |
| 67 /** @inheritDoc */ | 67 /** @inheritDoc */ |
| 68 decorate: function() { | 68 decorate: function() { |
| 69 this.frame_ = $('signin-frame'); | 69 this.frame_ = $('signin-frame'); |
| 70 | 70 |
| 71 this.updateLocalizedContent(); | 71 this.updateLocalizedContent(); |
| 72 }, | 72 }, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 96 /** | 96 /** |
| 97 * Handler for Gaia loading suspiciously long timeout. | 97 * Handler for Gaia loading suspiciously long timeout. |
| 98 * @private | 98 * @private |
| 99 */ | 99 */ |
| 100 onLoadingSuspiciouslyLong_: function() { | 100 onLoadingSuspiciouslyLong_: function() { |
| 101 if (this != Oobe.getInstance().currentScreen) | 101 if (this != Oobe.getInstance().currentScreen) |
| 102 return; | 102 return; |
| 103 chrome.send('fixCaptivePortal'); | 103 chrome.send('fixCaptivePortal'); |
| 104 this.loadingTimer_ = window.setTimeout( | 104 this.loadingTimer_ = window.setTimeout( |
| 105 this.onLoadingTimeOut_.bind(this), | 105 this.onLoadingTimeOut_.bind(this), |
| 106 (MAX_GAIA_LOADING_TIME_SEC - GAIA_LOADING_PORTAL_SUSSPECT_TIME_SEC) | 106 (MAX_GAIA_LOADING_TIME_SEC - GAIA_LOADING_PORTAL_SUSSPECT_TIME_SEC) * |
| 107 * 1000); | 107 1000); |
| 108 }, | 108 }, |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * Handler for Gaia loading timeout. | 111 * Handler for Gaia loading timeout. |
| 112 * @private | 112 * @private |
| 113 */ | 113 */ |
| 114 onLoadingTimeOut_: function() { | 114 onLoadingTimeOut_: function() { |
| 115 this.loadingTimer_ = undefined; | 115 this.loadingTimer_ = undefined; |
| 116 this.clearRetry_(); | 116 this.clearRetry_(); |
| 117 $('error-message').showLoadingTimeoutError(); | 117 $('error-message').showLoadingTimeoutError(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 }, | 148 }, |
| 149 set loading(loading) { | 149 set loading(loading) { |
| 150 if (loading == this.loading) | 150 if (loading == this.loading) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 this.showLoadingUI_(loading); | 153 this.showLoadingUI_(loading); |
| 154 }, | 154 }, |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Event handler that is invoked just before the frame is shown. | 157 * Event handler that is invoked just before the frame is shown. |
| 158 * @param data {string} Screen init payload. Url of auth extension start | 158 * @param {string} data Screen init payload. Url of auth extension start |
| 159 * page. | 159 * page. |
| 160 */ | 160 */ |
| 161 onBeforeShow: function(data) { | 161 onBeforeShow: function(data) { |
| 162 // Announce the name of the screen, if accessibility is on. | 162 // Announce the name of the screen, if accessibility is on. |
| 163 $('gaia-signin-aria-label').setAttribute( | 163 $('gaia-signin-aria-label').setAttribute( |
| 164 'aria-label', localStrings.getString('signinScreenTitle')); | 164 'aria-label', localStrings.getString('signinScreenTitle')); |
| 165 | 165 |
| 166 // Button header is always visible when sign in is presented. | 166 // Button header is always visible when sign in is presented. |
| 167 // Header is hidden once GAIA reports on successful sign in. | 167 // Header is hidden once GAIA reports on successful sign in. |
| 168 Oobe.getInstance().headerHidden = false; | 168 Oobe.getInstance().headerHidden = false; |
| 169 }, | 169 }, |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * Loads the authentication extension into the iframe. | 172 * Loads the authentication extension into the iframe. |
| 173 * @param {Object} data Extension parameters bag. | 173 * @param {Object} data Extension parameters bag. |
| 174 * @private | 174 * @private |
| 175 */ | 175 */ |
| 176 loadAuthExtension_: function(data) { | 176 loadAuthExtension_: function(data) { |
| 177 this.silentLoad_ = data.silentLoad; | 177 this.silentLoad_ = data.silentLoad; |
| 178 this.isLocal = data.isLocal; | 178 this.isLocal = data.isLocal; |
| 179 this.email = ""; | 179 this.email = ''; |
| 180 | 180 |
| 181 // Offline sign-in is only allowed for the case when users aren't shown | 181 // Offline sign-in is only allowed for the case when users aren't shown |
| 182 // because there is no other way for an user to enter when device is | 182 // because there is no other way for an user to enter when device is |
| 183 // offline. | 183 // offline. |
| 184 this.isOfflineAllowed = !data.isShowUsers; | 184 this.isOfflineAllowed = !data.isShowUsers; |
| 185 | 185 |
| 186 this.updateAuthExtension_(data); | 186 this.updateAuthExtension_(data); |
| 187 | 187 |
| 188 var params = []; | 188 var params = []; |
| 189 if (data.gaiaOrigin) | 189 if (data.gaiaOrigin) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } else { | 245 } else { |
| 246 reasonLabel.hidden = true; | 246 reasonLabel.hidden = true; |
| 247 } | 247 } |
| 248 | 248 |
| 249 $('createAccount').hidden = !data.createAccount; | 249 $('createAccount').hidden = !data.createAccount; |
| 250 $('guestSignin').hidden = !data.guestSignin; | 250 $('guestSignin').hidden = !data.guestSignin; |
| 251 }, | 251 }, |
| 252 | 252 |
| 253 /** | 253 /** |
| 254 * Checks if message comes from the loaded authentication extension. | 254 * Checks if message comes from the loaded authentication extension. |
| 255 * @param e {object} Payload of the received HTML5 message. | 255 * @param {object} e Payload of the received HTML5 message. |
| 256 * @type {boolean} | 256 * @type {boolean} |
| 257 */ | 257 */ |
| 258 isAuthExtMessage_: function(e) { | 258 isAuthExtMessage_: function(e) { |
| 259 return this.extensionUrl_ != null && | 259 return this.extensionUrl_ != null && |
| 260 this.extensionUrl_.indexOf(e.origin) == 0 && | 260 this.extensionUrl_.indexOf(e.origin) == 0 && |
| 261 e.source == this.frame_.contentWindow; | 261 e.source == this.frame_.contentWindow; |
| 262 }, | 262 }, |
| 263 | 263 |
| 264 /** | 264 /** |
| 265 * Event handler that is invoked when HTML5 message is received. | 265 * Event handler that is invoked when HTML5 message is received. |
| 266 * @param e {object} Payload of the received HTML5 message. | 266 * @param {object} e Payload of the received HTML5 message. |
| 267 */ | 267 */ |
| 268 onMessage_: function(e) { | 268 onMessage_: function(e) { |
| 269 if (!this.isAuthExtMessage_(e)) { | 269 if (!this.isAuthExtMessage_(e)) { |
| 270 console.log('GaiaSigninScreen.onMessage_: Unknown message origin, ' + | 270 console.log('GaiaSigninScreen.onMessage_: Unknown message origin, ' + |
| 271 'e.origin=' + e.origin); | 271 'e.origin=' + e.origin); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 | 274 |
| 275 var msg = e.data; | 275 var msg = e.data; |
| 276 console.log('GaiaSigninScreen.onMessage_: method=' + msg.method); | 276 console.log('GaiaSigninScreen.onMessage_: method=' + msg.method); |
| 277 | 277 |
| 278 if (msg.method == 'completeLogin') { | 278 if (msg.method == 'completeLogin') { |
| 279 chrome.send('completeLogin', [msg.email, msg.password] ); | 279 chrome.send('completeLogin', [msg.email, msg.password]); |
| 280 this.loading = true; | 280 this.loading = true; |
| 281 // Now that we're in logged in state header should be hidden. | 281 // Now that we're in logged in state header should be hidden. |
| 282 Oobe.getInstance().headerHidden = true; | 282 Oobe.getInstance().headerHidden = true; |
| 283 } else if (msg.method == 'loginUILoaded') { | 283 } else if (msg.method == 'loginUILoaded') { |
| 284 this.loading = false; | 284 this.loading = false; |
| 285 $('error-message').update(); | 285 $('error-message').update(); |
| 286 this.clearLoadingTimer_(); | 286 this.clearLoadingTimer_(); |
| 287 // Show deferred error bubble. | 287 // Show deferred error bubble. |
| 288 if (this.errorBubble_) { | 288 if (this.errorBubble_) { |
| 289 this.showErrorBubble(this.errorBubble_[0], this.errorBubble_[1]); | 289 this.showErrorBubble(this.errorBubble_[0], this.errorBubble_[1]); |
| 290 this.errorBubble_ = undefined; | 290 this.errorBubble_ = undefined; |
| 291 } | 291 } |
| 292 this.clearRetry_(); | 292 this.clearRetry_(); |
| 293 chrome.send('loginWebuiReady'); | 293 chrome.send('loginWebuiReady'); |
| 294 } else if (msg.method =='offlineLogin') { | 294 // Report back sign in UI being painted. |
| 295 window.webkitRequestAnimationFrame(function() { |
| 296 chrome.send('loginVisible'); |
| 297 }); |
| 298 } else if (msg.method == 'offlineLogin') { |
| 295 this.email = msg.email; | 299 this.email = msg.email; |
| 296 chrome.send('authenticateUser', [msg.email, msg.password]); | 300 chrome.send('authenticateUser', [msg.email, msg.password]); |
| 297 this.loading = true; | 301 this.loading = true; |
| 298 Oobe.getInstance().headerHidden = true; | 302 Oobe.getInstance().headerHidden = true; |
| 299 } | 303 } |
| 300 }, | 304 }, |
| 301 | 305 |
| 302 /** | 306 /** |
| 303 * Clears input fields and switches to input mode. | 307 * Clears input fields and switches to input mode. |
| 304 * @param {boolean} takeFocus True to take focus. | 308 * @param {boolean} takeFocus True to take focus. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 this.startLoadingTimer_(); | 350 this.startLoadingTimer_(); |
| 347 }, | 351 }, |
| 348 | 352 |
| 349 /** | 353 /** |
| 350 * Schedules extension frame reload. | 354 * Schedules extension frame reload. |
| 351 */ | 355 */ |
| 352 scheduleRetry: function() { | 356 scheduleRetry: function() { |
| 353 if (this.retryCount_ >= 3 || this.retryTimer_) | 357 if (this.retryCount_ >= 3 || this.retryTimer_) |
| 354 return; | 358 return; |
| 355 | 359 |
| 356 const MAX_DELAY = 7200; // 7200 seconds (i.e. 2 hours) | 360 /** @const */ var MAX_DELAY = 7200; // 7200 seconds (i.e. 2 hours) |
| 357 const MIN_DELAY = 1; // 1 second | 361 /** @const */ var MIN_DELAY = 1; // 1 second |
| 358 | 362 |
| 359 var delay = Math.pow(2, this.retryCount_) * 5; | 363 var delay = Math.pow(2, this.retryCount_) * 5; |
| 360 delay = Math.max(MIN_DELAY, Math.min(MAX_DELAY, delay)) * 1000; | 364 delay = Math.max(MIN_DELAY, Math.min(MAX_DELAY, delay)) * 1000; |
| 361 | 365 |
| 362 ++this.retryCount_; | 366 ++this.retryCount_; |
| 363 this.retryTimer_ = window.setTimeout(this.doReload.bind(this), delay); | 367 this.retryTimer_ = window.setTimeout(this.doReload.bind(this), delay); |
| 364 console.log('GaiaSigninScreen scheduleRetry in ' + delay + 'ms.'); | 368 console.log('GaiaSigninScreen scheduleRetry in ' + delay + 'ms.'); |
| 365 }, | 369 }, |
| 366 | 370 |
| 367 /** | 371 /** |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 * @param {Object} data New extension parameters bag. | 431 * @param {Object} data New extension parameters bag. |
| 428 */ | 432 */ |
| 429 GaiaSigninScreen.updateAuthExtension = function(data) { | 433 GaiaSigninScreen.updateAuthExtension = function(data) { |
| 430 $('gaia-signin').updateAuthExtension_(data); | 434 $('gaia-signin').updateAuthExtension_(data); |
| 431 }; | 435 }; |
| 432 | 436 |
| 433 return { | 437 return { |
| 434 GaiaSigninScreen: GaiaSigninScreen | 438 GaiaSigninScreen: GaiaSigninScreen |
| 435 }; | 439 }; |
| 436 }); | 440 }); |
| OLD | NEW |