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 <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 void OnEnableIPv6(const base::ListValue* list); | 292 void OnEnableIPv6(const base::ListValue* list); |
293 void OnHSTSQuery(const base::ListValue* list); | 293 void OnHSTSQuery(const base::ListValue* list); |
294 void OnHSTSAdd(const base::ListValue* list); | 294 void OnHSTSAdd(const base::ListValue* list); |
295 void OnHSTSDelete(const base::ListValue* list); | 295 void OnHSTSDelete(const base::ListValue* list); |
296 void OnGetSessionNetworkStats(const base::ListValue* list); | 296 void OnGetSessionNetworkStats(const base::ListValue* list); |
297 void OnCloseIdleSockets(const base::ListValue* list); | 297 void OnCloseIdleSockets(const base::ListValue* list); |
298 void OnFlushSocketPools(const base::ListValue* list); | 298 void OnFlushSocketPools(const base::ListValue* list); |
299 #if defined(OS_WIN) | 299 #if defined(OS_WIN) |
300 void OnGetServiceProviders(const base::ListValue* list); | 300 void OnGetServiceProviders(const base::ListValue* list); |
301 #endif | 301 #endif |
302 void OnSetLogLevel(const base::ListValue* list); | 302 void OnSetCaptureMode(const base::ListValue* list); |
303 | 303 |
304 // ChromeNetLog::ThreadSafeObserver implementation: | 304 // ChromeNetLog::ThreadSafeObserver implementation: |
305 void OnAddEntry(const net::NetLog::Entry& entry) override; | 305 void OnAddEntry(const net::NetLog::Entry& entry) override; |
306 | 306 |
307 // Helper that calls g_browser.receive in the renderer, passing in |command| | 307 // Helper that calls g_browser.receive in the renderer, passing in |command| |
308 // and |arg|. Takes ownership of |arg|. If the renderer is displaying a log | 308 // and |arg|. Takes ownership of |arg|. If the renderer is displaying a log |
309 // file, the message will be ignored. Note that this can be called from any | 309 // file, the message will be ignored. Note that this can be called from any |
310 // thread. | 310 // thread. |
311 void SendJavascriptCommand(const std::string& command, base::Value* arg); | 311 void SendJavascriptCommand(const std::string& command, base::Value* arg); |
312 | 312 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 base::Bind(&IOThreadImpl::CallbackHelper, | 459 base::Bind(&IOThreadImpl::CallbackHelper, |
460 &IOThreadImpl::OnFlushSocketPools, proxy_)); | 460 &IOThreadImpl::OnFlushSocketPools, proxy_)); |
461 #if defined(OS_WIN) | 461 #if defined(OS_WIN) |
462 web_ui()->RegisterMessageCallback( | 462 web_ui()->RegisterMessageCallback( |
463 "getServiceProviders", | 463 "getServiceProviders", |
464 base::Bind(&IOThreadImpl::CallbackHelper, | 464 base::Bind(&IOThreadImpl::CallbackHelper, |
465 &IOThreadImpl::OnGetServiceProviders, proxy_)); | 465 &IOThreadImpl::OnGetServiceProviders, proxy_)); |
466 #endif | 466 #endif |
467 | 467 |
468 web_ui()->RegisterMessageCallback( | 468 web_ui()->RegisterMessageCallback( |
469 "setLogLevel", | 469 "setCaptureMode", base::Bind(&IOThreadImpl::CallbackHelper, |
470 base::Bind(&IOThreadImpl::CallbackHelper, | 470 &IOThreadImpl::OnSetCaptureMode, proxy_)); |
471 &IOThreadImpl::OnSetLogLevel, proxy_)); | |
472 web_ui()->RegisterMessageCallback( | 471 web_ui()->RegisterMessageCallback( |
473 "clearBrowserCache", | 472 "clearBrowserCache", |
474 base::Bind(&NetInternalsMessageHandler::OnClearBrowserCache, | 473 base::Bind(&NetInternalsMessageHandler::OnClearBrowserCache, |
475 base::Unretained(this))); | 474 base::Unretained(this))); |
476 web_ui()->RegisterMessageCallback( | 475 web_ui()->RegisterMessageCallback( |
477 "getPrerenderInfo", | 476 "getPrerenderInfo", |
478 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, | 477 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, |
479 base::Unretained(this))); | 478 base::Unretained(this))); |
480 web_ui()->RegisterMessageCallback( | 479 web_ui()->RegisterMessageCallback( |
481 "getHistoricNetworkStats", | 480 "getHistoricNetworkStats", |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 if (net_log()) { | 675 if (net_log()) { |
677 net_log()->DeprecatedRemoveObserver(this); | 676 net_log()->DeprecatedRemoveObserver(this); |
678 PostPendingEntries(); | 677 PostPendingEntries(); |
679 } | 678 } |
680 | 679 |
681 SendJavascriptCommand("receivedConstants", NetInternalsUI::GetConstants()); | 680 SendJavascriptCommand("receivedConstants", NetInternalsUI::GetConstants()); |
682 | 681 |
683 PrePopulateEventList(); | 682 PrePopulateEventList(); |
684 | 683 |
685 // Register with network stack to observe events. | 684 // Register with network stack to observe events. |
686 io_thread_->net_log()->DeprecatedAddObserver(this, | 685 io_thread_->net_log()->DeprecatedAddObserver( |
687 net::NetLog::LOG_ALL_BUT_BYTES); | 686 this, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); |
688 } | 687 } |
689 | 688 |
690 void NetInternalsMessageHandler::IOThreadImpl::OnGetNetInfo( | 689 void NetInternalsMessageHandler::IOThreadImpl::OnGetNetInfo( |
691 const base::ListValue* list) { | 690 const base::ListValue* list) { |
692 DCHECK(list); | 691 DCHECK(list); |
693 int info_sources; | 692 int info_sources; |
694 if (!list->GetInteger(0, &info_sources)) | 693 if (!list->GetInteger(0, &info_sources)) |
695 return; | 694 return; |
696 SendNetInfo(info_sources); | 695 SendNetInfo(info_sources); |
697 } | 696 } |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 std::string status; | 1062 std::string status; |
1064 if (succeeded) | 1063 if (succeeded) |
1065 status = "Debug mode is changed to " + subsystem; | 1064 status = "Debug mode is changed to " + subsystem; |
1066 else | 1065 else |
1067 status = "Failed to change debug mode to " + subsystem; | 1066 status = "Failed to change debug mode to " + subsystem; |
1068 SendJavascriptCommand("receivedSetNetworkDebugMode", | 1067 SendJavascriptCommand("receivedSetNetworkDebugMode", |
1069 new base::StringValue(status)); | 1068 new base::StringValue(status)); |
1070 } | 1069 } |
1071 #endif // defined(OS_CHROMEOS) | 1070 #endif // defined(OS_CHROMEOS) |
1072 | 1071 |
1073 void NetInternalsMessageHandler::IOThreadImpl::OnSetLogLevel( | 1072 void NetInternalsMessageHandler::IOThreadImpl::OnSetCaptureMode( |
1074 const base::ListValue* list) { | 1073 const base::ListValue* list) { |
1075 int log_level; | 1074 std::string capture_mode_string; |
1076 std::string log_level_string; | 1075 if (!list->GetString(0, &capture_mode_string)) { |
1077 if (!list->GetString(0, &log_level_string) || | |
1078 !base::StringToInt(log_level_string, &log_level)) { | |
1079 NOTREACHED(); | 1076 NOTREACHED(); |
1080 return; | 1077 return; |
1081 } | 1078 } |
1082 | 1079 |
1083 DCHECK_GE(log_level, net::NetLog::LOG_ALL); | 1080 // Convert the string to a NetLogCaptureMode. |
1084 DCHECK_LT(log_level, net::NetLog::LOG_NONE); | 1081 net::NetLogCaptureMode mode; |
1085 net_log()->SetObserverLogLevel( | 1082 if (capture_mode_string == "IncludeSocketBytes") { |
1086 this, static_cast<net::NetLog::LogLevel>(log_level)); | 1083 mode = net::NetLogCaptureMode::IncludeSocketBytes(); |
| 1084 } else if (capture_mode_string == "IncludeCookiesAndCredentials") { |
| 1085 mode = net::NetLogCaptureMode::IncludeCookiesAndCredentials(); |
| 1086 } else { |
| 1087 NOTREACHED(); |
| 1088 } |
| 1089 |
| 1090 net_log()->SetObserverCaptureMode(this, mode); |
1087 } | 1091 } |
1088 | 1092 |
1089 // Note that unlike other methods of IOThreadImpl, this function | 1093 // Note that unlike other methods of IOThreadImpl, this function |
1090 // can be called from ANY THREAD. | 1094 // can be called from ANY THREAD. |
1091 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 1095 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
1092 const net::NetLog::Entry& entry) { | 1096 const net::NetLog::Entry& entry) { |
1093 BrowserThread::PostTask( | 1097 BrowserThread::PostTask( |
1094 BrowserThread::IO, FROM_HERE, | 1098 BrowserThread::IO, FROM_HERE, |
1095 base::Bind(&IOThreadImpl::AddEntryToQueue, this, entry.ToValue())); | 1099 base::Bind(&IOThreadImpl::AddEntryToQueue, this, entry.ToValue())); |
1096 } | 1100 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 } | 1206 } |
1203 | 1207 |
1204 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1208 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1205 : WebUIController(web_ui) { | 1209 : WebUIController(web_ui) { |
1206 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1210 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
1207 | 1211 |
1208 // Set up the chrome://net-internals/ source. | 1212 // Set up the chrome://net-internals/ source. |
1209 Profile* profile = Profile::FromWebUI(web_ui); | 1213 Profile* profile = Profile::FromWebUI(web_ui); |
1210 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1214 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
1211 } | 1215 } |
OLD | NEW |