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

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

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

Powered by Google App Engine
This is Rietveld 408576698