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/net_internals/net_internals_ui.h" | 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 82 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
83 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h" | 83 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h" |
84 #include "chrome/browser/net/nss_context.h" | 84 #include "chrome/browser/net/nss_context.h" |
85 #include "chromeos/dbus/dbus_thread_manager.h" | 85 #include "chromeos/dbus/dbus_thread_manager.h" |
86 #include "chromeos/dbus/debug_daemon_client.h" | 86 #include "chromeos/dbus/debug_daemon_client.h" |
87 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 87 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
88 #include "chromeos/network/onc/onc_utils.h" | 88 #include "chromeos/network/onc/onc_utils.h" |
89 #include "components/user_manager/user.h" | 89 #include "components/user_manager/user.h" |
90 #endif | 90 #endif |
91 | 91 |
92 using base::StringValue; | 92 using base::Value; |
93 using content::BrowserThread; | 93 using content::BrowserThread; |
94 using content::WebContents; | 94 using content::WebContents; |
95 using content::WebUIMessageHandler; | 95 using content::WebUIMessageHandler; |
96 | 96 |
97 namespace { | 97 namespace { |
98 | 98 |
99 // Delay between when an event occurs and when it is passed to the Javascript | 99 // Delay between when an event occurs and when it is passed to the Javascript |
100 // page. All events that occur during this period are grouped together and | 100 // page. All events that occur during this period are grouped together and |
101 // sent to the page at once, which reduces context switching and CPU usage. | 101 // sent to the page at once, which reduces context switching and CPU usage. |
102 const int kNetLogEventDelayMilliseconds = 100; | 102 const int kNetLogEventDelayMilliseconds = 100; |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 web_ui()->RegisterMessageCallback( | 477 web_ui()->RegisterMessageCallback( |
478 "setNetworkDebugMode", | 478 "setNetworkDebugMode", |
479 base::Bind(&NetInternalsMessageHandler::OnSetNetworkDebugMode, | 479 base::Bind(&NetInternalsMessageHandler::OnSetNetworkDebugMode, |
480 base::Unretained(this))); | 480 base::Unretained(this))); |
481 #endif | 481 #endif |
482 } | 482 } |
483 | 483 |
484 void NetInternalsMessageHandler::SendJavascriptCommand( | 484 void NetInternalsMessageHandler::SendJavascriptCommand( |
485 const std::string& command, | 485 const std::string& command, |
486 std::unique_ptr<base::Value> arg) { | 486 std::unique_ptr<base::Value> arg) { |
487 std::unique_ptr<base::Value> command_value(new base::StringValue(command)); | 487 std::unique_ptr<base::Value> command_value(new base::Value(command)); |
488 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 488 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
489 if (arg) { | 489 if (arg) { |
490 web_ui()->CallJavascriptFunctionUnsafe("g_browser.receive", | 490 web_ui()->CallJavascriptFunctionUnsafe("g_browser.receive", |
491 *command_value.get(), *arg.get()); | 491 *command_value.get(), *arg.get()); |
492 } else { | 492 } else { |
493 web_ui()->CallJavascriptFunctionUnsafe("g_browser.receive", | 493 web_ui()->CallJavascriptFunctionUnsafe("g_browser.receive", |
494 *command_value.get()); | 494 *command_value.get()); |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 const std::string& onc_blob, | 838 const std::string& onc_blob, |
839 const std::string& passcode, | 839 const std::string& passcode, |
840 net::NSSCertDatabase* nssdb) { | 840 net::NSSCertDatabase* nssdb) { |
841 const user_manager::User* user = | 841 const user_manager::User* user = |
842 chromeos::ProfileHelper::Get()->GetUserByProfile( | 842 chromeos::ProfileHelper::Get()->GetUserByProfile( |
843 Profile::FromWebUI(web_ui())); | 843 Profile::FromWebUI(web_ui())); |
844 | 844 |
845 if (!user) { | 845 if (!user) { |
846 std::string error = "User not found."; | 846 std::string error = "User not found."; |
847 SendJavascriptCommand("receivedONCFileParse", | 847 SendJavascriptCommand("receivedONCFileParse", |
848 base::MakeUnique<base::StringValue>(error)); | 848 base::MakeUnique<base::Value>(error)); |
849 return; | 849 return; |
850 } | 850 } |
851 | 851 |
852 std::string error; | 852 std::string error; |
853 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT; | 853 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT; |
854 base::ListValue network_configs; | 854 base::ListValue network_configs; |
855 base::DictionaryValue global_network_config; | 855 base::DictionaryValue global_network_config; |
856 base::ListValue certificates; | 856 base::ListValue certificates; |
857 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob, | 857 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob, |
858 onc_source, | 858 onc_source, |
(...skipping 21 matching lines...) Expand all Loading... |
880 | 880 |
881 void NetInternalsMessageHandler::OnCertificatesImported( | 881 void NetInternalsMessageHandler::OnCertificatesImported( |
882 const std::string& previous_error, | 882 const std::string& previous_error, |
883 bool success, | 883 bool success, |
884 const net::CertificateList& /* unused onc_trusted_certificates */) { | 884 const net::CertificateList& /* unused onc_trusted_certificates */) { |
885 std::string error = previous_error; | 885 std::string error = previous_error; |
886 if (!success) | 886 if (!success) |
887 error += "Some certificates couldn't be imported. "; | 887 error += "Some certificates couldn't be imported. "; |
888 | 888 |
889 SendJavascriptCommand("receivedONCFileParse", | 889 SendJavascriptCommand("receivedONCFileParse", |
890 base::MakeUnique<base::StringValue>(error)); | 890 base::MakeUnique<base::Value>(error)); |
891 } | 891 } |
892 | 892 |
893 void NetInternalsMessageHandler::OnImportONCFile( | 893 void NetInternalsMessageHandler::OnImportONCFile( |
894 const base::ListValue* list) { | 894 const base::ListValue* list) { |
895 std::string onc_blob; | 895 std::string onc_blob; |
896 std::string passcode; | 896 std::string passcode; |
897 if (list->GetSize() != 2 || | 897 if (list->GetSize() != 2 || |
898 !list->GetString(0, &onc_blob) || | 898 !list->GetString(0, &onc_blob) || |
899 !list->GetString(1, &passcode)) { | 899 !list->GetString(1, &passcode)) { |
900 NOTREACHED(); | 900 NOTREACHED(); |
901 } | 901 } |
902 | 902 |
903 GetNSSCertDatabaseForProfile( | 903 GetNSSCertDatabaseForProfile( |
904 Profile::FromWebUI(web_ui()), | 904 Profile::FromWebUI(web_ui()), |
905 base::Bind(&NetInternalsMessageHandler::ImportONCFileToNSSDB, AsWeakPtr(), | 905 base::Bind(&NetInternalsMessageHandler::ImportONCFileToNSSDB, AsWeakPtr(), |
906 onc_blob, passcode)); | 906 onc_blob, passcode)); |
907 } | 907 } |
908 | 908 |
909 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) { | 909 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) { |
910 DCHECK(list); | 910 DCHECK(list); |
911 | 911 |
912 SendJavascriptCommand( | 912 SendJavascriptCommand("receivedStoreDebugLogs", |
913 "receivedStoreDebugLogs", | 913 base::MakeUnique<base::Value>("Creating log file...")); |
914 base::MakeUnique<base::StringValue>("Creating log file...")); | |
915 Profile* profile = Profile::FromWebUI(web_ui()); | 914 Profile* profile = Profile::FromWebUI(web_ui()); |
916 const DownloadPrefs* const prefs = DownloadPrefs::FromBrowserContext(profile); | 915 const DownloadPrefs* const prefs = DownloadPrefs::FromBrowserContext(profile); |
917 base::FilePath path = prefs->DownloadPath(); | 916 base::FilePath path = prefs->DownloadPath(); |
918 if (file_manager::util::IsUnderNonNativeLocalPath(profile, path)) | 917 if (file_manager::util::IsUnderNonNativeLocalPath(profile, path)) |
919 path = prefs->GetDefaultDownloadDirectoryForProfile(); | 918 path = prefs->GetDefaultDownloadDirectoryForProfile(); |
920 chromeos::DebugLogWriter::StoreLogs( | 919 chromeos::DebugLogWriter::StoreLogs( |
921 path, | 920 path, |
922 true, // should_compress | 921 true, // should_compress |
923 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, | 922 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, |
924 AsWeakPtr())); | 923 AsWeakPtr())); |
925 } | 924 } |
926 | 925 |
927 void NetInternalsMessageHandler::OnStoreDebugLogsCompleted( | 926 void NetInternalsMessageHandler::OnStoreDebugLogsCompleted( |
928 const base::FilePath& log_path, bool succeeded) { | 927 const base::FilePath& log_path, bool succeeded) { |
929 std::string status; | 928 std::string status; |
930 if (succeeded) | 929 if (succeeded) |
931 status = "Created log file: " + log_path.BaseName().AsUTF8Unsafe(); | 930 status = "Created log file: " + log_path.BaseName().AsUTF8Unsafe(); |
932 else | 931 else |
933 status = "Failed to create log file"; | 932 status = "Failed to create log file"; |
934 SendJavascriptCommand("receivedStoreDebugLogs", | 933 SendJavascriptCommand("receivedStoreDebugLogs", |
935 base::MakeUnique<base::StringValue>(status)); | 934 base::MakeUnique<base::Value>(status)); |
936 } | 935 } |
937 | 936 |
938 void NetInternalsMessageHandler::OnSetNetworkDebugMode( | 937 void NetInternalsMessageHandler::OnSetNetworkDebugMode( |
939 const base::ListValue* list) { | 938 const base::ListValue* list) { |
940 std::string subsystem; | 939 std::string subsystem; |
941 if (list->GetSize() != 1 || !list->GetString(0, &subsystem)) | 940 if (list->GetSize() != 1 || !list->GetString(0, &subsystem)) |
942 NOTREACHED(); | 941 NOTREACHED(); |
943 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | 942 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> |
944 SetDebugMode( | 943 SetDebugMode( |
945 subsystem, | 944 subsystem, |
946 base::Bind( | 945 base::Bind( |
947 &NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted, | 946 &NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted, |
948 AsWeakPtr(), | 947 AsWeakPtr(), |
949 subsystem)); | 948 subsystem)); |
950 } | 949 } |
951 | 950 |
952 void NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted( | 951 void NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted( |
953 const std::string& subsystem, | 952 const std::string& subsystem, |
954 bool succeeded) { | 953 bool succeeded) { |
955 std::string status = succeeded ? "Debug mode is changed to " | 954 std::string status = succeeded ? "Debug mode is changed to " |
956 : "Failed to change debug mode to "; | 955 : "Failed to change debug mode to "; |
957 status += subsystem; | 956 status += subsystem; |
958 SendJavascriptCommand("receivedSetNetworkDebugMode", | 957 SendJavascriptCommand("receivedSetNetworkDebugMode", |
959 base::MakeUnique<base::StringValue>(status)); | 958 base::MakeUnique<base::Value>(status)); |
960 } | 959 } |
961 #endif // defined(OS_CHROMEOS) | 960 #endif // defined(OS_CHROMEOS) |
962 | 961 |
963 void NetInternalsMessageHandler::IOThreadImpl::OnSetCaptureMode( | 962 void NetInternalsMessageHandler::IOThreadImpl::OnSetCaptureMode( |
964 const base::ListValue* list) { | 963 const base::ListValue* list) { |
965 std::string capture_mode_string; | 964 std::string capture_mode_string; |
966 if (!list->GetString(0, &capture_mode_string)) { | 965 if (!list->GetString(0, &capture_mode_string)) { |
967 NOTREACHED(); | 966 NOTREACHED(); |
968 return; | 967 return; |
969 } | 968 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 //////////////////////////////////////////////////////////////////////////////// | 1054 //////////////////////////////////////////////////////////////////////////////// |
1056 | 1055 |
1057 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1056 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1058 : WebUIController(web_ui) { | 1057 : WebUIController(web_ui) { |
1059 web_ui->AddMessageHandler(base::MakeUnique<NetInternalsMessageHandler>()); | 1058 web_ui->AddMessageHandler(base::MakeUnique<NetInternalsMessageHandler>()); |
1060 | 1059 |
1061 // Set up the chrome://net-internals/ source. | 1060 // Set up the chrome://net-internals/ source. |
1062 Profile* profile = Profile::FromWebUI(web_ui); | 1061 Profile* profile = Profile::FromWebUI(web_ui); |
1063 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1062 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
1064 } | 1063 } |
OLD | NEW |