| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // Calls g_browser.receive in the renderer, passing in |command| and |arg|. | 204 // Calls g_browser.receive in the renderer, passing in |command| and |arg|. |
| 205 // If the renderer is displaying a log file, the message will be ignored. | 205 // If the renderer is displaying a log file, the message will be ignored. |
| 206 void SendJavascriptCommand(const std::string& command, | 206 void SendJavascriptCommand(const std::string& command, |
| 207 std::unique_ptr<base::Value> arg); | 207 std::unique_ptr<base::Value> arg); |
| 208 | 208 |
| 209 // Javascript message handlers. | 209 // Javascript message handlers. |
| 210 void OnRendererReady(const base::ListValue* list); | 210 void OnRendererReady(const base::ListValue* list); |
| 211 void OnClearBrowserCache(const base::ListValue* list); | 211 void OnClearBrowserCache(const base::ListValue* list); |
| 212 void OnGetPrerenderInfo(const base::ListValue* list); | 212 void OnGetPrerenderInfo(const base::ListValue* list); |
| 213 void OnGetHistoricNetworkStats(const base::ListValue* list); | 213 void OnGetHistoricNetworkStats(const base::ListValue* list); |
| 214 void OnGetSessionNetworkStats(const base::ListValue* list); |
| 214 void OnGetExtensionInfo(const base::ListValue* list); | 215 void OnGetExtensionInfo(const base::ListValue* list); |
| 215 void OnGetDataReductionProxyInfo(const base::ListValue* list); | 216 void OnGetDataReductionProxyInfo(const base::ListValue* list); |
| 216 #if defined(OS_CHROMEOS) | 217 #if defined(OS_CHROMEOS) |
| 217 void OnImportONCFile(const base::ListValue* list); | 218 void OnImportONCFile(const base::ListValue* list); |
| 218 void OnStoreDebugLogs(const base::ListValue* list); | 219 void OnStoreDebugLogs(const base::ListValue* list); |
| 219 void OnStoreDebugLogsCompleted(const base::FilePath& log_path, | 220 void OnStoreDebugLogsCompleted(const base::FilePath& log_path, |
| 220 bool succeeded); | 221 bool succeeded); |
| 221 void OnSetNetworkDebugMode(const base::ListValue* list); | 222 void OnSetNetworkDebugMode(const base::ListValue* list); |
| 222 void OnSetNetworkDebugModeCompleted(const std::string& subsystem, | 223 void OnSetNetworkDebugModeCompleted(const std::string& subsystem, |
| 223 bool succeeded); | 224 bool succeeded); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 294 |
| 294 void OnRendererReady(const base::ListValue* list); | 295 void OnRendererReady(const base::ListValue* list); |
| 295 | 296 |
| 296 void OnGetNetInfo(const base::ListValue* list); | 297 void OnGetNetInfo(const base::ListValue* list); |
| 297 void OnReloadProxySettings(const base::ListValue* list); | 298 void OnReloadProxySettings(const base::ListValue* list); |
| 298 void OnClearBadProxies(const base::ListValue* list); | 299 void OnClearBadProxies(const base::ListValue* list); |
| 299 void OnClearHostResolverCache(const base::ListValue* list); | 300 void OnClearHostResolverCache(const base::ListValue* list); |
| 300 void OnHSTSQuery(const base::ListValue* list); | 301 void OnHSTSQuery(const base::ListValue* list); |
| 301 void OnHSTSAdd(const base::ListValue* list); | 302 void OnHSTSAdd(const base::ListValue* list); |
| 302 void OnHSTSDelete(const base::ListValue* list); | 303 void OnHSTSDelete(const base::ListValue* list); |
| 303 void OnGetSessionNetworkStats(const base::ListValue* list); | |
| 304 void OnCloseIdleSockets(const base::ListValue* list); | 304 void OnCloseIdleSockets(const base::ListValue* list); |
| 305 void OnFlushSocketPools(const base::ListValue* list); | 305 void OnFlushSocketPools(const base::ListValue* list); |
| 306 #if defined(OS_WIN) | 306 #if defined(OS_WIN) |
| 307 void OnGetServiceProviders(const base::ListValue* list); | 307 void OnGetServiceProviders(const base::ListValue* list); |
| 308 #endif | 308 #endif |
| 309 void OnSetCaptureMode(const base::ListValue* list); | 309 void OnSetCaptureMode(const base::ListValue* list); |
| 310 | 310 |
| 311 // NetLog::ThreadSafeObserver implementation: | 311 // NetLog::ThreadSafeObserver implementation: |
| 312 void OnAddEntry(const net::NetLogEntry& entry) override; | 312 void OnAddEntry(const net::NetLogEntry& entry) override; |
| 313 | 313 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 &IOThreadImpl::OnHSTSQuery, proxy_)); | 437 &IOThreadImpl::OnHSTSQuery, proxy_)); |
| 438 web_ui()->RegisterMessageCallback( | 438 web_ui()->RegisterMessageCallback( |
| 439 "hstsAdd", | 439 "hstsAdd", |
| 440 base::Bind(&IOThreadImpl::CallbackHelper, | 440 base::Bind(&IOThreadImpl::CallbackHelper, |
| 441 &IOThreadImpl::OnHSTSAdd, proxy_)); | 441 &IOThreadImpl::OnHSTSAdd, proxy_)); |
| 442 web_ui()->RegisterMessageCallback( | 442 web_ui()->RegisterMessageCallback( |
| 443 "hstsDelete", | 443 "hstsDelete", |
| 444 base::Bind(&IOThreadImpl::CallbackHelper, | 444 base::Bind(&IOThreadImpl::CallbackHelper, |
| 445 &IOThreadImpl::OnHSTSDelete, proxy_)); | 445 &IOThreadImpl::OnHSTSDelete, proxy_)); |
| 446 web_ui()->RegisterMessageCallback( | 446 web_ui()->RegisterMessageCallback( |
| 447 "getSessionNetworkStats", | |
| 448 base::Bind(&IOThreadImpl::CallbackHelper, | |
| 449 &IOThreadImpl::OnGetSessionNetworkStats, proxy_)); | |
| 450 web_ui()->RegisterMessageCallback( | |
| 451 "closeIdleSockets", | 447 "closeIdleSockets", |
| 452 base::Bind(&IOThreadImpl::CallbackHelper, | 448 base::Bind(&IOThreadImpl::CallbackHelper, |
| 453 &IOThreadImpl::OnCloseIdleSockets, proxy_)); | 449 &IOThreadImpl::OnCloseIdleSockets, proxy_)); |
| 454 web_ui()->RegisterMessageCallback( | 450 web_ui()->RegisterMessageCallback( |
| 455 "flushSocketPools", | 451 "flushSocketPools", |
| 456 base::Bind(&IOThreadImpl::CallbackHelper, | 452 base::Bind(&IOThreadImpl::CallbackHelper, |
| 457 &IOThreadImpl::OnFlushSocketPools, proxy_)); | 453 &IOThreadImpl::OnFlushSocketPools, proxy_)); |
| 458 #if defined(OS_WIN) | 454 #if defined(OS_WIN) |
| 459 web_ui()->RegisterMessageCallback( | 455 web_ui()->RegisterMessageCallback( |
| 460 "getServiceProviders", | 456 "getServiceProviders", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 471 base::Unretained(this))); | 467 base::Unretained(this))); |
| 472 web_ui()->RegisterMessageCallback( | 468 web_ui()->RegisterMessageCallback( |
| 473 "getPrerenderInfo", | 469 "getPrerenderInfo", |
| 474 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, | 470 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, |
| 475 base::Unretained(this))); | 471 base::Unretained(this))); |
| 476 web_ui()->RegisterMessageCallback( | 472 web_ui()->RegisterMessageCallback( |
| 477 "getHistoricNetworkStats", | 473 "getHistoricNetworkStats", |
| 478 base::Bind(&NetInternalsMessageHandler::OnGetHistoricNetworkStats, | 474 base::Bind(&NetInternalsMessageHandler::OnGetHistoricNetworkStats, |
| 479 base::Unretained(this))); | 475 base::Unretained(this))); |
| 480 web_ui()->RegisterMessageCallback( | 476 web_ui()->RegisterMessageCallback( |
| 477 "getSessionNetworkStats", |
| 478 base::Bind(&NetInternalsMessageHandler::OnGetSessionNetworkStats, |
| 479 base::Unretained(this))); |
| 480 web_ui()->RegisterMessageCallback( |
| 481 "getExtensionInfo", | 481 "getExtensionInfo", |
| 482 base::Bind(&NetInternalsMessageHandler::OnGetExtensionInfo, | 482 base::Bind(&NetInternalsMessageHandler::OnGetExtensionInfo, |
| 483 base::Unretained(this))); | 483 base::Unretained(this))); |
| 484 web_ui()->RegisterMessageCallback( | 484 web_ui()->RegisterMessageCallback( |
| 485 "getDataReductionProxyInfo", | 485 "getDataReductionProxyInfo", |
| 486 base::Bind(&NetInternalsMessageHandler::OnGetDataReductionProxyInfo, | 486 base::Bind(&NetInternalsMessageHandler::OnGetDataReductionProxyInfo, |
| 487 base::Unretained(this))); | 487 base::Unretained(this))); |
| 488 #if defined(OS_CHROMEOS) | 488 #if defined(OS_CHROMEOS) |
| 489 web_ui()->RegisterMessageCallback( | 489 web_ui()->RegisterMessageCallback( |
| 490 "importONCFile", | 490 "importONCFile", |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 compression_stats = | 561 compression_stats = |
| 562 data_reduction_proxy_settings->data_reduction_proxy_service() | 562 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 563 ->compression_stats(); | 563 ->compression_stats(); |
| 564 historic_network_info = | 564 historic_network_info = |
| 565 compression_stats->HistoricNetworkStatsInfoToValue(); | 565 compression_stats->HistoricNetworkStatsInfoToValue(); |
| 566 } | 566 } |
| 567 SendJavascriptCommand("receivedHistoricNetworkStats", | 567 SendJavascriptCommand("receivedHistoricNetworkStats", |
| 568 std::move(historic_network_info)); | 568 std::move(historic_network_info)); |
| 569 } | 569 } |
| 570 | 570 |
| 571 void NetInternalsMessageHandler::OnGetSessionNetworkStats( |
| 572 const base::ListValue* list) { |
| 573 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 574 std::unique_ptr<base::Value> session_network_info; |
| 575 Profile* profile = Profile::FromWebUI(web_ui()); |
| 576 DataReductionProxyChromeSettings* data_reduction_proxy_settings = |
| 577 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile); |
| 578 if (data_reduction_proxy_settings) { |
| 579 data_reduction_proxy::DataReductionProxyCompressionStats* |
| 580 compression_stats = |
| 581 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 582 ->compression_stats(); |
| 583 session_network_info = compression_stats->SessionNetworkStatsInfoToValue(); |
| 584 } |
| 585 SendJavascriptCommand("receivedSessionNetworkStats", |
| 586 std::move(session_network_info)); |
| 587 } |
| 588 |
| 571 void NetInternalsMessageHandler::OnGetExtensionInfo( | 589 void NetInternalsMessageHandler::OnGetExtensionInfo( |
| 572 const base::ListValue* list) { | 590 const base::ListValue* list) { |
| 573 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 591 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 574 auto extension_list = base::MakeUnique<base::ListValue>(); | 592 auto extension_list = base::MakeUnique<base::ListValue>(); |
| 575 #if BUILDFLAG(ENABLE_EXTENSIONS) | 593 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 576 Profile* profile = Profile::FromWebUI(web_ui()); | 594 Profile* profile = Profile::FromWebUI(web_ui()); |
| 577 extensions::ExtensionSystem* extension_system = | 595 extensions::ExtensionSystem* extension_system = |
| 578 extensions::ExtensionSystem::Get(profile); | 596 extensions::ExtensionSystem::Get(profile); |
| 579 if (extension_system) { | 597 if (extension_system) { |
| 580 ExtensionService* extension_service = extension_system->extension_service(); | 598 ExtensionService* extension_service = extension_system->extension_service(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 return; | 877 return; |
| 860 } | 878 } |
| 861 net::TransportSecurityState* transport_security_state = | 879 net::TransportSecurityState* transport_security_state = |
| 862 GetMainContext()->transport_security_state(); | 880 GetMainContext()->transport_security_state(); |
| 863 if (!transport_security_state) | 881 if (!transport_security_state) |
| 864 return; | 882 return; |
| 865 | 883 |
| 866 transport_security_state->DeleteDynamicDataForHost(domain); | 884 transport_security_state->DeleteDynamicDataForHost(domain); |
| 867 } | 885 } |
| 868 | 886 |
| 869 void NetInternalsMessageHandler::IOThreadImpl::OnGetSessionNetworkStats( | |
| 870 const base::ListValue* list) { | |
| 871 DCHECK(!list); | |
| 872 net::URLRequestContext* context = | |
| 873 main_context_getter_->GetURLRequestContext(); | |
| 874 net::HttpNetworkSession* http_network_session = | |
| 875 GetHttpNetworkSession(context); | |
| 876 | |
| 877 std::unique_ptr<base::Value> network_info; | |
| 878 if (http_network_session) { | |
| 879 // TODO(mmenke): This cast is ugly. Can we get rid of it, or, better, | |
| 880 // remove DRP data from net-internals entirely? | |
| 881 data_reduction_proxy::DataReductionProxyNetworkDelegate* net_delegate = | |
| 882 static_cast<data_reduction_proxy::DataReductionProxyNetworkDelegate*>( | |
| 883 context->network_delegate()); | |
| 884 if (net_delegate) | |
| 885 network_info = net_delegate->SessionNetworkStatsInfoToValue(); | |
| 886 } | |
| 887 SendJavascriptCommand("receivedSessionNetworkStats", std::move(network_info)); | |
| 888 } | |
| 889 | |
| 890 void NetInternalsMessageHandler::IOThreadImpl::OnFlushSocketPools( | 887 void NetInternalsMessageHandler::IOThreadImpl::OnFlushSocketPools( |
| 891 const base::ListValue* list) { | 888 const base::ListValue* list) { |
| 892 DCHECK(!list); | 889 DCHECK(!list); |
| 893 net::HttpNetworkSession* http_network_session = | 890 net::HttpNetworkSession* http_network_session = |
| 894 GetHttpNetworkSession(GetMainContext()); | 891 GetHttpNetworkSession(GetMainContext()); |
| 895 | 892 |
| 896 if (http_network_session) | 893 if (http_network_session) |
| 897 http_network_session->CloseAllConnections(); | 894 http_network_session->CloseAllConnections(); |
| 898 } | 895 } |
| 899 | 896 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 //////////////////////////////////////////////////////////////////////////////// | 1169 //////////////////////////////////////////////////////////////////////////////// |
| 1173 | 1170 |
| 1174 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1171 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
| 1175 : WebUIController(web_ui) { | 1172 : WebUIController(web_ui) { |
| 1176 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1173 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
| 1177 | 1174 |
| 1178 // Set up the chrome://net-internals/ source. | 1175 // Set up the chrome://net-internals/ source. |
| 1179 Profile* profile = Profile::FromWebUI(web_ui); | 1176 Profile* profile = Profile::FromWebUI(web_ui); |
| 1180 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1177 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
| 1181 } | 1178 } |
| OLD | NEW |