Index: chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc |
diff --git a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc |
index 09dbe3900dea19e75536e99958eacc228c16238f..dd9c6f4c4fe1ef4183de9eb09f823c85d57ba88e 100644 |
--- a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc |
+++ b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc |
@@ -18,6 +18,7 @@ |
#include "base/bind_helpers.h" |
#include "base/command_line.h" |
#include "base/i18n/time_formatting.h" |
+#include "base/json/json_writer.h" |
#include "base/string16.h" |
#include "base/string_number_conversions.h" |
#include "base/stringprintf.h" |
@@ -27,6 +28,7 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/chromeos/choose_mobile_network_dialog.h" |
#include "chrome/browser/chromeos/cros/cros_library.h" |
+#include "chrome/browser/chromeos/cros/cros_network_functions.h" |
#include "chrome/browser/chromeos/cros/network_library.h" |
#include "chrome/browser/chromeos/cros/onc_constants.h" |
#include "chrome/browser/chromeos/enrollment_dialog_view.h" |
@@ -54,6 +56,7 @@ |
#include "grit/generated_resources.h" |
#include "grit/locale_settings.h" |
#include "grit/theme_resources.h" |
+#include "third_party/cros_system_api/dbus/service_constants.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/layout.h" |
#include "ui/base/resource/resource_bundle.h" |
@@ -81,6 +84,27 @@ const char kNetworkInfoKeyRemembered[] = "remembered"; |
const char kNetworkInfoKeyServicePath[] = "servicePath"; |
const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; |
+// These are keys for getting IP information from the web ui. |
+const char kIpConfigAddress[] = "address"; |
+const char kIpConfigPrefixLength[] = "prefixLength"; |
+const char kIpConfigNetmask[] = "netmask"; |
+const char kIpConfigGateway[] = "gateway"; |
+const char kIpConfigNameServers[] = "nameServers"; |
+const char kIpConfigAutoConfig[] = "ipAutoConfig"; |
+ |
+// These are types of name server selections from the web ui. |
+const char kNameServerTypeAutomatic[] = "automatic"; |
+const char kNameServerTypeGoogle[] = "google"; |
+const char kNameServerTypeUser[] = "user"; |
+ |
+// These are dictionary names used to send data to the web ui. |
+const char kDictionaryIpConfig[] = "ipconfig"; |
+const char kDictionaryStaticIp[] = "staticIP"; |
+const char kDictionarySavedIp[] = "savedIP"; |
+ |
+// Google public name servers (DNS). |
+const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; |
+ |
// A helper class for building network information dictionaries to be sent to |
// the webui code. |
class NetworkInfoDictionary { |
@@ -260,6 +284,68 @@ DictionaryValue* NetworkInfoDictionary::BuildDictionary() { |
return network_info.release(); |
} |
+// Pulls IP information out of a shill service properties dictionary. If |
+// |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it |
+// fetches "SavedIP.*" properties. Caller must take ownership of returned |
+// dictionary. If non-NULL, |ip_parameters_set| returns a count of the number |
+// of IP routing parameters that get set. |
+DictionaryValue* BuildIPInfoDictionary(const DictionaryValue& shill_properties, |
+ bool static_ip, |
+ int* routing_parameters_set) { |
+ std::string address_key; |
+ std::string prefix_len_key; |
+ std::string gateway_key; |
+ std::string name_servers_key; |
+ if (static_ip) { |
+ address_key = shill::kStaticIPAddressProperty; |
+ prefix_len_key = shill::kStaticIPPrefixlenProperty; |
+ gateway_key = shill::kStaticIPGatewayProperty; |
+ name_servers_key = shill::kStaticIPNameServersProperty; |
+ } else { |
+ address_key = shill::kSavedIPAddressProperty; |
+ prefix_len_key = shill::kSavedIPPrefixlenProperty; |
+ gateway_key = shill::kSavedIPGatewayProperty; |
+ name_servers_key = shill::kSavedIPNameServersProperty; |
+ } |
+ |
+ scoped_ptr<DictionaryValue> ip_info_dict(new DictionaryValue); |
+ std::string address; |
+ int routing_parameters = 0; |
+ if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) { |
+ ip_info_dict->SetString(kIpConfigAddress, address); |
+ VLOG(2) << "Found " << address_key << ": " << address; |
+ routing_parameters++; |
+ } |
+ int prefix_len = -1; |
+ if (shill_properties.GetIntegerWithoutPathExpansion( |
+ prefix_len_key, &prefix_len)) { |
+ ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len); |
+ ip_info_dict->SetString(kIpConfigNetmask, |
+ chromeos::CrosPrefixLengthToNetmask(prefix_len)); |
+ VLOG(2) << "Found " << prefix_len_key << ": " |
+ << prefix_len |
+ << " (" << chromeos::CrosPrefixLengthToNetmask(prefix_len) << ")"; |
+ routing_parameters++; |
+ } |
+ std::string gateway; |
+ if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) { |
+ ip_info_dict->SetString(kIpConfigGateway, gateway); |
+ VLOG(2) << "Found " << gateway_key << ": " << gateway; |
+ routing_parameters++; |
+ } |
+ if (routing_parameters_set) |
+ *routing_parameters_set = routing_parameters; |
+ |
+ std::string name_servers; |
+ if (shill_properties.GetStringWithoutPathExpansion( |
+ name_servers_key, &name_servers)) { |
+ ip_info_dict->SetString(kIpConfigNameServers, name_servers); |
+ VLOG(2) << "Found " << name_servers_key << ": " << name_servers; |
+ } |
+ |
+ return ip_info_dict.release(); |
+} |
+ |
} // namespace |
namespace options2 { |
@@ -338,13 +424,21 @@ void InternetOptionsHandler::GetLocalizedValues( |
{ "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK }, |
{ "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY }, |
{ "proxyTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PROXY }, |
- { "useDHCP", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_DHCP }, |
- { "useStaticIP", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_STATIC_IP }, |
{ "connectionState", IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE }, |
{ "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS }, |
- { "inetSubnetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK }, |
+ { "inetNetmask", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK }, |
{ "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY }, |
- { "inetDns", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER }, |
+ { "inetNameServers", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER }, |
+ { "ipAutomaticConfiguration", |
+ IDS_OPTIONS_SETTINGS_INTERNET_IP_AUTOMATIC_CONFIGURATION }, |
+ { "automaticNameServers", |
+ IDS_OPTIONS_SETTINGS_INTERNET_AUTOMATIC_NAME_SERVERS }, |
+ { "userNameServer1", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_1 }, |
+ { "userNameServer2", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_2 }, |
+ { "userNameServer3", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_3 }, |
+ { "userNameServer4", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_4 }, |
+ { "googleNameServers", IDS_OPTIONS_SETTINGS_INTERNET_GOOGLE_NAME_SERVERS }, |
+ { "userNameServers", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVERS }, |
{ "hardwareAddress", |
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS }, |
{ "detailsInternetDismiss", IDS_CLOSE }, |
@@ -811,37 +905,70 @@ void InternetOptionsHandler::SetAutoConnectCallback(const ListValue* args) { |
void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) { |
std::string service_path; |
- std::string dhcp_str; |
+ bool dhcp_for_ip; |
std::string address; |
std::string netmask; |
std::string gateway; |
+ std::string name_server_type; |
std::string name_servers; |
- if (args->GetSize() < 6 || |
+ if (args->GetSize() < 7 || |
!args->GetString(0, &service_path) || |
- !args->GetString(1, &dhcp_str) || |
+ !args->GetBoolean(1, &dhcp_for_ip) || |
!args->GetString(2, &address) || |
!args->GetString(3, &netmask) || |
!args->GetString(4, &gateway) || |
- !args->GetString(5, &name_servers)) { |
+ !args->GetString(5, &name_server_type) || |
+ !args->GetString(6, &name_servers)) { |
NOTREACHED(); |
return; |
} |
- chromeos::Network* network = cros_->FindNetworkByPath(service_path); |
- if (!network) |
- return; |
+ int dhcp_usage_mask = 0; |
+ if (dhcp_for_ip) { |
+ dhcp_usage_mask = (chromeos::NetworkLibrary::USE_DHCP_ADDRESS | |
+ chromeos::NetworkLibrary::USE_DHCP_NETMASK | |
+ chromeos::NetworkLibrary::USE_DHCP_GATEWAY); |
+ } |
+ if (name_server_type == kNameServerTypeAutomatic) { |
+ dhcp_usage_mask |= chromeos::NetworkLibrary::USE_DHCP_NAME_SERVERS; |
+ name_servers.clear(); |
+ } else if (name_server_type == kNameServerTypeGoogle) { |
+ name_servers = kGoogleNameServers; |
+ } |
- cros_->SetIPConfig(chromeos::NetworkIPConfig(network->device_path(), |
- dhcp_str == "true" ? chromeos::IPCONFIG_TYPE_DHCP : |
- chromeos::IPCONFIG_TYPE_IPV4, |
- address, netmask, gateway, name_servers)); |
+ cros_->SetIPParameters(service_path, |
+ address, |
+ netmask, |
+ gateway, |
+ name_servers, |
+ dhcp_usage_mask); |
} |
void InternetOptionsHandler::PopulateDictionaryDetails( |
const chromeos::Network* network) { |
DCHECK(network); |
+ // Send off an asynchronous request to Shill to get the service properties |
+ // and continue in the callback. |
+ chromeos::CrosRequestNetworkServiceProperties( |
+ network->service_path(), |
+ base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, |
+ weak_factory_.GetWeakPtr(), network)); |
+} |
+ |
+void InternetOptionsHandler::PopulateDictionaryDetailsCallback( |
+ const chromeos::Network* network, |
+ const std::string& service_path, |
+ const base::DictionaryValue* shill_properties) { |
+ if (VLOG_IS_ON(2)) { |
+ std::string properties_json; |
+ base::JSONWriter::WriteWithOptions(shill_properties, |
+ base::JSONWriter::OPTIONS_PRETTY_PRINT, |
+ &properties_json); |
+ VLOG(2) << "Shill Properties: " << std::endl << properties_json; |
+ } |
+ |
if (web_ui()) { |
Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork( |
network->service_path()); |
@@ -851,7 +978,7 @@ void InternetOptionsHandler::PopulateDictionaryDetails( |
const base::DictionaryValue* onc = |
cros_->FindOncForNetwork(network->unique_id()); |
- DictionaryValue dictionary; |
+ base::DictionaryValue dictionary; |
std::string hardware_address; |
chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( |
network->device_path(), &hardware_address, |
@@ -859,28 +986,58 @@ void InternetOptionsHandler::PopulateDictionaryDetails( |
if (!hardware_address.empty()) |
dictionary.SetString("hardwareAddress", hardware_address); |
- scoped_ptr<DictionaryValue> ipconfig_dhcp; |
- scoped_ptr<DictionaryValue> ipconfig_static; |
+ // The DHCP IPConfig contains the values that are actually in use at the |
+ // moment, even if some are overridden by static IP values. |
+ scoped_ptr<DictionaryValue> ipconfig_dhcp(new DictionaryValue); |
+ std::string ipconfig_name_servers; |
for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); |
it != ipconfigs.end(); ++it) { |
const chromeos::NetworkIPConfig& ipconfig = *it; |
- scoped_ptr<DictionaryValue> ipconfig_dict(new DictionaryValue()); |
- ipconfig_dict->SetString("address", ipconfig.address); |
- ipconfig_dict->SetString("subnetAddress", ipconfig.netmask); |
- ipconfig_dict->SetString("gateway", ipconfig.gateway); |
- ipconfig_dict->SetString("dns", ipconfig.name_servers); |
- if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) |
- ipconfig_dhcp.reset(ipconfig_dict.release()); |
- else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) |
- ipconfig_static.reset(ipconfig_dict.release()); |
+ if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { |
+ ipconfig_dhcp->SetString(kIpConfigAddress, ipconfig.address); |
+ VLOG(2) << "Found DHCP Address: " << ipconfig.address; |
+ ipconfig_dhcp->SetString(kIpConfigNetmask, ipconfig.netmask); |
+ VLOG(2) << "Found DHCP Netmask: " << ipconfig.netmask; |
+ ipconfig_dhcp->SetString(kIpConfigGateway, ipconfig.gateway); |
+ VLOG(2) << "Found DHCP Gateway: " << ipconfig.gateway; |
+ ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig.name_servers); |
+ ipconfig_name_servers = ipconfig.name_servers; // save for later |
+ VLOG(2) << "Found DHCP Name Servers: " << ipconfig.name_servers; |
+ break; |
+ } |
} |
chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data); |
- SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(), |
+ |
+ chromeos::NetworkPropertyUIData static_ip_ui_data(ui_data); |
+ int automatic_ip_config; |
+ scoped_ptr<DictionaryValue> static_ip_dict( |
+ BuildIPInfoDictionary(*shill_properties, true, &automatic_ip_config)); |
+ dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0); |
+ DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0) |
+ << "UI doesn't support automatic specification of individual " |
+ << "static ip parameters."; |
+ scoped_ptr<DictionaryValue> saved_ip_dict( |
+ BuildIPInfoDictionary(*shill_properties, false, NULL)); |
+ dictionary.Set(kDictionarySavedIp, saved_ip_dict.release()); |
+ |
+ // Determine what kind of name server setting we have by comparing the |
+ // StaticIP and Google values with the ipconfig values. |
+ std::string name_server_type = kNameServerTypeAutomatic; |
+ std::string static_ip_nameservers; |
+ static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers); |
+ if (!static_ip_nameservers.empty() && |
+ static_ip_nameservers == ipconfig_name_servers) { |
+ name_server_type = kNameServerTypeUser; |
+ } |
+ if (ipconfig_name_servers == kGoogleNameServers) { |
+ name_server_type = kNameServerTypeGoogle; |
+ } |
+ |
+ SetValueDictionary(&dictionary, kDictionaryIpConfig, ipconfig_dhcp.release(), |
ipconfig_dhcp_ui_data); |
- chromeos::NetworkPropertyUIData ipconfig_static_ui_data(ui_data); |
- SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(), |
- ipconfig_static_ui_data); |
+ SetValueDictionary(&dictionary, kDictionaryStaticIp, static_ip_dict.release(), |
+ static_ip_ui_data); |
chromeos::ConnectionType type = network->type(); |
dictionary.SetInteger("type", type); |
@@ -889,6 +1046,8 @@ void InternetOptionsHandler::PopulateDictionaryDetails( |
dictionary.SetBoolean("connected", network->connected()); |
dictionary.SetString("connectionState", network->GetStateString()); |
dictionary.SetString("networkName", network->name()); |
+ dictionary.SetString("nameServerType", name_server_type); |
+ dictionary.SetString("nameServersGoogle", kGoogleNameServers); |
// Only show proxy for remembered networks. |
chromeos::NetworkProfileType network_profile = network->profile_type(); |