Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: chrome/browser/resources/login/screen_account_picker.js

Issue 402403005: Move common account picker/user pod js/css/html out of src/chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge + move Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 /**
6 * @fileoverview Account picker screen implementation.
7 */
8
9 login.createScreen('AccountPickerScreen', 'account-picker', function() {
10 /**
11 * Maximum number of offline login failures before online login.
12 * @type {number}
13 * @const
14 */
15 var MAX_LOGIN_ATTEMPTS_IN_POD = 3;
16 /**
17 * Whether to preselect the first pod automatically on login screen.
18 * @type {boolean}
19 * @const
20 */
21 var PRESELECT_FIRST_POD = true;
22
23 return {
24 EXTERNAL_API: [
25 'loadUsers',
26 'runAppForTesting',
27 'setApps',
28 'setShouldShowApps',
29 'showAppError',
30 'updateUserImage',
31 'setCapsLockState',
32 'forceLockedUserPodFocus',
33 'removeUser',
34 'showBannerMessage',
35 'showUserPodCustomIcon',
36 'hideUserPodCustomIcon',
37 'setAuthType',
38 'showEasyUnlockBubble',
39 'setPublicSessionKeyboardLayouts',
40 ],
41
42 preferredWidth_: 0,
43 preferredHeight_: 0,
44
45 // Whether this screen is shown for the first time.
46 firstShown_: true,
47
48 /** @override */
49 decorate: function() {
50 login.PodRow.decorate($('pod-row'));
51 },
52
53 /** @override */
54 getPreferredSize: function() {
55 return {width: this.preferredWidth_, height: this.preferredHeight_};
56 },
57
58 /** @override */
59 onWindowResize: function() {
60 $('pod-row').onWindowResize();
61 },
62
63 /**
64 * Sets preferred size for account picker screen.
65 */
66 setPreferredSize: function(width, height) {
67 this.preferredWidth_ = width;
68 this.preferredHeight_ = height;
69 },
70
71 /**
72 * When the account picker is being used to lock the screen, pressing the
73 * exit accelerator key will sign out the active user as it would when
74 * they are signed in.
75 */
76 exit: function() {
77 // Check and disable the sign out button so that we can never have two
78 // sign out requests generated in a row.
79 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) {
80 $('sign-out-user-button').disabled = true;
81 chrome.send('signOutUser');
82 }
83 },
84
85 /* Cancel user adding if ESC was pressed.
86 */
87 cancel: function() {
88 if (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING)
89 chrome.send('cancelUserAdding');
90 },
91
92 /**
93 * Event handler that is invoked just after the frame is shown.
94 * @param {string} data Screen init payload.
95 */
96 onAfterShow: function(data) {
97 $('pod-row').handleAfterShow();
98 },
99
100 /**
101 * Event handler that is invoked just before the frame is shown.
102 * @param {string} data Screen init payload.
103 */
104 onBeforeShow: function(data) {
105 chrome.send('loginUIStateChanged', ['account-picker', true]);
106 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ACCOUNT_PICKER;
107 chrome.send('hideCaptivePortal');
108 var podRow = $('pod-row');
109 podRow.handleBeforeShow();
110
111 // In case of the preselected pod onShow will be called once pod
112 // receives focus.
113 if (!podRow.preselectedPod)
114 this.onShow();
115 },
116
117 /**
118 * Event handler invoked when the page is shown and ready.
119 */
120 onShow: function() {
121 if (!this.firstShown_) return;
122 this.firstShown_ = false;
123
124 // Ensure that login is actually visible.
125 window.webkitRequestAnimationFrame(function() {
126 chrome.send('accountPickerReady');
127 chrome.send('loginVisible', ['account-picker']);
128 });
129 },
130
131 /**
132 * Event handler that is invoked just before the frame is hidden.
133 */
134 onBeforeHide: function() {
135 chrome.send('loginUIStateChanged', ['account-picker', false]);
136 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN;
137 $('pod-row').handleHide();
138 },
139
140 /**
141 * Shows sign-in error bubble.
142 * @param {number} loginAttempts Number of login attemps tried.
143 * @param {HTMLElement} content Content to show in bubble.
144 */
145 showErrorBubble: function(loginAttempts, error) {
146 var activatedPod = $('pod-row').activatedPod;
147 if (!activatedPod) {
148 $('bubble').showContentForElement($('pod-row'),
149 cr.ui.Bubble.Attachment.RIGHT,
150 error);
151 return;
152 }
153 // Show web authentication if this is not a locally managed user.
154 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD &&
155 !activatedPod.user.locallyManagedUser) {
156 activatedPod.showSigninUI();
157 } else {
158 // We want bubble's arrow to point to the first letter of input.
159 /** @const */ var BUBBLE_OFFSET = 7;
160 /** @const */ var BUBBLE_PADDING = 4;
161 $('bubble').showContentForElement(activatedPod.mainInput,
162 cr.ui.Bubble.Attachment.BOTTOM,
163 error,
164 BUBBLE_OFFSET, BUBBLE_PADDING);
165 }
166 },
167
168 /**
169 * Loads given users in pod row.
170 * @param {array} users Array of user.
171 * @param {boolean} showGuest Whether to show guest session button.
172 */
173 loadUsers: function(users, showGuest) {
174 $('pod-row').loadPods(users);
175 $('login-header-bar').showGuestButton = showGuest;
176
177 // The desktop User Manager can send the index of a pod that should be
178 // initially focused.
179 var hash = window.location.hash;
180 if (hash) {
181 var podIndex = hash.substr(1);
182 if (podIndex)
183 $('pod-row').focusPodByIndex(podIndex, false);
184 }
185 },
186
187 /**
188 * Runs app with a given id from the list of loaded apps.
189 * @param {!string} app_id of an app to run.
190 * @param {boolean=} opt_diagnostic_mode Whether to run the app in
191 * diagnostic mode. Default is false.
192 */
193 runAppForTesting: function(app_id, opt_diagnostic_mode) {
194 $('pod-row').findAndRunAppForTesting(app_id, opt_diagnostic_mode);
195 },
196
197 /**
198 * Adds given apps to the pod row.
199 * @param {array} apps Array of apps.
200 */
201 setApps: function(apps) {
202 $('pod-row').setApps(apps);
203 },
204
205 /**
206 * Sets the flag of whether app pods should be visible.
207 * @param {boolean} shouldShowApps Whether to show app pods.
208 */
209 setShouldShowApps: function(shouldShowApps) {
210 $('pod-row').setShouldShowApps(shouldShowApps);
211 },
212
213 /**
214 * Shows the given kiosk app error message.
215 * @param {!string} message Error message to show.
216 */
217 showAppError: function(message) {
218 // TODO(nkostylev): Figure out a way to show kiosk app launch error
219 // pointing to the kiosk app pod.
220 /** @const */ var BUBBLE_PADDING = 12;
221 $('bubble').showTextForElement($('pod-row'),
222 message,
223 cr.ui.Bubble.Attachment.BOTTOM,
224 $('pod-row').offsetWidth / 2,
225 BUBBLE_PADDING);
226 },
227
228 /**
229 * Updates current image of a user.
230 * @param {string} username User for which to update the image.
231 */
232 updateUserImage: function(username) {
233 $('pod-row').updateUserImage(username);
234 },
235
236 /**
237 * Updates Caps Lock state (for Caps Lock hint in password input field).
238 * @param {boolean} enabled Whether Caps Lock is on.
239 */
240 setCapsLockState: function(enabled) {
241 $('pod-row').classList.toggle('capslock-on', enabled);
242 },
243
244 /**
245 * Enforces focus on user pod of locked user.
246 */
247 forceLockedUserPodFocus: function() {
248 var row = $('pod-row');
249 if (row.lockedPod)
250 row.focusPod(row.lockedPod, true);
251 },
252
253 /**
254 * Remove given user from pod row if it is there.
255 * @param {string} user name.
256 */
257 removeUser: function(username) {
258 $('pod-row').removeUserPod(username);
259 },
260
261 /**
262 * Displays a banner containing |message|. If the banner is already present
263 * this function updates the message in the banner. This function is used
264 * by the chrome.screenlockPrivate.showMessage API.
265 * @param {string} message Text to be displayed
266 */
267 showBannerMessage: function(message) {
268 var banner = $('signin-banner');
269 banner.textContent = message;
270 banner.classList.toggle('message-set', true);
271 },
272
273 /**
274 * Shows a custom icon in the user pod of |username|. This function
275 * is used by the chrome.screenlockPrivate API.
276 * @param {string} username Username of pod to add button
277 * @param {{scale1x: string, scale2x: string}} icon Dictionary of URLs of
278 * the custom icon's representations for 1x and 2x scale factors.
279 */
280 showUserPodCustomIcon: function(username, icon) {
281 $('pod-row').showUserPodCustomIcon(username, icon);
282 },
283
284 /**
285 * Hides the custom icon in the user pod of |username| added by
286 * showUserPodCustomIcon(). This function is used by the
287 * chrome.screenlockPrivate API.
288 * @param {string} username Username of pod to remove button
289 */
290 hideUserPodCustomIcon: function(username) {
291 $('pod-row').hideUserPodCustomIcon(username);
292 },
293
294 /**
295 * Sets the authentication type used to authenticate the user.
296 * @param {string} username Username of selected user
297 * @param {number} authType Authentication type, must be a valid value in
298 * the AUTH_TYPE enum in user_pod_row.js.
299 * @param {string} value The initial value to use for authentication.
300 */
301 setAuthType: function(username, authType, value) {
302 $('pod-row').setAuthType(username, authType, value);
303 },
304
305 /**
306 * Shows a tooltip bubble explaining Easy Unlock.
307 */
308 showEasyUnlockBubble: function() {
309 $('pod-row').showEasyUnlockBubble();
310 },
311
312 /**
313 * Updates the list of available keyboard layouts for a public session pod.
314 * @param {string} userID The user ID of the public session
315 * @param {!Object} list List of available keyboard layouts
316 */
317 setPublicSessionKeyboardLayouts: function(userID, list) {
318 $('pod-row').setPublicSessionKeyboardLayouts(userID, list);
319 }
320 };
321 });
322
OLDNEW
« no previous file with comments | « chrome/browser/resources/login/screen_account_picker.html ('k') | chrome/browser/resources/login/screen_container.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698