| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/mobile_config.h" | 21 #include "chrome/browser/chromeos/mobile_config.h" |
| 21 #include "chrome/browser/chromeos/net/onc_utils.h" | 22 #include "chrome/browser/chromeos/net/onc_utils.h" |
| 22 #include "chrome/browser/chromeos/options/network_config_view.h" | 23 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 23 #include "chrome/browser/chromeos/options/network_property_ui_data.h" | 24 #include "chrome/browser/chromeos/options/network_property_ui_data.h" |
| 24 #include "chrome/browser/chromeos/settings/cros_settings.h" | 25 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 25 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 26 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 26 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" | 27 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Keys for the initial "localized" dictionary values. | 67 // Keys for the initial "localized" dictionary values. |
| 67 const char kLoggedInAsOwnerKey[] = "loggedInAsOwner"; | 68 const char kLoggedInAsOwnerKey[] = "loggedInAsOwner"; |
| 68 const char kShowCarrierSelectKey[] = "showCarrierSelect"; | 69 const char kShowCarrierSelectKey[] = "showCarrierSelect"; |
| 69 const char kNetworkDataKey[] = "networkData"; | 70 const char kNetworkDataKey[] = "networkData"; |
| 70 | 71 |
| 71 // 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 |
| 72 // 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. |
| 73 const char kNetworkInfoKeyIconURL[] = "iconURL"; | 74 const char kNetworkInfoKeyIconURL[] = "iconURL"; |
| 74 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; | 75 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; |
| 75 | 76 |
| 76 // These are types of name server selections from the web ui. | |
| 77 const char kNameServerTypeAutomatic[] = "automatic"; | |
| 78 const char kNameServerTypeGoogle[] = "google"; | |
| 79 | |
| 80 // Google public name servers (DNS). | |
| 81 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; | |
| 82 | |
| 83 // Functions we call in JavaScript. | 77 // Functions we call in JavaScript. |
| 84 const char kRefreshNetworkDataFunction[] = | 78 const char kRefreshNetworkDataFunction[] = |
| 85 "options.network.NetworkList.refreshNetworkData"; | 79 "options.network.NetworkList.refreshNetworkData"; |
| 86 const char kSetDefaultNetworkIconsFunction[] = | 80 const char kSetDefaultNetworkIconsFunction[] = |
| 87 "options.network.NetworkList.setDefaultNetworkIcons"; | 81 "options.network.NetworkList.setDefaultNetworkIcons"; |
| 88 const char kGetManagedPropertiesResultFunction[] = | 82 const char kGetManagedPropertiesResultFunction[] = |
| 89 "options.internet.DetailsInternetPage.getManagedPropertiesResult"; | 83 "options.internet.DetailsInternetPage.getManagedPropertiesResult"; |
| 90 const char kUpdateConnectionDataFunction[] = | 84 const char kUpdateConnectionDataFunction[] = |
| 91 "options.internet.DetailsInternetPage.updateConnectionData"; | 85 "options.internet.DetailsInternetPage.updateConnectionData"; |
| 92 const char kUpdateCarrierFunction[] = | 86 const char kUpdateCarrierFunction[] = |
| 93 "options.internet.DetailsInternetPage.updateCarrier"; | 87 "options.internet.DetailsInternetPage.updateCarrier"; |
| 94 | 88 |
| 95 // Setter methods called from JS that still need to be converted to match | 89 // Setter methods called from JS that still need to be converted to match |
| 96 // networkingPrivate methods. | 90 // networkingPrivate methods. |
| 97 const char kSetApnMessage[] = "setApn"; | 91 const char kSetApnMessage[] = "setApn"; |
| 98 const char kSetCarrierMessage[] = "setCarrier"; | 92 const char kSetCarrierMessage[] = "setCarrier"; |
| 99 const char kSetIPConfigMessage[] = "setIPConfig"; | |
| 100 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo"; | 93 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo"; |
| 101 const char kSimOperationMessage[] = "simOperation"; | 94 const char kSimOperationMessage[] = "simOperation"; |
| 102 | 95 |
| 103 // TODO(stevenjb): Replace these with the matching networkingPrivate methods. | 96 // TODO(stevenjb): Replace these with the matching networkingPrivate methods. |
| 104 // crbug.com/279351. | 97 // crbug.com/279351. |
| 105 const char kDisableNetworkTypeMessage[] = "disableNetworkType"; | 98 const char kDisableNetworkTypeMessage[] = "disableNetworkType"; |
| 106 const char kEnableNetworkTypeMessage[] = "enableNetworkType"; | 99 const char kEnableNetworkTypeMessage[] = "enableNetworkType"; |
| 107 const char kGetManagedPropertiesMessage[] = "getManagedProperties"; | 100 const char kGetManagedPropertiesMessage[] = "getManagedProperties"; |
| 108 const char kRequestNetworkScanMessage[] = "requestNetworkScan"; | 101 const char kRequestNetworkScanMessage[] = "requestNetworkScan"; |
| 109 const char kStartConnectMessage[] = "startConnect"; | 102 const char kStartConnectMessage[] = "startConnect"; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 device->properties().GetStringWithoutPathExpansion(shill::kMdnProperty, | 211 device->properties().GetStringWithoutPathExpansion(shill::kMdnProperty, |
| 219 &mdn); | 212 &mdn); |
| 220 } | 213 } |
| 221 if (mdn.empty()) | 214 if (mdn.empty()) |
| 222 return false; | 215 return false; |
| 223 } | 216 } |
| 224 | 217 |
| 225 return true; | 218 return true; |
| 226 } | 219 } |
| 227 | 220 |
| 228 // Helper methods for SetIPConfigProperties | |
| 229 bool AppendPropertyKeyIfPresent(const std::string& key, | |
| 230 const base::DictionaryValue& old_properties, | |
| 231 std::vector<std::string>* property_keys) { | |
| 232 if (old_properties.HasKey(key)) { | |
| 233 property_keys->push_back(key); | |
| 234 return true; | |
| 235 } | |
| 236 return false; | |
| 237 } | |
| 238 | |
| 239 bool AddStringPropertyIfChanged(const std::string& key, | |
| 240 const std::string& new_value, | |
| 241 const base::DictionaryValue& old_properties, | |
| 242 base::DictionaryValue* new_properties) { | |
| 243 std::string old_value; | |
| 244 if (!old_properties.GetStringWithoutPathExpansion(key, &old_value) || | |
| 245 new_value != old_value) { | |
| 246 new_properties->SetStringWithoutPathExpansion(key, new_value); | |
| 247 return true; | |
| 248 } | |
| 249 return false; | |
| 250 } | |
| 251 | |
| 252 bool AddIntegerPropertyIfChanged(const std::string& key, | |
| 253 int new_value, | |
| 254 const base::DictionaryValue& old_properties, | |
| 255 base::DictionaryValue* new_properties) { | |
| 256 int old_value; | |
| 257 if (!old_properties.GetIntegerWithoutPathExpansion(key, &old_value) || | |
| 258 new_value != old_value) { | |
| 259 new_properties->SetIntegerWithoutPathExpansion(key, new_value); | |
| 260 return true; | |
| 261 } | |
| 262 return false; | |
| 263 } | |
| 264 | |
| 265 } // namespace | 221 } // namespace |
| 266 | 222 |
| 267 InternetOptionsHandler::InternetOptionsHandler() | 223 InternetOptionsHandler::InternetOptionsHandler() |
| 268 : weak_factory_(this) { | 224 : weak_factory_(this) { |
| 269 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); | 225 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
| 270 } | 226 } |
| 271 | 227 |
| 272 InternetOptionsHandler::~InternetOptionsHandler() { | 228 InternetOptionsHandler::~InternetOptionsHandler() { |
| 273 if (NetworkHandler::IsInitialized()) { | 229 if (NetworkHandler::IsInitialized()) { |
| 274 NetworkHandler::Get()->network_state_handler()->RemoveObserver( | 230 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 base::Unretained(this))); | 273 base::Unretained(this))); |
| 318 web_ui()->RegisterMessageCallback(kRemoveNetworkMessage, | 274 web_ui()->RegisterMessageCallback(kRemoveNetworkMessage, |
| 319 base::Bind(&InternetOptionsHandler::RemoveNetwork, | 275 base::Bind(&InternetOptionsHandler::RemoveNetwork, |
| 320 base::Unretained(this))); | 276 base::Unretained(this))); |
| 321 web_ui()->RegisterMessageCallback(kConfigureNetworkMessage, | 277 web_ui()->RegisterMessageCallback(kConfigureNetworkMessage, |
| 322 base::Bind(&InternetOptionsHandler::ConfigureNetwork, | 278 base::Bind(&InternetOptionsHandler::ConfigureNetwork, |
| 323 base::Unretained(this))); | 279 base::Unretained(this))); |
| 324 web_ui()->RegisterMessageCallback(kActivateNetworkMessage, | 280 web_ui()->RegisterMessageCallback(kActivateNetworkMessage, |
| 325 base::Bind(&InternetOptionsHandler::ActivateNetwork, | 281 base::Bind(&InternetOptionsHandler::ActivateNetwork, |
| 326 base::Unretained(this))); | 282 base::Unretained(this))); |
| 327 web_ui()->RegisterMessageCallback(kSetIPConfigMessage, | |
| 328 base::Bind(&InternetOptionsHandler::SetIPConfigCallback, | |
| 329 base::Unretained(this))); | |
| 330 web_ui()->RegisterMessageCallback(kShowMorePlanInfoMessage, | 283 web_ui()->RegisterMessageCallback(kShowMorePlanInfoMessage, |
| 331 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback, | 284 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback, |
| 332 base::Unretained(this))); | 285 base::Unretained(this))); |
| 333 web_ui()->RegisterMessageCallback(kSetApnMessage, | 286 web_ui()->RegisterMessageCallback(kSetApnMessage, |
| 334 base::Bind(&InternetOptionsHandler::SetApnCallback, | 287 base::Bind(&InternetOptionsHandler::SetApnCallback, |
| 335 base::Unretained(this))); | 288 base::Unretained(this))); |
| 336 web_ui()->RegisterMessageCallback(kSetCarrierMessage, | 289 web_ui()->RegisterMessageCallback(kSetCarrierMessage, |
| 337 base::Bind(&InternetOptionsHandler::SetCarrierCallback, | 290 base::Bind(&InternetOptionsHandler::SetCarrierCallback, |
| 338 base::Unretained(this))); | 291 base::Unretained(this))); |
| 339 web_ui()->RegisterMessageCallback(kSimOperationMessage, | 292 web_ui()->RegisterMessageCallback(kSimOperationMessage, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 !args->GetDictionary(1, &properties)) { | 642 !args->GetDictionary(1, &properties)) { |
| 690 NOTREACHED(); | 643 NOTREACHED(); |
| 691 return; | 644 return; |
| 692 } | 645 } |
| 693 NetworkHandler::Get()->managed_network_configuration_handler()->SetProperties( | 646 NetworkHandler::Get()->managed_network_configuration_handler()->SetProperties( |
| 694 service_path, *properties, | 647 service_path, *properties, |
| 695 base::Bind(&base::DoNothing), | 648 base::Bind(&base::DoNothing), |
| 696 base::Bind(&ShillError, "SetProperties")); | 649 base::Bind(&ShillError, "SetProperties")); |
| 697 } | 650 } |
| 698 | 651 |
| 699 void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) { | |
| 700 std::string service_path; | |
| 701 if (!args->GetString(0, &service_path)) { | |
| 702 NOTREACHED(); | |
| 703 return; | |
| 704 } | |
| 705 NetworkHandler::Get()->network_configuration_handler()->GetProperties( | |
| 706 service_path, | |
| 707 base::Bind(&InternetOptionsHandler::SetIPConfigProperties, | |
| 708 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())), | |
| 709 base::Bind(&ShillError, "SetIPConfigCallback")); | |
| 710 } | |
| 711 | |
| 712 void InternetOptionsHandler::SetIPConfigProperties( | |
| 713 const base::ListValue* args, | |
| 714 const std::string& service_path, | |
| 715 const base::DictionaryValue& shill_properties) { | |
| 716 std::string address, netmask, gateway, name_server_type, name_servers; | |
| 717 bool dhcp_for_ip; | |
| 718 if (!args->GetBoolean(1, &dhcp_for_ip) || | |
| 719 !args->GetString(2, &address) || | |
| 720 !args->GetString(3, &netmask) || | |
| 721 !args->GetString(4, &gateway) || | |
| 722 !args->GetString(5, &name_server_type) || | |
| 723 !args->GetString(6, &name_servers)) { | |
| 724 NOTREACHED(); | |
| 725 return; | |
| 726 } | |
| 727 NET_LOG_USER("SetIPConfigProperties: " + name_server_type, service_path); | |
| 728 | |
| 729 std::vector<std::string> properties_to_clear; | |
| 730 base::DictionaryValue properties_to_set; | |
| 731 | |
| 732 if (dhcp_for_ip) { | |
| 733 AppendPropertyKeyIfPresent(shill::kStaticIPAddressProperty, | |
| 734 shill_properties, | |
| 735 &properties_to_clear); | |
| 736 AppendPropertyKeyIfPresent(shill::kStaticIPPrefixlenProperty, | |
| 737 shill_properties, | |
| 738 &properties_to_clear); | |
| 739 AppendPropertyKeyIfPresent(shill::kStaticIPGatewayProperty, | |
| 740 shill_properties, | |
| 741 &properties_to_clear); | |
| 742 } else { | |
| 743 AddStringPropertyIfChanged(shill::kStaticIPAddressProperty, | |
| 744 address, | |
| 745 shill_properties, | |
| 746 &properties_to_set); | |
| 747 int prefixlen = network_util::NetmaskToPrefixLength(netmask); | |
| 748 if (prefixlen < 0) { | |
| 749 LOG(ERROR) << "Invalid prefix length for: " << service_path | |
| 750 << " with netmask " << netmask; | |
| 751 prefixlen = 0; | |
| 752 } | |
| 753 AddIntegerPropertyIfChanged(shill::kStaticIPPrefixlenProperty, | |
| 754 prefixlen, | |
| 755 shill_properties, | |
| 756 &properties_to_set); | |
| 757 AddStringPropertyIfChanged(shill::kStaticIPGatewayProperty, | |
| 758 gateway, | |
| 759 shill_properties, | |
| 760 &properties_to_set); | |
| 761 } | |
| 762 | |
| 763 if (name_server_type == kNameServerTypeAutomatic) { | |
| 764 AppendPropertyKeyIfPresent(shill::kStaticIPNameServersProperty, | |
| 765 shill_properties, | |
| 766 &properties_to_clear); | |
| 767 } else { | |
| 768 if (name_server_type == kNameServerTypeGoogle) | |
| 769 name_servers = kGoogleNameServers; | |
| 770 AddStringPropertyIfChanged(shill::kStaticIPNameServersProperty, | |
| 771 name_servers, | |
| 772 shill_properties, | |
| 773 &properties_to_set); | |
| 774 } | |
| 775 | |
| 776 if (!properties_to_clear.empty()) { | |
| 777 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( | |
| 778 service_path, | |
| 779 properties_to_clear, | |
| 780 base::Bind(&base::DoNothing), | |
| 781 base::Bind(&ShillError, "ClearIPConfigProperties")); | |
| 782 } | |
| 783 if (!properties_to_set.empty()) { | |
| 784 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | |
| 785 service_path, | |
| 786 properties_to_set, | |
| 787 NetworkConfigurationObserver::SOURCE_USER_ACTION, | |
| 788 base::Bind(&base::DoNothing), | |
| 789 base::Bind(&ShillError, "SetIPConfigProperties")); | |
| 790 } | |
| 791 std::string device_path; | |
| 792 shill_properties.GetStringWithoutPathExpansion(shill::kDeviceProperty, | |
| 793 &device_path); | |
| 794 if (!device_path.empty()) { | |
| 795 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs( | |
| 796 device_path, | |
| 797 base::Bind(&base::DoNothing), | |
| 798 base::Bind(&ShillError, "RequestRefreshIPConfigs")); | |
| 799 } | |
| 800 } | |
| 801 | |
| 802 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { | 652 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { |
| 803 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 653 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
| 804 } | 654 } |
| 805 | 655 |
| 806 float InternetOptionsHandler::GetScaleFactor() const { | 656 float InternetOptionsHandler::GetScaleFactor() const { |
| 807 return web_ui()->GetDeviceScaleFactor(); | 657 return web_ui()->GetDeviceScaleFactor(); |
| 808 } | 658 } |
| 809 | 659 |
| 810 const PrefService* InternetOptionsHandler::GetPrefs() const { | 660 const PrefService* InternetOptionsHandler::GetPrefs() const { |
| 811 return Profile::FromWebUI(web_ui())->GetPrefs(); | 661 return Profile::FromWebUI(web_ui())->GetPrefs(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 dictionary->SetBoolean( | 804 dictionary->SetBoolean( |
| 955 kTagWimaxAvailable, | 805 kTagWimaxAvailable, |
| 956 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); | 806 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); |
| 957 dictionary->SetBoolean( | 807 dictionary->SetBoolean( |
| 958 kTagWimaxEnabled, | 808 kTagWimaxEnabled, |
| 959 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); | 809 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); |
| 960 } | 810 } |
| 961 | 811 |
| 962 } // namespace options | 812 } // namespace options |
| 963 } // namespace chromeos | 813 } // namespace chromeos |
| OLD | NEW |