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 in $('select-apn') (which may or may not |
| 189 // == userApnIndex_). |
184 this.selectedApnIndex_ = -1; | 190 this.selectedApnIndex_ = -1; |
185 this.userApn_ = {}; | 191 |
186 // We show the Proxy configuration tab for remembered networks and when | 192 // We show the Proxy configuration tab for remembered networks and when |
187 // configuring a proxy from the login screen. | 193 // configuring a proxy from the login screen. |
188 this.showProxy_ = false; | 194 this.showProxy_ = false; |
189 | 195 |
190 Page.call(this, 'detailsInternetPage', '', 'details-internet-page'); | 196 Page.call(this, 'detailsInternetPage', '', 'details-internet-page'); |
191 } | 197 } |
192 | 198 |
193 cr.addSingletonGetter(DetailsInternetPage); | 199 cr.addSingletonGetter(DetailsInternetPage); |
194 | 200 |
195 DetailsInternetPage.prototype = { | 201 DetailsInternetPage.prototype = { |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 typeLabel.textContent = loadTimeData.getString(typeKey); | 783 typeLabel.textContent = loadTimeData.getString(typeKey); |
778 typeLabel.hidden = false; | 784 typeLabel.hidden = false; |
779 typeSeparator.hidden = false; | 785 typeSeparator.hidden = false; |
780 } else { | 786 } else { |
781 typeLabel.hidden = true; | 787 typeLabel.hidden = true; |
782 typeSeparator.hidden = true; | 788 typeSeparator.hidden = true; |
783 } | 789 } |
784 }, | 790 }, |
785 | 791 |
786 /** | 792 /** |
787 * Helper method called from initializeDetailsPage to initialize the Apn | 793 * Helper method to insert a 'user' option into the Apn list. |
788 * list. | 794 * @param {Object} userOption The 'user' apn dictionary |
789 * @private | 795 * @private |
790 */ | 796 */ |
791 initializeApnList_: function() { | 797 insertApnUserOption_: function(userOption) { |
| 798 // Add the 'user' option before the last option ('other') |
| 799 var apnSelector = $('select-apn'); |
| 800 assert(apnSelector.length > 0); |
| 801 var otherOption = apnSelector[apnSelector.length - 1]; |
| 802 apnSelector.add(userOption, otherOption); |
| 803 this.userApnIndex_ = apnSelector.length - 2; |
| 804 this.selectedApnIndex_ = this.userApnIndex_; |
| 805 }, |
| 806 |
| 807 /** |
| 808 * Helper method called from initializeApnList to populate the Apn list. |
| 809 * @param {Array} apnList List of available APNs. |
| 810 * @private |
| 811 */ |
| 812 populateApnList_: function(apnList) { |
792 var onc = this.onc_; | 813 var onc = this.onc_; |
793 | |
794 var apnSelector = $('select-apn'); | 814 var apnSelector = $('select-apn'); |
795 // Clear APN lists, keep only last element that "other". | 815 assert(apnSelector.length == 1); |
796 while (apnSelector.length != 1) { | |
797 apnSelector.remove(0); | |
798 } | |
799 var otherOption = apnSelector[0]; | 816 var otherOption = apnSelector[0]; |
800 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); | 817 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); |
801 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); | 818 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); |
802 var activePassword = onc.getActiveValue('Cellular.APN.Password'); | 819 var activePassword = onc.getActiveValue('Cellular.APN.Password'); |
803 var lastGoodApn = | 820 var lastGoodApn = |
804 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName'); | 821 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName'); |
805 var lastGoodUsername = | 822 var lastGoodUsername = |
806 onc.getActiveValue('Cellular.LastGoodAPN.Username'); | 823 onc.getActiveValue('Cellular.LastGoodAPN.Username'); |
807 var lastGoodPassword = | 824 var lastGoodPassword = |
808 onc.getActiveValue('Cellular.LastGoodAPN.Password'); | 825 onc.getActiveValue('Cellular.LastGoodAPN.Password'); |
809 var apnList = onc.getActiveValue('Cellular.APNList'); | |
810 for (var i = 0; i < apnList.length; i++) { | 826 for (var i = 0; i < apnList.length; i++) { |
811 var apnDict = apnList[i]; | 827 var apnDict = apnList[i]; |
812 var option = document.createElement('option'); | 828 var option = document.createElement('option'); |
813 var localizedName = apnDict['LocalizedName']; | 829 var localizedName = apnDict['LocalizedName']; |
814 var name = localizedName ? localizedName : apnDict['Name']; | 830 var name = localizedName ? localizedName : apnDict['Name']; |
815 var accessPointName = apnDict['AccessPointName']; | 831 var accessPointName = apnDict['AccessPointName']; |
816 option.textContent = | 832 option.textContent = |
817 name ? (name + ' (' + accessPointName + ')') : accessPointName; | 833 name ? (name + ' (' + accessPointName + ')') : accessPointName; |
818 option.value = i; | 834 option.value = i; |
819 // Insert new option before "other" option. | 835 // Insert new option before 'other' option. |
820 apnSelector.add(option, otherOption); | 836 apnSelector.add(option, otherOption); |
821 if (this.selectedApnIndex_ != -1) | 837 if (this.selectedApnIndex_ != -1) |
822 continue; | 838 continue; |
823 // If this matches the active Apn, or LastGoodApn (or there is no last | 839 // If this matches the active Apn name, or LastGoodApn name (or there |
824 // good APN), set it as the selected Apn. | 840 // is no last good APN), set it as the selected Apn. |
825 if ((activeApn == accessPointName && | 841 if ((activeApn == accessPointName) || |
826 activeUsername == apnDict['Username'] && | 842 (!activeApn && (!lastGoodApn || lastGoodApn == accessPointName))) { |
827 activePassword == apnDict['Password']) || | |
828 (!activeApn && !lastGoodApn) || | |
829 (!activeApn && | |
830 lastGoodApn == accessPointName && | |
831 lastGoodUsername == apnDict['Username'] && | |
832 lastGoodPassword == apnDict['Password'])) { | |
833 this.selectedApnIndex_ = i; | 843 this.selectedApnIndex_ = i; |
834 } | 844 } |
835 } | 845 } |
836 if (this.selectedApnIndex_ == -1 && activeApn) { | 846 if (this.selectedApnIndex_ == -1 && activeApn) { |
837 var activeOption = document.createElement('option'); | 847 this.userApn_ = activeApn; |
838 activeOption.textContent = activeApn; | 848 // Create a 'user' entry for any active apn not in the list. |
839 activeOption.value = -1; | 849 var userOption = document.createElement('option'); |
840 apnSelector.add(activeOption, otherOption); | 850 userOption.textContent = activeApn; |
841 this.selectedApnIndex_ = apnSelector.length - 2; | 851 userOption.value = -1; |
842 this.userApnIndex_ = this.selectedApnIndex_; | 852 this.insertApnUserOption_(userOption); |
| 853 } |
| 854 }, |
| 855 |
| 856 /** |
| 857 * Helper method called from initializeDetailsPage to initialize the Apn |
| 858 * list. |
| 859 * @private |
| 860 */ |
| 861 initializeApnList_: function() { |
| 862 this.selectedApnIndex_ = -1; |
| 863 this.userApnIndex_ = -1; |
| 864 |
| 865 var onc = this.onc_; |
| 866 var apnSelector = $('select-apn'); |
| 867 |
| 868 // Clear APN lists, keep only last element, 'other'. |
| 869 while (apnSelector.length != 1) |
| 870 apnSelector.remove(0); |
| 871 |
| 872 var apnList = onc.getActiveValue('Cellular.APNList'); |
| 873 if (apnList) { |
| 874 // Populate the list with the existing APNs. |
| 875 this.populateApnList_(apnList); |
| 876 } else { |
| 877 // Create a single 'default' entry. |
| 878 var otherOption = apnSelector[0]; |
| 879 var defaultOption = document.createElement('option'); |
| 880 defaultOption.textContent = |
| 881 loadTimeData.getString('cellularApnUseDefault'); |
| 882 defaultOption.value = -1; |
| 883 // Add 'default' entry before 'other' option |
| 884 apnSelector.add(defaultOption, otherOption); |
| 885 assert(apnSelector.length == 2); // 'default', 'other' |
| 886 this.selectedApnIndex_ = 0; // Select 'default' |
843 } | 887 } |
844 assert(this.selectedApnIndex_ >= 0); | 888 assert(this.selectedApnIndex_ >= 0); |
845 apnSelector.selectedIndex = this.selectedApnIndex_; | 889 apnSelector.selectedIndex = this.selectedApnIndex_; |
846 updateHidden('.apn-list-view', false); | 890 updateHidden('.apn-list-view', false); |
847 updateHidden('.apn-details-view', true); | 891 updateHidden('.apn-details-view', true); |
848 }, | 892 }, |
849 | 893 |
850 /** | 894 /** |
| 895 * Helper function for setting APN properties. |
| 896 * @param {Object} apnValue Dictionary of APN properties. |
| 897 * @private |
| 898 */ |
| 899 setActiveApn_: function(apnValue) { |
| 900 var activeApn = {}; |
| 901 var apnName = apnValue['AccessPointName']; |
| 902 if (apnName) { |
| 903 activeApn['AccessPointName'] = apnName; |
| 904 activeApn['Username'] = stringFromValue(apnValue['Username']); |
| 905 activeApn['Password'] = stringFromValue(apnValue['Password']); |
| 906 } |
| 907 // Set the cached ONC data. |
| 908 this.onc_.setProperty('Cellular.APN', activeApn); |
| 909 // Set an ONC object with just the APN values. |
| 910 var oncData = new OncData({}); |
| 911 oncData.setProperty('Cellular.APN', activeApn); |
| 912 // TODO(stevenjb): chrome.networkingPrivate.setProperties |
| 913 chrome.send('setProperties', [this.servicePath_, oncData.getData()]); |
| 914 }, |
| 915 |
| 916 /** |
851 * Event Listener for the cellular-apn-use-default button. | 917 * Event Listener for the cellular-apn-use-default button. |
852 * @private | 918 * @private |
853 */ | 919 */ |
854 setDefaultApn_: function() { | 920 setDefaultApn_: function() { |
855 var onc = this.onc_; | |
856 var apnSelector = $('select-apn'); | 921 var apnSelector = $('select-apn'); |
857 | 922 |
| 923 // Remove the 'user' entry if it exists. |
858 if (this.userApnIndex_ != -1) { | 924 if (this.userApnIndex_ != -1) { |
| 925 assert(this.userApnIndex_ < apnSelector.length - 1); |
859 apnSelector.remove(this.userApnIndex_); | 926 apnSelector.remove(this.userApnIndex_); |
860 this.userApnIndex_ = -1; | 927 this.userApnIndex_ = -1; |
861 } | 928 } |
862 | 929 |
863 var iApn = -1; | 930 var apnList = this.onc_.getActiveValue('Cellular.APNList'); |
864 var apnList = onc.getActiveValue('Cellular.APNList'); | 931 var iApn = (apnList != undefined && apnList.length > 0) ? 0 : -1; |
865 if (apnList != undefined && apnList.length > 0) { | |
866 iApn = 0; | |
867 var defaultApn = 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 } | |
879 apnSelector.selectedIndex = iApn; | 932 apnSelector.selectedIndex = iApn; |
880 this.selectedApnIndex_ = iApn; | 933 this.selectedApnIndex_ = iApn; |
881 | 934 |
| 935 // Clear any user APN entry to inform Chrome to use the default APN. |
| 936 this.setActiveApn_({}); |
| 937 |
882 updateHidden('.apn-list-view', false); | 938 updateHidden('.apn-list-view', false); |
883 updateHidden('.apn-details-view', true); | 939 updateHidden('.apn-details-view', true); |
884 }, | 940 }, |
885 | 941 |
886 /** | 942 /** |
887 * Event Listener for the cellular-apn-set button. | 943 * Event Listener for the cellular-apn-set button. |
888 * @private | 944 * @private |
889 */ | 945 */ |
890 setApn_: function(apnValue) { | 946 setApn_: function(apnValue) { |
891 if (apnValue == '') | 947 if (apnValue == '') |
892 return; | 948 return; |
893 | 949 |
894 var onc = this.onc_; | |
895 var apnSelector = $('select-apn'); | 950 var apnSelector = $('select-apn'); |
896 | 951 |
897 var activeApn = {}; | 952 var activeApn = {}; |
898 activeApn['AccessPointName'] = stringFromValue(apnValue); | 953 activeApn['AccessPointName'] = stringFromValue(apnValue); |
899 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); | 954 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); |
900 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); | 955 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); |
901 onc.setProperty('Cellular.APN', activeApn); | 956 this.setActiveApn_(activeApn); |
| 957 // Set the user selected APN. |
902 this.userApn_ = activeApn; | 958 this.userApn_ = activeApn; |
903 chrome.send('setApn', [this.servicePath_, | |
904 activeApn['AccessPointName'], | |
905 activeApn['Username'], | |
906 activeApn['Password']]); | |
907 | 959 |
| 960 // Remove any existing 'user' entry. |
908 if (this.userApnIndex_ != -1) { | 961 if (this.userApnIndex_ != -1) { |
| 962 assert(this.userApnIndex_ < apnSelector.length - 1); |
909 apnSelector.remove(this.userApnIndex_); | 963 apnSelector.remove(this.userApnIndex_); |
910 this.userApnIndex_ = -1; | 964 this.userApnIndex_ = -1; |
911 } | 965 } |
912 | 966 |
| 967 // Create a new 'user' entry with the new active apn. |
913 var option = document.createElement('option'); | 968 var option = document.createElement('option'); |
914 option.textContent = activeApn['AccessPointName']; | 969 option.textContent = activeApn['AccessPointName']; |
915 option.value = -1; | 970 option.value = -1; |
916 option.selected = true; | 971 option.selected = true; |
917 apnSelector.add(option, apnSelector[apnSelector.length - 1]); | 972 this.insertApnUserOption_(option); |
918 this.userApnIndex_ = apnSelector.length - 2; | |
919 this.selectedApnIndex_ = this.userApnIndex_; | |
920 | 973 |
921 updateHidden('.apn-list-view', false); | 974 updateHidden('.apn-list-view', false); |
922 updateHidden('.apn-details-view', true); | 975 updateHidden('.apn-details-view', true); |
923 }, | 976 }, |
924 | 977 |
925 /** | 978 /** |
926 * Event Listener for the cellular-apn-cancel button. | 979 * Event Listener for the cellular-apn-cancel button. |
927 * @private | 980 * @private |
928 */ | 981 */ |
929 cancelApn_: function() { | 982 cancelApn_: function() { |
930 $('select-apn').selectedIndex = this.selectedApnIndex_; | 983 this.initializeApnList_(); |
931 updateHidden('.apn-list-view', false); | |
932 updateHidden('.apn-details-view', true); | |
933 }, | 984 }, |
934 | 985 |
935 /** | 986 /** |
936 * Event Listener for the select-apn button. | 987 * Event Listener for the select-apn button. |
937 * @private | 988 * @private |
938 */ | 989 */ |
939 selectApn_: function() { | 990 selectApn_: function() { |
940 var onc = this.onc_; | 991 var onc = this.onc_; |
941 var apnSelector = $('select-apn'); | 992 var apnSelector = $('select-apn'); |
942 var apnDict; | |
943 if (apnSelector[apnSelector.selectedIndex].value != -1) { | 993 if (apnSelector[apnSelector.selectedIndex].value != -1) { |
944 var apnList = onc.getActiveValue('Cellular.APNList'); | 994 var apnList = onc.getActiveValue('Cellular.APNList'); |
945 var apnIndex = apnSelector.selectedIndex; | 995 var apnIndex = apnSelector.selectedIndex; |
946 assert(apnIndex < apnList.length); | 996 assert(apnIndex < apnList.length); |
947 apnDict = apnList[apnIndex]; | |
948 chrome.send('setApn', [this.servicePath_, | |
949 stringFromValue(apnDict['AccessPointName']), | |
950 stringFromValue(apnDict['Username']), | |
951 stringFromValue(apnDict['Password'])]); | |
952 this.selectedApnIndex_ = apnIndex; | 997 this.selectedApnIndex_ = apnIndex; |
| 998 this.setActiveApn_(apnList[apnIndex]); |
953 } else if (apnSelector.selectedIndex == this.userApnIndex_) { | 999 } else if (apnSelector.selectedIndex == this.userApnIndex_) { |
954 apnDict = this.userApn_; | |
955 chrome.send('setApn', [this.servicePath_, | |
956 stringFromValue(apnDict['AccessPointName']), | |
957 stringFromValue(apnDict['Username']), | |
958 stringFromValue(apnDict['Password'])]); | |
959 this.selectedApnIndex_ = apnSelector.selectedIndex; | 1000 this.selectedApnIndex_ = apnSelector.selectedIndex; |
960 } else { | 1001 this.setActiveApn_(this.userApn_); |
961 $('cellular-apn').value = | 1002 } else { // 'Other' |
962 stringFromValue(onc.getActiveValue('Cellular.APN.AccessPointName')); | 1003 var apnDict; |
963 $('cellular-apn-username').value = | 1004 if (this.userApn_['AccessPointName']) { |
964 stringFromValue(onc.getActiveValue('Cellular.APN.Username')); | 1005 // Fill in the details fields with the existing 'user' config. |
965 $('cellular-apn-password').value = | 1006 apnDict = this.userApn_; |
966 stringFromValue(onc.getActiveValue('Cellular.APN.Password')); | 1007 } else { |
| 1008 // No 'user' config, use the current values. |
| 1009 apnDict = {}; |
| 1010 apnDict['AccessPointName'] = |
| 1011 onc.getActiveValue('Cellular.APN.AccessPointName'); |
| 1012 apnDict['Username'] = onc.getActiveValue('Cellular.APN.Username'); |
| 1013 apnDict['Password'] = onc.getActiveValue('Cellular.APN.Password'); |
| 1014 } |
| 1015 $('cellular-apn').value = stringFromValue(apnDict['AccessPointName']); |
| 1016 $('cellular-apn-username').value = stringFromValue(apnDict['Username']); |
| 1017 $('cellular-apn-password').value = stringFromValue(apnDict['Password']); |
967 updateHidden('.apn-list-view', true); | 1018 updateHidden('.apn-list-view', true); |
968 updateHidden('.apn-details-view', false); | 1019 updateHidden('.apn-details-view', false); |
969 } | 1020 } |
970 } | 1021 } |
971 }; | 1022 }; |
972 | 1023 |
973 /** | 1024 /** |
974 * Enables or Disables all buttons that provide operations on the cellular | 1025 * Enables or Disables all buttons that provide operations on the cellular |
975 * network. | 1026 * network. |
976 */ | 1027 */ |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 | 1703 |
1653 // Don't show page name in address bar and in history to prevent people | 1704 // 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. | 1705 // navigate here by hand and solve issue with page session restore. |
1655 PageManager.showPageByName('detailsInternetPage', false); | 1706 PageManager.showPageByName('detailsInternetPage', false); |
1656 }; | 1707 }; |
1657 | 1708 |
1658 return { | 1709 return { |
1659 DetailsInternetPage: DetailsInternetPage | 1710 DetailsInternetPage: DetailsInternetPage |
1660 }; | 1711 }; |
1661 }); | 1712 }); |
OLD | NEW |