Chromium Code Reviews| 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 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 | 172 |
| 173 ///////////////////////////////////////////////////////////////////////////// | 173 ///////////////////////////////////////////////////////////////////////////// |
| 174 // DetailsInternetPage class: | 174 // DetailsInternetPage class: |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * Encapsulated handling of ChromeOS internet details overlay page. | 177 * Encapsulated handling of ChromeOS internet details overlay page. |
| 178 * @constructor | 178 * @constructor |
| 179 * @extends {cr.ui.pageManager.Page} | 179 * @extends {cr.ui.pageManager.Page} |
| 180 */ | 180 */ |
| 181 function DetailsInternetPage() { | 181 function DetailsInternetPage() { |
| 182 // Cached Apn properties | 182 // If non-negative, indicates a custom entry in select-apn. |
| 183 this.userApnIndex_ = -1; | 183 this.userApnIndex_ = -1; |
| 184 | |
| 185 // The custom APN properties associated with entry |userApnIndex_|. | |
| 186 this.userApn_ = {}; | |
| 187 | |
| 188 // The currently selected APN entry (which may or may not == userApnIndex_). | |
| 184 this.selectedApnIndex_ = -1; | 189 this.selectedApnIndex_ = -1; |
| 185 this.userApn_ = {}; | 190 |
| 186 // We show the Proxy configuration tab for remembered networks and when | 191 // We show the Proxy configuration tab for remembered networks and when |
| 187 // configuring a proxy from the login screen. | 192 // configuring a proxy from the login screen. |
| 188 this.showProxy_ = false; | 193 this.showProxy_ = false; |
| 189 | 194 |
| 190 Page.call(this, 'detailsInternetPage', '', 'details-internet-page'); | 195 Page.call(this, 'detailsInternetPage', '', 'details-internet-page'); |
| 191 } | 196 } |
| 192 | 197 |
| 193 cr.addSingletonGetter(DetailsInternetPage); | 198 cr.addSingletonGetter(DetailsInternetPage); |
| 194 | 199 |
| 195 DetailsInternetPage.prototype = { | 200 DetailsInternetPage.prototype = { |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 typeLabel.textContent = loadTimeData.getString(typeKey); | 782 typeLabel.textContent = loadTimeData.getString(typeKey); |
| 778 typeLabel.hidden = false; | 783 typeLabel.hidden = false; |
| 779 typeSeparator.hidden = false; | 784 typeSeparator.hidden = false; |
| 780 } else { | 785 } else { |
| 781 typeLabel.hidden = true; | 786 typeLabel.hidden = true; |
| 782 typeSeparator.hidden = true; | 787 typeSeparator.hidden = true; |
| 783 } | 788 } |
| 784 }, | 789 }, |
| 785 | 790 |
| 786 /** | 791 /** |
| 787 * Helper method called from initializeDetailsPage to initialize the Apn | 792 * Helper method called from initializeApnList to populate the Apn list. |
| 788 * list. | 793 * @param {Array} apnList List of available APNs. |
| 789 * @private | 794 * @private |
| 790 */ | 795 */ |
| 791 initializeApnList_: function() { | 796 populateApnList_: function(apnList) { |
| 792 var onc = this.onc_; | 797 var onc = this.onc_; |
| 793 | |
| 794 var apnSelector = $('select-apn'); | 798 var apnSelector = $('select-apn'); |
| 795 // Clear APN lists, keep only last element that "other". | |
| 796 while (apnSelector.length != 1) { | |
| 797 apnSelector.remove(0); | |
| 798 } | |
| 799 var otherOption = apnSelector[0]; | 799 var otherOption = apnSelector[0]; |
| 800 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); | 800 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); |
| 801 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); | 801 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); |
| 802 var activePassword = onc.getActiveValue('Cellular.APN.Password'); | 802 var activePassword = onc.getActiveValue('Cellular.APN.Password'); |
| 803 var lastGoodApn = | 803 var lastGoodApn = |
| 804 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName'); | 804 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName'); |
| 805 var lastGoodUsername = | 805 var lastGoodUsername = |
| 806 onc.getActiveValue('Cellular.LastGoodAPN.Username'); | 806 onc.getActiveValue('Cellular.LastGoodAPN.Username'); |
| 807 var lastGoodPassword = | 807 var lastGoodPassword = |
| 808 onc.getActiveValue('Cellular.LastGoodAPN.Password'); | 808 onc.getActiveValue('Cellular.LastGoodAPN.Password'); |
| 809 var apnList = onc.getActiveValue('Cellular.APNList'); | |
| 810 for (var i = 0; i < apnList.length; i++) { | 809 for (var i = 0; i < apnList.length; i++) { |
| 811 var apnDict = apnList[i]; | 810 var apnDict = apnList[i]; |
| 812 var option = document.createElement('option'); | 811 var option = document.createElement('option'); |
| 813 var localizedName = apnDict['LocalizedName']; | 812 var localizedName = apnDict['LocalizedName']; |
| 814 var name = localizedName ? localizedName : apnDict['Name']; | 813 var name = localizedName ? localizedName : apnDict['Name']; |
| 815 var accessPointName = apnDict['AccessPointName']; | 814 var accessPointName = apnDict['AccessPointName']; |
| 816 option.textContent = | 815 option.textContent = |
| 817 name ? (name + ' (' + accessPointName + ')') : accessPointName; | 816 name ? (name + ' (' + accessPointName + ')') : accessPointName; |
| 818 option.value = i; | 817 option.value = i; |
| 819 // Insert new option before "other" option. | 818 // Insert new option before 'other' option. |
| 820 apnSelector.add(option, otherOption); | 819 apnSelector.add(option, otherOption); |
| 821 if (this.selectedApnIndex_ != -1) | 820 if (this.selectedApnIndex_ != -1) |
| 822 continue; | 821 continue; |
| 823 // If this matches the active Apn, or LastGoodApn (or there is no last | 822 // If this matches the active Apn, or LastGoodApn (or there is no last |
| 824 // good APN), set it as the selected Apn. | 823 // good APN), set it as the selected Apn. |
| 825 if ((activeApn == accessPointName && | 824 if ((activeApn == accessPointName && |
| 826 activeUsername == apnDict['Username'] && | 825 activeUsername == apnDict['Username'] && |
| 827 activePassword == apnDict['Password']) || | 826 activePassword == apnDict['Password']) || |
| 828 (!activeApn && !lastGoodApn) || | 827 (!activeApn && !lastGoodApn) || |
| 829 (!activeApn && | 828 (!activeApn && |
| 830 lastGoodApn == accessPointName && | 829 lastGoodApn == accessPointName && |
| 831 lastGoodUsername == apnDict['Username'] && | 830 lastGoodUsername == apnDict['Username'] && |
| 832 lastGoodPassword == apnDict['Password'])) { | 831 lastGoodPassword == apnDict['Password'])) { |
| 833 this.selectedApnIndex_ = i; | 832 this.selectedApnIndex_ = i; |
| 834 } | 833 } |
| 835 } | 834 } |
| 836 if (this.selectedApnIndex_ == -1 && activeApn) { | 835 if (this.selectedApnIndex_ == -1 && activeApn) { |
| 836 // Create a 'user' entry for any active apn not in the list. | |
| 837 var activeOption = document.createElement('option'); | 837 var activeOption = document.createElement('option'); |
| 838 activeOption.textContent = activeApn; | 838 activeOption.textContent = activeApn; |
| 839 activeOption.value = -1; | 839 activeOption.value = -1; |
| 840 apnSelector.add(activeOption, otherOption); | 840 apnSelector.add(activeOption, otherOption); |
| 841 this.selectedApnIndex_ = apnSelector.length - 2; | 841 this.selectedApnIndex_ = apnSelector.length - 2; |
| 842 this.userApnIndex_ = this.selectedApnIndex_; | 842 this.userApnIndex_ = this.selectedApnIndex_; |
| 843 } | 843 } |
| 844 }, | |
| 845 | |
| 846 /** | |
| 847 * Helper method called from initializeDetailsPage to initialize the Apn | |
| 848 * list. | |
| 849 * @private | |
| 850 */ | |
| 851 initializeApnList_: function() { | |
| 852 var onc = this.onc_; | |
| 853 | |
| 854 var apnSelector = $('select-apn'); | |
| 855 | |
| 856 // Clear APN lists, keep only last element, 'other'. | |
| 857 while (apnSelector.length != 1) | |
| 858 apnSelector.remove(0); | |
| 859 | |
| 860 var apnList = onc.getActiveValue('Cellular.APNList'); | |
| 861 if (apnList) { | |
| 862 // Populate the list with the existing APNs. | |
| 863 this.populateApnList_(apnList); | |
| 864 } else { | |
| 865 // Create a single 'default' entry. | |
| 866 var otherOption = apnSelector[0]; | |
| 867 var activeOption = document.createElement('option'); | |
| 868 activeOption.textContent = | |
| 869 loadTimeData.getString('cellularApnUseDefault'); | |
| 870 activeOption.value = -1; | |
| 871 apnSelector.add(activeOption, otherOption); | |
| 872 this.selectedApnIndex_ = apnSelector.length - 2; | |
| 873 } | |
| 844 assert(this.selectedApnIndex_ >= 0); | 874 assert(this.selectedApnIndex_ >= 0); |
| 845 apnSelector.selectedIndex = this.selectedApnIndex_; | 875 apnSelector.selectedIndex = this.selectedApnIndex_; |
| 846 updateHidden('.apn-list-view', false); | 876 updateHidden('.apn-list-view', false); |
| 847 updateHidden('.apn-details-view', true); | 877 updateHidden('.apn-details-view', true); |
| 848 }, | 878 }, |
| 849 | 879 |
| 850 /** | 880 /** |
| 881 * Helper function for setting APN properties. | |
| 882 * @param {Object} apnValue Dictionary of APN properties. | |
| 883 * @private | |
| 884 */ | |
| 885 setActiveApn_: function(apnValue) { | |
| 886 var activeApn = {}; | |
| 887 var apnName = apnValue['AccessPointName']; | |
| 888 if (apnName) { | |
|
pneubeck (no reviews)
2015/01/13 09:48:15
is the 'else' case meant for clearing the APN sett
stevenjb
2015/01/13 17:13:06
re: 'else': Correct. I can make that explicit or c
| |
| 889 activeApn['AccessPointName'] = apnName; | |
| 890 activeApn['Username'] = stringFromValue(apnValue['Username']); | |
| 891 activeApn['Password'] = stringFromValue(apnValue['Password']); | |
| 892 } | |
| 893 // Set the cached ONC data. | |
| 894 this.onc_.setProperty('Cellular.APN', activeApn); | |
| 895 // Set an ONC object with just the APN values. | |
| 896 var oncData = new OncData({}); | |
| 897 oncData.setProperty('Cellular.APN', activeApn); | |
| 898 // TODO(stevenjb): chrome.networkingPrivate.setProperties | |
| 899 chrome.send('setProperties', [this.servicePath_, oncData.getData()]); | |
| 900 }, | |
| 901 | |
| 902 /** | |
| 851 * Event Listener for the cellular-apn-use-default button. | 903 * Event Listener for the cellular-apn-use-default button. |
| 852 * @private | 904 * @private |
| 853 */ | 905 */ |
| 854 setDefaultApn_: function() { | 906 setDefaultApn_: function() { |
| 855 var onc = this.onc_; | |
| 856 var apnSelector = $('select-apn'); | 907 var apnSelector = $('select-apn'); |
| 857 | 908 |
| 909 // Remove any 'user' entry. | |
| 858 if (this.userApnIndex_ != -1) { | 910 if (this.userApnIndex_ != -1) { |
| 859 apnSelector.remove(this.userApnIndex_); | 911 apnSelector.remove(this.userApnIndex_); |
| 860 this.userApnIndex_ = -1; | 912 this.userApnIndex_ = -1; |
| 861 } | 913 } |
| 862 | 914 |
| 863 var iApn = -1; | 915 var iApn = -1; |
| 864 var apnList = onc.getActiveValue('Cellular.APNList'); | 916 var apnList = this.onc_.getActiveValue('Cellular.APNList'); |
| 865 if (apnList != undefined && apnList.length > 0) { | 917 if (apnList != undefined && apnList.length > 0) { |
| 866 iApn = 0; | 918 iApn = 0; |
| 867 var defaultApn = apnList[iApn]; | 919 this.setActiveApn_(apnList[iApn]); |
| 868 var activeApn = {}; | |
| 869 activeApn['AccessPointName'] = | |
| 870 stringFromValue(defaultApn['AccessPointName']); | |
| 871 activeApn['Username'] = stringFromValue(defaultApn['Username']); | |
| 872 activeApn['Password'] = stringFromValue(defaultApn['Password']); | |
| 873 onc.setProperty('Cellular.APN', activeApn); | |
| 874 chrome.send('setApn', [this.servicePath_, | |
| 875 activeApn['AccessPointName'], | |
| 876 activeApn['Username'], | |
| 877 activeApn['Password']]); | |
| 878 } | 920 } |
| 879 apnSelector.selectedIndex = iApn; | 921 apnSelector.selectedIndex = iApn; |
| 880 this.selectedApnIndex_ = iApn; | 922 this.selectedApnIndex_ = iApn; |
| 881 | 923 |
| 882 updateHidden('.apn-list-view', false); | 924 updateHidden('.apn-list-view', false); |
| 883 updateHidden('.apn-details-view', true); | 925 updateHidden('.apn-details-view', true); |
| 884 }, | 926 }, |
| 885 | 927 |
| 886 /** | 928 /** |
| 887 * Event Listener for the cellular-apn-set button. | 929 * Event Listener for the cellular-apn-set button. |
| 888 * @private | 930 * @private |
| 889 */ | 931 */ |
| 890 setApn_: function(apnValue) { | 932 setApn_: function(apnValue) { |
| 891 if (apnValue == '') | 933 if (apnValue == '') |
| 892 return; | 934 return; |
| 893 | 935 |
| 894 var onc = this.onc_; | |
| 895 var apnSelector = $('select-apn'); | 936 var apnSelector = $('select-apn'); |
| 896 | 937 |
| 897 var activeApn = {}; | 938 var activeApn = {}; |
| 898 activeApn['AccessPointName'] = stringFromValue(apnValue); | 939 activeApn['AccessPointName'] = stringFromValue(apnValue); |
| 899 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); | 940 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); |
| 900 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); | 941 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); |
| 901 onc.setProperty('Cellular.APN', activeApn); | 942 this.setActiveApn_(activeApn); |
| 943 // Set the user selected APN. | |
| 902 this.userApn_ = activeApn; | 944 this.userApn_ = activeApn; |
| 903 chrome.send('setApn', [this.servicePath_, | |
| 904 activeApn['AccessPointName'], | |
| 905 activeApn['Username'], | |
| 906 activeApn['Password']]); | |
| 907 | 945 |
| 908 if (this.userApnIndex_ != -1) { | 946 // Remove any existing 'user' entry. |
| 947 if (this.userApnIndex_ != -1) | |
| 909 apnSelector.remove(this.userApnIndex_); | 948 apnSelector.remove(this.userApnIndex_); |
| 910 this.userApnIndex_ = -1; | |
| 911 } | |
| 912 | 949 |
| 950 // Create a new 'user' entry with the new active apn. | |
| 913 var option = document.createElement('option'); | 951 var option = document.createElement('option'); |
| 914 option.textContent = activeApn['AccessPointName']; | 952 option.textContent = activeApn['AccessPointName']; |
| 915 option.value = -1; | 953 option.value = -1; |
| 916 option.selected = true; | 954 option.selected = true; |
| 917 apnSelector.add(option, apnSelector[apnSelector.length - 1]); | 955 apnSelector.add(option, apnSelector[apnSelector.length - 1]); |
| 918 this.userApnIndex_ = apnSelector.length - 2; | 956 this.userApnIndex_ = apnSelector.length - 2; |
| 919 this.selectedApnIndex_ = this.userApnIndex_; | 957 this.selectedApnIndex_ = this.userApnIndex_; |
| 920 | 958 |
| 921 updateHidden('.apn-list-view', false); | 959 updateHidden('.apn-list-view', false); |
| 922 updateHidden('.apn-details-view', true); | 960 updateHidden('.apn-details-view', true); |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 | 1690 |
| 1653 // Don't show page name in address bar and in history to prevent people | 1691 // Don't show page name in address bar and in history to prevent people |
| 1654 // navigate here by hand and solve issue with page session restore. | 1692 // navigate here by hand and solve issue with page session restore. |
| 1655 PageManager.showPageByName('detailsInternetPage', false); | 1693 PageManager.showPageByName('detailsInternetPage', false); |
| 1656 }; | 1694 }; |
| 1657 | 1695 |
| 1658 return { | 1696 return { |
| 1659 DetailsInternetPage: DetailsInternetPage | 1697 DetailsInternetPage: DetailsInternetPage |
| 1660 }; | 1698 }; |
| 1661 }); | 1699 }); |
| OLD | NEW |