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

Side by Side Diff: chrome/browser/resources/settings/people_page/setup_pin_dialog.js

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

Powered by Google App Engine
This is Rietveld 408576698