| 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-setup-pin-dialog' 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 * * <settings-setup-pin-dialog set-modes="[[quickUnlockSetModes]]"> | 10 * * <settings-setup-pin-dialog set-modes="[[quickUnlockSetModes]]"> |
| 11 * </settings-setup-pin-dialog> | 11 * </settings-setup-pin-dialog> |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 (function() { | 14 (function() { |
| 15 'use strict'; | 15 'use strict'; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Keep in sync with the string keys provided by settings. | 18 * Keep in sync with the string keys provided by settings. |
| 19 * @enum {string} | 19 * @enum {string} |
| 20 */ | 20 */ |
| 21 var MessageType = { | 21 var MessageType = { |
| 22 TOO_SHORT: 'configurePinTooShort', | 22 TOO_SHORT: 'configurePinTooShort', |
| 23 TOO_LONG: 'configurePinTooLong', | 23 TOO_LONG: 'configurePinTooLong', |
| 24 TOO_WEAK: 'configurePinWeakPin', | 24 TOO_WEAK: 'configurePinWeakPin', |
| 25 MISMATCH: 'configurePinMismatched' | 25 MISMATCH: 'configurePinMismatched' |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 /** @enum {string} */ | 28 /** @enum {string} */ |
| 29 var ProblemType = { | 29 var ProblemType = {WARNING: 'warning', ERROR: 'error'}; |
| 30 WARNING: 'warning', | |
| 31 ERROR: 'error' | |
| 32 }; | |
| 33 | 30 |
| 34 Polymer({ | 31 Polymer({ |
| 35 is: 'settings-setup-pin-dialog', | 32 is: 'settings-setup-pin-dialog', |
| 36 | 33 |
| 37 behaviors: [I18nBehavior], | 34 behaviors: [I18nBehavior], |
| 38 | 35 |
| 39 properties: { | 36 properties: { |
| 40 /** | 37 /** |
| 41 * The current PIN keyboard value. | 38 * The current PIN keyboard value. |
| 42 * @private | 39 * @private |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 | 65 |
| 69 /** | 66 /** |
| 70 * writeUma_ is a function that handles writing uma stats. It may be | 67 * writeUma_ is a function that handles writing uma stats. It may be |
| 71 * overridden for tests. | 68 * overridden for tests. |
| 72 * | 69 * |
| 73 * @type {Function} | 70 * @type {Function} |
| 74 * @private | 71 * @private |
| 75 */ | 72 */ |
| 76 writeUma_: { | 73 writeUma_: { |
| 77 type: Object, | 74 type: Object, |
| 78 value: function() { return settings.recordLockScreenProgress; } | 75 value: function() { |
| 76 return settings.recordLockScreenProgress; |
| 77 } |
| 79 }, | 78 }, |
| 80 | 79 |
| 81 /** | 80 /** |
| 82 * The current step/subpage we are on. | 81 * The current step/subpage we are on. |
| 83 * @private | 82 * @private |
| 84 */ | 83 */ |
| 85 isConfirmStep_: { | 84 isConfirmStep_: {type: Boolean, value: false}, |
| 86 type: Boolean, | |
| 87 value: false | |
| 88 }, | |
| 89 | 85 |
| 90 /** | 86 /** |
| 91 * Interface for chrome.quickUnlockPrivate calls. May be overriden by tests. | 87 * Interface for chrome.quickUnlockPrivate calls. May be overriden by tests. |
| 92 * @private | 88 * @private |
| 93 */ | 89 */ |
| 94 quickUnlockPrivate_: { | 90 quickUnlockPrivate_: {type: Object, value: chrome.quickUnlockPrivate}, |
| 95 type: Object, | |
| 96 value: chrome.quickUnlockPrivate | |
| 97 }, | |
| 98 }, | 91 }, |
| 99 | 92 |
| 100 /** @override */ | 93 /** @override */ |
| 101 attached: function() { | 94 attached: function() { |
| 102 this.resetState_(); | 95 this.resetState_(); |
| 103 this.$.dialog.showModal(); | 96 this.$.dialog.showModal(); |
| 104 }, | 97 }, |
| 105 | 98 |
| 106 close: function() { | 99 close: function() { |
| 107 if (this.$.dialog.open) | 100 if (this.$.dialog.open) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 * @private | 162 * @private |
| 170 * @param {string} messageId | 163 * @param {string} messageId |
| 171 * @param {string} problemClass | 164 * @param {string} problemClass |
| 172 */ | 165 */ |
| 173 showProblem_: function(messageId, problemClass) { | 166 showProblem_: function(messageId, problemClass) { |
| 174 this.quickUnlockPrivate_.getCredentialRequirements( | 167 this.quickUnlockPrivate_.getCredentialRequirements( |
| 175 chrome.quickUnlockPrivate.QuickUnlockMode.PIN, | 168 chrome.quickUnlockPrivate.QuickUnlockMode.PIN, |
| 176 this.processPinRequirements_.bind(this, messageId)); | 169 this.processPinRequirements_.bind(this, messageId)); |
| 177 this.problemClass_ = problemClass; | 170 this.problemClass_ = problemClass; |
| 178 this.updateStyles(); | 171 this.updateStyles(); |
| 179 this.enableSubmit_ = problemClass != ProblemType.ERROR && | 172 this.enableSubmit_ = |
| 180 messageId != MessageType.MISMATCH; | 173 problemClass != ProblemType.ERROR && messageId != MessageType.MISMATCH; |
| 181 }, | 174 }, |
| 182 | 175 |
| 183 /** @private */ | 176 /** @private */ |
| 184 hideProblem_: function() { | 177 hideProblem_: function() { |
| 185 this.problemMessage_ = ''; | 178 this.problemMessage_ = ''; |
| 186 this.problemClass_ = ''; | 179 this.problemClass_ = ''; |
| 187 }, | 180 }, |
| 188 | 181 |
| 189 /** | 182 /** |
| 190 * Processes the message received from the quick unlock api and hides/shows | 183 * Processes the message received from the quick unlock api and hides/shows |
| 191 * the problem based on the message. | 184 * the problem based on the message. |
| 192 * @private | 185 * @private |
| 193 * @param {chrome.quickUnlockPrivate.CredentialCheck} message The message | 186 * @param {chrome.quickUnlockPrivate.CredentialCheck} message The message |
| 194 * received from checkCredential. | 187 * received from checkCredential. |
| 195 */ | 188 */ |
| 196 processPinProblems_: function(message) { | 189 processPinProblems_: function(message) { |
| 197 if (!message.errors.length && !message.warnings.length) { | 190 if (!message.errors.length && !message.warnings.length) { |
| 198 this.hideProblem_(); | 191 this.hideProblem_(); |
| 199 this.enableSubmit_ = true; | 192 this.enableSubmit_ = true; |
| 200 return; | 193 return; |
| 201 } | 194 } |
| 202 | 195 |
| 203 if (message.warnings.length) { | 196 if (message.warnings.length) { |
| 204 assert(message.warnings[0] == | 197 assert( |
| 198 message.warnings[0] == |
| 205 chrome.quickUnlockPrivate.CredentialProblem.TOO_WEAK); | 199 chrome.quickUnlockPrivate.CredentialProblem.TOO_WEAK); |
| 206 this.showProblem_(MessageType.TOO_WEAK, ProblemType.WARNING); | 200 this.showProblem_(MessageType.TOO_WEAK, ProblemType.WARNING); |
| 207 } | 201 } |
| 208 | 202 |
| 209 if (message.errors.length) { | 203 if (message.errors.length) { |
| 210 switch (message.errors[0]) { | 204 switch (message.errors[0]) { |
| 211 case chrome.quickUnlockPrivate.CredentialProblem.TOO_SHORT: | 205 case chrome.quickUnlockPrivate.CredentialProblem.TOO_SHORT: |
| 212 this.showProblem_(MessageType.TOO_SHORT, ProblemType.ERROR); | 206 this.showProblem_(MessageType.TOO_SHORT, ProblemType.ERROR); |
| 213 break; | 207 break; |
| 214 case chrome.quickUnlockPrivate.CredentialProblem.TOO_LONG: | 208 case chrome.quickUnlockPrivate.CredentialProblem.TOO_LONG: |
| 215 this.showProblem_(MessageType.TOO_LONG, ProblemType.ERROR); | 209 this.showProblem_(MessageType.TOO_LONG, ProblemType.ERROR); |
| 216 break; | 210 break; |
| 217 case chrome.quickUnlockPrivate.CredentialProblem.TOO_WEAK: | 211 case chrome.quickUnlockPrivate.CredentialProblem.TOO_WEAK: |
| 218 this.showProblem_(MessageType.TOO_WEAK, ProblemType.ERROR); | 212 this.showProblem_(MessageType.TOO_WEAK, ProblemType.ERROR); |
| 219 break; | 213 break; |
| 220 default: | 214 default: |
| 221 assertNotReached(); | 215 assertNotReached(); |
| 222 break; | 216 break; |
| 223 } | 217 } |
| 224 } | 218 } |
| 225 | 219 |
| 226 }, | 220 }, |
| 227 | 221 |
| 228 /** @private */ | 222 /** @private */ |
| 229 onPinChange_: function() { | 223 onPinChange_: function() { |
| 230 if (!this.isConfirmStep_) { | 224 if (!this.isConfirmStep_) { |
| 231 if (this.pinKeyboardValue_) { | 225 if (this.pinKeyboardValue_) { |
| 232 this.quickUnlockPrivate_.checkCredential( | 226 this.quickUnlockPrivate_.checkCredential( |
| 233 chrome.quickUnlockPrivate.QuickUnlockMode.PIN, | 227 chrome.quickUnlockPrivate.QuickUnlockMode.PIN, |
| 234 this.pinKeyboardValue_, | 228 this.pinKeyboardValue_, this.processPinProblems_.bind(this)); |
| 235 this.processPinProblems_.bind(this)); | |
| 236 } | 229 } |
| 237 return; | 230 return; |
| 238 } | 231 } |
| 239 | 232 |
| 240 if (this.canSubmit_()) { | 233 if (this.canSubmit_()) { |
| 241 this.hideProblem_(); | 234 this.hideProblem_(); |
| 242 this.enableSubmit_ = true; | 235 this.enableSubmit_ = true; |
| 243 return; | 236 return; |
| 244 } | 237 } |
| 245 | 238 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 269 console.error('Failed to update pin'); | 262 console.error('Failed to update pin'); |
| 270 return; | 263 return; |
| 271 } | 264 } |
| 272 | 265 |
| 273 this.resetState_(); | 266 this.resetState_(); |
| 274 if (this.$.dialog.open) | 267 if (this.$.dialog.open) |
| 275 this.$.dialog.close(); | 268 this.$.dialog.close(); |
| 276 } | 269 } |
| 277 | 270 |
| 278 this.setModes.call( | 271 this.setModes.call( |
| 279 null, | 272 null, [chrome.quickUnlockPrivate.QuickUnlockMode.PIN], |
| 280 [chrome.quickUnlockPrivate.QuickUnlockMode.PIN], | 273 [this.pinKeyboardValue_], onSetModesCompleted.bind(this)); |
| 281 [this.pinKeyboardValue_], | |
| 282 onSetModesCompleted.bind(this)); | |
| 283 this.writeUma_(LockScreenProgress.CONFIRM_PIN); | 274 this.writeUma_(LockScreenProgress.CONFIRM_PIN); |
| 284 }, | 275 }, |
| 285 | 276 |
| 286 /** | 277 /** |
| 287 * @private | 278 * @private |
| 288 * @param {string} problemMessage | 279 * @param {string} problemMessage |
| 289 * @param {string} problemClass | 280 * @param {string} problemClass |
| 290 * @return {boolean} | 281 * @return {boolean} |
| 291 */ | 282 */ |
| 292 hasError_: function(problemMessage, problemClass) { | 283 hasError_: function(problemMessage, problemClass) { |
| 293 return !!problemMessage && problemClass == ProblemType.ERROR; | 284 return !!problemMessage && problemClass == ProblemType.ERROR; |
| 294 }, | 285 }, |
| 295 | 286 |
| 296 /** | 287 /** |
| 297 * @private | 288 * @private |
| 298 * @param {boolean} isConfirmStep | 289 * @param {boolean} isConfirmStep |
| 299 * @return {string} | 290 * @return {string} |
| 300 */ | 291 */ |
| 301 getTitleMessage_: function(isConfirmStep) { | 292 getTitleMessage_: function(isConfirmStep) { |
| 302 return this.i18n(isConfirmStep ? 'configurePinConfirmPinTitle' : | 293 return this.i18n( |
| 303 'configurePinChoosePinTitle'); | 294 isConfirmStep ? 'configurePinConfirmPinTitle' : |
| 295 'configurePinChoosePinTitle'); |
| 304 }, | 296 }, |
| 305 | 297 |
| 306 /** | 298 /** |
| 307 * @private | 299 * @private |
| 308 * @param {boolean} isConfirmStep | 300 * @param {boolean} isConfirmStep |
| 309 * @return {string} | 301 * @return {string} |
| 310 */ | 302 */ |
| 311 getContinueMessage_: function(isConfirmStep) { | 303 getContinueMessage_: function(isConfirmStep) { |
| 312 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); | 304 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); |
| 313 }, | 305 }, |
| 314 }); | 306 }); |
| 315 | 307 |
| 316 })(); | 308 })(); |
| OLD | NEW |