| 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 login.createScreen('GaiaSigninScreen', 'gaia-signin', function() { | 9 login.createScreen('GaiaSigninScreen', 'gaia-signin', function() { |
| 10 // GAIA animation guard timer. Started when GAIA page is loaded | 10 // GAIA animation guard timer. Started when GAIA page is loaded |
| 11 // (Authenticator 'ready' event) and is intended to guard against edge cases | 11 // (Authenticator 'ready' event) and is intended to guard against edge cases |
| 12 // when 'showView' message is not generated/received. | 12 // when 'showView' message is not generated/received. |
| 13 /** @const */ var GAIA_ANIMATION_GUARD_MILLISEC = 300; | 13 /** @const */ var GAIA_ANIMATION_GUARD_MILLISEC = 300; |
| 14 | 14 |
| 15 // Maximum Gaia loading time in seconds. | 15 // Maximum Gaia loading time in seconds. |
| 16 /** @const */ var MAX_GAIA_LOADING_TIME_SEC = 60; | 16 /** @const */ var MAX_GAIA_LOADING_TIME_SEC = 60; |
| 17 | 17 |
| 18 // The help topic regarding user not being in the whitelist. | 18 // The help topic regarding user not being in the whitelist. |
| 19 /** @const */ var HELP_CANT_ACCESS_ACCOUNT = 188036; | 19 /** @const */ var HELP_CANT_ACCESS_ACCOUNT = 188036; |
| 20 | 20 |
| 21 // Amount of time the user has to be idle for before showing the online login | 21 // Amount of time the user has to be idle for before showing the online login |
| 22 // page. | 22 // page. |
| 23 /** @const */ var IDLE_TIME_UNTIL_EXIT_OFFLINE_IN_MILLISECONDS = 180 * 1000; | 23 /** @const */ var IDLE_TIME_UNTIL_EXIT_OFFLINE_IN_MILLISECONDS = 180 * 1000; |
| 24 | 24 |
| 25 // Approximate amount of time between checks to see if we should go to the | 25 // Approximate amount of time between checks to see if we should go to the |
| 26 // online login page when we're in the offline login page and the device is | 26 // online login page when we're in the offline login page and the device is |
| 27 // online. | 27 // online. |
| 28 /** @const */ var IDLE_TIME_CHECK_FREQUENCY = 5 * 1000; | 28 /** @const */ var IDLE_TIME_CHECK_FREQUENCY = 5 * 1000; |
| 29 | 29 |
| 30 /** |
| 31 * The modes this screen can be in. |
| 32 * @enum {integer} |
| 33 */ |
| 34 var ScreenMode = { |
| 35 DEFAULT: 0, // Default GAIA login flow. |
| 36 OFFLINE: 1, // GAIA offline login. |
| 37 SAML_INTERSTITIAL: 2 // Interstitial page before SAML redirection. |
| 38 }; |
| 39 |
| 30 return { | 40 return { |
| 31 EXTERNAL_API: [ | 41 EXTERNAL_API: [ |
| 32 'loadAuthExtension', | 42 'loadAuthExtension', |
| 33 'doReload', | 43 'doReload', |
| 34 'monitorOfflineIdle', | 44 'monitorOfflineIdle', |
| 35 'updateControlsState', | 45 'updateControlsState', |
| 36 'showWhitelistCheckFailedError', | 46 'showWhitelistCheckFailedError', |
| 37 ], | 47 ], |
| 38 | 48 |
| 39 /** | 49 /** |
| 40 * Saved gaia auth host load params. | 50 * Saved gaia auth host load params. |
| 41 * @type {?string} | 51 * @type {?string} |
| 42 * @private | 52 * @private |
| 43 */ | 53 */ |
| 44 gaiaAuthParams_: null, | 54 gaiaAuthParams_: null, |
| 45 | 55 |
| 46 /** | 56 /** |
| 47 * Whether offline version of Gaia page is used. | 57 * Current mode of this screen. |
| 48 * @type {boolean} | 58 * @type {integer} |
| 49 * @private | 59 * @private |
| 50 */ | 60 */ |
| 51 isOffline_: false, | 61 screenMode_: ScreenMode.DEFAULT, |
| 52 | 62 |
| 53 /** | 63 /** |
| 54 * Email of the user, which is logging in using offline mode. | 64 * Email of the user, which is logging in using offline mode. |
| 55 * @type {string} | 65 * @type {string} |
| 56 */ | 66 */ |
| 57 email: '', | 67 email: '', |
| 58 | 68 |
| 59 /** | 69 /** |
| 60 * Timer id of pending load. | 70 * Timer id of pending load. |
| 61 * @type {number} | 71 * @type {number} |
| 62 * @private | 72 * @private |
| 63 */ | 73 */ |
| 64 loadingTimer_: undefined, | 74 loadingTimer_: undefined, |
| 65 | 75 |
| 66 /** | 76 /** |
| 67 * Timer id of a guard timer that is fired in case 'showView' message | 77 * Timer id of a guard timer that is fired in case 'showView' message |
| 68 * is not received from GAIA. | 78 * is not received from GAIA. |
| 69 * @type {number} | 79 * @type {number} |
| 70 * @private | 80 * @private |
| 71 */ | 81 */ |
| 72 loadAnimationGuardTimer_: undefined, | 82 loadAnimationGuardTimer_: undefined, |
| 73 | 83 |
| 74 /** | 84 /** |
| 75 * Whether we've processed 'showView' message - either from GAIA or from | 85 * Whether we've processed 'showView' message - either from GAIA or from |
| 76 * guard timer. | 86 * guard timer. |
| 77 * @type {boolean} | 87 * @type {boolean} |
| 78 * @private | 88 * @private |
| 79 */ | 89 */ |
| 80 showViewProcessed_: undefined, | 90 showViewProcessed_: false, |
| 81 | 91 |
| 82 /** | 92 /** |
| 83 * Whether we've processed 'authCompleted' message. | 93 * Whether we've processed 'authCompleted' message. |
| 84 * @type {boolean} | 94 * @type {boolean} |
| 85 * @private | 95 * @private |
| 86 */ | 96 */ |
| 87 authCompleted_: false, | 97 authCompleted_: false, |
| 88 | 98 |
| 89 /** | 99 /** |
| 90 * Value contained in the last received 'backButton' event. | 100 * Value contained in the last received 'backButton' event. |
| 91 * @type {boolean} | 101 * @type {boolean} |
| 92 * @private | 102 * @private |
| 93 */ | 103 */ |
| 94 lastBackMessageValue_: false, | 104 lastBackMessageValue_: false, |
| 95 | 105 |
| 96 /** | 106 /** |
| 97 * Whether the dialog could be closed. | 107 * Whether the dialog could be closed. |
| 98 * @type {boolean} | 108 * @type {boolean} |
| 99 */ | 109 */ |
| 100 get closable() { | 110 get closable() { |
| 101 return !!$('pod-row').pods.length || this.isOffline; | 111 return !!$('pod-row').pods.length || this.isOffline(); |
| 102 }, | 112 }, |
| 103 | 113 |
| 104 /** | 114 /** |
| 105 * Returns true if GAIA is at the begging of flow (i.e. the email page). | 115 * Returns true if GAIA is at the begging of flow (i.e. the email page). |
| 106 * @type {boolean} | 116 * @type {boolean} |
| 107 */ | 117 */ |
| 108 isAtTheBeginning: function() { | 118 isAtTheBeginning: function() { |
| 109 return !this.navigation_.backVisible && | 119 return !this.navigation_.backVisible && |
| 110 !this.isSAML() && | 120 !this.isSAML() && |
| 111 !this.classList.contains('whitelist-error') && | 121 !this.classList.contains('whitelist-error') && |
| 112 !this.authCompleted_; | 122 !this.authCompleted_; |
| 113 }, | 123 }, |
| 114 | 124 |
| 115 /** | 125 /** |
| 116 * Updates visibility of navigation buttons. | 126 * Updates visibility of navigation buttons. |
| 117 */ | 127 */ |
| 118 updateControlsState: function() { | 128 updateControlsState: function() { |
| 119 var isWhitelistError = this.classList.contains('whitelist-error'); | 129 var isWhitelistError = this.classList.contains('whitelist-error'); |
| 120 | 130 |
| 121 this.navigation_.backVisible = | 131 this.navigation_.backVisible = |
| 122 this.lastBackMessageValue_ && | 132 this.lastBackMessageValue_ && |
| 123 !isWhitelistError && | 133 !isWhitelistError && |
| 124 !this.authCompleted_ && | 134 !this.authCompleted_ && |
| 125 !this.loading && | 135 !this.loading && |
| 126 !this.isSAML(); | 136 !this.isSAML(); |
| 127 | 137 |
| 128 this.navigation_.refreshVisible = | 138 this.navigation_.refreshVisible = |
| 129 !this.closable && this.isAtTheBeginning(); | 139 !this.closable && this.isAtTheBeginning() && |
| 140 this.screenMode_ != ScreenMode.SAML_INTERSTITIAL; |
| 130 | 141 |
| 131 this.navigation_.closeVisible = | 142 this.navigation_.closeVisible = |
| 132 !this.navigation_.refreshVisible && | 143 !this.navigation_.refreshVisible && |
| 133 !isWhitelistError && | 144 !isWhitelistError && |
| 134 !this.authCompleted; | 145 !this.authCompleted && |
| 146 this.screenMode_ != ScreenMode.SAML_INTERSTITIAL; |
| 135 | 147 |
| 136 $('login-header-bar').updateUI_(); | 148 $('login-header-bar').updateUI_(); |
| 137 }, | 149 }, |
| 138 | 150 |
| 139 /** | 151 /** |
| 140 * SAML password confirmation attempt count. | 152 * SAML password confirmation attempt count. |
| 141 * @type {number} | 153 * @type {number} |
| 142 */ | 154 */ |
| 143 samlPasswordConfirmAttempt_: 0, | 155 samlPasswordConfirmAttempt_: 0, |
| 144 | 156 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 167 this.gaiaAuthHost_ = new cr.login.GaiaAuthHost($('signin-frame')); | 179 this.gaiaAuthHost_ = new cr.login.GaiaAuthHost($('signin-frame')); |
| 168 this.gaiaAuthHost_.addEventListener( | 180 this.gaiaAuthHost_.addEventListener( |
| 169 'ready', this.onAuthReady_.bind(this)); | 181 'ready', this.onAuthReady_.bind(this)); |
| 170 | 182 |
| 171 var that = this; | 183 var that = this; |
| 172 [this.gaiaAuthHost_, $('offline-gaia')].forEach(function(frame) { | 184 [this.gaiaAuthHost_, $('offline-gaia')].forEach(function(frame) { |
| 173 // Ignore events from currently inactive frame. | 185 // Ignore events from currently inactive frame. |
| 174 var frameFilter = function(callback) { | 186 var frameFilter = function(callback) { |
| 175 return function(e) { | 187 return function(e) { |
| 176 var isEventOffline = frame === $('offline-gaia'); | 188 var isEventOffline = frame === $('offline-gaia'); |
| 177 if (isEventOffline === that.isOffline) | 189 if (isEventOffline === that.isOffline()) |
| 178 callback.call(that, e); | 190 callback.call(that, e); |
| 179 }; | 191 }; |
| 180 }; | 192 }; |
| 181 | 193 |
| 182 frame.addEventListener('authCompleted', | 194 frame.addEventListener('authCompleted', |
| 183 frameFilter(that.onAuthCompletedMessage_)); | 195 frameFilter(that.onAuthCompletedMessage_)); |
| 184 frame.addEventListener('backButton', frameFilter(that.onBackButton_)); | 196 frame.addEventListener('backButton', frameFilter(that.onBackButton_)); |
| 185 frame.addEventListener('dialogShown', frameFilter(that.onDialogShown_)); | 197 frame.addEventListener('dialogShown', frameFilter(that.onDialogShown_)); |
| 186 frame.addEventListener('dialogHidden', | 198 frame.addEventListener('dialogHidden', |
| 187 frameFilter(that.onDialogHidden_)); | 199 frameFilter(that.onDialogHidden_)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 this.cancel(); | 233 this.cancel(); |
| 222 }.bind(this)); | 234 }.bind(this)); |
| 223 | 235 |
| 224 $('gaia-whitelist-error').addEventListener('buttonclick', function() { | 236 $('gaia-whitelist-error').addEventListener('buttonclick', function() { |
| 225 this.showWhitelistCheckFailedError(false); | 237 this.showWhitelistCheckFailedError(false); |
| 226 }.bind(this)); | 238 }.bind(this)); |
| 227 | 239 |
| 228 $('gaia-whitelist-error').addEventListener('linkclick', function() { | 240 $('gaia-whitelist-error').addEventListener('linkclick', function() { |
| 229 chrome.send('launchHelpApp', [HELP_CANT_ACCESS_ACCOUNT]); | 241 chrome.send('launchHelpApp', [HELP_CANT_ACCESS_ACCOUNT]); |
| 230 }); | 242 }); |
| 243 |
| 244 // Register handlers for the saml interstitial page events. |
| 245 $('saml-interstitial').addEventListener('samlPageNextClicked', |
| 246 function() { |
| 247 this.screenMode = ScreenMode.DEFAULT; |
| 248 this.loadGaiaAuthHost_(true /* doSamlRedirect */); |
| 249 }.bind(this)); |
| 250 $('saml-interstitial').addEventListener('samlPageChangeAccountClicked', |
| 251 function() { |
| 252 this.screenMode = ScreenMode.DEFAULT; |
| 253 this.loadGaiaAuthHost_(false /* doSamlRedirect */); |
| 254 }.bind(this)); |
| 231 }, | 255 }, |
| 232 | 256 |
| 233 /** | 257 /** |
| 258 * Loads the authenticator and updates the UI to reflect the loading state. |
| 259 * @param {boolean} doSamlRedirect If the authenticator should do |
| 260 * authentication by automatic redirection |
| 261 * to the SAML-based enrollment enterprise |
| 262 * domain IdP. |
| 263 */ |
| 264 loadGaiaAuthHost_: function(doSamlRedirect) { |
| 265 this.loading = true; |
| 266 this.startLoadingTimer_(); |
| 267 |
| 268 this.gaiaAuthParams_.doSamlRedirect = doSamlRedirect; |
| 269 this.gaiaAuthHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT, |
| 270 this.gaiaAuthParams_); |
| 271 }, |
| 272 |
| 273 /** |
| 234 * Header text of the screen. | 274 * Header text of the screen. |
| 235 * @type {string} | 275 * @type {string} |
| 236 */ | 276 */ |
| 237 get header() { | 277 get header() { |
| 238 return loadTimeData.getString('signinScreenTitle'); | 278 return loadTimeData.getString('signinScreenTitle'); |
| 239 }, | 279 }, |
| 240 | 280 |
| 241 /** | 281 /** |
| 242 * Returns true if offline version of Gaia is used. | 282 * Returns true if offline version of Gaia is used. |
| 243 * @type {boolean} | 283 * @type {boolean} |
| 244 */ | 284 */ |
| 245 get isOffline() { | 285 isOffline: function() { |
| 246 return this.isOffline_; | 286 return this.screenMode_ == ScreenMode.OFFLINE; |
| 247 }, | 287 }, |
| 248 | 288 |
| 249 /** | 289 /** |
| 250 * Sets whether offline version of Gaia is used. | 290 * Sets the current screen mode and updates the visible elements |
| 251 * @param {boolean} value Whether offline version of Gaia is used. | 291 * accordingly. |
| 292 * @param {integer} value The screen mode. |
| 252 */ | 293 */ |
| 253 set isOffline(value) { | 294 set screenMode(value) { |
| 254 this.isOffline_ = !!value; | 295 this.screenMode_ = value; |
| 255 $('signin-frame').hidden = this.isOffline_; | 296 switch (this.screenMode_) { |
| 256 $('offline-gaia').hidden = !this.isOffline_; | 297 case ScreenMode.DEFAULT: |
| 257 chrome.send('updateOfflineLogin', [value]); | 298 $('signin-frame').hidden = false; |
| 299 $('offline-gaia').hidden = true; |
| 300 $('saml-interstitial').hidden = true; |
| 301 break; |
| 302 case ScreenMode.OFFLINE: |
| 303 $('signin-frame').hidden = true; |
| 304 $('offline-gaia').hidden = false; |
| 305 $('saml-interstitial').hidden = true; |
| 306 break; |
| 307 case ScreenMode.SAML_INTERSTITIAL: |
| 308 $('signin-frame').hidden = true; |
| 309 $('offline-gaia').hidden = true; |
| 310 $('saml-interstitial').hidden = false; |
| 311 break; |
| 312 } |
| 313 |
| 314 chrome.send('updateOfflineLogin', [this.isOffline()]); |
| 315 this.updateControlsState(); |
| 258 }, | 316 }, |
| 259 | 317 |
| 260 /** | 318 /** |
| 261 * This enables or disables trying to go back to the online login page | 319 * This enables or disables trying to go back to the online login page |
| 262 * after the user is idle for a few minutes, assuming that we're currently | 320 * after the user is idle for a few minutes, assuming that we're currently |
| 263 * in the offline one. This is only applicable when the offline page is | 321 * in the offline one. This is only applicable when the offline page is |
| 264 * currently active. It is intended that when the device goes online, this | 322 * currently active. It is intended that when the device goes online, this |
| 265 * gets called with true; when it goes offline, this gets called with | 323 * gets called with true; when it goes offline, this gets called with |
| 266 * false. | 324 * false. |
| 267 */ | 325 */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 280 if (!self.updateActivityTime_) { | 338 if (!self.updateActivityTime_) { |
| 281 self.updateActivityTime_ = function() { | 339 self.updateActivityTime_ = function() { |
| 282 self.mostRecentUserActivity_ = Date.now(); | 340 self.mostRecentUserActivity_ = Date.now(); |
| 283 }; | 341 }; |
| 284 } | 342 } |
| 285 | 343 |
| 286 // Begin monitoring. | 344 // Begin monitoring. |
| 287 if (shouldMonitor) { | 345 if (shouldMonitor) { |
| 288 // If we're not using the offline login page or we're already | 346 // If we're not using the offline login page or we're already |
| 289 // monitoring, then we don't need to do anything. | 347 // monitoring, then we don't need to do anything. |
| 290 if (!self.isOffline || self.tryToGoToOnlineLoginPageCallbackId_ !== -1) | 348 if (!self.isOffline() || |
| 349 self.tryToGoToOnlineLoginPageCallbackId_ !== -1) { |
| 291 return; | 350 return; |
| 351 } |
| 292 | 352 |
| 293 self.mostRecentUserActivity_ = Date.now(); | 353 self.mostRecentUserActivity_ = Date.now(); |
| 294 ACTIVITY_EVENTS.forEach(function(event) { | 354 ACTIVITY_EVENTS.forEach(function(event) { |
| 295 document.addEventListener(event, self.updateActivityTime_); | 355 document.addEventListener(event, self.updateActivityTime_); |
| 296 }); | 356 }); |
| 297 | 357 |
| 298 self.tryToGoToOnlineLoginPageCallbackId_ = setInterval(function() { | 358 self.tryToGoToOnlineLoginPageCallbackId_ = setInterval(function() { |
| 299 // If we're not in the offline page or the signin page, then we want | 359 // If we're not in the offline page or the signin page, then we want |
| 300 // to terminate monitoring. | 360 // to terminate monitoring. |
| 301 if (!self.isOffline || | 361 if (!self.isOffline() || |
| 302 Oobe.getInstance().currentScreen.id != 'gaia-signin') { | 362 Oobe.getInstance().currentScreen.id != 'gaia-signin') { |
| 303 self.monitorOfflineIdle(false); | 363 self.monitorOfflineIdle(false); |
| 304 return; | 364 return; |
| 305 } | 365 } |
| 306 | 366 |
| 307 var idleDuration = Date.now() - self.mostRecentUserActivity_; | 367 var idleDuration = Date.now() - self.mostRecentUserActivity_; |
| 308 if (idleDuration > IDLE_TIME_UNTIL_EXIT_OFFLINE_IN_MILLISECONDS) { | 368 if (idleDuration > IDLE_TIME_UNTIL_EXIT_OFFLINE_IN_MILLISECONDS) { |
| 309 self.monitorOfflineIdle(false); | 369 self.monitorOfflineIdle(false); |
| 310 Oobe.resetSigninUI(true); | 370 Oobe.resetSigninUI(true); |
| 311 } | 371 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 326 } | 386 } |
| 327 }, | 387 }, |
| 328 | 388 |
| 329 /** | 389 /** |
| 330 * Shows/hides loading UI. | 390 * Shows/hides loading UI. |
| 331 * @param {boolean} show True to show loading UI. | 391 * @param {boolean} show True to show loading UI. |
| 332 * @private | 392 * @private |
| 333 */ | 393 */ |
| 334 showLoadingUI_: function(show) { | 394 showLoadingUI_: function(show) { |
| 335 $('gaia-loading').hidden = !show; | 395 $('gaia-loading').hidden = !show; |
| 396 |
| 397 // Only set hidden for offline-gaia or saml-interstitial and not set it on |
| 398 // the 'sign-frame' webview element. Setting it on webview not only hides |
| 399 // but also affects its loading events. |
| 400 if (this.screenMode_ != ScreenMode.DEFAULT) |
| 401 this.getSigninFrame_().hidden = show; |
| 402 this.getSigninFrame_().classList.toggle('show', !show); |
| 336 this.classList.toggle('loading', show); | 403 this.classList.toggle('loading', show); |
| 337 // Only set hidden for offline-gaia and not set it on the 'sign-frame' | |
| 338 // webview element. Setting it on webview not only hides but also affects | |
| 339 // its loading events. | |
| 340 if (this.isOffline) | |
| 341 this.getSigninFrame_().hidden = show; | |
| 342 $('signin-frame').classList.remove('show'); | |
| 343 this.updateControlsState(); | 404 this.updateControlsState(); |
| 344 }, | 405 }, |
| 345 | 406 |
| 346 /** | 407 /** |
| 347 * Handler for Gaia loading timeout. | 408 * Handler for Gaia loading timeout. |
| 348 * @private | 409 * @private |
| 349 */ | 410 */ |
| 350 onLoadingTimeOut_: function() { | 411 onLoadingTimeOut_: function() { |
| 351 if (this != Oobe.getInstance().currentScreen) | 412 if (this != Oobe.getInstance().currentScreen) |
| 352 return; | 413 return; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 480 |
| 420 this.showLoadingUI_(loading); | 481 this.showLoadingUI_(loading); |
| 421 }, | 482 }, |
| 422 | 483 |
| 423 /** | 484 /** |
| 424 * Event handler that is invoked just before the frame is shown. | 485 * Event handler that is invoked just before the frame is shown. |
| 425 * @param {string} data Screen init payload. Url of auth extension start | 486 * @param {string} data Screen init payload. Url of auth extension start |
| 426 * page. | 487 * page. |
| 427 */ | 488 */ |
| 428 onBeforeShow: function(data) { | 489 onBeforeShow: function(data) { |
| 490 this.screenMode = ScreenMode.DEFAULT; |
| 491 this.loading = true; |
| 429 chrome.send('loginUIStateChanged', ['gaia-signin', true]); | 492 chrome.send('loginUIStateChanged', ['gaia-signin', true]); |
| 430 $('progress-dots').hidden = true; | 493 $('progress-dots').hidden = true; |
| 431 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.GAIA_SIGNIN; | 494 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.GAIA_SIGNIN; |
| 432 | 495 |
| 433 // Ensure that GAIA signin (or loading UI) is actually visible. | 496 // Ensure that GAIA signin (or loading UI) is actually visible. |
| 434 window.requestAnimationFrame(function() { | 497 window.requestAnimationFrame(function() { |
| 435 chrome.send('loginVisible', ['gaia-loading']); | 498 chrome.send('loginVisible', ['gaia-loading']); |
| 436 }); | 499 }); |
| 437 | 500 |
| 438 this.classList.toggle('loading', this.loading); | |
| 439 | |
| 440 // Button header is always visible when sign in is presented. | 501 // Button header is always visible when sign in is presented. |
| 441 // Header is hidden once GAIA reports on successful sign in. | 502 // Header is hidden once GAIA reports on successful sign in. |
| 442 Oobe.getInstance().headerHidden = false; | 503 Oobe.getInstance().headerHidden = false; |
| 443 | 504 |
| 444 this.lastBackMessageValue_ = false; | 505 this.lastBackMessageValue_ = false; |
| 445 this.updateControlsState(); | 506 this.updateControlsState(); |
| 446 }, | 507 }, |
| 447 | 508 |
| 448 getSigninFrame_: function() { | 509 getSigninFrame_: function() { |
| 449 return this.isOffline ? $('offline-gaia') : $('signin-frame'); | 510 switch (this.screenMode_) { |
| 511 case ScreenMode.DEFAULT: |
| 512 return $('signin-frame'); |
| 513 case ScreenMode.OFFLINE: |
| 514 return $('offline-gaia'); |
| 515 case ScreenMode.SAML_INTERSTITIAL: |
| 516 return $('saml-interstitial'); |
| 517 } |
| 450 }, | 518 }, |
| 451 | 519 |
| 452 focusSigninFrame: function() { | 520 focusSigninFrame: function() { |
| 453 this.getSigninFrame_().focus(); | 521 this.getSigninFrame_().focus(); |
| 454 }, | 522 }, |
| 455 | 523 |
| 456 onAfterShow: function() { | 524 onAfterShow: function() { |
| 457 if (!this.loading) | 525 if (!this.loading) |
| 458 this.focusSigninFrame(); | 526 this.focusSigninFrame(); |
| 459 }, | 527 }, |
| 460 | 528 |
| 461 /** | 529 /** |
| 462 * Event handler that is invoked just before the screen is hidden. | 530 * Event handler that is invoked just before the screen is hidden. |
| 463 */ | 531 */ |
| 464 onBeforeHide: function() { | 532 onBeforeHide: function() { |
| 465 chrome.send('loginUIStateChanged', ['gaia-signin', false]); | 533 chrome.send('loginUIStateChanged', ['gaia-signin', false]); |
| 466 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN; | 534 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN; |
| 467 $('offline-gaia').switchToEmailCard(false /* animated */); | 535 $('offline-gaia').switchToEmailCard(false /* animated */); |
| 468 }, | 536 }, |
| 469 | 537 |
| 470 /** | 538 /** |
| 471 * Loads the authentication extension into the iframe. | 539 * Loads the authentication extension into the iframe. |
| 472 * @param {Object} data Extension parameters bag. | 540 * @param {Object} data Extension parameters bag. |
| 473 * @private | 541 * @private |
| 474 */ | 542 */ |
| 475 loadAuthExtension: function(data) { | 543 loadAuthExtension: function(data) { |
| 476 this.isOffline = data.useOffline; | 544 this.screenMode = data.screenMode; |
| 477 this.email = ''; | 545 this.email = ''; |
| 478 this.authCompleted_ = false; | 546 this.authCompleted_ = false; |
| 479 this.lastBackMessageValue_ = false; | 547 this.lastBackMessageValue_ = false; |
| 480 | 548 |
| 481 // Reset SAML | |
| 482 this.classList.toggle('full-width', false); | |
| 483 this.samlPasswordConfirmAttempt_ = 0; | |
| 484 | |
| 485 this.updateAuthExtension_(data); | 549 this.updateAuthExtension_(data); |
| 486 | 550 |
| 487 var params = {}; | 551 var params = {}; |
| 488 for (var i in cr.login.GaiaAuthHost.SUPPORTED_PARAMS) { | 552 for (var i in cr.login.GaiaAuthHost.SUPPORTED_PARAMS) { |
| 489 var name = cr.login.GaiaAuthHost.SUPPORTED_PARAMS[i]; | 553 var name = cr.login.GaiaAuthHost.SUPPORTED_PARAMS[i]; |
| 490 if (data[name]) | 554 if (data[name]) |
| 491 params[name] = data[name]; | 555 params[name] = data[name]; |
| 492 } | 556 } |
| 493 | 557 |
| 494 if (data.enterpriseInfoMessage) | |
| 495 params.enterpriseInfoMessage = data.enterpriseInfoMessage; | |
| 496 | |
| 497 params.isNewGaiaFlow = true; | 558 params.isNewGaiaFlow = true; |
| 559 params.doSamlRedirect = |
| 560 (this.screenMode_ == ScreenMode.SAML_INTERSTITIAL); |
| 498 | 561 |
| 499 // Screen size could have been changed because of 'full-width' classes. | 562 // Screen size could have been changed because of 'full-width' classes. |
| 500 if (Oobe.getInstance().currentScreen === this) | 563 if (Oobe.getInstance().currentScreen === this) |
| 501 Oobe.getInstance().updateScreenSize(this); | 564 Oobe.getInstance().updateScreenSize(this); |
| 502 | 565 |
| 503 if (data.forceReload || | 566 if (data.forceReload || |
| 504 JSON.stringify(this.gaiaAuthParams_) != JSON.stringify(params)) { | 567 JSON.stringify(this.gaiaAuthParams_) != JSON.stringify(params)) { |
| 505 this.gaiaAuthParams_ = params; | 568 this.gaiaAuthParams_ = params; |
| 506 this.loading = true; | |
| 507 this.startLoadingTimer_(); | |
| 508 | 569 |
| 509 if (this.isOffline) { | 570 switch (this.screenMode_) { |
| 510 this.loadOffline(params); | 571 case ScreenMode.DEFAULT: |
| 511 } else { | 572 this.loadGaiaAuthHost_(false /* doSamlRedirect */); |
| 512 this.gaiaAuthHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT, | 573 break; |
| 513 params); | 574 |
| 575 case ScreenMode.OFFLINE: |
| 576 this.loadOffline(params); |
| 577 break; |
| 578 |
| 579 case ScreenMode.SAML_INTERSTITIAL: |
| 580 $('saml-interstitial').domain = data.enterpriseDomain; |
| 581 if (this.loading) |
| 582 this.loading = false; |
| 583 break; |
| 514 } | 584 } |
| 515 } | 585 } |
| 516 this.updateControlsState(); | 586 this.updateControlsState(); |
| 517 }, | 587 }, |
| 518 | 588 |
| 519 /** | 589 /** |
| 520 * Updates the authentication extension with new parameters, if needed. | 590 * Updates the authentication extension with new parameters, if needed. |
| 521 * @param {Object} data New extension parameters bag. | 591 * @param {Object} data New extension parameters bag. |
| 522 * @private | 592 * @private |
| 523 */ | 593 */ |
| 524 updateAuthExtension_: function(data) { | 594 updateAuthExtension_: function(data) { |
| 525 $('login-header-bar').showCreateSupervisedButton = | 595 $('login-header-bar').showCreateSupervisedButton = |
| 526 data.supervisedUsersCanCreate; | 596 data.supervisedUsersCanCreate; |
| 527 $('login-header-bar').showGuestButton = data.guestSignin; | 597 $('login-header-bar').showGuestButton = data.guestSignin; |
| 528 | 598 |
| 529 this.updateControlsState(); | 599 this.updateControlsState(); |
| 530 | 600 |
| 601 // Reset SAML |
| 531 this.classList.toggle('full-width', false); | 602 this.classList.toggle('full-width', false); |
| 603 this.samlPasswordConfirmAttempt_ = 0; |
| 532 if (Oobe.getInstance().currentScreen === this) | 604 if (Oobe.getInstance().currentScreen === this) |
| 533 Oobe.getInstance().updateScreenSize(this); | 605 Oobe.getInstance().updateScreenSize(this); |
| 534 }, | 606 }, |
| 535 | 607 |
| 536 /** | 608 /** |
| 537 * Whether the current auth flow is SAML. | 609 * Whether the current auth flow is SAML. |
| 538 */ | 610 */ |
| 539 isSAML: function() { | 611 isSAML: function() { |
| 540 return this.gaiaAuthHost_.authFlow == | 612 return this.gaiaAuthHost_.authFlow == |
| 541 cr.login.GaiaAuthHost.AuthFlow.SAML; | 613 cr.login.GaiaAuthHost.AuthFlow.SAML; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 564 } | 636 } |
| 565 | 637 |
| 566 this.updateControlsState(); | 638 this.updateControlsState(); |
| 567 }, | 639 }, |
| 568 | 640 |
| 569 /** | 641 /** |
| 570 * Invoked when the auth host emits 'ready' event. | 642 * Invoked when the auth host emits 'ready' event. |
| 571 * @private | 643 * @private |
| 572 */ | 644 */ |
| 573 onAuthReady_: function() { | 645 onAuthReady_: function() { |
| 574 showViewProcessed_ = false; | 646 this.showViewProcessed_ = false; |
| 575 this.startLoadAnimationGuardTimer_(); | 647 this.startLoadAnimationGuardTimer_(); |
| 576 this.clearLoadingTimer_(); | 648 this.clearLoadingTimer_(); |
| 577 this.loading = false; | 649 this.loading = false; |
| 578 | 650 |
| 579 // Warm up the user images screen. | 651 // Warm up the user images screen. |
| 580 Oobe.getInstance().preloadScreen({id: SCREEN_USER_IMAGE_PICKER}); | 652 Oobe.getInstance().preloadScreen({id: SCREEN_USER_IMAGE_PICKER}); |
| 581 }, | 653 }, |
| 582 | 654 |
| 583 /** | 655 /** |
| 584 * Invoked when the auth host emits 'dialogShown' event. | 656 * Invoked when the auth host emits 'dialogShown' event. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 605 this.lastBackMessageValue_ = !!e.detail; | 677 this.lastBackMessageValue_ = !!e.detail; |
| 606 this.updateControlsState(); | 678 this.updateControlsState(); |
| 607 }, | 679 }, |
| 608 | 680 |
| 609 /** | 681 /** |
| 610 * Invoked when the auth host emits 'showView' event or when corresponding | 682 * Invoked when the auth host emits 'showView' event or when corresponding |
| 611 * guard time fires. | 683 * guard time fires. |
| 612 * @private | 684 * @private |
| 613 */ | 685 */ |
| 614 onShowView_: function(e) { | 686 onShowView_: function(e) { |
| 615 if (showViewProcessed_) | 687 if (this.showViewProcessed_) |
| 616 return; | 688 return; |
| 617 | 689 |
| 618 showViewProcessed_ = true; | 690 this.showViewProcessed_ = true; |
| 619 this.clearLoadAnimationGuardTimer_(); | 691 this.clearLoadAnimationGuardTimer_(); |
| 620 $('signin-frame').classList.add('show'); | 692 this.getSigninFrame_().classList.toggle('show', true); |
| 621 this.onLoginUIVisible_(); | 693 this.onLoginUIVisible_(); |
| 622 }, | 694 }, |
| 623 | 695 |
| 624 /** | 696 /** |
| 625 * Called when UI is shown. | 697 * Called when UI is shown. |
| 626 * @private | 698 * @private |
| 627 */ | 699 */ |
| 628 onLoginUIVisible_: function() { | 700 onLoginUIVisible_: function() { |
| 629 // Show deferred error bubble. | 701 // Show deferred error bubble. |
| 630 if (this.errorBubble_) { | 702 if (this.errorBubble_) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 | 873 |
| 802 /** | 874 /** |
| 803 * Clears input fields and switches to input mode. | 875 * Clears input fields and switches to input mode. |
| 804 * @param {boolean} takeFocus True to take focus. | 876 * @param {boolean} takeFocus True to take focus. |
| 805 * @param {boolean} forceOnline Whether online sign-in should be forced. | 877 * @param {boolean} forceOnline Whether online sign-in should be forced. |
| 806 * If |forceOnline| is false previously used sign-in type will be used. | 878 * If |forceOnline| is false previously used sign-in type will be used. |
| 807 */ | 879 */ |
| 808 reset: function(takeFocus, forceOnline) { | 880 reset: function(takeFocus, forceOnline) { |
| 809 // Reload and show the sign-in UI if needed. | 881 // Reload and show the sign-in UI if needed. |
| 810 if (takeFocus) { | 882 if (takeFocus) { |
| 811 if (!forceOnline && this.isOffline) { | 883 if (!forceOnline && this.isOffline()) { |
| 812 // Show 'Cancel' button to allow user to return to the main screen | 884 // Show 'Cancel' button to allow user to return to the main screen |
| 813 // (e.g. this makes sense when connection is back). | 885 // (e.g. this makes sense when connection is back). |
| 814 Oobe.getInstance().headerHidden = false; | 886 Oobe.getInstance().headerHidden = false; |
| 815 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.GAIA_SIGNIN; | 887 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.GAIA_SIGNIN; |
| 816 // Do nothing, since offline version is reloaded after an error comes. | 888 // Do nothing, since offline version is reloaded after an error comes. |
| 817 } else { | 889 } else { |
| 818 Oobe.showSigninUI(); | 890 Oobe.showSigninUI(); |
| 819 } | 891 } |
| 820 } | 892 } |
| 821 }, | 893 }, |
| 822 | 894 |
| 823 /** | 895 /** |
| 824 * Reloads extension frame. | 896 * Reloads extension frame. |
| 825 */ | 897 */ |
| 826 doReload: function() { | 898 doReload: function() { |
| 827 if (this.isOffline) | 899 if (this.isOffline()) |
| 828 return; | 900 return; |
| 829 this.gaiaAuthHost_.reload(); | 901 this.gaiaAuthHost_.reload(); |
| 830 this.loading = true; | 902 this.loading = true; |
| 831 this.startLoadingTimer_(); | 903 this.startLoadingTimer_(); |
| 832 this.lastBackMessageValue_ = false; | 904 this.lastBackMessageValue_ = false; |
| 833 this.authCompleted_ = false; | 905 this.authCompleted_ = false; |
| 834 this.updateControlsState(); | 906 this.updateControlsState(); |
| 835 }, | 907 }, |
| 836 | 908 |
| 837 /** | 909 /** |
| 838 * Shows sign-in error bubble. | 910 * Shows sign-in error bubble. |
| 839 * @param {number} loginAttempts Number of login attemps tried. | 911 * @param {number} loginAttempts Number of login attemps tried. |
| 840 * @param {HTMLElement} content Content to show in bubble. | 912 * @param {HTMLElement} content Content to show in bubble. |
| 841 */ | 913 */ |
| 842 showErrorBubble: function(loginAttempts, error) { | 914 showErrorBubble: function(loginAttempts, error) { |
| 843 if (this.isOffline) { | 915 if (this.isOffline()) { |
| 844 $('add-user-button').hidden = true; | 916 $('add-user-button').hidden = true; |
| 845 // Reload offline version of the sign-in extension, which will show | 917 // Reload offline version of the sign-in extension, which will show |
| 846 // error itself. | 918 // error itself. |
| 847 chrome.send('offlineLogin', [this.email]); | 919 chrome.send('offlineLogin', [this.email]); |
| 848 } else if (!this.loading) { | 920 } else if (!this.loading) { |
| 849 // TODO(dzhioev): investigate if this branch ever get hit. | 921 // TODO(dzhioev): investigate if this branch ever get hit. |
| 850 $('bubble').showContentForElement($('gaia-signin-form-container'), | 922 $('bubble').showContentForElement($('gaia-signin-form-container'), |
| 851 cr.ui.Bubble.Attachment.LEFT, | 923 cr.ui.Bubble.Attachment.LEFT, |
| 852 error); | 924 error); |
| 853 } else { | 925 } else { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 onIdentifierEntered: function(data) { | 959 onIdentifierEntered: function(data) { |
| 888 chrome.send('identifierEntered', [data.accountIdentifier]); | 960 chrome.send('identifierEntered', [data.accountIdentifier]); |
| 889 }, | 961 }, |
| 890 | 962 |
| 891 /** | 963 /** |
| 892 * Sets enterprise info strings for offline gaia. | 964 * Sets enterprise info strings for offline gaia. |
| 893 * Also sets callback and sends message whether we already have email and | 965 * Also sets callback and sends message whether we already have email and |
| 894 * should switch to the password screen with error. | 966 * should switch to the password screen with error. |
| 895 */ | 967 */ |
| 896 loadOffline: function(params) { | 968 loadOffline: function(params) { |
| 969 this.loading = true; |
| 970 this.startLoadingTimer_(); |
| 897 var offlineLogin = $('offline-gaia'); | 971 var offlineLogin = $('offline-gaia'); |
| 898 if ('enterpriseInfoMessage' in params) | 972 offlineLogin.showEnterpriseMessage = !!('enterpriseDomain' in params); |
| 899 offlineLogin.enterpriseInfo = params['enterpriseInfoMessage']; | |
| 900 if ('emailDomain' in params) | 973 if ('emailDomain' in params) |
| 901 offlineLogin.emailDomain = '@' + params['emailDomain']; | 974 offlineLogin.emailDomain = '@' + params['emailDomain']; |
| 902 offlineLogin.setEmail(params.email); | 975 offlineLogin.setEmail(params.email); |
| 903 this.onAuthReady_(); | 976 this.onAuthReady_(); |
| 904 }, | 977 }, |
| 905 | 978 |
| 906 /** | 979 /** |
| 907 * Show/Hide error when user is not in whitelist. When UI is hidden | 980 * Show/Hide error when user is not in whitelist. When UI is hidden |
| 908 * GAIA is reloaded. | 981 * GAIA is reloaded. |
| 909 * @param {boolean} show Show/hide error UI. | 982 * @param {boolean} show Show/hide error UI. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 920 this.classList.toggle('whitelist-error', show); | 993 this.classList.toggle('whitelist-error', show); |
| 921 this.loading = !show; | 994 this.loading = !show; |
| 922 | 995 |
| 923 if (!show) | 996 if (!show) |
| 924 Oobe.showSigninUI(); | 997 Oobe.showSigninUI(); |
| 925 | 998 |
| 926 this.updateControlsState(); | 999 this.updateControlsState(); |
| 927 } | 1000 } |
| 928 }; | 1001 }; |
| 929 }); | 1002 }); |
| OLD | NEW |