cros: Update SAML flow.
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / login / header_bar.js
blobdac8d258cdd8eebcae5628ae19d3effa78c4c1a3
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
3 // found in the LICENSE file.
5 /**
6 * @fileoverview Login UI header bar implementation.
7 */
9 cr.define('login', function() {
10 /**
11 * Creates a header bar element.
12 * @constructor
13 * @extends {HTMLDivElement}
15 var HeaderBar = cr.ui.define('div');
17 HeaderBar.prototype = {
18 __proto__: HTMLDivElement.prototype,
20 // Whether guest button should be shown when header bar is in normal mode.
21 showGuest_: false,
23 // Current UI state of the sign-in screen.
24 signinUIState_: SIGNIN_UI_STATE.HIDDEN,
26 // Whether to show kiosk apps menu.
27 hasApps_: false,
29 /** @override */
30 decorate: function() {
31 $('shutdown-header-bar-item').addEventListener('click',
32 this.handleShutdownClick_);
33 $('shutdown-button').addEventListener('click',
34 this.handleShutdownClick_);
35 $('add-user-button').addEventListener('click',
36 this.handleAddUserClick_);
37 $('cancel-add-user-button').addEventListener('click',
38 this.handleCancelAddUserClick_);
39 $('guest-user-header-bar-item').addEventListener('click',
40 this.handleGuestClick_);
41 $('guest-user-button').addEventListener('click',
42 this.handleGuestClick_);
43 $('sign-out-user-button').addEventListener('click',
44 this.handleSignoutClick_);
45 $('cancel-multiple-sign-in-button').addEventListener('click',
46 this.handleCancelMultipleSignInClick_);
47 if (Oobe.getInstance().displayType == DISPLAY_TYPE.LOGIN ||
48 Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE)
49 login.AppsMenuButton.decorate($('show-apps-button'));
52 /**
53 * Tab index value for all button elements.
54 * @type {number}
56 set buttonsTabIndex(tabIndex) {
57 var buttons = this.getElementsByTagName('button');
58 for (var i = 0, button; button = buttons[i]; ++i) {
59 button.tabIndex = tabIndex;
63 /**
64 * Disables the header bar and all of its elements.
65 * @type {boolean}
67 set disabled(value) {
68 var buttons = this.getElementsByTagName('button');
69 for (var i = 0, button; button = buttons[i]; ++i)
70 if (!button.classList.contains('button-restricted'))
71 button.disabled = value;
74 /**
75 * Add user button click handler.
76 * @private
78 handleAddUserClick_: function(e) {
79 Oobe.showSigninUI();
80 // Prevent further propagation of click event. Otherwise, the click event
81 // handler of document object will set wallpaper to user's wallpaper when
82 // there is only one existing user. See http://crbug.com/166477
83 e.stopPropagation();
86 /**
87 * Cancel add user button click handler.
88 * @private
90 handleCancelAddUserClick_: function(e) {
91 // Let screen handle cancel itself if that is capable of doing so.
92 if (Oobe.getInstance().currentScreen &&
93 Oobe.getInstance().currentScreen.cancel) {
94 Oobe.getInstance().currentScreen.cancel();
95 return;
98 $('pod-row').loadLastWallpaper();
100 Oobe.showScreen({id: SCREEN_ACCOUNT_PICKER});
101 Oobe.resetSigninUI(true);
105 * Guest button click handler.
106 * @private
108 handleGuestClick_: function(e) {
109 Oobe.disableSigninUI();
110 chrome.send('launchIncognito');
111 e.stopPropagation();
115 * Sign out button click handler.
116 * @private
118 handleSignoutClick_: function(e) {
119 this.disabled = true;
120 chrome.send('signOutUser');
121 e.stopPropagation();
125 * Shutdown button click handler.
126 * @private
128 handleShutdownClick_: function(e) {
129 chrome.send('shutdownSystem');
130 e.stopPropagation();
134 * Cancel user adding button handler.
135 * @private
137 handleCancelMultipleSignInClick_: function(e) {
138 chrome.send('cancelUserAdding');
139 e.stopPropagation();
143 * If true then "Browse as Guest" button is shown.
144 * @type {boolean}
146 set showGuestButton(value) {
147 this.showGuest_ = value;
148 this.updateUI_();
152 * Update current header bar UI.
153 * @type {number} state Current state of the sign-in screen
154 * (see SIGNIN_UI_STATE).
156 set signinUIState(state) {
157 this.signinUIState_ = state;
158 this.updateUI_();
162 * Whether the Cancel button is enabled during Gaia sign-in.
163 * @type {boolean}
165 set allowCancel(value) {
166 this.allowCancel_ = value;
167 this.updateUI_();
171 * Update whether there are kiosk apps.
172 * @type {boolean}
174 set hasApps(value) {
175 this.hasApps_ = value;
176 this.updateUI_();
180 * Updates visibility state of action buttons.
181 * @private
183 updateUI_: function() {
184 var gaiaIsActive = (this.signinUIState_ == SIGNIN_UI_STATE.GAIA_SIGNIN);
185 var accountPickerIsActive =
186 (this.signinUIState_ == SIGNIN_UI_STATE.ACCOUNT_PICKER);
187 var managedUserCreationDialogIsActive =
188 (this.signinUIState_ == SIGNIN_UI_STATE.MANAGED_USER_CREATION_FLOW);
189 var wrongHWIDWarningIsActive =
190 (this.signinUIState_ == SIGNIN_UI_STATE.WRONG_HWID_WARNING);
191 var isSamlPasswordConfirm =
192 (this.signinUIState_ == SIGNIN_UI_STATE.SAML_PASSWORD_CONFIRM);
193 var isMultiProfilesUI =
194 (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING);
196 $('add-user-button').hidden = !accountPickerIsActive || isMultiProfilesUI;
197 $('cancel-add-user-button').hidden = accountPickerIsActive ||
198 !this.allowCancel_ ||
199 wrongHWIDWarningIsActive ||
200 isMultiProfilesUI;
201 $('guest-user-header-bar-item').hidden = gaiaIsActive ||
202 managedUserCreationDialogIsActive ||
203 !this.showGuest_ ||
204 wrongHWIDWarningIsActive ||
205 isSamlPasswordConfirm ||
206 isMultiProfilesUI;
207 $('add-user-header-bar-item').hidden =
208 $('add-user-button').hidden && $('cancel-add-user-button').hidden;
209 $('apps-header-bar-item').hidden = !this.hasApps_ ||
210 (!gaiaIsActive && !accountPickerIsActive);
211 $('cancel-multiple-sign-in-item').hidden = !isMultiProfilesUI;
213 if (!$('apps-header-bar-item').hidden)
214 $('show-apps-button').didShow();
218 * Animates Header bar to hide from the screen.
219 * @param {function()} callback will be called once animation is finished.
221 animateOut: function(callback) {
222 var launcher = this;
223 launcher.addEventListener(
224 'webkitTransitionEnd', function f(e) {
225 launcher.removeEventListener('webkitTransitionEnd', f);
226 callback();
228 // Guard timer for 2 seconds + 200 ms + epsilon.
229 ensureTransitionEndEvent(launcher, 2250);
231 this.classList.remove('login-header-bar-animate-slow');
232 this.classList.add('login-header-bar-animate-fast');
233 this.classList.add('login-header-bar-hidden');
237 * Animates Header bar to slowly appear on the screen.
239 animateIn: function() {
240 this.classList.remove('login-header-bar-animate-fast');
241 this.classList.add('login-header-bar-animate-slow');
242 this.classList.remove('login-header-bar-hidden');
247 * Convenience wrapper of animateOut.
249 HeaderBar.animateOut = function(callback) {
250 $('login-header-bar').animateOut(callback);
254 * Convenience wrapper of animateIn.
256 HeaderBar.animateIn = function() {
257 $('login-header-bar').animateIn();
260 return {
261 HeaderBar: HeaderBar