Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc

Issue 10827283: This updates the StaticIP configuration UI to match new mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Steven Review Changes Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // These are keys for getting IP information from the web ui.
88 const char kIpConfigAddress[] = "address";
89 const char kIpConfigPrefixLength[] = "prefixLength";
90 const char kIpConfigNetmask[] = "netmask";
91 const char kIpConfigGateway[] = "gateway";
92 const char kIpConfigNameServers[] = "nameServers";
93 const char kIpConfigAutoConfig[] = "ipAutoConfig";
94
95 // These are types of name server selections from the web ui.
96 const char kNameServerTypeAutomatic[] = "automatic";
97 const char kNameServerTypeGoogle[] = "google";
98 const char kNameServerTypeUser[] = "user";
99
100 // These are dictionary names used to send data to the web ui.
101 const char kDictionaryIpConfig[] = "ipconfig";
102 const char kDictionaryStaticIp[] = "staticIP";
103 const char kDictionarySavedIp[] = "savedIP";
104
105 // Google public name servers (DNS).
106 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8";
107
84 // A helper class for building network information dictionaries to be sent to 108 // A helper class for building network information dictionaries to be sent to
85 // the webui code. 109 // the webui code.
86 class NetworkInfoDictionary { 110 class NetworkInfoDictionary {
87 public: 111 public:
88 // Initializes the dictionary with default values. 112 // Initializes the dictionary with default values.
89 explicit NetworkInfoDictionary(float icon_scale); 113 explicit NetworkInfoDictionary(float icon_scale);
90 114
91 // Copies in service path, connect{ing|ed|able} flags and connection type from 115 // 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 116 // the provided network object. Also chooses an appropriate icon based on the
93 // network type. 117 // network type.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 network_info->SetString(kNetworkInfoKeyNetworkName, name_); 277 network_info->SetString(kNetworkInfoKeyNetworkName, name_);
254 network_info->SetString(kNetworkInfoKeyNetworkStatus, status); 278 network_info->SetString(kNetworkInfoKeyNetworkStatus, status);
255 network_info->SetInteger(kNetworkInfoKeyNetworkType, 279 network_info->SetInteger(kNetworkInfoKeyNetworkType,
256 static_cast<int>(connection_type_)); 280 static_cast<int>(connection_type_));
257 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_); 281 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_);
258 network_info->SetString(kNetworkInfoKeyServicePath, service_path_); 282 network_info->SetString(kNetworkInfoKeyServicePath, service_path_);
259 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_); 283 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_);
260 return network_info.release(); 284 return network_info.release();
261 } 285 }
262 286
287 // Pulls IP information out of a shill service properties dictionary. If
288 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it
289 // fetches "SavedIP.*" properties. Caller must take ownership of returned
290 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number
291 // of IP routing parameters that get set.
292 DictionaryValue* BuildIPInfoDictionary(const DictionaryValue& shill_properties,
293 bool static_ip,
294 int* routing_parameters_set) {
295 std::string address_key;
296 std::string prefix_len_key;
297 std::string gateway_key;
298 std::string name_servers_key;
299 if (static_ip) {
300 address_key = shill::kStaticIPAddressProperty;
301 prefix_len_key = shill::kStaticIPPrefixlenProperty;
302 gateway_key = shill::kStaticIPGatewayProperty;
303 name_servers_key = shill::kStaticIPNameServersProperty;
304 } else {
305 address_key = shill::kSavedIPAddressProperty;
306 prefix_len_key = shill::kSavedIPPrefixlenProperty;
307 gateway_key = shill::kSavedIPGatewayProperty;
308 name_servers_key = shill::kSavedIPNameServersProperty;
309 }
310
311 scoped_ptr<DictionaryValue> ip_info_dict(new DictionaryValue);
312 std::string address;
313 int routing_parameters = 0;
314 if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) {
315 ip_info_dict->SetString(kIpConfigAddress, address);
316 VLOG(2) << "Found " << address_key << ": " << address;
317 routing_parameters++;
318 }
319 int prefix_len = -1;
320 if (shill_properties.GetIntegerWithoutPathExpansion(
321 prefix_len_key, &prefix_len)) {
322 ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len);
323 ip_info_dict->SetString(kIpConfigNetmask,
324 chromeos::CrosPrefixLengthToNetmask(prefix_len));
325 VLOG(2) << "Found " << prefix_len_key << ": "
326 << prefix_len
327 << " (" << chromeos::CrosPrefixLengthToNetmask(prefix_len) << ")";
328 routing_parameters++;
329 }
330 std::string gateway;
331 if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) {
332 ip_info_dict->SetString(kIpConfigGateway, gateway);
333 VLOG(2) << "Found " << gateway_key << ": " << gateway;
334 routing_parameters++;
335 }
336 if (routing_parameters_set)
337 *routing_parameters_set = routing_parameters;
338
339 std::string name_servers;
340 if (shill_properties.GetStringWithoutPathExpansion(
341 name_servers_key, &name_servers)) {
342 ip_info_dict->SetString(kIpConfigNameServers, name_servers);
343 VLOG(2) << "Found " << name_servers_key << ": " << name_servers;
344 }
345
346 return ip_info_dict.release();
347 }
348
263 } // namespace 349 } // namespace
264 350
265 namespace options2 { 351 namespace options2 {
266 352
267 InternetOptionsHandler::InternetOptionsHandler() 353 InternetOptionsHandler::InternetOptionsHandler()
268 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 354 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
269 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, 355 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED,
270 content::NotificationService::AllSources()); 356 content::NotificationService::AllSources());
271 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED, 357 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED,
272 content::NotificationService::AllSources()); 358 content::NotificationService::AllSources());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON }, 417 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON },
332 { "managedNetwork", IDS_OPTIONS_SETTINGS_MANAGED_NETWORK }, 418 { "managedNetwork", IDS_OPTIONS_SETTINGS_MANAGED_NETWORK },
333 { "wifiNetworkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, 419 { "wifiNetworkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION },
334 { "vpnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN }, 420 { "vpnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN },
335 { "cellularPlanTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PLAN }, 421 { "cellularPlanTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PLAN },
336 { "cellularConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, 422 { "cellularConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION },
337 { "cellularDeviceTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE }, 423 { "cellularDeviceTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE },
338 { "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK }, 424 { "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK },
339 { "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY }, 425 { "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY },
340 { "proxyTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PROXY }, 426 { "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 }, 427 { "connectionState", IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE },
344 { "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS }, 428 { "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS },
345 { "inetSubnetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK }, 429 { "inetNetmask", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK },
346 { "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY }, 430 { "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY },
347 { "inetDns", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER }, 431 { "inetNameServers", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER },
432 { "ipAutomaticConfiguration",
433 IDS_OPTIONS_SETTINGS_INTERNET_IP_AUTOMATIC_CONFIGURATION },
434 { "automaticNameServers",
435 IDS_OPTIONS_SETTINGS_INTERNET_AUTOMATIC_NAME_SERVERS },
436 { "userNameServer1", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_1 },
437 { "userNameServer2", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_2 },
438 { "userNameServer3", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_3 },
439 { "userNameServer4", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_4 },
440 { "googleNameServers", IDS_OPTIONS_SETTINGS_INTERNET_GOOGLE_NAME_SERVERS },
441 { "userNameServers", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVERS },
348 { "hardwareAddress", 442 { "hardwareAddress",
349 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS }, 443 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS },
350 { "detailsInternetDismiss", IDS_CLOSE }, 444 { "detailsInternetDismiss", IDS_CLOSE },
351 { "activateButton", IDS_OPTIONS_SETTINGS_ACTIVATE }, 445 { "activateButton", IDS_OPTIONS_SETTINGS_ACTIVATE },
352 { "buyplanButton", IDS_OPTIONS_SETTINGS_BUY_PLAN }, 446 { "buyplanButton", IDS_OPTIONS_SETTINGS_BUY_PLAN },
353 { "connectButton", IDS_OPTIONS_SETTINGS_CONNECT }, 447 { "connectButton", IDS_OPTIONS_SETTINGS_CONNECT },
354 { "disconnectButton", IDS_OPTIONS_SETTINGS_DISCONNECT }, 448 { "disconnectButton", IDS_OPTIONS_SETTINGS_DISCONNECT },
355 { "viewAccountButton", IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT }, 449 { "viewAccountButton", IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT },
356 450
357 // TODO(zelidrag): Change details title to Wimax once we get strings. 451 // TODO(zelidrag): Change details title to Wimax once we get strings.
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 if (!network) 898 if (!network)
805 return; 899 return;
806 900
807 bool auto_connect = auto_connect_str == "true"; 901 bool auto_connect = auto_connect_str == "true";
808 if (auto_connect != network->auto_connect()) 902 if (auto_connect != network->auto_connect())
809 network->SetAutoConnect(auto_connect); 903 network->SetAutoConnect(auto_connect);
810 } 904 }
811 905
812 void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) { 906 void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) {
813 std::string service_path; 907 std::string service_path;
814 std::string dhcp_str; 908 bool dhcp_for_ip;
815 std::string address; 909 std::string address;
816 std::string netmask; 910 std::string netmask;
817 std::string gateway; 911 std::string gateway;
912 std::string name_server_type;
818 std::string name_servers; 913 std::string name_servers;
819 914
820 if (args->GetSize() < 6 || 915 if (args->GetSize() < 7 ||
821 !args->GetString(0, &service_path) || 916 !args->GetString(0, &service_path) ||
822 !args->GetString(1, &dhcp_str) || 917 !args->GetBoolean(1, &dhcp_for_ip) ||
823 !args->GetString(2, &address) || 918 !args->GetString(2, &address) ||
824 !args->GetString(3, &netmask) || 919 !args->GetString(3, &netmask) ||
825 !args->GetString(4, &gateway) || 920 !args->GetString(4, &gateway) ||
826 !args->GetString(5, &name_servers)) { 921 !args->GetString(5, &name_server_type) ||
922 !args->GetString(6, &name_servers)) {
827 NOTREACHED(); 923 NOTREACHED();
828 return; 924 return;
829 } 925 }
830 926
831 chromeos::Network* network = cros_->FindNetworkByPath(service_path); 927 int dhcp_usage_mask = 0;
832 if (!network) 928 if (dhcp_for_ip) {
833 return; 929 dhcp_usage_mask = (chromeos::NetworkLibrary::USE_DHCP_ADDRESS |
930 chromeos::NetworkLibrary::USE_DHCP_NETMASK |
931 chromeos::NetworkLibrary::USE_DHCP_GATEWAY);
932 }
933 if (name_server_type == kNameServerTypeAutomatic) {
934 dhcp_usage_mask |= chromeos::NetworkLibrary::USE_DHCP_NAME_SERVERS;
935 name_servers.clear();
936 } else if (name_server_type == kNameServerTypeGoogle) {
937 name_servers = kGoogleNameServers;
938 }
834 939
835 cros_->SetIPConfig(chromeos::NetworkIPConfig(network->device_path(), 940 cros_->SetIPParameters(service_path,
836 dhcp_str == "true" ? chromeos::IPCONFIG_TYPE_DHCP : 941 address,
837 chromeos::IPCONFIG_TYPE_IPV4, 942 netmask,
838 address, netmask, gateway, name_servers)); 943 gateway,
944 name_servers,
945 dhcp_usage_mask);
839 } 946 }
840 947
841 void InternetOptionsHandler::PopulateDictionaryDetails( 948 void InternetOptionsHandler::PopulateDictionaryDetails(
842 const chromeos::Network* network) { 949 const chromeos::Network* network) {
843 DCHECK(network); 950 DCHECK(network);
844 951
952 // Send off an asynchronous request to Shill to get the service properties
953 // and continue in the callback.
954 chromeos::CrosRequestNetworkServiceProperties(
955 network->service_path(),
956 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback,
957 weak_factory_.GetWeakPtr(), network));
958 }
959
960 void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
961 const chromeos::Network* network,
962 const std::string& service_path,
963 const base::DictionaryValue* shill_properties) {
964 if (VLOG_IS_ON(2)) {
965 std::string properties_json;
966 base::JSONWriter::WriteWithOptions(shill_properties,
967 base::JSONWriter::OPTIONS_PRETTY_PRINT,
968 &properties_json);
969 VLOG(2) << "Shill Properties: " << std::endl << properties_json;
970 }
971
845 if (web_ui()) { 972 if (web_ui()) {
846 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork( 973 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork(
847 network->service_path()); 974 network->service_path());
848 } 975 }
849 976
850 const chromeos::NetworkUIData& ui_data = network->ui_data(); 977 const chromeos::NetworkUIData& ui_data = network->ui_data();
851 const base::DictionaryValue* onc = 978 const base::DictionaryValue* onc =
852 cros_->FindOncForNetwork(network->unique_id()); 979 cros_->FindOncForNetwork(network->unique_id());
853 980
854 DictionaryValue dictionary; 981 base::DictionaryValue dictionary;
855 std::string hardware_address; 982 std::string hardware_address;
856 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( 983 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs(
857 network->device_path(), &hardware_address, 984 network->device_path(), &hardware_address,
858 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); 985 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX);
859 if (!hardware_address.empty()) 986 if (!hardware_address.empty())
860 dictionary.SetString("hardwareAddress", hardware_address); 987 dictionary.SetString("hardwareAddress", hardware_address);
861 988
862 scoped_ptr<DictionaryValue> ipconfig_dhcp; 989 // The DHCP IPConfig contains the values that are actually in use at the
863 scoped_ptr<DictionaryValue> ipconfig_static; 990 // moment, even if some are overridden by static IP values.
991 scoped_ptr<DictionaryValue> ipconfig_dhcp(new DictionaryValue);
992 std::string ipconfig_name_servers;
864 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); 993 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin();
865 it != ipconfigs.end(); ++it) { 994 it != ipconfigs.end(); ++it) {
866 const chromeos::NetworkIPConfig& ipconfig = *it; 995 const chromeos::NetworkIPConfig& ipconfig = *it;
867 scoped_ptr<DictionaryValue> ipconfig_dict(new DictionaryValue()); 996 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) {
868 ipconfig_dict->SetString("address", ipconfig.address); 997 ipconfig_dhcp->SetString(kIpConfigAddress, ipconfig.address);
869 ipconfig_dict->SetString("subnetAddress", ipconfig.netmask); 998 VLOG(2) << "Found DHCP Address: " << ipconfig.address;
870 ipconfig_dict->SetString("gateway", ipconfig.gateway); 999 ipconfig_dhcp->SetString(kIpConfigNetmask, ipconfig.netmask);
871 ipconfig_dict->SetString("dns", ipconfig.name_servers); 1000 VLOG(2) << "Found DHCP Netmask: " << ipconfig.netmask;
872 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) 1001 ipconfig_dhcp->SetString(kIpConfigGateway, ipconfig.gateway);
873 ipconfig_dhcp.reset(ipconfig_dict.release()); 1002 VLOG(2) << "Found DHCP Gateway: " << ipconfig.gateway;
874 else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) 1003 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig.name_servers);
875 ipconfig_static.reset(ipconfig_dict.release()); 1004 ipconfig_name_servers = ipconfig.name_servers; // save for later
1005 VLOG(2) << "Found DHCP Name Servers: " << ipconfig.name_servers;
1006 break;
1007 }
876 } 1008 }
877 1009
878 chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data); 1010 chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data);
879 SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(), 1011
1012 chromeos::NetworkPropertyUIData static_ip_ui_data(ui_data);
1013 int automatic_ip_config;
1014 scoped_ptr<DictionaryValue> static_ip_dict(
1015 BuildIPInfoDictionary(*shill_properties, true, &automatic_ip_config));
1016 dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0);
1017 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0)
1018 << "UI doesn't support automatic specification of individual "
1019 << "static ip parameters.";
1020 scoped_ptr<DictionaryValue> saved_ip_dict(
1021 BuildIPInfoDictionary(*shill_properties, false, NULL));
1022 dictionary.Set(kDictionarySavedIp, saved_ip_dict.release());
1023
1024 // Determine what kind of name server setting we have by comparing the
1025 // StaticIP and Google values with the ipconfig values.
1026 std::string name_server_type = kNameServerTypeAutomatic;
1027 std::string static_ip_nameservers;
1028 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers);
1029 if (!static_ip_nameservers.empty() &&
1030 static_ip_nameservers == ipconfig_name_servers) {
1031 name_server_type = kNameServerTypeUser;
1032 }
1033 if (ipconfig_name_servers == kGoogleNameServers) {
1034 name_server_type = kNameServerTypeGoogle;
1035 }
1036
1037 SetValueDictionary(&dictionary, kDictionaryIpConfig, ipconfig_dhcp.release(),
880 ipconfig_dhcp_ui_data); 1038 ipconfig_dhcp_ui_data);
881 chromeos::NetworkPropertyUIData ipconfig_static_ui_data(ui_data); 1039 SetValueDictionary(&dictionary, kDictionaryStaticIp, static_ip_dict.release(),
882 SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(), 1040 static_ip_ui_data);
883 ipconfig_static_ui_data);
884 1041
885 chromeos::ConnectionType type = network->type(); 1042 chromeos::ConnectionType type = network->type();
886 dictionary.SetInteger("type", type); 1043 dictionary.SetInteger("type", type);
887 dictionary.SetString("servicePath", network->service_path()); 1044 dictionary.SetString("servicePath", network->service_path());
888 dictionary.SetBoolean("connecting", network->connecting()); 1045 dictionary.SetBoolean("connecting", network->connecting());
889 dictionary.SetBoolean("connected", network->connected()); 1046 dictionary.SetBoolean("connected", network->connected());
890 dictionary.SetString("connectionState", network->GetStateString()); 1047 dictionary.SetString("connectionState", network->GetStateString());
891 dictionary.SetString("networkName", network->name()); 1048 dictionary.SetString("networkName", network->name());
1049 dictionary.SetString("nameServerType", name_server_type);
1050 dictionary.SetString("nameServersGoogle", kGoogleNameServers);
892 1051
893 // Only show proxy for remembered networks. 1052 // Only show proxy for remembered networks.
894 chromeos::NetworkProfileType network_profile = network->profile_type(); 1053 chromeos::NetworkProfileType network_profile = network->profile_type();
895 dictionary.SetBoolean("showProxy", network_profile != chromeos::PROFILE_NONE); 1054 dictionary.SetBoolean("showProxy", network_profile != chromeos::PROFILE_NONE);
896 1055
897 // Enable static ip config for ethernet. For wifi, enable if flag is set. 1056 // Enable static ip config for ethernet. For wifi, enable if flag is set.
898 bool staticIPConfig = type == chromeos::TYPE_ETHERNET || 1057 bool staticIPConfig = type == chromeos::TYPE_ETHERNET ||
899 (type == chromeos::TYPE_WIFI && 1058 (type == chromeos::TYPE_WIFI &&
900 CommandLine::ForCurrentProcess()->HasSwitch( 1059 CommandLine::ForCurrentProcess()->HasSwitch(
901 switches::kEnableStaticIPConfig)); 1060 switches::kEnableStaticIPConfig));
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 if (default_value) 1623 if (default_value)
1465 value_dict->Set("default", default_value->DeepCopy()); 1624 value_dict->Set("default", default_value->DeepCopy());
1466 if (ui_data.managed()) 1625 if (ui_data.managed())
1467 value_dict->SetString("controlledBy", "policy"); 1626 value_dict->SetString("controlledBy", "policy");
1468 else if (ui_data.recommended()) 1627 else if (ui_data.recommended())
1469 value_dict->SetString("controlledBy", "recommended"); 1628 value_dict->SetString("controlledBy", "recommended");
1470 settings->Set(key, value_dict); 1629 settings->Set(key, value_dict);
1471 } 1630 }
1472 1631
1473 } // namespace options2 1632 } // namespace options2
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698