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 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/chromeos/options/network_property_ui_data.h" | 24 #include "chrome/browser/chromeos/options/network_property_ui_data.h" |
25 #include "chrome/browser/chromeos/settings/cros_settings.h" | 25 #include "chrome/browser/chromeos/settings/cros_settings.h" |
26 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 26 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
27 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" | 27 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" |
28 #include "chrome/browser/chromeos/ui/mobile_config_ui.h" | 28 #include "chrome/browser/chromeos/ui/mobile_config_ui.h" |
29 #include "chrome/browser/chromeos/ui_proxy_config_service.h" | 29 #include "chrome/browser/chromeos/ui_proxy_config_service.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" | 31 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" |
32 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri
ngs.h" | 32 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri
ngs.h" |
33 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
| 34 #include "chromeos/login/login_state.h" |
34 #include "chromeos/network/device_state.h" | 35 #include "chromeos/network/device_state.h" |
35 #include "chromeos/network/managed_network_configuration_handler.h" | 36 #include "chromeos/network/managed_network_configuration_handler.h" |
36 #include "chromeos/network/network_configuration_handler.h" | 37 #include "chromeos/network/network_configuration_handler.h" |
37 #include "chromeos/network/network_connection_handler.h" | 38 #include "chromeos/network/network_connection_handler.h" |
38 #include "chromeos/network/network_device_handler.h" | 39 #include "chromeos/network/network_device_handler.h" |
39 #include "chromeos/network/network_event_log.h" | 40 #include "chromeos/network/network_event_log.h" |
40 #include "chromeos/network/network_ip_config.h" | 41 #include "chromeos/network/network_ip_config.h" |
41 #include "chromeos/network/network_profile.h" | 42 #include "chromeos/network/network_profile.h" |
42 #include "chromeos/network/network_profile_handler.h" | 43 #include "chromeos/network/network_profile_handler.h" |
43 #include "chromeos/network/network_state.h" | 44 #include "chromeos/network/network_state.h" |
(...skipping 20 matching lines...) Expand all Loading... |
64 namespace options { | 65 namespace options { |
65 | 66 |
66 namespace { | 67 namespace { |
67 | 68 |
68 // Keys for the network description dictionary passed to the web ui. Make sure | 69 // Keys for the network description dictionary passed to the web ui. Make sure |
69 // to keep the strings in sync with what the JavaScript side uses. | 70 // to keep the strings in sync with what the JavaScript side uses. |
70 const char kNetworkInfoKeyIconURL[] = "iconURL"; | 71 const char kNetworkInfoKeyIconURL[] = "iconURL"; |
71 const char kNetworkInfoKeyServicePath[] = "servicePath"; | 72 const char kNetworkInfoKeyServicePath[] = "servicePath"; |
72 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; | 73 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; |
73 | 74 |
74 // These are keys for getting IP information from the web ui. | |
75 const char kIpConfigAddress[] = "address"; | |
76 const char kIpConfigPrefixLength[] = "prefixLength"; | |
77 const char kIpConfigNetmask[] = "netmask"; | |
78 const char kIpConfigGateway[] = "gateway"; | |
79 const char kIpConfigNameServers[] = "nameServers"; | |
80 const char kIpConfigAutoConfig[] = "ipAutoConfig"; | |
81 const char kIpConfigWebProxyAutoDiscoveryUrl[] = "webProxyAutoDiscoveryUrl"; | |
82 | |
83 // These are types of name server selections from the web ui. | 75 // These are types of name server selections from the web ui. |
84 const char kNameServerTypeAutomatic[] = "automatic"; | 76 const char kNameServerTypeAutomatic[] = "automatic"; |
85 const char kNameServerTypeGoogle[] = "google"; | 77 const char kNameServerTypeGoogle[] = "google"; |
86 const char kNameServerTypeUser[] = "user"; | |
87 | |
88 // These are dictionary names used to send data to the web ui. | |
89 const char kDictionaryIpConfig[] = "ipconfig"; | |
90 const char kDictionaryStaticIp[] = "staticIP"; | |
91 const char kDictionarySavedIp[] = "savedIP"; | |
92 | 78 |
93 // Google public name servers (DNS). | 79 // Google public name servers (DNS). |
94 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; | 80 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; |
95 | 81 |
96 // Functions we call in JavaScript. | 82 // Functions we call in JavaScript. |
97 const char kRefreshNetworkDataFunction[] = | 83 const char kRefreshNetworkDataFunction[] = |
98 "options.network.NetworkList.refreshNetworkData"; | 84 "options.network.NetworkList.refreshNetworkData"; |
99 const char kSetDefaultNetworkIconsFunction[] = | 85 const char kSetDefaultNetworkIconsFunction[] = |
100 "options.network.NetworkList.setDefaultNetworkIcons"; | 86 "options.network.NetworkList.setDefaultNetworkIcons"; |
101 const char kShowDetailedInfoFunction[] = | 87 const char kShowDetailedInfoFunction[] = |
(...skipping 26 matching lines...) Expand all Loading... |
128 // These are strings used to communicate with JavaScript. | 114 // These are strings used to communicate with JavaScript. |
129 const char kTagActivate[] = "activate"; | 115 const char kTagActivate[] = "activate"; |
130 const char kTagAddConnection[] = "add"; | 116 const char kTagAddConnection[] = "add"; |
131 const char kTagCarrierSelectFlag[] = "showCarrierSelect"; | 117 const char kTagCarrierSelectFlag[] = "showCarrierSelect"; |
132 const char kTagCarrierUrl[] = "carrierUrl"; | 118 const char kTagCarrierUrl[] = "carrierUrl"; |
133 const char kTagCellularAvailable[] = "cellularAvailable"; | 119 const char kTagCellularAvailable[] = "cellularAvailable"; |
134 const char kTagCellularEnabled[] = "cellularEnabled"; | 120 const char kTagCellularEnabled[] = "cellularEnabled"; |
135 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; | 121 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; |
136 const char kTagConfigure[] = "configure"; | 122 const char kTagConfigure[] = "configure"; |
137 const char kTagConnect[] = "connect"; | 123 const char kTagConnect[] = "connect"; |
138 const char kTagControlledBy[] = "controlledBy"; | |
139 const char kTagDeviceConnected[] = "deviceConnected"; | 124 const char kTagDeviceConnected[] = "deviceConnected"; |
140 const char kTagDisconnect[] = "disconnect"; | 125 const char kTagDisconnect[] = "disconnect"; |
141 const char kTagErrorMessage[] = "errorMessage"; | 126 const char kTagErrorMessage[] = "errorMessage"; |
142 const char kTagForget[] = "forget"; | 127 const char kTagForget[] = "forget"; |
143 const char kTagNameServersGoogle[] = "nameServersGoogle"; | |
144 const char kTagNameServerType[] = "nameServerType"; | |
145 const char kTagOptions[] = "options"; | 128 const char kTagOptions[] = "options"; |
146 const char kTagPolicy[] = "policy"; | |
147 const char kTagRecommended[] = "recommended"; | |
148 const char kTagRecommendedValue[] = "recommendedValue"; | |
149 const char kTagRemembered[] = "remembered"; | 129 const char kTagRemembered[] = "remembered"; |
150 const char kTagRememberedList[] = "rememberedList"; | 130 const char kTagRememberedList[] = "rememberedList"; |
151 const char kTagCarriers[] = "carriers"; | 131 const char kTagCarriers[] = "carriers"; |
152 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex"; | 132 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex"; |
153 const char kTagShared[] = "shared"; | 133 const char kTagShared[] = "shared"; |
154 const char kTagShowActivateButton[] = "showActivateButton"; | 134 const char kTagShowActivateButton[] = "showActivateButton"; |
155 const char kTagShowViewAccountButton[] = "showViewAccountButton"; | 135 const char kTagShowViewAccountButton[] = "showViewAccountButton"; |
156 const char kTagTrue[] = "true"; | 136 const char kTagTrue[] = "true"; |
157 const char kTagValue[] = "value"; | |
158 const char kTagVpnList[] = "vpnList"; | 137 const char kTagVpnList[] = "vpnList"; |
159 const char kTagWifiAvailable[] = "wifiAvailable"; | 138 const char kTagWifiAvailable[] = "wifiAvailable"; |
160 const char kTagWifiEnabled[] = "wifiEnabled"; | 139 const char kTagWifiEnabled[] = "wifiEnabled"; |
161 const char kTagWimaxAvailable[] = "wimaxAvailable"; | 140 const char kTagWimaxAvailable[] = "wimaxAvailable"; |
162 const char kTagWimaxEnabled[] = "wimaxEnabled"; | 141 const char kTagWimaxEnabled[] = "wimaxEnabled"; |
163 const char kTagWiredList[] = "wiredList"; | 142 const char kTagWiredList[] = "wiredList"; |
164 const char kTagWirelessList[] = "wirelessList"; | 143 const char kTagWirelessList[] = "wirelessList"; |
165 | 144 |
166 const int kPreferredPriority = 1; | 145 const int kPreferredPriority = 1; |
167 | 146 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 192 |
214 std::string icon_url = ui::network_icon::GetImageUrlForNetwork( | 193 std::string icon_url = ui::network_icon::GetImageUrlForNetwork( |
215 network, ui::network_icon::ICON_TYPE_LIST, icon_scale_factor); | 194 network, ui::network_icon::ICON_TYPE_LIST, icon_scale_factor); |
216 | 195 |
217 network_info->SetString(kNetworkInfoKeyIconURL, icon_url); | 196 network_info->SetString(kNetworkInfoKeyIconURL, icon_url); |
218 network_info->SetString(kNetworkInfoKeyServicePath, network->path()); | 197 network_info->SetString(kNetworkInfoKeyServicePath, network->path()); |
219 | 198 |
220 return network_info.release(); | 199 return network_info.release(); |
221 } | 200 } |
222 | 201 |
223 // Pulls IP information out of a shill service properties dictionary. If | |
224 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it | |
225 // fetches "SavedIP.*" properties. Caller must take ownership of returned | |
226 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number | |
227 // of IP routing parameters that get set. | |
228 base::DictionaryValue* BuildIPInfoDictionary( | |
229 const base::DictionaryValue& shill_properties, | |
230 bool static_ip, | |
231 int* routing_parameters_set) { | |
232 std::string address_key; | |
233 std::string prefix_len_key; | |
234 std::string gateway_key; | |
235 std::string name_servers_key; | |
236 if (static_ip) { | |
237 address_key = shill::kStaticIPAddressProperty; | |
238 prefix_len_key = shill::kStaticIPPrefixlenProperty; | |
239 gateway_key = shill::kStaticIPGatewayProperty; | |
240 name_servers_key = shill::kStaticIPNameServersProperty; | |
241 } else { | |
242 address_key = shill::kSavedIPAddressProperty; | |
243 prefix_len_key = shill::kSavedIPPrefixlenProperty; | |
244 gateway_key = shill::kSavedIPGatewayProperty; | |
245 name_servers_key = shill::kSavedIPNameServersProperty; | |
246 } | |
247 | |
248 scoped_ptr<base::DictionaryValue> ip_info_dict(new base::DictionaryValue); | |
249 std::string address; | |
250 int routing_parameters = 0; | |
251 if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) { | |
252 ip_info_dict->SetString(kIpConfigAddress, address); | |
253 VLOG(2) << "Found " << address_key << ": " << address; | |
254 routing_parameters++; | |
255 } | |
256 int prefix_len = -1; | |
257 if (shill_properties.GetIntegerWithoutPathExpansion( | |
258 prefix_len_key, &prefix_len)) { | |
259 ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len); | |
260 std::string netmask = network_util::PrefixLengthToNetmask(prefix_len); | |
261 ip_info_dict->SetString(kIpConfigNetmask, netmask); | |
262 VLOG(2) << "Found " << prefix_len_key << ": " | |
263 << prefix_len << " (" << netmask << ")"; | |
264 routing_parameters++; | |
265 } | |
266 std::string gateway; | |
267 if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) { | |
268 ip_info_dict->SetString(kIpConfigGateway, gateway); | |
269 VLOG(2) << "Found " << gateway_key << ": " << gateway; | |
270 routing_parameters++; | |
271 } | |
272 if (routing_parameters_set) | |
273 *routing_parameters_set = routing_parameters; | |
274 | |
275 std::string name_servers; | |
276 if (shill_properties.GetStringWithoutPathExpansion( | |
277 name_servers_key, &name_servers)) { | |
278 ip_info_dict->SetString(kIpConfigNameServers, name_servers); | |
279 VLOG(2) << "Found " << name_servers_key << ": " << name_servers; | |
280 } | |
281 | |
282 return ip_info_dict.release(); | |
283 } | |
284 | |
285 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and | |
286 // store it under |key| in |settings|. Takes ownership of |value|. | |
287 void SetValueDictionary(const char* key, | |
288 base::Value* value, | |
289 const NetworkPropertyUIData& ui_data, | |
290 base::DictionaryValue* settings) { | |
291 base::DictionaryValue* dict = new base::DictionaryValue(); | |
292 // DictionaryValue::Set() takes ownership of |value|. | |
293 dict->Set(kTagValue, value); | |
294 settings->Set(key, dict); | |
295 | |
296 const base::Value* recommended_value = ui_data.default_value(); | |
297 if (ui_data.IsManaged()) | |
298 dict->SetString(kTagControlledBy, kTagPolicy); | |
299 else if (recommended_value && recommended_value->Equals(value)) | |
300 dict->SetString(kTagControlledBy, kTagRecommended); | |
301 | |
302 if (recommended_value) | |
303 dict->Set(kTagRecommendedValue, recommended_value->DeepCopy()); | |
304 } | |
305 | |
306 const char* GetOncPolicyString(::onc::ONCSource onc_source) { | |
307 if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY) | |
308 return ::onc::kAugmentationDevicePolicy; | |
309 return ::onc::kAugmentationUserPolicy; | |
310 } | |
311 | |
312 const char* GetOncEditableString(::onc::ONCSource onc_source) { | |
313 if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY) | |
314 return ::onc::kAugmentationDeviceEditable; | |
315 return ::onc::kAugmentationUserEditable; | |
316 } | |
317 | |
318 const char* GetOncSettingString(::onc::ONCSource onc_source) { | |
319 if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY) | |
320 return ::onc::kAugmentationSharedSetting; | |
321 return ::onc::kAugmentationUserSetting; | |
322 } | |
323 | |
324 // Creates a GetManagedProperties style dictionary and adds it to |settings|. | |
325 // |default_value| represents either the recommended value if |recommended| | |
326 // is true, or the enforced value if |recommended| is false. |settings_dict_key| | |
327 // is expected to be an ONC key with no '.' in it. | |
328 // Note(stevenjb): This is bridge code until we use GetManagedProperties to | |
329 // retrieve Shill properties. | |
330 void SetManagedValueDictionaryEx(const char* settings_dict_key, | |
331 const base::Value& value, | |
332 ::onc::ONCSource onc_source, | |
333 bool recommended, | |
334 const base::Value* default_value, | |
335 base::DictionaryValue* settings_dict) { | |
336 base::DictionaryValue* dict = new base::DictionaryValue(); | |
337 settings_dict->SetWithoutPathExpansion(settings_dict_key, dict); | |
338 | |
339 dict->Set(::onc::kAugmentationActiveSetting, value.DeepCopy()); | |
340 | |
341 if (onc_source == ::onc::ONC_SOURCE_NONE) | |
342 return; | |
343 | |
344 if (recommended) { | |
345 // If an ONC property is 'Recommended' it can be edited by the user. | |
346 std::string editable = GetOncEditableString(onc_source); | |
347 dict->Set(editable, new base::FundamentalValue(true)); | |
348 } | |
349 if (default_value) { | |
350 std::string policy_source = GetOncPolicyString(onc_source); | |
351 dict->Set(policy_source, default_value->DeepCopy()); | |
352 if (recommended && !value.Equals(default_value)) { | |
353 std::string setting_source = GetOncSettingString(onc_source); | |
354 dict->Set(setting_source, value.DeepCopy()); | |
355 dict->SetString(::onc::kAugmentationEffectiveSetting, setting_source); | |
356 } else { | |
357 dict->SetString(::onc::kAugmentationEffectiveSetting, policy_source); | |
358 } | |
359 } | |
360 } | |
361 | |
362 // Wrapper for SetManagedValueDictionaryEx that does the policy lookup. | |
363 // Note: We have to pass |onc_key| separately from |settings_dict_key| since | |
364 // we might be populating a sub-dictionary in which case |onc_key| will be the | |
365 // complete path (e.g. 'VPN.Host') and |settings_dict_key| is the dictionary key | |
366 // (e.g. 'Host'). | |
367 void SetManagedValueDictionary(const std::string& guid, | |
368 const char* settings_dict_key, | |
369 const base::Value& value, | |
370 const std::string& onc_key, | |
371 base::DictionaryValue* settings_dict) { | |
372 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE; | |
373 const base::DictionaryValue* onc = | |
374 onc::FindPolicyForActiveUser(guid, &onc_source); | |
375 DCHECK_EQ(onc == NULL, onc_source == ::onc::ONC_SOURCE_NONE); | |
376 const base::Value* default_value = NULL; | |
377 bool recommended = false; | |
378 if (onc) { | |
379 onc->Get(onc_key, &default_value); | |
380 recommended = onc::IsRecommendedValue(onc, onc_key); | |
381 } | |
382 SetManagedValueDictionaryEx(settings_dict_key, | |
383 value, | |
384 onc_source, | |
385 recommended, | |
386 default_value, | |
387 settings_dict); | |
388 } | |
389 | |
390 // Fills |dictionary| with the configuration details of |vpn|. |onc| is required | |
391 // for augmenting the policy-managed information. | |
392 void PopulateVPNDetails(const NetworkState* vpn, | |
393 const base::DictionaryValue& shill_properties, | |
394 base::DictionaryValue* dictionary) { | |
395 // Name and Remembered are set in PopulateConnectionDetails(). | |
396 // Provider properties are stored in the "Provider" dictionary. | |
397 const base::DictionaryValue* shill_provider_properties = NULL; | |
398 if (!shill_properties.GetDictionaryWithoutPathExpansion( | |
399 shill::kProviderProperty, &shill_provider_properties)) { | |
400 LOG(ERROR) << "No provider properties for VPN: " << vpn->path(); | |
401 return; | |
402 } | |
403 base::DictionaryValue* vpn_dictionary; | |
404 if (!dictionary->GetDictionary( | |
405 ::onc::network_config::kVPN, &vpn_dictionary)) { | |
406 vpn_dictionary = new base::DictionaryValue; | |
407 dictionary->Set(::onc::network_config::kVPN, vpn_dictionary); | |
408 } | |
409 std::string shill_provider_type; | |
410 if (!shill_provider_properties->GetStringWithoutPathExpansion( | |
411 shill::kTypeProperty, &shill_provider_type)) { | |
412 LOG(ERROR) << "Shill VPN has no Provider.Type: " << vpn->path(); | |
413 return; | |
414 } | |
415 std::string provider_type_key; | |
416 if (shill_provider_type == shill::kProviderOpenVpn) | |
417 provider_type_key = ::onc::vpn::kOpenVPN; | |
418 else | |
419 provider_type_key = ::onc::vpn::kL2TP; | |
420 | |
421 base::DictionaryValue* provider_type_dictionary; | |
422 if (!vpn_dictionary->GetDictionary( | |
423 provider_type_key, &provider_type_dictionary)) { | |
424 provider_type_dictionary = new base::DictionaryValue; | |
425 vpn_dictionary->Set(provider_type_key, provider_type_dictionary); | |
426 } | |
427 std::string provider_host; | |
428 shill_provider_properties->GetStringWithoutPathExpansion( | |
429 shill::kHostProperty, &provider_host); | |
430 SetManagedValueDictionary( | |
431 vpn->guid(), | |
432 ::onc::vpn::kHost, | |
433 base::StringValue(provider_host), | |
434 ::onc::network_config::VpnProperty(::onc::vpn::kHost), | |
435 vpn_dictionary); | |
436 } | |
437 | |
438 // Given a list of supported carrier's by the device, return the index of | 202 // Given a list of supported carrier's by the device, return the index of |
439 // the carrier the device is currently using. | 203 // the carrier the device is currently using. |
440 int FindCurrentCarrierIndex(const base::ListValue* carriers, | 204 int FindCurrentCarrierIndex(const base::ListValue* carriers, |
441 const DeviceState* device) { | 205 const DeviceState* device) { |
442 DCHECK(carriers); | 206 DCHECK(carriers); |
443 DCHECK(device); | 207 DCHECK(device); |
444 bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm); | 208 bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm); |
445 int index = 0; | 209 int index = 0; |
446 for (base::ListValue::const_iterator it = carriers->begin(); | 210 for (base::ListValue::const_iterator it = carriers->begin(); |
447 it != carriers->end(); ++it, ++index) { | 211 it != carriers->end(); ++it, ++index) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 // The button will trigger ShowMorePlanInfoCallback() which will open | 304 // The button will trigger ShowMorePlanInfoCallback() which will open |
541 // carrier specific portal. | 305 // carrier specific portal. |
542 if (cellular->IsConnectedState() || force_show_view_account_button) | 306 if (cellular->IsConnectedState() || force_show_view_account_button) |
543 dictionary->SetBoolean(kTagShowViewAccountButton, true); | 307 dictionary->SetBoolean(kTagShowViewAccountButton, true); |
544 } | 308 } |
545 } | 309 } |
546 } | 310 } |
547 | 311 |
548 scoped_ptr<base::DictionaryValue> PopulateConnectionDetails( | 312 scoped_ptr<base::DictionaryValue> PopulateConnectionDetails( |
549 const NetworkState* network, | 313 const NetworkState* network, |
550 const base::DictionaryValue& shill_properties) { | 314 const base::DictionaryValue& onc_properties) { |
551 // TODO(stevenjb): Once we eliminate all references to Shill properties, | 315 scoped_ptr<base::DictionaryValue> dictionary(onc_properties.DeepCopy()); |
552 // we can switch to using managed_network_configuration_handler which | |
553 // includes Device properties for Cellular (and skip the call to | |
554 // onc::TranslateShillServiceToONCPart). For now we copy them over here. | |
555 scoped_ptr<base::DictionaryValue> shill_properties_with_device( | |
556 shill_properties.DeepCopy()); | |
557 const DeviceState* device = | |
558 NetworkHandler::Get()->network_state_handler()->GetDeviceState( | |
559 network->device_path()); | |
560 if (device) { | |
561 shill_properties_with_device->SetWithoutPathExpansion( | |
562 shill::kDeviceProperty, device->properties().DeepCopy()); | |
563 // Get the hardware MAC address from the DeviceState. | |
564 // (Note: this is done in ManagedNetworkConfigurationHandler but not | |
565 // in NetworkConfigurationHandler). | |
566 if (!device->mac_address().empty()) { | |
567 shill_properties_with_device->SetStringWithoutPathExpansion( | |
568 shill::kAddressProperty, device->mac_address()); | |
569 } | |
570 } | |
571 scoped_ptr<base::DictionaryValue> dictionary = | |
572 onc::TranslateShillServiceToONCPart( | |
573 *shill_properties_with_device, &onc::kNetworkWithStateSignature); | |
574 ::onc::TranslateOncStrings(dictionary.get()); | 316 ::onc::TranslateOncStrings(dictionary.get()); |
575 | 317 |
576 dictionary->SetString(kNetworkInfoKeyServicePath, network->path()); | 318 dictionary->SetString(kNetworkInfoKeyServicePath, network->path()); |
577 dictionary->SetString( | 319 dictionary->SetString( |
578 kTagErrorMessage, | 320 kTagErrorMessage, |
579 ash::network_connect::ErrorString(network->error(), network->path())); | 321 ash::network_connect::ErrorString(network->error(), network->path())); |
580 | 322 |
581 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty()); | 323 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty()); |
582 bool shared = !network->IsPrivate(); | 324 bool shared = !network->IsPrivate(); |
583 dictionary->SetBoolean(kTagShared, shared); | 325 dictionary->SetBoolean(kTagShared, shared); |
584 | 326 |
585 const std::string& type = network->type(); | 327 const std::string& type = network->type(); |
586 | 328 |
587 const NetworkState* connected_network = | 329 const NetworkState* connected_network = |
588 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( | 330 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( |
589 NetworkTypePattern::Primitive(type)); | 331 NetworkTypePattern::Primitive(type)); |
590 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); | 332 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); |
591 | 333 |
592 if (type == shill::kTypeCellular) | 334 if (type == shill::kTypeCellular) |
593 PopulateCellularDetails(network, dictionary.get()); | 335 PopulateCellularDetails(network, dictionary.get()); |
594 else if (type == shill::kTypeVPN) | |
595 PopulateVPNDetails(network, shill_properties, dictionary.get()); | |
596 | 336 |
597 return dictionary.Pass(); | 337 return dictionary.Pass(); |
598 } | 338 } |
599 | 339 |
600 // Helper methods for SetIPConfigProperties | 340 // Helper methods for SetIPConfigProperties |
601 bool AppendPropertyKeyIfPresent(const std::string& key, | 341 bool AppendPropertyKeyIfPresent(const std::string& key, |
602 const base::DictionaryValue& old_properties, | 342 const base::DictionaryValue& old_properties, |
603 std::vector<std::string>* property_keys) { | 343 std::vector<std::string>* property_keys) { |
604 if (old_properties.HasKey(key)) { | 344 if (old_properties.HasKey(key)) { |
605 property_keys->push_back(key); | 345 property_keys->push_back(key); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 } | 708 } |
969 | 709 |
970 void InternetOptionsHandler::RefreshNetworkData() { | 710 void InternetOptionsHandler::RefreshNetworkData() { |
971 base::DictionaryValue dictionary; | 711 base::DictionaryValue dictionary; |
972 FillNetworkInfo(&dictionary); | 712 FillNetworkInfo(&dictionary); |
973 web_ui()->CallJavascriptFunction(kRefreshNetworkDataFunction, dictionary); | 713 web_ui()->CallJavascriptFunction(kRefreshNetworkDataFunction, dictionary); |
974 } | 714 } |
975 | 715 |
976 void InternetOptionsHandler::UpdateConnectionData( | 716 void InternetOptionsHandler::UpdateConnectionData( |
977 const std::string& service_path) { | 717 const std::string& service_path) { |
978 NetworkHandler::Get()->network_configuration_handler()->GetProperties( | 718 NetworkHandler::Get() |
979 service_path, | 719 ->managed_network_configuration_handler() |
980 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback, | 720 ->GetManagedProperties( |
981 weak_factory_.GetWeakPtr()), | 721 LoginState::Get()->primary_user_hash(), |
982 base::Bind(&ShillError, "UpdateConnectionData")); | 722 service_path, |
| 723 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback, |
| 724 weak_factory_.GetWeakPtr()), |
| 725 base::Bind(&ShillError, "UpdateConnectionData")); |
983 } | 726 } |
984 | 727 |
985 void InternetOptionsHandler::UpdateConnectionDataCallback( | 728 void InternetOptionsHandler::UpdateConnectionDataCallback( |
986 const std::string& service_path, | 729 const std::string& service_path, |
987 const base::DictionaryValue& shill_properties) { | 730 const base::DictionaryValue& onc_properties) { |
988 const NetworkState* network = GetNetworkState(service_path); | 731 const NetworkState* network = GetNetworkState(service_path); |
989 if (!network) | 732 if (!network) |
990 return; | 733 return; |
991 scoped_ptr<base::DictionaryValue> dictionary = | 734 scoped_ptr<base::DictionaryValue> dictionary = |
992 PopulateConnectionDetails(network, shill_properties); | 735 PopulateConnectionDetails(network, onc_properties); |
993 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, *dictionary); | 736 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, *dictionary); |
994 } | 737 } |
995 | 738 |
996 void InternetOptionsHandler::UpdateCarrier() { | 739 void InternetOptionsHandler::UpdateCarrier() { |
997 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction); | 740 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction); |
998 } | 741 } |
999 | 742 |
1000 void InternetOptionsHandler::DeviceListChanged() { | 743 void InternetOptionsHandler::DeviceListChanged() { |
1001 if (!web_ui()) | 744 if (!web_ui()) |
1002 return; | 745 return; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 callback = base::Bind(&RequestReconnect, service_path, GetNativeWindow()); | 925 callback = base::Bind(&RequestReconnect, service_path, GetNativeWindow()); |
1183 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs( | 926 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs( |
1184 device_path, | 927 device_path, |
1185 callback, | 928 callback, |
1186 base::Bind(&ShillError, "RequestRefreshIPConfigs")); | 929 base::Bind(&ShillError, "RequestRefreshIPConfigs")); |
1187 } | 930 } |
1188 } | 931 } |
1189 | 932 |
1190 void InternetOptionsHandler::PopulateDictionaryDetailsCallback( | 933 void InternetOptionsHandler::PopulateDictionaryDetailsCallback( |
1191 const std::string& service_path, | 934 const std::string& service_path, |
1192 const base::DictionaryValue& shill_properties) { | 935 const base::DictionaryValue& onc_properties) { |
1193 const NetworkState* network = GetNetworkState(service_path); | 936 const NetworkState* network = GetNetworkState(service_path); |
1194 if (!network) { | 937 if (!network) { |
1195 LOG(ERROR) << "Network properties not found: " << service_path; | 938 LOG(ERROR) << "Network properties not found: " << service_path; |
1196 return; | 939 return; |
1197 } | 940 } |
1198 | 941 |
1199 details_path_ = service_path; | 942 details_path_ = service_path; |
1200 | 943 |
1201 scoped_ptr<base::DictionaryValue> dictionary = | 944 scoped_ptr<base::DictionaryValue> dictionary = |
1202 PopulateConnectionDetails(network, shill_properties); | 945 PopulateConnectionDetails(network, onc_properties); |
1203 | 946 |
1204 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE; | |
1205 const base::DictionaryValue* onc = | |
1206 onc::FindPolicyForActiveUser(network->guid(), &onc_source); | |
1207 const NetworkPropertyUIData property_ui_data(onc_source); | |
1208 | |
1209 // IP config | |
1210 scoped_ptr<base::DictionaryValue> ipconfig_dhcp(new base::DictionaryValue); | |
1211 ipconfig_dhcp->SetString(kIpConfigAddress, network->ip_address()); | |
1212 ipconfig_dhcp->SetString(kIpConfigNetmask, network->GetNetmask()); | |
1213 ipconfig_dhcp->SetString(kIpConfigGateway, network->gateway()); | |
1214 std::string ipconfig_name_servers = network->GetDnsServersAsString(); | |
1215 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers); | |
1216 ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl, | |
1217 network->web_proxy_auto_discovery_url().spec()); | |
1218 SetValueDictionary(kDictionaryIpConfig, | |
1219 ipconfig_dhcp.release(), | |
1220 property_ui_data, | |
1221 dictionary.get()); | |
1222 | |
1223 std::string name_server_type = kNameServerTypeAutomatic; | |
1224 int automatic_ip_config = 0; | |
1225 scoped_ptr<base::DictionaryValue> static_ip_dict( | |
1226 BuildIPInfoDictionary(shill_properties, true, &automatic_ip_config)); | |
1227 dictionary->SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0); | |
1228 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0) | |
1229 << "UI doesn't support automatic specification of individual " | |
1230 << "static IP parameters."; | |
1231 scoped_ptr<base::DictionaryValue> saved_ip_dict( | |
1232 BuildIPInfoDictionary(shill_properties, false, NULL)); | |
1233 dictionary->Set(kDictionarySavedIp, saved_ip_dict.release()); | |
1234 | |
1235 // Determine what kind of name server setting we have by comparing the | |
1236 // StaticIP and Google values with the ipconfig values. | |
1237 std::string static_ip_nameservers; | |
1238 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers); | |
1239 if (!static_ip_nameservers.empty() && | |
1240 static_ip_nameservers == ipconfig_name_servers) { | |
1241 name_server_type = kNameServerTypeUser; | |
1242 } | |
1243 if (ipconfig_name_servers == kGoogleNameServers) { | |
1244 name_server_type = kNameServerTypeGoogle; | |
1245 } | |
1246 SetValueDictionary(kDictionaryStaticIp, | |
1247 static_ip_dict.release(), | |
1248 property_ui_data, | |
1249 dictionary.get()); | |
1250 | |
1251 dictionary->SetString(kTagNameServerType, name_server_type); | |
1252 dictionary->SetString(kTagNameServersGoogle, kGoogleNameServers); | |
1253 | |
1254 int priority = 0; | |
1255 shill_properties.GetIntegerWithoutPathExpansion( | |
1256 shill::kPriorityProperty, &priority); | |
1257 SetManagedValueDictionary(network->guid(), | |
1258 ::onc::network_config::kPriority, | |
1259 base::FundamentalValue(priority), | |
1260 ::onc::network_config::kPriority, | |
1261 dictionary.get()); | |
1262 | |
1263 std::string onc_path_to_auto_connect; | |
1264 if (network->Matches(NetworkTypePattern::WiFi())) { | 947 if (network->Matches(NetworkTypePattern::WiFi())) { |
1265 content::RecordAction( | 948 content::RecordAction( |
1266 base::UserMetricsAction("Options_NetworkShowDetailsWifi")); | 949 base::UserMetricsAction("Options_NetworkShowDetailsWifi")); |
1267 if (network->IsConnectedState()) { | 950 if (network->IsConnectedState()) { |
1268 content::RecordAction( | 951 content::RecordAction( |
1269 base::UserMetricsAction("Options_NetworkShowDetailsWifiConnected")); | 952 base::UserMetricsAction("Options_NetworkShowDetailsWifiConnected")); |
1270 } | 953 } |
1271 onc_path_to_auto_connect = | |
1272 ::onc::network_config::WifiProperty(::onc::wifi::kAutoConnect); | |
1273 } else if (network->Matches(NetworkTypePattern::VPN())) { | 954 } else if (network->Matches(NetworkTypePattern::VPN())) { |
1274 content::RecordAction( | 955 content::RecordAction( |
1275 base::UserMetricsAction("Options_NetworkShowDetailsVPN")); | 956 base::UserMetricsAction("Options_NetworkShowDetailsVPN")); |
1276 if (network->IsConnectedState()) { | 957 if (network->IsConnectedState()) { |
1277 content::RecordAction( | 958 content::RecordAction( |
1278 base::UserMetricsAction("Options_NetworkShowDetailsVPNConnected")); | 959 base::UserMetricsAction("Options_NetworkShowDetailsVPNConnected")); |
1279 } | 960 } |
1280 onc_path_to_auto_connect = ::onc::network_config::VpnProperty( | |
1281 ::onc::vpn::kAutoConnect); | |
1282 } else if (network->Matches(NetworkTypePattern::Cellular())) { | 961 } else if (network->Matches(NetworkTypePattern::Cellular())) { |
1283 content::RecordAction( | 962 content::RecordAction( |
1284 base::UserMetricsAction("Options_NetworkShowDetailsCellular")); | 963 base::UserMetricsAction("Options_NetworkShowDetailsCellular")); |
1285 if (network->IsConnectedState()) { | 964 if (network->IsConnectedState()) { |
1286 content::RecordAction(base::UserMetricsAction( | 965 content::RecordAction(base::UserMetricsAction( |
1287 "Options_NetworkShowDetailsCellularConnected")); | 966 "Options_NetworkShowDetailsCellularConnected")); |
1288 } | 967 } |
1289 } | 968 } |
1290 | 969 |
1291 if (!onc_path_to_auto_connect.empty()) { | |
1292 bool auto_connect = false; | |
1293 shill_properties.GetBooleanWithoutPathExpansion( | |
1294 shill::kAutoConnectProperty, &auto_connect); | |
1295 | |
1296 base::FundamentalValue auto_connect_value(auto_connect); | |
1297 ::onc::ONCSource auto_connect_onc_source = onc_source; | |
1298 | |
1299 DCHECK_EQ(onc == NULL, onc_source == ::onc::ONC_SOURCE_NONE); | |
1300 bool auto_connect_recommended = | |
1301 auto_connect_onc_source != ::onc::ONC_SOURCE_NONE && | |
1302 onc::IsRecommendedValue(onc, onc_path_to_auto_connect); | |
1303 // If a policy exists, |auto_connect_default_value| will contain either a | |
1304 // recommended value (if |auto_connect_recommended| is true) or an enforced | |
1305 // value (if |auto_connect_recommended| is false). | |
1306 const base::Value* auto_connect_default_value = NULL; | |
1307 if (onc) | |
1308 onc->Get(onc_path_to_auto_connect, &auto_connect_default_value); | |
1309 | |
1310 // Autoconnect can be controlled by the GlobalNetworkConfiguration of the | |
1311 // ONC policy. | |
1312 if (auto_connect_onc_source == ::onc::ONC_SOURCE_NONE && | |
1313 onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect( | |
1314 network->IsPrivate())) { | |
1315 auto_connect_recommended = false; | |
1316 auto_connect_onc_source = network->IsPrivate() | |
1317 ? ::onc::ONC_SOURCE_USER_POLICY | |
1318 : ::onc::ONC_SOURCE_DEVICE_POLICY; | |
1319 if (auto_connect) { | |
1320 LOG(WARNING) << "Policy prevents autoconnect, but value is True."; | |
1321 auto_connect_value = base::FundamentalValue(false); | |
1322 } | |
1323 } | |
1324 SetManagedValueDictionaryEx(shill::kAutoConnectProperty, | |
1325 auto_connect_value, | |
1326 auto_connect_onc_source, | |
1327 auto_connect_recommended, | |
1328 auto_connect_default_value, | |
1329 dictionary.get()); | |
1330 } | |
1331 | |
1332 // Show details dialog | 970 // Show details dialog |
1333 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary); | 971 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary); |
1334 } | 972 } |
1335 | 973 |
1336 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { | 974 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { |
1337 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 975 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
1338 } | 976 } |
1339 | 977 |
1340 float InternetOptionsHandler::GetScaleFactor() const { | 978 float InternetOptionsHandler::GetScaleFactor() const { |
1341 return web_ui()->GetDeviceScaleFactor(); | 979 return web_ui()->GetDeviceScaleFactor(); |
(...skipping 24 matching lines...) Expand all Loading... |
1366 // Process commands that do not require an existing network. | 1004 // Process commands that do not require an existing network. |
1367 if (command == kTagAddConnection) { | 1005 if (command == kTagAddConnection) { |
1368 AddConnection(type); | 1006 AddConnection(type); |
1369 } else if (command == kTagForget) { | 1007 } else if (command == kTagForget) { |
1370 NetworkHandler::Get()->network_configuration_handler()-> | 1008 NetworkHandler::Get()->network_configuration_handler()-> |
1371 RemoveConfiguration( | 1009 RemoveConfiguration( |
1372 service_path, | 1010 service_path, |
1373 base::Bind(&base::DoNothing), | 1011 base::Bind(&base::DoNothing), |
1374 base::Bind(&ShillError, "NetworkCommand: " + command)); | 1012 base::Bind(&ShillError, "NetworkCommand: " + command)); |
1375 } else if (command == kTagOptions) { | 1013 } else if (command == kTagOptions) { |
1376 NetworkHandler::Get()->network_configuration_handler()->GetProperties( | 1014 NetworkHandler::Get() |
1377 service_path, | 1015 ->managed_network_configuration_handler() |
1378 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, | 1016 ->GetManagedProperties( |
1379 weak_factory_.GetWeakPtr()), | 1017 LoginState::Get()->primary_user_hash(), |
1380 base::Bind(&ShillError, "NetworkCommand: " + command)); | 1018 service_path, |
| 1019 base::Bind( |
| 1020 &InternetOptionsHandler::PopulateDictionaryDetailsCallback, |
| 1021 weak_factory_.GetWeakPtr()), |
| 1022 base::Bind(&ShillError, "NetworkCommand: " + command)); |
1381 } else if (command == kTagConnect) { | 1023 } else if (command == kTagConnect) { |
1382 const NetworkState* network = GetNetworkState(service_path); | 1024 const NetworkState* network = GetNetworkState(service_path); |
1383 if (network && network->type() == shill::kTypeWifi) | 1025 if (network && network->type() == shill::kTypeWifi) |
1384 content::RecordAction( | 1026 content::RecordAction( |
1385 base::UserMetricsAction("Options_NetworkConnectToWifi")); | 1027 base::UserMetricsAction("Options_NetworkConnectToWifi")); |
1386 else if (network && network->type() == shill::kTypeVPN) | 1028 else if (network && network->type() == shill::kTypeVPN) |
1387 content::RecordAction( | 1029 content::RecordAction( |
1388 base::UserMetricsAction("Options_NetworkConnectToVPN")); | 1030 base::UserMetricsAction("Options_NetworkConnectToVPN")); |
1389 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow()); | 1031 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow()); |
1390 } else if (command == kTagDisconnect) { | 1032 } else if (command == kTagDisconnect) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 dictionary->SetBoolean( | 1163 dictionary->SetBoolean( |
1522 kTagWimaxAvailable, | 1164 kTagWimaxAvailable, |
1523 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); | 1165 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); |
1524 dictionary->SetBoolean( | 1166 dictionary->SetBoolean( |
1525 kTagWimaxEnabled, | 1167 kTagWimaxEnabled, |
1526 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); | 1168 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); |
1527 } | 1169 } |
1528 | 1170 |
1529 } // namespace options | 1171 } // namespace options |
1530 } // namespace chromeos | 1172 } // namespace chromeos |
OLD | NEW |