OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/devtools/protocol/network_handler.h" | 5 #include "content/browser/devtools/protocol/network_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "content/browser/frame_host/frame_tree_node.h" | 12 #include "content/browser/frame_host/frame_tree_node.h" |
13 #include "content/browser/frame_host/render_frame_host_impl.h" | 13 #include "content/browser/frame_host/render_frame_host_impl.h" |
14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/cert_store.h" | 16 #include "content/public/browser/cert_store.h" |
17 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/resource_context.h" | 19 #include "content/public/browser/resource_context.h" |
20 #include "content/public/browser/site_instance.h" | 20 #include "content/public/browser/site_instance.h" |
21 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_delegate.h" | |
24 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
25 #include "net/cert/x509_cert_types.h" | |
26 #include "net/cert/x509_certificate.h" | |
27 #include "net/cookies/cookie_store.h" | 24 #include "net/cookies/cookie_store.h" |
28 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
29 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
30 | 27 |
31 namespace content { | 28 namespace content { |
32 namespace devtools { | 29 namespace devtools { |
33 namespace network { | 30 namespace network { |
34 | 31 |
35 using Response = DevToolsProtocolClient::Response; | 32 using Response = DevToolsProtocolClient::Response; |
36 using CookieListCallback = net::CookieStore::GetCookieListCallback; | 33 using CookieListCallback = net::CookieStore::GetCookieListCallback; |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 400 |
404 Response NetworkHandler::EmulateNetworkConditions( | 401 Response NetworkHandler::EmulateNetworkConditions( |
405 bool offline, | 402 bool offline, |
406 double latency, | 403 double latency, |
407 double download_throughput, | 404 double download_throughput, |
408 double upload_throughput, | 405 double upload_throughput, |
409 const std::string* connection_type) { | 406 const std::string* connection_type) { |
410 return Response::FallThrough(); | 407 return Response::FallThrough(); |
411 } | 408 } |
412 | 409 |
413 Response NetworkHandler::GetCertificateDetails( | |
414 int certificate_id, | |
415 scoped_refptr<CertificateDetails>* result) { | |
416 scoped_refptr<net::X509Certificate> cert; | |
417 content::CertStore* cert_store = CertStore::GetInstance(); | |
418 cert_store->RetrieveCert(certificate_id, &cert); | |
419 if (!cert.get()) | |
420 return Response::InvalidParams("certificateId"); | |
421 | |
422 std::string name(cert->subject().GetDisplayName()); | |
423 std::string issuer(cert->issuer().GetDisplayName()); | |
424 base::Time valid_from = cert->valid_start(); | |
425 base::Time valid_to = cert->valid_expiry(); | |
426 | |
427 std::vector<std::string> dns_names; | |
428 std::vector<std::string> ip_addrs; | |
429 cert->GetSubjectAltName(&dns_names, &ip_addrs); | |
430 | |
431 // IP addresses are in raw network bytes and must be converted to string form | |
432 std::vector<std::string> ip_addrs_string; | |
433 for (const std::string& ip : ip_addrs) { | |
434 net::IPAddress ip_addr(reinterpret_cast<const uint8_t*>(ip.c_str()), | |
435 ip.length()); | |
436 ip_addrs_string.push_back(ip_addr.ToString()); | |
437 } | |
438 | |
439 *result = CertificateDetails::Create() | |
440 ->set_subject(CertificateSubject::Create() | |
441 ->set_name(name) | |
442 ->set_san_dns_names(dns_names) | |
443 ->set_san_ip_addresses(ip_addrs_string)) | |
444 ->set_issuer(issuer) | |
445 ->set_valid_from(valid_from.ToDoubleT()) | |
446 ->set_valid_to(valid_to.ToDoubleT()); | |
447 return Response::OK(); | |
448 } | |
449 | |
450 Response NetworkHandler::ShowCertificateViewer(int certificate_id) { | |
451 if (!host_) | |
452 return Response::InternalError("Could not connect to view"); | |
453 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); | |
454 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( | |
455 web_contents, certificate_id); | |
456 return Response::OK(); | |
457 } | |
458 | |
459 } // namespace network | 410 } // namespace network |
460 } // namespace devtools | 411 } // namespace devtools |
461 } // namespace content | 412 } // namespace content |
OLD | NEW |