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

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

Issue 2300783002: MD Settings: Internet: Cleanup JS (Closed)
Patch Set: Feedback Created 4 years, 3 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 cellular sim info. 6 * @fileoverview Polymer element for displaying and modifying cellular sim info.
7 */ 7 */
8 (function() { 8 (function() {
9 9
10 /** @enum {string} */ 10 /** @enum {string} */
(...skipping 15 matching lines...) Expand all
26 properties: { 26 properties: {
27 /** 27 /**
28 * The network properties associated with the element. 28 * The network properties associated with the element.
29 * @type {!CrOnc.NetworkProperties|undefined} 29 * @type {!CrOnc.NetworkProperties|undefined}
30 */ 30 */
31 networkProperties: { 31 networkProperties: {
32 type: Object, 32 type: Object,
33 observer: 'networkPropertiesChanged_', 33 observer: 'networkPropertiesChanged_',
34 }, 34 },
35 35
36 /** Set to true when a PUK is required to unlock the SIM. */ 36 /**
37 pukRequired: { 37 * Interface for networkingPrivate calls, passed from internet_page.
38 * @type {NetworkingPrivate}
39 */
40 networkingPrivate: Object,
41
42 /**
43 * Set to true when a PUK is required to unlock the SIM.
44 * @private
45 */
46 pukRequired_: {
38 type: Boolean, 47 type: Boolean,
39 value: false, 48 value: false,
40 observer: 'pukRequiredChanged_', 49 observer: 'pukRequiredChanged_',
41 }, 50 },
42 51
43 /** 52 /**
44 * Set to an ErrorType value after an incorrect PIN or PUK entry. 53 * Set to an ErrorType value after an incorrect PIN or PUK entry.
45 * @type {ErrorType} 54 * @private {ErrorType}
46 */ 55 */
47 error: { 56 error_: {
48 type: Object, 57 type: Object,
49 value: ErrorType.NONE, 58 value: ErrorType.NONE,
50 }, 59 },
51
52 /**
53 * Interface for networkingPrivate calls, passed from internet_page.
54 * @type {NetworkingPrivate}
55 */
56 networkingPrivate: {
57 type: Object,
58 },
59 }, 60 },
60 61
61 sendSimLockEnabled_: false, 62 sendSimLockEnabled_: false,
62 63
63 networkPropertiesChanged_: function() { 64 networkPropertiesChanged_: function() {
64 if (!this.networkProperties || !this.networkProperties.Cellular) 65 if (!this.networkProperties || !this.networkProperties.Cellular)
65 return; 66 return;
66 var simLockStatus = this.networkProperties.Cellular.SIMLockStatus; 67 var simLockStatus = this.networkProperties.Cellular.SIMLockStatus;
67 this.pukRequired = 68 this.pukRequired_ =
68 !!simLockStatus && simLockStatus.LockType == CrOnc.LockType.PUK; 69 !!simLockStatus && simLockStatus.LockType == CrOnc.LockType.PUK;
69 }, 70 },
70 71
71 pukRequiredChanged_: function() { 72 pukRequiredChanged_: function() {
72 if (this.$.unlockPukDialog.open) { 73 if (this.$.unlockPukDialog.open) {
73 if (this.pukRequired) 74 if (this.pukRequired_)
74 this.$.unlockPuk.focus(); 75 this.$.unlockPuk.focus();
75 else 76 else
76 this.$.unlockPukDialog.close(); 77 this.$.unlockPukDialog.close();
77 return; 78 return;
78 } 79 }
79 80
80 if (!this.pukRequired) 81 if (!this.pukRequired_)
81 return; 82 return;
82 83
83 // If the PUK was activated while attempting to enter or change a pin, 84 // If the PUK was activated while attempting to enter or change a pin,
84 // close the dialog and open the unlock PUK dialog. 85 // close the dialog and open the unlock PUK dialog.
85 var showUnlockPuk = false; 86 var showUnlockPuk = false;
86 if (this.$.enterPinDialog.open) { 87 if (this.$.enterPinDialog.open) {
87 this.$.enterPinDialog.close(); 88 this.$.enterPinDialog.close();
88 showUnlockPuk = true; 89 showUnlockPuk = true;
89 } 90 }
90 if (this.$.changePinDialog.open) { 91 if (this.$.changePinDialog.open) {
91 this.$.changePinDialog.close(); 92 this.$.changePinDialog.close();
92 showUnlockPuk = true; 93 showUnlockPuk = true;
93 } 94 }
94 if (this.$.unlockPinDialog.open) { 95 if (this.$.unlockPinDialog.open) {
95 this.$.unlockPinDialog.close(); 96 this.$.unlockPinDialog.close();
96 showUnlockPuk = true; 97 showUnlockPuk = true;
97 } 98 }
98 if (!showUnlockPuk) 99 if (!showUnlockPuk)
99 return; 100 return;
100 101
101 this.error = ErrorType.NONE; 102 this.error_ = ErrorType.NONE;
102 this.$.unlockPukDialog.showModal(); 103 this.$.unlockPukDialog.showModal();
103 }, 104 },
104 105
105 /** 106 /**
106 * Opens the pin dialog when the sim lock enabled state changes. 107 * Opens the pin dialog when the sim lock enabled state changes.
107 * @param {Event} event 108 * @param {Event} event
108 * @private 109 * @private
109 */ 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.showModal(); 116 this.$.enterPinDialog.showModal();
116 this.$.enterPin.value = ''; 117 this.$.enterPin.value = '';
117 }, 118 },
118 119
119 /** 120 /**
120 * Sends the PIN value from the Enter PIN dialog. 121 * Sends the PIN value from the Enter PIN dialog.
121 * @param {Event} event 122 * @param {Event} event
122 * @private 123 * @private
123 */ 124 */
124 sendEnterPin_: function(event) { 125 sendEnterPin_: function(event) {
125 var guid = this.networkProperties && this.networkProperties.GUID; 126 var guid = this.networkProperties && this.networkProperties.GUID;
126 if (!guid) 127 if (!guid)
127 return; 128 return;
128 129
129 var pin = this.$.enterPin.value; 130 var pin = this.$.enterPin.value;
130 if (!this.validatePin_(pin)) 131 if (!this.validatePin_(pin))
131 return; 132 return;
132 133
133 var simState = /** @type {!CrOnc.CellularSimState} */ ({ 134 var simState = /** @type {!CrOnc.CellularSimState} */ ({
134 currentPin: pin, 135 currentPin: pin,
135 requirePin: this.sendSimLockEnabled_, 136 requirePin: this.sendSimLockEnabled_,
136 }); 137 });
137 this.networkingPrivate.setCellularSimState(guid, simState, function() { 138 this.networkingPrivate.setCellularSimState(guid, simState, function() {
138 if (chrome.runtime.lastError) { 139 if (chrome.runtime.lastError) {
139 this.error = ErrorType.INCORRECT_PIN; 140 this.error_ = ErrorType.INCORRECT_PIN;
140 this.$.enterPin.inputElement.select(); 141 this.$.enterPin.inputElement.select();
141 } else { 142 } else {
142 this.error = ErrorType.NONE; 143 this.error_ = ErrorType.NONE;
143 this.$.enterPinDialog.close(); 144 this.$.enterPinDialog.close();
144 } 145 }
145 }.bind(this)); 146 }.bind(this));
146 }, 147 },
147 148
148 /** 149 /**
149 * Opens the Change PIN dialog. 150 * Opens the Change PIN dialog.
150 * @param {Event} event 151 * @param {Event} event
151 * @private 152 * @private
152 */ 153 */
153 onChangePinTap_: function(event) { 154 onChangePinTap_: function(event) {
154 if (!this.networkProperties || !this.networkProperties.Cellular) 155 if (!this.networkProperties || !this.networkProperties.Cellular)
155 return; 156 return;
156 this.error = ErrorType.NONE; 157 this.error_ = ErrorType.NONE;
157 this.$.changePinDialog.showModal(); 158 this.$.changePinDialog.showModal();
158 this.$.changePinOld.value = ''; 159 this.$.changePinOld.value = '';
159 this.$.changePinNew1.value = ''; 160 this.$.changePinNew1.value = '';
160 this.$.changePinNew2.value = ''; 161 this.$.changePinNew2.value = '';
161 }, 162 },
162 163
163 /** 164 /**
164 * Sends the old and new PIN values from the Change PIN dialog. 165 * Sends the old and new PIN values from the Change PIN dialog.
165 * @param {Event} event 166 * @param {Event} event
166 * @private 167 * @private
167 */ 168 */
168 sendChangePin_: function(event) { 169 sendChangePin_: function(event) {
169 var guid = this.networkProperties && this.networkProperties.GUID; 170 var guid = this.networkProperties && this.networkProperties.GUID;
170 if (!guid) 171 if (!guid)
171 return; 172 return;
172 173
173 var newPin = this.$.changePinNew1.value; 174 var newPin = this.$.changePinNew1.value;
174 if (!this.validatePin_(newPin, this.$.changePinNew2.value)) 175 if (!this.validatePin_(newPin, this.$.changePinNew2.value))
175 return; 176 return;
176 177
177 var simState = /** @type {!CrOnc.CellularSimState} */ ({ 178 var simState = /** @type {!CrOnc.CellularSimState} */ ({
178 requirePin: true, 179 requirePin: true,
179 currentPin: this.$.changePinOld.value, 180 currentPin: this.$.changePinOld.value,
180 newPin: newPin 181 newPin: newPin
181 }); 182 });
182 this.networkingPrivate.setCellularSimState(guid, simState, function() { 183 this.networkingPrivate.setCellularSimState(guid, simState, function() {
183 if (chrome.runtime.lastError) { 184 if (chrome.runtime.lastError) {
184 this.error = ErrorType.INCORRECT_PIN; 185 this.error_ = ErrorType.INCORRECT_PIN;
185 this.$.changePinOld.inputElement.select(); 186 this.$.changePinOld.inputElement.select();
186 } else { 187 } else {
187 this.error = ErrorType.NONE; 188 this.error_ = ErrorType.NONE;
188 this.$.changePinDialog.close(); 189 this.$.changePinDialog.close();
189 } 190 }
190 }.bind(this)); 191 }.bind(this));
191 }, 192 },
192 193
193 /** 194 /**
194 * Opens the Unlock PIN dialog. 195 * Opens the Unlock PIN dialog.
195 * @param {Event} event 196 * @param {Event} event
196 * @private 197 * @private
197 */ 198 */
198 onUnlockPinTap_: function(event) { 199 onUnlockPinTap_: function(event) {
199 this.error = ErrorType.NONE; 200 this.error_ = ErrorType.NONE;
200 this.$.unlockPinDialog.showModal(); 201 this.$.unlockPinDialog.showModal();
201 this.$.unlockPin.value = ''; 202 this.$.unlockPin.value = '';
202 }, 203 },
203 204
204 /** 205 /**
205 * Sends the PIN value from the Unlock PIN dialog. 206 * Sends the PIN value from the Unlock PIN dialog.
206 * @param {Event} event 207 * @param {Event} event
207 * @private 208 * @private
208 */ 209 */
209 sendUnlockPin_: function(event) { 210 sendUnlockPin_: function(event) {
210 var guid = this.networkProperties && this.networkProperties.GUID; 211 var guid = this.networkProperties && this.networkProperties.GUID;
211 if (!guid) 212 if (!guid)
212 return; 213 return;
213 var pin = this.$.unlockPin.value; 214 var pin = this.$.unlockPin.value;
214 if (!this.validatePin_(pin)) 215 if (!this.validatePin_(pin))
215 return; 216 return;
216 217
217 this.networkingPrivate.unlockCellularSim(guid, pin, '', function() { 218 this.networkingPrivate.unlockCellularSim(guid, pin, '', function() {
218 if (chrome.runtime.lastError) { 219 if (chrome.runtime.lastError) {
219 this.error = ErrorType.INCORRECT_PIN; 220 this.error_ = ErrorType.INCORRECT_PIN;
220 this.$.unlockPin.inputElement.select(); 221 this.$.unlockPin.inputElement.select();
221 } else { 222 } else {
222 this.error = ErrorType.NONE; 223 this.error_ = ErrorType.NONE;
223 this.$.unlockPinDialog.close(); 224 this.$.unlockPinDialog.close();
224 } 225 }
225 }.bind(this)); 226 }.bind(this));
226 }, 227 },
227 228
228 /** 229 /**
229 * Opens the Unlock PUK dialog. 230 * Opens the Unlock PUK dialog.
230 * @param {Event} event 231 * @param {Event} event
231 * @private 232 * @private
232 */ 233 */
233 unlockPuk_: function(event) { 234 unlockPuk_: function(event) {
234 this.error = ErrorType.NONE; 235 this.error_ = ErrorType.NONE;
235 this.$.unlockPukDialog.showModal(); 236 this.$.unlockPukDialog.showModal();
236 this.$.unlockPuk.value = ''; 237 this.$.unlockPuk.value = '';
237 this.$.unlockPin1.value = ''; 238 this.$.unlockPin1.value = '';
238 this.$.unlockPin2.value = ''; 239 this.$.unlockPin2.value = '';
239 }, 240 },
240 241
241 /** 242 /**
242 * Sends the PUK value and new PIN value from the Unblock PUK dialog. 243 * Sends the PUK value and new PIN value from the Unblock PUK dialog.
243 * @param {Event} event 244 * @param {Event} event
244 * @private 245 * @private
245 */ 246 */
246 sendUnlockPuk_: function(event) { 247 sendUnlockPuk_: function(event) {
247 var guid = this.networkProperties && this.networkProperties.GUID; 248 var guid = this.networkProperties && this.networkProperties.GUID;
248 if (!guid) 249 if (!guid)
249 return; 250 return;
250 251
251 var puk = this.$.unlockPuk.value; 252 var puk = this.$.unlockPuk.value;
252 if (!this.validatePuk_(puk)) 253 if (!this.validatePuk_(puk))
253 return; 254 return;
254 var pin = this.$.unlockPin1.value; 255 var pin = this.$.unlockPin1.value;
255 if (!this.validatePin_(pin, this.$.unlockPin2.value)) 256 if (!this.validatePin_(pin, this.$.unlockPin2.value))
256 return; 257 return;
257 258
258 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() { 259 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() {
259 if (chrome.runtime.lastError) { 260 if (chrome.runtime.lastError) {
260 this.error = ErrorType.INCORRECT_PUK; 261 this.error_ = ErrorType.INCORRECT_PUK;
261 this.$.unlockPuk.inputElement.select(); 262 this.$.unlockPuk.inputElement.select();
262 } else { 263 } else {
263 this.error = ErrorType.NONE; 264 this.error_ = ErrorType.NONE;
264 this.$.unlockPukDialog.close(); 265 this.$.unlockPukDialog.close();
265 } 266 }
266 }.bind(this)); 267 }.bind(this));
267 }, 268 },
268 269
269 /** 270 /**
270 * @return {boolean} 271 * @return {boolean}
271 * @private 272 * @private
272 */ 273 */
273 showSimLocked_: function() { 274 showSimLocked_: function() {
(...skipping 11 matching lines...) Expand all
285 showSimUnlocked_: function() { 286 showSimUnlocked_: function() {
286 if (!this.networkProperties || !this.networkProperties.Cellular || 287 if (!this.networkProperties || !this.networkProperties.Cellular ||
287 !this.networkProperties.Cellular.SIMPresent) { 288 !this.networkProperties.Cellular.SIMPresent) {
288 return false; 289 return false;
289 } 290 }
290 return !CrOnc.isSimLocked(this.networkProperties); 291 return !CrOnc.isSimLocked(this.networkProperties);
291 }, 292 },
292 293
293 /** @private */ 294 /** @private */
294 getErrorMsg_: function() { 295 getErrorMsg_: function() {
295 if (this.error == ErrorType.NONE) 296 if (this.error_ == ErrorType.NONE)
296 return ''; 297 return '';
297 // TODO(stevenjb): Translate 298 // TODO(stevenjb): Translate
298 var msg; 299 var msg;
299 if (this.error == ErrorType.INCORRECT_PIN) 300 if (this.error_ == ErrorType.INCORRECT_PIN)
300 msg = 'Incorrect PIN.'; 301 msg = 'Incorrect PIN.';
301 else if (this.error == ErrorType.INCORRECT_PUK) 302 else if (this.error_ == ErrorType.INCORRECT_PUK)
302 msg = 'Incorrect PUK.'; 303 msg = 'Incorrect PUK.';
303 else if (this.error == ErrorType.MISMATCHED_PIN) 304 else if (this.error_ == ErrorType.MISMATCHED_PIN)
304 msg = 'PIN values do not match.'; 305 msg = 'PIN values do not match.';
305 else if (this.error == ErrorType.INVALID_PIN) 306 else if (this.error_ == ErrorType.INVALID_PIN)
306 msg = 'Invalid PIN.'; 307 msg = 'Invalid PIN.';
307 else if (this.error == ErrorType.INVALID_PUK) 308 else if (this.error_ == ErrorType.INVALID_PUK)
308 msg = 'Invalid PUK.'; 309 msg = 'Invalid PUK.';
309 else 310 else
310 return 'UNKNOWN ERROR'; 311 return 'UNKNOWN ERROR';
311 var retriesLeft = 312 var retriesLeft =
312 this.get( 313 this.get(
313 'Cellular.SIMLockStatus.RetriesLeft', this.networkProperties) || 314 'Cellular.SIMLockStatus.RetriesLeft', this.networkProperties) ||
314 0; 315 0;
315 msg += ' Retries left: ' + retriesLeft.toString(); 316 msg += ' Retries left: ' + retriesLeft.toString();
316 return msg; 317 return msg;
317 }, 318 },
318 319
319 /** 320 /**
320 * Checks whether |pin1| is of the proper length and if opt_pin2 is not 321 * Checks whether |pin1| is of the proper length and if opt_pin2 is not
321 * undefined, whether pin1 and opt_pin2 match. On any failure, sets 322 * undefined, whether pin1 and opt_pin2 match. On any failure, sets
322 * |this.error| and returns false. 323 * |this.error_| and returns false.
323 * @param {string} pin1 324 * @param {string} pin1
324 * @param {string=} opt_pin2 325 * @param {string=} opt_pin2
325 * @return {boolean} True if the pins match and are of minimum length. 326 * @return {boolean} True if the pins match and are of minimum length.
326 * @private 327 * @private
327 */ 328 */
328 validatePin_: function(pin1, opt_pin2) { 329 validatePin_: function(pin1, opt_pin2) {
329 if (pin1.length < PIN_MIN_LENGTH) { 330 if (pin1.length < PIN_MIN_LENGTH) {
330 this.error = ErrorType.INVALID_PIN; 331 this.error_ = ErrorType.INVALID_PIN;
331 return false; 332 return false;
332 } 333 }
333 if (opt_pin2 != undefined && pin1 != opt_pin2) { 334 if (opt_pin2 != undefined && pin1 != opt_pin2) {
334 this.error = ErrorType.MISMATCHED_PIN; 335 this.error_ = ErrorType.MISMATCHED_PIN;
335 return false; 336 return false;
336 } 337 }
337 return true; 338 return true;
338 }, 339 },
339 340
340 /** 341 /**
341 * Checks whether |puk| is of the proper length. If not, sets |this.error| 342 * Checks whether |puk| is of the proper length. If not, sets |this.error_|
342 * and returns false. 343 * and returns false.
343 * @param {string} puk 344 * @param {string} puk
344 * @return {boolean} True if the puk is of minimum length. 345 * @return {boolean} True if the puk is of minimum length.
345 * @private 346 * @private
346 */ 347 */
347 validatePuk_: function(puk) { 348 validatePuk_: function(puk) {
348 if (puk.length < PUK_MIN_LENGTH) { 349 if (puk.length < PUK_MIN_LENGTH) {
349 this.error = ErrorType.INVALID_PUK; 350 this.error_ = ErrorType.INVALID_PUK;
350 return false; 351 return false;
351 } 352 }
352 return true; 353 return true;
353 } 354 }
354 }); 355 });
355 })(); 356 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698