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.
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;
29 'forceLockedUserPodFocus',
38 // Whether this screen is shown for the first time.
42 decorate: function() {
43 login.PodRow.decorate($('pod-row'));
47 getPreferredSize: function() {
48 return {width: this.preferredWidth_, height: this.preferredHeight_};
52 onWindowResize: function() {
53 $('pod-row').onWindowResize();
57 * Sets preferred size for account picker screen.
59 setPreferredSize: function(width, height) {
60 this.preferredWidth_ = width;
61 this.preferredHeight_ = height;
65 * When the account picker is being used to lock the screen, pressing the
66 * exit accelerator key will sign out the active user as it would when
70 // Check and disable the sign out button so that we can never have two
71 // sign out requests generated in a row.
72 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) {
73 $('sign-out-user-button').disabled = true;
74 chrome.send('signOutUser');
78 /* Cancel user adding if ESC was pressed.
81 if (Oobe.getInstance().displayType() == DISPLAY_TYPE.USER_ADDING)
82 chrome.send('cancelUserAdding');
86 * Event handler that is invoked just after the frame is shown.
87 * @param {string} data Screen init payload.
89 onAfterShow: function(data) {
90 $('pod-row').handleAfterShow();
94 * Event handler that is invoked just before the frame is shown.
95 * @param {string} data Screen init payload.
97 onBeforeShow: function(data) {
98 chrome.send('loginUIStateChanged', ['account-picker', true]);
99 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ACCOUNT_PICKER;
100 chrome.send('hideCaptivePortal');
101 var podRow = $('pod-row');
102 podRow.handleBeforeShow();
104 // If this is showing for the lock screen display the sign out button,
105 // hide the add user button and activate the locked user's pod.
106 var lockedPod = podRow.lockedPod;
107 $('add-user-header-bar-item').hidden = !!lockedPod;
108 var signOutUserItem = $('sign-out-user-item');
110 signOutUserItem.hidden = !lockedPod;
111 // In case of the preselected pod onShow will be called once pod
113 if (!podRow.preselectedPod)
118 * Event handler invoked when the page is shown and ready.
121 if (!this.firstShown_) return;
122 this.firstShown_ = false;
123 // TODO(nkostylev): Enable animation back when session start jank
124 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307
125 // $('pod-row').startInitAnimation();
127 // Ensure that login is actually visible.
128 window.webkitRequestAnimationFrame(function() {
129 chrome.send('accountPickerReady');
130 chrome.send('loginVisible', ['account-picker']);
135 * Event handler that is invoked just before the frame is hidden.
137 onBeforeHide: function() {
138 chrome.send('loginUIStateChanged', ['account-picker', false]);
139 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN;
140 $('pod-row').handleHide();
144 * Shows sign-in error bubble.
145 * @param {number} loginAttempts Number of login attemps tried.
146 * @param {HTMLElement} content Content to show in bubble.
148 showErrorBubble: function(loginAttempts, error) {
149 var activatedPod = $('pod-row').activatedPod;
151 $('bubble').showContentForElement($('pod-row'),
152 cr.ui.Bubble.Attachment.RIGHT,
156 // Show web authentication if this is not a locally managed user.
157 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD &&
158 !activatedPod.user.locallyManagedUser) {
159 activatedPod.showSigninUI();
161 // We want bubble's arrow to point to the first letter of input.
162 /** @const */ var BUBBLE_OFFSET = 7;
163 /** @const */ var BUBBLE_PADDING = 4;
164 $('bubble').showContentForElement(activatedPod.mainInput,
165 cr.ui.Bubble.Attachment.BOTTOM,
167 BUBBLE_OFFSET, BUBBLE_PADDING);
172 * Loads given users in pod row.
173 * @param {array} users Array of user.
174 * @param {boolean} animated Whether to use init animation.
175 * @param {boolean} showGuest Whether to show guest session button.
177 loadUsers: function(users, animated, showGuest) {
178 $('pod-row').loadPods(users, animated);
179 $('login-header-bar').showGuestButton = showGuest;
181 // The desktop User Manager can send the index of a pod that should be
182 // initially focused.
183 var hash = window.location.hash;
185 var podIndex = hash.substr(1);
187 $('pod-row').focusPodByIndex(podIndex, false);
192 * Updates current image of a user.
193 * @param {string} username User for which to update the image.
195 updateUserImage: function(username) {
196 $('pod-row').updateUserImage(username);
200 * Indicates that the given user must authenticate against GAIA during the
202 * @param {string} username User for whom to enforce GAIA sign-in.
204 forceOnlineSignin: function(username) {
205 $('pod-row').forceOnlineSigninForUser(username);
209 * Updates Caps Lock state (for Caps Lock hint in password input field).
210 * @param {boolean} enabled Whether Caps Lock is on.
212 setCapsLockState: function(enabled) {
213 $('pod-row').classList.toggle('capslock-on', enabled);
217 * Enforces focus on user pod of locked user.
219 forceLockedUserPodFocus: function() {
220 var row = $('pod-row');
222 row.focusPod(row.lockedPod, true);
226 * Remove given user from pod row if it is there.
227 * @param {string} user name.
229 removeUser: function(username) {
230 $('pod-row').removeUserPod(username);
234 * Displays a banner containing |message|. If the banner is already present
235 * this function updates the message in the banner. This function is used
236 * by the chrome.screenlockPrivate.showMessage API.
237 * @param {string} message Text to be displayed
239 showBannerMessage: function(message) {
240 var banner = $('signin-banner');
241 banner.textContent = message;
242 banner.classList.toggle('message-set', true);
246 * Shows a button with an icon on the user pod of |username|. This function
247 * is used by the chrome.screenlockPrivate API.
248 * @param {string} username Username of pod to add button
249 * @param {string} iconURL URL of the button icon
251 showUserPodButton: function(username, iconURL) {
252 $('pod-row').showUserPodButton(username, iconURL);