MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / ui / login / account_picker / screen_account_picker.js
blob865d64d3c88f5650193507429543cd5d70e94b23
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.
5 /**
6 * @fileoverview Account picker screen implementation.
7 */
9 login.createScreen('AccountPickerScreen', 'account-picker', function() {
10 /**
11 * Maximum number of offline login failures before online login.
12 * @type {number}
13 * @const
15 var MAX_LOGIN_ATTEMPTS_IN_POD = 3;
17 return {
18 EXTERNAL_API: [
19 'loadUsers',
20 'runAppForTesting',
21 'setApps',
22 'setShouldShowApps',
23 'showAppError',
24 'updateUserImage',
25 'setCapsLockState',
26 'forceLockedUserPodFocus',
27 'removeUser',
28 'showBannerMessage',
29 'showUserPodCustomIcon',
30 'hideUserPodCustomIcon',
31 'setAuthType',
32 'setTouchViewState',
33 'setPublicSessionDisplayName',
34 'setPublicSessionLocales',
35 'setPublicSessionKeyboardLayouts',
38 preferredWidth_: 0,
39 preferredHeight_: 0,
41 // Whether this screen is shown for the first time.
42 firstShown_: true,
44 /** @override */
45 decorate: function() {
46 login.PodRow.decorate($('pod-row'));
49 /** @override */
50 getPreferredSize: function() {
51 return {width: this.preferredWidth_, height: this.preferredHeight_};
54 /** @override */
55 onWindowResize: function() {
56 $('pod-row').onWindowResize();
59 /**
60 * Sets preferred size for account picker screen.
62 setPreferredSize: function(width, height) {
63 this.preferredWidth_ = width;
64 this.preferredHeight_ = height;
67 /**
68 * When the account picker is being used to lock the screen, pressing the
69 * exit accelerator key will sign out the active user as it would when
70 * they are signed in.
72 exit: function() {
73 // Check and disable the sign out button so that we can never have two
74 // sign out requests generated in a row.
75 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) {
76 $('sign-out-user-button').disabled = true;
77 chrome.send('signOutUser');
81 /* Cancel user adding if ESC was pressed.
83 cancel: function() {
84 if (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING)
85 chrome.send('cancelUserAdding');
88 /**
89 * Event handler that is invoked just after the frame is shown.
90 * @param {string} data Screen init payload.
92 onAfterShow: function(data) {
93 $('pod-row').handleAfterShow();
96 /**
97 * Event handler that is invoked just before the frame is shown.
98 * @param {string} data Screen init payload.
100 onBeforeShow: function(data) {
101 chrome.send('loginUIStateChanged', ['account-picker', true]);
102 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ACCOUNT_PICKER;
103 chrome.send('hideCaptivePortal');
104 var podRow = $('pod-row');
105 podRow.handleBeforeShow();
107 // In case of the preselected pod onShow will be called once pod
108 // receives focus.
109 if (!podRow.preselectedPod)
110 this.onShow();
114 * Event handler invoked when the page is shown and ready.
116 onShow: function() {
117 chrome.send('getTouchViewState');
118 if (!this.firstShown_) return;
119 this.firstShown_ = false;
121 // Ensure that login is actually visible.
122 window.requestAnimationFrame(function() {
123 chrome.send('accountPickerReady');
124 chrome.send('loginVisible', ['account-picker']);
129 * Event handler that is invoked just before the frame is hidden.
131 onBeforeHide: function() {
132 chrome.send('loginUIStateChanged', ['account-picker', false]);
133 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN;
134 $('pod-row').handleHide();
138 * Shows sign-in error bubble.
139 * @param {number} loginAttempts Number of login attemps tried.
140 * @param {HTMLElement} content Content to show in bubble.
142 showErrorBubble: function(loginAttempts, error) {
143 var activatedPod = $('pod-row').activatedPod;
144 if (!activatedPod) {
145 $('bubble').showContentForElement($('pod-row'),
146 cr.ui.Bubble.Attachment.RIGHT,
147 error);
148 return;
150 // Show web authentication if this is not a supervised user.
151 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD &&
152 !activatedPod.user.supervisedUser) {
153 activatedPod.showSigninUI();
154 } else {
155 // We want bubble's arrow to point to the first letter of input.
156 /** @const */ var BUBBLE_OFFSET = 7;
157 /** @const */ var BUBBLE_PADDING = 4;
158 $('bubble').showContentForElement(activatedPod.mainInput,
159 cr.ui.Bubble.Attachment.BOTTOM,
160 error,
161 BUBBLE_OFFSET, BUBBLE_PADDING);
162 // Move error bubble up if it overlaps the shelf.
163 var maxHeight =
164 cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping($('bubble'));
165 if (maxHeight < $('bubble').offsetHeight) {
166 $('bubble').showContentForElement(activatedPod.mainInput,
167 cr.ui.Bubble.Attachment.TOP,
168 error,
169 BUBBLE_OFFSET, BUBBLE_PADDING);
175 * Loads given users in pod row.
176 * @param {array} users Array of user.
177 * @param {boolean} showGuest Whether to show guest session button.
179 loadUsers: function(users, showGuest) {
180 $('pod-row').loadPods(users);
181 $('login-header-bar').showGuestButton = showGuest;
185 * Runs app with a given id from the list of loaded apps.
186 * @param {!string} app_id of an app to run.
187 * @param {boolean=} opt_diagnostic_mode Whether to run the app in
188 * diagnostic mode. Default is false.
190 runAppForTesting: function(app_id, opt_diagnostic_mode) {
191 $('pod-row').findAndRunAppForTesting(app_id, opt_diagnostic_mode);
195 * Adds given apps to the pod row.
196 * @param {array} apps Array of apps.
198 setApps: function(apps) {
199 $('pod-row').setApps(apps);
203 * Sets the flag of whether app pods should be visible.
204 * @param {boolean} shouldShowApps Whether to show app pods.
206 setShouldShowApps: function(shouldShowApps) {
207 $('pod-row').setShouldShowApps(shouldShowApps);
211 * Shows the given kiosk app error message.
212 * @param {!string} message Error message to show.
214 showAppError: function(message) {
215 // TODO(nkostylev): Figure out a way to show kiosk app launch error
216 // pointing to the kiosk app pod.
217 /** @const */ var BUBBLE_PADDING = 12;
218 $('bubble').showTextForElement($('pod-row'),
219 message,
220 cr.ui.Bubble.Attachment.BOTTOM,
221 $('pod-row').offsetWidth / 2,
222 BUBBLE_PADDING);
226 * Updates current image of a user.
227 * @param {string} username User for which to update the image.
229 updateUserImage: function(username) {
230 $('pod-row').updateUserImage(username);
234 * Updates Caps Lock state (for Caps Lock hint in password input field).
235 * @param {boolean} enabled Whether Caps Lock is on.
237 setCapsLockState: function(enabled) {
238 $('pod-row').classList.toggle('capslock-on', enabled);
242 * Enforces focus on user pod of locked user.
244 forceLockedUserPodFocus: function() {
245 var row = $('pod-row');
246 if (row.lockedPod)
247 row.focusPod(row.lockedPod, true);
251 * Remove given user from pod row if it is there.
252 * @param {string} user name.
254 removeUser: function(username) {
255 $('pod-row').removeUserPod(username);
259 * Displays a banner containing |message|. If the banner is already present
260 * this function updates the message in the banner. This function is used
261 * by the chrome.screenlockPrivate.showMessage API.
262 * @param {string} message Text to be displayed
264 showBannerMessage: function(message) {
265 var banner = $('signin-banner');
266 banner.textContent = message;
267 banner.classList.toggle('message-set', true);
271 * Shows a custom icon in the user pod of |username|. This function
272 * is used by the chrome.screenlockPrivate API.
273 * @param {string} username Username of pod to add button
274 * @param {!{id: !string,
275 * hardlockOnClick: boolean,
276 * tooltip: ({text: string, autoshow: boolean} | undefined)}} icon
277 * The icon parameters.
279 showUserPodCustomIcon: function(username, icon) {
280 $('pod-row').showUserPodCustomIcon(username, icon);
284 * Hides the custom icon in the user pod of |username| added by
285 * showUserPodCustomIcon(). This function is used by the
286 * chrome.screenlockPrivate API.
287 * @param {string} username Username of pod to remove button
289 hideUserPodCustomIcon: function(username) {
290 $('pod-row').hideUserPodCustomIcon(username);
294 * Sets the authentication type used to authenticate the user.
295 * @param {string} username Username of selected user
296 * @param {number} authType Authentication type, must be a valid value in
297 * the AUTH_TYPE enum in user_pod_row.js.
298 * @param {string} value The initial value to use for authentication.
300 setAuthType: function(username, authType, value) {
301 $('pod-row').setAuthType(username, authType, value);
305 * Sets the state of touch view mode.
306 * @param {boolean} isTouchViewEnabled true if the mode is on.
308 setTouchViewState: function(isTouchViewEnabled) {
309 $('pod-row').setTouchViewState(isTouchViewEnabled);
313 * Updates the display name shown on a public session pod.
314 * @param {string} userID The user ID of the public session
315 * @param {string} displayName The new display name
317 setPublicSessionDisplayName: function(userID, displayName) {
318 $('pod-row').setPublicSessionDisplayName(userID, displayName);
322 * Updates the list of locales available for a public session.
323 * @param {string} userID The user ID of the public session
324 * @param {!Object} locales The list of available locales
325 * @param {string} defaultLocale The locale to select by default
326 * @param {boolean} multipleRecommendedLocales Whether |locales| contains
327 * two or more recommended locales
329 setPublicSessionLocales: function(userID,
330 locales,
331 defaultLocale,
332 multipleRecommendedLocales) {
333 $('pod-row').setPublicSessionLocales(userID,
334 locales,
335 defaultLocale,
336 multipleRecommendedLocales);
340 * Updates the list of available keyboard layouts for a public session pod.
341 * @param {string} userID The user ID of the public session
342 * @param {string} locale The locale to which this list of keyboard layouts
343 * applies
344 * @param {!Object} list List of available keyboard layouts
346 setPublicSessionKeyboardLayouts: function(userID, locale, list) {
347 $('pod-row').setPublicSessionKeyboardLayouts(userID, locale, list);