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;
27 'updateUserGaiaNeeded',
29 'forceLockedUserPodFocus',
39 // Whether this screen is shown for the first time.
43 decorate: function() {
44 login.PodRow.decorate($('pod-row'));
48 getPreferredSize: function() {
49 return {width: this.preferredWidth_, height: this.preferredHeight_};
53 onWindowResize: function() {
54 $('pod-row').onWindowResize();
58 * Sets preferred size for account picker screen.
60 setPreferredSize: function(width, height) {
61 this.preferredWidth_ = width;
62 this.preferredHeight_ = height;
66 * When the account picker is being used to lock the screen, pressing the
67 * exit accelerator key will sign out the active user as it would when
71 // Check and disable the sign out button so that we can never have two
72 // sign out requests generated in a row.
73 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) {
74 $('sign-out-user-button').disabled = true;
75 chrome.send('signOutUser');
79 /* Cancel user adding if ESC was pressed.
82 if (Oobe.getInstance().displayType() == DISPLAY_TYPE.USER_ADDING)
83 chrome.send('cancelUserAdding');
87 * Event handler that is invoked just after the frame is shown.
88 * @param {string} data Screen init payload.
90 onAfterShow: function(data) {
91 $('pod-row').handleAfterShow();
95 * Event handler that is invoked just before the frame is shown.
96 * @param {string} data Screen init payload.
98 onBeforeShow: function(data) {
99 chrome.send('loginUIStateChanged', ['account-picker', true]);
100 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ACCOUNT_PICKER;
101 chrome.send('hideCaptivePortal');
102 var podRow = $('pod-row');
103 podRow.handleBeforeShow();
105 // If this is showing for the lock screen display the sign out button,
106 // hide the add user button and activate the locked user's pod.
107 var lockedPod = podRow.lockedPod;
108 $('add-user-header-bar-item').hidden = !!lockedPod;
109 var signOutUserItem = $('sign-out-user-item');
111 signOutUserItem.hidden = !lockedPod;
112 // In case of the preselected pod onShow will be called once pod
114 if (!podRow.preselectedPod)
119 * Event handler invoked when the page is shown and ready.
122 if (!this.firstShown_) return;
123 this.firstShown_ = false;
124 // TODO(nkostylev): Enable animation back when session start jank
125 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307
126 // $('pod-row').startInitAnimation();
128 // Ensure that login is actually visible.
129 window.webkitRequestAnimationFrame(function() {
130 chrome.send('accountPickerReady');
131 chrome.send('loginVisible', ['account-picker']);
136 * Event handler that is invoked just before the frame is hidden.
138 onBeforeHide: function() {
139 chrome.send('loginUIStateChanged', ['account-picker', false]);
140 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN;
141 $('pod-row').handleHide();
145 * Shows sign-in error bubble.
146 * @param {number} loginAttempts Number of login attemps tried.
147 * @param {HTMLElement} content Content to show in bubble.
149 showErrorBubble: function(loginAttempts, error) {
150 var activatedPod = $('pod-row').activatedPod;
152 $('bubble').showContentForElement($('pod-row'),
153 cr.ui.Bubble.Attachment.RIGHT,
157 // Show web authentication if this is not a locally managed user.
158 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD &&
159 !activatedPod.user.locallyManagedUser) {
160 activatedPod.showSigninUI();
162 // We want bubble's arrow to point to the first letter of input.
163 /** @const */ var BUBBLE_OFFSET = 7;
164 /** @const */ var BUBBLE_PADDING = 4;
165 $('bubble').showContentForElement(activatedPod.mainInput,
166 cr.ui.Bubble.Attachment.BOTTOM,
168 BUBBLE_OFFSET, BUBBLE_PADDING);
173 * Loads given users in pod row.
174 * @param {array} users Array of user.
175 * @param {boolean} animated Whether to use init animation.
176 * @param {boolean} showGuest Whether to show guest session button.
178 loadUsers: function(users, animated, showGuest) {
179 $('pod-row').loadPods(users, animated);
180 $('login-header-bar').showGuestButton = showGuest;
182 // The desktop User Manager can send the index of a pod that should be
183 // initially focused.
184 var hash = window.location.hash;
186 var podIndex = hash.substr(1);
188 $('pod-row').focusPodByIndex(podIndex, false);
193 * Updates current image of a user.
194 * @param {string} username User for which to update the image.
196 updateUserImage: function(username) {
197 $('pod-row').updateUserImage(username);
201 * Updates user to use gaia login.
202 * @param {string} username User for which to state the state.
204 updateUserGaiaNeeded: function(username) {
205 $('pod-row').resetUserOAuthTokenStatus(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 * Mark wallpaper loaded
228 onWallpaperLoaded: function(username) {
229 $('pod-row').onWallpaperLoaded(username);
233 * Remove given user from pod row if it is there.
234 * @param {string} user name.
236 removeUser: function(username) {
237 $('pod-row').removeUserPod(username);
241 * Displays a banner containing |message|. If the banner is already present
242 * this function updates the message in the banner. This function is used
243 * by the chrome.screenlockPrivate.showMessage API.
244 * @param {string} message Text to be displayed
246 showBannerMessage: function(message) {
247 var banner = $('signin-banner');
248 banner.textContent = message;
249 banner.classList.toggle('message-set', true);
253 * Shows a button with an icon on the user pod of |username|. This function
254 * is used by the chrome.screenlockPrivate API.
255 * @param {string} username Username of pod to add button
256 * @param {string} iconURL URL of the button icon
258 showUserPodButton: function(username, iconURL) {
259 $('pod-row').showUserPodButton(username, iconURL);