| 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| 6 | 6 |
| 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "content/browser/loader/navigation_resource_throttle.h" | 54 #include "content/browser/loader/navigation_resource_throttle.h" |
| 55 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 55 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 56 #include "content/browser/loader/power_save_block_resource_throttle.h" | 56 #include "content/browser/loader/power_save_block_resource_throttle.h" |
| 57 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 57 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
| 58 #include "content/browser/loader/resource_message_filter.h" | 58 #include "content/browser/loader/resource_message_filter.h" |
| 59 #include "content/browser/loader/resource_request_info_impl.h" | 59 #include "content/browser/loader/resource_request_info_impl.h" |
| 60 #include "content/browser/loader/stream_resource_handler.h" | 60 #include "content/browser/loader/stream_resource_handler.h" |
| 61 #include "content/browser/loader/sync_resource_handler.h" | 61 #include "content/browser/loader/sync_resource_handler.h" |
| 62 #include "content/browser/loader/throttling_resource_handler.h" | 62 #include "content/browser/loader/throttling_resource_handler.h" |
| 63 #include "content/browser/loader/upload_data_stream_builder.h" | 63 #include "content/browser/loader/upload_data_stream_builder.h" |
| 64 #include "content/browser/renderer_host/render_view_host_delegate.h" | |
| 65 #include "content/browser/renderer_host/render_view_host_impl.h" | 64 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 66 #include "content/browser/resource_context_impl.h" | 65 #include "content/browser/resource_context_impl.h" |
| 67 #include "content/browser/service_worker/foreign_fetch_request_handler.h" | 66 #include "content/browser/service_worker/foreign_fetch_request_handler.h" |
| 68 #include "content/browser/service_worker/link_header_support.h" | 67 #include "content/browser/service_worker/link_header_support.h" |
| 69 #include "content/browser/service_worker/service_worker_request_handler.h" | 68 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 70 #include "content/browser/streams/stream.h" | 69 #include "content/browser/streams/stream.h" |
| 71 #include "content/browser/streams/stream_context.h" | 70 #include "content/browser/streams/stream_context.h" |
| 72 #include "content/browser/streams/stream_registry.h" | 71 #include "content/browser/streams/stream_registry.h" |
| 73 #include "content/browser/web_contents/web_contents_impl.h" | 72 #include "content/browser/web_contents/web_contents_impl.h" |
| 74 #include "content/common/appcache_interfaces.h" | |
| 75 #include "content/common/navigation_params.h" | 73 #include "content/common/navigation_params.h" |
| 76 #include "content/common/net/url_request_service_worker_data.h" | 74 #include "content/common/net/url_request_service_worker_data.h" |
| 77 #include "content/common/resource_messages.h" | 75 #include "content/common/resource_messages.h" |
| 78 #include "content/common/resource_request.h" | 76 #include "content/common/resource_request.h" |
| 79 #include "content/common/resource_request_completion_status.h" | 77 #include "content/common/resource_request_completion_status.h" |
| 80 #include "content/common/site_isolation_policy.h" | 78 #include "content/common/site_isolation_policy.h" |
| 81 #include "content/common/ssl_status_serialization.h" | 79 #include "content/common/ssl_status_serialization.h" |
| 82 #include "content/common/view_messages.h" | 80 #include "content/common/view_messages.h" |
| 83 #include "content/public/browser/browser_thread.h" | 81 #include "content/public/browser/browser_thread.h" |
| 84 #include "content/public/browser/content_browser_client.h" | 82 #include "content/public/browser/content_browser_client.h" |
| 85 #include "content/public/browser/download_manager.h" | |
| 86 #include "content/public/browser/download_url_parameters.h" | |
| 87 #include "content/public/browser/global_request_id.h" | 83 #include "content/public/browser/global_request_id.h" |
| 88 #include "content/public/browser/plugin_service.h" | 84 #include "content/public/browser/plugin_service.h" |
| 89 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 85 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 90 #include "content/public/browser/resource_request_details.h" | 86 #include "content/public/browser/resource_request_details.h" |
| 91 #include "content/public/browser/resource_throttle.h" | 87 #include "content/public/browser/resource_throttle.h" |
| 92 #include "content/public/browser/stream_handle.h" | 88 #include "content/public/browser/stream_handle.h" |
| 93 #include "content/public/browser/stream_info.h" | 89 #include "content/public/browser/stream_info.h" |
| 94 #include "content/public/browser/user_metrics.h" | 90 #include "content/public/browser/user_metrics.h" |
| 95 #include "content/public/common/browser_side_navigation_policy.h" | 91 #include "content/public/common/browser_side_navigation_policy.h" |
| 96 #include "content/public/common/content_features.h" | 92 #include "content/public/common/content_features.h" |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 626 |
| 631 void ResourceDispatcherHostImpl::SetDelegate( | 627 void ResourceDispatcherHostImpl::SetDelegate( |
| 632 ResourceDispatcherHostDelegate* delegate) { | 628 ResourceDispatcherHostDelegate* delegate) { |
| 633 delegate_ = delegate; | 629 delegate_ = delegate; |
| 634 } | 630 } |
| 635 | 631 |
| 636 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { | 632 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { |
| 637 allow_cross_origin_auth_prompt_ = value; | 633 allow_cross_origin_auth_prompt_ = value; |
| 638 } | 634 } |
| 639 | 635 |
| 640 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) { | |
| 641 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 642 active_resource_contexts_.insert(context); | |
| 643 } | |
| 644 | |
| 645 void ResourceDispatcherHostImpl::RemoveResourceContext( | |
| 646 ResourceContext* context) { | |
| 647 CHECK(ContainsKey(active_resource_contexts_, context)); | |
| 648 active_resource_contexts_.erase(context); | |
| 649 } | |
| 650 | |
| 651 void ResourceDispatcherHostImpl::CancelRequestsForContext( | 636 void ResourceDispatcherHostImpl::CancelRequestsForContext( |
| 652 ResourceContext* context) { | 637 ResourceContext* context) { |
| 653 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 638 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 654 DCHECK(context); | 639 DCHECK(context); |
| 655 | 640 |
| 656 CHECK(ContainsKey(active_resource_contexts_, context)); | |
| 657 | |
| 658 // Note that request cancellation has side effects. Therefore, we gather all | 641 // Note that request cancellation has side effects. Therefore, we gather all |
| 659 // the requests to cancel first, and then we start cancelling. We assert at | 642 // the requests to cancel first, and then we start cancelling. We assert at |
| 660 // the end that there are no more to cancel since the context is about to go | 643 // the end that there are no more to cancel since the context is about to go |
| 661 // away. | 644 // away. |
| 662 typedef std::vector<std::unique_ptr<ResourceLoader>> LoaderList; | 645 typedef std::vector<std::unique_ptr<ResourceLoader>> LoaderList; |
| 663 LoaderList loaders_to_cancel; | 646 LoaderList loaders_to_cancel; |
| 664 | 647 |
| 665 for (LoaderMap::iterator i = pending_loaders_.begin(); | 648 for (LoaderMap::iterator i = pending_loaders_.begin(); |
| 666 i != pending_loaders_.end();) { | 649 i != pending_loaders_.end();) { |
| 667 ResourceLoader* loader = i->second.get(); | 650 ResourceLoader* loader = i->second.get(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 #endif | 701 #endif |
| 719 | 702 |
| 720 loaders_to_cancel.clear(); | 703 loaders_to_cancel.clear(); |
| 721 | 704 |
| 722 if (async_revalidation_manager_) { | 705 if (async_revalidation_manager_) { |
| 723 // Cancelling async revalidations should not result in the creation of new | 706 // Cancelling async revalidations should not result in the creation of new |
| 724 // requests. Do it before the CHECKs to ensure this does not happen. | 707 // requests. Do it before the CHECKs to ensure this does not happen. |
| 725 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( | 708 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( |
| 726 context); | 709 context); |
| 727 } | 710 } |
| 728 | |
| 729 // Validate that no more requests for this context were added. | |
| 730 for (const auto& loader : pending_loaders_) { | |
| 731 // http://crbug.com/90971 | |
| 732 CHECK_NE(loader.second->GetRequestInfo()->GetContext(), context); | |
| 733 } | |
| 734 | |
| 735 for (const auto& blocked_loaders : blocked_loaders_map_) { | |
| 736 BlockedLoadersList* loaders = blocked_loaders.second.get(); | |
| 737 if (!loaders->empty()) { | |
| 738 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo(); | |
| 739 // http://crbug.com/90971 | |
| 740 CHECK_NE(info->GetContext(), context); | |
| 741 } | |
| 742 } | |
| 743 } | 711 } |
| 744 | 712 |
| 745 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload( | 713 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload( |
| 746 std::unique_ptr<net::URLRequest> request, | 714 std::unique_ptr<net::URLRequest> request, |
| 747 const Referrer& referrer, | 715 const Referrer& referrer, |
| 748 bool is_content_initiated, | 716 bool is_content_initiated, |
| 749 ResourceContext* context, | 717 ResourceContext* context, |
| 750 int render_process_id, | 718 int render_process_id, |
| 751 int render_view_route_id, | 719 int render_view_route_id, |
| 752 int render_frame_route_id, | 720 int render_frame_route_id, |
| 753 bool do_not_prompt_for_login) { | 721 bool do_not_prompt_for_login) { |
| 754 if (is_shutdown_) | 722 if (is_shutdown_) |
| 755 return DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN; | 723 return DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN; |
| 756 | 724 |
| 757 const GURL& url = request->original_url(); | 725 const GURL& url = request->original_url(); |
| 758 | |
| 759 // http://crbug.com/90971 | |
| 760 char url_buf[128]; | |
| 761 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); | |
| 762 base::debug::Alias(url_buf); | |
| 763 CHECK(ContainsKey(active_resource_contexts_, context)); | |
| 764 | |
| 765 SetReferrerForRequest(request.get(), referrer); | 726 SetReferrerForRequest(request.get(), referrer); |
| 766 | 727 |
| 767 // We treat a download as a main frame load, and thus update the policy URL on | 728 // We treat a download as a main frame load, and thus update the policy URL on |
| 768 // redirects. | 729 // redirects. |
| 769 // | 730 // |
| 770 // TODO(davidben): Is this correct? If this came from a | 731 // TODO(davidben): Is this correct? If this came from a |
| 771 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set | 732 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set |
| 772 // appropriately? | 733 // appropriately? |
| 773 request->set_first_party_url_policy( | 734 request->set_first_party_url_policy( |
| 774 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); | 735 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 bad_message::ReceivedBadMessage( | 1381 bad_message::ReceivedBadMessage( |
| 1421 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1382 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
| 1422 } | 1383 } |
| 1423 return; | 1384 return; |
| 1424 } | 1385 } |
| 1425 | 1386 |
| 1426 ResourceContext* resource_context = NULL; | 1387 ResourceContext* resource_context = NULL; |
| 1427 net::URLRequestContext* request_context = NULL; | 1388 net::URLRequestContext* request_context = NULL; |
| 1428 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, | 1389 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, |
| 1429 &resource_context, &request_context); | 1390 &resource_context, &request_context); |
| 1430 // http://crbug.com/90971 | |
| 1431 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | |
| 1432 | 1391 |
| 1433 // Parse the headers before calling ShouldServiceRequest, so that they are | 1392 // Parse the headers before calling ShouldServiceRequest, so that they are |
| 1434 // available to be validated. | 1393 // available to be validated. |
| 1435 net::HttpRequestHeaders headers; | 1394 net::HttpRequestHeaders headers; |
| 1436 headers.AddHeadersFromString(request_data.headers); | 1395 headers.AddHeadersFromString(request_data.headers); |
| 1437 | 1396 |
| 1438 if (is_shutdown_ || | 1397 if (is_shutdown_ || |
| 1439 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1398 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
| 1440 filter_, resource_context)) { | 1399 filter_, resource_context)) { |
| 1441 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1400 AbortRequestBeforeItStarts(filter_, sync_result, request_id); |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 const Referrer& referrer, | 1869 const Referrer& referrer, |
| 1911 SaveItemId save_item_id, | 1870 SaveItemId save_item_id, |
| 1912 SavePackageId save_package_id, | 1871 SavePackageId save_package_id, |
| 1913 int child_id, | 1872 int child_id, |
| 1914 int render_view_route_id, | 1873 int render_view_route_id, |
| 1915 int render_frame_route_id, | 1874 int render_frame_route_id, |
| 1916 ResourceContext* context) { | 1875 ResourceContext* context) { |
| 1917 if (is_shutdown_) | 1876 if (is_shutdown_) |
| 1918 return; | 1877 return; |
| 1919 | 1878 |
| 1920 // http://crbug.com/90971 | |
| 1921 char url_buf[128]; | |
| 1922 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); | |
| 1923 base::debug::Alias(url_buf); | |
| 1924 CHECK(ContainsKey(active_resource_contexts_, context)); | |
| 1925 | |
| 1926 request_id_--; | 1879 request_id_--; |
| 1927 | 1880 |
| 1928 const net::URLRequestContext* request_context = context->GetRequestContext(); | 1881 const net::URLRequestContext* request_context = context->GetRequestContext(); |
| 1929 bool known_proto = | 1882 bool known_proto = |
| 1930 request_context->job_factory()->IsHandledURL(url); | 1883 request_context->job_factory()->IsHandledURL(url); |
| 1931 if (!known_proto) { | 1884 if (!known_proto) { |
| 1932 // Since any URLs which have non-standard scheme have been filtered | 1885 // Since any URLs which have non-standard scheme have been filtered |
| 1933 // by save manager(see GURL::SchemeIsStandard). This situation | 1886 // by save manager(see GURL::SchemeIsStandard). This situation |
| 1934 // should not happen. | 1887 // should not happen. |
| 1935 NOTREACHED(); | 1888 NOTREACHED(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 // navigation. It's where file upload checks, etc., come in. | 2153 // navigation. It's where file upload checks, etc., come in. |
| 2201 (delegate_ && !delegate_->ShouldBeginRequest( | 2154 (delegate_ && !delegate_->ShouldBeginRequest( |
| 2202 info.common_params.method, | 2155 info.common_params.method, |
| 2203 info.common_params.url, | 2156 info.common_params.url, |
| 2204 resource_type, | 2157 resource_type, |
| 2205 resource_context))) { | 2158 resource_context))) { |
| 2206 loader->NotifyRequestFailed(false, net::ERR_ABORTED); | 2159 loader->NotifyRequestFailed(false, net::ERR_ABORTED); |
| 2207 return; | 2160 return; |
| 2208 } | 2161 } |
| 2209 | 2162 |
| 2210 // Save the URL on the stack to help catch URLRequests which outlive their | |
| 2211 // URLRequestContexts. See https://crbug.com/90971 | |
| 2212 char url_buf[128]; | |
| 2213 base::strlcpy( | |
| 2214 url_buf, info.common_params.url.spec().c_str(), arraysize(url_buf)); | |
| 2215 base::debug::Alias(url_buf); | |
| 2216 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | |
| 2217 | |
| 2218 const net::URLRequestContext* request_context = | 2163 const net::URLRequestContext* request_context = |
| 2219 resource_context->GetRequestContext(); | 2164 resource_context->GetRequestContext(); |
| 2220 | 2165 |
| 2221 int load_flags = info.begin_params.load_flags; | 2166 int load_flags = info.begin_params.load_flags; |
| 2222 load_flags |= net::LOAD_VERIFY_EV_CERT; | 2167 load_flags |= net::LOAD_VERIFY_EV_CERT; |
| 2223 if (info.is_main_frame) | 2168 if (info.is_main_frame) |
| 2224 load_flags |= net::LOAD_MAIN_FRAME; | 2169 load_flags |= net::LOAD_MAIN_FRAME; |
| 2225 | 2170 |
| 2226 // TODO(davidben): BuildLoadFlagsForRequest includes logic for | 2171 // TODO(davidben): BuildLoadFlagsForRequest includes logic for |
| 2227 // CanSendCookiesForOrigin and CanReadRawCookies. Is this needed here? | 2172 // CanSendCookiesForOrigin and CanReadRawCookies. Is this needed here? |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2693 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2638 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
| 2694 response->head.security_info = SerializeSecurityInfo(ssl); | 2639 response->head.security_info = SerializeSecurityInfo(ssl); |
| 2695 } | 2640 } |
| 2696 | 2641 |
| 2697 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2642 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
| 2698 return cert_store_for_testing_ ? cert_store_for_testing_ | 2643 return cert_store_for_testing_ ? cert_store_for_testing_ |
| 2699 : CertStore::GetInstance(); | 2644 : CertStore::GetInstance(); |
| 2700 } | 2645 } |
| 2701 | 2646 |
| 2702 } // namespace content | 2647 } // namespace content |
| OLD | NEW |