| 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/ui/webui/net_internals_ui.h" | 5 #include "chrome/browser/ui/webui/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/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.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_split.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/io_thread.h" | 24 #include "chrome/browser/io_thread.h" |
| 24 #include "chrome/browser/net/chrome_net_log.h" | 25 #include "chrome/browser/net/chrome_net_log.h" |
| 25 #include "chrome/browser/net/connection_tester.h" | 26 #include "chrome/browser/net/connection_tester.h" |
| 26 #include "chrome/browser/net/passive_log_collector.h" | 27 #include "chrome/browser/net/passive_log_collector.h" |
| 27 #include "chrome/browser/net/url_fixer_upper.h" | 28 #include "chrome/browser/net/url_fixer_upper.h" |
| 28 #include "chrome/browser/platform_util.h" | 29 #include "chrome/browser/platform_util.h" |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 net::TransportSecurityState::DomainState state; | 1059 net::TransportSecurityState::DomainState state; |
| 1059 const bool found = transport_security_state->IsEnabledForHost( | 1060 const bool found = transport_security_state->IsEnabledForHost( |
| 1060 &state, domain); | 1061 &state, domain); |
| 1061 | 1062 |
| 1062 result->SetBoolean("result", found); | 1063 result->SetBoolean("result", found); |
| 1063 if (found) { | 1064 if (found) { |
| 1064 result->SetInteger("mode", static_cast<int>(state.mode)); | 1065 result->SetInteger("mode", static_cast<int>(state.mode)); |
| 1065 result->SetBoolean("subdomains", state.include_subdomains); | 1066 result->SetBoolean("subdomains", state.include_subdomains); |
| 1066 result->SetBoolean("preloaded", state.preloaded); | 1067 result->SetBoolean("preloaded", state.preloaded); |
| 1067 result->SetString("domain", state.domain); | 1068 result->SetString("domain", state.domain); |
| 1069 result->SetString("cert_pins", |
| 1070 JoinString(state.cert_pins, ',')); |
| 1068 } | 1071 } |
| 1069 } | 1072 } |
| 1070 } | 1073 } |
| 1071 | 1074 |
| 1072 CallJavascriptFunction(L"g_browser.receivedHSTSResult", result); | 1075 CallJavascriptFunction(L"g_browser.receivedHSTSResult", result); |
| 1073 } | 1076 } |
| 1074 | 1077 |
| 1075 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( | 1078 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( |
| 1076 const ListValue* list) { | 1079 const ListValue* list) { |
| 1077 // |list| should be: [<domain to query>, <include subdomains>]. | 1080 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. |
| 1078 std::string domain; | 1081 std::string domain; |
| 1079 CHECK(list->GetString(0, &domain)); | 1082 CHECK(list->GetString(0, &domain)); |
| 1080 if (!IsStringASCII(domain)) { | 1083 if (!IsStringASCII(domain)) { |
| 1081 // Silently fail. The user will get a helpful error if they query for the | 1084 // Silently fail. The user will get a helpful error if they query for the |
| 1082 // name. | 1085 // name. |
| 1083 return; | 1086 return; |
| 1084 } | 1087 } |
| 1085 bool include_subdomains; | 1088 bool include_subdomains; |
| 1086 CHECK(list->GetBoolean(1, &include_subdomains)); | 1089 CHECK(list->GetBoolean(1, &include_subdomains)); |
| 1090 std::string cert_pins_str; |
| 1091 CHECK(list->GetString(2, &cert_pins_str)); |
| 1087 | 1092 |
| 1088 net::TransportSecurityState* transport_security_state = | 1093 net::TransportSecurityState* transport_security_state = |
| 1089 context_getter_->GetURLRequestContext()->transport_security_state(); | 1094 context_getter_->GetURLRequestContext()->transport_security_state(); |
| 1090 if (!transport_security_state) | 1095 if (!transport_security_state) |
| 1091 return; | 1096 return; |
| 1092 | 1097 |
| 1093 net::TransportSecurityState::DomainState state; | 1098 net::TransportSecurityState::DomainState state; |
| 1094 state.expiry = state.created + base::TimeDelta::FromDays(1000); | 1099 state.expiry = state.created + base::TimeDelta::FromDays(1000); |
| 1095 state.include_subdomains = include_subdomains; | 1100 state.include_subdomains = include_subdomains; |
| 1101 state.cert_pins.clear(); |
| 1102 if (!cert_pins_str.empty()) { |
| 1103 std::vector<std::string> cert_pins; |
| 1104 base::SplitString(cert_pins_str, ',', &cert_pins); |
| 1105 std::vector<std::string>::const_iterator i = cert_pins.begin(); |
| 1106 for (; i != cert_pins.end(); ++i) { |
| 1107 std::string pin = *i; |
| 1108 RemoveChars(pin, " \t\r\n", &pin); |
| 1109 StringToLowerASCII(&pin); |
| 1110 state.cert_pins.push_back(pin); |
| 1111 } |
| 1112 } |
| 1096 | 1113 |
| 1097 transport_security_state->EnableHost(domain, state); | 1114 transport_security_state->EnableHost(domain, state); |
| 1098 } | 1115 } |
| 1099 | 1116 |
| 1100 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( | 1117 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( |
| 1101 const ListValue* list) { | 1118 const ListValue* list) { |
| 1102 // |list| should be: [<domain to query>]. | 1119 // |list| should be: [<domain to query>]. |
| 1103 std::string domain; | 1120 std::string domain; |
| 1104 CHECK(list->GetString(0, &domain)); | 1121 CHECK(list->GetString(0, &domain)); |
| 1105 if (!IsStringASCII(domain)) { | 1122 if (!IsStringASCII(domain)) { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 //////////////////////////////////////////////////////////////////////////////// | 1396 //////////////////////////////////////////////////////////////////////////////// |
| 1380 | 1397 |
| 1381 NetInternalsUI::NetInternalsUI(TabContents* contents) : WebUI(contents) { | 1398 NetInternalsUI::NetInternalsUI(TabContents* contents) : WebUI(contents) { |
| 1382 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); | 1399 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); |
| 1383 | 1400 |
| 1384 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 1401 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
| 1385 | 1402 |
| 1386 // Set up the chrome://net-internals/ source. | 1403 // Set up the chrome://net-internals/ source. |
| 1387 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 1404 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
| 1388 } | 1405 } |
| OLD | NEW |