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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 | 82 |
83 /** | 83 /** |
84 * @param {string} action An action to send to coreOptionsUserMetricsAction. | 84 * @param {string} action An action to send to coreOptionsUserMetricsAction. |
85 */ | 85 */ |
86 function sendChromeMetricsAction(action) { | 86 function sendChromeMetricsAction(action) { |
87 chrome.send('coreOptionsUserMetricsAction', [action]); | 87 chrome.send('coreOptionsUserMetricsAction', [action]); |
88 } | 88 } |
89 | 89 |
90 /** | 90 /** |
91 * Sends the 'checked' state of a control to chrome for a network. | |
92 * @param {string} path The service path of the network. | |
93 * @param {string} message The message to send to chrome. | |
94 * @param {string} checkboxId The id of the checkbox with the value to send. | |
95 * @param {string=} opt_action Optional action to record. | |
96 */ | |
97 function sendCheckedIfEnabled(path, message, checkboxId, opt_action) { | |
98 var checkbox = assertInstanceof($(checkboxId), HTMLInputElement); | |
99 if (!checkbox.hidden && !checkbox.disabled) { | |
100 chrome.send(message, [path, !!checkbox.checked]); | |
101 if (opt_action) | |
102 sendChromeMetricsAction(opt_action); | |
103 } | |
104 } | |
105 | |
106 /** | |
107 * Send metrics to Chrome when the detailed page is opened. | 91 * Send metrics to Chrome when the detailed page is opened. |
108 * @param {string} type The ONC type of the network being shown. | 92 * @param {string} type The ONC type of the network being shown. |
109 * @param {string} state The ONC network state. | 93 * @param {string} state The ONC network state. |
110 */ | 94 */ |
111 function sendShowDetailsMetrics(type, state) { | 95 function sendShowDetailsMetrics(type, state) { |
112 if (type == 'WiFi') { | 96 if (type == 'WiFi') { |
113 sendChromeMetricsAction('Options_NetworkShowDetailsWifi'); | 97 sendChromeMetricsAction('Options_NetworkShowDetailsWifi'); |
114 if (state != 'NotConnected') | 98 if (state != 'NotConnected') |
115 sendChromeMetricsAction('Options_NetworkShowDetailsWifiConnected'); | 99 sendChromeMetricsAction('Options_NetworkShowDetailsWifiConnected'); |
116 } else if (type == 'Cellular') { | 100 } else if (type == 'Cellular') { |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 var iApn = -1; | 811 var iApn = -1; |
828 var apnList = onc.getActiveValue('Cellular.APNList'); | 812 var apnList = onc.getActiveValue('Cellular.APNList'); |
829 if (apnList != undefined && apnList.length > 0) { | 813 if (apnList != undefined && apnList.length > 0) { |
830 iApn = 0; | 814 iApn = 0; |
831 var defaultApn = apnList[iApn]; | 815 var defaultApn = apnList[iApn]; |
832 var activeApn = {}; | 816 var activeApn = {}; |
833 activeApn['AccessPointName'] = | 817 activeApn['AccessPointName'] = |
834 stringFromValue(defaultApn['AccessPointName']); | 818 stringFromValue(defaultApn['AccessPointName']); |
835 activeApn['Username'] = stringFromValue(defaultApn['Username']); | 819 activeApn['Username'] = stringFromValue(defaultApn['Username']); |
836 activeApn['Password'] = stringFromValue(defaultApn['Password']); | 820 activeApn['Password'] = stringFromValue(defaultApn['Password']); |
837 onc.setManagedProperty('Cellular.APN', activeApn); | 821 onc.setProperty('Cellular.APN', activeApn); |
838 chrome.send('setApn', [this.servicePath_, | 822 chrome.send('setApn', [this.servicePath_, |
839 activeApn['AccessPointName'], | 823 activeApn['AccessPointName'], |
840 activeApn['Username'], | 824 activeApn['Username'], |
841 activeApn['Password']]); | 825 activeApn['Password']]); |
842 } | 826 } |
843 apnSelector.selectedIndex = iApn; | 827 apnSelector.selectedIndex = iApn; |
844 this.selectedApnIndex_ = iApn; | 828 this.selectedApnIndex_ = iApn; |
845 | 829 |
846 updateHidden('.apn-list-view', false); | 830 updateHidden('.apn-list-view', false); |
847 updateHidden('.apn-details-view', true); | 831 updateHidden('.apn-details-view', true); |
848 }, | 832 }, |
849 | 833 |
850 /** | 834 /** |
851 * Event Listener for the cellular-apn-set button. | 835 * Event Listener for the cellular-apn-set button. |
852 * @private | 836 * @private |
853 */ | 837 */ |
854 setApn_: function(apnValue) { | 838 setApn_: function(apnValue) { |
855 if (apnValue == '') | 839 if (apnValue == '') |
856 return; | 840 return; |
857 | 841 |
858 var onc = this.onc_; | 842 var onc = this.onc_; |
859 var apnSelector = $('select-apn'); | 843 var apnSelector = $('select-apn'); |
860 | 844 |
861 var activeApn = {}; | 845 var activeApn = {}; |
862 activeApn['AccessPointName'] = stringFromValue(apnValue); | 846 activeApn['AccessPointName'] = stringFromValue(apnValue); |
863 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); | 847 activeApn['Username'] = stringFromValue($('cellular-apn-username').value); |
864 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); | 848 activeApn['Password'] = stringFromValue($('cellular-apn-password').value); |
865 onc.setManagedProperty('Cellular.APN', activeApn); | 849 onc.setProperty('Cellular.APN', activeApn); |
866 this.userApn_ = activeApn; | 850 this.userApn_ = activeApn; |
867 chrome.send('setApn', [this.servicePath_, | 851 chrome.send('setApn', [this.servicePath_, |
868 activeApn['AccessPointName'], | 852 activeApn['AccessPointName'], |
869 activeApn['Username'], | 853 activeApn['Username'], |
870 activeApn['Password']]); | 854 activeApn['Password']]); |
871 | 855 |
872 if (this.userApnIndex_ != -1) { | 856 if (this.userApnIndex_ != -1) { |
873 apnSelector.remove(this.userApnIndex_); | 857 apnSelector.remove(this.userApnIndex_); |
874 this.userApnIndex_ = -1; | 858 this.userApnIndex_ = -1; |
875 } | 859 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 }; | 1063 }; |
1080 | 1064 |
1081 /** | 1065 /** |
1082 * Event handler called when the details page is closed. Sends changed | 1066 * Event handler called when the details page is closed. Sends changed |
1083 * properties to Chrome and closes the overlay. | 1067 * properties to Chrome and closes the overlay. |
1084 */ | 1068 */ |
1085 DetailsInternetPage.setDetails = function() { | 1069 DetailsInternetPage.setDetails = function() { |
1086 var detailsPage = DetailsInternetPage.getInstance(); | 1070 var detailsPage = DetailsInternetPage.getInstance(); |
1087 var type = detailsPage.type_; | 1071 var type = detailsPage.type_; |
1088 var servicePath = detailsPage.servicePath_; | 1072 var servicePath = detailsPage.servicePath_; |
| 1073 var oncData = new OncData({}); |
| 1074 var autoConnectCheckboxId = ''; |
1089 if (type == 'WiFi') { | 1075 if (type == 'WiFi') { |
1090 sendCheckedIfEnabled(servicePath, | 1076 var preferredCheckbox = |
1091 'setPreferNetwork', | 1077 assertInstanceof($('prefer-network-wifi'), HTMLInputElement); |
1092 'prefer-network-wifi', | 1078 if (!preferredCheckbox.hidden && !preferredCheckbox.disabled) { |
1093 'Options_NetworkSetPrefer'); | 1079 var kPreferredPriority = 1; |
1094 sendCheckedIfEnabled(servicePath, | 1080 var priority = preferredCheckbox.checked ? kPreferredPriority : 0; |
1095 'setAutoConnect', | 1081 oncData.setProperty('Priority', priority); |
1096 'auto-connect-network-wifi', | 1082 sendChromeMetricsAction('Options_NetworkSetPrefer'); |
1097 'Options_NetworkAutoConnect'); | 1083 } |
| 1084 autoConnectCheckboxId = 'auto-connect-network-wifi'; |
1098 } else if (type == 'WiMAX') { | 1085 } else if (type == 'WiMAX') { |
1099 sendCheckedIfEnabled(servicePath, | 1086 autoConnectCheckboxId = 'auto-connect-network-wimax'; |
1100 'setAutoConnect', | |
1101 'auto-connect-network-wimax', | |
1102 'Options_NetworkAutoConnect'); | |
1103 } else if (type == 'Cellular') { | 1087 } else if (type == 'Cellular') { |
1104 sendCheckedIfEnabled(servicePath, | 1088 autoConnectCheckboxId = 'auto-connect-network-cellular'; |
1105 'setAutoConnect', | |
1106 'auto-connect-network-cellular', | |
1107 'Options_NetworkAutoConnect'); | |
1108 } else if (type == 'VPN') { | 1089 } else if (type == 'VPN') { |
1109 chrome.send('setServerHostname', | 1090 oncData.setProperty('VPN.Host', $('inet-server-hostname').value); |
1110 [servicePath, $('inet-server-hostname').value]); | 1091 autoConnectCheckboxId = 'auto-connect-network-vpn'; |
1111 sendCheckedIfEnabled(servicePath, | 1092 } |
1112 'setAutoConnect', | 1093 if (autoConnectCheckboxId != '') { |
1113 'auto-connect-network-vpn', | 1094 var autoConnectCheckbox = |
1114 'Options_NetworkAutoConnect'); | 1095 assertInstanceof($(autoConnectCheckboxId), HTMLInputElement); |
| 1096 if (!autoConnectCheckbox.hidden && !autoConnectCheckbox.disabled) { |
| 1097 var autoConnectKey = type + '.AutoConnect'; |
| 1098 oncData.setProperty(autoConnectKey, !!autoConnectCheckbox.checked); |
| 1099 sendChromeMetricsAction('Options_NetworkAutoConnect'); |
| 1100 } |
1115 } | 1101 } |
1116 | 1102 |
1117 var nameServerTypes = ['automatic', 'google', 'user']; | 1103 var nameServerTypes = ['automatic', 'google', 'user']; |
1118 var nameServerType = 'automatic'; | 1104 var nameServerType = 'automatic'; |
1119 for (var i = 0; i < nameServerTypes.length; ++i) { | 1105 for (var i = 0; i < nameServerTypes.length; ++i) { |
1120 if ($(nameServerTypes[i] + '-dns-radio').checked) { | 1106 if ($(nameServerTypes[i] + '-dns-radio').checked) { |
1121 nameServerType = nameServerTypes[i]; | 1107 nameServerType = nameServerTypes[i]; |
1122 break; | 1108 break; |
1123 } | 1109 } |
1124 } | 1110 } |
1125 detailsPage.sendIpConfig_(nameServerType); | 1111 detailsPage.sendIpConfig_(nameServerType); |
1126 | 1112 |
| 1113 var data = oncData.getData(); |
| 1114 if (Object.keys(data).length > 0) { |
| 1115 // TODO(stevenjb): chrome.networkingPrivate.setProperties |
| 1116 chrome.send('setProperties', [servicePath, data]); |
| 1117 } |
| 1118 |
1127 PageManager.closeOverlay(); | 1119 PageManager.closeOverlay(); |
1128 }; | 1120 }; |
1129 | 1121 |
1130 /** | 1122 /** |
1131 * Event handler called when the name server type changes. | 1123 * Event handler called when the name server type changes. |
1132 * @param {string} type The selected name sever type, 'automatic', 'google', | 1124 * @param {string} type The selected name sever type, 'automatic', 'google', |
1133 * or 'user'. | 1125 * or 'user'. |
1134 */ | 1126 */ |
1135 DetailsInternetPage.updateNameServerDisplay = function(type) { | 1127 DetailsInternetPage.updateNameServerDisplay = function(type) { |
1136 var editable = type == 'user'; | 1128 var editable = type == 'user'; |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 | 1587 |
1596 // Don't show page name in address bar and in history to prevent people | 1588 // Don't show page name in address bar and in history to prevent people |
1597 // navigate here by hand and solve issue with page session restore. | 1589 // navigate here by hand and solve issue with page session restore. |
1598 PageManager.showPageByName('detailsInternetPage', false); | 1590 PageManager.showPageByName('detailsInternetPage', false); |
1599 }; | 1591 }; |
1600 | 1592 |
1601 return { | 1593 return { |
1602 DetailsInternetPage: DetailsInternetPage | 1594 DetailsInternetPage: DetailsInternetPage |
1603 }; | 1595 }; |
1604 }); | 1596 }); |
OLD | NEW |