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 // require: onc_data.js | 5 // require: onc_data.js |
6 | 6 |
7 // NOTE(stevenjb): This code is in the process of being converted to be | 7 // NOTE(stevenjb): This code is in the process of being converted to be |
8 // compatible with the networkingPrivate extension API: | 8 // compatible with the networkingPrivate extension API: |
9 // * The network property dictionaries are being converted to use ONC values. | 9 // * The network property dictionaries are being converted to use ONC values. |
10 // * chrome.send calls will be replaced with an API object that simulates the | 10 // * chrome.send calls will be replaced with an API object that simulates the |
11 // networkingPrivate API. See network_config.js. | 11 // networkingPrivate API. See network_config.js. |
12 // See crbug.com/279351 for more info. | 12 // See crbug.com/279351 for more info. |
13 | 13 |
14 /** @typedef {{activationState: (string|undefined), | 14 /** |
15 * carriers: Array, | 15 * InternetDetailedInfo argument passed to showDetailedInfo. |
16 * currentCarrierIndex; (number|undefined), | |
17 * ipAutoConfig: boolean, | |
18 * ipconfig: Object, | |
19 * nameServerType: string, | |
20 * restrictedPool: (string|undefined), | |
21 * roamingState: (string|undefined), | |
22 * savedIP: Object, | |
23 * showActivateButton: (boolean|undefined) | |
24 * showViewAccountButton: (boolean|undefined), | |
25 * staticIP: Object}} | |
26 * Only the keys which had caused problems are declared in this typedef. | |
27 * There are many more of them. | |
28 * @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc | 16 * @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc |
| 17 * @typedef {{ |
| 18 * carriers: (Array.<string>|undefined), |
| 19 * currentCarrierIndex: (number|undefined), |
| 20 * deviceConnected: (boolean|undefined), |
| 21 * errorMessage: (string|undefined), |
| 22 * servicePath: string, |
| 23 * showCarrierSelect: (boolean|undefined), |
| 24 * showViewAccountButton: (boolean|undefined) |
| 25 * }} |
29 */ | 26 */ |
30 var InternetDetailedInfo; | 27 var InternetDetailedInfo; |
31 | 28 |
32 cr.define('options.internet', function() { | 29 cr.define('options.internet', function() { |
33 var OncData = cr.onc.OncData; | 30 var OncData = cr.onc.OncData; |
34 var Page = cr.ui.pageManager.Page; | 31 var Page = cr.ui.pageManager.Page; |
35 var PageManager = cr.ui.pageManager.PageManager; | 32 var PageManager = cr.ui.pageManager.PageManager; |
36 /** @const */ var IPAddressField = options.internet.IPAddressField; | 33 /** @const */ var IPAddressField = options.internet.IPAddressField; |
37 | 34 |
38 /** @const */ var GoogleNameServersString = '8.8.4.4,8.8.8.8'; | 35 /** @const */ var GoogleNameServersString = '8.8.4.4,8.8.8.8'; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 * @param {string} message The message to send to chrome. | 91 * @param {string} message The message to send to chrome. |
95 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. | 92 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. |
96 */ | 93 */ |
97 function sendCheckedIfEnabled(path, message, checkbox) { | 94 function sendCheckedIfEnabled(path, message, checkbox) { |
98 if (!checkbox.hidden && !checkbox.disabled) | 95 if (!checkbox.hidden && !checkbox.disabled) |
99 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); | 96 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); |
100 } | 97 } |
101 | 98 |
102 /** | 99 /** |
103 * Returns the netmask as a string for a given prefix length. | 100 * Returns the netmask as a string for a given prefix length. |
104 * @param {string} prefixLength The ONC routing prefix length. | 101 * @param {number} prefixLength The ONC routing prefix length. |
105 * @return {string} The corresponding netmask. | 102 * @return {string} The corresponding netmask. |
106 */ | 103 */ |
107 function prefixLengthToNetmask(prefixLength) { | 104 function prefixLengthToNetmask(prefixLength) { |
108 // Return the empty string for invalid inputs. | 105 // Return the empty string for invalid inputs. |
109 if (prefixLength < 0 || prefixLength > 32) | 106 if (prefixLength < 0 || prefixLength > 32) |
110 return ''; | 107 return ''; |
111 var netmask = ''; | 108 var netmask = ''; |
112 for (var i = 0; i < 4; ++i) { | 109 for (var i = 0; i < 4; ++i) { |
113 var remainder = 8; | 110 var remainder = 8; |
114 if (prefixLength >= 8) { | 111 if (prefixLength >= 8) { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 $('socks-host').disabled = allDisabled; | 566 $('socks-host').disabled = allDisabled; |
570 $('socks-port').disabled = allDisabled; | 567 $('socks-port').disabled = allDisabled; |
571 $('proxy-use-pac-url').disabled = true; | 568 $('proxy-use-pac-url').disabled = true; |
572 $('proxy-pac-url').disabled = true; | 569 $('proxy-pac-url').disabled = true; |
573 $('auto-proxy-parms').hidden = !$('auto-proxy').checked; | 570 $('auto-proxy-parms').hidden = !$('auto-proxy').checked; |
574 $('manual-proxy-parms').hidden = !$('manual-proxy').checked; | 571 $('manual-proxy-parms').hidden = !$('manual-proxy').checked; |
575 chrome.send('coreOptionsUserMetricsAction', | 572 chrome.send('coreOptionsUserMetricsAction', |
576 ['Options_NetworkManualProxy_Enable']); | 573 ['Options_NetworkManualProxy_Enable']); |
577 }, | 574 }, |
578 | 575 |
| 576 /** |
| 577 * Helper method called from showDetailedInfo and updateConnectionData. |
| 578 * Updates visibilty/enabled of the login/disconnect/configure buttons. |
| 579 * @private |
| 580 */ |
579 updateConnectionButtonVisibilty_: function() { | 581 updateConnectionButtonVisibilty_: function() { |
580 var onc = this.onc_; | 582 var onc = this.onc_; |
581 if (this.type_ == 'Ethernet') { | 583 if (this.type_ == 'Ethernet') { |
582 // Ethernet can never be connected or disconnected and can always be | 584 // Ethernet can never be connected or disconnected and can always be |
583 // configured (e.g. to set security). | 585 // configured (e.g. to set security). |
584 $('details-internet-login').hidden = true; | 586 $('details-internet-login').hidden = true; |
585 $('details-internet-disconnect').hidden = true; | 587 $('details-internet-disconnect').hidden = true; |
586 $('details-internet-configure').hidden = false; | 588 $('details-internet-configure').hidden = false; |
587 return; | 589 return; |
588 } | 590 } |
(...skipping 14 matching lines...) Expand all Loading... |
603 var connectable = onc.getActiveValue('Connectable'); | 605 var connectable = onc.getActiveValue('Connectable'); |
604 if (connectState != 'Connected' && | 606 if (connectState != 'Connected' && |
605 (!connectable || onc.getWiFiSecurity() != 'None' || | 607 (!connectable || onc.getWiFiSecurity() != 'None' || |
606 (this.type_ == 'Wimax' || this.type_ == 'VPN'))) { | 608 (this.type_ == 'Wimax' || this.type_ == 'VPN'))) { |
607 $('details-internet-configure').hidden = false; | 609 $('details-internet-configure').hidden = false; |
608 } else { | 610 } else { |
609 $('details-internet-configure').hidden = true; | 611 $('details-internet-configure').hidden = true; |
610 } | 612 } |
611 }, | 613 }, |
612 | 614 |
| 615 /** |
| 616 * Helper method called from showDetailedInfo and updateConnectionData. |
| 617 * Updates the connection state property and account / sim card links. |
| 618 * @param {InternetDetailedInfo} data |
| 619 * @private |
| 620 */ |
613 updateDetails_: function(data) { | 621 updateDetails_: function(data) { |
614 var onc = this.onc_; | 622 var onc = this.onc_; |
615 | 623 |
616 if ('deviceConnected' in data) | 624 if ('deviceConnected' in data) |
617 this.deviceConnected_ = data.deviceConnected; | 625 this.deviceConnected_ = data.deviceConnected; |
618 | 626 |
619 var connectionStateString = onc.getTranslatedValue('ConnectionState'); | 627 var connectionStateString = onc.getTranslatedValue('ConnectionState'); |
620 $('connection-state').textContent = connectionStateString; | 628 $('connection-state').textContent = connectionStateString; |
621 | 629 |
622 var type = this.type_; | 630 var type = this.type_; |
(...skipping 18 matching lines...) Expand all Loading... |
641 activationState == 'PartiallyActivated'; | 649 activationState == 'PartiallyActivated'; |
642 } | 650 } |
643 | 651 |
644 $('view-account-details').hidden = !showViewAccount; | 652 $('view-account-details').hidden = !showViewAccount; |
645 $('activate-details').hidden = !showActivate; | 653 $('activate-details').hidden = !showActivate; |
646 // If activation is not complete, hide the login button. | 654 // If activation is not complete, hide the login button. |
647 if (showActivate) | 655 if (showActivate) |
648 $('details-internet-login').hidden = true; | 656 $('details-internet-login').hidden = true; |
649 }, | 657 }, |
650 | 658 |
| 659 /** |
| 660 * Helper method called from showDetailedInfo and updateConnectionData. |
| 661 * Updates the fields in the header section of the details frame. |
| 662 * @private |
| 663 */ |
651 populateHeader_: function() { | 664 populateHeader_: function() { |
652 var onc = this.onc_; | 665 var onc = this.onc_; |
653 | 666 |
654 $('network-details-title').textContent = onc.getTranslatedValue('Name'); | 667 $('network-details-title').textContent = onc.getTranslatedValue('Name'); |
655 var connectionState = onc.getActiveValue('ConnectionState'); | 668 var connectionState = onc.getActiveValue('ConnectionState'); |
656 var connectionStateString = onc.getTranslatedValue('ConnectionState'); | 669 var connectionStateString = onc.getTranslatedValue('ConnectionState'); |
657 $('network-details-subtitle-status').textContent = connectionStateString; | 670 $('network-details-subtitle-status').textContent = connectionStateString; |
658 | 671 |
659 var typeKey; | 672 var typeKey; |
660 var type = this.type_; | 673 var type = this.type_; |
(...skipping 14 matching lines...) Expand all Loading... |
675 if (typeKey) { | 688 if (typeKey) { |
676 typeLabel.textContent = loadTimeData.getString(typeKey); | 689 typeLabel.textContent = loadTimeData.getString(typeKey); |
677 typeLabel.hidden = false; | 690 typeLabel.hidden = false; |
678 typeSeparator.hidden = false; | 691 typeSeparator.hidden = false; |
679 } else { | 692 } else { |
680 typeLabel.hidden = true; | 693 typeLabel.hidden = true; |
681 typeSeparator.hidden = true; | 694 typeSeparator.hidden = true; |
682 } | 695 } |
683 }, | 696 }, |
684 | 697 |
685 initializeApnList_: function(onc) { | 698 /** |
| 699 * Helper method called from showDetailedInfo to intialize the Apn list. |
| 700 * @private |
| 701 */ |
| 702 initializeApnList_: function() { |
| 703 var onc = this.onc_; |
| 704 |
686 var apnSelector = $('select-apn'); | 705 var apnSelector = $('select-apn'); |
687 // Clear APN lists, keep only last element that "other". | 706 // Clear APN lists, keep only last element that "other". |
688 while (apnSelector.length != 1) { | 707 while (apnSelector.length != 1) { |
689 apnSelector.remove(0); | 708 apnSelector.remove(0); |
690 } | 709 } |
691 var otherOption = apnSelector[0]; | 710 var otherOption = apnSelector[0]; |
692 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); | 711 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); |
693 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); | 712 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); |
694 var activePassword = onc.getActiveValue('Cellular.APN.Password'); | 713 var activePassword = onc.getActiveValue('Cellular.APN.Password'); |
695 var lastGoodApn = | 714 var lastGoodApn = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 apnSelector.add(activeOption, otherOption); | 748 apnSelector.add(activeOption, otherOption); |
730 this.selectedApnIndex_ = apnSelector.length - 2; | 749 this.selectedApnIndex_ = apnSelector.length - 2; |
731 this.userApnIndex_ = this.selectedApnIndex_; | 750 this.userApnIndex_ = this.selectedApnIndex_; |
732 } | 751 } |
733 assert(this.selectedApnIndex_ >= 0); | 752 assert(this.selectedApnIndex_ >= 0); |
734 apnSelector.selectedIndex = this.selectedApnIndex_; | 753 apnSelector.selectedIndex = this.selectedApnIndex_; |
735 updateHidden('.apn-list-view', false); | 754 updateHidden('.apn-list-view', false); |
736 updateHidden('.apn-details-view', true); | 755 updateHidden('.apn-details-view', true); |
737 }, | 756 }, |
738 | 757 |
| 758 /** |
| 759 * Event Listener for the cellular-apn-use-default button. |
| 760 * @private |
| 761 */ |
739 setDefaultApn_: function() { | 762 setDefaultApn_: function() { |
740 var onc = this.onc_; | 763 var onc = this.onc_; |
741 var apnSelector = $('select-apn'); | 764 var apnSelector = $('select-apn'); |
742 | 765 |
743 if (this.userApnIndex_ != -1) { | 766 if (this.userApnIndex_ != -1) { |
744 apnSelector.remove(this.userApnIndex_); | 767 apnSelector.remove(this.userApnIndex_); |
745 this.userApnIndex_ = -1; | 768 this.userApnIndex_ = -1; |
746 } | 769 } |
747 | 770 |
748 var iApn = -1; | 771 var iApn = -1; |
(...skipping 12 matching lines...) Expand all Loading... |
761 activeApn['Username'], | 784 activeApn['Username'], |
762 activeApn['Password']]); | 785 activeApn['Password']]); |
763 } | 786 } |
764 apnSelector.selectedIndex = iApn; | 787 apnSelector.selectedIndex = iApn; |
765 this.selectedApnIndex_ = iApn; | 788 this.selectedApnIndex_ = iApn; |
766 | 789 |
767 updateHidden('.apn-list-view', false); | 790 updateHidden('.apn-list-view', false); |
768 updateHidden('.apn-details-view', true); | 791 updateHidden('.apn-details-view', true); |
769 }, | 792 }, |
770 | 793 |
| 794 /** |
| 795 * Event Listener for the cellular-apn-set button. |
| 796 * @private |
| 797 */ |
771 setApn_: function(apnValue) { | 798 setApn_: function(apnValue) { |
772 if (apnValue == '') | 799 if (apnValue == '') |
773 return; | 800 return; |
774 | 801 |
775 var onc = this.onc_; | 802 var onc = this.onc_; |
776 var apnSelector = $('select-apn'); | 803 var apnSelector = $('select-apn'); |
777 | 804 |
778 var activeApn = {}; | 805 var activeApn = {}; |
779 activeApn['AccessPointName'] = stringFromValue(apnValue); | 806 activeApn['AccessPointName'] = stringFromValue(apnValue); |
780 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); | 807 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); |
(...skipping 15 matching lines...) Expand all Loading... |
796 option.value = -1; | 823 option.value = -1; |
797 option.selected = true; | 824 option.selected = true; |
798 apnSelector.add(option, apnSelector[apnSelector.length - 1]); | 825 apnSelector.add(option, apnSelector[apnSelector.length - 1]); |
799 this.userApnIndex_ = apnSelector.length - 2; | 826 this.userApnIndex_ = apnSelector.length - 2; |
800 this.selectedApnIndex_ = this.userApnIndex_; | 827 this.selectedApnIndex_ = this.userApnIndex_; |
801 | 828 |
802 updateHidden('.apn-list-view', false); | 829 updateHidden('.apn-list-view', false); |
803 updateHidden('.apn-details-view', true); | 830 updateHidden('.apn-details-view', true); |
804 }, | 831 }, |
805 | 832 |
| 833 /** |
| 834 * Event Listener for the cellular-apn-cancel button. |
| 835 * @private |
| 836 */ |
806 cancelApn_: function() { | 837 cancelApn_: function() { |
807 $('select-apn').selectedIndex = this.selectedApnIndex_; | 838 $('select-apn').selectedIndex = this.selectedApnIndex_; |
808 updateHidden('.apn-list-view', false); | 839 updateHidden('.apn-list-view', false); |
809 updateHidden('.apn-details-view', true); | 840 updateHidden('.apn-details-view', true); |
810 }, | 841 }, |
811 | 842 |
| 843 /** |
| 844 * Event Listener for the select-apn button. |
| 845 * @private |
| 846 */ |
812 selectApn_: function() { | 847 selectApn_: function() { |
813 var onc = this.onc_; | 848 var onc = this.onc_; |
814 var apnSelector = $('select-apn'); | 849 var apnSelector = $('select-apn'); |
815 var apnDict; | 850 var apnDict; |
816 if (apnSelector[apnSelector.selectedIndex].value != -1) { | 851 if (apnSelector[apnSelector.selectedIndex].value != -1) { |
817 var apnList = onc.getActiveValue('Cellular.APNList'); | 852 var apnList = onc.getActiveValue('Cellular.APNList'); |
818 var apnIndex = apnSelector.selectedIndex; | 853 var apnIndex = apnSelector.selectedIndex; |
819 assert(apnIndex < apnList.length); | 854 assert(apnIndex < apnList.length); |
820 apnDict = apnList[apnIndex]; | 855 apnDict = apnList[apnIndex]; |
821 chrome.send('setApn', [this.servicePath_, | 856 chrome.send('setApn', [this.servicePath_, |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 carrierSelector.selectedIndex = data.currentCarrierIndex; | 1367 carrierSelector.selectedIndex = data.currentCarrierIndex; |
1333 } else { | 1368 } else { |
1334 $('service-name').textContent = networkName; | 1369 $('service-name').textContent = networkName; |
1335 } | 1370 } |
1336 | 1371 |
1337 $('network-technology').textContent = | 1372 $('network-technology').textContent = |
1338 onc.getActiveValue('Cellular.NetworkTechnology'); | 1373 onc.getActiveValue('Cellular.NetworkTechnology'); |
1339 $('roaming-state').textContent = | 1374 $('roaming-state').textContent = |
1340 onc.getTranslatedValue('Cellular.RoamingState'); | 1375 onc.getTranslatedValue('Cellular.RoamingState'); |
1341 $('cellular-restricted-connectivity').textContent = restrictedString; | 1376 $('cellular-restricted-connectivity').textContent = restrictedString; |
1342 $('error-state').textContent = data.errorMessage; | 1377 if ('errorMessage' in data) |
| 1378 $('error-state').textContent = data.errorMessage; |
1343 $('manufacturer').textContent = | 1379 $('manufacturer').textContent = |
1344 onc.getActiveValue('Cellular.Manufacturer'); | 1380 onc.getActiveValue('Cellular.Manufacturer'); |
1345 $('model-id').textContent = onc.getActiveValue('Cellular.ModelID'); | 1381 $('model-id').textContent = onc.getActiveValue('Cellular.ModelID'); |
1346 $('firmware-revision').textContent = | 1382 $('firmware-revision').textContent = |
1347 onc.getActiveValue('Cellular.FirmwareRevision'); | 1383 onc.getActiveValue('Cellular.FirmwareRevision'); |
1348 $('hardware-revision').textContent = | 1384 $('hardware-revision').textContent = |
1349 onc.getActiveValue('Cellular.HardwareRevision'); | 1385 onc.getActiveValue('Cellular.HardwareRevision'); |
1350 $('mdn').textContent = onc.getActiveValue('Cellular.MDN'); | 1386 $('mdn').textContent = onc.getActiveValue('Cellular.MDN'); |
1351 | 1387 |
1352 // Show ServingOperator properties only if available. | 1388 // Show ServingOperator properties only if available. |
(...skipping 17 matching lines...) Expand all Loading... |
1370 // Show IMEI/ESN/MEID/MIN/PRL only if they are available. | 1406 // Show IMEI/ESN/MEID/MIN/PRL only if they are available. |
1371 setOrHideParent('esn', onc.getActiveValue('Cellular.ESN')); | 1407 setOrHideParent('esn', onc.getActiveValue('Cellular.ESN')); |
1372 setOrHideParent('imei', onc.getActiveValue('Cellular.IMEI')); | 1408 setOrHideParent('imei', onc.getActiveValue('Cellular.IMEI')); |
1373 setOrHideParent('meid', onc.getActiveValue('Cellular.MEID')); | 1409 setOrHideParent('meid', onc.getActiveValue('Cellular.MEID')); |
1374 setOrHideParent('min', onc.getActiveValue('Cellular.MIN')); | 1410 setOrHideParent('min', onc.getActiveValue('Cellular.MIN')); |
1375 setOrHideParent('prl-version', onc.getActiveValue('Cellular.PRLVersion')); | 1411 setOrHideParent('prl-version', onc.getActiveValue('Cellular.PRLVersion')); |
1376 | 1412 |
1377 if (onc.getActiveValue('Cellular.Family') == 'GSM') { | 1413 if (onc.getActiveValue('Cellular.Family') == 'GSM') { |
1378 $('iccid').textContent = onc.getActiveValue('Cellular.ICCID'); | 1414 $('iccid').textContent = onc.getActiveValue('Cellular.ICCID'); |
1379 $('imsi').textContent = onc.getActiveValue('Cellular.IMSI'); | 1415 $('imsi').textContent = onc.getActiveValue('Cellular.IMSI'); |
1380 detailsPage.initializeApnList_(onc); | 1416 detailsPage.initializeApnList_(); |
1381 } | 1417 } |
1382 $('auto-connect-network-cellular').checked = | 1418 $('auto-connect-network-cellular').checked = |
1383 onc.getActiveValue('AutoConnect'); | 1419 onc.getActiveValue('AutoConnect'); |
1384 $('auto-connect-network-cellular').disabled = false; | 1420 $('auto-connect-network-cellular').disabled = false; |
1385 } else if (type == 'VPN') { | 1421 } else if (type == 'VPN') { |
1386 OptionsPage.showTab($('vpn-nav-tab')); | 1422 OptionsPage.showTab($('vpn-nav-tab')); |
1387 $('inet-service-name').textContent = networkName; | 1423 $('inet-service-name').textContent = networkName; |
1388 $('inet-provider-type').textContent = | 1424 $('inet-provider-type').textContent = |
1389 onc.getTranslatedValue('VPN.Type'); | 1425 onc.getTranslatedValue('VPN.Type'); |
1390 var providerType = onc.getActiveValue('VPN.Type'); | 1426 var providerType = onc.getActiveValue('VPN.Type'); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 | 1475 |
1440 // Don't show page name in address bar and in history to prevent people | 1476 // Don't show page name in address bar and in history to prevent people |
1441 // navigate here by hand and solve issue with page session restore. | 1477 // navigate here by hand and solve issue with page session restore. |
1442 PageManager.showPageByName('detailsInternetPage', false); | 1478 PageManager.showPageByName('detailsInternetPage', false); |
1443 }; | 1479 }; |
1444 | 1480 |
1445 return { | 1481 return { |
1446 DetailsInternetPage: DetailsInternetPage | 1482 DetailsInternetPage: DetailsInternetPage |
1447 }; | 1483 }; |
1448 }); | 1484 }); |
OLD | NEW |