| 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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
| 9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 network_library->EnableWifiNetworkDevice(enable); | 625 network_library->EnableWifiNetworkDevice(enable); |
| 626 } else if (device == "cellular") { | 626 } else if (device == "cellular") { |
| 627 network_library->EnableCellularNetworkDevice(enable); | 627 network_library->EnableCellularNetworkDevice(enable); |
| 628 } else { | 628 } else { |
| 629 reply.SendError( | 629 reply.SendError( |
| 630 "Unknown device. Valid devices are ethernet, wifi, cellular."); | 630 "Unknown device. Valid devices are ethernet, wifi, cellular."); |
| 631 return; | 631 return; |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 | 634 |
| 635 void TestingAutomationProvider::SetSharedProxies( | |
| 636 DictionaryValue* args, | |
| 637 IPC::Message* reply_message) { | |
| 638 | |
| 639 AutomationJSONReply reply(this, reply_message); | |
| 640 base::Value* value; | |
| 641 if (!args->Get("value", &value)) { | |
| 642 reply.SendError("Invalid or missing value argument."); | |
| 643 return; | |
| 644 } | |
| 645 std::string error_message; | |
| 646 Profile* profile = | |
| 647 automation_util::GetCurrentProfileOnChromeOS(&error_message); | |
| 648 if (!profile) { | |
| 649 reply.SendError(error_message); | |
| 650 return; | |
| 651 } | |
| 652 PrefService* pref_service = profile->GetPrefs(); | |
| 653 pref_service->Set(prefs::kUseSharedProxies, *value); | |
| 654 reply.SendSuccess(NULL); | |
| 655 } | |
| 656 | |
| 657 void TestingAutomationProvider::SetProxySettings(DictionaryValue* args, | |
| 658 IPC::Message* reply_message) { | |
| 659 AutomationJSONReply reply(this, reply_message); | |
| 660 std::string proxy_config_str; | |
| 661 if (!args->GetString("proxy_config", &proxy_config_str)) { | |
| 662 reply.SendError("Invalid or missing args."); | |
| 663 return; | |
| 664 } | |
| 665 | |
| 666 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get()-> | |
| 667 network_state_handler()->DefaultNetwork(); | |
| 668 if (!network) { | |
| 669 reply.SendError("No network connected."); | |
| 670 return; | |
| 671 } | |
| 672 | |
| 673 scoped_ptr<base::DictionaryValue> proxy_config_dict( | |
| 674 chromeos::onc::ReadDictionaryFromJson(proxy_config_str)); | |
| 675 ProxyConfigDictionary proxy_config(proxy_config_dict.get()); | |
| 676 chromeos::proxy_config::SetProxyConfigForNetwork(proxy_config, *network); | |
| 677 | |
| 678 reply.SendSuccess(NULL); | |
| 679 } | |
| 680 | |
| 681 void TestingAutomationProvider::ConnectToCellularNetwork( | |
| 682 DictionaryValue* args, IPC::Message* reply_message) { | |
| 683 std::string service_path; | |
| 684 if (!args->GetString("service_path", &service_path)) { | |
| 685 AutomationJSONReply(this, reply_message).SendError( | |
| 686 "Invalid or missing args."); | |
| 687 return; | |
| 688 } | |
| 689 | |
| 690 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 691 chromeos::CellularNetwork* cellular = | |
| 692 network_library->FindCellularNetworkByPath(service_path); | |
| 693 if (!cellular) { | |
| 694 AutomationJSONReply(this, reply_message).SendError( | |
| 695 "No network found with specified service path."); | |
| 696 return; | |
| 697 } | |
| 698 | |
| 699 // Set up an observer (it will delete itself). | |
| 700 new ServicePathConnectObserver(this, reply_message, service_path); | |
| 701 | |
| 702 network_library->ConnectToCellularNetwork(cellular); | |
| 703 network_library->RequestNetworkScan(); | |
| 704 } | |
| 705 | |
| 706 void TestingAutomationProvider::DisconnectFromCellularNetwork( | |
| 707 DictionaryValue* args, IPC::Message* reply_message) { | |
| 708 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 709 const chromeos::CellularNetwork* cellular = | |
| 710 network_library->cellular_network(); | |
| 711 if (!cellular) { | |
| 712 AutomationJSONReply(this, reply_message).SendError( | |
| 713 "Not connected to any cellular network."); | |
| 714 return; | |
| 715 } | |
| 716 | |
| 717 // Set up an observer (it will delete itself). | |
| 718 new NetworkDisconnectObserver(this, reply_message, cellular->service_path()); | |
| 719 | |
| 720 network_library->DisconnectFromNetwork(cellular); | |
| 721 } | |
| 722 | |
| 723 void TestingAutomationProvider::ConnectToWifiNetwork( | |
| 724 DictionaryValue* args, IPC::Message* reply_message) { | |
| 725 AutomationJSONReply reply(this, reply_message); | |
| 726 std::string service_path, password; | |
| 727 bool shared; | |
| 728 if (!args->GetString("service_path", &service_path) || | |
| 729 !args->GetString("password", &password) || | |
| 730 !args->GetBoolean("shared", &shared)) { | |
| 731 reply.SendError("Invalid or missing args."); | |
| 732 return; | |
| 733 } | |
| 734 | |
| 735 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 736 chromeos::WifiNetwork* wifi = | |
| 737 network_library->FindWifiNetworkByPath(service_path); | |
| 738 if (!wifi) { | |
| 739 reply.SendError("No network found with specified service path."); | |
| 740 return; | |
| 741 } | |
| 742 if (!password.empty()) | |
| 743 wifi->SetPassphrase(password); | |
| 744 | |
| 745 // Regardless of what was passed, if the network is open and visible, | |
| 746 // the network must be shared because of a UI restriction. | |
| 747 if (wifi->encryption() == chromeos::SECURITY_NONE) | |
| 748 shared = true; | |
| 749 | |
| 750 // Set up an observer (it will delete itself). | |
| 751 new ServicePathConnectObserver(this, reply_message, service_path); | |
| 752 | |
| 753 network_library->ConnectToWifiNetwork(wifi, shared); | |
| 754 network_library->RequestNetworkScan(); | |
| 755 } | |
| 756 | |
| 757 void TestingAutomationProvider::ForgetWifiNetwork( | 635 void TestingAutomationProvider::ForgetWifiNetwork( |
| 758 DictionaryValue* args, IPC::Message* reply_message) { | 636 DictionaryValue* args, IPC::Message* reply_message) { |
| 759 std::string service_path; | 637 std::string service_path; |
| 760 if (!args->GetString("service_path", &service_path)) { | 638 if (!args->GetString("service_path", &service_path)) { |
| 761 AutomationJSONReply(this, reply_message).SendError( | 639 AutomationJSONReply(this, reply_message).SendError( |
| 762 "Invalid or missing args."); | 640 "Invalid or missing args."); |
| 763 return; | 641 return; |
| 764 } | 642 } |
| 765 | 643 |
| 766 NetworkLibrary::Get()->ForgetNetwork(service_path); | 644 NetworkLibrary::Get()->ForgetNetwork(service_path); |
| 767 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 645 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 768 } | 646 } |
| 769 | 647 |
| 770 void TestingAutomationProvider::ConnectToHiddenWifiNetwork( | |
| 771 DictionaryValue* args, IPC::Message* reply_message) { | |
| 772 std::string ssid, security, password; | |
| 773 bool shared; | |
| 774 if (!args->GetString("ssid", &ssid) || | |
| 775 !args->GetString("security", &security) || | |
| 776 !args->GetString("password", &password) || | |
| 777 !args->GetBoolean("shared", &shared)) { | |
| 778 AutomationJSONReply(this, reply_message).SendError( | |
| 779 "Invalid or missing args."); | |
| 780 return; | |
| 781 } | |
| 782 | |
| 783 std::map<std::string, chromeos::ConnectionSecurity> connection_security_map; | |
| 784 connection_security_map["SECURITY_NONE"] = chromeos::SECURITY_NONE; | |
| 785 connection_security_map["SECURITY_WEP"] = chromeos::SECURITY_WEP; | |
| 786 connection_security_map["SECURITY_WPA"] = chromeos::SECURITY_WPA; | |
| 787 connection_security_map["SECURITY_RSN"] = chromeos::SECURITY_RSN; | |
| 788 connection_security_map["SECURITY_8021X"] = chromeos::SECURITY_8021X; | |
| 789 | |
| 790 if (connection_security_map.find(security) == connection_security_map.end()) { | |
| 791 AutomationJSONReply(this, reply_message).SendError( | |
| 792 "Unknown security type."); | |
| 793 return; | |
| 794 } | |
| 795 chromeos::ConnectionSecurity connection_security = | |
| 796 connection_security_map[security]; | |
| 797 | |
| 798 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 799 | |
| 800 // Set up an observer (it will delete itself). | |
| 801 new SSIDConnectObserver(this, reply_message, ssid); | |
| 802 | |
| 803 bool save_credentials = false; | |
| 804 | |
| 805 if (connection_security == chromeos::SECURITY_8021X) { | |
| 806 chromeos::NetworkLibrary::EAPConfigData config_data; | |
| 807 std::string eap_method, eap_auth, eap_identity; | |
| 808 if (!args->GetString("eap_method", &eap_method) || | |
| 809 !args->GetString("eap_auth", &eap_auth) || | |
| 810 !args->GetString("eap_identity", &eap_identity) || | |
| 811 !args->GetBoolean("save_credentials", &save_credentials)) { | |
| 812 AutomationJSONReply(this, reply_message).SendError( | |
| 813 "Invalid or missing EAP args."); | |
| 814 return; | |
| 815 } | |
| 816 | |
| 817 std::map<std::string, chromeos::EAPMethod> eap_method_map; | |
| 818 eap_method_map["EAP_METHOD_NONE"] = chromeos::EAP_METHOD_UNKNOWN; | |
| 819 eap_method_map["EAP_METHOD_PEAP"] = chromeos::EAP_METHOD_PEAP; | |
| 820 eap_method_map["EAP_METHOD_TLS"] = chromeos::EAP_METHOD_TLS; | |
| 821 eap_method_map["EAP_METHOD_TTLS"] = chromeos::EAP_METHOD_TTLS; | |
| 822 eap_method_map["EAP_METHOD_LEAP"] = chromeos::EAP_METHOD_LEAP; | |
| 823 if (eap_method_map.find(eap_method) == eap_method_map.end()) { | |
| 824 AutomationJSONReply(this, reply_message).SendError( | |
| 825 "Unknown EAP Method type."); | |
| 826 return; | |
| 827 } | |
| 828 config_data.method = eap_method_map[eap_method]; | |
| 829 | |
| 830 std::map<std::string, chromeos::EAPPhase2Auth> eap_auth_map; | |
| 831 eap_auth_map["EAP_PHASE_2_AUTH_AUTO"] = chromeos::EAP_PHASE_2_AUTH_AUTO; | |
| 832 eap_auth_map["EAP_PHASE_2_AUTH_MD5"] = chromeos::EAP_PHASE_2_AUTH_MD5; | |
| 833 eap_auth_map["EAP_PHASE_2_AUTH_MSCHAP"] = | |
| 834 chromeos::EAP_PHASE_2_AUTH_MSCHAP; | |
| 835 eap_auth_map["EAP_PHASE_2_AUTH_MSCHAPV2"] = | |
| 836 chromeos::EAP_PHASE_2_AUTH_MSCHAPV2; | |
| 837 eap_auth_map["EAP_PHASE_2_AUTH_PAP"] = chromeos::EAP_PHASE_2_AUTH_PAP; | |
| 838 eap_auth_map["EAP_PHASE_2_AUTH_CHAP"] = chromeos::EAP_PHASE_2_AUTH_CHAP; | |
| 839 if (eap_auth_map.find(eap_auth) == eap_auth_map.end()) { | |
| 840 AutomationJSONReply(this, reply_message).SendError( | |
| 841 "Unknown EAP Phase2 Auth type."); | |
| 842 return; | |
| 843 } | |
| 844 config_data.auth = eap_auth_map[eap_auth]; | |
| 845 | |
| 846 config_data.identity = eap_identity; | |
| 847 | |
| 848 // TODO(stevenjb): Parse cert values? | |
| 849 config_data.use_system_cas = false; | |
| 850 config_data.client_cert_pkcs11_id = ""; | |
| 851 | |
| 852 network_library->ConnectToUnconfiguredWifiNetwork( | |
| 853 ssid, chromeos::SECURITY_8021X, password, &config_data, | |
| 854 save_credentials, shared); | |
| 855 } else { | |
| 856 network_library->ConnectToUnconfiguredWifiNetwork( | |
| 857 ssid, connection_security, password, NULL, | |
| 858 save_credentials, shared); | |
| 859 } | |
| 860 } | |
| 861 | |
| 862 void TestingAutomationProvider::DisconnectFromWifiNetwork( | |
| 863 DictionaryValue* args, IPC::Message* reply_message) { | |
| 864 AutomationJSONReply reply(this, reply_message); | |
| 865 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 866 const chromeos::WifiNetwork* wifi = network_library->wifi_network(); | |
| 867 if (!wifi) { | |
| 868 reply.SendError("Not connected to any wifi network."); | |
| 869 return; | |
| 870 } | |
| 871 | |
| 872 network_library->DisconnectFromNetwork(wifi); | |
| 873 reply.SendSuccess(NULL); | |
| 874 } | |
| 875 | |
| 876 void TestingAutomationProvider::AddPrivateNetwork( | |
| 877 DictionaryValue* args, IPC::Message* reply_message) { | |
| 878 std::string hostname, service_name, provider_type, key, cert_id, username, | |
| 879 password; | |
| 880 if (!args->GetString("hostname", &hostname) || | |
| 881 !args->GetString("service_name", &service_name) || | |
| 882 !args->GetString("provider_type", &provider_type) || | |
| 883 !args->GetString("username", &username) || | |
| 884 !args->GetString("password", &password)) { | |
| 885 AutomationJSONReply(this, reply_message) | |
| 886 .SendError("Invalid or missing args."); | |
| 887 return; | |
| 888 } | |
| 889 | |
| 890 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 891 | |
| 892 // Attempt to connect to the VPN based on the provider type. | |
| 893 if (provider_type == VPNProviderTypeToString( | |
| 894 chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK)) { | |
| 895 if (!args->GetString("key", &key)) { | |
| 896 AutomationJSONReply(this, reply_message) | |
| 897 .SendError("Missing key arg."); | |
| 898 return; | |
| 899 } | |
| 900 new VirtualConnectObserver(this, reply_message, service_name); | |
| 901 // Connect using a pre-shared key. | |
| 902 chromeos::NetworkLibrary::VPNConfigData config_data; | |
| 903 config_data.psk = key; | |
| 904 config_data.username = username; | |
| 905 config_data.user_passphrase = password; | |
| 906 network_library->ConnectToUnconfiguredVirtualNetwork( | |
| 907 service_name, | |
| 908 hostname, | |
| 909 chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK, | |
| 910 config_data); | |
| 911 } else if (provider_type == VPNProviderTypeToString( | |
| 912 chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT)) { | |
| 913 if (!args->GetString("cert_id", &cert_id)) { | |
| 914 AutomationJSONReply(this, reply_message) | |
| 915 .SendError("Missing a certificate arg."); | |
| 916 return; | |
| 917 } | |
| 918 new VirtualConnectObserver(this, reply_message, service_name); | |
| 919 // Connect using a user certificate. | |
| 920 chromeos::NetworkLibrary::VPNConfigData config_data; | |
| 921 config_data.client_cert_pkcs11_id = cert_id; | |
| 922 config_data.username = username; | |
| 923 config_data.user_passphrase = password; | |
| 924 network_library->ConnectToUnconfiguredVirtualNetwork( | |
| 925 service_name, | |
| 926 hostname, | |
| 927 chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT, | |
| 928 config_data); | |
| 929 } else if (provider_type == VPNProviderTypeToString( | |
| 930 chromeos::PROVIDER_TYPE_OPEN_VPN)) { | |
| 931 std::string otp; | |
| 932 args->GetString("otp", &otp); | |
| 933 // Connect using OPEN_VPN. | |
| 934 chromeos::NetworkLibrary::VPNConfigData config_data; | |
| 935 config_data.client_cert_pkcs11_id = cert_id; | |
| 936 config_data.username = username; | |
| 937 config_data.user_passphrase = password; | |
| 938 config_data.otp = otp; | |
| 939 network_library->ConnectToUnconfiguredVirtualNetwork( | |
| 940 service_name, | |
| 941 hostname, | |
| 942 chromeos::PROVIDER_TYPE_OPEN_VPN, | |
| 943 config_data); | |
| 944 } else { | |
| 945 AutomationJSONReply(this, reply_message) | |
| 946 .SendError("Unsupported provider type."); | |
| 947 return; | |
| 948 } | |
| 949 } | |
| 950 | |
| 951 void TestingAutomationProvider::ConnectToPrivateNetwork( | |
| 952 DictionaryValue* args, IPC::Message* reply_message) { | |
| 953 AutomationJSONReply reply(this, reply_message); | |
| 954 std::string service_path; | |
| 955 if (!args->GetString("service_path", &service_path)) { | |
| 956 reply.SendError("Invalid or missing args."); | |
| 957 return; | |
| 958 } | |
| 959 | |
| 960 // Connect to a remembered VPN by its service_path. Valid service_paths | |
| 961 // can be found in the dictionary returned by GetPrivateNetworkInfo. | |
| 962 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 963 chromeos::VirtualNetwork* network = | |
| 964 network_library->FindVirtualNetworkByPath(service_path); | |
| 965 if (!network) { | |
| 966 reply.SendError(base::StringPrintf("No virtual network found: %s", | |
| 967 service_path.c_str())); | |
| 968 return; | |
| 969 } | |
| 970 if (network->NeedMoreInfoToConnect()) { | |
| 971 reply.SendError("Virtual network is missing info required to connect."); | |
| 972 return; | |
| 973 }; | |
| 974 | |
| 975 // Set up an observer (it will delete itself). | |
| 976 new VirtualConnectObserver(this, reply_message, network->name()); | |
| 977 network_library->ConnectToVirtualNetwork(network); | |
| 978 } | |
| 979 | |
| 980 void TestingAutomationProvider::GetPrivateNetworkInfo( | |
| 981 DictionaryValue* args, IPC::Message* reply_message) { | |
| 982 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
| 983 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 984 const chromeos::VirtualNetworkVector& virtual_networks = | |
| 985 network_library->virtual_networks(); | |
| 986 | |
| 987 // Construct a dictionary of fields describing remembered VPNs. Also list | |
| 988 // the currently active VPN, if any. | |
| 989 if (network_library->virtual_network()) | |
| 990 return_value->SetString("connected", | |
| 991 network_library->virtual_network()->service_path()); | |
| 992 for (chromeos::VirtualNetworkVector::const_iterator iter = | |
| 993 virtual_networks.begin(); iter != virtual_networks.end(); ++iter) { | |
| 994 const chromeos::VirtualNetwork* virt = *iter; | |
| 995 DictionaryValue* item = new DictionaryValue; | |
| 996 item->SetString("name", virt->name()); | |
| 997 item->SetString("provider_type", | |
| 998 VPNProviderTypeToString(virt->provider_type())); | |
| 999 item->SetString("hostname", virt->server_hostname()); | |
| 1000 item->SetString("key", virt->psk_passphrase()); | |
| 1001 item->SetString("cert_id", virt->client_cert_id()); | |
| 1002 item->SetString("username", virt->username()); | |
| 1003 item->SetString("password", virt->user_passphrase()); | |
| 1004 return_value->Set(virt->service_path(), item); | |
| 1005 } | |
| 1006 | |
| 1007 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | |
| 1008 } | |
| 1009 | |
| 1010 void TestingAutomationProvider::DisconnectFromPrivateNetwork( | |
| 1011 DictionaryValue* args, IPC::Message* reply_message) { | |
| 1012 AutomationJSONReply reply(this, reply_message); | |
| 1013 NetworkLibrary* network_library = NetworkLibrary::Get(); | |
| 1014 const chromeos::VirtualNetwork* virt = network_library->virtual_network(); | |
| 1015 if (!virt) { | |
| 1016 reply.SendError("Not connected to any virtual network."); | |
| 1017 return; | |
| 1018 } | |
| 1019 | |
| 1020 network_library->DisconnectFromNetwork(virt); | |
| 1021 reply.SendSuccess(NULL); | |
| 1022 } | |
| 1023 | |
| 1024 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI( | 648 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI( |
| 1025 DictionaryValue* args, IPC::Message* reply_message) { | 649 DictionaryValue* args, IPC::Message* reply_message) { |
| 1026 std::string javascript, frame_xpath; | 650 std::string javascript, frame_xpath; |
| 1027 if (!args->GetString("javascript", &javascript)) { | 651 if (!args->GetString("javascript", &javascript)) { |
| 1028 AutomationJSONReply(this, reply_message) | 652 AutomationJSONReply(this, reply_message) |
| 1029 .SendError("'javascript' missing or invalid"); | 653 .SendError("'javascript' missing or invalid"); |
| 1030 return; | 654 return; |
| 1031 } | 655 } |
| 1032 if (!args->GetString("frame_xpath", &frame_xpath)) { | 656 if (!args->GetString("frame_xpath", &frame_xpath)) { |
| 1033 AutomationJSONReply(this, reply_message) | 657 AutomationJSONReply(this, reply_message) |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 816 |
| 1193 void TestingAutomationProvider::AddChromeosObservers() { | 817 void TestingAutomationProvider::AddChromeosObservers() { |
| 1194 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 818 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 1195 AddObserver(this); | 819 AddObserver(this); |
| 1196 } | 820 } |
| 1197 | 821 |
| 1198 void TestingAutomationProvider::RemoveChromeosObservers() { | 822 void TestingAutomationProvider::RemoveChromeosObservers() { |
| 1199 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 823 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 1200 RemoveObserver(this); | 824 RemoveObserver(this); |
| 1201 } | 825 } |
| OLD | NEW |