OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | 6 * @fileoverview |
7 * 'settings-quick-unlock-setup-pin' is the settings page for choosing a PIN. | 7 * 'settings-setup-pin-dialog' is the settings page for choosing a PIN. |
8 * | 8 * |
9 * Example: | 9 * Example: |
10 * | 10 * |
11 * <settings-quick-unlock-setup-pin | 11 * <settings-setup-pin-dialog |
12 * set-modes="[[quickUnlockSetModes]]" | 12 * set-modes="[[quickUnlockSetModes]]" |
tommycli
2016/08/05 17:46:20
fold into above line and add ">" ending char
jdufault
2016/08/05 20:59:52
Done.
| |
13 * current-route="{{currentRoute}}"> | 13 * </settings-setup-pin-dialog> |
14 * </settings-quick-unlock-setup-pin> | |
15 */ | 14 */ |
16 | 15 |
17 (function() { | 16 (function() { |
18 'use strict'; | 17 'use strict'; |
19 | 18 |
20 /** | 19 /** |
21 * Metainformation about a problem message to pass to showProblem. |class| is | |
22 * the css class to show the problem message with. |messageId| is the i18n | |
23 * string id to use. | |
24 * @const | |
25 */ | |
26 var ProblemInfo = { | |
27 TOO_SHORT: { | |
28 messageId: 'quickUnlockConfigurePinChoosePinTooShort', | |
29 class: 'error' | |
30 }, | |
31 WEAK: { | |
32 messageId: 'quickUnlockConfigurePinChoosePinWeakPinWarning', | |
33 class: 'warning' | |
34 }, | |
35 MISMATCHED: { | |
36 messageId: 'quickUnlockConfigurePinMismatchedPins', | |
37 class: 'error' | |
38 } | |
39 }; | |
40 | |
41 /** | |
42 * A list of the top-10 most commmonly used PINs. This list is taken from | 20 * A list of the top-10 most commmonly used PINs. This list is taken from |
43 * www.datagenetics.com/blog/september32012/. | 21 * www.datagenetics.com/blog/september32012/. |
44 * @const | 22 * @const |
45 */ | 23 */ |
46 var WEAK_PINS = [ | 24 var WEAK_PINS = [ |
47 '1234', '1111', '0000', '1212', '7777', '1004', '2000', '4444', '2222', | 25 '1234', '1111', '0000', '1212', '7777', '1004', '2000', '4444', '2222', |
48 '6969' | 26 '6969' |
49 ]; | 27 ]; |
50 | 28 |
51 Polymer({ | 29 Polymer({ |
52 is: 'settings-quick-unlock-setup-pin', | 30 is: 'settings-setup-pin-dialog', |
53 | 31 |
54 behaviors: [I18nBehavior, QuickUnlockPasswordDetectBehavior], | 32 behaviors: [I18nBehavior], |
55 | 33 |
56 properties: { | 34 properties: { |
57 /** @type {!settings.Route} */ | |
58 currentRoute: { | |
59 type: Object, | |
60 observer: 'onRouteChanged_', | |
61 }, | |
62 | |
63 /** | 35 /** |
64 * The current PIN keyboard value. | 36 * The current PIN keyboard value. |
65 * @private | 37 * @private |
66 */ | 38 */ |
67 pinKeyboardValue_: String, | 39 pinKeyboardValue_: String, |
68 | 40 |
69 /** | 41 /** |
70 * Stores the initial PIN value so it can be confirmed. | 42 * Stores the initial PIN value so it can be confirmed. |
71 * @private | 43 * @private |
72 */ | 44 */ |
(...skipping 19 matching lines...) Expand all Loading... | |
92 /** | 64 /** |
93 * The current step/subpage we are on. | 65 * The current step/subpage we are on. |
94 * @private | 66 * @private |
95 */ | 67 */ |
96 isConfirmStep_: { | 68 isConfirmStep_: { |
97 type: Boolean, | 69 type: Boolean, |
98 value: false | 70 value: false |
99 }, | 71 }, |
100 }, | 72 }, |
101 | 73 |
102 observers: ['onSetModesChanged_(setModes)'], | |
103 | |
104 /** @override */ | 74 /** @override */ |
105 attached: function() { | 75 attached: function() { |
106 this.resetState_(); | 76 this.resetState_(); |
107 | |
108 if (this.currentRoute == settings.Route.QUICK_UNLOCK_SETUP_PIN) | |
109 this.askForPasswordIfUnset(); | |
110 }, | 77 }, |
111 | 78 |
112 /** | 79 open: function() { |
113 * @param {!settings.Route} currentRoute | 80 this.$.dialog.showModal(); |
114 * @private | 81 this.$.pinKeyboard.focus(); |
115 */ | |
116 onRouteChanged_: function(currentRoute) { | |
117 if (this.currentRoute == settings.Route.QUICK_UNLOCK_SETUP_PIN) { | |
118 this.askForPasswordIfUnset(); | |
119 } else { | |
120 // If the user hits the back button, they can leave the element | |
121 // half-completed; therefore, reset state if the element is not active. | |
122 this.resetState_(); | |
123 } | |
124 }, | 82 }, |
125 | 83 |
126 /** @private */ | 84 close: function() { |
127 onSetModesChanged_: function() { | 85 if (this.$.dialog.open) |
128 if (this.currentRoute == settings.Route.QUICK_UNLOCK_SETUP_PIN) | 86 this.$.dialog.close(); |
129 this.askForPasswordIfUnset(); | |
130 }, | 87 }, |
131 | 88 |
89 // TODO(jdufault): Make sure we reset flow if half-completed. | |
tommycli
2016/08/05 17:46:20
?
jdufault
2016/08/05 20:59:52
Fixed the bug and removed the TODO.
| |
90 | |
132 /** | 91 /** |
133 * Resets the element to the initial state. | 92 * Resets the element to the initial state. |
134 * @private | 93 * @private |
135 */ | 94 */ |
136 resetState_: function() { | 95 resetState_: function() { |
137 this.initialPin_ = ''; | 96 this.initialPin_ = ''; |
138 this.pinKeyboardValue_ = ''; | 97 this.pinKeyboardValue_ = ''; |
139 this.enableSubmit_ = false; | 98 this.enableSubmit_ = false; |
140 this.isConfirmStep_ = false; | 99 this.isConfirmStep_ = false; |
141 this.onPinChange_(); | 100 this.onPinChange_(); |
142 }, | 101 }, |
143 | 102 |
103 /** @private */ | |
104 onCancelTap_: function() { | |
105 this.resetState_(); | |
106 this.$.dialog.cancel(); | |
107 }, | |
108 | |
144 /** | 109 /** |
145 * Returns true if the given PIN is likely easy to guess. | 110 * Returns true if the given PIN is likely easy to guess. |
146 * @private | 111 * @private |
147 * @param {string} pin | 112 * @param {string} pin |
148 * @return {boolean} | 113 * @return {boolean} |
149 */ | 114 */ |
150 isPinWeak_: function(pin) { | 115 isPinWeak_: function(pin) { |
151 // Warn if it's a top-10 pin. | 116 // Warn if it's a top-10 pin. |
152 if (WEAK_PINS.includes(pin)) | 117 if (WEAK_PINS.includes(pin)) |
153 return true; | 118 return true; |
(...skipping 28 matching lines...) Expand all Loading... | |
182 * @return {boolean} | 147 * @return {boolean} |
183 */ | 148 */ |
184 canSubmit_: function() { | 149 canSubmit_: function() { |
185 return this.isPinLongEnough_(this.pinKeyboardValue_) && | 150 return this.isPinLongEnough_(this.pinKeyboardValue_) && |
186 this.initialPin_ == this.pinKeyboardValue_; | 151 this.initialPin_ == this.pinKeyboardValue_; |
187 }, | 152 }, |
188 | 153 |
189 /** | 154 /** |
190 * Notify the user about a problem. | 155 * Notify the user about a problem. |
191 * @private | 156 * @private |
192 * @param {!{messageId: string, class: string}} problemInfo | 157 * @param {string} messageId |
158 * @param {string} problemClass | |
193 */ | 159 */ |
194 showProblem_: function(problemInfo) { | 160 showProblem_: function(messageId, problemClass) { |
195 this.problemMessage_ = this.i18n(problemInfo.messageId); | 161 this.problemMessage_ = this.i18n(messageId); |
196 this.problemClass_ = problemInfo.class; | 162 this.problemClass_ = problemClass; |
197 this.updateStyles(); | 163 this.updateStyles(); |
198 }, | 164 }, |
199 | 165 |
200 /** @private */ | 166 /** @private */ |
201 hideProblem_: function() { | 167 hideProblem_: function() { |
202 this.problemMessage_ = ''; | 168 this.problemMessage_ = ''; |
203 this.problemClass_ = ''; | 169 this.problemClass_ = ''; |
204 }, | 170 }, |
205 | 171 |
206 /** @private */ | 172 /** @private */ |
207 onPinChange_: function() { | 173 onPinChange_: function() { |
208 if (!this.isConfirmStep_) { | 174 if (!this.isConfirmStep_) { |
209 var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_); | 175 var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_); |
210 var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_); | 176 var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_); |
211 | 177 |
212 if (!isPinLongEnough && this.pinKeyboardValue_) | 178 if (!isPinLongEnough && this.pinKeyboardValue_) |
213 this.showProblem_(ProblemInfo.TOO_SHORT); | 179 this.showProblem_('configurePinTooShort', 'error'); |
214 else if (isWeak) | 180 else if (isWeak) |
215 this.showProblem_(ProblemInfo.WEAK); | 181 this.showProblem_('configurePinWeakPin', 'warning'); |
216 else | 182 else |
217 this.hideProblem_(); | 183 this.hideProblem_(); |
218 | 184 |
219 this.enableSubmit_ = isPinLongEnough; | 185 this.enableSubmit_ = isPinLongEnough; |
220 | 186 |
221 } else { | 187 } else { |
222 var canSubmit = this.canSubmit_(); | 188 var canSubmit = this.canSubmit_(); |
223 | 189 |
224 if (!canSubmit && this.pinKeyboardValue_) | 190 if (!canSubmit && this.pinKeyboardValue_) |
225 this.showProblem_(ProblemInfo.MISMATCHED); | 191 this.showProblem_('configurePinMismatched', 'error'); |
226 else | 192 else |
227 this.hideProblem_(); | 193 this.hideProblem_(); |
228 | 194 |
229 this.enableSubmit_ = canSubmit; | 195 this.enableSubmit_ = canSubmit; |
230 } | 196 } |
231 }, | 197 }, |
232 | 198 |
233 /** @private */ | 199 /** @private */ |
234 onPinSubmit_: function() { | 200 onPinSubmit_: function() { |
235 if (!this.isConfirmStep_) { | 201 if (!this.isConfirmStep_) { |
236 if (this.isPinLongEnough_(this.pinKeyboardValue_)) { | 202 if (this.isPinLongEnough_(this.pinKeyboardValue_)) { |
237 this.initialPin_ = this.pinKeyboardValue_; | 203 this.initialPin_ = this.pinKeyboardValue_; |
238 this.pinKeyboardValue_ = ''; | 204 this.pinKeyboardValue_ = ''; |
239 this.isConfirmStep_ = true; | 205 this.isConfirmStep_ = true; |
240 this.onPinChange_(); | 206 this.onPinChange_(); |
241 } | 207 } |
242 } else { | 208 } else { |
243 // onPinSubmit_ gets called if the user hits enter on the PIN keyboard. | 209 // onPinSubmit_ gets called if the user hits enter on the PIN keyboard. |
244 // The PIN is not guaranteed to be valid in that case. | 210 // The PIN is not guaranteed to be valid in that case. |
245 if (!this.canSubmit_()) | 211 if (!this.canSubmit_()) |
246 return; | 212 return; |
247 | 213 |
248 function onSetModesCompleted(didSet) { | 214 function onSetModesCompleted(didSet) { |
249 if (!didSet) { | 215 if (!didSet) { |
250 console.error('Failed to update pin'); | 216 console.error('Failed to update pin'); |
251 return; | 217 return; |
252 } | 218 } |
253 | 219 |
254 this.resetState_(); | 220 this.resetState_(); |
255 settings.navigateTo(settings.Route.QUICK_UNLOCK_CHOOSE_METHOD); | 221 this.fire('done'); |
256 } | 222 } |
257 | 223 |
258 this.setModes.call( | 224 this.setModes.call( |
259 null, | 225 null, |
260 [chrome.quickUnlockPrivate.QuickUnlockMode.PIN], | 226 [chrome.quickUnlockPrivate.QuickUnlockMode.PIN], |
261 [this.pinKeyboardValue_], | 227 [this.pinKeyboardValue_], |
262 onSetModesCompleted.bind(this)); | 228 onSetModesCompleted.bind(this)); |
263 } | 229 } |
264 }, | 230 }, |
265 | 231 |
266 /** | 232 /** |
267 * @private | 233 * @private |
268 * @param {string} problemMessage | 234 * @param {string} problemMessage |
269 * @return {boolean} | 235 * @return {boolean} |
270 */ | 236 */ |
271 hasProblem_: function(problemMessage) { | 237 hasProblem_: function(problemMessage) { |
272 return !!problemMessage; | 238 return !!problemMessage; |
273 }, | 239 }, |
274 | 240 |
275 /** | 241 /** |
276 * @private | 242 * @private |
277 * @param {boolean} isConfirmStep | 243 * @param {boolean} isConfirmStep |
278 * @return {string} | 244 * @return {string} |
279 */ | 245 */ |
280 getTitleMessage_: function(isConfirmStep) { | 246 getTitleMessage_: function(isConfirmStep) { |
281 if (!isConfirmStep) | 247 if (!isConfirmStep) |
tommycli
2016/08/05 17:46:20
Ternary expression?
jdufault
2016/08/05 20:59:52
Done.
| |
282 return this.i18n('quickUnlockConfigurePinChoosePinTitle'); | 248 return this.i18n('configurePinChoosePinTitle'); |
283 return this.i18n('quickUnlockConfigurePinConfirmPinTitle'); | 249 return this.i18n('configurePinConfirmPinTitle'); |
284 }, | 250 }, |
285 | 251 |
286 /** | 252 /** |
287 * @private | 253 * @private |
288 * @param {boolean} isConfirmStep | 254 * @param {boolean} isConfirmStep |
289 * @return {string} | 255 * @return {string} |
290 */ | 256 */ |
291 getContinueMessage_: function(isConfirmStep) { | 257 getContinueMessage_: function(isConfirmStep) { |
292 if (!isConfirmStep) | 258 if (!isConfirmStep) |
tommycli
2016/08/05 17:46:20
Ternary expression?
jdufault
2016/08/05 20:59:52
Done.
| |
293 return this.i18n('quickUnlockConfigurePinContinueButton'); | 259 return this.i18n('configurePinContinueButton'); |
294 return this.i18n('save'); | 260 return this.i18n('confirm'); |
295 }, | 261 }, |
296 }); | 262 }); |
297 | 263 |
298 })(); | 264 })(); |
OLD | NEW |