OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('mobile', function() { | 5 cr.define('mobile', function() { |
6 | 6 |
7 function SimUnlock() { | 7 function SimUnlock() { |
8 } | 8 } |
9 | 9 |
10 cr.addSingletonGetter(SimUnlock); | 10 cr.addSingletonGetter(SimUnlock); |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // Error codes. | 29 // Error codes. |
30 SimUnlock.ERROR_PIN = 'incorrectPin'; | 30 SimUnlock.ERROR_PIN = 'incorrectPin'; |
31 SimUnlock.ERROR_PUK = 'incorrectPuk'; | 31 SimUnlock.ERROR_PUK = 'incorrectPuk'; |
32 SimUnlock.ERROR_OK = 'ok'; | 32 SimUnlock.ERROR_OK = 'ok'; |
33 | 33 |
34 // Misc constants. | 34 // Misc constants. |
35 SimUnlock.PIN_MIN_LENGTH = 4; | 35 SimUnlock.PIN_MIN_LENGTH = 4; |
36 SimUnlock.PUK_LENGTH = 8; | 36 SimUnlock.PUK_LENGTH = 8; |
37 | 37 |
38 SimUnlock.localStrings_ = new LocalStrings(); | |
39 | |
40 SimUnlock.prototype = { | 38 SimUnlock.prototype = { |
41 initialized_: false, | 39 initialized_: false, |
42 mode_: SimUnlock.SIM_DIALOG_UNLOCK, | 40 mode_: SimUnlock.SIM_DIALOG_UNLOCK, |
43 pukValue_: '', | 41 pukValue_: '', |
44 defaultDialogSize_: { | 42 defaultDialogSize_: { |
45 'width': window.innerWidth, | 43 'width': window.innerWidth, |
46 'height': window.innerHeight | 44 'height': window.innerHeight |
47 }, | 45 }, |
48 state_: SimUnlock.SIM_UNLOCK_LOADING, | 46 state_: SimUnlock.SIM_UNLOCK_LOADING, |
49 | 47 |
50 changeState_: function(simInfo) { | 48 changeState_: function(simInfo) { |
51 var newState = simInfo.state; | 49 var newState = simInfo.state; |
52 var error = simInfo.error; | 50 var error = simInfo.error; |
53 var tries = simInfo.tries; | 51 var tries = simInfo.tries; |
54 var pinMessage; | 52 var pinMessage; |
55 this.hideAll_(); | 53 this.hideAll_(); |
56 switch (newState) { | 54 switch (newState) { |
57 case SimUnlock.SIM_UNLOCK_LOADING: | 55 case SimUnlock.SIM_UNLOCK_LOADING: |
58 break; | 56 break; |
59 case SimUnlock.SIM_ABSENT_NOT_LOCKED: | 57 case SimUnlock.SIM_ABSENT_NOT_LOCKED: |
60 SimUnlock.close(); | 58 SimUnlock.close(); |
61 break; | 59 break; |
62 case SimUnlock.SIM_LOCKED_PIN: | 60 case SimUnlock.SIM_LOCKED_PIN: |
63 if (error == SimUnlock.ERROR_OK) { | 61 if (error == SimUnlock.ERROR_OK) { |
64 pinMessage = SimUnlock.localStrings_.getStringF( | 62 pinMessage = loadTimeData.getStringF('enterPinTriesMessage', tries); |
65 'enterPinTriesMessage', tries); | |
66 $('pin-error-msg').classList.remove('error'); | 63 $('pin-error-msg').classList.remove('error'); |
67 } else if (error == SimUnlock.ERROR_PIN) { | 64 } else if (error == SimUnlock.ERROR_PIN) { |
68 pinMessage = SimUnlock.localStrings_.getStringF( | 65 pinMessage = loadTimeData.getStringF( |
69 'incorrectPinTriesMessage', tries); | 66 'incorrectPinTriesMessage', tries); |
70 $('pin-error-msg').classList.add('error'); | 67 $('pin-error-msg').classList.add('error'); |
71 } | 68 } |
72 $('pin-error-msg').textContent = pinMessage; | 69 $('pin-error-msg').textContent = pinMessage; |
73 $('pin-input').value = ''; | 70 $('pin-input').value = ''; |
74 SimUnlock.enablePinDialog(true); | 71 SimUnlock.enablePinDialog(true); |
75 $('locked-pin-overlay').hidden = false; | 72 $('locked-pin-overlay').hidden = false; |
76 $('pin-input').focus(); | 73 $('pin-input').focus(); |
77 break; | 74 break; |
78 case SimUnlock.SIM_NOT_LOCKED_ASK_PIN: | 75 case SimUnlock.SIM_NOT_LOCKED_ASK_PIN: |
79 if (error == SimUnlock.ERROR_OK) { | 76 if (error == SimUnlock.ERROR_OK) { |
80 pinMessage = SimUnlock.localStrings_.getString('enterPinMessage'); | 77 pinMessage = loadTimeData.getString('enterPinMessage'); |
81 $('pin-error-msg').classList.remove('error'); | 78 $('pin-error-msg').classList.remove('error'); |
82 } else if (error == SimUnlock.ERROR_PIN) { | 79 } else if (error == SimUnlock.ERROR_PIN) { |
83 pinMessage = SimUnlock.localStrings_.getStringF( | 80 pinMessage = loadTimeData.getStringF( |
84 'incorrectPinTriesMessage', tries); | 81 'incorrectPinTriesMessage', tries); |
85 $('pin-error-msg').classList.add('error'); | 82 $('pin-error-msg').classList.add('error'); |
86 } | 83 } |
87 $('pin-error-msg').textContent = pinMessage; | 84 $('pin-error-msg').textContent = pinMessage; |
88 $('pin-input').value = ''; | 85 $('pin-input').value = ''; |
89 SimUnlock.enablePinDialog(true); | 86 SimUnlock.enablePinDialog(true); |
90 $('locked-pin-overlay').hidden = false; | 87 $('locked-pin-overlay').hidden = false; |
91 $('pin-input').focus(); | 88 $('pin-input').focus(); |
92 break; | 89 break; |
93 case SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN: | 90 case SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN: |
94 SimUnlock.prepareChoosePinDialog(true); | 91 SimUnlock.prepareChoosePinDialog(true); |
95 if (error == SimUnlock.ERROR_OK) { | 92 if (error == SimUnlock.ERROR_OK) { |
96 pinMessage = SimUnlock.localStrings_.getString('changePinMessage'); | 93 pinMessage = loadTimeData.getString('changePinMessage'); |
97 $('choose-pin-msg').classList.remove('error'); | 94 $('choose-pin-msg').classList.remove('error'); |
98 } else if (error == SimUnlock.ERROR_PIN) { | 95 } else if (error == SimUnlock.ERROR_PIN) { |
99 pinMessage = SimUnlock.localStrings_.getStringF( | 96 pinMessage = loadTimeData.getStringF( |
100 'incorrectPinTriesMessage', tries); | 97 'incorrectPinTriesMessage', tries); |
101 $('choose-pin-msg').classList.add('error'); | 98 $('choose-pin-msg').classList.add('error'); |
102 } | 99 } |
103 $('choose-pin-msg').textContent = pinMessage; | 100 $('choose-pin-msg').textContent = pinMessage; |
104 $('old-pin-input').value = ''; | 101 $('old-pin-input').value = ''; |
105 $('new-pin-input').value = ''; | 102 $('new-pin-input').value = ''; |
106 $('retype-new-pin-input').value = ''; | 103 $('retype-new-pin-input').value = ''; |
107 $('choose-pin-overlay').hidden = false; | 104 $('choose-pin-overlay').hidden = false; |
108 SimUnlock.enableChoosePinDialog(true); | 105 SimUnlock.enableChoosePinDialog(true); |
109 $('old-pin-input').focus(); | 106 $('old-pin-input').focus(); |
110 break; | 107 break; |
111 case SimUnlock.SIM_LOCKED_NO_PIN_TRIES_LEFT: | 108 case SimUnlock.SIM_LOCKED_NO_PIN_TRIES_LEFT: |
112 $('locked-pin-no-tries-overlay').hidden = false; | 109 $('locked-pin-no-tries-overlay').hidden = false; |
113 break; | 110 break; |
114 case SimUnlock.SIM_LOCKED_PUK: | 111 case SimUnlock.SIM_LOCKED_PUK: |
115 $('puk-input').value = ''; | 112 $('puk-input').value = ''; |
116 if (tries && tries >= 0) { | 113 if (tries && tries >= 0) { |
117 var pukMessage = SimUnlock.localStrings_.getStringF( | 114 var pukMessage = loadTimeData.getStringF('enterPukWarning', tries); |
118 'enterPukWarning', tries); | |
119 $('puk-warning-msg').textContent = pukMessage; | 115 $('puk-warning-msg').textContent = pukMessage; |
120 } | 116 } |
121 $('enter-puk-confirm').disabled = true; | 117 $('enter-puk-confirm').disabled = true; |
122 $('locked-puk-overlay').hidden = false; | 118 $('locked-puk-overlay').hidden = false; |
123 $('puk-input').focus(); | 119 $('puk-input').focus(); |
124 | 120 |
125 // Resize the dialog to accomodate the PUK contents. | 121 // Resize the dialog to accomodate the PUK contents. |
126 this.updateDialogSize_(0, 45); | 122 this.updateDialogSize_(0, 45); |
127 break; | 123 break; |
128 case SimUnlock.SIM_LOCKED_NO_PUK_TRIES_LEFT: | 124 case SimUnlock.SIM_LOCKED_NO_PUK_TRIES_LEFT: |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 SimUnlock.enablePinDialog(false); | 377 SimUnlock.enablePinDialog(false); |
382 chrome.send('enterPinCode', [pin]); | 378 chrome.send('enterPinCode', [pin]); |
383 }; | 379 }; |
384 | 380 |
385 SimUnlock.prepareChoosePinDialog = function(changePin) { | 381 SimUnlock.prepareChoosePinDialog = function(changePin) { |
386 // Our dialog has different height than choose-pin step of the | 382 // Our dialog has different height than choose-pin step of the |
387 // unlock process which we're reusing. | 383 // unlock process which we're reusing. |
388 if (changePin) { | 384 if (changePin) { |
389 $('choose-pin-content-area').classList.remove('choose-pin-content-area'); | 385 $('choose-pin-content-area').classList.remove('choose-pin-content-area'); |
390 $('choose-pin-content-area').classList.add('change-pin-content-area'); | 386 $('choose-pin-content-area').classList.add('change-pin-content-area'); |
391 var title = SimUnlock.localStrings_.getString('changePinTitle'); | 387 var title = loadTimeData.getString('changePinTitle'); |
392 $('choose-pin-title').textContent = title; | 388 $('choose-pin-title').textContent = title; |
393 } else { | 389 } else { |
394 $('choose-pin-content-area').classList.remove('change-pin-content-area'); | 390 $('choose-pin-content-area').classList.remove('change-pin-content-area'); |
395 $('choose-pin-content-area').classList.add('choose-pin-content-area'); | 391 $('choose-pin-content-area').classList.add('choose-pin-content-area'); |
396 var pinMessage = SimUnlock.localStrings_.getString('choosePinMessage'); | 392 var pinMessage = loadTimeData.getString('choosePinMessage'); |
397 $('choose-pin-msg').classList.remove('error'); | 393 $('choose-pin-msg').classList.remove('error'); |
398 $('choose-pin-msg').textContent = pinMessage; | 394 $('choose-pin-msg').textContent = pinMessage; |
399 var title = SimUnlock.localStrings_.getString('choosePinTitle'); | 395 var title = loadTimeData.getString('choosePinTitle'); |
400 $('choose-pin-title').textContent = title; | 396 $('choose-pin-title').textContent = title; |
401 } | 397 } |
402 $('old-pin-label').hidden = !changePin; | 398 $('old-pin-label').hidden = !changePin; |
403 $('old-pin-input-area').hidden = !changePin; | 399 $('old-pin-input-area').hidden = !changePin; |
404 }; | 400 }; |
405 | 401 |
406 SimUnlock.newPinEntered = function(newPin, newPin2) { | 402 SimUnlock.newPinEntered = function(newPin, newPin2) { |
407 SimUnlock.getInstance().newPinEntered_(newPin, newPin2); | 403 SimUnlock.getInstance().newPinEntered_(newPin, newPin2); |
408 }; | 404 }; |
409 | 405 |
(...skipping 14 matching lines...) Expand all Loading... |
424 }; | 420 }; |
425 | 421 |
426 // Export | 422 // Export |
427 return { | 423 return { |
428 SimUnlock: SimUnlock | 424 SimUnlock: SimUnlock |
429 }; | 425 }; |
430 | 426 |
431 }); | 427 }); |
432 | 428 |
433 disableTextSelectAndDrag(); | 429 disableTextSelectAndDrag(); |
OLD | NEW |