| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "content/browser/appcache/appcache_interceptor.h" | 15 #include "content/browser/appcache/appcache_interceptor.h" |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/loader/cross_site_resource_handler.h" | 17 #include "content/browser/loader/cross_site_resource_handler.h" |
| 17 #include "content/browser/loader/detachable_resource_handler.h" | 18 #include "content/browser/loader/detachable_resource_handler.h" |
| 18 #include "content/browser/loader/resource_loader_delegate.h" | 19 #include "content/browser/loader/resource_loader_delegate.h" |
| 19 #include "content/browser/loader/resource_request_info_impl.h" | 20 #include "content/browser/loader/resource_request_info_impl.h" |
| 20 #include "content/browser/service_worker/service_worker_request_handler.h" | 21 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 21 #include "content/browser/ssl/ssl_client_auth_handler.h" | 22 #include "content/browser/ssl/ssl_client_auth_handler.h" |
| 22 #include "content/browser/ssl/ssl_manager.h" | 23 #include "content/browser/ssl/ssl_manager.h" |
| 23 #include "content/browser/ssl/ssl_policy.h" | 24 #include "content/browser/ssl/ssl_policy.h" |
| 24 #include "content/common/ssl_status_serialization.h" | 25 #include "content/common/ssl_status_serialization.h" |
| 25 #include "content/public/browser/cert_store.h" | 26 #include "content/public/browser/cert_store.h" |
| 26 #include "content/public/browser/resource_context.h" | 27 #include "content/public/browser/resource_context.h" |
| 27 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 28 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 28 #include "content/public/browser/signed_certificate_timestamp_store.h" | 29 #include "content/public/browser/signed_certificate_timestamp_store.h" |
| 29 #include "content/public/common/content_client.h" | 30 #include "content/public/common/content_client.h" |
| 30 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 31 #include "content/public/common/process_type.h" | 32 #include "content/public/common/process_type.h" |
| 32 #include "content/public/common/resource_response.h" | 33 #include "content/public/common/resource_response.h" |
| 33 #include "content/public/common/security_style.h" | 34 #include "content/public/common/security_style.h" |
| 35 #include "content/public/common/ssl_status.h" |
| 34 #include "net/base/io_buffer.h" | 36 #include "net/base/io_buffer.h" |
| 35 #include "net/base/load_flags.h" | 37 #include "net/base/load_flags.h" |
| 36 #include "net/http/http_response_headers.h" | 38 #include "net/http/http_response_headers.h" |
| 37 #include "net/ssl/client_cert_store.h" | 39 #include "net/ssl/client_cert_store.h" |
| 38 #include "net/url_request/redirect_info.h" | 40 #include "net/url_request/redirect_info.h" |
| 39 #include "net/url_request/url_request_status.h" | 41 #include "net/url_request/url_request_status.h" |
| 40 | 42 |
| 41 using base::TimeDelta; | 43 using base::TimeDelta; |
| 42 using base::TimeTicks; | 44 using base::TimeTicks; |
| 43 | 45 |
| 44 namespace content { | 46 namespace content { |
| 45 namespace { | 47 namespace { |
| 46 | 48 |
| 49 // Stores the SignedCertificateTimestamps held in |sct_list| in the |
| 50 // SignedCertificateTimestampStore singleton, associated with |process_id|. |
| 51 // On return, |sct_ids| contains the assigned ID and verification status of |
| 52 // each SignedCertificateTimestamp. |
| 47 void StoreSignedCertificateTimestamps( | 53 void StoreSignedCertificateTimestamps( |
| 48 const net::SignedCertificateTimestampAndStatusList& sct_list, | 54 const net::SignedCertificateTimestampAndStatusList& sct_list, |
| 49 int process_id, | 55 int process_id, |
| 50 SignedCertificateTimestampIDStatusList* sct_ids) { | 56 SignedCertificateTimestampIDStatusList* sct_ids) { |
| 51 SignedCertificateTimestampStore* sct_store( | 57 SignedCertificateTimestampStore* sct_store( |
| 52 SignedCertificateTimestampStore::GetInstance()); | 58 SignedCertificateTimestampStore::GetInstance()); |
| 53 | 59 |
| 54 for (auto iter = sct_list.begin(); iter != sct_list.end(); ++iter) { | 60 for (const auto& sct : sct_list) { |
| 55 const int sct_id(sct_store->Store(iter->sct.get(), process_id)); | 61 const int sct_id(sct_store->Store(sct.sct.get(), process_id)); |
| 56 sct_ids->push_back( | 62 sct_ids->push_back( |
| 57 SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); | 63 SignedCertificateTimestampIDAndStatus(sct_id, sct.status)); |
| 58 } | 64 } |
| 59 } | 65 } |
| 60 | 66 |
| 61 void GetSSLStatusForRequest(const GURL& url, | 67 void GetSSLStatusForRequest(const GURL& url, |
| 62 const net::SSLInfo& ssl_info, | 68 const net::SSLInfo& ssl_info, |
| 63 int child_id, | 69 int child_id, |
| 64 SSLStatus* ssl_status) { | 70 SSLStatus* ssl_status) { |
| 65 DCHECK(ssl_info.cert); | 71 DCHECK(ssl_info.cert); |
| 66 | 72 |
| 67 int cert_id = | 73 int cert_id = |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, | 272 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, |
| 267 net::AuthChallengeInfo* auth_info) { | 273 net::AuthChallengeInfo* auth_info) { |
| 268 DCHECK_EQ(request_.get(), unused); | 274 DCHECK_EQ(request_.get(), unused); |
| 269 | 275 |
| 270 ResourceRequestInfoImpl* info = GetRequestInfo(); | 276 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 271 if (info->do_not_prompt_for_login()) { | 277 if (info->do_not_prompt_for_login()) { |
| 272 request_->CancelAuth(); | 278 request_->CancelAuth(); |
| 273 return; | 279 return; |
| 274 } | 280 } |
| 275 | 281 |
| 282 // Update the SSL state before showing the auth prompt. |
| 283 const net::SSLInfo& ssl_info = request_->response_info().ssl_info; |
| 284 if (ssl_info.cert.get()) { |
| 285 bool is_main_frame = (request_->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
| 286 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 287 int render_process_id; |
| 288 int render_frame_id; |
| 289 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) |
| 290 CHECK(false); |
| 291 |
| 292 SSLStatus status; |
| 293 GetSSLStatusForRequest(request_->url(), ssl_info, render_process_id, |
| 294 &status); |
| 295 |
| 296 SSLManager::OnAuthDialog(render_process_id, render_frame_id, status, |
| 297 is_main_frame); |
| 298 } else { |
| 299 // We should not have any SSL state. |
| 300 DCHECK(!ssl_info.cert_status && ssl_info.security_bits == -1 && |
| 301 !ssl_info.connection_status); |
| 302 } |
| 303 |
| 276 // Create a login dialog on the UI thread to get authentication data, or pull | 304 // Create a login dialog on the UI thread to get authentication data, or pull |
| 277 // from cache and continue on the IO thread. | 305 // from cache and continue on the IO thread. |
| 278 | |
| 279 DCHECK(!login_delegate_.get()) | 306 DCHECK(!login_delegate_.get()) |
| 280 << "OnAuthRequired called with login_delegate pending"; | 307 << "OnAuthRequired called with login_delegate pending"; |
| 281 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info); | 308 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info); |
| 282 if (!login_delegate_.get()) | 309 if (!login_delegate_.get()) |
| 283 request_->CancelAuth(); | 310 request_->CancelAuth(); |
| 284 } | 311 } |
| 285 | 312 |
| 286 void ResourceLoader::OnCertificateRequested( | 313 void ResourceLoader::OnCertificateRequested( |
| 287 net::URLRequest* unused, | 314 net::URLRequest* unused, |
| 288 net::SSLCertRequestInfo* cert_info) { | 315 net::SSLCertRequestInfo* cert_info) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 302 } | 329 } |
| 303 | 330 |
| 304 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, | 331 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, |
| 305 const net::SSLInfo& ssl_info, | 332 const net::SSLInfo& ssl_info, |
| 306 bool fatal) { | 333 bool fatal) { |
| 307 ResourceRequestInfoImpl* info = GetRequestInfo(); | 334 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 308 | 335 |
| 309 int render_process_id; | 336 int render_process_id; |
| 310 int render_frame_id; | 337 int render_frame_id; |
| 311 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) | 338 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) |
| 312 NOTREACHED(); | 339 CHECK(false); |
| 313 | 340 |
| 314 SSLManager::OnSSLCertificateError( | 341 SSLManager::OnSSLCertificateError( |
| 315 weak_ptr_factory_.GetWeakPtr(), | 342 weak_ptr_factory_.GetWeakPtr(), |
| 316 info->GetResourceType(), | 343 info->GetResourceType(), |
| 317 request_->url(), | 344 request_->url(), |
| 318 render_process_id, | 345 render_process_id, |
| 319 render_frame_id, | 346 render_frame_id, |
| 320 ssl_info, | 347 ssl_info, |
| 321 fatal); | 348 fatal); |
| 322 } | 349 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } else { | 542 } else { |
| 516 times_cancelled_after_request_start_++; | 543 times_cancelled_after_request_start_++; |
| 517 } | 544 } |
| 518 | 545 |
| 519 request_->CancelWithError(error); | 546 request_->CancelWithError(error); |
| 520 | 547 |
| 521 if (!was_pending) { | 548 if (!was_pending) { |
| 522 // If the request isn't in flight, then we won't get an asynchronous | 549 // If the request isn't in flight, then we won't get an asynchronous |
| 523 // notification from the request, so we have to signal ourselves to finish | 550 // notification from the request, so we have to signal ourselves to finish |
| 524 // this request. | 551 // this request. |
| 525 base::ThreadTaskRunnerHandle::Get()->PostTask( | 552 base::MessageLoop::current()->PostTask( |
| 526 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, | 553 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, |
| 527 weak_ptr_factory_.GetWeakPtr())); | 554 weak_ptr_factory_.GetWeakPtr())); |
| 528 } | 555 } |
| 529 } | 556 } |
| 530 | 557 |
| 531 void ResourceLoader::CompleteResponseStarted() { | 558 void ResourceLoader::CompleteResponseStarted() { |
| 532 ResourceRequestInfoImpl* info = GetRequestInfo(); | 559 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 533 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 560 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 534 PopulateResourceResponse(info, request_.get(), response.get()); | 561 PopulateResourceResponse(info, request_.get(), response.get()); |
| 535 | 562 |
| 563 if (request_->ssl_info().cert.get()) { |
| 564 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 565 tracked_objects::ScopedTracker tracking_profile3( |
| 566 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 567 "423948 ResourceLoader::CompleteResponseStarted3")); |
| 568 |
| 569 SSLStatus status; |
| 570 GetSSLStatusForRequest(request_->url(), request_->ssl_info(), |
| 571 info->GetChildID(), &status); |
| 572 response->head.security_info = SerializeSecurityInfo(status); |
| 573 } else { |
| 574 // We should not have any SSL state. |
| 575 DCHECK(!request_->ssl_info().cert_status && |
| 576 request_->ssl_info().security_bits == -1 && |
| 577 !request_->ssl_info().connection_status); |
| 578 } |
| 579 |
| 580 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 581 tracked_objects::ScopedTracker tracking_profile5( |
| 582 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 583 "423948 ResourceLoader::CompleteResponseStarted5")); |
| 584 |
| 536 delegate_->DidReceiveResponse(this); | 585 delegate_->DidReceiveResponse(this); |
| 537 | 586 |
| 538 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 587 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 539 tracked_objects::ScopedTracker tracking_profile( | 588 tracked_objects::ScopedTracker tracking_profile( |
| 540 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); | 589 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); |
| 541 | 590 |
| 542 bool defer = false; | 591 bool defer = false; |
| 543 if (!handler_->OnResponseStarted(response.get(), &defer)) { | 592 if (!handler_->OnResponseStarted(response.get(), &defer)) { |
| 544 Cancel(); | 593 Cancel(); |
| 545 } else if (defer) { | 594 } else if (defer) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 } | 683 } |
| 635 | 684 |
| 636 void ResourceLoader::ResponseCompleted() { | 685 void ResourceLoader::ResponseCompleted() { |
| 637 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); | 686 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); |
| 638 RecordHistograms(); | 687 RecordHistograms(); |
| 639 ResourceRequestInfoImpl* info = GetRequestInfo(); | 688 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 640 | 689 |
| 641 std::string security_info; | 690 std::string security_info; |
| 642 const net::SSLInfo& ssl_info = request_->ssl_info(); | 691 const net::SSLInfo& ssl_info = request_->ssl_info(); |
| 643 if (ssl_info.cert.get() != NULL) { | 692 if (ssl_info.cert.get() != NULL) { |
| 644 SSLStatus ssl_status; | 693 SSLStatus status; |
| 645 GetSSLStatusForRequest(request_->url(), ssl_info, info->GetChildID(), | 694 GetSSLStatusForRequest(request_->url(), ssl_info, info->GetChildID(), |
| 646 &ssl_status); | 695 &status); |
| 647 | 696 security_info = SerializeSecurityInfo(status); |
| 648 security_info = SerializeSecurityInfo(ssl_status); | |
| 649 } | 697 } |
| 650 | 698 |
| 651 bool defer = false; | 699 bool defer = false; |
| 652 { | 700 { |
| 653 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 701 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 654 tracked_objects::ScopedTracker tracking_profile( | 702 tracked_objects::ScopedTracker tracking_profile( |
| 655 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()")); | 703 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()")); |
| 656 | 704 |
| 657 handler_->OnResponseCompleted(request_->status(), security_info, &defer); | 705 handler_->OnResponseCompleted(request_->status(), security_info, &defer); |
| 658 } | 706 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 case net::URLRequestStatus::FAILED: | 745 case net::URLRequestStatus::FAILED: |
| 698 status = STATUS_UNDEFINED; | 746 status = STATUS_UNDEFINED; |
| 699 break; | 747 break; |
| 700 } | 748 } |
| 701 | 749 |
| 702 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 750 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
| 703 } | 751 } |
| 704 } | 752 } |
| 705 | 753 |
| 706 } // namespace content | 754 } // namespace content |
| OLD | NEW |