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

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

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

Powered by Google App Engine
This is Rietveld 408576698