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 Account picker screen implementation.
9 login.createScreen('AccountPickerScreen', 'account-picker', function() {
11 * Maximum number of offline login failures before online login.
15 var MAX_LOGIN_ATTEMPTS_IN_POD = 3;
17 * Whether to preselect the first pod automatically on login screen.
21 var PRESELECT_FIRST_POD = true;
32 'forceLockedUserPodFocus',
35 'showUserPodCustomIcon',
36 'hideUserPodCustomIcon',
38 'showEasyUnlockBubble',
44 // Whether this screen is shown for the first time.
48 decorate: function() {
49 login.PodRow.decorate($('pod-row'));
53 getPreferredSize: function() {
54 return {width: this.preferredWidth_, height: this.preferredHeight_};
58 onWindowResize: function() {
59 $('pod-row').onWindowResize();
63 * Sets preferred size for account picker screen.
65 setPreferredSize: function(width, height) {
66 this.preferredWidth_ = width;
67 this.preferredHeight_ = height;
71 * When the account picker is being used to lock the screen, pressing the
72 * exit accelerator key will sign out the active user as it would when
76 // Check and disable the sign out button so that we can never have two
77 // sign out requests generated in a row.
78 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) {
79 $('sign-out-user-button').disabled = true;
80 chrome.send('signOutUser');
84 /* Cancel user adding if ESC was pressed.
87 if (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING)
88 chrome.send('cancelUserAdding');
92 * Event handler that is invoked just after the frame is shown.
93 * @param {string} data Screen init payload.
95 onAfterShow: function(data) {
96 $('pod-row').handleAfterShow();
100 * Event handler that is invoked just before the frame is shown.
101 * @param {string} data Screen init payload.
103 onBeforeShow: function(data) {
104 chrome.send('loginUIStateChanged', ['account-picker', true]);
105 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ACCOUNT_PICKER;
106 chrome.send('hideCaptivePortal');
107 var podRow = $('pod-row');
108 podRow.handleBeforeShow();
110 // In case of the preselected pod onShow will be called once pod
112 if (!podRow.preselectedPod)
117 * Event handler invoked when the page is shown and ready.
120 if (!this.firstShown_) return;
121 this.firstShown_ = false;
122 // TODO(nkostylev): Enable animation back when session start jank
123 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307
124 // $('pod-row').startInitAnimation();
126 // Ensure that login is actually visible.
127 window.webkitRequestAnimationFrame(function() {
128 chrome.send('accountPickerReady');
129 chrome.send('loginVisible', ['account-picker']);
134 * Event handler that is invoked just before the frame is hidden.
136 onBeforeHide: function() {
137 chrome.send('loginUIStateChanged', ['account-picker', false]);
138 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN;
139 $('pod-row').handleHide();
143 * Shows sign-in error bubble.
144 * @param {number} loginAttempts Number of login attemps tried.
145 * @param {HTMLElement} content Content to show in bubble.
147 showErrorBubble: function(loginAttempts, error) {
148 var activatedPod = $('pod-row').activatedPod;
150 $('bubble').showContentForElement($('pod-row'),
151 cr.ui.Bubble.Attachment.RIGHT,
155 // Show web authentication if this is not a locally managed user.
156 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD &&
157 !activatedPod.user.locallyManagedUser) {
158 activatedPod.showSigninUI();
160 // We want bubble's arrow to point to the first letter of input.
161 /** @const */ var BUBBLE_OFFSET = 7;
162 /** @const */ var BUBBLE_PADDING = 4;
163 $('bubble').showContentForElement(activatedPod.mainInput,
164 cr.ui.Bubble.Attachment.BOTTOM,
166 BUBBLE_OFFSET, BUBBLE_PADDING);
171 * Loads given users in pod row.
172 * @param {array} users Array of user.
173 * @param {boolean} animated Whether to use init animation.
174 * @param {boolean} showGuest Whether to show guest session button.
176 loadUsers: function(users, animated, showGuest) {
177 $('pod-row').loadPods(users, animated);
178 $('login-header-bar').showGuestButton = showGuest;
180 // The desktop User Manager can send the index of a pod that should be
181 // initially focused.
182 var hash = window.location.hash;
184 var podIndex = hash.substr(1);
186 $('pod-row').focusPodByIndex(podIndex, false);
191 * Runs app with a given id from the list of loaded apps.
192 * @param {!string} app_id of an app to run.
193 * @param {boolean=} opt_diagnostic_mode Whether to run the app in
194 * diagnostic mode. Default is false.
196 runAppForTesting: function(app_id, opt_diagnostic_mode) {
197 $('pod-row').findAndRunAppForTesting(app_id, opt_diagnostic_mode);
201 * Adds given apps to the pod row.
202 * @param {array} apps Array of apps.
204 setApps: function(apps) {
205 $('pod-row').setApps(apps);
209 * Sets the flag of whether app pods should be visible.
210 * @param {boolean} shouldShowApps Whether to show app pods.
212 setShouldShowApps: function(shouldShowApps) {
213 $('pod-row').setShouldShowApps(shouldShowApps);
217 * Shows the given kiosk app error message.
218 * @param {!string} message Error message to show.
220 showAppError: function(message) {
221 // TODO(nkostylev): Figure out a way to show kiosk app launch error
222 // pointing to the kiosk app pod.
223 /** @const */ var BUBBLE_PADDING = 12;
224 $('bubble').showTextForElement($('pod-row'),
226 cr.ui.Bubble.Attachment.BOTTOM,
227 $('pod-row').offsetWidth / 2,
232 * Updates current image of a user.
233 * @param {string} username User for which to update the image.
235 updateUserImage: function(username) {
236 $('pod-row').updateUserImage(username);
240 * Updates Caps Lock state (for Caps Lock hint in password input field).
241 * @param {boolean} enabled Whether Caps Lock is on.
243 setCapsLockState: function(enabled) {
244 $('pod-row').classList.toggle('capslock-on', enabled);
248 * Enforces focus on user pod of locked user.
250 forceLockedUserPodFocus: function() {
251 var row = $('pod-row');
253 row.focusPod(row.lockedPod, true);
257 * Remove given user from pod row if it is there.
258 * @param {string} user name.
260 removeUser: function(username) {
261 $('pod-row').removeUserPod(username);
265 * Displays a banner containing |message|. If the banner is already present
266 * this function updates the message in the banner. This function is used
267 * by the chrome.screenlockPrivate.showMessage API.
268 * @param {string} message Text to be displayed
270 showBannerMessage: function(message) {
271 var banner = $('signin-banner');
272 banner.textContent = message;
273 banner.classList.toggle('message-set', true);
277 * Shows a custom icon in the user pod of |username|. This function
278 * is used by the chrome.screenlockPrivate API.
279 * @param {string} username Username of pod to add button
280 * @param {{scale1x: string, scale2x: string}} icon Dictionary of URLs of
281 * the custom icon's representations for 1x and 2x scale factors.
283 showUserPodCustomIcon: function(username, icon) {
284 $('pod-row').showUserPodCustomIcon(username, icon);
288 * Hides the custom icon in the user pod of |username| added by
289 * showUserPodCustomIcon(). This function is used by the
290 * chrome.screenlockPrivate API.
291 * @param {string} username Username of pod to remove button
293 hideUserPodCustomIcon: function(username) {
294 $('pod-row').hideUserPodCustomIcon(username);
298 * Sets the authentication type used to authenticate the user.
299 * @param {string} username Username of selected user
300 * @param {number} authType Authentication type, must be a valid value in
301 * the AUTH_TYPE enum in user_pod_row.js.
302 * @param {string} value The initial value to use for authentication.
304 setAuthType: function(username, authType, value) {
305 $('pod-row').setAuthType(username, authType, value);
309 * Shows a tooltip bubble explaining Easy Unlock.
311 showEasyUnlockBubble: function() {
312 $('pod-row').showEasyUnlockBubble();