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