Chromium Code Reviews| 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 "content/browser/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 &response->head.service_worker_fetch_end); | 70 &response->head.service_worker_fetch_end); |
| 71 } | 71 } |
| 72 AppCacheInterceptor::GetExtraResponseInfo( | 72 AppCacheInterceptor::GetExtraResponseInfo( |
| 73 request, | 73 request, |
| 74 &response->head.appcache_id, | 74 &response->head.appcache_id, |
| 75 &response->head.appcache_manifest_url); | 75 &response->head.appcache_manifest_url); |
| 76 if (info->is_load_timing_enabled()) | 76 if (info->is_load_timing_enabled()) |
| 77 request->GetLoadTimingInfo(&response->head.load_timing); | 77 request->GetLoadTimingInfo(&response->head.load_timing); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Stores the SignedCertificateTimestamps held in |sct_list| in the | |
| 81 // SignedCertificateTimestampStore singleton, associated with |process_id|. | |
| 82 // On return, |sct_ids| contains the assigned ID and verification status of | |
| 83 // each SignedCertificateTimestamp. | |
| 84 void StoreSignedCertificateTimestamps( | |
| 85 const net::SignedCertificateTimestampAndStatusList& sct_list, | |
| 86 int process_id, | |
| 87 SignedCertificateTimestampIDStatusList* sct_ids) { | |
| 88 SignedCertificateTimestampStore* sct_store( | |
| 89 SignedCertificateTimestampStore::GetInstance()); | |
| 90 | |
| 91 for (net::SignedCertificateTimestampAndStatusList::const_iterator iter = | |
| 92 sct_list.begin(); | |
| 93 iter != sct_list.end(); ++iter) { | |
| 94 const int sct_id(sct_store->Store(iter->sct.get(), process_id)); | |
| 95 sct_ids->push_back( | |
| 96 SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 std::string StoreAndSerializeSecurityInfo(const net::SSLInfo& ssl_info, | |
| 101 int process_id) { | |
| 102 DCHECK(ssl_info.cert.get()); | |
| 103 int cert_id = | |
| 104 CertStore::GetInstance()->StoreCert(ssl_info.cert.get(), process_id); | |
| 105 | |
| 106 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; | |
| 107 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps, | |
| 108 process_id, | |
| 109 &signed_certificate_timestamp_ids); | |
| 110 | |
| 111 return SerializeSecurityInfo( | |
| 112 cert_id, ssl_info.cert_status, ssl_info.security_bits, | |
| 113 ssl_info.connection_status, signed_certificate_timestamp_ids); | |
| 114 } | |
| 115 | |
| 80 } // namespace | 116 } // namespace |
| 81 | 117 |
| 82 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, | 118 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, |
| 83 scoped_ptr<ResourceHandler> handler, | 119 scoped_ptr<ResourceHandler> handler, |
| 84 ResourceLoaderDelegate* delegate) | 120 ResourceLoaderDelegate* delegate) |
| 85 : deferred_stage_(DEFERRED_NONE), | 121 : deferred_stage_(DEFERRED_NONE), |
| 86 request_(request.Pass()), | 122 request_(request.Pass()), |
| 87 handler_(handler.Pass()), | 123 handler_(handler.Pass()), |
| 88 delegate_(delegate), | 124 delegate_(delegate), |
| 89 last_upload_position_(0), | 125 last_upload_position_(0), |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, | 316 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, |
| 281 net::AuthChallengeInfo* auth_info) { | 317 net::AuthChallengeInfo* auth_info) { |
| 282 DCHECK_EQ(request_.get(), unused); | 318 DCHECK_EQ(request_.get(), unused); |
| 283 | 319 |
| 284 ResourceRequestInfoImpl* info = GetRequestInfo(); | 320 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 285 if (info->do_not_prompt_for_login()) { | 321 if (info->do_not_prompt_for_login()) { |
| 286 request_->CancelAuth(); | 322 request_->CancelAuth(); |
| 287 return; | 323 return; |
| 288 } | 324 } |
| 289 | 325 |
| 326 // Update the SSL state before showing the auth prompt. | |
| 327 const net::SSLInfo& ssl_info = request_->response_info().ssl_info; | |
| 328 if (ssl_info.cert.get()) { | |
| 329 bool is_main_frame = (request_->load_flags() & net::LOAD_MAIN_FRAME) != 0; | |
| 330 ResourceRequestInfoImpl* info = GetRequestInfo(); | |
| 331 int render_process_id; | |
| 332 int render_frame_id; | |
| 333 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) | |
|
Charlie Reis
2015/03/18 17:46:38
Random question: Why does this method return a boo
| |
| 334 CHECK(0); | |
|
Charlie Reis
2015/03/18 17:46:38
nit: CHECK(false) is more common.
palmer
2015/09/29 00:03:33
Done in https://codereview.chromium.org/1368863002
| |
| 335 std::string security_info = | |
| 336 StoreAndSerializeSecurityInfo(ssl_info, info->GetChildID()); | |
| 337 SSLManager::OnAuthDialog(render_process_id, render_frame_id, security_info, | |
| 338 is_main_frame); | |
| 339 } else { | |
| 340 // We should not have any SSL state. | |
| 341 DCHECK(!ssl_info.cert_status && ssl_info.security_bits == -1 && | |
| 342 !ssl_info.connection_status); | |
| 343 } | |
| 344 | |
| 290 // Create a login dialog on the UI thread to get authentication data, or pull | 345 // Create a login dialog on the UI thread to get authentication data, or pull |
| 291 // from cache and continue on the IO thread. | 346 // from cache and continue on the IO thread. |
| 292 | |
| 293 DCHECK(!login_delegate_.get()) | 347 DCHECK(!login_delegate_.get()) |
| 294 << "OnAuthRequired called with login_delegate pending"; | 348 << "OnAuthRequired called with login_delegate pending"; |
| 295 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info); | 349 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info); |
| 296 if (!login_delegate_.get()) | 350 if (!login_delegate_.get()) |
| 297 request_->CancelAuth(); | 351 request_->CancelAuth(); |
| 298 } | 352 } |
| 299 | 353 |
| 300 void ResourceLoader::OnCertificateRequested( | 354 void ResourceLoader::OnCertificateRequested( |
| 301 net::URLRequest* unused, | 355 net::URLRequest* unused, |
| 302 net::SSLCertRequestInfo* cert_info) { | 356 net::SSLCertRequestInfo* cert_info) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 316 } | 370 } |
| 317 | 371 |
| 318 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, | 372 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, |
| 319 const net::SSLInfo& ssl_info, | 373 const net::SSLInfo& ssl_info, |
| 320 bool fatal) { | 374 bool fatal) { |
| 321 ResourceRequestInfoImpl* info = GetRequestInfo(); | 375 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 322 | 376 |
| 323 int render_process_id; | 377 int render_process_id; |
| 324 int render_frame_id; | 378 int render_frame_id; |
| 325 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) | 379 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) |
| 326 NOTREACHED(); | 380 CHECK(0); |
| 327 | 381 |
| 328 SSLManager::OnSSLCertificateError( | 382 SSLManager::OnSSLCertificateError( |
| 329 weak_ptr_factory_.GetWeakPtr(), | 383 weak_ptr_factory_.GetWeakPtr(), |
| 330 info->GetResourceType(), | 384 info->GetResourceType(), |
| 331 request_->url(), | 385 request_->url(), |
| 332 render_process_id, | 386 render_process_id, |
| 333 render_frame_id, | 387 render_frame_id, |
| 334 ssl_info, | 388 ssl_info, |
| 335 fatal); | 389 fatal); |
| 336 } | 390 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 // If the request isn't in flight, then we won't get an asynchronous | 658 // If the request isn't in flight, then we won't get an asynchronous |
| 605 // notification from the request, so we have to signal ourselves to finish | 659 // notification from the request, so we have to signal ourselves to finish |
| 606 // this request. | 660 // this request. |
| 607 base::MessageLoop::current()->PostTask( | 661 base::MessageLoop::current()->PostTask( |
| 608 FROM_HERE, | 662 FROM_HERE, |
| 609 base::Bind(&ResourceLoader::ResponseCompleted, | 663 base::Bind(&ResourceLoader::ResponseCompleted, |
| 610 weak_ptr_factory_.GetWeakPtr())); | 664 weak_ptr_factory_.GetWeakPtr())); |
| 611 } | 665 } |
| 612 } | 666 } |
| 613 | 667 |
| 614 void ResourceLoader::StoreSignedCertificateTimestamps( | |
| 615 const net::SignedCertificateTimestampAndStatusList& sct_list, | |
| 616 int process_id, | |
| 617 SignedCertificateTimestampIDStatusList* sct_ids) { | |
| 618 SignedCertificateTimestampStore* sct_store( | |
| 619 SignedCertificateTimestampStore::GetInstance()); | |
| 620 | |
| 621 for (net::SignedCertificateTimestampAndStatusList::const_iterator iter = | |
| 622 sct_list.begin(); iter != sct_list.end(); ++iter) { | |
| 623 const int sct_id(sct_store->Store(iter->sct.get(), process_id)); | |
| 624 sct_ids->push_back( | |
| 625 SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); | |
| 626 } | |
| 627 } | |
| 628 | |
| 629 void ResourceLoader::CompleteResponseStarted() { | 668 void ResourceLoader::CompleteResponseStarted() { |
| 630 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. | 669 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 631 tracked_objects::ScopedTracker tracking_profile1( | 670 tracked_objects::ScopedTracker tracking_profile1( |
| 632 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 671 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 633 "423948 ResourceLoader::CompleteResponseStarted1")); | 672 "423948 ResourceLoader::CompleteResponseStarted1")); |
| 634 | 673 |
| 635 ResourceRequestInfoImpl* info = GetRequestInfo(); | 674 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 636 | 675 |
| 637 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. | 676 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 638 tracked_objects::ScopedTracker tracking_profile2( | 677 tracked_objects::ScopedTracker tracking_profile2( |
| 639 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 678 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 640 "423948 ResourceLoader::CompleteResponseStarted2")); | 679 "423948 ResourceLoader::CompleteResponseStarted2")); |
| 641 | 680 |
| 642 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 681 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 643 PopulateResourceResponse(info, request_.get(), response.get()); | 682 PopulateResourceResponse(info, request_.get(), response.get()); |
| 644 | 683 |
| 645 if (request_->ssl_info().cert.get()) { | 684 if (request_->ssl_info().cert.get()) { |
| 646 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. | 685 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 647 tracked_objects::ScopedTracker tracking_profile3( | 686 tracked_objects::ScopedTracker tracking_profile3( |
| 648 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 687 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 649 "423948 ResourceLoader::CompleteResponseStarted3")); | 688 "423948 ResourceLoader::CompleteResponseStarted3")); |
| 650 | 689 |
| 651 int cert_id = CertStore::GetInstance()->StoreCert( | 690 response->head.security_info = |
| 652 request_->ssl_info().cert.get(), info->GetChildID()); | 691 StoreAndSerializeSecurityInfo(request_->ssl_info(), info->GetChildID()); |
| 653 | 692 |
| 654 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; | |
| 655 StoreSignedCertificateTimestamps( | |
| 656 request_->ssl_info().signed_certificate_timestamps, | |
| 657 info->GetChildID(), | |
| 658 &signed_certificate_timestamp_ids); | |
| 659 | |
| 660 response->head.security_info = SerializeSecurityInfo( | |
| 661 cert_id, | |
| 662 request_->ssl_info().cert_status, | |
| 663 request_->ssl_info().security_bits, | |
| 664 request_->ssl_info().connection_status, | |
| 665 signed_certificate_timestamp_ids); | |
| 666 } else { | 693 } else { |
| 667 // We should not have any SSL state. | 694 // We should not have any SSL state. |
| 668 DCHECK(!request_->ssl_info().cert_status && | 695 DCHECK(!request_->ssl_info().cert_status && |
| 669 request_->ssl_info().security_bits == -1 && | 696 request_->ssl_info().security_bits == -1 && |
| 670 !request_->ssl_info().connection_status); | 697 !request_->ssl_info().connection_status); |
| 671 } | 698 } |
| 672 | 699 |
| 673 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. | 700 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 674 tracked_objects::ScopedTracker tracking_profile5( | 701 tracked_objects::ScopedTracker tracking_profile5( |
| 675 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 702 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 // instance.) | 813 // instance.) |
| 787 } | 814 } |
| 788 | 815 |
| 789 void ResourceLoader::ResponseCompleted() { | 816 void ResourceLoader::ResponseCompleted() { |
| 790 VLOG(1) << "ResponseCompleted: " << request_->url().spec(); | 817 VLOG(1) << "ResponseCompleted: " << request_->url().spec(); |
| 791 RecordHistograms(); | 818 RecordHistograms(); |
| 792 ResourceRequestInfoImpl* info = GetRequestInfo(); | 819 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 793 | 820 |
| 794 std::string security_info; | 821 std::string security_info; |
| 795 const net::SSLInfo& ssl_info = request_->ssl_info(); | 822 const net::SSLInfo& ssl_info = request_->ssl_info(); |
| 796 if (ssl_info.cert.get() != NULL) { | 823 if (ssl_info.cert.get() != NULL) |
| 797 int cert_id = CertStore::GetInstance()->StoreCert(ssl_info.cert.get(), | 824 security_info = StoreAndSerializeSecurityInfo(ssl_info, info->GetChildID()); |
| 798 info->GetChildID()); | |
| 799 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; | |
| 800 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps, | |
| 801 info->GetChildID(), | |
| 802 &signed_certificate_timestamp_ids); | |
| 803 | |
| 804 security_info = SerializeSecurityInfo( | |
| 805 cert_id, ssl_info.cert_status, ssl_info.security_bits, | |
| 806 ssl_info.connection_status, signed_certificate_timestamp_ids); | |
| 807 } | |
| 808 | 825 |
| 809 bool defer = false; | 826 bool defer = false; |
| 810 { | 827 { |
| 811 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. | 828 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 812 tracked_objects::ScopedTracker tracking_profile( | 829 tracked_objects::ScopedTracker tracking_profile( |
| 813 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 830 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 814 "423948 ResourceLoader::ResponseCompleted")); | 831 "423948 ResourceLoader::ResponseCompleted")); |
| 815 | 832 |
| 816 handler_->OnResponseCompleted(request_->status(), security_info, &defer); | 833 handler_->OnResponseCompleted(request_->status(), security_info, &defer); |
| 817 } | 834 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 case net::URLRequestStatus::FAILED: | 873 case net::URLRequestStatus::FAILED: |
| 857 status = STATUS_UNDEFINED; | 874 status = STATUS_UNDEFINED; |
| 858 break; | 875 break; |
| 859 } | 876 } |
| 860 | 877 |
| 861 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 878 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
| 862 } | 879 } |
| 863 } | 880 } |
| 864 | 881 |
| 865 } // namespace content | 882 } // namespace content |
| OLD | NEW |