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 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 }; | 1060 }; |
1077 | 1061 |
1078 /** | 1062 /** |
1079 * Event handler called when the details page is closed. Sends changed | 1063 * Event handler called when the details page is closed. Sends changed |
1080 * properties to Chrome and closes the overlay. | 1064 * properties to Chrome and closes the overlay. |
1081 */ | 1065 */ |
1082 DetailsInternetPage.setDetails = function() { | 1066 DetailsInternetPage.setDetails = function() { |
1083 var detailsPage = DetailsInternetPage.getInstance(); | 1067 var detailsPage = DetailsInternetPage.getInstance(); |
1084 var type = detailsPage.type_; | 1068 var type = detailsPage.type_; |
1085 var servicePath = detailsPage.servicePath_; | 1069 var servicePath = detailsPage.servicePath_; |
| 1070 var oncData = new OncData({}); |
| 1071 var autoConnectCheckboxId = ''; |
1086 if (type == 'WiFi') { | 1072 if (type == 'WiFi') { |
1087 sendCheckedIfEnabled(servicePath, | 1073 var preferredCheckbox = |
1088 'setPreferNetwork', | 1074 assertInstanceof($('prefer-network-wifi'), HTMLInputElement); |
1089 'prefer-network-wifi', | 1075 if (!preferredCheckbox.hidden && !preferredCheckbox.disabled) { |
1090 'Options_NetworkSetPrefer'); | 1076 var kPreferredPriority = 1; |
1091 sendCheckedIfEnabled(servicePath, | 1077 var priority = preferredCheckbox.checked ? kPreferredPriority : 0; |
1092 'setAutoConnect', | 1078 oncData.setManagedProperty('Priority', priority); |
1093 'auto-connect-network-wifi', | 1079 sendChromeMetricsAction('Options_NetworkSetPrefer'); |
1094 'Options_NetworkAutoConnect'); | 1080 } |
| 1081 autoConnectCheckboxId = 'auto-connect-network-wifi'; |
1095 } else if (type == 'WiMAX') { | 1082 } else if (type == 'WiMAX') { |
1096 sendCheckedIfEnabled(servicePath, | 1083 autoConnectCheckboxId = 'auto-connect-network-wimax'; |
1097 'setAutoConnect', | |
1098 'auto-connect-network-wimax', | |
1099 'Options_NetworkAutoConnect'); | |
1100 } else if (type == 'Cellular') { | 1084 } else if (type == 'Cellular') { |
1101 sendCheckedIfEnabled(servicePath, | 1085 autoConnectCheckboxId = 'auto-connect-network-cellular'; |
1102 'setAutoConnect', | |
1103 'auto-connect-network-cellular', | |
1104 'Options_NetworkAutoConnect'); | |
1105 } else if (type == 'VPN') { | 1086 } else if (type == 'VPN') { |
1106 chrome.send('setServerHostname', | 1087 oncData.setManagedProperty('VPN.Host', $('inet-server-hostname').value); |
1107 [servicePath, $('inet-server-hostname').value]); | 1088 autoConnectCheckboxId = 'auto-connect-network-vpn'; |
1108 sendCheckedIfEnabled(servicePath, | 1089 } |
1109 'setAutoConnect', | 1090 if (autoConnectCheckboxId != '') { |
1110 'auto-connect-network-vpn', | 1091 var autoConnectCheckbox = |
1111 'Options_NetworkAutoConnect'); | 1092 assertInstanceof($(autoConnectCheckboxId), HTMLInputElement); |
| 1093 if (!autoConnectCheckbox.hidden && !autoConnectCheckbox.disabled) { |
| 1094 var autoConnectKey = type + '.AutoConnect'; |
| 1095 oncData.setManagedProperty(autoConnectKey, |
| 1096 !!autoConnectCheckbox.checked); |
| 1097 sendChromeMetricsAction('Options_NetworkAutoConnect'); |
| 1098 } |
1112 } | 1099 } |
1113 | 1100 |
1114 var nameServerTypes = ['automatic', 'google', 'user']; | 1101 var nameServerTypes = ['automatic', 'google', 'user']; |
1115 var nameServerType = 'automatic'; | 1102 var nameServerType = 'automatic'; |
1116 for (var i = 0; i < nameServerTypes.length; ++i) { | 1103 for (var i = 0; i < nameServerTypes.length; ++i) { |
1117 if ($(nameServerTypes[i] + '-dns-radio').checked) { | 1104 if ($(nameServerTypes[i] + '-dns-radio').checked) { |
1118 nameServerType = nameServerTypes[i]; | 1105 nameServerType = nameServerTypes[i]; |
1119 break; | 1106 break; |
1120 } | 1107 } |
1121 } | 1108 } |
1122 detailsPage.sendIpConfig_(nameServerType); | 1109 detailsPage.sendIpConfig_(nameServerType); |
1123 | 1110 |
| 1111 var data = oncData.getData(); |
| 1112 if (Object.keys(data).length > 0) { |
| 1113 // TODO(stevenjb): chrome.networkingPrivate.setProperties |
| 1114 chrome.send('setProperties', [servicePath, data]); |
| 1115 } |
| 1116 |
1124 PageManager.closeOverlay(); | 1117 PageManager.closeOverlay(); |
1125 }; | 1118 }; |
1126 | 1119 |
1127 /** | 1120 /** |
1128 * Event handler called when the name server type changes. | 1121 * Event handler called when the name server type changes. |
1129 * @param {string} type The selected name sever type, 'automatic', 'google', | 1122 * @param {string} type The selected name sever type, 'automatic', 'google', |
1130 * or 'user'. | 1123 * or 'user'. |
1131 */ | 1124 */ |
1132 DetailsInternetPage.updateNameServerDisplay = function(type) { | 1125 DetailsInternetPage.updateNameServerDisplay = function(type) { |
1133 var editable = type == 'user'; | 1126 var editable = type == 'user'; |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 | 1584 |
1592 // Don't show page name in address bar and in history to prevent people | 1585 // Don't show page name in address bar and in history to prevent people |
1593 // navigate here by hand and solve issue with page session restore. | 1586 // navigate here by hand and solve issue with page session restore. |
1594 PageManager.showPageByName('detailsInternetPage', false); | 1587 PageManager.showPageByName('detailsInternetPage', false); |
1595 }; | 1588 }; |
1596 | 1589 |
1597 return { | 1590 return { |
1598 DetailsInternetPage: DetailsInternetPage | 1591 DetailsInternetPage: DetailsInternetPage |
1599 }; | 1592 }; |
1600 }); | 1593 }); |
OLD | NEW |