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
3 // found in the LICENSE file.
6 * @fileoverview Display manager for WebUI OOBE and login.
9 // TODO(xiyuan): Find a better to share those constants.
10 /** @const */ var SCREEN_OOBE_NETWORK = 'connect';
11 /** @const */ var SCREEN_OOBE_HID_DETECTION = 'hid-detection';
12 /** @const */ var SCREEN_OOBE_EULA = 'eula';
13 /** @const */ var SCREEN_OOBE_UPDATE = 'update';
14 /** @const */ var SCREEN_OOBE_RESET = 'reset';
15 /** @const */ var SCREEN_OOBE_ENROLLMENT = 'oauth-enrollment';
16 /** @const */ var SCREEN_OOBE_KIOSK_ENABLE = 'kiosk-enable';
17 /** @const */ var SCREEN_OOBE_AUTO_ENROLLMENT_CHECK = 'auto-enrollment-check';
18 /** @const */ var SCREEN_GAIA_SIGNIN = 'gaia-signin';
19 /** @const */ var SCREEN_ACCOUNT_PICKER = 'account-picker';
20 /** @const */ var SCREEN_USER_IMAGE_PICKER = 'user-image';
21 /** @const */ var SCREEN_ERROR_MESSAGE = 'error-message';
22 /** @const */ var SCREEN_TPM_ERROR = 'tpm-error-message';
23 /** @const */ var SCREEN_PASSWORD_CHANGED = 'password-changed';
24 /** @const */ var SCREEN_CREATE_SUPERVISED_USER_FLOW =
25 'supervised-user-creation';
26 /** @const */ var SCREEN_APP_LAUNCH_SPLASH = 'app-launch-splash';
27 /** @const */ var SCREEN_CONFIRM_PASSWORD = 'confirm-password';
28 /** @const */ var SCREEN_FATAL_ERROR = 'fatal-error';
29 /** @const */ var SCREEN_KIOSK_ENABLE = 'kiosk-enable';
30 /** @const */ var SCREEN_TERMS_OF_SERVICE = 'terms-of-service';
31 /** @const */ var SCREEN_WRONG_HWID = 'wrong-hwid';
33 /* Accelerator identifiers. Must be kept in sync with webui_login_view.cc. */
34 /** @const */ var ACCELERATOR_CANCEL = 'cancel';
35 /** @const */ var ACCELERATOR_ENROLLMENT = 'enrollment';
36 /** @const */ var ACCELERATOR_KIOSK_ENABLE = 'kiosk_enable';
37 /** @const */ var ACCELERATOR_VERSION = 'version';
38 /** @const */ var ACCELERATOR_RESET = 'reset';
39 /** @const */ var ACCELERATOR_FOCUS_PREV = 'focus_prev';
40 /** @const */ var ACCELERATOR_FOCUS_NEXT = 'focus_next';
41 /** @const */ var ACCELERATOR_DEVICE_REQUISITION = 'device_requisition';
42 /** @const */ var ACCELERATOR_DEVICE_REQUISITION_REMORA =
43 'device_requisition_remora';
44 /** @const */ var ACCELERATOR_DEVICE_REQUISITION_SHARK =
45 'device_requisition_shark';
46 /** @const */ var ACCELERATOR_APP_LAUNCH_BAILOUT = 'app_launch_bailout';
47 /** @const */ var ACCELERATOR_APP_LAUNCH_NETWORK_CONFIG =
48 'app_launch_network_config';
50 /* Signin UI state constants. Used to control header bar UI. */
51 /** @const */ var SIGNIN_UI_STATE = {
55 WRONG_HWID_WARNING: 3,
56 SUPERVISED_USER_CREATION_FLOW: 4,
57 SAML_PASSWORD_CONFIRM: 5,
58 CONSUMER_MANAGEMENT_ENROLLMENT: 6,
61 /* Possible UI states of the error screen. */
62 /** @const */ var ERROR_SCREEN_UI_STATE = {
63 UNKNOWN: 'ui-state-unknown',
64 UPDATE: 'ui-state-update',
65 SIGNIN: 'ui-state-signin',
66 SUPERVISED_USER_CREATION_FLOW: 'ui-state-supervised',
67 KIOSK_MODE: 'ui-state-kiosk-mode',
68 LOCAL_STATE_ERROR: 'ui-state-local-state-error',
69 AUTO_ENROLLMENT_ERROR: 'ui-state-auto-enrollment-error',
70 ROLLBACK_ERROR: 'ui-state-rollback-error'
73 /* Possible types of UI. */
74 /** @const */ var DISPLAY_TYPE = {
79 USER_ADDING: 'user-adding',
80 APP_LAUNCH_SPLASH: 'app-launch-splash',
81 DESKTOP_USER_MANAGER: 'login-add-user'
84 cr.define('cr.ui.login', function() {
85 var Bubble = cr.ui.Bubble;
88 * Maximum time in milliseconds to wait for step transition to finish.
89 * The value is used as the duration for ensureTransitionEndEvent below.
90 * It needs to be inline with the step screen transition duration time
91 * defined in css file. The current value in css is 200ms. To avoid emulated
92 * webkitTransitionEnd fired before real one, 250ms is used.
95 var MAX_SCREEN_TRANSITION_DURATION = 250;
98 * Groups of screens (screen IDs) that should have the same dimensions.
99 * @type Array.<Array.<string>>
102 var SCREEN_GROUPS = [[SCREEN_OOBE_NETWORK,
105 SCREEN_OOBE_AUTO_ENROLLMENT_CHECK]
108 * Group of screens (screen IDs) where factory-reset screen invocation is
110 * @type Array.<string>
113 var RESET_AVAILABLE_SCREEN_GROUP = [
117 SCREEN_OOBE_ENROLLMENT,
118 SCREEN_OOBE_AUTO_ENROLLMENT_CHECK,
120 SCREEN_ACCOUNT_PICKER,
122 SCREEN_ERROR_MESSAGE,
123 SCREEN_USER_IMAGE_PICKER,
125 SCREEN_PASSWORD_CHANGED,
126 SCREEN_TERMS_OF_SERVICE,
128 SCREEN_CONFIRM_PASSWORD,
133 * Group of screens (screen IDs) that are not participating in
134 * left-current-right animation.
135 * @type Array.<string>
138 var NOT_ANIMATED_SCREEN_GROUP = [
144 * OOBE screens group index.
146 var SCREEN_GROUP_OOBE = 0;
149 * Constructor a display manager that manages initialization of screens,
150 * transitions, error messages display.
154 function DisplayManager() {
157 DisplayManager.prototype = {
159 * Registered screens.
164 * Current OOBE step, index in the screens array.
170 * Whether version label can be toggled by ACCELERATOR_VERSION.
173 allowToggleVersion_: false,
176 * Whether keyboard navigation flow is enforced.
179 forceKeyboardFlow_: false,
182 * Whether virtual keyboard is shown.
185 virtualKeyboardShown_: false,
188 * Virtual keyboard width.
191 virtualKeyboardWidth_: 0,
194 * Virtual keyboard height.
197 virtualKeyboardHeight_: 0,
203 displayType_: DISPLAY_TYPE.UNKNOWN,
206 * Error message (bubble) was shown. This is checked in tests.
208 errorMessageWasShownForTesting_: false,
211 return this.displayType_;
214 set displayType(displayType) {
215 this.displayType_ = displayType;
216 document.documentElement.setAttribute('screen', displayType);
220 return loadTimeData.getString('newKioskUI') == 'on';
224 * Returns dimensions of screen exluding header bar.
227 get clientAreaSize() {
228 var container = $('outer-container');
229 return {width: container.offsetWidth, height: container.offsetHeight};
233 * Gets current screen element.
234 * @type {HTMLElement}
236 get currentScreen() {
237 return $(this.screens_[this.currentStep_]);
241 * Hides/shows header (Shutdown/Add User/Cancel buttons).
242 * @param {boolean} hidden Whether header is hidden.
245 return $('login-header-bar').hidden;
248 set headerHidden(hidden) {
249 $('login-header-bar').hidden = hidden;
253 * Virtual keyboard state (hidden/shown).
254 * @param {boolean} hidden Whether keyboard is shown.
256 get virtualKeyboardShown() {
257 return this.virtualKeyboardShown_;
260 set virtualKeyboardShown(shown) {
261 this.virtualKeyboardShown_ = shown;
265 * Sets the current size of the virtual keyboard.
266 * @param {number} width keyboard width
267 * @param {number} height keyboard height
269 setVirtualKeyboardSize: function(width, height) {
270 this.virtualKeyboardWidth_ = width;
271 this.virtualKeyboardHeight_ = height;
275 * Sets the current size of the client area (display size).
276 * @param {number} width client area width
277 * @param {number} height client area height
279 setClientAreaSize: function(width, height) {
280 var clientArea = $('outer-container');
281 var bottom = parseInt(window.getComputedStyle(clientArea).bottom);
282 clientArea.style.minHeight = cr.ui.toCssPx(height - bottom);
286 * Toggles background of main body between transparency and solid.
287 * @param {boolean} solid Whether to show a solid background.
289 set solidBackground(solid) {
291 document.body.classList.add('solid');
293 document.body.classList.remove('solid');
297 * Forces keyboard based OOBE navigation.
298 * @param {boolean} value True if keyboard navigation flow is forced.
300 set forceKeyboardFlow(value) {
301 this.forceKeyboardFlow_ = value;
303 keyboard.initializeKeyboardFlow();
304 cr.ui.DropDown.enableKeyboardFlow();
305 for (var i = 0; i < this.screens_.length; ++i) {
306 var screen = $(this.screens_[i]);
307 if (screen.enableKeyboardFlow)
308 screen.enableKeyboardFlow();
314 * Shows/hides version labels.
315 * @param {boolean} show Whether labels should be visible by default. If
316 * false, visibility can be toggled by ACCELERATOR_VERSION.
318 showVersion: function(show) {
319 $('version-labels').hidden = !show;
320 this.allowToggleVersion_ = !show;
324 * Handle accelerators.
325 * @param {string} name Accelerator name.
327 handleAccelerator: function(name) {
328 var currentStepId = this.screens_[this.currentStep_];
329 if (name == ACCELERATOR_CANCEL) {
330 if (this.currentScreen.cancel) {
331 this.currentScreen.cancel();
333 } else if (name == ACCELERATOR_ENROLLMENT) {
334 if (currentStepId == SCREEN_GAIA_SIGNIN ||
335 currentStepId == SCREEN_ACCOUNT_PICKER) {
336 chrome.send('toggleEnrollmentScreen');
337 } else if (currentStepId == SCREEN_OOBE_NETWORK ||
338 currentStepId == SCREEN_OOBE_EULA) {
339 // In this case update check will be skipped and OOBE will
340 // proceed straight to enrollment screen when EULA is accepted.
341 chrome.send('skipUpdateEnrollAfterEula');
342 } else if (currentStepId == SCREEN_OOBE_ENROLLMENT) {
343 // This accelerator is also used to manually cancel auto-enrollment.
344 if (this.currentScreen.cancelAutoEnrollment)
345 this.currentScreen.cancelAutoEnrollment();
347 } else if (name == ACCELERATOR_KIOSK_ENABLE) {
348 if (currentStepId == SCREEN_GAIA_SIGNIN ||
349 currentStepId == SCREEN_ACCOUNT_PICKER) {
350 chrome.send('toggleKioskEnableScreen');
352 } else if (name == ACCELERATOR_VERSION) {
353 if (this.allowToggleVersion_)
354 $('version-labels').hidden = !$('version-labels').hidden;
355 } else if (name == ACCELERATOR_RESET) {
356 if (RESET_AVAILABLE_SCREEN_GROUP.indexOf(currentStepId) != -1)
357 chrome.send('toggleResetScreen');
358 } else if (name == ACCELERATOR_DEVICE_REQUISITION) {
360 this.showDeviceRequisitionPrompt_();
361 } else if (name == ACCELERATOR_DEVICE_REQUISITION_REMORA) {
363 this.showDeviceRequisitionRemoraPrompt_(
364 'deviceRequisitionRemoraPromptText', 'remora');
365 } else if (name == ACCELERATOR_DEVICE_REQUISITION_SHARK) {
367 this.showDeviceRequisitionRemoraPrompt_(
368 'deviceRequisitionSharkPromptText', 'shark');
369 } else if (name == ACCELERATOR_APP_LAUNCH_BAILOUT) {
370 if (currentStepId == SCREEN_APP_LAUNCH_SPLASH)
371 chrome.send('cancelAppLaunch');
372 } else if (name == ACCELERATOR_APP_LAUNCH_NETWORK_CONFIG) {
373 if (currentStepId == SCREEN_APP_LAUNCH_SPLASH)
374 chrome.send('networkConfigRequest');
377 if (!this.forceKeyboardFlow_)
380 // Handle special accelerators for keyboard enhanced navigation flow.
381 if (name == ACCELERATOR_FOCUS_PREV)
382 keyboard.raiseKeyFocusPrevious(document.activeElement);
383 else if (name == ACCELERATOR_FOCUS_NEXT)
384 keyboard.raiseKeyFocusNext(document.activeElement);
388 * Appends buttons to the button strip.
389 * @param {Array.<HTMLElement>} buttons Array with the buttons to append.
390 * @param {string} screenId Id of the screen that buttons belong to.
392 appendButtons_: function(buttons, screenId) {
394 var buttonStrip = $(screenId + '-controls');
396 for (var i = 0; i < buttons.length; ++i)
397 buttonStrip.appendChild(buttons[i]);
403 * Disables or enables control buttons on the specified screen.
404 * @param {HTMLElement} screen Screen which controls should be affected.
405 * @param {boolean} disabled Whether to disable controls.
407 disableButtons_: function(screen, disabled) {
408 var buttons = document.querySelectorAll(
409 '#' + screen.id + '-controls button:not(.preserve-disabled-state)');
410 for (var i = 0; i < buttons.length; ++i) {
411 buttons[i].disabled = disabled;
415 screenIsAnimated_: function(screenId) {
416 return NOT_ANIMATED_SCREEN_GROUP.indexOf(screenId) != -1;
420 * Updates a step's css classes to reflect left, current, or right position.
421 * @param {number} stepIndex step index.
422 * @param {string} state one of 'left', 'current', 'right'.
424 updateStep_: function(stepIndex, state) {
425 var stepId = this.screens_[stepIndex];
426 var step = $(stepId);
427 var header = $('header-' + stepId);
428 var states = ['left', 'right', 'current'];
429 for (var i = 0; i < states.length; ++i) {
430 if (states[i] != state) {
431 step.classList.remove(states[i]);
432 header.classList.remove(states[i]);
436 step.classList.add(state);
437 header.classList.add(state);
441 * Switches to the next OOBE step.
442 * @param {number} nextStepIndex Index of the next step.
444 toggleStep_: function(nextStepIndex, screenData) {
445 var currentStepId = this.screens_[this.currentStep_];
446 var nextStepId = this.screens_[nextStepIndex];
447 var oldStep = $(currentStepId);
448 var newStep = $(nextStepId);
449 var newHeader = $('header-' + nextStepId);
451 // Disable controls before starting animation.
452 this.disableButtons_(oldStep, true);
454 if (oldStep.onBeforeHide)
455 oldStep.onBeforeHide();
457 $('oobe').className = nextStepId;
459 // Need to do this before calling newStep.onBeforeShow() so that new step
460 // is back in DOM tree and has correct offsetHeight / offsetWidth.
461 newStep.hidden = false;
463 if (newStep.onBeforeShow)
464 newStep.onBeforeShow(screenData);
466 newStep.classList.remove('hidden');
468 if (this.isOobeUI() &&
469 this.screenIsAnimated_(nextStepId) &&
470 this.screenIsAnimated_(currentStepId)) {
471 // Start gliding animation for OOBE steps.
472 if (nextStepIndex > this.currentStep_) {
473 for (var i = this.currentStep_; i < nextStepIndex; ++i)
474 this.updateStep_(i, 'left');
475 this.updateStep_(nextStepIndex, 'current');
476 } else if (nextStepIndex < this.currentStep_) {
477 for (var i = this.currentStep_; i > nextStepIndex; --i)
478 this.updateStep_(i, 'right');
479 this.updateStep_(nextStepIndex, 'current');
482 // Start fading animation for login display or reset screen.
483 oldStep.classList.add('faded');
484 newStep.classList.remove('faded');
485 if (!this.screenIsAnimated_(nextStepId)) {
486 newStep.classList.remove('left');
487 newStep.classList.remove('right');
491 this.disableButtons_(newStep, false);
493 // Adjust inner container height based on new step's height.
494 this.updateScreenSize(newStep);
496 if (newStep.onAfterShow)
497 newStep.onAfterShow(screenData);
499 // Workaround for gaia and network screens.
500 // Due to other origin iframe and long ChromeVox focusing correspondingly
501 // passive aria-label title is not pronounced.
502 // Gaia hack can be removed on fixed crbug.com/316726.
503 if (nextStepId == SCREEN_GAIA_SIGNIN) {
504 newStep.setAttribute(
506 loadTimeData.getString('signinScreenTitle'));
507 } else if (nextStepId == SCREEN_OOBE_NETWORK) {
508 newStep.setAttribute(
510 loadTimeData.getString('networkScreenAccessibleTitle'));
513 // Default control to be focused (if specified).
514 var defaultControl = newStep.defaultControl;
516 var outerContainer = $('outer-container');
517 var innerContainer = $('inner-container');
518 var isOOBE = this.isOobeUI();
519 if (this.currentStep_ != nextStepIndex &&
520 !oldStep.classList.contains('hidden')) {
521 if (oldStep.classList.contains('animated')) {
522 innerContainer.classList.add('animation');
523 oldStep.addEventListener('webkitTransitionEnd', function f(e) {
524 oldStep.removeEventListener('webkitTransitionEnd', f);
525 if (oldStep.classList.contains('faded') ||
526 oldStep.classList.contains('left') ||
527 oldStep.classList.contains('right')) {
528 innerContainer.classList.remove('animation');
529 oldStep.classList.add('hidden');
531 oldStep.hidden = true;
533 // Refresh defaultControl. It could have changed.
534 var defaultControl = newStep.defaultControl;
536 defaultControl.focus();
538 ensureTransitionEndEvent(oldStep, MAX_SCREEN_TRANSITION_DURATION);
540 oldStep.classList.add('hidden');
541 oldStep.hidden = true;
543 defaultControl.focus();
546 // First screen on OOBE launch.
547 if (this.isOobeUI() && innerContainer.classList.contains('down')) {
548 innerContainer.classList.remove('down');
549 innerContainer.addEventListener(
550 'webkitTransitionEnd', function f(e) {
551 innerContainer.removeEventListener('webkitTransitionEnd', f);
552 outerContainer.classList.remove('down');
553 $('progress-dots').classList.remove('down');
554 chrome.send('loginVisible', ['oobe']);
555 // Refresh defaultControl. It could have changed.
556 var defaultControl = newStep.defaultControl;
558 defaultControl.focus();
560 ensureTransitionEndEvent(innerContainer,
561 MAX_SCREEN_TRANSITION_DURATION);
564 defaultControl.focus();
565 chrome.send('loginVisible', ['oobe']);
568 this.currentStep_ = nextStepIndex;
570 $('step-logo').hidden = newStep.classList.contains('no-logo');
572 chrome.send('updateCurrentScreen', [this.currentScreen.id]);
576 * Make sure that screen is initialized and decorated.
577 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: {}}.
579 preloadScreen: function(screen) {
580 var screenEl = $(screen.id);
581 if (screenEl.deferredDecorate !== undefined) {
582 screenEl.deferredDecorate();
583 delete screenEl.deferredDecorate;
588 * Show screen of given screen id.
589 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: {}}.
591 showScreen: function(screen) {
592 var screenId = screen.id;
594 // Make sure the screen is decorated.
595 this.preloadScreen(screen);
597 if (screen.data !== undefined && screen.data.disableAddUser)
598 DisplayManager.updateAddUserButtonStatus(true);
601 // Show sign-in screen instead of account picker if pod row is empty.
602 if (screenId == SCREEN_ACCOUNT_PICKER && $('pod-row').pods.length == 0) {
603 // Manually hide 'add-user' header bar, because of the case when
604 // 'Cancel' button is used on the offline login page.
605 $('add-user-header-bar-item').hidden = true;
606 Oobe.showSigninUI(true);
610 var data = screen.data;
611 var index = this.getScreenIndex_(screenId);
613 this.toggleStep_(index, data);
617 * Gets index of given screen id in screens_.
618 * @param {string} screenId Id of the screen to look up.
621 getScreenIndex_: function(screenId) {
622 for (var i = 0; i < this.screens_.length; ++i) {
623 if (this.screens_[i] == screenId)
630 * Register an oobe screen.
631 * @param {Element} el Decorated screen element.
633 registerScreen: function(el) {
634 var screenId = el.id;
635 this.screens_.push(screenId);
637 var header = document.createElement('span');
638 header.id = 'header-' + screenId;
639 header.textContent = el.header ? el.header : '';
640 header.className = 'header-section';
641 $('header-sections').appendChild(header);
643 var dot = document.createElement('div');
644 dot.id = screenId + '-dot';
645 dot.className = 'progdot';
646 var progressDots = $('progress-dots');
648 progressDots.appendChild(dot);
650 this.appendButtons_(el.buttons, screenId);
654 * Updates inner container size based on the size of the current screen and
655 * other screens in the same group.
656 * Should be executed on screen change / screen size change.
657 * @param {!HTMLElement} screen Screen that is being shown.
659 updateScreenSize: function(screen) {
660 // Have to reset any previously predefined screen size first
661 // so that screen contents would define it instead.
662 $('inner-container').style.height = '';
663 $('inner-container').style.width = '';
664 screen.style.width = '';
665 screen.style.height = '';
667 $('outer-container').classList.toggle(
668 'fullscreen', screen.classList.contains('fullscreen'));
670 var width = screen.getPreferredSize().width;
671 var height = screen.getPreferredSize().height;
672 for (var i = 0, screenGroup; screenGroup = SCREEN_GROUPS[i]; i++) {
673 if (screenGroup.indexOf(screen.id) != -1) {
674 // Set screen dimensions to maximum dimensions within this group.
675 for (var j = 0, screen2; screen2 = $(screenGroup[j]); j++) {
676 width = Math.max(width, screen2.getPreferredSize().width);
677 height = Math.max(height, screen2.getPreferredSize().height);
682 $('inner-container').style.height = height + 'px';
683 $('inner-container').style.width = width + 'px';
684 // This requires |screen| to have 'box-sizing: border-box'.
685 screen.style.width = width + 'px';
686 screen.style.height = height + 'px';
690 * Updates localized content of the screens like headers, buttons and links.
691 * Should be executed on language change.
693 updateLocalizedContent_: function() {
694 for (var i = 0, screenId; screenId = this.screens_[i]; ++i) {
695 var screen = $(screenId);
696 var buttonStrip = $(screenId + '-controls');
698 buttonStrip.innerHTML = '';
699 // TODO(nkostylev): Update screen headers for new OOBE design.
700 this.appendButtons_(screen.buttons, screenId);
701 if (screen.updateLocalizedContent)
702 screen.updateLocalizedContent();
705 var currentScreenId = this.screens_[this.currentStep_];
706 var currentScreen = $(currentScreenId);
707 this.updateScreenSize(currentScreen);
709 // Trigger network drop-down to reload its state
710 // so that strings are reloaded.
711 // Will be reloaded if drowdown is actually shown.
712 cr.ui.DropDown.refresh();
716 * Initialized first group of OOBE screens.
718 initializeOOBEScreens: function() {
719 if (this.isOobeUI() && $('inner-container').classList.contains('down')) {
720 for (var i = 0, screen;
721 screen = $(SCREEN_GROUPS[SCREEN_GROUP_OOBE][i]); i++) {
722 screen.hidden = false;
728 * Prepares screens to use in login display.
730 prepareForLoginDisplay_: function() {
731 for (var i = 0, screenId; screenId = this.screens_[i]; ++i) {
732 var screen = $(screenId);
733 screen.classList.add('faded');
734 screen.classList.remove('right');
735 screen.classList.remove('left');
740 * Shows the device requisition prompt.
742 showDeviceRequisitionPrompt_: function() {
743 if (!this.deviceRequisitionDialog_) {
744 this.deviceRequisitionDialog_ =
745 new cr.ui.dialogs.PromptDialog(document.body);
746 this.deviceRequisitionDialog_.setOkLabel(
747 loadTimeData.getString('deviceRequisitionPromptOk'));
748 this.deviceRequisitionDialog_.setCancelLabel(
749 loadTimeData.getString('deviceRequisitionPromptCancel'));
751 this.deviceRequisitionDialog_.show(
752 loadTimeData.getString('deviceRequisitionPromptText'),
753 this.deviceRequisition_,
754 this.onConfirmDeviceRequisitionPrompt_.bind(this));
758 * Confirmation handle for the device requisition prompt.
759 * @param {string} value The value entered by the user.
762 onConfirmDeviceRequisitionPrompt_: function(value) {
763 this.deviceRequisition_ = value;
764 chrome.send('setDeviceRequisition', [value == '' ? 'none' : value]);
768 * Called when window size changed. Notifies current screen about change.
771 onWindowResize_: function() {
772 var currentScreenId = this.screens_[this.currentStep_];
773 var currentScreen = $(currentScreenId);
775 currentScreen.onWindowResize();
779 * Updates the device requisition string shown in the requisition prompt.
780 * @param {string} requisition The device requisition.
782 updateDeviceRequisition: function(requisition) {
783 this.deviceRequisition_ = requisition;
787 * Shows the special remora/shark device requisition prompt.
790 showDeviceRequisitionRemoraPrompt_: function(promptText, requisition) {
791 if (!this.deviceRequisitionRemoraDialog_) {
792 this.deviceRequisitionRemoraDialog_ =
793 new cr.ui.dialogs.ConfirmDialog(document.body);
794 this.deviceRequisitionRemoraDialog_.setOkLabel(
795 loadTimeData.getString('deviceRequisitionRemoraPromptOk'));
796 this.deviceRequisitionRemoraDialog_.setCancelLabel(
797 loadTimeData.getString('deviceRequisitionRemoraPromptCancel'));
799 this.deviceRequisitionRemoraDialog_.show(
800 loadTimeData.getString(promptText),
801 function() { // onShow
802 chrome.send('setDeviceRequisition', [requisition]);
804 function() { // onCancel
805 chrome.send('setDeviceRequisition', ['none']);
810 * Returns true if Oobe UI is shown.
812 isOobeUI: function() {
813 return document.body.classList.contains('oobe-display');
817 * Sets or unsets given |className| for top-level container. Useful for
818 * customizing #inner-container with CSS rules. All classes set with with
819 * this method will be removed after screen change.
820 * @param {string} className Class to toggle.
821 * @param {boolean} enabled Whether class should be enabled or disabled.
823 toggleClass: function(className, enabled) {
824 $('oobe').classList.toggle(className, enabled);
829 * Initializes display manager.
831 DisplayManager.initialize = function() {
832 var givenDisplayType = DISPLAY_TYPE.UNKNOWN;
833 if (document.documentElement.hasAttribute('screen')) {
834 // Display type set in HTML property.
835 givenDisplayType = document.documentElement.getAttribute('screen');
837 // Extracting display type from URL.
838 givenDisplayType = window.location.pathname.substr(1);
840 var instance = Oobe.getInstance();
841 Object.getOwnPropertyNames(DISPLAY_TYPE).forEach(function(type) {
842 if (DISPLAY_TYPE[type] == givenDisplayType) {
843 instance.displayType = givenDisplayType;
846 if (instance.displayType == DISPLAY_TYPE.UNKNOWN) {
847 console.error("Unknown display type '" + givenDisplayType +
848 "'. Setting default.");
849 instance.displayType = DISPLAY_TYPE.LOGIN;
852 instance.initializeOOBEScreens();
854 window.addEventListener('resize', instance.onWindowResize_.bind(instance));
858 * Returns offset (top, left) of the element.
859 * @param {!Element} element HTML element.
860 * @return {!Object} The offset (top, left).
862 DisplayManager.getOffset = function(element) {
865 while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
866 x += element.offsetLeft - element.scrollLeft;
867 y += element.offsetTop - element.scrollTop;
868 element = element.offsetParent;
870 return { top: y, left: x };
874 * Returns position (top, left, right, bottom) of the element.
875 * @param {!Element} element HTML element.
876 * @return {!Object} Element position (top, left, right, bottom).
878 DisplayManager.getPosition = function(element) {
879 var offset = DisplayManager.getOffset(element);
880 return { top: offset.top,
881 right: window.innerWidth - element.offsetWidth - offset.left,
882 bottom: window.innerHeight - element.offsetHeight - offset.top,
887 * Disables signin UI.
889 DisplayManager.disableSigninUI = function() {
890 $('login-header-bar').disabled = true;
891 $('pod-row').disabled = true;
896 * @param {string} opt_email An optional email for signin UI.
898 DisplayManager.showSigninUI = function(opt_email) {
899 var currentScreenId = Oobe.getInstance().currentScreen.id;
900 if (currentScreenId == SCREEN_GAIA_SIGNIN)
901 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.GAIA_SIGNIN;
902 else if (currentScreenId == SCREEN_ACCOUNT_PICKER)
903 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ACCOUNT_PICKER;
904 chrome.send('showAddUser', [opt_email]);
908 * Resets sign-in input fields.
909 * @param {boolean} forceOnline Whether online sign-in should be forced.
910 * If |forceOnline| is false previously used sign-in type will be used.
912 DisplayManager.resetSigninUI = function(forceOnline) {
913 var currentScreenId = Oobe.getInstance().currentScreen.id;
915 $(SCREEN_GAIA_SIGNIN).reset(
916 currentScreenId == SCREEN_GAIA_SIGNIN, forceOnline);
917 $('login-header-bar').disabled = false;
918 $('pod-row').reset(currentScreenId == SCREEN_ACCOUNT_PICKER);
922 * Shows sign-in error bubble.
923 * @param {number} loginAttempts Number of login attemps tried.
924 * @param {string} message Error message to show.
925 * @param {string} link Text to use for help link.
926 * @param {number} helpId Help topic Id associated with help link.
928 DisplayManager.showSignInError = function(loginAttempts, message, link,
930 var error = document.createElement('div');
932 var messageDiv = document.createElement('div');
933 messageDiv.className = 'error-message-bubble';
934 messageDiv.textContent = message;
935 error.appendChild(messageDiv);
938 messageDiv.classList.add('error-message-bubble-padding');
940 var helpLink = document.createElement('a');
942 helpLink.textContent = link;
943 helpLink.addEventListener('click', function(e) {
944 chrome.send('launchHelpApp', [helpId]);
947 error.appendChild(helpLink);
950 var currentScreen = Oobe.getInstance().currentScreen;
951 if (currentScreen && typeof currentScreen.showErrorBubble === 'function') {
952 currentScreen.showErrorBubble(loginAttempts, error);
953 this.errorMessageWasShownForTesting_ = true;
958 * Shows password changed screen that offers migration.
959 * @param {boolean} showError Whether to show the incorrect password error.
961 DisplayManager.showPasswordChangedScreen = function(showError) {
962 login.PasswordChangedScreen.show(showError);
966 * Shows dialog to create a supervised user.
968 DisplayManager.showSupervisedUserCreationScreen = function() {
969 login.SupervisedUserCreationScreen.show();
973 * Shows TPM error screen.
975 DisplayManager.showTpmError = function() {
976 login.TPMErrorMessageScreen.show();
980 * Clears error bubble.
982 DisplayManager.clearErrors = function() {
984 this.errorMessageWasShownForTesting_ = false;
986 var bubbles = document.querySelectorAll('.bubble-shown');
987 for (var i = 0; i < bubbles.length; ++i)
988 bubbles[i].classList.remove('bubble-shown');
992 * Sets text content for a div with |labelId|.
993 * @param {string} labelId Id of the label div.
994 * @param {string} labelText Text for the label.
996 DisplayManager.setLabelText = function(labelId, labelText) {
997 $(labelId).textContent = labelText;
1001 * Sets the text content of the enterprise info message.
1002 * @param {string} messageText The message text.
1004 DisplayManager.setEnterpriseInfo = function(messageText) {
1005 $('enterprise-info-message').textContent = messageText;
1007 $('enterprise-info').hidden = false;
1012 * Disable Add users button if said.
1013 * @param {boolean} disable true to disable
1015 DisplayManager.updateAddUserButtonStatus = function(disable) {
1016 $('add-user-button').disabled = disable;
1017 $('add-user-button').classList[
1018 disable ? 'add' : 'remove']('button-restricted');
1019 $('add-user-button').title = disable ?
1020 loadTimeData.getString('disabledAddUserTooltip') : '';
1024 * Clears password field in user-pod.
1026 DisplayManager.clearUserPodPassword = function() {
1027 $('pod-row').clearFocusedPod();
1031 * Restores input focus to currently selected pod.
1033 DisplayManager.refocusCurrentPod = function() {
1034 $('pod-row').refocusCurrentPod();
1039 DisplayManager: DisplayManager