OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/dom_ui/net_internals_ui.h" | 5 #include "chrome/browser/dom_ui/net_internals_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/singleton.h" | 16 #include "base/singleton.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 19 #include "base/string_util.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/browser_thread.h" | 23 #include "chrome/browser/browser_thread.h" |
23 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 24 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
24 #include "chrome/browser/io_thread.h" | 25 #include "chrome/browser/io_thread.h" |
25 #include "chrome/browser/net/chrome_net_log.h" | 26 #include "chrome/browser/net/chrome_net_log.h" |
26 #include "chrome/browser/net/connection_tester.h" | 27 #include "chrome/browser/net/connection_tester.h" |
27 #include "chrome/browser/net/passive_log_collector.h" | 28 #include "chrome/browser/net/passive_log_collector.h" |
28 #include "chrome/browser/net/url_fixer_upper.h" | 29 #include "chrome/browser/net/url_fixer_upper.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 void OnRendererReady(const ListValue* list); | 249 void OnRendererReady(const ListValue* list); |
249 | 250 |
250 void OnGetProxySettings(const ListValue* list); | 251 void OnGetProxySettings(const ListValue* list); |
251 void OnReloadProxySettings(const ListValue* list); | 252 void OnReloadProxySettings(const ListValue* list); |
252 void OnGetBadProxies(const ListValue* list); | 253 void OnGetBadProxies(const ListValue* list); |
253 void OnClearBadProxies(const ListValue* list); | 254 void OnClearBadProxies(const ListValue* list); |
254 void OnGetHostResolverInfo(const ListValue* list); | 255 void OnGetHostResolverInfo(const ListValue* list); |
255 void OnClearHostResolverCache(const ListValue* list); | 256 void OnClearHostResolverCache(const ListValue* list); |
256 void OnEnableIPv6(const ListValue* list); | 257 void OnEnableIPv6(const ListValue* list); |
257 void OnStartConnectionTests(const ListValue* list); | 258 void OnStartConnectionTests(const ListValue* list); |
| 259 void OnHSTSQuery(const ListValue* list); |
| 260 void OnHSTSAdd(const ListValue* list); |
| 261 void OnHSTSDelete(const ListValue* list); |
258 void OnGetHttpCacheInfo(const ListValue* list); | 262 void OnGetHttpCacheInfo(const ListValue* list); |
259 void OnGetSocketPoolInfo(const ListValue* list); | 263 void OnGetSocketPoolInfo(const ListValue* list); |
260 void OnGetSpdySessionInfo(const ListValue* list); | 264 void OnGetSpdySessionInfo(const ListValue* list); |
261 void OnGetSpdyStatus(const ListValue* list); | 265 void OnGetSpdyStatus(const ListValue* list); |
262 void OnGetSpdyAlternateProtocolMappings(const ListValue* list); | 266 void OnGetSpdyAlternateProtocolMappings(const ListValue* list); |
263 #ifdef OS_WIN | 267 #ifdef OS_WIN |
264 void OnGetServiceProviders(const ListValue* list); | 268 void OnGetServiceProviders(const ListValue* list); |
265 #endif | 269 #endif |
266 | 270 |
267 void OnSetLogLevel(const ListValue* list); | 271 void OnSetLogLevel(const ListValue* list); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 dom_ui_->RegisterMessageCallback( | 504 dom_ui_->RegisterMessageCallback( |
501 "clearHostResolverCache", | 505 "clearHostResolverCache", |
502 proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache)); | 506 proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache)); |
503 dom_ui_->RegisterMessageCallback( | 507 dom_ui_->RegisterMessageCallback( |
504 "enableIPv6", | 508 "enableIPv6", |
505 proxy_->CreateCallback(&IOThreadImpl::OnEnableIPv6)); | 509 proxy_->CreateCallback(&IOThreadImpl::OnEnableIPv6)); |
506 dom_ui_->RegisterMessageCallback( | 510 dom_ui_->RegisterMessageCallback( |
507 "startConnectionTests", | 511 "startConnectionTests", |
508 proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests)); | 512 proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests)); |
509 dom_ui_->RegisterMessageCallback( | 513 dom_ui_->RegisterMessageCallback( |
| 514 "hstsQuery", |
| 515 proxy_->CreateCallback(&IOThreadImpl::OnHSTSQuery)); |
| 516 dom_ui_->RegisterMessageCallback( |
| 517 "hstsAdd", |
| 518 proxy_->CreateCallback(&IOThreadImpl::OnHSTSAdd)); |
| 519 dom_ui_->RegisterMessageCallback( |
| 520 "hstsDelete", |
| 521 proxy_->CreateCallback(&IOThreadImpl::OnHSTSDelete)); |
| 522 dom_ui_->RegisterMessageCallback( |
510 "getHttpCacheInfo", | 523 "getHttpCacheInfo", |
511 proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo)); | 524 proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo)); |
512 dom_ui_->RegisterMessageCallback( | 525 dom_ui_->RegisterMessageCallback( |
513 "getSocketPoolInfo", | 526 "getSocketPoolInfo", |
514 proxy_->CreateCallback(&IOThreadImpl::OnGetSocketPoolInfo)); | 527 proxy_->CreateCallback(&IOThreadImpl::OnGetSocketPoolInfo)); |
515 dom_ui_->RegisterMessageCallback( | 528 dom_ui_->RegisterMessageCallback( |
516 "getSpdySessionInfo", | 529 "getSpdySessionInfo", |
517 proxy_->CreateCallback(&IOThreadImpl::OnGetSpdySessionInfo)); | 530 proxy_->CreateCallback(&IOThreadImpl::OnGetSpdySessionInfo)); |
518 dom_ui_->RegisterMessageCallback( | 531 dom_ui_->RegisterMessageCallback( |
519 "getSpdyStatus", | 532 "getSpdyStatus", |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 | 960 |
948 // Try to fix-up the user provided URL into something valid. | 961 // Try to fix-up the user provided URL into something valid. |
949 // For example, turn "www.google.com" into "http://www.google.com". | 962 // For example, turn "www.google.com" into "http://www.google.com". |
950 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); | 963 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); |
951 | 964 |
952 connection_tester_.reset(new ConnectionTester( | 965 connection_tester_.reset(new ConnectionTester( |
953 this, io_thread_->globals()->proxy_script_fetcher_context.get())); | 966 this, io_thread_->globals()->proxy_script_fetcher_context.get())); |
954 connection_tester_->RunAllTests(url); | 967 connection_tester_->RunAllTests(url); |
955 } | 968 } |
956 | 969 |
| 970 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery( |
| 971 const ListValue* list) { |
| 972 // |list| should be: [<domain to query>]. |
| 973 std::string domain; |
| 974 CHECK(list->GetString(0, &domain)); |
| 975 DictionaryValue* result = new(DictionaryValue); |
| 976 |
| 977 if (!IsStringASCII(domain)) { |
| 978 result->SetString("error", "non-ASCII domain name"); |
| 979 } else { |
| 980 net::TransportSecurityState* transport_security_state = |
| 981 context_getter_->GetURLRequestContext()->transport_security_state(); |
| 982 if (!transport_security_state) { |
| 983 result->SetString("error", "no TransportSecurityState active"); |
| 984 } else { |
| 985 net::TransportSecurityState::DomainState state; |
| 986 const bool found = transport_security_state->IsEnabledForHost( |
| 987 &state, domain); |
| 988 |
| 989 result->SetBoolean("result", found); |
| 990 if (found) { |
| 991 result->SetInteger("mode", static_cast<int>(state.mode)); |
| 992 result->SetBoolean("subdomains", state.include_subdomains); |
| 993 result->SetBoolean("preloaded", state.preloaded); |
| 994 result->SetString("domain", state.domain); |
| 995 } |
| 996 } |
| 997 } |
| 998 |
| 999 CallJavascriptFunction(L"g_browser.receivedHSTSResult", result); |
| 1000 } |
| 1001 |
| 1002 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( |
| 1003 const ListValue* list) { |
| 1004 // |list| should be: [<domain to query>, <include subdomains>]. |
| 1005 std::string domain; |
| 1006 CHECK(list->GetString(0, &domain)); |
| 1007 if (!IsStringASCII(domain)) { |
| 1008 // Silently fail. The user will get a helpful error if they query for the |
| 1009 // name. |
| 1010 return; |
| 1011 } |
| 1012 bool include_subdomains; |
| 1013 CHECK(list->GetBoolean(1, &include_subdomains)); |
| 1014 |
| 1015 net::TransportSecurityState* transport_security_state = |
| 1016 context_getter_->GetURLRequestContext()->transport_security_state(); |
| 1017 if (!transport_security_state) |
| 1018 return; |
| 1019 |
| 1020 net::TransportSecurityState::DomainState state; |
| 1021 state.expiry = state.created + base::TimeDelta::FromDays(1000); |
| 1022 state.include_subdomains = include_subdomains; |
| 1023 |
| 1024 transport_security_state->EnableHost(domain, state); |
| 1025 } |
| 1026 |
| 1027 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( |
| 1028 const ListValue* list) { |
| 1029 // |list| should be: [<domain to query>]. |
| 1030 std::string domain; |
| 1031 CHECK(list->GetString(0, &domain)); |
| 1032 if (!IsStringASCII(domain)) { |
| 1033 // There cannot be a unicode entry in the HSTS set. |
| 1034 return; |
| 1035 } |
| 1036 net::TransportSecurityState* transport_security_state = |
| 1037 context_getter_->GetURLRequestContext()->transport_security_state(); |
| 1038 if (!transport_security_state) |
| 1039 return; |
| 1040 |
| 1041 transport_security_state->DeleteHost(domain); |
| 1042 } |
| 1043 |
957 void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpCacheInfo( | 1044 void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpCacheInfo( |
958 const ListValue* list) { | 1045 const ListValue* list) { |
959 DictionaryValue* info_dict = new DictionaryValue(); | 1046 DictionaryValue* info_dict = new DictionaryValue(); |
960 DictionaryValue* stats_dict = new DictionaryValue(); | 1047 DictionaryValue* stats_dict = new DictionaryValue(); |
961 | 1048 |
962 disk_cache::Backend* disk_cache = GetDiskCacheBackend( | 1049 disk_cache::Backend* disk_cache = GetDiskCacheBackend( |
963 context_getter_->GetURLRequestContext()); | 1050 context_getter_->GetURLRequestContext()); |
964 | 1051 |
965 if (disk_cache) { | 1052 if (disk_cache) { |
966 // Extract the statistics key/value pairs from the backend. | 1053 // Extract the statistics key/value pairs from the backend. |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 //////////////////////////////////////////////////////////////////////////////// | 1306 //////////////////////////////////////////////////////////////////////////////// |
1220 | 1307 |
1221 NetInternalsUI::NetInternalsUI(TabContents* contents) : WebUI(contents) { | 1308 NetInternalsUI::NetInternalsUI(TabContents* contents) : WebUI(contents) { |
1222 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); | 1309 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); |
1223 | 1310 |
1224 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 1311 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
1225 | 1312 |
1226 // Set up the chrome://net-internals/ source. | 1313 // Set up the chrome://net-internals/ source. |
1227 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 1314 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
1228 } | 1315 } |
OLD | NEW |