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

Side by Side Diff: chrome/browser/automation/testing_automation_provider_chromeos.cc

Issue 23618026: NOT FOR SUBMIT: Remove NetworkLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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/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"
11 #include "base/i18n/time_formatting.h" 11 #include "base/i18n/time_formatting.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/automation/automation_provider_json.h" 16 #include "chrome/browser/automation/automation_provider_json.h"
17 #include "chrome/browser/automation/automation_provider_observers.h" 17 #include "chrome/browser/automation/automation_provider_observers.h"
18 #include "chrome/browser/automation/automation_util.h" 18 #include "chrome/browser/automation/automation_util.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
21 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 21 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
22 #include "chrome/browser/chromeos/cros/network_library.h"
23 #include "chrome/browser/chromeos/login/default_user_images.h" 22 #include "chrome/browser/chromeos/login/default_user_images.h"
24 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" 23 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
25 #include "chrome/browser/chromeos/login/existing_user_controller.h" 24 #include "chrome/browser/chromeos/login/existing_user_controller.h"
26 #include "chrome/browser/chromeos/login/login_display.h" 25 #include "chrome/browser/chromeos/login/login_display.h"
27 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 26 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
28 #include "chrome/browser/chromeos/login/screen_locker.h" 27 #include "chrome/browser/chromeos/login/screen_locker.h"
29 #include "chrome/browser/chromeos/login/screens/eula_screen.h" 28 #include "chrome/browser/chromeos/login/screens/eula_screen.h"
30 #include "chrome/browser/chromeos/login/screens/network_screen.h" 29 #include "chrome/browser/chromeos/login/screens/network_screen.h"
31 #include "chrome/browser/chromeos/login/screens/update_screen.h" 30 #include "chrome/browser/chromeos/login/screens/update_screen.h"
32 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" 31 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
(...skipping 15 matching lines...) Expand all
48 #include "chromeos/dbus/update_engine_client.h" 47 #include "chromeos/dbus/update_engine_client.h"
49 #include "chromeos/network/network_state_handler.h" 48 #include "chromeos/network/network_state_handler.h"
50 #include "chromeos/network/onc/onc_utils.h" 49 #include "chromeos/network/onc/onc_utils.h"
51 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
52 #include "net/base/network_change_notifier.h" 51 #include "net/base/network_change_notifier.h"
53 #include "policy/policy_constants.h" 52 #include "policy/policy_constants.h"
54 #include "ui/views/widget/widget.h" 53 #include "ui/views/widget/widget.h"
55 54
56 using chromeos::DBusThreadManager; 55 using chromeos::DBusThreadManager;
57 using chromeos::ExistingUserController; 56 using chromeos::ExistingUserController;
58 using chromeos::NetworkLibrary;
59 using chromeos::UpdateEngineClient; 57 using chromeos::UpdateEngineClient;
60 using chromeos::User; 58 using chromeos::User;
61 using chromeos::UserManager; 59 using chromeos::UserManager;
62 using chromeos::WizardController; 60 using chromeos::WizardController;
63 61
64 namespace { 62 namespace {
65 63
66 DictionaryValue* GetNetworkInfoDict(const chromeos::Network* network) {
67 DictionaryValue* item = new DictionaryValue;
68 item->SetString("name", network->name());
69 item->SetString("device_path", network->device_path());
70 item->SetString("status", network->GetStateString());
71 return item;
72 }
73
74 DictionaryValue* GetWifiInfoDict(const chromeos::WifiNetwork* wifi) {
75 DictionaryValue* item = GetNetworkInfoDict(wifi);
76 item->SetInteger("strength", wifi->strength());
77 item->SetBoolean("encrypted", wifi->encrypted());
78 item->SetString("encryption", wifi->GetEncryptionString());
79 return item;
80 }
81
82 const char* UpdateStatusToString( 64 const char* UpdateStatusToString(
83 UpdateEngineClient::UpdateStatusOperation status) { 65 UpdateEngineClient::UpdateStatusOperation status) {
84 switch (status) { 66 switch (status) {
85 case UpdateEngineClient::UPDATE_STATUS_IDLE: 67 case UpdateEngineClient::UPDATE_STATUS_IDLE:
86 return "idle"; 68 return "idle";
87 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: 69 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE:
88 return "checking for update"; 70 return "checking for update";
89 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: 71 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE:
90 return "update available"; 72 return "update available";
91 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: 73 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING:
(...skipping 13 matching lines...) Expand all
105 87
106 void UpdateCheckCallback(AutomationJSONReply* reply, 88 void UpdateCheckCallback(AutomationJSONReply* reply,
107 UpdateEngineClient::UpdateCheckResult result) { 89 UpdateEngineClient::UpdateCheckResult result) {
108 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS) 90 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS)
109 reply->SendSuccess(NULL); 91 reply->SendSuccess(NULL);
110 else 92 else
111 reply->SendError("update check failed"); 93 reply->SendError("update check failed");
112 delete reply; 94 delete reply;
113 } 95 }
114 96
115 const std::string VPNProviderTypeToString(
116 chromeos::ProviderType provider_type) {
117 switch (provider_type) {
118 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK:
119 return std::string("L2TP_IPSEC_PSK");
120 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT:
121 return std::string("L2TP_IPSEC_USER_CERT");
122 case chromeos::PROVIDER_TYPE_OPEN_VPN:
123 return std::string("OPEN_VPN");
124 default:
125 return std::string("UNSUPPORTED_PROVIDER_TYPE");
126 }
127 }
128
129 } // namespace 97 } // namespace
130 98
131 #if defined(OS_CHROMEOS) 99 #if defined(OS_CHROMEOS)
132 void TestingAutomationProvider::PowerChanged( 100 void TestingAutomationProvider::PowerChanged(
133 const power_manager::PowerSupplyProperties& proto) { 101 const power_manager::PowerSupplyProperties& proto) {
134 power_supply_properties_ = proto; 102 power_supply_properties_ = proto;
135 } 103 }
136 #endif 104 #endif
137 105
138 void TestingAutomationProvider::AcceptOOBENetworkScreen( 106 void TestingAutomationProvider::AcceptOOBENetworkScreen(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } else { 454 } else {
487 int64 time = power_supply_properties_.battery_time_to_empty_sec(); 455 int64 time = power_supply_properties_.battery_time_to_empty_sec();
488 if (time > 0) 456 if (time > 0)
489 return_value->SetInteger("battery_seconds_to_empty", time); 457 return_value->SetInteger("battery_seconds_to_empty", time);
490 } 458 }
491 } 459 }
492 460
493 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); 461 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
494 } 462 }
495 463
496 void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
497 IPC::Message* reply_message) {
498 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
499 NetworkLibrary* network_library = NetworkLibrary::Get();
500
501 return_value->SetBoolean("offline_mode",
502 net::NetworkChangeNotifier::IsOffline());
503
504 // Currently connected networks.
505 if (network_library->ethernet_network())
506 return_value->SetString(
507 "connected_ethernet",
508 network_library->ethernet_network()->service_path());
509 if (network_library->wifi_network())
510 return_value->SetString("connected_wifi",
511 network_library->wifi_network()->service_path());
512 if (network_library->cellular_network())
513 return_value->SetString(
514 "connected_cellular",
515 network_library->cellular_network()->service_path());
516
517 // Ethernet network.
518 bool ethernet_available = network_library->ethernet_available();
519 bool ethernet_enabled = network_library->ethernet_enabled();
520 return_value->SetBoolean("ethernet_available", ethernet_available);
521 return_value->SetBoolean("ethernet_enabled", ethernet_enabled);
522 if (ethernet_available && ethernet_enabled) {
523 const chromeos::EthernetNetwork* ethernet_network =
524 network_library->ethernet_network();
525 if (ethernet_network) {
526 DictionaryValue* items = new DictionaryValue;
527 DictionaryValue* item = GetNetworkInfoDict(ethernet_network);
528 items->Set(ethernet_network->service_path(), item);
529 items->SetInteger("network_type", chromeos::TYPE_ETHERNET);
530 return_value->Set("ethernet_networks", items);
531 }
532 }
533
534 // Wi-fi networks.
535 bool wifi_available = network_library->wifi_available();
536 bool wifi_enabled = network_library->wifi_enabled();
537 return_value->SetBoolean("wifi_available", wifi_available);
538 return_value->SetBoolean("wifi_enabled", wifi_enabled);
539 if (wifi_available && wifi_enabled) {
540 const chromeos::WifiNetworkVector& wifi_networks =
541 network_library->wifi_networks();
542 DictionaryValue* items = new DictionaryValue;
543 for (chromeos::WifiNetworkVector::const_iterator iter =
544 wifi_networks.begin(); iter != wifi_networks.end(); ++iter) {
545 const chromeos::WifiNetwork* wifi = *iter;
546 DictionaryValue* item = GetWifiInfoDict(wifi);
547 items->Set(wifi->service_path(), item);
548 }
549 items->SetInteger("network_type", chromeos::TYPE_WIFI);
550 return_value->Set("wifi_networks", items);
551 }
552
553 // Cellular networks.
554 bool cellular_available = network_library->cellular_available();
555 bool cellular_enabled = network_library->cellular_enabled();
556 return_value->SetBoolean("cellular_available", cellular_available);
557 return_value->SetBoolean("cellular_enabled", cellular_enabled);
558 if (cellular_available && cellular_enabled) {
559 const chromeos::CellularNetworkVector& cellular_networks =
560 network_library->cellular_networks();
561 DictionaryValue* items = new DictionaryValue;
562 for (size_t i = 0; i < cellular_networks.size(); ++i) {
563 DictionaryValue* item = GetNetworkInfoDict(cellular_networks[i]);
564 item->SetInteger("strength", cellular_networks[i]->strength());
565 item->SetString("operator_name", cellular_networks[i]->operator_name());
566 item->SetString("operator_code", cellular_networks[i]->operator_code());
567 item->SetString("payment_url", cellular_networks[i]->payment_url());
568 item->SetString("usage_url", cellular_networks[i]->usage_url());
569 item->SetString("network_technology",
570 cellular_networks[i]->GetNetworkTechnologyString());
571 item->SetString("activation_state",
572 cellular_networks[i]->GetActivationStateString());
573 item->SetString("roaming_state",
574 cellular_networks[i]->GetRoamingStateString());
575 items->Set(cellular_networks[i]->service_path(), item);
576 }
577 items->SetInteger("network_type", chromeos::TYPE_CELLULAR);
578 return_value->Set("cellular_networks", items);
579 }
580
581 // Remembered Wifi Networks.
582 const chromeos::WifiNetworkVector& remembered_wifi =
583 network_library->remembered_wifi_networks();
584 DictionaryValue* remembered_wifi_items = new DictionaryValue;
585 for (chromeos::WifiNetworkVector::const_iterator iter =
586 remembered_wifi.begin(); iter != remembered_wifi.end();
587 ++iter) {
588 const chromeos::WifiNetwork* wifi = *iter;
589 DictionaryValue* item = GetWifiInfoDict(wifi);
590 remembered_wifi_items->Set(wifi->service_path(), item);
591 }
592 remembered_wifi_items->SetInteger("network_type", chromeos::TYPE_WIFI);
593 return_value->Set("remembered_wifi", remembered_wifi_items);
594
595 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
596 }
597
598 void TestingAutomationProvider::NetworkScan(DictionaryValue* args,
599 IPC::Message* reply_message) {
600 NetworkLibrary* network_library = NetworkLibrary::Get();
601 network_library->RequestNetworkScan();
602
603 // Set up an observer (it will delete itself).
604 new NetworkScanObserver(this, reply_message);
605 }
606
607 void TestingAutomationProvider::ToggleNetworkDevice(
608 DictionaryValue* args, IPC::Message* reply_message) {
609 AutomationJSONReply reply(this, reply_message);
610 std::string device;
611 bool enable;
612 if (!args->GetString("device", &device) ||
613 !args->GetBoolean("enable", &enable)) {
614 reply.SendError("Invalid or missing args.");
615 return;
616 }
617
618 // Set up an observer (it will delete itself).
619 new ToggleNetworkDeviceObserver(this, reply_message, device, enable);
620
621 NetworkLibrary* network_library = NetworkLibrary::Get();
622 if (device == "ethernet") {
623 network_library->EnableEthernetNetworkDevice(enable);
624 } else if (device == "wifi") {
625 network_library->EnableWifiNetworkDevice(enable);
626 } else if (device == "cellular") {
627 network_library->EnableCellularNetworkDevice(enable);
628 } else {
629 reply.SendError(
630 "Unknown device. Valid devices are ethernet, wifi, cellular.");
631 return;
632 }
633 }
634
635 void TestingAutomationProvider::ForgetWifiNetwork(
636 DictionaryValue* args, IPC::Message* reply_message) {
637 std::string service_path;
638 if (!args->GetString("service_path", &service_path)) {
639 AutomationJSONReply(this, reply_message).SendError(
640 "Invalid or missing args.");
641 return;
642 }
643
644 NetworkLibrary::Get()->ForgetNetwork(service_path);
645 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
646 }
647
648 void TestingAutomationProvider::ConnectToHiddenWifiNetwork(
649 DictionaryValue* args, IPC::Message* reply_message) {
650 std::string ssid, security, password;
651 bool shared;
652 if (!args->GetString("ssid", &ssid) ||
653 !args->GetString("security", &security) ||
654 !args->GetString("password", &password) ||
655 !args->GetBoolean("shared", &shared)) {
656 AutomationJSONReply(this, reply_message).SendError(
657 "Invalid or missing args.");
658 return;
659 }
660
661 std::map<std::string, chromeos::ConnectionSecurity> connection_security_map;
662 connection_security_map["SECURITY_NONE"] = chromeos::SECURITY_NONE;
663 connection_security_map["SECURITY_WEP"] = chromeos::SECURITY_WEP;
664 connection_security_map["SECURITY_WPA"] = chromeos::SECURITY_WPA;
665 connection_security_map["SECURITY_RSN"] = chromeos::SECURITY_RSN;
666 connection_security_map["SECURITY_8021X"] = chromeos::SECURITY_8021X;
667
668 if (connection_security_map.find(security) == connection_security_map.end()) {
669 AutomationJSONReply(this, reply_message).SendError(
670 "Unknown security type.");
671 return;
672 }
673 chromeos::ConnectionSecurity connection_security =
674 connection_security_map[security];
675
676 NetworkLibrary* network_library = NetworkLibrary::Get();
677
678 // Set up an observer (it will delete itself).
679 new SSIDConnectObserver(this, reply_message, ssid);
680
681 bool save_credentials = false;
682
683 if (connection_security == chromeos::SECURITY_8021X) {
684 chromeos::NetworkLibrary::EAPConfigData config_data;
685 std::string eap_method, eap_auth, eap_identity;
686 if (!args->GetString("eap_method", &eap_method) ||
687 !args->GetString("eap_auth", &eap_auth) ||
688 !args->GetString("eap_identity", &eap_identity) ||
689 !args->GetBoolean("save_credentials", &save_credentials)) {
690 AutomationJSONReply(this, reply_message).SendError(
691 "Invalid or missing EAP args.");
692 return;
693 }
694
695 std::map<std::string, chromeos::EAPMethod> eap_method_map;
696 eap_method_map["EAP_METHOD_NONE"] = chromeos::EAP_METHOD_UNKNOWN;
697 eap_method_map["EAP_METHOD_PEAP"] = chromeos::EAP_METHOD_PEAP;
698 eap_method_map["EAP_METHOD_TLS"] = chromeos::EAP_METHOD_TLS;
699 eap_method_map["EAP_METHOD_TTLS"] = chromeos::EAP_METHOD_TTLS;
700 eap_method_map["EAP_METHOD_LEAP"] = chromeos::EAP_METHOD_LEAP;
701 if (eap_method_map.find(eap_method) == eap_method_map.end()) {
702 AutomationJSONReply(this, reply_message).SendError(
703 "Unknown EAP Method type.");
704 return;
705 }
706 config_data.method = eap_method_map[eap_method];
707
708 std::map<std::string, chromeos::EAPPhase2Auth> eap_auth_map;
709 eap_auth_map["EAP_PHASE_2_AUTH_AUTO"] = chromeos::EAP_PHASE_2_AUTH_AUTO;
710 eap_auth_map["EAP_PHASE_2_AUTH_MD5"] = chromeos::EAP_PHASE_2_AUTH_MD5;
711 eap_auth_map["EAP_PHASE_2_AUTH_MSCHAP"] =
712 chromeos::EAP_PHASE_2_AUTH_MSCHAP;
713 eap_auth_map["EAP_PHASE_2_AUTH_MSCHAPV2"] =
714 chromeos::EAP_PHASE_2_AUTH_MSCHAPV2;
715 eap_auth_map["EAP_PHASE_2_AUTH_PAP"] = chromeos::EAP_PHASE_2_AUTH_PAP;
716 eap_auth_map["EAP_PHASE_2_AUTH_CHAP"] = chromeos::EAP_PHASE_2_AUTH_CHAP;
717 if (eap_auth_map.find(eap_auth) == eap_auth_map.end()) {
718 AutomationJSONReply(this, reply_message).SendError(
719 "Unknown EAP Phase2 Auth type.");
720 return;
721 }
722 config_data.auth = eap_auth_map[eap_auth];
723
724 config_data.identity = eap_identity;
725
726 // TODO(stevenjb): Parse cert values?
727 config_data.use_system_cas = false;
728 config_data.client_cert_pkcs11_id = "";
729
730 network_library->ConnectToUnconfiguredWifiNetwork(
731 ssid, chromeos::SECURITY_8021X, password, &config_data,
732 save_credentials, shared);
733 } else {
734 network_library->ConnectToUnconfiguredWifiNetwork(
735 ssid, connection_security, password, NULL,
736 save_credentials, shared);
737 }
738 }
739
740 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI( 464 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI(
741 DictionaryValue* args, IPC::Message* reply_message) { 465 DictionaryValue* args, IPC::Message* reply_message) {
742 std::string javascript, frame_xpath; 466 std::string javascript, frame_xpath;
743 if (!args->GetString("javascript", &javascript)) { 467 if (!args->GetString("javascript", &javascript)) {
744 AutomationJSONReply(this, reply_message) 468 AutomationJSONReply(this, reply_message)
745 .SendError("'javascript' missing or invalid"); 469 .SendError("'javascript' missing or invalid");
746 return; 470 return;
747 } 471 }
748 if (!args->GetString("frame_xpath", &frame_xpath)) { 472 if (!args->GetString("frame_xpath", &frame_xpath)) {
749 AutomationJSONReply(this, reply_message) 473 AutomationJSONReply(this, reply_message)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 632
909 void TestingAutomationProvider::AddChromeosObservers() { 633 void TestingAutomationProvider::AddChromeosObservers() {
910 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 634 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
911 AddObserver(this); 635 AddObserver(this);
912 } 636 }
913 637
914 void TestingAutomationProvider::RemoveChromeosObservers() { 638 void TestingAutomationProvider::RemoveChromeosObservers() {
915 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 639 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
916 RemoveObserver(this); 640 RemoveObserver(this);
917 } 641 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.cc ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698