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

Side by Side Diff: chrome/browser/resources/settings/internet_page/network_siminfo.js

Issue 2189523003: MD Settings: Internet: Clean up SIM info and dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_609156_internet_cleanup_4
Patch Set: . 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 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 },
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 */ 131 */
133 sendEnterPin_: function(event) { 132 sendEnterPin_: function(event) {
134 var guid = this.networkProperties && this.networkProperties.GUID; 133 var guid = this.networkProperties && this.networkProperties.GUID;
135 if (!guid) 134 if (!guid)
136 return; 135 return;
137 136
138 var pin = this.$.enterPin.value; 137 var pin = this.$.enterPin.value;
139 if (!this.validatePin_(pin)) 138 if (!this.validatePin_(pin))
140 return; 139 return;
141 140
142 var simState = /** @type {!CrOnc.CellularSimState} */({ 141 var simState = /** @type {!CrOnc.CellularSimState} */ ({
143 currentPin: pin, 142 currentPin: pin,
144 requirePin: this.sendSimLockEnabled_ 143 requirePin: this.sendSimLockEnabled_,
145 }); 144 });
146 this.networkingPrivate.setCellularSimState(guid, simState, function() { 145 this.networkingPrivate.setCellularSimState(guid, simState, function() {
147 if (chrome.runtime.lastError) { 146 if (chrome.runtime.lastError) {
148 this.error = ErrorType.INCORRECT_PIN; 147 this.error = ErrorType.INCORRECT_PIN;
149 } else { 148 } else {
150 this.error = ErrorType.NONE; 149 this.error = ErrorType.NONE;
151 this.$.enterPinDialog.close(); 150 this.$.enterPinDialog.close();
152 } 151 }
153 }.bind(this)); 152 }.bind(this));
154 }, 153 },
(...skipping 29 matching lines...) Expand all
184 */ 183 */
185 sendChangePin_: function(event) { 184 sendChangePin_: function(event) {
186 var guid = this.networkProperties && this.networkProperties.GUID; 185 var guid = this.networkProperties && this.networkProperties.GUID;
187 if (!guid) 186 if (!guid)
188 return; 187 return;
189 188
190 var newPin = this.$.changePinNew1.value; 189 var newPin = this.$.changePinNew1.value;
191 if (!this.validatePin_(newPin, this.$.changePinNew2.value)) 190 if (!this.validatePin_(newPin, this.$.changePinNew2.value))
192 return; 191 return;
193 192
194 var simState = /** @type {!CrOnc.CellularSimState} */({ 193 var simState = /** @type {!CrOnc.CellularSimState} */ ({
195 requirePin: true, 194 requirePin: true,
196 currentPin: this.$.changePinOld.value, 195 currentPin: this.$.changePinOld.value,
197 newPin: newPin 196 newPin: newPin
198 }); 197 });
199 this.networkingPrivate.setCellularSimState(guid, simState, function() { 198 this.networkingPrivate.setCellularSimState(guid, simState, function() {
200 if (chrome.runtime.lastError) { 199 if (chrome.runtime.lastError) {
201 this.error = ErrorType.INCORRECT_PIN; 200 this.error = ErrorType.INCORRECT_PIN;
202 } else { 201 } else {
203 this.error = ErrorType.NONE; 202 this.error = ErrorType.NONE;
204 this.$.changePinDialog.close(); 203 this.$.changePinDialog.close();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return; 285 return;
287 var pin = this.$.unlockPin1.value; 286 var pin = this.$.unlockPin1.value;
288 if (!this.validatePin_(pin, this.$.unlockPin2.value)) 287 if (!this.validatePin_(pin, this.$.unlockPin2.value))
289 return; 288 return;
290 289
291 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() { 290 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() {
292 if (chrome.runtime.lastError) { 291 if (chrome.runtime.lastError) {
293 this.error = ErrorType.INCORRECT_PUK; 292 this.error = ErrorType.INCORRECT_PUK;
294 } else { 293 } else {
295 this.error = ErrorType.NONE; 294 this.error = ErrorType.NONE;
296 this.$.unlockSimDialog.close(); 295 this.$.unlockPukDialog.close();
297 } 296 }
298 }.bind(this)); 297 }.bind(this));
299 }, 298 },
300 299
301 /** 300 /**
302 * @param {!CrOnc.NetworkProperties|undefined} networkProperties 301 * @param {!CrOnc.NetworkProperties|undefined} networkProperties
303 * @return {boolean} True if the Cellular SIM is locked. 302 * @return {boolean}
304 * @private 303 * @private
305 */ 304 */
306 isSimLocked_: function(networkProperties) { 305 showSimLocked_: function(networkProperties) {
307 return !!networkProperties && CrOnc.isSimLocked(networkProperties); 306 if (!networkProperties || !networkProperties.Cellular ||
307 !networkProperties.Cellular.SIMPresent) {
308 return false;
309 }
310 return CrOnc.isSimLocked(networkProperties);
308 }, 311 },
309 312
310 /** 313 /**
311 * @param {!CrOnc.NetworkProperties|undefined} networkProperties 314 * @param {!CrOnc.NetworkProperties|undefined} networkProperties
312 * @return {string} The message for the number of retries left. 315 * @return {boolean}
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) {
dschuyler 2016/07/28 22:12:16 missing @param. (may need to add file to compiled_
stevenjb 2016/07/29 17:48:34 I am going to remove networkProperties from all of
328 return !!error && error != ErrorType.NONE; 331 if (error == ErrorType.NONE)
332 return '';
333 // TODO(stevenjb_: Translate
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
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 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698