Repository navigation
Expand file tree
/
Copy pathwifi.js
More file actions
856 lines (759 loc) · 27.2 KB
/
Copy pathwifi.js
File metadata and controls
856 lines (759 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
// handle Wi-Fi settings
navigator.mozL10n.ready(function wifiSettings() {
var _ = navigator.mozL10n.get;
var settings = window.navigator.mozSettings;
if (!settings)
return;
var gWifiManager = WifiHelper.getWifiManager();
var gWifi = document.querySelector('#wifi');
var gWifiCheckBox = document.querySelector('#wifi-enabled input');
var gWifiInfoBlock = document.querySelector('#wifi-desc');
var gWpsInfoBlock = document.querySelector('#wps-column small');
var gWpsPbcLabelBlock = document.querySelector('#wps-column a');
var gCurrentNetwork = gWifiManager.connection.network;
// auto-scan networks when the Wi-Fi panel gets visible
var gScanPending = false;
var gWifiSectionVisible = false;
function updateVisibilityStatus() {
var computedStyle = window.getComputedStyle(gWifi);
gWifiSectionVisible = (!document.hidden &&
computedStyle.visibility != 'hidden');
if (gWifiSectionVisible && gScanPending) {
gNetworkList.scan();
gScanPending = false;
}
}
document.addEventListener('visibilitychange', updateVisibilityStatus);
gWifi.addEventListener('transitionend', function(evt) {
if (evt.target == gWifi) {
updateVisibilityStatus();
}
});
// toggle wifi on/off
gWifiCheckBox. toggleWifi() {
// 'wifi.suspended' is always false if users toggle wifi manually.
settings.createLock().set({
'wifi.enabled': this.checked,
'wifi.suspended': false
}). {
// Fail to write mozSettings, return toggle control to the user.
gWifiCheckBox.disabled = false;
};
this.disabled = true;
};
/**
* mozWifiManager status
* see dom/wifi/nsIWifi.idl -- the 4 possible statuses are:
* - connecting:
* fires when we start the process of connecting to a network.
* - associated:
* fires when we have connected to an access point but do not yet
* have an IP address.
* - connected:
* fires once we are fully connected to an access point.
* - connectingfailed:
* fires when we fail to connect to an access point.
* - disconnected:
* fires when we were connected to a network but have been
* disconnected.
*/
var gScanStates = new Set(['connected', 'connectingfailed', 'disconnected']);
Connectivity.wifiStatusChange = function(event) {
updateNetworkState();
if (gScanStates.has(event.status)) {
if (gWifiSectionVisible) {
gNetworkList.scan();
} else {
gScanPending = true;
}
}
};
Connectivity.wifiEnabled = function onWifiEnabled() {
// Re-enable UI toggle
gWifiCheckBox.disabled = false;
updateNetworkState();
gNetworkList.scan();
};
Connectivity.wifiDisabled = function onWifiDisabled() {
// Re-enable UI toggle
gWifiCheckBox.disabled = false;
gWifiInfoBlock.textContent = _('disabled');
gWifiInfoBlock.dataset.l10nId = 'disabled';
gNetworkList.clear(false);
gNetworkList.autoscan = false;
};
// Wi-Fi Protected Setup
var gWpsInProgress = false;
function wpsStatusReset() {
// The WPS process is done (connected, cancelled or error):
// - reset the title of the WPS item ("Connect with WPS") right now;
// - leave the current status for a moment, then reset it to the default
// message ("Automatic Wi-Fi setup").
localize(gWpsPbcLabelBlock, 'wpsMessage');
setTimeout(function resetWpsInfoBlock() {
localize(gWpsInfoBlock, 'wpsDescription2');
}, 1500);
}
document.getElementById('wps-column'). {
if (gWpsInProgress) {
var req = gWifiManager.wps({
method: 'cancel'
});
req. {
gWpsInProgress = false;
localize(gWpsInfoBlock, 'fullStatus-wps-canceled');
wpsStatusReset();
};
req. {
gWpsInfoBlock.textContent = _('wpsCancelFailedMessage') +
' [' + req.error.name + ']';
};
} else {
wpsDialog('wifi-wps', wpsCallback);
}
function wpsCallback(bssid, method, pin) {
var req;
if (method === 'pbc') {
req = gWifiManager.wps({
method: 'pbc'
});
} else if (method === 'myPin') {
req = gWifiManager.wps({
method: 'pin',
bssid: bssid
});
} else {
req = gWifiManager.wps({
method: 'pin',
bssid: bssid,
pin: pin
});
}
req. {
if (method === 'myPin') {
alert(_('wpsPinInput', { pin: req.result }));
}
gWpsInProgress = true;
localize(gWpsPbcLabelBlock, 'wpsCancelMessage');
localize(gWpsInfoBlock, 'fullStatus-wps-inprogress');
};
req. {
gWpsInfoBlock.textContent = _('fullStatus-wps-failed') +
' [' + req.error.name + ']';
};
}
function wpsDialog(dialogID, callback) {
// hide dialog box
function pinChecksum(pin) {
var accum = 0;
while (pin > 0) {
accum += 3 * (pin % 10);
pin = Math.floor(pin / 10);
accum += pin % 10;
pin = Math.floor(pin / 10);
}
return (10 - accum % 10) % 10;
}
function isValidWpsPin(pin) {
if (pin.match(/[^0-9]+/))
return false;
if (pin.length === 4)
return true;
if (pin.length !== 8)
return false;
var num = pin - 0;
return pinChecksum(Math.floor(num / 10)) === (num % 10);
}
var dialog = document.getElementById(dialogID);
if (!dialog)
return;
var apSelectionArea = dialog.querySelector('#wifi-wps-pin-aps');
var apSelect = apSelectionArea.querySelector('select');
for (var i = apSelect.childNodes.length - 1; i >= 0; i--) {
apSelect.removeChild(apSelect.childNodes[i]);
}
var option = document.createElement('option');
option.textContent = _('wpsAnyAp');
option.value = 'any';
apSelect.appendChild(option);
var wpsAvailableNetworks = gNetworkList.getWpsAvailableNetworks();
for (var i = 0; i < wpsAvailableNetworks.length; i++) {
option = document.createElement('option');
option.textContent = wpsAvailableNetworks[i].ssid;
option.value = wpsAvailableNetworks[i].bssid;
apSelect.appendChild(option);
}
var submitWpsButton = dialog.querySelector('button[type=submit]');
var pinItem = document.getElementById('wifi-wps-pin-area');
var pinDesc = pinItem.querySelector('p');
var pinInput = pinItem.querySelector('input');
pinInput. {
submitWpsButton.disabled = !isValidWpsPin(pinInput.value);
};
function onWpsMethodChange() {
var method =
dialog.querySelector("input[type='radio']:checked").value;
if (method === 'apPin') {
submitWpsButton.disabled = !isValidWpsPin(pinInput.value);
pinItem.hidden = false;
} else {
submitWpsButton.disabled = false;
pinItem.hidden = true;
}
apSelectionArea.hidden = method === 'pbc';
}
var radios = dialog.querySelectorAll('input[type="radio"]');
for (var i = 0; i < radios.length; i++) {
radios[i].>
}
onWpsMethodChange();
openDialog(dialogID, function submit() {
callback(apSelect.options[apSelect.selectedIndex].value,
dialog.querySelector("input[type='radio']:checked").value,
pinInput.value);
});
}
};
// create a network list item
function newListItem(network, callback) {
/**
* A Wi-Fi list item has the following HTML structure:
* <li>
* <aside class="pack-end wifi-icon level-[?] [secured]"></aside>
* <small> Network Security </small>
* <a> Network SSID </a>
* </li>
*/
// icon
var icon = document.createElement('aside');
icon.classList.add('pack-end');
icon.classList.add('wifi-icon');
var level = Math.min(Math.floor(network.relSignalStrength / 20), 4);
icon.classList.add('level-' + level);
// ssid
var ssid = document.createElement('a');
ssid.textContent = network.ssid;
// supported authentication methods
var small = document.createElement('small');
var keys = WifiHelper.getSecurity(network);
if (keys && keys.length) {
small.textContent = _('securedBy', { capabilities: keys.join(', ') });
icon.classList.add('secured');
} else {
small.textContent = _('securityOpen');
}
// create list item
var li = document.createElement('li');
li.appendChild(icon);
li.appendChild(small);
li.appendChild(ssid);
// Show connection status
icon.classList.add('wifi-signal');
if (WifiHelper.isConnected(network)) {
small.textContent = _('shortStatus-connected');
icon.classList.add('connected');
li.classList.add('active');
}
// bind connection callback
li. {
callback(network);
};
return li;
}
// create an explanatory list item
function newExplanationItem(message) {
var li = document.createElement('li');
li.className = 'explanation';
li.textContent = _(message);
return li;
}
// available network list
var gNetworkList = (function networkList(list) {
var scanning = false;
var autoscan = false;
var scanRate = 5000; // 5s after last scan results
var index = []; // index of all scanned networks
var networks = {};
// get the "Searching..." and "Search Again" items, respectively
var infoItem = list.querySelector('li[data-state="on"]');
var scanItem = list.querySelector('li[data-state="ready"]');
scanItem. {
clear(true);
scan();
};
// clear the network list
function clear(addScanningItem) {
index = [];
networks = {};
// remove all items except the text expl. and the "search again" button
var wifiItems = list.querySelectorAll('li:not([data-state])');
var len = wifiItems.length;
for (var i = len - 1; i >= 0; i--) {
list.removeChild(wifiItems[i]);
}
list.dataset.state = addScanningItem ? 'on' : 'off';
}
// scan wifi networks and display them in the list
function scan() {
if (scanning)
return;
// stop auto-scanning if wifi disabled or the app is hidden
if (!gWifiManager.enabled || document.hidden) {
scanning = false;
gScanPending = true;
return;
}
scanning = true;
var req = WifiHelper.getAvailableAndKnownNetworks();
req. onScanSuccess() {
clear(false);
var allNetworks = req.result;
for (var i = 0; i < allNetworks.length; ++i) {
var network = allNetworks[i];
// use ssid + security as a composited key
var key = network.ssid + '+' +
WifiHelper.getSecurity(network).join('+');
// keep connected network first, or select the highest strength
if (!networks[key] || network.connected) {
networks[key] = network;
} else {
if (!networks[key].connected &&
network.relSignalStrength > networks[key].relSignalStrength) {
networks[key] = network;
}
}
}
var networkKeys = Object.getOwnPropertyNames(networks);
// display network list
if (networkKeys.length) {
// sort networks by signal strength
networkKeys.sort(function(a, b) {
return networks[b].relSignalStrength -
networks[a].relSignalStrength;
});
// add detected networks
for (var i = 0; i < networkKeys.length; i++) {
var network = networks[networkKeys[i]];
var listItem = newListItem(network, toggleNetwork);
// put connected network on top of list
if (WifiHelper.isConnected(network)) {
list.insertBefore(listItem, infoItem.nextSibling);
} else {
list.insertBefore(listItem, scanItem);
}
index[networkKeys[i]] = listItem; // add composited key to index
}
} else {
// display a "no networks found" message if necessary
list.insertBefore(newExplanationItem('noNetworksFound'), scanItem);
}
// display the "Search Again" button
list.dataset.state = 'ready';
PerformanceTestingHelper.dispatch('settings-panel-wifi-ready');
// auto-rescan if requested
if (autoscan) {
window.setTimeout(scan, scanRate);
}
scanning = false;
};
req. onScanError(error) {
// always try again.
scanning = false;
PerformanceTestingHelper.dispatch('settings-panel-wifi-ready');
window.setTimeout(scan, scanRate);
};
}
// display a message on the network item matching the ssid
function display(network, networkStatus) {
if (!network) {
return;
}
var key = network.ssid + '+' +
WifiHelper.getSecurity(network).join('+');
var listItem = index[key];
var active = list.querySelector('.active');
if (active && active != listItem) {
active.classList.remove('active');
active.querySelector('small').textContent =
_('shortStatus-disconnected');
active.querySelector('aside').classList.remove('connecting');
active.querySelector('aside').classList.remove('connected');
}
if (listItem) {
listItem.classList.add('active');
listItem.querySelector('small').textContent =
_('shortStatus-' + networkStatus);
if (networkStatus === 'connecting') {
listItem.querySelector('aside').classList.add('connecting');
}
if (networkStatus === 'connected') {
listItem.querySelector('aside').classList.remove('connecting');
}
}
}
// get WPS available networks
function getWpsAvailableNetworks() {
var ssids = Object.getOwnPropertyNames(networks);
var wpsAvailableNetworks = [];
for (var i = 0; i < ssids.length; i++) {
var network = networks[ssids[i]];
if (WifiHelper.isWpsAvailable(network)) {
wpsAvailableNetworks.push(network);
}
}
return wpsAvailableNetworks;
}
// API
return {
get autoscan() { return autoscan; },
set autoscan(value) { autoscan = value; },
display: display,
clear: clear,
scan: scan,
get scanning() { return scanning; },
getWpsAvailableNetworks: getWpsAvailableNetworks
};
}) (document.getElementById('wifi-availableNetworks'));
// saved network list
var gKnownNetworkList = (function knownNetworkList(list) {
// clear the network list
function clear() {
while (list.hasChildNodes()) {
list.removeChild(list.lastChild);
}
}
// propose to forget a network
function forgetNetwork(network) {
var dialog = document.querySelector('#wifi-manageNetworks form');
dialog.hidden = false;
dialog. forget() {
gWifiManager.forget(network);
scan();
dialog.hidden = true;
return false;
};
dialog. cancel() {
dialog.hidden = true;
return false;
};
}
// list known networks
function scan() {
var req = gWifiManager.getKnownNetworks();
req. onSuccess() {
var allNetworks = req.result;
var networks = {};
for (var i = 0; i < allNetworks.length; ++i) {
var network = allNetworks[i];
// use ssid + capabilities as a composited key
var key = network.ssid + '+' +
WifiHelper.getSecurity(network).join('+');
networks[key] = network;
}
var networkKeys = Object.getOwnPropertyNames(networks);
clear();
// display network list
if (networkKeys.length) {
networkKeys.sort();
for (var i = 0; i < networkKeys.length; i++) {
var aItem = newListItem(networks[networkKeys[i]], forgetNetwork);
list.appendChild(aItem);
}
} else {
// display a "no known networks" message if necessary
list.appendChild(newExplanationItem('noKnownNetworks'));
}
};
req. onScanError(error) {
console.warn('wifi: could not retrieve any known network. ');
};
}
// API
return {
clear: clear,
scan: scan
};
}) (document.getElementById('wifi-knownNetworks'));
document.getElementById('manageNetworks'). knownNetworks() {
gKnownNetworkList.scan();
openDialog('wifi-manageNetworks');
};
// join hidden network
document.getElementById('joinHidden'). joinHiddenNetwork() {
toggleNetwork();
};
// UI to connect/disconnect
function toggleNetwork(network) {
if (!network) {
// offline, hidden SSID
network = {};
wifiDialog('wifi-joinHidden', wifiConnect);
} else if (WifiHelper.isConnected(network)) {
// online: show status + offer to disconnect
wifiDialog('wifi-status', wifiDisconnect);
} else if (network.password && (network.password == '*')) {
// offline, known network (hence the '*' password value):
// no further authentication required.
WifiHelper.setPassword(network);
wifiConnect();
} else {
// offline, unknown network: propose to connect
var key = WifiHelper.getKeyManagement(network);
switch (key) {
case 'WEP':
case 'WPA-PSK':
case 'WPA-EAP':
wifiDialog('wifi-auth', wifiConnect, key);
break;
default:
wifiConnect();
}
}
function wifiConnect() {
gCurrentNetwork = network;
gWifiManager.associate(network);
settings.createLock().set({'wifi.connect_via_settings': true});
}
function wifiDisconnect() {
settings.createLock().set({'wifi.connect_via_settings': false});
gWifiManager.forget(network);
// get available network list
gNetworkList.scan();
gCurrentNetwork = null;
}
// generic wifi property dialog
function wifiDialog(dialogID, callback, key) {
var dialog = document.getElementById(dialogID);
// authentication fields
var identity, password, showPassword, eap, simPin;
if (dialogID != 'wifi-status') {
identity = dialog.querySelector('input[name=identity]');
identity.value = network.identity || '';
password = dialog.querySelector('input[name=password]');
password.type = 'password';
password.value = network.password || '';
showPassword = dialog.querySelector('input[name=show-pwd]');
showPassword.checked = false;
showPassword. {
password.type = this.checked ? 'text' : 'password';
};
eap = dialog.querySelector('li.eap select');
simPin = dialog.querySelector('input[name=simPin]');
}
if (dialogID === 'wifi-joinHidden') {
network.hidden = true;
// Make sure ssid length is less then 32 bytes.
var ssid = dialog.querySelector('input[name=ssid]');
ssid. {
var ssidStr = ssid.value;
// Non-ASCII chars in SSID will be encoded by UTF-8, and length of
// each char might be longer than 1 byte.
// Use encodeURIComponent() to encode ssid, then calculate correct
// length.
if (encodeURIComponent(ssidStr).replace(/%[\w\d]{2}/g, '1')
.length > 32) {
ssid.value = ssidStr.substring(0, ssidStr.length - 1);
}
};
}
// disable the "OK" button if the password is too short
if (password) {
var checkPassword = function checkPassword() {
dialog.querySelector('button[type=submit]').disabled =
!WifiHelper.isValidInput(key, password.value, identity.value,
eap.value, simPin.value);
};
eap. {
checkPassword();
changeDisplay(key);
};
simPin.>
password.>
identity.>
checkPassword();
}
// initialisation
var keys = WifiHelper.getSecurity(network);
var security = (keys && keys.length) ? keys.join(', ') : '';
var sl = Math.min(Math.floor(network.relSignalStrength / 20), 4);
var updateBaseStationInfo = function update_base_station_info() {
dialog.querySelector('[data-ssid]').textContent = network.ssid;
dialog.querySelector('[data-signal]').textContent =
_('signalLevel' + sl);
dialog.querySelector('[data-security]').textContent =
security || _('securityNone');
dialog.dataset.security = security;
};
switch (dialogID) {
case 'wifi-status':
// we're connected, let's display some connection info
var ipAddress = dialog.querySelector('[data-ip]'); // IP address
var speed = dialog.querySelector('[data-speed]'); // link speed
var updateNetInfo = function() {
var info = gWifiManager.connectionInformation;
ipAddress.textContent = info.ipAddress || '';
speed.textContent =
_('linkSpeedMbs', { linkSpeed: info.linkSpeed });
};
gWifiManager.connectionInfoUpdate = updateNetInfo;
updateNetInfo();
updateBaseStationInfo();
break;
case 'wifi-auth':
// network info -- #wifi-auth
updateBaseStationInfo();
changeDisplay(security);
break;
case 'wifi-joinHidden':
var security = dialog.querySelector('select');
var {
key = security.selectedIndex ? security.value : '';
WifiHelper.setSecurity(network, [key]);
dialog.dataset.security = key;
checkPassword();
changeDisplay(key);
};
security.>
onSecurityChange();
break;
<
C6B3
div>
}
// change element display
function changeDisplay(security) {
if (dialogID !== 'wifi-status') {
if (security === 'WEP' || security === 'WPA-PSK') {
simPin.parentNode.style.display = 'none';
identity.parentNode.style.display = 'none';
password.parentNode.style.display = 'block';
} else if (security === 'WPA-EAP') {
if (eap) {
switch (eap.value) {
case 'SIM':
case 'AKA':
case 'AKA\'':
simPin.parentNode.style.display = 'block';
identity.parentNode.style.display = 'none';
password.parentNode.style.display = 'none';
break;
default:
simPin.parentNode.style.display = 'none';
identity.parentNode.style.display = 'block';
password.parentNode.style.display = 'block';
break;
}
}
} else {
simPin.parentNode.style.display = 'none';
identity.parentNode.style.display = 'none';
password.parentNode.style.display = 'none';
}
}
}
// reset dialog box
function reset() {
if (speed) {
gWifiManager.connectionInfoUpdate = null;
}
if (dialogID != 'wifi-status') {
simPin.value = '';
identity.value = '';
password.value = '';
showPassword.checked = false;
}
}
// OK|Cancel buttons
function submit() {
if (dialogID === 'wifi-joinHidden') {
network.ssid = dialog.querySelector('input[name=ssid]').value;
}
if (key) {
WifiHelper.setPassword(network, password.value, identity.value,
eap.value, simPin.value);
}
if (callback) {
callback();
if (dialogID === 'wifi-joinHidden') {
gKnownNetworkList.scan();
}
}
reset();
};
// show dialog box
openDialog(dialogID, submit, reset);
}
}
// update network state, called only when wifi enabled.
function updateNetworkState() {
var networkStatus = gWifiManager.connection.status;
// networkStatus has one of the following values:
// connecting, associated, connected, connectingfailed, disconnected.
gNetworkList.display(gCurrentNetwork, networkStatus);
gWifiInfoBlock.textContent =
_('fullStatus-' + networkStatus, gWifiManager.connection.network);
if (networkStatus === 'connectingfailed' && gCurrentNetwork) {
settings.createLock().set({'wifi.connect_via_settings': false});
// connection has failed, probably an authentication issue...
delete(gCurrentNetwork.password);
gWifiManager.forget(gCurrentNetwork); // force a new authentication dialog
gCurrentNetwork = null;
}
if (gWpsInProgress) {
if (networkStatus !== 'disconnected') {
gWpsInfoBlock.textContent = gWifiInfoBlock.textContent;
}
if (networkStatus === 'connected' ||
networkStatus === 'wps-timedout' ||
networkStatus === 'wps-failed' ||
networkStatus === 'wps-overlapped') {
gWpsInProgress = false;
wpsStatusReset();
}
}
}
function setMozSettingsEnabled(value) {
gWifiCheckBox.checked = value;
if (value) {
/**
* gWifiManager may not be ready (enabled) at this moment.
* To be responsive, show 'initializing' status and 'search...' first.
* A 'scan' would be called when gWifiManager is enabled.
*/
gWifiInfoBlock.textContent = _('fullStatus-initializing');
gNetworkList.clear(true);
document.querySelector('#wps-column').hidden = false;
} else {
gWifiInfoBlock.textContent = _('disabled');
if (gWpsInProgress) {
gWpsInfoBlock.textContent = gWifiInfoBlock.textContent;
}
gNetworkList.clear(false);
gNetworkList.autoscan = false;
document.querySelector('#wps-column').hidden = true;
}
}
var lastMozSettingValue = true;
// register an observer to monitor wifi.enabled changes
settings.addObserver('wifi.enabled', function(event) {
if (lastMozSettingValue == event.settingValue)
return;
lastMozSettingValue = event.settingValue;
setMozSettingsEnabled(event.settingValue);
});
// startup, update status
var req = settings.createLock().get('wifi.enabled');
req. wf_getStatusSuccess() {
lastMozSettingValue = req.result['wifi.enabled'];
setMozSettingsEnabled(lastMozSettingValue);
if (lastMozSettingValue) {
/**
* At this moment, gWifiManager has probably been enabled.
* This means it won't invoke any status changed callback function;
* therefore, we have to get network list here.
*/
updateNetworkState();
gNetworkList.scan();
}
};
});
You can’t perform that action at this time.