Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 Polymer element for displaying and modifying a list of cellular | 6 * @fileoverview Polymer element for displaying and modifying cellular sim info. |
| 7 * access points. | |
| 8 */ | 7 */ |
| 9 (function() { | 8 (function() { |
| 10 | 9 |
| 11 /** @enum {string} */ | 10 /** @enum {string} */ |
| 12 var ErrorType = { | 11 var ErrorType = { |
| 13 NONE: 'none', | 12 NONE: 'none', |
| 14 INCORRECT_PIN: 'incorrect-pin', | 13 INCORRECT_PIN: 'incorrect-pin', |
| 15 INCORRECT_PUK: 'incorrect-puk', | 14 INCORRECT_PUK: 'incorrect-puk', |
| 16 MISMATCHED_PIN: 'mismatched-pin', | 15 MISMATCHED_PIN: 'mismatched-pin', |
| 17 INVALID_PIN: 'invalid-pin', | 16 INVALID_PIN: 'invalid-pin', |
| 18 INVALID_PUK: 'invalid-puk' | 17 INVALID_PUK: 'invalid-puk' |
| 19 }; | 18 }; |
| 20 | 19 |
| 21 var PIN_MIN_LENGTH = 4; | 20 var PIN_MIN_LENGTH = 4; |
| 22 var PUK_MIN_LENGTH = 8; | 21 var PUK_MIN_LENGTH = 8; |
| 23 | 22 |
| 24 Polymer({ | 23 Polymer({ |
| 25 is: 'network-siminfo', | 24 is: 'network-siminfo', |
| 26 | 25 |
| 27 properties: { | 26 properties: { |
| 28 /** | 27 /** |
| 29 * The network properties associated with the element. | 28 * The network properties associated with the element. |
| 30 * @type {!CrOnc.NetworkProperties|undefined} | 29 * @type {!CrOnc.NetworkProperties|undefined} |
| 31 */ | 30 */ |
| 32 networkProperties: { | 31 networkProperties: { |
| 33 type: Object, | 32 type: Object, |
| 34 observer: 'networkPropertiesChanged_' | 33 observer: 'networkPropertiesChanged_', |
| 35 }, | 34 }, |
| 36 | 35 |
| 37 /** Set to true when a PUK is required to unlock the SIM. */ | 36 /** Set to true when a PUK is required to unlock the SIM. */ |
| 38 pukRequired: { | 37 pukRequired: { |
| 39 type: Boolean, | 38 type: Boolean, |
| 40 value: false, | 39 value: false, |
| 41 observer: 'pukRequiredChanged_' | 40 observer: 'pukRequiredChanged_', |
| 42 }, | 41 }, |
| 43 | 42 |
| 44 /** | 43 /** |
| 45 * Set to an ErrorType value after an incorrect PIN or PUK entry. | 44 * Set to an ErrorType value after an incorrect PIN or PUK entry. |
| 46 * @type {ErrorType} | 45 * @type {ErrorType} |
| 47 */ | 46 */ |
| 48 error: { | 47 error: { |
| 49 type: Object, | 48 type: Object, |
| 50 value: ErrorType.NONE | 49 value: ErrorType.NONE, |
| 51 }, | 50 }, |
| 52 | 51 |
| 53 /** | 52 /** |
| 54 * Interface for networkingPrivate calls, passed from internet_page. | 53 * Interface for networkingPrivate calls, passed from internet_page. |
| 55 * @type {NetworkingPrivate} | 54 * @type {NetworkingPrivate} |
| 56 */ | 55 */ |
| 57 networkingPrivate: { | 56 networkingPrivate: { |
| 58 type: Object, | 57 type: Object, |
| 59 }, | 58 }, |
| 60 }, | 59 }, |
| 61 | 60 |
| 62 sendSimLockEnabled_: false, | 61 sendSimLockEnabled_: false, |
| 63 | 62 |
| 64 /** Polymer networkProperties changed method. */ | |
| 65 networkPropertiesChanged_: function() { | 63 networkPropertiesChanged_: function() { |
| 66 if (!this.networkProperties || !this.networkProperties.Cellular) | 64 if (!this.networkProperties || !this.networkProperties.Cellular) |
| 67 return; | 65 return; |
| 68 var simLockStatus = this.networkProperties.Cellular.SIMLockStatus; | 66 var simLockStatus = this.networkProperties.Cellular.SIMLockStatus; |
| 69 this.pukRequired = | 67 this.pukRequired = |
| 70 !!simLockStatus && simLockStatus.LockType == CrOnc.LockType.PUK; | 68 !!simLockStatus && simLockStatus.LockType == CrOnc.LockType.PUK; |
| 71 }, | 69 }, |
| 72 | 70 |
| 73 /** Polymer networkProperties changed method. */ | |
| 74 pukRequiredChanged_: function() { | 71 pukRequiredChanged_: function() { |
| 75 if (this.$.unlockPukDialog.opened) { | 72 if (this.$.unlockPukDialog.opened) { |
| 76 if (this.pukRequired) | 73 if (this.pukRequired) |
| 77 this.$.unlockPuk.focus(); | 74 this.$.unlockPuk.focus(); |
| 78 else | 75 else |
| 79 this.$.unlockPukDialog.close(); | 76 this.$.unlockPukDialog.close(); |
| 80 return; | 77 return; |
| 81 } | 78 } |
| 82 | 79 |
| 83 if (!this.pukRequired) | 80 if (!this.pukRequired) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 99 showUnlockPuk = true; | 96 showUnlockPuk = true; |
| 100 } | 97 } |
| 101 if (!showUnlockPuk) | 98 if (!showUnlockPuk) |
| 102 return; | 99 return; |
| 103 | 100 |
| 104 this.error = ErrorType.NONE; | 101 this.error = ErrorType.NONE; |
| 105 this.$.unlockPukDialog.open(); | 102 this.$.unlockPukDialog.open(); |
| 106 this.$.unlockPuk.focus(); | 103 this.$.unlockPuk.focus(); |
| 107 }, | 104 }, |
| 108 | 105 |
| 109 /** Polymer networkProperties changed method. */ | 106 /** |
| 107 * Opens the pin dialog when the sim lock enabled state changes. | |
| 108 * @param {Event} event | |
| 109 * @private | |
| 110 */ | |
| 110 onSimLockEnabledChange_: function(event) { | 111 onSimLockEnabledChange_: function(event) { |
| 111 if (!this.networkProperties || !this.networkProperties.Cellular) | 112 if (!this.networkProperties || !this.networkProperties.Cellular) |
| 112 return; | 113 return; |
| 113 this.sendSimLockEnabled_ = event.target.checked; | 114 this.sendSimLockEnabled_ = event.target.checked; |
| 114 this.error = ErrorType.NONE; | 115 this.error = ErrorType.NONE; |
| 115 this.$.enterPinDialog.open(); | 116 this.$.enterPinDialog.open(); |
| 116 }, | 117 }, |
| 117 | 118 |
| 118 /** | 119 /** |
| 119 * Focuses the correct element when the dialog is opened. | 120 * Focuses the correct element when the dialog is opened. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 132 */ | 133 */ |
| 133 sendEnterPin_: function(event) { | 134 sendEnterPin_: function(event) { |
| 134 var guid = this.networkProperties && this.networkProperties.GUID; | 135 var guid = this.networkProperties && this.networkProperties.GUID; |
| 135 if (!guid) | 136 if (!guid) |
| 136 return; | 137 return; |
| 137 | 138 |
| 138 var pin = this.$.enterPin.value; | 139 var pin = this.$.enterPin.value; |
| 139 if (!this.validatePin_(pin)) | 140 if (!this.validatePin_(pin)) |
| 140 return; | 141 return; |
| 141 | 142 |
| 142 var simState = /** @type {!CrOnc.CellularSimState} */({ | 143 var simState = /** @type {!CrOnc.CellularSimState} */ ({ |
| 143 currentPin: pin, | 144 currentPin: pin, |
| 144 requirePin: this.sendSimLockEnabled_ | 145 requirePin: this.sendSimLockEnabled_, |
| 145 }); | 146 }); |
| 146 this.networkingPrivate.setCellularSimState(guid, simState, function() { | 147 this.networkingPrivate.setCellularSimState(guid, simState, function() { |
| 147 if (chrome.runtime.lastError) { | 148 if (chrome.runtime.lastError) { |
| 148 this.error = ErrorType.INCORRECT_PIN; | 149 this.error = ErrorType.INCORRECT_PIN; |
| 149 } else { | 150 } else { |
| 150 this.error = ErrorType.NONE; | 151 this.error = ErrorType.NONE; |
| 151 this.$.enterPinDialog.close(); | 152 this.$.enterPinDialog.close(); |
| 152 } | 153 } |
| 153 }.bind(this)); | 154 }.bind(this)); |
| 154 }, | 155 }, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 184 */ | 185 */ |
| 185 sendChangePin_: function(event) { | 186 sendChangePin_: function(event) { |
| 186 var guid = this.networkProperties && this.networkProperties.GUID; | 187 var guid = this.networkProperties && this.networkProperties.GUID; |
| 187 if (!guid) | 188 if (!guid) |
| 188 return; | 189 return; |
| 189 | 190 |
| 190 var newPin = this.$.changePinNew1.value; | 191 var newPin = this.$.changePinNew1.value; |
| 191 if (!this.validatePin_(newPin, this.$.changePinNew2.value)) | 192 if (!this.validatePin_(newPin, this.$.changePinNew2.value)) |
| 192 return; | 193 return; |
| 193 | 194 |
| 194 var simState = /** @type {!CrOnc.CellularSimState} */({ | 195 var simState = /** @type {!CrOnc.CellularSimState} */ ({ |
| 195 requirePin: true, | 196 requirePin: true, |
| 196 currentPin: this.$.changePinOld.value, | 197 currentPin: this.$.changePinOld.value, |
| 197 newPin: newPin | 198 newPin: newPin |
| 198 }); | 199 }); |
| 199 this.networkingPrivate.setCellularSimState(guid, simState, function() { | 200 this.networkingPrivate.setCellularSimState(guid, simState, function() { |
| 200 if (chrome.runtime.lastError) { | 201 if (chrome.runtime.lastError) { |
| 201 this.error = ErrorType.INCORRECT_PIN; | 202 this.error = ErrorType.INCORRECT_PIN; |
| 202 } else { | 203 } else { |
| 203 this.error = ErrorType.NONE; | 204 this.error = ErrorType.NONE; |
| 204 this.$.changePinDialog.close(); | 205 this.$.changePinDialog.close(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 return; | 287 return; |
| 287 var pin = this.$.unlockPin1.value; | 288 var pin = this.$.unlockPin1.value; |
| 288 if (!this.validatePin_(pin, this.$.unlockPin2.value)) | 289 if (!this.validatePin_(pin, this.$.unlockPin2.value)) |
| 289 return; | 290 return; |
| 290 | 291 |
| 291 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() { | 292 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() { |
| 292 if (chrome.runtime.lastError) { | 293 if (chrome.runtime.lastError) { |
| 293 this.error = ErrorType.INCORRECT_PUK; | 294 this.error = ErrorType.INCORRECT_PUK; |
| 294 } else { | 295 } else { |
| 295 this.error = ErrorType.NONE; | 296 this.error = ErrorType.NONE; |
| 296 this.$.unlockSimDialog.close(); | 297 this.$.unlockPukDialog.close(); |
| 297 } | 298 } |
| 298 }.bind(this)); | 299 }.bind(this)); |
| 299 }, | 300 }, |
| 300 | 301 |
| 301 /** | 302 /** |
| 302 * @param {!CrOnc.NetworkProperties|undefined} networkProperties | 303 * @return {boolean} |
| 303 * @return {boolean} True if the Cellular SIM is locked. | |
| 304 * @private | 304 * @private |
| 305 */ | 305 */ |
| 306 isSimLocked_: function(networkProperties) { | 306 showSimLocked_: function(networkProperties) { |
| 307 return !!networkProperties && CrOnc.isSimLocked(networkProperties); | 307 if (!networkProperties || !networkProperties.Cellular || |
| 308 !networkProperties.Cellular.SIMPresent) { | |
| 309 return false; | |
| 310 } | |
| 311 return CrOnc.isSimLocked(networkProperties); | |
| 308 }, | 312 }, |
| 309 | 313 |
| 310 /** | 314 /** |
| 311 * @param {!CrOnc.NetworkProperties|undefined} networkProperties | 315 * @return {boolean} |
| 312 * @return {string} The message for the number of retries left. | |
| 313 * @private | 316 * @private |
| 314 */ | 317 */ |
| 315 getRetriesLeftMsg_: function(networkProperties) { | 318 showSimUnlocked_: function(networkProperties) { |
| 316 var retriesLeft = | 319 if (!networkProperties || !networkProperties.Cellular || |
| 317 this.get('Cellular.SIMLockStatus.RetriesLeft', networkProperties) || 0; | 320 !networkProperties.Cellular.SIMPresent) { |
| 318 // TODO(stevenjb): Localize | 321 return false; |
| 319 return 'Retries left: ' + retriesLeft.toString(); | 322 } |
| 323 return !CrOnc.isSimLocked(networkProperties); | |
| 320 }, | 324 }, |
| 321 | 325 |
| 322 /** | 326 /** |
| 323 * @param {string} error | 327 * @return {string} The error message to display for |error|. |
| 324 * @return {boolean} True if an error message should be shown for |error|. | |
| 325 * @private | 328 * @private |
| 326 */ | 329 */ |
| 327 showError_: function(error) { | 330 getErrorMsg_: function(error, networkProperties) { |
| 328 return !!error && error != ErrorType.NONE; | 331 if (error == ErrorType.NONE) |
| 332 return ''; | |
| 333 // TODO(stevenjb_: Translate | |
|
dschuyler
2016/07/29 19:13:19
// TODO(stevenjb): Translate
changing _ to )
stevenjb
2016/07/30 23:56:32
Done.
| |
| 334 var msg; | |
| 335 if (error == ErrorType.INCORRECT_PIN) | |
| 336 msg = 'Incorrect PIN.'; | |
| 337 else if (error == ErrorType.INCORRECT_PUK) | |
| 338 msg = 'Incorrect PUK.'; | |
| 339 else if (error == ErrorType.MISMATCHED_PIN) | |
| 340 msg = 'PIN values do not match.'; | |
| 341 else if (error == ErrorType.INVALID_PIN) | |
| 342 msg = 'Invalid PIN.'; | |
| 343 else if (error == ErrorType.INVALID_PUK) | |
| 344 msg = 'Invalid PUK.'; | |
| 345 else | |
| 346 return 'UNKNOWN ERROR'; | |
| 347 var retriesLeft = | |
| 348 this.get('Cellular.SIMLockStatus.RetriesLeft', networkProperties) || 0; | |
| 349 msg += ' Retries left: ' + retriesLeft.toString(); | |
| 350 return msg; | |
| 329 }, | 351 }, |
| 330 | 352 |
| 331 /** | 353 /** |
| 332 * @param {string} error | |
| 333 * @return {string} The error message to display for |error|. | |
| 334 * @private | |
| 335 */ | |
| 336 getErrorMsg_: function(error) { | |
| 337 // TODO(stevenjb_: Translate | |
| 338 if (error == ErrorType.INCORRECT_PIN) | |
| 339 return 'Incorrect PIN.'; | |
| 340 if (error == ErrorType.INCORRECT_PUK) | |
| 341 return 'Incorrect PUK.'; | |
| 342 if (error == ErrorType.MISMATCHED_PIN) | |
| 343 return 'PIN values do not match.'; | |
| 344 if (error == ErrorType.INVALID_PIN) | |
| 345 return 'Invalid PIN.'; | |
| 346 if (error == ErrorType.INVALID_PUK) | |
| 347 return 'Invalid PUK.'; | |
| 348 return ''; | |
| 349 }, | |
| 350 | |
| 351 /** | |
| 352 * Checks whether |pin1| is of the proper length and if opt_pin2 is not | 354 * Checks whether |pin1| is of the proper length and if opt_pin2 is not |
| 353 * undefined, whether pin1 and opt_pin2 match. On any failure, sets | 355 * undefined, whether pin1 and opt_pin2 match. On any failure, sets |
| 354 * |this.error| and returns false. | 356 * |this.error| and returns false. |
| 355 * @param {string} pin1 | 357 * @param {string} pin1 |
| 356 * @param {string=} opt_pin2 | 358 * @param {string=} opt_pin2 |
| 357 * @return {boolean} True if the pins match and are of minimum length. | 359 * @return {boolean} True if the pins match and are of minimum length. |
| 358 * @private | 360 * @private |
| 359 */ | 361 */ |
| 360 validatePin_: function(pin1, opt_pin2) { | 362 validatePin_: function(pin1, opt_pin2) { |
| 361 if (pin1.length < PIN_MIN_LENGTH) { | 363 if (pin1.length < PIN_MIN_LENGTH) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 378 */ | 380 */ |
| 379 validatePuk_: function(puk) { | 381 validatePuk_: function(puk) { |
| 380 if (puk.length < PUK_MIN_LENGTH) { | 382 if (puk.length < PUK_MIN_LENGTH) { |
| 381 this.error = ErrorType.INVALID_PUK; | 383 this.error = ErrorType.INVALID_PUK; |
| 382 return false; | 384 return false; |
| 383 } | 385 } |
| 384 return true; | 386 return true; |
| 385 } | 387 } |
| 386 }); | 388 }); |
| 387 })(); | 389 })(); |
| OLD | NEW |