OLD | NEW |
| (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 ], | |
40 | |
41 preferredWidth_: 0, | |
42 preferredHeight_: 0, | |
43 | |
44 // Whether this screen is shown for the first time. | |
45 firstShown_: true, | |
46 | |
47 /** @override */ | |
48 decorate: function() { | |
49 login.PodRow.decorate($('pod-row')); | |
50 }, | |
51 | |
52 /** @override */ | |
53 getPreferredSize: function() { | |
54 return {width: this.preferredWidth_, height: this.preferredHeight_}; | |
55 }, | |
56 | |
57 /** @override */ | |
58 onWindowResize: function() { | |
59 $('pod-row').onWindowResize(); | |
60 }, | |
61 | |
62 /** | |
63 * Sets preferred size for account picker screen. | |
64 */ | |
65 setPreferredSize: function(width, height) { | |
66 this.preferredWidth_ = width; | |
67 this.preferredHeight_ = height; | |
68 }, | |
69 | |
70 /** | |
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 | |
73 * they are signed in. | |
74 */ | |
75 exit: function() { | |
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'); | |
81 } | |
82 }, | |
83 | |
84 /* Cancel user adding if ESC was pressed. | |
85 */ | |
86 cancel: function() { | |
87 if (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING) | |
88 chrome.send('cancelUserAdding'); | |
89 }, | |
90 | |
91 /** | |
92 * Event handler that is invoked just after the frame is shown. | |
93 * @param {string} data Screen init payload. | |
94 */ | |
95 onAfterShow: function(data) { | |
96 $('pod-row').handleAfterShow(); | |
97 }, | |
98 | |
99 /** | |
100 * Event handler that is invoked just before the frame is shown. | |
101 * @param {string} data Screen init payload. | |
102 */ | |
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(); | |
109 | |
110 // In case of the preselected pod onShow will be called once pod | |
111 // receives focus. | |
112 if (!podRow.preselectedPod) | |
113 this.onShow(); | |
114 }, | |
115 | |
116 /** | |
117 * Event handler invoked when the page is shown and ready. | |
118 */ | |
119 onShow: function() { | |
120 if (!this.firstShown_) return; | |
121 this.firstShown_ = false; | |
122 | |
123 // Ensure that login is actually visible. | |
124 window.webkitRequestAnimationFrame(function() { | |
125 chrome.send('accountPickerReady'); | |
126 chrome.send('loginVisible', ['account-picker']); | |
127 }); | |
128 }, | |
129 | |
130 /** | |
131 * Event handler that is invoked just before the frame is hidden. | |
132 */ | |
133 onBeforeHide: function() { | |
134 chrome.send('loginUIStateChanged', ['account-picker', false]); | |
135 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.HIDDEN; | |
136 $('pod-row').handleHide(); | |
137 }, | |
138 | |
139 /** | |
140 * Shows sign-in error bubble. | |
141 * @param {number} loginAttempts Number of login attemps tried. | |
142 * @param {HTMLElement} content Content to show in bubble. | |
143 */ | |
144 showErrorBubble: function(loginAttempts, error) { | |
145 var activatedPod = $('pod-row').activatedPod; | |
146 if (!activatedPod) { | |
147 $('bubble').showContentForElement($('pod-row'), | |
148 cr.ui.Bubble.Attachment.RIGHT, | |
149 error); | |
150 return; | |
151 } | |
152 // Show web authentication if this is not a locally managed user. | |
153 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD && | |
154 !activatedPod.user.locallyManagedUser) { | |
155 activatedPod.showSigninUI(); | |
156 } else { | |
157 // We want bubble's arrow to point to the first letter of input. | |
158 /** @const */ var BUBBLE_OFFSET = 7; | |
159 /** @const */ var BUBBLE_PADDING = 4; | |
160 $('bubble').showContentForElement(activatedPod.mainInput, | |
161 cr.ui.Bubble.Attachment.BOTTOM, | |
162 error, | |
163 BUBBLE_OFFSET, BUBBLE_PADDING); | |
164 } | |
165 }, | |
166 | |
167 /** | |
168 * Loads given users in pod row. | |
169 * @param {array} users Array of user. | |
170 * @param {boolean} showGuest Whether to show guest session button. | |
171 */ | |
172 loadUsers: function(users, showGuest) { | |
173 $('pod-row').loadPods(users); | |
174 $('login-header-bar').showGuestButton = showGuest; | |
175 | |
176 // The desktop User Manager can send the index of a pod that should be | |
177 // initially focused. | |
178 var hash = window.location.hash; | |
179 if (hash) { | |
180 var podIndex = hash.substr(1); | |
181 if (podIndex) | |
182 $('pod-row').focusPodByIndex(podIndex, false); | |
183 } | |
184 }, | |
185 | |
186 /** | |
187 * Runs app with a given id from the list of loaded apps. | |
188 * @param {!string} app_id of an app to run. | |
189 * @param {boolean=} opt_diagnostic_mode Whether to run the app in | |
190 * diagnostic mode. Default is false. | |
191 */ | |
192 runAppForTesting: function(app_id, opt_diagnostic_mode) { | |
193 $('pod-row').findAndRunAppForTesting(app_id, opt_diagnostic_mode); | |
194 }, | |
195 | |
196 /** | |
197 * Adds given apps to the pod row. | |
198 * @param {array} apps Array of apps. | |
199 */ | |
200 setApps: function(apps) { | |
201 $('pod-row').setApps(apps); | |
202 }, | |
203 | |
204 /** | |
205 * Sets the flag of whether app pods should be visible. | |
206 * @param {boolean} shouldShowApps Whether to show app pods. | |
207 */ | |
208 setShouldShowApps: function(shouldShowApps) { | |
209 $('pod-row').setShouldShowApps(shouldShowApps); | |
210 }, | |
211 | |
212 /** | |
213 * Shows the given kiosk app error message. | |
214 * @param {!string} message Error message to show. | |
215 */ | |
216 showAppError: function(message) { | |
217 // TODO(nkostylev): Figure out a way to show kiosk app launch error | |
218 // pointing to the kiosk app pod. | |
219 /** @const */ var BUBBLE_PADDING = 12; | |
220 $('bubble').showTextForElement($('pod-row'), | |
221 message, | |
222 cr.ui.Bubble.Attachment.BOTTOM, | |
223 $('pod-row').offsetWidth / 2, | |
224 BUBBLE_PADDING); | |
225 }, | |
226 | |
227 /** | |
228 * Updates current image of a user. | |
229 * @param {string} username User for which to update the image. | |
230 */ | |
231 updateUserImage: function(username) { | |
232 $('pod-row').updateUserImage(username); | |
233 }, | |
234 | |
235 /** | |
236 * Updates Caps Lock state (for Caps Lock hint in password input field). | |
237 * @param {boolean} enabled Whether Caps Lock is on. | |
238 */ | |
239 setCapsLockState: function(enabled) { | |
240 $('pod-row').classList.toggle('capslock-on', enabled); | |
241 }, | |
242 | |
243 /** | |
244 * Enforces focus on user pod of locked user. | |
245 */ | |
246 forceLockedUserPodFocus: function() { | |
247 var row = $('pod-row'); | |
248 if (row.lockedPod) | |
249 row.focusPod(row.lockedPod, true); | |
250 }, | |
251 | |
252 /** | |
253 * Remove given user from pod row if it is there. | |
254 * @param {string} user name. | |
255 */ | |
256 removeUser: function(username) { | |
257 $('pod-row').removeUserPod(username); | |
258 }, | |
259 | |
260 /** | |
261 * Displays a banner containing |message|. If the banner is already present | |
262 * this function updates the message in the banner. This function is used | |
263 * by the chrome.screenlockPrivate.showMessage API. | |
264 * @param {string} message Text to be displayed | |
265 */ | |
266 showBannerMessage: function(message) { | |
267 var banner = $('signin-banner'); | |
268 banner.textContent = message; | |
269 banner.classList.toggle('message-set', true); | |
270 }, | |
271 | |
272 /** | |
273 * Shows a custom icon in the user pod of |username|. This function | |
274 * is used by the chrome.screenlockPrivate API. | |
275 * @param {string} username Username of pod to add button | |
276 * @param {{scale1x: string, scale2x: string}} icon Dictionary of URLs of | |
277 * the custom icon's representations for 1x and 2x scale factors. | |
278 */ | |
279 showUserPodCustomIcon: function(username, icon) { | |
280 $('pod-row').showUserPodCustomIcon(username, icon); | |
281 }, | |
282 | |
283 /** | |
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 | |
288 */ | |
289 hideUserPodCustomIcon: function(username) { | |
290 $('pod-row').hideUserPodCustomIcon(username); | |
291 }, | |
292 | |
293 /** | |
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. | |
299 */ | |
300 setAuthType: function(username, authType, value) { | |
301 $('pod-row').setAuthType(username, authType, value); | |
302 }, | |
303 | |
304 /** | |
305 * Shows a tooltip bubble explaining Easy Unlock. | |
306 */ | |
307 showEasyUnlockBubble: function() { | |
308 $('pod-row').showEasyUnlockBubble(); | |
309 } | |
310 }; | |
311 }); | |
312 | |
OLD | NEW |