OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chromeos/network/network_profile.h" | 42 #include "chromeos/network/network_profile.h" |
43 #include "chromeos/network/network_profile_handler.h" | 43 #include "chromeos/network/network_profile_handler.h" |
44 #include "chromeos/network/network_state.h" | 44 #include "chromeos/network/network_state.h" |
45 #include "chromeos/network/network_state_handler.h" | 45 #include "chromeos/network/network_state_handler.h" |
46 #include "chromeos/network/network_util.h" | 46 #include "chromeos/network/network_util.h" |
47 #include "chromeos/network/onc/onc_signature.h" | 47 #include "chromeos/network/onc/onc_signature.h" |
48 #include "chromeos/network/onc/onc_translation_tables.h" | 48 #include "chromeos/network/onc/onc_translation_tables.h" |
49 #include "chromeos/network/onc/onc_translator.h" | 49 #include "chromeos/network/onc/onc_translator.h" |
50 #include "chromeos/network/onc/onc_utils.h" | 50 #include "chromeos/network/onc/onc_utils.h" |
51 #include "components/onc/onc_constants.h" | 51 #include "components/onc/onc_constants.h" |
52 #include "content/public/browser/user_metrics.h" | |
53 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
54 #include "content/public/browser/web_ui.h" | 53 #include "content/public/browser/web_ui.h" |
55 #include "grit/ui_chromeos_resources.h" | 54 #include "grit/ui_chromeos_resources.h" |
56 #include "third_party/cros_system_api/dbus/service_constants.h" | 55 #include "third_party/cros_system_api/dbus/service_constants.h" |
57 #include "ui/base/resource/resource_bundle.h" | 56 #include "ui/base/resource/resource_bundle.h" |
58 #include "ui/base/webui/web_ui_util.h" | 57 #include "ui/base/webui/web_ui_util.h" |
59 #include "ui/chromeos/network/network_icon.h" | 58 #include "ui/chromeos/network/network_icon.h" |
60 #include "ui/gfx/image/image_skia.h" | 59 #include "ui/gfx/image/image_skia.h" |
61 | 60 |
62 namespace chromeos { | 61 namespace chromeos { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 base::Unretained(this))); | 398 base::Unretained(this))); |
400 web_ui()->RegisterMessageCallback(kChangePinMessage, | 399 web_ui()->RegisterMessageCallback(kChangePinMessage, |
401 base::Bind(&InternetOptionsHandler::ChangePinCallback, | 400 base::Bind(&InternetOptionsHandler::ChangePinCallback, |
402 base::Unretained(this))); | 401 base::Unretained(this))); |
403 web_ui()->RegisterMessageCallback(kSetServerHostname, | 402 web_ui()->RegisterMessageCallback(kSetServerHostname, |
404 base::Bind(&InternetOptionsHandler::SetServerHostnameCallback, | 403 base::Bind(&InternetOptionsHandler::SetServerHostnameCallback, |
405 base::Unretained(this))); | 404 base::Unretained(this))); |
406 } | 405 } |
407 | 406 |
408 void InternetOptionsHandler::EnableWifiCallback(const base::ListValue* args) { | 407 void InternetOptionsHandler::EnableWifiCallback(const base::ListValue* args) { |
409 content::RecordAction(base::UserMetricsAction("Options_NetworkWifiToggle")); | |
410 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( | 408 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( |
411 NetworkTypePattern::WiFi(), true, | 409 NetworkTypePattern::WiFi(), true, |
412 base::Bind(&ShillError, "EnableWifiCallback")); | 410 base::Bind(&ShillError, "EnableWifiCallback")); |
413 } | 411 } |
414 | 412 |
415 void InternetOptionsHandler::DisableWifiCallback(const base::ListValue* args) { | 413 void InternetOptionsHandler::DisableWifiCallback(const base::ListValue* args) { |
416 content::RecordAction(base::UserMetricsAction("Options_NetworkWifiToggle")); | |
417 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( | 414 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( |
418 NetworkTypePattern::WiFi(), false, | 415 NetworkTypePattern::WiFi(), false, |
419 base::Bind(&ShillError, "DisableWifiCallback")); | 416 base::Bind(&ShillError, "DisableWifiCallback")); |
420 } | 417 } |
421 | 418 |
422 void InternetOptionsHandler::EnableCellularCallback( | 419 void InternetOptionsHandler::EnableCellularCallback( |
423 const base::ListValue* args) { | 420 const base::ListValue* args) { |
424 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 421 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
425 const DeviceState* device = | 422 const DeviceState* device = |
426 handler->GetDeviceStateByType(NetworkTypePattern::Cellular()); | 423 handler->GetDeviceStateByType(NetworkTypePattern::Cellular()); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 702 |
706 void InternetOptionsHandler::SetPreferNetworkCallback( | 703 void InternetOptionsHandler::SetPreferNetworkCallback( |
707 const base::ListValue* args) { | 704 const base::ListValue* args) { |
708 std::string service_path, prefer_network_str; | 705 std::string service_path, prefer_network_str; |
709 if (args->GetSize() < 2 || | 706 if (args->GetSize() < 2 || |
710 !args->GetString(0, &service_path) || | 707 !args->GetString(0, &service_path) || |
711 !args->GetString(1, &prefer_network_str)) { | 708 !args->GetString(1, &prefer_network_str)) { |
712 NOTREACHED(); | 709 NOTREACHED(); |
713 return; | 710 return; |
714 } | 711 } |
715 content::RecordAction(base::UserMetricsAction("Options_NetworkSetPrefer")); | |
716 int priority = (prefer_network_str == kTagTrue) ? kPreferredPriority : 0; | 712 int priority = (prefer_network_str == kTagTrue) ? kPreferredPriority : 0; |
717 SetNetworkProperty(service_path, | 713 SetNetworkProperty(service_path, |
718 shill::kPriorityProperty, | 714 shill::kPriorityProperty, |
719 new base::FundamentalValue(priority)); | 715 new base::FundamentalValue(priority)); |
720 } | 716 } |
721 | 717 |
722 void InternetOptionsHandler::SetAutoConnectCallback( | 718 void InternetOptionsHandler::SetAutoConnectCallback( |
723 const base::ListValue* args) { | 719 const base::ListValue* args) { |
724 std::string service_path, auto_connect_str; | 720 std::string service_path, auto_connect_str; |
725 if (args->GetSize() < 2 || | 721 if (args->GetSize() < 2 || |
726 !args->GetString(0, &service_path) || | 722 !args->GetString(0, &service_path) || |
727 !args->GetString(1, &auto_connect_str)) { | 723 !args->GetString(1, &auto_connect_str)) { |
728 NOTREACHED(); | 724 NOTREACHED(); |
729 return; | 725 return; |
730 } | 726 } |
731 content::RecordAction(base::UserMetricsAction("Options_NetworkAutoConnect")); | |
732 bool auto_connect = auto_connect_str == kTagTrue; | 727 bool auto_connect = auto_connect_str == kTagTrue; |
733 SetNetworkProperty(service_path, | 728 SetNetworkProperty(service_path, |
734 shill::kAutoConnectProperty, | 729 shill::kAutoConnectProperty, |
735 new base::FundamentalValue(auto_connect)); | 730 new base::FundamentalValue(auto_connect)); |
736 } | 731 } |
737 | 732 |
738 void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) { | 733 void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) { |
739 std::string service_path; | 734 std::string service_path; |
740 if (!args->GetString(0, &service_path)) { | 735 if (!args->GetString(0, &service_path)) { |
741 NOTREACHED(); | 736 NOTREACHED(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 if (!network) { | 838 if (!network) { |
844 LOG(ERROR) << "Network properties not found: " << service_path; | 839 LOG(ERROR) << "Network properties not found: " << service_path; |
845 return; | 840 return; |
846 } | 841 } |
847 | 842 |
848 details_path_ = service_path; | 843 details_path_ = service_path; |
849 | 844 |
850 scoped_ptr<base::DictionaryValue> dictionary = | 845 scoped_ptr<base::DictionaryValue> dictionary = |
851 PopulateConnectionDetails(network, onc_properties); | 846 PopulateConnectionDetails(network, onc_properties); |
852 | 847 |
853 if (network->Matches(NetworkTypePattern::WiFi())) { | |
854 content::RecordAction( | |
855 base::UserMetricsAction("Options_NetworkShowDetailsWifi")); | |
856 if (network->IsConnectedState()) { | |
857 content::RecordAction( | |
858 base::UserMetricsAction("Options_NetworkShowDetailsWifiConnected")); | |
859 } | |
860 } else if (network->Matches(NetworkTypePattern::VPN())) { | |
861 content::RecordAction( | |
862 base::UserMetricsAction("Options_NetworkShowDetailsVPN")); | |
863 if (network->IsConnectedState()) { | |
864 content::RecordAction( | |
865 base::UserMetricsAction("Options_NetworkShowDetailsVPNConnected")); | |
866 } | |
867 } else if (network->Matches(NetworkTypePattern::Cellular())) { | |
868 content::RecordAction( | |
869 base::UserMetricsAction("Options_NetworkShowDetailsCellular")); | |
870 if (network->IsConnectedState()) { | |
871 content::RecordAction(base::UserMetricsAction( | |
872 "Options_NetworkShowDetailsCellularConnected")); | |
873 } | |
874 } | |
875 | |
876 // Show details dialog | 848 // Show details dialog |
877 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary); | 849 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary); |
878 } | 850 } |
879 | 851 |
880 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { | 852 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { |
881 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 853 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
882 } | 854 } |
883 | 855 |
884 float InternetOptionsHandler::GetScaleFactor() const { | 856 float InternetOptionsHandler::GetScaleFactor() const { |
885 return web_ui()->GetDeviceScaleFactor(); | 857 return web_ui()->GetDeviceScaleFactor(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 NetworkHandler::Get() | 892 NetworkHandler::Get() |
921 ->managed_network_configuration_handler() | 893 ->managed_network_configuration_handler() |
922 ->GetManagedProperties( | 894 ->GetManagedProperties( |
923 LoginState::Get()->primary_user_hash(), | 895 LoginState::Get()->primary_user_hash(), |
924 service_path, | 896 service_path, |
925 base::Bind( | 897 base::Bind( |
926 &InternetOptionsHandler::PopulateDictionaryDetailsCallback, | 898 &InternetOptionsHandler::PopulateDictionaryDetailsCallback, |
927 weak_factory_.GetWeakPtr()), | 899 weak_factory_.GetWeakPtr()), |
928 base::Bind(&ShillError, "NetworkCommand: " + command)); | 900 base::Bind(&ShillError, "NetworkCommand: " + command)); |
929 } else if (command == kTagConnect) { | 901 } else if (command == kTagConnect) { |
930 const NetworkState* network = GetNetworkState(service_path); | |
931 if (network && network->type() == shill::kTypeWifi) | |
932 content::RecordAction( | |
933 base::UserMetricsAction("Options_NetworkConnectToWifi")); | |
934 else if (network && network->type() == shill::kTypeVPN) | |
935 content::RecordAction( | |
936 base::UserMetricsAction("Options_NetworkConnectToVPN")); | |
937 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow()); | 902 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow()); |
938 } else if (command == kTagDisconnect) { | 903 } else if (command == kTagDisconnect) { |
939 const NetworkState* network = GetNetworkState(service_path); | |
940 if (network && network->type() == shill::kTypeWifi) | |
941 content::RecordAction( | |
942 base::UserMetricsAction("Options_NetworkDisconnectWifi")); | |
943 else if (network && network->type() == shill::kTypeVPN) | |
944 content::RecordAction( | |
945 base::UserMetricsAction("Options_NetworkDisconnectVPN")); | |
946 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( | 904 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
947 service_path, | 905 service_path, |
948 base::Bind(&base::DoNothing), | 906 base::Bind(&base::DoNothing), |
949 base::Bind(&ShillError, "NetworkCommand: " + command)); | 907 base::Bind(&ShillError, "NetworkCommand: " + command)); |
950 } else if (command == kTagConfigure) { | 908 } else if (command == kTagConfigure) { |
951 NetworkConfigView::Show(service_path, GetNativeWindow()); | 909 NetworkConfigView::Show(service_path, GetNativeWindow()); |
952 } else if (command == kTagActivate && type == shill::kTypeCellular) { | 910 } else if (command == kTagActivate && type == shill::kTypeCellular) { |
953 ash::network_connect::ActivateCellular(service_path); | 911 ash::network_connect::ActivateCellular(service_path); |
954 // Activation may update network properties (e.g. ActivationState), so | 912 // Activation may update network properties (e.g. ActivationState), so |
955 // request them here in case they change. | 913 // request them here in case they change. |
956 UpdateConnectionData(service_path); | 914 UpdateConnectionData(service_path); |
957 } else { | 915 } else { |
958 VLOG(1) << "Unknown command: " << command; | 916 VLOG(1) << "Unknown command: " << command; |
959 NOTREACHED(); | 917 NOTREACHED(); |
960 } | 918 } |
961 } | 919 } |
962 | 920 |
963 void InternetOptionsHandler::AddConnection(const std::string& type) { | 921 void InternetOptionsHandler::AddConnection(const std::string& type) { |
964 if (type == shill::kTypeWifi) { | 922 if (type == shill::kTypeWifi) { |
965 content::RecordAction( | |
966 base::UserMetricsAction("Options_NetworkJoinOtherWifi")); | |
967 NetworkConfigView::ShowForType(shill::kTypeWifi, GetNativeWindow()); | 923 NetworkConfigView::ShowForType(shill::kTypeWifi, GetNativeWindow()); |
968 } else if (type == shill::kTypeVPN) { | 924 } else if (type == shill::kTypeVPN) { |
969 content::RecordAction( | |
970 base::UserMetricsAction("Options_NetworkJoinOtherVPN")); | |
971 NetworkConfigView::ShowForType(shill::kTypeVPN, GetNativeWindow()); | 925 NetworkConfigView::ShowForType(shill::kTypeVPN, GetNativeWindow()); |
972 } else if (type == shill::kTypeCellular) { | 926 } else if (type == shill::kTypeCellular) { |
973 ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow()); | 927 ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow()); |
974 } else { | 928 } else { |
975 LOG(ERROR) << "Unsupported type for AddConnection"; | 929 LOG(ERROR) << "Unsupported type for AddConnection"; |
976 } | 930 } |
977 } | 931 } |
978 | 932 |
979 base::ListValue* InternetOptionsHandler::GetWiredList() { | 933 base::ListValue* InternetOptionsHandler::GetWiredList() { |
980 base::ListValue* list = new base::ListValue(); | 934 base::ListValue* list = new base::ListValue(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 dictionary->SetBoolean( | 1023 dictionary->SetBoolean( |
1070 kTagWimaxAvailable, | 1024 kTagWimaxAvailable, |
1071 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); | 1025 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); |
1072 dictionary->SetBoolean( | 1026 dictionary->SetBoolean( |
1073 kTagWimaxEnabled, | 1027 kTagWimaxEnabled, |
1074 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); | 1028 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); |
1075 } | 1029 } |
1076 | 1030 |
1077 } // namespace options | 1031 } // namespace options |
1078 } // namespace chromeos | 1032 } // namespace chromeos |
OLD | NEW |