Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: chrome/browser/resources/options/chromeos/internet_detail.js

Issue 700383008: Use setProperties for Cellular APN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_430113_internet_options_2
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 typeLabel.textContent = loadTimeData.getString(typeKey); 786 typeLabel.textContent = loadTimeData.getString(typeKey);
787 typeLabel.hidden = false; 787 typeLabel.hidden = false;
788 typeSeparator.hidden = false; 788 typeSeparator.hidden = false;
789 } else { 789 } else {
790 typeLabel.hidden = true; 790 typeLabel.hidden = true;
791 typeSeparator.hidden = true; 791 typeSeparator.hidden = true;
792 } 792 }
793 }, 793 },
794 794
795 /** 795 /**
796 * Helper method called from initializeDetailsPage to initialize the Apn 796 * Helper method called from initializeApnList to populate the Apn list.
797 * list. 797 * @param {Array} apnList List of available APNs.
798 * @private 798 * @private
799 */ 799 */
800 initializeApnList_: function() { 800 populateApnList_: function(apnList) {
801 var onc = this.onc_;
802
803 var apnSelector = $('select-apn'); 801 var apnSelector = $('select-apn');
804 // Clear APN lists, keep only last element that "other".
805 while (apnSelector.length != 1) {
806 apnSelector.remove(0);
807 }
808 var otherOption = apnSelector[0]; 802 var otherOption = apnSelector[0];
809 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); 803 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName');
810 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); 804 var activeUsername = onc.getActiveValue('Cellular.APN.Username');
811 var activePassword = onc.getActiveValue('Cellular.APN.Password'); 805 var activePassword = onc.getActiveValue('Cellular.APN.Password');
812 var lastGoodApn = 806 var lastGoodApn =
813 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName'); 807 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName');
814 var lastGoodUsername = 808 var lastGoodUsername =
815 onc.getActiveValue('Cellular.LastGoodAPN.Username'); 809 onc.getActiveValue('Cellular.LastGoodAPN.Username');
816 var lastGoodPassword = 810 var lastGoodPassword =
817 onc.getActiveValue('Cellular.LastGoodAPN.Password'); 811 onc.getActiveValue('Cellular.LastGoodAPN.Password');
818 var apnList = onc.getActiveValue('Cellular.APNList'); 812 var onc = this.onc_;
pneubeck (no reviews) 2014/12/01 13:54:10 used before declaration and not afterwards?
stevenjb 2015/01/09 20:10:59 Rebase conflict. Fixed.
819 for (var i = 0; i < apnList.length; i++) { 813 for (var i = 0; i < apnList.length; i++) {
820 var apnDict = apnList[i]; 814 var apnDict = apnList[i];
821 var option = document.createElement('option'); 815 var option = document.createElement('option');
822 var localizedName = apnDict['LocalizedName']; 816 var localizedName = apnDict['LocalizedName'];
823 var name = localizedName ? localizedName : apnDict['Name']; 817 var name = localizedName ? localizedName : apnDict['Name'];
824 var accessPointName = apnDict['AccessPointName']; 818 var accessPointName = apnDict['AccessPointName'];
825 option.textContent = 819 option.textContent =
826 name ? (name + ' (' + accessPointName + ')') : accessPointName; 820 name ? (name + ' (' + accessPointName + ')') : accessPointName;
827 option.value = i; 821 option.value = i;
828 // Insert new option before "other" option. 822 // Insert new option before "other" option.
(...skipping 12 matching lines...) Expand all
841 lastGoodPassword == apnDict['Password'])) { 835 lastGoodPassword == apnDict['Password'])) {
842 this.selectedApnIndex_ = i; 836 this.selectedApnIndex_ = i;
843 } 837 }
844 } 838 }
845 if (this.selectedApnIndex_ == -1 && activeApn) { 839 if (this.selectedApnIndex_ == -1 && activeApn) {
846 var activeOption = document.createElement('option'); 840 var activeOption = document.createElement('option');
847 activeOption.textContent = activeApn; 841 activeOption.textContent = activeApn;
848 activeOption.value = -1; 842 activeOption.value = -1;
849 apnSelector.add(activeOption, otherOption); 843 apnSelector.add(activeOption, otherOption);
850 this.selectedApnIndex_ = apnSelector.length - 2; 844 this.selectedApnIndex_ = apnSelector.length - 2;
851 this.userApnIndex_ = this.selectedApnIndex_; 845 }
846 },
847
848 /**
849 * Helper method called from initializeDetailsPage to initialize the Apn
850 * list.
851 * @private
852 */
853 initializeApnList_: function() {
854 var onc = this.onc_;
855
856 var apnSelector = $('select-apn');
857 // Clear APN lists, keep only last element that "other".
pneubeck (no reviews) 2014/12/01 13:54:10 i don't understand this sentence. could you rephra
stevenjb 2015/01/09 20:10:59 s/that/,/
858 while (apnSelector.length != 1) {
859 apnSelector.remove(0);
860 }
861 var apnList = onc.getActiveValue('Cellular.APNList');
862 if (apnList) {
863 this.populateApnList_(apnList);
864 } else {
865 var otherOption = apnSelector[0];
866 var activeOption = document.createElement('option');
867 activeOption.textContent =
868 loadTimeData.getString('cellularApnUseDefault');
869 activeOption.value = -1;
870 apnSelector.add(activeOption, otherOption);
871 this.selectedApnIndex_ = apnSelector.length - 2;
852 } 872 }
853 assert(this.selectedApnIndex_ >= 0); 873 assert(this.selectedApnIndex_ >= 0);
874 this.userApnIndex_ = this.selectedApnIndex_;
pneubeck (no reviews) 2014/12/01 13:54:10 before this change, userApnIndex_ was not modified
stevenjb 2015/01/09 20:10:59 Good catch, I'm not sure why/how this got moved he
854 apnSelector.selectedIndex = this.selectedApnIndex_; 875 apnSelector.selectedIndex = this.selectedApnIndex_;
855 updateHidden('.apn-list-view', false); 876 updateHidden('.apn-list-view', false);
856 updateHidden('.apn-details-view', true); 877 updateHidden('.apn-details-view', true);
857 }, 878 },
858 879
859 /** 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 = null;
887 var apnName = apnValue['AccessPointName'];
888 if (apnName) {
889 activeApn = {};
890 activeApn['AccessPointName'] = apnName;
891 activeApn['Username'] = stringFromValue(apnValue['Username']);
892 activeApn['Password'] = stringFromValue(apnValue['Password']);
893 }
894 // Set the cached ONC data.
895 this.onc_.setManagedProperty('Cellular.APN', activeApn);
pneubeck (no reviews) 2014/12/01 13:54:10 IIRC, this will change to setProperty after the ne
stevenjb 2015/01/09 20:10:59 Acknowledged.
896 // Set an ONC object with just the APN values.
897 var oncData = new OncData({});
898 oncData.setManagedProperty('Cellular.APN', activeApn);
pneubeck (no reviews) 2014/12/01 13:54:10 IIUC, you will change this from NULL to an 'Automa
stevenjb 2015/01/09 20:10:59 I will need to test whether or not we can send an
899 // TODO(stevenjb): chrome.networkingPrivate.setProperties
900 chrome.send('setProperties', [this.servicePath_, oncData.getData()]);
901 },
902
903 /**
860 * Event Listener for the cellular-apn-use-default button. 904 * Event Listener for the cellular-apn-use-default button.
861 * @private 905 * @private
862 */ 906 */
863 setDefaultApn_: function() { 907 setDefaultApn_: function() {
864 var onc = this.onc_;
865 var apnSelector = $('select-apn'); 908 var apnSelector = $('select-apn');
866 909
867 if (this.userApnIndex_ != -1) { 910 if (this.userApnIndex_ != -1) {
868 apnSelector.remove(this.userApnIndex_); 911 apnSelector.remove(this.userApnIndex_);
869 this.userApnIndex_ = -1; 912 this.userApnIndex_ = -1;
870 } 913 }
871 914
872 var iApn = -1; 915 var iApn = -1;
873 var apnList = onc.getActiveValue('Cellular.APNList'); 916 var apnList = this.onc_.getActiveValue('Cellular.APNList');
874 if (apnList != undefined && apnList.length > 0) { 917 if (apnList != undefined && apnList.length > 0) {
875 iApn = 0; 918 iApn = 0;
876 var defaultApn = apnList[iApn]; 919 this.setActiveApn_(apnList[iApn]);
877 var activeApn = {};
878 activeApn['AccessPointName'] =
879 stringFromValue(defaultApn['AccessPointName']);
880 activeApn['Username'] = stringFromValue(defaultApn['Username']);
881 activeApn['Password'] = stringFromValue(defaultApn['Password']);
882 onc.setManagedProperty('Cellular.APN', activeApn);
883 chrome.send('setApn', [this.servicePath_,
884 activeApn['AccessPointName'],
885 activeApn['Username'],
886 activeApn['Password']]);
887 } 920 }
888 apnSelector.selectedIndex = iApn; 921 apnSelector.selectedIndex = iApn;
889 this.selectedApnIndex_ = iApn; 922 this.selectedApnIndex_ = iApn;
890 923
891 updateHidden('.apn-list-view', false); 924 updateHidden('.apn-list-view', false);
892 updateHidden('.apn-details-view', true); 925 updateHidden('.apn-details-view', true);
893 }, 926 },
894 927
895 /** 928 /**
896 * Event Listener for the cellular-apn-set button. 929 * Event Listener for the cellular-apn-set button.
897 * @private 930 * @private
898 */ 931 */
899 setApn_: function(apnValue) { 932 setApn_: function(apnValue) {
900 if (apnValue == '') 933 if (apnValue == '')
901 return; 934 return;
902 935
903 var onc = this.onc_;
904 var apnSelector = $('select-apn'); 936 var apnSelector = $('select-apn');
905 937
906 var activeApn = {}; 938 var activeApn = {};
907 activeApn['AccessPointName'] = stringFromValue(apnValue); 939 activeApn['AccessPointName'] = stringFromValue(apnValue);
908 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); 940 activeApn['Username'] = stringFromValue($('cellular-apn-username').value);
909 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); 941 activeApn['Password'] = stringFromValue($('cellular-apn-password').value);
910 onc.setManagedProperty('Cellular.APN', activeApn); 942 this.setActiveApn_(activeApn);
943 // Set the user selected APN.
911 this.userApn_ = activeApn; 944 this.userApn_ = activeApn;
912 chrome.send('setApn', [this.servicePath_,
913 activeApn['AccessPointName'],
914 activeApn['Username'],
915 activeApn['Password']]);
916 945
917 if (this.userApnIndex_ != -1) { 946 if (this.userApnIndex_ != -1) {
pneubeck (no reviews) 2014/12/01 13:54:10 Sorry. Even after staring at this for a while, I h
stevenjb 2015/01/09 20:10:59 'userApnIndex_' points to a user defined entry in
918 apnSelector.remove(this.userApnIndex_); 947 apnSelector.remove(this.userApnIndex_);
919 this.userApnIndex_ = -1; 948 this.userApnIndex_ = -1;
920 } 949 }
921 950
922 var option = document.createElement('option'); 951 var option = document.createElement('option');
923 option.textContent = activeApn['AccessPointName']; 952 option.textContent = activeApn['AccessPointName'];
924 option.value = -1; 953 option.value = -1;
925 option.selected = true; 954 option.selected = true;
926 apnSelector.add(option, apnSelector[apnSelector.length - 1]); 955 apnSelector.add(option, apnSelector[apnSelector.length - 1]);
927 this.userApnIndex_ = apnSelector.length - 2; 956 this.userApnIndex_ = apnSelector.length - 2;
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 1679
1651 // Don't show page name in address bar and in history to prevent people 1680 // Don't show page name in address bar and in history to prevent people
1652 // navigate here by hand and solve issue with page session restore. 1681 // navigate here by hand and solve issue with page session restore.
1653 PageManager.showPageByName('detailsInternetPage', false); 1682 PageManager.showPageByName('detailsInternetPage', false);
1654 }; 1683 };
1655 1684
1656 return { 1685 return {
1657 DetailsInternetPage: DetailsInternetPage 1686 DetailsInternetPage: DetailsInternetPage
1658 }; 1687 };
1659 }); 1688 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698