Chromium Code Reviews| 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/options2/chromeos/internet_options_handler.h" | 5 #include "chrome/browser/ui/webui/options2/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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_delegate.h" | 14 #include "ash/shell_delegate.h" |
| 15 #include "base/base64.h" | 15 #include "base/base64.h" |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
| 19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/i18n/time_formatting.h" | 20 #include "base/i18n/time_formatting.h" |
| 21 #include "base/json/json_writer.h" | |
| 21 #include "base/string16.h" | 22 #include "base/string16.h" |
| 22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
| 23 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
| 24 #include "base/time.h" | 25 #include "base/time.h" |
| 25 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" | 29 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" |
| 29 #include "chrome/browser/chromeos/cros/cros_library.h" | 30 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 31 #include "chrome/browser/chromeos/cros/cros_network_functions.h" | |
| 30 #include "chrome/browser/chromeos/cros/network_library.h" | 32 #include "chrome/browser/chromeos/cros/network_library.h" |
| 31 #include "chrome/browser/chromeos/cros/onc_constants.h" | 33 #include "chrome/browser/chromeos/cros/onc_constants.h" |
| 32 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 34 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
| 33 #include "chrome/browser/chromeos/mobile_config.h" | 35 #include "chrome/browser/chromeos/mobile_config.h" |
| 34 #include "chrome/browser/chromeos/options/network_config_view.h" | 36 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 35 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 37 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 36 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 37 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 39 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 38 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 40 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 39 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 41 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
| 40 #include "chrome/browser/profiles/profile.h" | 42 #include "chrome/browser/profiles/profile.h" |
| 41 #include "chrome/browser/profiles/profile_manager.h" | 43 #include "chrome/browser/profiles/profile_manager.h" |
| 42 #include "chrome/browser/ui/browser.h" | 44 #include "chrome/browser/ui/browser.h" |
| 43 #include "chrome/browser/ui/browser_finder.h" | 45 #include "chrome/browser/ui/browser_finder.h" |
| 44 #include "chrome/browser/ui/browser_window.h" | 46 #include "chrome/browser/ui/browser_window.h" |
| 45 #include "chrome/browser/ui/singleton_tabs.h" | 47 #include "chrome/browser/ui/singleton_tabs.h" |
| 46 #include "chrome/browser/ui/webui/web_ui_util.h" | 48 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 47 #include "chrome/common/chrome_notification_types.h" | 49 #include "chrome/common/chrome_notification_types.h" |
| 48 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
| 49 #include "chrome/common/time_format.h" | 51 #include "chrome/common/time_format.h" |
| 50 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_ui.h" | 54 #include "content/public/browser/web_ui.h" |
| 53 #include "grit/chromium_strings.h" | 55 #include "grit/chromium_strings.h" |
| 54 #include "grit/generated_resources.h" | 56 #include "grit/generated_resources.h" |
| 55 #include "grit/locale_settings.h" | 57 #include "grit/locale_settings.h" |
| 56 #include "grit/theme_resources.h" | 58 #include "grit/theme_resources.h" |
| 59 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 57 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
| 58 #include "ui/base/layout.h" | 61 #include "ui/base/layout.h" |
| 59 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
| 60 #include "ui/gfx/display.h" | 63 #include "ui/gfx/display.h" |
| 61 #include "ui/gfx/image/image_skia.h" | 64 #include "ui/gfx/image/image_skia.h" |
| 62 #include "ui/gfx/screen.h" | 65 #include "ui/gfx/screen.h" |
| 63 #include "ui/views/widget/widget.h" | 66 #include "ui/views/widget/widget.h" |
| 64 | 67 |
| 65 namespace { | 68 namespace { |
| 66 | 69 |
| 67 static const char kOtherNetworksFakePath[] = "?"; | 70 static const char kOtherNetworksFakePath[] = "?"; |
| 68 | 71 |
| 69 // Keys for the network description dictionary passed to the web ui. Make sure | 72 // Keys for the network description dictionary passed to the web ui. Make sure |
| 70 // to keep the strings in sync with what the Javascript side uses. | 73 // to keep the strings in sync with what the Javascript side uses. |
| 71 const char kNetworkInfoKeyActivationState[] = "activation_state"; | 74 const char kNetworkInfoKeyActivationState[] = "activation_state"; |
| 72 const char kNetworkInfoKeyConnectable[] = "connectable"; | 75 const char kNetworkInfoKeyConnectable[] = "connectable"; |
| 73 const char kNetworkInfoKeyConnected[] = "connected"; | 76 const char kNetworkInfoKeyConnected[] = "connected"; |
| 74 const char kNetworkInfoKeyConnecting[] = "connecting"; | 77 const char kNetworkInfoKeyConnecting[] = "connecting"; |
| 75 const char kNetworkInfoKeyIconURL[] = "iconURL"; | 78 const char kNetworkInfoKeyIconURL[] = "iconURL"; |
| 76 const char kNetworkInfoKeyNeedsNewPlan[] = "needs_new_plan"; | 79 const char kNetworkInfoKeyNeedsNewPlan[] = "needs_new_plan"; |
| 77 const char kNetworkInfoKeyNetworkName[] = "networkName"; | 80 const char kNetworkInfoKeyNetworkName[] = "networkName"; |
| 78 const char kNetworkInfoKeyNetworkStatus[] = "networkStatus"; | 81 const char kNetworkInfoKeyNetworkStatus[] = "networkStatus"; |
| 79 const char kNetworkInfoKeyNetworkType[] = "networkType"; | 82 const char kNetworkInfoKeyNetworkType[] = "networkType"; |
| 80 const char kNetworkInfoKeyRemembered[] = "remembered"; | 83 const char kNetworkInfoKeyRemembered[] = "remembered"; |
| 81 const char kNetworkInfoKeyServicePath[] = "servicePath"; | 84 const char kNetworkInfoKeyServicePath[] = "servicePath"; |
| 82 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; | 85 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; |
| 83 | 86 |
| 87 // Google public name servers (DNS). | |
| 88 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; | |
| 89 | |
| 84 // A helper class for building network information dictionaries to be sent to | 90 // A helper class for building network information dictionaries to be sent to |
| 85 // the webui code. | 91 // the webui code. |
| 86 class NetworkInfoDictionary { | 92 class NetworkInfoDictionary { |
| 87 public: | 93 public: |
| 88 // Initializes the dictionary with default values. | 94 // Initializes the dictionary with default values. |
| 89 explicit NetworkInfoDictionary(float icon_scale); | 95 explicit NetworkInfoDictionary(float icon_scale); |
| 90 | 96 |
| 91 // Copies in service path, connect{ing|ed|able} flags and connection type from | 97 // Copies in service path, connect{ing|ed|able} flags and connection type from |
| 92 // the provided network object. Also chooses an appropriate icon based on the | 98 // the provided network object. Also chooses an appropriate icon based on the |
| 93 // network type. | 99 // network type. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 network_info->SetString(kNetworkInfoKeyNetworkName, name_); | 259 network_info->SetString(kNetworkInfoKeyNetworkName, name_); |
| 254 network_info->SetString(kNetworkInfoKeyNetworkStatus, status); | 260 network_info->SetString(kNetworkInfoKeyNetworkStatus, status); |
| 255 network_info->SetInteger(kNetworkInfoKeyNetworkType, | 261 network_info->SetInteger(kNetworkInfoKeyNetworkType, |
| 256 static_cast<int>(connection_type_)); | 262 static_cast<int>(connection_type_)); |
| 257 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_); | 263 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_); |
| 258 network_info->SetString(kNetworkInfoKeyServicePath, service_path_); | 264 network_info->SetString(kNetworkInfoKeyServicePath, service_path_); |
| 259 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_); | 265 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_); |
| 260 return network_info.release(); | 266 return network_info.release(); |
| 261 } | 267 } |
| 262 | 268 |
| 269 // Pulls IP information out of a shill service properties dictionary. If | |
| 270 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it | |
| 271 // fetches "SavedIP.*" properties. Caller must take ownership of returned | |
| 272 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number | |
| 273 // of IP routing parameters that get set. | |
| 274 DictionaryValue* BuildIPInfoDictionary(const DictionaryValue& shill_properties, | |
| 275 bool static_ip, | |
| 276 int* routing_parameters_set) { | |
| 277 std::string address_key; | |
| 278 std::string prefix_len_key; | |
| 279 std::string gateway_key; | |
| 280 std::string name_servers_key; | |
| 281 if (static_ip) { | |
| 282 address_key = shill::kStaticIPAddressProperty; | |
| 283 prefix_len_key = shill::kStaticIPPrefixlenProperty; | |
| 284 gateway_key = shill::kStaticIPGatewayProperty; | |
| 285 name_servers_key = shill::kStaticIPNameServersProperty; | |
| 286 } else { | |
| 287 address_key = shill::kSavedIPAddressProperty; | |
| 288 prefix_len_key = shill::kSavedIPPrefixlenProperty; | |
| 289 gateway_key = shill::kSavedIPGatewayProperty; | |
| 290 name_servers_key = shill::kSavedIPNameServersProperty; | |
| 291 } | |
| 292 | |
| 293 scoped_ptr<DictionaryValue> ip_info_dict(new DictionaryValue); | |
| 294 std::string value; | |
|
stevenjb
2012/08/13 17:43:44
nit: I think this would be more readable using sep
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done.
| |
| 295 int routing_parameters = 0; | |
| 296 if (shill_properties.GetStringWithoutPathExpansion(address_key, &value)) { | |
| 297 ip_info_dict->SetString("address", value); | |
|
stevenjb
2012/08/13 17:43:44
"address" and other JS (I assume?) keys should be
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done, but I'd like to point out that there are sev
stevenjb
2012/08/14 01:06:38
Thanks for doing these. Anything that is used as a
Greg Spencer (Chromium)
2012/08/14 01:19:27
OK, I do agree that they *should* be. I'll take a
| |
| 298 VLOG(2) << "Found " << address_key << ": " << value; | |
| 299 routing_parameters++; | |
| 300 } | |
| 301 int prefix_len = -1; | |
| 302 if (shill_properties.GetIntegerWithoutPathExpansion( | |
| 303 prefix_len_key, &prefix_len)) { | |
| 304 ip_info_dict->SetInteger("prefixLength", prefix_len); | |
| 305 ip_info_dict->SetString("netmask", | |
| 306 chromeos::CrosPrefixLengthToNetmask(prefix_len)); | |
| 307 VLOG(2) << "Found " << prefix_len_key << ": " | |
| 308 << prefix_len | |
| 309 << " (" << chromeos::CrosPrefixLengthToNetmask(prefix_len) << ")"; | |
| 310 routing_parameters++; | |
| 311 } | |
| 312 value.clear(); | |
| 313 if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &value)) { | |
| 314 ip_info_dict->SetString("gateway", value); | |
| 315 VLOG(2) << "Found " << gateway_key << ": " << value; | |
| 316 routing_parameters++; | |
| 317 } | |
| 318 if (routing_parameters_set) | |
| 319 *routing_parameters_set = routing_parameters; | |
| 320 | |
| 321 value.clear(); | |
| 322 if (shill_properties.GetStringWithoutPathExpansion( | |
| 323 name_servers_key, &value)) { | |
| 324 ip_info_dict->SetString("nameServers", value); | |
| 325 VLOG(2) << "Found " << name_servers_key << ": " << value; | |
| 326 } | |
| 327 | |
| 328 return ip_info_dict.release(); | |
| 329 } | |
| 330 | |
| 263 } // namespace | 331 } // namespace |
| 264 | 332 |
| 265 namespace options2 { | 333 namespace options2 { |
| 266 | 334 |
| 267 InternetOptionsHandler::InternetOptionsHandler() | 335 InternetOptionsHandler::InternetOptionsHandler() |
| 268 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 336 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 269 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, | 337 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, |
| 270 content::NotificationService::AllSources()); | 338 content::NotificationService::AllSources()); |
| 271 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED, | 339 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED, |
| 272 content::NotificationService::AllSources()); | 340 content::NotificationService::AllSources()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON }, | 399 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON }, |
| 332 { "managedNetwork", IDS_OPTIONS_SETTINGS_MANAGED_NETWORK }, | 400 { "managedNetwork", IDS_OPTIONS_SETTINGS_MANAGED_NETWORK }, |
| 333 { "wifiNetworkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, | 401 { "wifiNetworkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, |
| 334 { "vpnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN }, | 402 { "vpnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN }, |
| 335 { "cellularPlanTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PLAN }, | 403 { "cellularPlanTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PLAN }, |
| 336 { "cellularConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, | 404 { "cellularConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, |
| 337 { "cellularDeviceTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE }, | 405 { "cellularDeviceTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE }, |
| 338 { "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK }, | 406 { "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK }, |
| 339 { "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY }, | 407 { "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY }, |
| 340 { "proxyTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PROXY }, | 408 { "proxyTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PROXY }, |
| 341 { "useDHCP", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_DHCP }, | |
| 342 { "useStaticIP", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_STATIC_IP }, | |
| 343 { "connectionState", IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE }, | 409 { "connectionState", IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE }, |
| 344 { "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS }, | 410 { "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS }, |
| 345 { "inetSubnetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK }, | 411 { "inetNetmask", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK }, |
| 346 { "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY }, | 412 { "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY }, |
| 347 { "inetDns", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER }, | 413 { "inetNameServers", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER }, |
| 414 { "ipAutomaticConfiguration", | |
| 415 IDS_OPTIONS_SETTINGS_INTERNET_IP_AUTOMATIC_CONFIGURATION }, | |
| 416 { "automaticNameServers", | |
| 417 IDS_OPTIONS_SETTINGS_INTERNET_AUTOMATIC_NAME_SERVERS }, | |
| 418 { "userNameServer1", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_1 }, | |
| 419 { "userNameServer2", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_2 }, | |
| 420 { "userNameServer3", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_3 }, | |
| 421 { "userNameServer4", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_4 }, | |
| 422 { "googleNameServers", IDS_OPTIONS_SETTINGS_INTERNET_GOOGLE_NAME_SERVERS }, | |
| 423 { "userNameServers", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVERS }, | |
| 348 { "hardwareAddress", | 424 { "hardwareAddress", |
| 349 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS }, | 425 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS }, |
| 350 { "detailsInternetDismiss", IDS_CLOSE }, | 426 { "detailsInternetDismiss", IDS_CLOSE }, |
| 351 { "activateButton", IDS_OPTIONS_SETTINGS_ACTIVATE }, | 427 { "activateButton", IDS_OPTIONS_SETTINGS_ACTIVATE }, |
| 352 { "buyplanButton", IDS_OPTIONS_SETTINGS_BUY_PLAN }, | 428 { "buyplanButton", IDS_OPTIONS_SETTINGS_BUY_PLAN }, |
| 353 { "connectButton", IDS_OPTIONS_SETTINGS_CONNECT }, | 429 { "connectButton", IDS_OPTIONS_SETTINGS_CONNECT }, |
| 354 { "disconnectButton", IDS_OPTIONS_SETTINGS_DISCONNECT }, | 430 { "disconnectButton", IDS_OPTIONS_SETTINGS_DISCONNECT }, |
| 355 { "viewAccountButton", IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT }, | 431 { "viewAccountButton", IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT }, |
| 356 | 432 |
| 357 // TODO(zelidrag): Change details title to Wimax once we get strings. | 433 // TODO(zelidrag): Change details title to Wimax once we get strings. |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 804 if (!network) | 880 if (!network) |
| 805 return; | 881 return; |
| 806 | 882 |
| 807 bool auto_connect = auto_connect_str == "true"; | 883 bool auto_connect = auto_connect_str == "true"; |
| 808 if (auto_connect != network->auto_connect()) | 884 if (auto_connect != network->auto_connect()) |
| 809 network->SetAutoConnect(auto_connect); | 885 network->SetAutoConnect(auto_connect); |
| 810 } | 886 } |
| 811 | 887 |
| 812 void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) { | 888 void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) { |
| 813 std::string service_path; | 889 std::string service_path; |
| 814 std::string dhcp_str; | 890 std::string dhcp_for_ip; |
| 815 std::string address; | 891 std::string address; |
| 816 std::string netmask; | 892 std::string netmask; |
| 817 std::string gateway; | 893 std::string gateway; |
| 894 std::string name_server_type; | |
| 818 std::string name_servers; | 895 std::string name_servers; |
| 819 | 896 |
| 820 if (args->GetSize() < 6 || | 897 if (args->GetSize() < 7 || |
| 821 !args->GetString(0, &service_path) || | 898 !args->GetString(0, &service_path) || |
| 822 !args->GetString(1, &dhcp_str) || | 899 !args->GetString(1, &dhcp_for_ip) || |
| 823 !args->GetString(2, &address) || | 900 !args->GetString(2, &address) || |
| 824 !args->GetString(3, &netmask) || | 901 !args->GetString(3, &netmask) || |
| 825 !args->GetString(4, &gateway) || | 902 !args->GetString(4, &gateway) || |
| 826 !args->GetString(5, &name_servers)) { | 903 !args->GetString(5, &name_server_type) || |
| 904 !args->GetString(6, &name_servers)) { | |
| 827 NOTREACHED(); | 905 NOTREACHED(); |
| 828 return; | 906 return; |
| 829 } | 907 } |
| 830 | 908 |
| 831 chromeos::Network* network = cros_->FindNetworkByPath(service_path); | 909 int dhcp_usage_mask = 0; |
| 832 if (!network) | 910 if (dhcp_for_ip == "true") { |
| 833 return; | 911 dhcp_usage_mask = (chromeos::NetworkLibrary::USE_DHCP_ADDRESS | |
| 912 chromeos::NetworkLibrary::USE_DHCP_NETMASK | | |
| 913 chromeos::NetworkLibrary::USE_DHCP_GATEWAY); | |
| 914 } | |
| 915 if (name_server_type == "automatic") { | |
|
stevenjb
2012/08/13 17:43:44
nit: kNameServerTypeAutomatic
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done.
| |
| 916 dhcp_usage_mask |= chromeos::NetworkLibrary::USE_DHCP_NAME_SERVERS; | |
| 917 name_servers.clear(); | |
| 918 } else if (name_server_type == "google") { | |
|
stevenjb
2012/08/13 17:43:44
nit: kNameServerTypeGoogle
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done.
| |
| 919 name_servers = kGoogleNameServers; | |
| 920 } | |
| 834 | 921 |
| 835 cros_->SetIPConfig(chromeos::NetworkIPConfig(network->device_path(), | 922 cros_->SetIPParameters(service_path, |
| 836 dhcp_str == "true" ? chromeos::IPCONFIG_TYPE_DHCP : | 923 address, |
| 837 chromeos::IPCONFIG_TYPE_IPV4, | 924 netmask, |
| 838 address, netmask, gateway, name_servers)); | 925 gateway, |
| 926 name_servers, | |
| 927 dhcp_usage_mask); | |
| 839 } | 928 } |
| 840 | 929 |
| 841 void InternetOptionsHandler::PopulateDictionaryDetails( | 930 void InternetOptionsHandler::PopulateDictionaryDetails( |
| 842 const chromeos::Network* network) { | 931 const chromeos::Network* network) { |
| 843 DCHECK(network); | 932 DCHECK(network); |
| 844 | 933 |
| 934 // Send off an asynchronous request to Shill to get the service properties | |
| 935 // before we continue. | |
|
stevenjb
2012/08/13 17:43:44
nit: 'before we continue' implies waiting to me; '
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done.
| |
| 936 chromeos::CrosRequestNetworkServiceProperties( | |
| 937 network->service_path(), | |
| 938 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, | |
| 939 weak_factory_.GetWeakPtr(), network)); | |
| 940 } | |
| 941 | |
| 942 void InternetOptionsHandler::PopulateDictionaryDetailsCallback( | |
| 943 const chromeos::Network* network, | |
| 944 const std::string& service_path, | |
| 945 const base::DictionaryValue* shill_properties) { | |
| 946 if (VLOG_IS_ON(2)) { | |
| 947 std::string properties_json; | |
| 948 base::JSONWriter::WriteWithOptions(shill_properties, | |
| 949 base::JSONWriter::OPTIONS_PRETTY_PRINT, | |
| 950 &properties_json); | |
| 951 VLOG(2) << "Shill Properties: " << std::endl << properties_json; | |
| 952 } | |
| 953 | |
| 845 if (web_ui()) { | 954 if (web_ui()) { |
| 846 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork( | 955 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork( |
| 847 network->service_path()); | 956 network->service_path()); |
| 848 } | 957 } |
| 849 | 958 |
| 850 const chromeos::NetworkUIData& ui_data = network->ui_data(); | 959 const chromeos::NetworkUIData& ui_data = network->ui_data(); |
| 851 const base::DictionaryValue* onc = | 960 const base::DictionaryValue* onc = |
| 852 cros_->FindOncForNetwork(network->unique_id()); | 961 cros_->FindOncForNetwork(network->unique_id()); |
| 853 | 962 |
| 854 DictionaryValue dictionary; | 963 base::DictionaryValue dictionary; |
| 855 std::string hardware_address; | 964 std::string hardware_address; |
| 856 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( | 965 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( |
| 857 network->device_path(), &hardware_address, | 966 network->device_path(), &hardware_address, |
| 858 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); | 967 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); |
| 859 if (!hardware_address.empty()) | 968 if (!hardware_address.empty()) |
| 860 dictionary.SetString("hardwareAddress", hardware_address); | 969 dictionary.SetString("hardwareAddress", hardware_address); |
| 861 | 970 |
| 862 scoped_ptr<DictionaryValue> ipconfig_dhcp; | 971 // The DHCP IPConfig contains the values that are actually in use at the |
| 863 scoped_ptr<DictionaryValue> ipconfig_static; | 972 // moment, even if some are overridden by static IP values. |
| 973 scoped_ptr<DictionaryValue> ipconfig_dhcp(new DictionaryValue); | |
| 974 std::string ipconfig_name_servers; | |
| 864 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); | 975 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); |
| 865 it != ipconfigs.end(); ++it) { | 976 it != ipconfigs.end(); ++it) { |
| 866 const chromeos::NetworkIPConfig& ipconfig = *it; | 977 const chromeos::NetworkIPConfig& ipconfig = *it; |
| 867 scoped_ptr<DictionaryValue> ipconfig_dict(new DictionaryValue()); | 978 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { |
| 868 ipconfig_dict->SetString("address", ipconfig.address); | 979 ipconfig_dhcp->SetString("address", ipconfig.address); |
|
stevenjb
2012/08/13 17:43:44
Use consts
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done.
| |
| 869 ipconfig_dict->SetString("subnetAddress", ipconfig.netmask); | 980 VLOG(2) << "Found DHCP Address: " << ipconfig.address; |
| 870 ipconfig_dict->SetString("gateway", ipconfig.gateway); | 981 ipconfig_dhcp->SetString("netmask", ipconfig.netmask); |
| 871 ipconfig_dict->SetString("dns", ipconfig.name_servers); | 982 VLOG(2) << "Found DHCP Netmask: " << ipconfig.netmask; |
| 872 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) | 983 ipconfig_dhcp->SetString("gateway", ipconfig.gateway); |
| 873 ipconfig_dhcp.reset(ipconfig_dict.release()); | 984 VLOG(2) << "Found DHCP Gateway: " << ipconfig.gateway; |
| 874 else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) | 985 ipconfig_dhcp->SetString("nameServers", ipconfig.name_servers); |
| 875 ipconfig_static.reset(ipconfig_dict.release()); | 986 ipconfig_name_servers = ipconfig.name_servers; // save for later |
| 987 VLOG(2) << "Found DHCP Name Servers: " << ipconfig.name_servers; | |
| 988 break; | |
| 989 } | |
| 876 } | 990 } |
| 877 | 991 |
| 878 chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data); | 992 chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data); |
| 879 SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(), | 993 |
| 994 chromeos::NetworkPropertyUIData static_ip_ui_data(ui_data); | |
| 995 int automatic_ip_config; | |
| 996 scoped_ptr<DictionaryValue> static_ip_dict( | |
| 997 BuildIPInfoDictionary(*shill_properties, true, &automatic_ip_config)); | |
| 998 dictionary.SetBoolean("ipAutoConfig", automatic_ip_config == 0); | |
|
stevenjb
2012/08/13 17:43:44
Use const here and below
Greg Spencer (Chromium)
2012/08/13 23:53:44
Done in my changes at least. Do you want me to fi
| |
| 999 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0) | |
| 1000 << "UI doesn't support automatic specification of individual " | |
| 1001 << "static ip parameters."; | |
| 1002 scoped_ptr<DictionaryValue> saved_ip_dict( | |
| 1003 BuildIPInfoDictionary(*shill_properties, false, NULL)); | |
| 1004 dictionary.Set("savedIP", saved_ip_dict.release()); | |
| 1005 | |
| 1006 // Determine what kind of name server setting we have by comparing the | |
| 1007 // StaticIP and Google values with the ipconfig values. | |
| 1008 std::string name_server_type = "automatic"; | |
| 1009 std::string static_ip_nameservers; | |
| 1010 static_ip_dict->GetString("nameServers", &static_ip_nameservers); | |
| 1011 if (!static_ip_nameservers.empty() && | |
| 1012 static_ip_nameservers == ipconfig_name_servers) { | |
| 1013 name_server_type = "user"; | |
| 1014 } | |
| 1015 if (ipconfig_name_servers == kGoogleNameServers) { | |
| 1016 name_server_type = "google"; | |
| 1017 } | |
| 1018 | |
| 1019 SetValueDictionary(&dictionary, "ipconfig", ipconfig_dhcp.release(), | |
| 880 ipconfig_dhcp_ui_data); | 1020 ipconfig_dhcp_ui_data); |
| 881 chromeos::NetworkPropertyUIData ipconfig_static_ui_data(ui_data); | 1021 SetValueDictionary(&dictionary, "staticIP", static_ip_dict.release(), |
| 882 SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(), | 1022 static_ip_ui_data); |
| 883 ipconfig_static_ui_data); | |
| 884 | 1023 |
| 885 chromeos::ConnectionType type = network->type(); | 1024 chromeos::ConnectionType type = network->type(); |
| 886 dictionary.SetInteger("type", type); | 1025 dictionary.SetInteger("type", type); |
| 887 dictionary.SetString("servicePath", network->service_path()); | 1026 dictionary.SetString("servicePath", network->service_path()); |
| 888 dictionary.SetBoolean("connecting", network->connecting()); | 1027 dictionary.SetBoolean("connecting", network->connecting()); |
| 889 dictionary.SetBoolean("connected", network->connected()); | 1028 dictionary.SetBoolean("connected", network->connected()); |
| 890 dictionary.SetString("connectionState", network->GetStateString()); | 1029 dictionary.SetString("connectionState", network->GetStateString()); |
| 891 dictionary.SetString("networkName", network->name()); | 1030 dictionary.SetString("networkName", network->name()); |
| 1031 dictionary.SetString("nameServerType", name_server_type); | |
| 1032 dictionary.SetString("nameServersGoogle", kGoogleNameServers); | |
| 892 | 1033 |
| 893 // Only show proxy for remembered networks. | 1034 // Only show proxy for remembered networks. |
| 894 chromeos::NetworkProfileType network_profile = network->profile_type(); | 1035 chromeos::NetworkProfileType network_profile = network->profile_type(); |
| 895 dictionary.SetBoolean("showProxy", network_profile != chromeos::PROFILE_NONE); | 1036 dictionary.SetBoolean("showProxy", network_profile != chromeos::PROFILE_NONE); |
| 896 | 1037 |
| 897 // Enable static ip config for ethernet. For wifi, enable if flag is set. | 1038 // Enable static ip config for ethernet. For wifi, enable if flag is set. |
| 898 bool staticIPConfig = type == chromeos::TYPE_ETHERNET || | 1039 bool staticIPConfig = type == chromeos::TYPE_ETHERNET || |
| 899 (type == chromeos::TYPE_WIFI && | 1040 (type == chromeos::TYPE_WIFI && |
| 900 CommandLine::ForCurrentProcess()->HasSwitch( | 1041 CommandLine::ForCurrentProcess()->HasSwitch( |
| 901 switches::kEnableStaticIPConfig)); | 1042 switches::kEnableStaticIPConfig)); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1464 if (default_value) | 1605 if (default_value) |
| 1465 value_dict->Set("default", default_value->DeepCopy()); | 1606 value_dict->Set("default", default_value->DeepCopy()); |
| 1466 if (ui_data.managed()) | 1607 if (ui_data.managed()) |
| 1467 value_dict->SetString("controlledBy", "policy"); | 1608 value_dict->SetString("controlledBy", "policy"); |
| 1468 else if (ui_data.recommended()) | 1609 else if (ui_data.recommended()) |
| 1469 value_dict->SetString("controlledBy", "recommended"); | 1610 value_dict->SetString("controlledBy", "recommended"); |
| 1470 settings->Set(key, value_dict); | 1611 settings->Set(key, value_dict); |
| 1471 } | 1612 } |
| 1472 | 1613 |
| 1473 } // namespace options2 | 1614 } // namespace options2 |
| OLD | NEW |