OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Account picker screen implementation. | 6 * @fileoverview Account picker screen implementation. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('login', function() { | 9 cr.define('login', function() { |
10 /** | 10 /** |
11 * Maximum number of offline login failures before online login. | 11 * Maximum number of offline login failures before online login. |
12 */ | 12 */ |
13 const MAX_LOGIN_ATTEMPTS_IN_POD = 3; | 13 /** @const */ var MAX_LOGIN_ATTEMPTS_IN_POD = 3; |
14 | 14 |
15 /** | 15 /** |
16 * Creates a new account picker screen div. | 16 * Creates a new account picker screen div. |
17 * @constructor | 17 * @constructor |
18 * @extends {HTMLDivElement} | 18 * @extends {HTMLDivElement} |
19 */ | 19 */ |
20 var AccountPickerScreen = cr.ui.define('div'); | 20 var AccountPickerScreen = cr.ui.define('div'); |
21 | 21 |
22 /** | 22 /** |
23 * Registers with Oobe. | 23 * Registers with Oobe. |
24 */ | 24 */ |
25 AccountPickerScreen.register = function() { | 25 AccountPickerScreen.register = function() { |
26 var screen = $('account-picker'); | 26 var screen = $('account-picker'); |
27 AccountPickerScreen.decorate(screen); | 27 AccountPickerScreen.decorate(screen); |
28 Oobe.getInstance().registerScreen(screen); | 28 Oobe.getInstance().registerScreen(screen); |
29 }; | 29 }; |
30 | 30 |
31 AccountPickerScreen.prototype = { | 31 AccountPickerScreen.prototype = { |
32 __proto__: HTMLDivElement.prototype, | 32 __proto__: HTMLDivElement.prototype, |
33 | 33 |
34 /** @inheritDoc */ | 34 /** @inheritDoc */ |
35 decorate: function() { | 35 decorate: function() { |
36 login.PodRow.decorate($('pod-row')); | 36 login.PodRow.decorate($('pod-row')); |
37 }, | 37 }, |
38 | 38 |
39 // Whether this screen is shown for the first time. | 39 // Whether this screen is shown for the first time. |
40 firstShown_ : true, | 40 firstShown_: true, |
41 | 41 |
42 /** | 42 /** |
43 * When the account picker is being used to lock the screen, pressing the | 43 * When the account picker is being used to lock the screen, pressing the |
44 * exit accelerator key will sign out the active user as it would when | 44 * exit accelerator key will sign out the active user as it would when |
45 * they are signed in. | 45 * they are signed in. |
46 */ | 46 */ |
47 exit: function() { | 47 exit: function() { |
48 // Check and disable the sign out button so that we can never have two | 48 // Check and disable the sign out button so that we can never have two |
49 // sign out requests generated in a row. | 49 // sign out requests generated in a row. |
50 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) { | 50 if ($('pod-row').lockedPod && !$('sign-out-user-button').disabled) { |
51 $('sign-out-user-button').disabled = true; | 51 $('sign-out-user-button').disabled = true; |
52 chrome.send('signOutUser'); | 52 chrome.send('signOutUser'); |
53 } | 53 } |
54 }, | 54 }, |
55 | 55 |
56 /** | 56 /** |
57 * Event handler that is invoked just before the frame is shown. | 57 * Event handler that is invoked just before the frame is shown. |
58 * @param data {string} Screen init payload. | 58 * @param {string} data Screen init payload. |
59 */ | 59 */ |
60 onBeforeShow: function(data) { | 60 onBeforeShow: function(data) { |
61 chrome.send('hideCaptivePortal'); | 61 chrome.send('hideCaptivePortal'); |
62 var podRow = $('pod-row'); | 62 var podRow = $('pod-row'); |
63 podRow.handleShow(); | 63 podRow.handleShow(); |
64 | 64 |
65 // If this is showing for the lock screen display the sign out button, | 65 // If this is showing for the lock screen display the sign out button, |
66 // hide the add user button and activate the locked user's pod. | 66 // hide the add user button and activate the locked user's pod. |
67 var lockedPod = podRow.lockedPod; | 67 var lockedPod = podRow.lockedPod; |
68 $('add-user-header-bar-item').hidden = !!lockedPod; | 68 $('add-user-header-bar-item').hidden = !!lockedPod; |
69 $('sign-out-user-item').hidden = !lockedPod; | 69 $('sign-out-user-item').hidden = !lockedPod; |
70 if (lockedPod) { | 70 var preselectedPod = lockedPod || podRow.pods[0]; |
Nikita (slow)
2012/06/06 09:40:04
nit: Please add a boolean flag somewhere in here t
Ivan Korotkov
2012/06/06 10:59:24
Done.
| |
71 // TODO(altimofeev): empirically I investigated that focus isn't | 71 // TODO(altimofeev): empirically I investigated that focus isn't |
72 // set correctly if following CSS rules are present: | 72 // set correctly if following CSS rules are present: |
73 // | 73 // |
74 // podrow { | 74 // podrow { |
75 // -webkit-transition: all 200ms ease-in-out; | 75 // -webkit-transition: all 200ms ease-in-out; |
76 // } | 76 // } |
77 // .pod { | 77 // .pod { |
78 // -webkit-transition: all 230ms ease; | 78 // -webkit-transition: all 230ms ease; |
79 // } | 79 // } |
80 // | 80 // |
81 // Workaround is either delete these rules or delay the focus setting. | 81 // Workaround is either delete these rules or delay the focus setting. |
82 var self = this; | 82 var self = this; |
83 lockedPod.addEventListener('webkitTransitionEnd', function f(e) { | 83 preselectedPod.addEventListener('webkitTransitionEnd', function f(e) { |
84 if (e.target == lockedPod) { | 84 if (e.target == preselectedPod) { |
85 podRow.focusPod(lockedPod); | 85 podRow.focusPod(preselectedPod); |
86 lockedPod.removeEventListener(f); | 86 preselectedPod.removeEventListener(f); |
87 // Delay the accountPickerReady signal so that if there are any | 87 // Delay the accountPickerReady signal so that if there are any |
88 // timeouts waiting to fire we can process these first. This was | 88 // timeouts waiting to fire we can process these first. This was |
89 // causing crbug.com/112218 as the account pod was sometimes focuse | 89 // causing crbug.com/112218 as the account pod was sometimes focuse |
90 // using focusPod (which resets the password) after the test code | 90 // using focusPod (which resets the password) after the test code |
91 // set the password. | 91 // set the password. |
92 self.onShow(); | 92 self.onShow(); |
93 } | 93 } |
94 }); | 94 }); |
95 } else { | |
96 this.onShow(); | |
97 } | |
98 }, | 95 }, |
99 | 96 |
100 /** | 97 /** |
101 * Event handler invoked when the page is shown and ready. | 98 * Event handler invoked when the page is shown and ready. |
102 */ | 99 */ |
103 onShow: function() { | 100 onShow: function() { |
104 if (!this.firstShown_) return; | 101 if (!this.firstShown_) return; |
105 this.firstShown_ = false; | 102 this.firstShown_ = false; |
106 // TODO(nkostylev): Enable animation back when session start jank | 103 // TODO(nkostylev): Enable animation back when session start jank |
107 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307 | 104 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307 |
108 // $('pod-row').startInitAnimation(); | 105 // $('pod-row').startInitAnimation(); |
109 | 106 |
110 // TODO(altimofeev): Call it after animation has stoped when animation | 107 // TODO(altimofeev): Call it after animation has stoped when animation |
111 // is enabled. | 108 // is enabled. |
112 chrome.send('accountPickerReady'); | 109 chrome.send('accountPickerReady'); |
113 }, | 110 }, |
114 | 111 |
115 /** | 112 /** |
116 * Event handler that is invoked just before the frame is hidden. | 113 * Event handler that is invoked just before the frame is hidden. |
117 * @param data {string} Screen init payload. | 114 * @param {string} data Screen init payload. |
118 */ | 115 */ |
119 onBeforeHide: function(data) { | 116 onBeforeHide: function(data) { |
120 $('pod-row').handleHide(); | 117 $('pod-row').handleHide(); |
121 }, | 118 }, |
122 | 119 |
123 /** | 120 /** |
124 * Shows sign-in error bubble. | 121 * Shows sign-in error bubble. |
125 * @param {number} loginAttempts Number of login attemps tried. | 122 * @param {number} loginAttempts Number of login attemps tried. |
126 * @param {HTMLElement} content Content to show in bubble. | 123 * @param {HTMLElement} content Content to show in bubble. |
127 */ | 124 */ |
128 showErrorBubble: function(loginAttempts, error) { | 125 showErrorBubble: function(loginAttempts, error) { |
129 var activatedPod = $('pod-row').activatedPod; | 126 var activatedPod = $('pod-row').activatedPod; |
130 if (!activatedPod) | 127 if (!activatedPod) |
131 return; | 128 return; |
132 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD) { | 129 if (loginAttempts > MAX_LOGIN_ATTEMPTS_IN_POD) { |
133 activatedPod.showSigninUI(); | 130 activatedPod.showSigninUI(); |
134 } else { | 131 } else { |
135 $('bubble').showContentForElement(activatedPod.mainInput, error, | 132 $('bubble').showContentForElement(activatedPod.mainInput, error, |
136 cr.ui.Bubble.Attachment.BOTTOM); | 133 cr.ui.Bubble.Attachment.BOTTOM); |
137 } | 134 } |
138 } | 135 } |
139 }; | 136 }; |
140 | 137 |
141 /** | 138 /** |
142 * Loads givens users in pod row. | 139 * Loads givens users in pod row. |
143 * @param {array} users Array of user. | 140 * @param {array} users Array of user. |
144 * @param {boolean} animated Whether to use init animation. | 141 * @param {boolean} animated Whether to use init animation. |
145 * @public | |
146 */ | 142 */ |
147 AccountPickerScreen.loadUsers = function(users, animated) { | 143 AccountPickerScreen.loadUsers = function(users, animated) { |
148 $('pod-row').loadPods(users, animated); | 144 $('pod-row').loadPods(users, animated); |
149 }; | 145 }; |
150 | 146 |
151 /** | 147 /** |
152 * Updates current image of a user. | 148 * Updates current image of a user. |
153 * @param {string} username User for which to update the image. | 149 * @param {string} username User for which to update the image. |
154 * @public | |
155 */ | 150 */ |
156 AccountPickerScreen.updateUserImage = function(username) { | 151 AccountPickerScreen.updateUserImage = function(username) { |
157 $('pod-row').updateUserImage(username); | 152 $('pod-row').updateUserImage(username); |
158 }; | 153 }; |
159 | 154 |
160 /** | 155 /** |
161 * Updates user to use gaia login. | 156 * Updates user to use gaia login. |
162 * @param {string} username User for which to state the state. | 157 * @param {string} username User for which to state the state. |
163 * @public | |
164 */ | 158 */ |
165 AccountPickerScreen.updateUserGaiaNeeded = function(username) { | 159 AccountPickerScreen.updateUserGaiaNeeded = function(username) { |
166 $('pod-row').resetUserOAuthTokenStatus(username); | 160 $('pod-row').resetUserOAuthTokenStatus(username); |
167 }; | 161 }; |
168 | 162 |
169 /** | 163 /** |
170 * Updates Caps Lock state (for Caps Lock hint in password input field). | 164 * Updates Caps Lock state (for Caps Lock hint in password input field). |
171 * @param {boolean} enabled Whether Caps Lock is on. | 165 * @param {boolean} enabled Whether Caps Lock is on. |
172 * @public | |
173 */ | 166 */ |
174 AccountPickerScreen.setCapsLockState = function(enabled) { | 167 AccountPickerScreen.setCapsLockState = function(enabled) { |
175 $('pod-row').classList[enabled ? 'add' : 'remove']('capslock-on'); | 168 $('pod-row').classList[enabled ? 'add' : 'remove']('capslock-on'); |
176 }; | 169 }; |
177 | 170 |
178 return { | 171 return { |
179 AccountPickerScreen: AccountPickerScreen | 172 AccountPickerScreen: AccountPickerScreen |
180 }; | 173 }; |
181 }); | 174 }); |
OLD | NEW |