| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "content/browser/loader/mime_sniffing_resource_handler.h" | 50 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
| 51 #include "content/browser/loader/mojo_async_resource_handler.h" | 51 #include "content/browser/loader/mojo_async_resource_handler.h" |
| 52 #include "content/browser/loader/navigation_resource_handler.h" | 52 #include "content/browser/loader/navigation_resource_handler.h" |
| 53 #include "content/browser/loader/navigation_resource_throttle.h" | 53 #include "content/browser/loader/navigation_resource_throttle.h" |
| 54 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 54 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 55 #include "content/browser/loader/power_save_block_resource_throttle.h" | 55 #include "content/browser/loader/power_save_block_resource_throttle.h" |
| 56 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 56 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
| 57 #include "content/browser/loader/resource_loader.h" | 57 #include "content/browser/loader/resource_loader.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/resource_requester_info.h" |
| 60 #include "content/browser/loader/resource_scheduler.h" | 61 #include "content/browser/loader/resource_scheduler.h" |
| 61 #include "content/browser/loader/stream_resource_handler.h" | 62 #include "content/browser/loader/stream_resource_handler.h" |
| 62 #include "content/browser/loader/sync_resource_handler.h" | 63 #include "content/browser/loader/sync_resource_handler.h" |
| 63 #include "content/browser/loader/throttling_resource_handler.h" | 64 #include "content/browser/loader/throttling_resource_handler.h" |
| 64 #include "content/browser/loader/upload_data_stream_builder.h" | 65 #include "content/browser/loader/upload_data_stream_builder.h" |
| 65 #include "content/browser/resource_context_impl.h" | 66 #include "content/browser/resource_context_impl.h" |
| 66 #include "content/browser/service_worker/foreign_fetch_request_handler.h" | 67 #include "content/browser/service_worker/foreign_fetch_request_handler.h" |
| 67 #include "content/browser/service_worker/link_header_support.h" | 68 #include "content/browser/service_worker/link_header_support.h" |
| 69 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 68 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" | 70 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" |
| 69 #include "content/browser/service_worker/service_worker_request_handler.h" | 71 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 70 #include "content/browser/streams/stream.h" | 72 #include "content/browser/streams/stream.h" |
| 71 #include "content/browser/streams/stream_context.h" | 73 #include "content/browser/streams/stream_context.h" |
| 72 #include "content/browser/streams/stream_registry.h" | 74 #include "content/browser/streams/stream_registry.h" |
| 73 #include "content/common/navigation_params.h" | 75 #include "content/common/navigation_params.h" |
| 74 #include "content/common/net/url_request_service_worker_data.h" | 76 #include "content/common/net/url_request_service_worker_data.h" |
| 75 #include "content/common/resource_messages.h" | 77 #include "content/common/resource_messages.h" |
| 76 #include "content/common/resource_request.h" | 78 #include "content/common/resource_request.h" |
| 77 #include "content/common/resource_request_body_impl.h" | 79 #include "content/common/resource_request_body_impl.h" |
| 78 #include "content/common/resource_request_completion_status.h" | 80 #include "content/common/resource_request_completion_status.h" |
| 79 #include "content/common/site_isolation_policy.h" | 81 #include "content/common/site_isolation_policy.h" |
| 80 #include "content/common/view_messages.h" | 82 #include "content/common/view_messages.h" |
| 81 #include "content/public/browser/browser_thread.h" | 83 #include "content/public/browser/browser_thread.h" |
| 82 #include "content/public/browser/global_request_id.h" | 84 #include "content/public/browser/global_request_id.h" |
| 83 #include "content/public/browser/navigation_ui_data.h" | 85 #include "content/public/browser/navigation_ui_data.h" |
| 84 #include "content/public/browser/plugin_service.h" | 86 #include "content/public/browser/plugin_service.h" |
| 85 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 87 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 86 #include "content/public/browser/resource_request_details.h" | 88 #include "content/public/browser/resource_request_details.h" |
| 87 #include "content/public/browser/resource_throttle.h" | 89 #include "content/public/browser/resource_throttle.h" |
| 88 #include "content/public/browser/stream_handle.h" | 90 #include "content/public/browser/stream_handle.h" |
| 89 #include "content/public/browser/stream_info.h" | 91 #include "content/public/browser/stream_info.h" |
| 90 #include "content/public/common/browser_side_navigation_policy.h" | 92 #include "content/public/common/browser_side_navigation_policy.h" |
| 91 #include "content/public/common/content_features.h" | 93 #include "content/public/common/content_features.h" |
| 92 #include "content/public/common/content_switches.h" | 94 #include "content/public/common/content_switches.h" |
| 93 #include "content/public/common/process_type.h" | |
| 94 #include "ipc/ipc_message_macros.h" | 95 #include "ipc/ipc_message_macros.h" |
| 95 #include "ipc/ipc_message_start.h" | 96 #include "ipc/ipc_message_start.h" |
| 96 #include "net/base/auth.h" | 97 #include "net/base/auth.h" |
| 97 #include "net/base/load_flags.h" | 98 #include "net/base/load_flags.h" |
| 98 #include "net/base/mime_util.h" | 99 #include "net/base/mime_util.h" |
| 99 #include "net/base/net_errors.h" | 100 #include "net/base/net_errors.h" |
| 100 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 101 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 101 #include "net/base/upload_data_stream.h" | 102 #include "net/base/upload_data_stream.h" |
| 102 #include "net/cert/cert_status_flags.h" | 103 #include "net/cert/cert_status_flags.h" |
| 103 #include "net/cookies/cookie_monster.h" | 104 #include "net/cookies/cookie_monster.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 case RESOURCE_TYPE_PING: | 222 case RESOURCE_TYPE_PING: |
| 222 case RESOURCE_TYPE_CSP_REPORT: | 223 case RESOURCE_TYPE_CSP_REPORT: |
| 223 return true; | 224 return true; |
| 224 default: | 225 default: |
| 225 return false; | 226 return false; |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 | 229 |
| 229 // Aborts a request before an URLRequest has actually been created. | 230 // Aborts a request before an URLRequest has actually been created. |
| 230 void AbortRequestBeforeItStarts( | 231 void AbortRequestBeforeItStarts( |
| 231 ResourceMessageFilter* filter, | 232 IPC::Sender* sender, |
| 232 const SyncLoadResultCallback& sync_result_handler, | 233 const SyncLoadResultCallback& sync_result_handler, |
| 233 int request_id, | 234 int request_id, |
| 234 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 235 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 235 if (sync_result_handler) { | 236 if (sync_result_handler) { |
| 236 SyncLoadResult result; | 237 SyncLoadResult result; |
| 237 result.error_code = net::ERR_ABORTED; | 238 result.error_code = net::ERR_ABORTED; |
| 238 sync_result_handler.Run(&result); | 239 sync_result_handler.Run(&result); |
| 239 } else { | 240 } else { |
| 240 // Tell the renderer that this request was disallowed. | 241 // Tell the renderer that this request was disallowed. |
| 241 ResourceRequestCompletionStatus request_complete_data; | 242 ResourceRequestCompletionStatus request_complete_data; |
| 242 request_complete_data.error_code = net::ERR_ABORTED; | 243 request_complete_data.error_code = net::ERR_ABORTED; |
| 243 request_complete_data.was_ignored_by_handler = false; | 244 request_complete_data.was_ignored_by_handler = false; |
| 244 request_complete_data.exists_in_cache = false; | 245 request_complete_data.exists_in_cache = false; |
| 245 // No security info needed, connection not established. | 246 // No security info needed, connection not established. |
| 246 request_complete_data.completion_time = base::TimeTicks(); | 247 request_complete_data.completion_time = base::TimeTicks(); |
| 247 request_complete_data.encoded_data_length = 0; | 248 request_complete_data.encoded_data_length = 0; |
| 248 request_complete_data.encoded_body_length = 0; | 249 request_complete_data.encoded_body_length = 0; |
| 249 if (url_loader_client) { | 250 if (url_loader_client) { |
| 250 url_loader_client->OnComplete(request_complete_data); | 251 url_loader_client->OnComplete(request_complete_data); |
| 251 } else { | 252 } else { |
| 252 filter->Send( | 253 sender->Send( |
| 253 new ResourceMsg_RequestComplete(request_id, request_complete_data)); | 254 new ResourceMsg_RequestComplete(request_id, request_complete_data)); |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 | 258 |
| 258 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { | 259 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { |
| 259 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 260 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 260 if (!referrer.url.is_valid() || | 261 if (!referrer.url.is_valid() || |
| 261 command_line->HasSwitch(switches::kNoReferrers)) { | 262 command_line->HasSwitch(switches::kNoReferrers)) { |
| 262 request->SetReferrer(std::string()); | 263 request->SetReferrer(std::string()); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl( | 463 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl( |
| 463 CreateDownloadHandlerIntercept download_handler_intercept) | 464 CreateDownloadHandlerIntercept download_handler_intercept) |
| 464 : request_id_(-1), | 465 : request_id_(-1), |
| 465 is_shutdown_(false), | 466 is_shutdown_(false), |
| 466 num_in_flight_requests_(0), | 467 num_in_flight_requests_(0), |
| 467 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 468 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
| 468 max_num_in_flight_requests_per_process_(static_cast<int>( | 469 max_num_in_flight_requests_per_process_(static_cast<int>( |
| 469 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 470 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
| 470 max_outstanding_requests_cost_per_process_( | 471 max_outstanding_requests_cost_per_process_( |
| 471 kMaxOutstandingRequestsCostPerProcess), | 472 kMaxOutstandingRequestsCostPerProcess), |
| 472 filter_(nullptr), | |
| 473 delegate_(nullptr), | 473 delegate_(nullptr), |
| 474 loader_delegate_(nullptr), | 474 loader_delegate_(nullptr), |
| 475 allow_cross_origin_auth_prompt_(false), | 475 allow_cross_origin_auth_prompt_(false), |
| 476 create_download_handler_intercept_(download_handler_intercept) { | 476 create_download_handler_intercept_(download_handler_intercept) { |
| 477 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 477 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 478 DCHECK(!g_resource_dispatcher_host); | 478 DCHECK(!g_resource_dispatcher_host); |
| 479 g_resource_dispatcher_host = this; | 479 g_resource_dispatcher_host = this; |
| 480 | 480 |
| 481 ANNOTATE_BENIGN_RACE( | 481 ANNOTATE_BENIGN_RACE( |
| 482 &last_user_gesture_time_, | 482 &last_user_gesture_time_, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 } | 612 } |
| 613 | 613 |
| 614 #ifndef NDEBUG | 614 #ifndef NDEBUG |
| 615 for (const auto& loader : loaders_to_cancel) { | 615 for (const auto& loader : loaders_to_cancel) { |
| 616 // There is no strict requirement that this be the case, but currently | 616 // There is no strict requirement that this be the case, but currently |
| 617 // downloads, streams, detachable requests, transferred requests, and | 617 // downloads, streams, detachable requests, transferred requests, and |
| 618 // browser-owned requests are the only requests that aren't cancelled when | 618 // browser-owned requests are the only requests that aren't cancelled when |
| 619 // the associated processes go away. It may be OK for this invariant to | 619 // the associated processes go away. It may be OK for this invariant to |
| 620 // change in the future, but if this assertion fires without the invariant | 620 // change in the future, but if this assertion fires without the invariant |
| 621 // changing, then it's indicative of a leak. | 621 // changing, then it's indicative of a leak. |
| 622 DCHECK(loader->GetRequestInfo()->IsDownload() || | 622 DCHECK( |
| 623 loader->GetRequestInfo()->is_stream() || | 623 loader->GetRequestInfo()->IsDownload() || |
| 624 (loader->GetRequestInfo()->detachable_handler() && | 624 loader->GetRequestInfo()->is_stream() || |
| 625 loader->GetRequestInfo()->detachable_handler()->is_detached()) || | 625 (loader->GetRequestInfo()->detachable_handler() && |
| 626 loader->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER || | 626 loader->GetRequestInfo()->detachable_handler()->is_detached()) || |
| 627 loader->is_transferring()); | 627 loader->GetRequestInfo()->requester_info()->IsBrowserSideNavigation() || |
| 628 loader->is_transferring()); |
| 628 } | 629 } |
| 629 #endif | 630 #endif |
| 630 | 631 |
| 631 loaders_to_cancel.clear(); | 632 loaders_to_cancel.clear(); |
| 632 | 633 |
| 633 if (async_revalidation_manager_) { | 634 if (async_revalidation_manager_) { |
| 634 // Cancelling async revalidations should not result in the creation of new | 635 // Cancelling async revalidations should not result in the creation of new |
| 635 // requests. Do it before the CHECKs to ensure this does not happen. | 636 // requests. Do it before the CHECKs to ensure this does not happen. |
| 636 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( | 637 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( |
| 637 context); | 638 context); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 delegate_->OnRequestRedirected( | 778 delegate_->OnRequestRedirected( |
| 778 new_url, loader->request(), info->GetContext(), response); | 779 new_url, loader->request(), info->GetContext(), response); |
| 779 } | 780 } |
| 780 | 781 |
| 781 net::URLRequest* request = loader->request(); | 782 net::URLRequest* request = loader->request(); |
| 782 if (request->response_info().async_revalidation_required) { | 783 if (request->response_info().async_revalidation_required) { |
| 783 // Async revalidation is only supported for the first redirect leg. | 784 // Async revalidation is only supported for the first redirect leg. |
| 784 DCHECK_EQ(request->url_chain().size(), 1u); | 785 DCHECK_EQ(request->url_chain().size(), 1u); |
| 785 DCHECK(async_revalidation_manager_); | 786 DCHECK(async_revalidation_manager_); |
| 786 | 787 |
| 787 async_revalidation_manager_->BeginAsyncRevalidation(*request, | 788 async_revalidation_manager_->BeginAsyncRevalidation(request, |
| 788 scheduler_.get()); | 789 scheduler_.get()); |
| 789 } | 790 } |
| 790 | 791 |
| 791 // Remove the LOAD_SUPPORT_ASYNC_REVALIDATION flag if it is present. | 792 // Remove the LOAD_SUPPORT_ASYNC_REVALIDATION flag if it is present. |
| 792 // It is difficult to create a URLRequest with the correct flags and headers | 793 // It is difficult to create a URLRequest with the correct flags and headers |
| 793 // for redirect legs other than the first one. Since stale-while-revalidate in | 794 // for redirect legs other than the first one. Since stale-while-revalidate in |
| 794 // combination with redirects isn't needed for experimental use, punt on it | 795 // combination with redirects isn't needed for experimental use, punt on it |
| 795 // for now. | 796 // for now. |
| 796 // TODO(ricea): Fix this before launching the feature. | 797 // TODO(ricea): Fix this before launching the feature. |
| 797 if (request->load_flags() & net::LOAD_SUPPORT_ASYNC_REVALIDATION) { | 798 if (request->load_flags() & net::LOAD_SUPPORT_ASYNC_REVALIDATION) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 820 net::URLRequest* request = loader->request(); | 821 net::URLRequest* request = loader->request(); |
| 821 if (request->was_fetched_via_proxy() && | 822 if (request->was_fetched_via_proxy() && |
| 822 request->was_fetched_via_spdy() && | 823 request->was_fetched_via_spdy() && |
| 823 request->url().SchemeIs(url::kHttpScheme)) { | 824 request->url().SchemeIs(url::kHttpScheme)) { |
| 824 scheduler_->OnReceivedSpdyProxiedHttpResponse( | 825 scheduler_->OnReceivedSpdyProxiedHttpResponse( |
| 825 info->GetChildID(), info->GetRouteID()); | 826 info->GetChildID(), info->GetRouteID()); |
| 826 } | 827 } |
| 827 | 828 |
| 828 if (request->response_info().async_revalidation_required) { | 829 if (request->response_info().async_revalidation_required) { |
| 829 DCHECK(async_revalidation_manager_); | 830 DCHECK(async_revalidation_manager_); |
| 830 async_revalidation_manager_->BeginAsyncRevalidation(*request, | 831 async_revalidation_manager_->BeginAsyncRevalidation(request, |
| 831 scheduler_.get()); | 832 scheduler_.get()); |
| 832 } | 833 } |
| 833 | 834 |
| 834 ProcessRequestForLinkHeaders(request); | 835 ProcessRequestForLinkHeaders(request); |
| 835 | 836 |
| 836 int render_process_id, render_frame_host; | 837 int render_process_id, render_frame_host; |
| 837 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) | 838 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) |
| 838 return; | 839 return; |
| 839 | 840 |
| 840 // Don't notify WebContents observers for requests known to be | 841 // Don't notify WebContents observers for requests known to be |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 } | 1004 } |
| 1004 for (const auto& routing_id : ids) { | 1005 for (const auto& routing_id : ids) { |
| 1005 CancelBlockedRequestsForRoute(routing_id); | 1006 CancelBlockedRequestsForRoute(routing_id); |
| 1006 } | 1007 } |
| 1007 | 1008 |
| 1008 scheduler_.reset(); | 1009 scheduler_.reset(); |
| 1009 } | 1010 } |
| 1010 | 1011 |
| 1011 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1012 bool ResourceDispatcherHostImpl::OnMessageReceived( |
| 1012 const IPC::Message& message, | 1013 const IPC::Message& message, |
| 1013 ResourceMessageFilter* filter) { | 1014 ResourceRequesterInfo* requester_info) { |
| 1014 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1015 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1015 filter_ = filter; | 1016 |
| 1016 bool handled = true; | 1017 bool handled = true; |
| 1017 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) | 1018 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ResourceDispatcherHostImpl, message, |
| 1019 requester_info) |
| 1018 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 1020 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
| 1019 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) | 1021 IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY(ResourceHostMsg_SyncLoad, |
| 1022 OnSyncLoad) |
| 1020 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 1023 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
| 1021 OnReleaseDownloadedFile) | 1024 OnReleaseDownloadedFile) |
| 1022 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 1025 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
| 1023 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) | 1026 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) |
| 1024 IPC_MESSAGE_UNHANDLED(handled = false) | 1027 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1025 IPC_END_MESSAGE_MAP() | 1028 IPC_END_MESSAGE_MAP() |
| 1026 | 1029 |
| 1027 if (!handled && IPC_MESSAGE_ID_CLASS(message.type()) == ResourceMsgStart) { | 1030 if (!handled && IPC_MESSAGE_ID_CLASS(message.type()) == ResourceMsgStart) { |
| 1028 base::PickleIterator iter(message); | 1031 base::PickleIterator iter(message); |
| 1029 int request_id = -1; | 1032 int request_id = -1; |
| 1030 bool ok = iter.ReadInt(&request_id); | 1033 bool ok = iter.ReadInt(&request_id); |
| 1031 DCHECK(ok); | 1034 DCHECK(ok); |
| 1032 GlobalRequestID id(filter_->child_id(), request_id); | 1035 GlobalRequestID id(requester_info->child_id(), request_id); |
| 1033 DelegateMap::iterator it = delegate_map_.find(id); | 1036 DelegateMap::iterator it = delegate_map_.find(id); |
| 1034 if (it != delegate_map_.end()) { | 1037 if (it != delegate_map_.end()) { |
| 1035 for (auto& delegate : *it->second) { | 1038 for (auto& delegate : *it->second) { |
| 1036 if (delegate.OnMessageReceived(message)) { | 1039 if (delegate.OnMessageReceived(message)) { |
| 1037 handled = true; | 1040 handled = true; |
| 1038 break; | 1041 break; |
| 1039 } | 1042 } |
| 1040 } | 1043 } |
| 1041 } | 1044 } |
| 1042 | 1045 |
| 1043 // As the unhandled resource message effectively has no consumer, mark it as | 1046 // As the unhandled resource message effectively has no consumer, mark it as |
| 1044 // handled to prevent needless propagation through the filter pipeline. | 1047 // handled to prevent needless propagation through the filter pipeline. |
| 1045 handled = true; | 1048 handled = true; |
| 1046 } | 1049 } |
| 1047 | 1050 |
| 1048 filter_ = NULL; | |
| 1049 return handled; | 1051 return handled; |
| 1050 } | 1052 } |
| 1051 | 1053 |
| 1052 void ResourceDispatcherHostImpl::OnRequestResource( | 1054 void ResourceDispatcherHostImpl::OnRequestResource( |
| 1055 ResourceRequesterInfo* requester_info, |
| 1053 int routing_id, | 1056 int routing_id, |
| 1054 int request_id, | 1057 int request_id, |
| 1055 const ResourceRequest& request_data) { | 1058 const ResourceRequest& request_data) { |
| 1056 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, | 1059 OnRequestResourceInternal(requester_info, routing_id, request_id, |
| 1057 nullptr); | 1060 request_data, nullptr, nullptr); |
| 1058 } | 1061 } |
| 1059 | 1062 |
| 1060 void ResourceDispatcherHostImpl::OnRequestResourceInternal( | 1063 void ResourceDispatcherHostImpl::OnRequestResourceInternal( |
| 1064 ResourceRequesterInfo* requester_info, |
| 1061 int routing_id, | 1065 int routing_id, |
| 1062 int request_id, | 1066 int request_id, |
| 1063 const ResourceRequest& request_data, | 1067 const ResourceRequest& request_data, |
| 1064 mojom::URLLoaderAssociatedRequest mojo_request, | 1068 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1065 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1069 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1070 DCHECK(requester_info->IsRenderer()); |
| 1066 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1071 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 1067 tracked_objects::ScopedTracker tracking_profile( | 1072 tracked_objects::ScopedTracker tracking_profile( |
| 1068 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1073 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1069 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1074 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
| 1070 // When logging time-to-network only care about main frame and non-transfer | 1075 // When logging time-to-network only care about main frame and non-transfer |
| 1071 // navigations. | 1076 // navigations. |
| 1072 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1077 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
| 1073 // instead. | 1078 // instead. |
| 1074 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1079 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
| 1075 request_data.transferred_request_request_id == -1 && | 1080 request_data.transferred_request_request_id == -1 && |
| 1076 !IsBrowserSideNavigationEnabled()) { | 1081 !IsBrowserSideNavigationEnabled()) { |
| 1077 BrowserThread::PostTask( | 1082 BrowserThread::PostTask( |
| 1078 BrowserThread::UI, | 1083 BrowserThread::UI, FROM_HERE, |
| 1079 FROM_HERE, | 1084 base::Bind(&LogResourceRequestTimeOnUI, TimeTicks::Now(), |
| 1080 base::Bind(&LogResourceRequestTimeOnUI, | 1085 requester_info->child_id(), request_data.render_frame_id, |
| 1081 TimeTicks::Now(), | |
| 1082 filter_->child_id(), | |
| 1083 request_data.render_frame_id, | |
| 1084 request_data.url)); | 1086 request_data.url)); |
| 1085 } | 1087 } |
| 1086 BeginRequest(request_id, request_data, SyncLoadResultCallback(), routing_id, | 1088 BeginRequest(requester_info, request_id, request_data, |
| 1087 std::move(mojo_request), std::move(url_loader_client)); | 1089 SyncLoadResultCallback(), routing_id, std::move(mojo_request), |
| 1090 std::move(url_loader_client)); |
| 1088 } | 1091 } |
| 1089 | 1092 |
| 1090 // Begins a resource request with the given params on behalf of the specified | 1093 // Begins a resource request with the given params on behalf of the specified |
| 1091 // child process. Responses will be dispatched through the given receiver. The | 1094 // child process. Responses will be dispatched through the given receiver. The |
| 1092 // process ID is used to lookup WebContentsImpl from routing_id's in the case of | 1095 // process ID is used to lookup WebContentsImpl from routing_id's in the case of |
| 1093 // a request from a renderer. request_context is the cookie/cache context to be | 1096 // a request from a renderer. request_context is the cookie/cache context to be |
| 1094 // used for this request. | 1097 // used for this request. |
| 1095 // | 1098 // |
| 1096 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1099 // If sync_result is non-null, then a SyncLoad reply will be generated, else |
| 1097 // a normal asynchronous set of response messages will be generated. | 1100 // a normal asynchronous set of response messages will be generated. |
| 1098 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, | 1101 void ResourceDispatcherHostImpl::OnSyncLoad( |
| 1099 const ResourceRequest& request_data, | 1102 ResourceRequesterInfo* requester_info, |
| 1100 IPC::Message* sync_result) { | 1103 int request_id, |
| 1101 SyncLoadResultCallback callback = base::Bind( | 1104 const ResourceRequest& request_data, |
| 1102 &HandleSyncLoadResult, filter_->GetWeakPtr(), | 1105 IPC::Message* sync_result) { |
| 1103 base::Passed(WrapUnique(sync_result))); | 1106 SyncLoadResultCallback callback = |
| 1104 BeginRequest(request_id, request_data, callback, sync_result->routing_id(), | 1107 base::Bind(&HandleSyncLoadResult, requester_info->filter()->GetWeakPtr(), |
| 1105 nullptr, nullptr); | 1108 base::Passed(WrapUnique(sync_result))); |
| 1109 BeginRequest(requester_info, request_id, request_data, callback, |
| 1110 sync_result->routing_id(), nullptr, nullptr); |
| 1106 } | 1111 } |
| 1107 | 1112 |
| 1108 bool ResourceDispatcherHostImpl::IsRequestIDInUse( | 1113 bool ResourceDispatcherHostImpl::IsRequestIDInUse( |
| 1109 const GlobalRequestID& id) const { | 1114 const GlobalRequestID& id) const { |
| 1110 if (pending_loaders_.find(id) != pending_loaders_.end()) | 1115 if (pending_loaders_.find(id) != pending_loaders_.end()) |
| 1111 return true; | 1116 return true; |
| 1112 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1117 for (const auto& blocked_loaders : blocked_loaders_map_) { |
| 1113 for (const auto& loader : *blocked_loaders.second.get()) { | 1118 for (const auto& loader : *blocked_loaders.second.get()) { |
| 1114 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1119 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 1115 if (info->GetGlobalRequestID() == id) | 1120 if (info->GetGlobalRequestID() == id) |
| 1116 return true; | 1121 return true; |
| 1117 } | 1122 } |
| 1118 } | 1123 } |
| 1119 return false; | 1124 return false; |
| 1120 } | 1125 } |
| 1121 | 1126 |
| 1122 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( | 1127 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
| 1123 int child_id, | 1128 ResourceRequesterInfo* requester_info, |
| 1124 int route_id, | 1129 int route_id, |
| 1125 int request_id, | 1130 int request_id, |
| 1126 const ResourceRequest& request_data, | 1131 const ResourceRequest& request_data, |
| 1127 LoaderMap::iterator iter, | 1132 LoaderMap::iterator iter, |
| 1128 mojom::URLLoaderAssociatedRequest mojo_request, | 1133 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1129 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1134 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1135 DCHECK(requester_info->IsRenderer()); |
| 1136 int child_id = requester_info->child_id(); |
| 1130 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); | 1137 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); |
| 1131 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, | 1138 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
| 1132 info->GetRenderFrameID()); | 1139 info->GetRenderFrameID()); |
| 1133 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1140 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
| 1134 request_data.transferred_request_request_id); | 1141 request_data.transferred_request_request_id); |
| 1135 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); | 1142 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
| 1136 GlobalRequestID new_request_id(child_id, request_id); | 1143 GlobalRequestID new_request_id(child_id, request_id); |
| 1137 | 1144 |
| 1138 // Clear out data that depends on |info| before updating it. | 1145 // Clear out data that depends on |info| before updating it. |
| 1139 // We always need to move the memory stats to the new process. In contrast, | 1146 // We always need to move the memory stats to the new process. In contrast, |
| 1140 // stats.num_requests is only tracked for some requests (those that require | 1147 // stats.num_requests is only tracked for some requests (those that require |
| 1141 // file descriptors for their shared memory buffer). | 1148 // file descriptors for their shared memory buffer). |
| 1142 IncrementOutstandingRequestsMemory(-1, *info); | 1149 IncrementOutstandingRequestsMemory(-1, *info); |
| 1143 bool should_update_count = info->counted_as_in_flight_request(); | 1150 bool should_update_count = info->counted_as_in_flight_request(); |
| 1144 if (should_update_count) | 1151 if (should_update_count) |
| 1145 IncrementOutstandingRequestsCount(-1, info); | 1152 IncrementOutstandingRequestsCount(-1, info); |
| 1146 | 1153 |
| 1147 DCHECK(pending_loaders_.find(old_request_id) == iter); | 1154 DCHECK(pending_loaders_.find(old_request_id) == iter); |
| 1148 std::unique_ptr<ResourceLoader> loader = std::move(iter->second); | 1155 std::unique_ptr<ResourceLoader> loader = std::move(iter->second); |
| 1149 ResourceLoader* loader_ptr = loader.get(); | 1156 ResourceLoader* loader_ptr = loader.get(); |
| 1150 pending_loaders_.erase(iter); | 1157 pending_loaders_.erase(iter); |
| 1151 | 1158 |
| 1152 // ResourceHandlers should always get state related to the request from the | 1159 // ResourceHandlers should always get state related to the request from the |
| 1153 // ResourceRequestInfo rather than caching it locally. This lets us update | 1160 // ResourceRequestInfo rather than caching it locally. This lets us update |
| 1154 // the info object when a transfer occurs. | 1161 // the info object when a transfer occurs. |
| 1155 info->UpdateForTransfer(child_id, route_id, request_data.render_frame_id, | 1162 info->UpdateForTransfer(route_id, request_data.render_frame_id, |
| 1156 request_data.origin_pid, request_id, | 1163 request_data.origin_pid, request_id, requester_info, |
| 1157 filter_->GetWeakPtr(), std::move(mojo_request), | 1164 std::move(mojo_request), |
| 1158 std::move(url_loader_client)); | 1165 std::move(url_loader_client)); |
| 1159 | 1166 |
| 1160 // Update maps that used the old IDs, if necessary. Some transfers in tests | 1167 // Update maps that used the old IDs, if necessary. Some transfers in tests |
| 1161 // do not actually use a different ID, so not all maps need to be updated. | 1168 // do not actually use a different ID, so not all maps need to be updated. |
| 1162 pending_loaders_[new_request_id] = std::move(loader); | 1169 pending_loaders_[new_request_id] = std::move(loader); |
| 1163 IncrementOutstandingRequestsMemory(1, *info); | 1170 IncrementOutstandingRequestsMemory(1, *info); |
| 1164 if (should_update_count) | 1171 if (should_update_count) |
| 1165 IncrementOutstandingRequestsCount(1, info); | 1172 IncrementOutstandingRequestsCount(1, info); |
| 1166 if (old_routing_id != new_routing_id) { | 1173 if (old_routing_id != new_routing_id) { |
| 1167 if (blocked_loaders_map_.find(old_routing_id) != | 1174 if (blocked_loaders_map_.find(old_routing_id) != |
| 1168 blocked_loaders_map_.end()) { | 1175 blocked_loaders_map_.end()) { |
| 1169 blocked_loaders_map_[new_routing_id] = | 1176 blocked_loaders_map_[new_routing_id] = |
| 1170 std::move(blocked_loaders_map_[old_routing_id]); | 1177 std::move(blocked_loaders_map_[old_routing_id]); |
| 1171 blocked_loaders_map_.erase(old_routing_id); | 1178 blocked_loaders_map_.erase(old_routing_id); |
| 1172 } | 1179 } |
| 1173 } | 1180 } |
| 1174 if (old_request_id != new_request_id) { | 1181 if (old_request_id != new_request_id) { |
| 1175 DelegateMap::iterator it = delegate_map_.find(old_request_id); | 1182 DelegateMap::iterator it = delegate_map_.find(old_request_id); |
| 1176 if (it != delegate_map_.end()) { | 1183 if (it != delegate_map_.end()) { |
| 1177 // Tell each delegate that the request ID has changed. | 1184 // Tell each delegate that the request ID has changed. |
| 1178 for (auto& delegate : *it->second) | 1185 for (auto& delegate : *it->second) |
| 1179 delegate.set_request_id(new_request_id); | 1186 delegate.set_request_id(new_request_id); |
| 1180 // Now store the observer list under the new request ID. | 1187 // Now store the observer list under the new request ID. |
| 1181 delegate_map_[new_request_id] = delegate_map_[old_request_id]; | 1188 delegate_map_[new_request_id] = delegate_map_[old_request_id]; |
| 1182 delegate_map_.erase(old_request_id); | 1189 delegate_map_.erase(old_request_id); |
| 1183 } | 1190 } |
| 1184 } | 1191 } |
| 1185 | 1192 |
| 1186 AppCacheInterceptor::CompleteCrossSiteTransfer( | 1193 AppCacheInterceptor::CompleteCrossSiteTransfer( |
| 1187 loader_ptr->request(), | 1194 loader_ptr->request(), child_id, request_data.appcache_host_id, |
| 1188 child_id, | 1195 requester_info); |
| 1189 request_data.appcache_host_id, | |
| 1190 filter_); | |
| 1191 | 1196 |
| 1192 ServiceWorkerRequestHandler* handler = | 1197 ServiceWorkerRequestHandler* handler = |
| 1193 ServiceWorkerRequestHandler::GetHandler(loader_ptr->request()); | 1198 ServiceWorkerRequestHandler::GetHandler(loader_ptr->request()); |
| 1194 if (handler) { | 1199 if (handler) { |
| 1195 if (!handler->SanityCheckIsSameContext(filter_->service_worker_context())) { | 1200 if (!handler->SanityCheckIsSameContext( |
| 1201 requester_info->service_worker_context())) { |
| 1196 bad_message::ReceivedBadMessage( | 1202 bad_message::ReceivedBadMessage( |
| 1197 filter_, bad_message::RDHI_WRONG_STORAGE_PARTITION); | 1203 requester_info->filter(), bad_message::RDHI_WRONG_STORAGE_PARTITION); |
| 1198 } else { | 1204 } else { |
| 1199 handler->CompleteCrossSiteTransfer( | 1205 handler->CompleteCrossSiteTransfer( |
| 1200 child_id, request_data.service_worker_provider_id); | 1206 child_id, request_data.service_worker_provider_id); |
| 1201 } | 1207 } |
| 1202 } | 1208 } |
| 1203 } | 1209 } |
| 1204 | 1210 |
| 1205 void ResourceDispatcherHostImpl::CompleteTransfer( | 1211 void ResourceDispatcherHostImpl::CompleteTransfer( |
| 1212 ResourceRequesterInfo* requester_info, |
| 1206 int request_id, | 1213 int request_id, |
| 1207 const ResourceRequest& request_data, | 1214 const ResourceRequest& request_data, |
| 1208 int route_id, | 1215 int route_id, |
| 1209 mojom::URLLoaderAssociatedRequest mojo_request, | 1216 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1210 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1217 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1218 DCHECK(requester_info->IsRenderer()); |
| 1211 // Caller should ensure that |request_data| is associated with a transfer. | 1219 // Caller should ensure that |request_data| is associated with a transfer. |
| 1212 DCHECK(request_data.transferred_request_child_id != -1 || | 1220 DCHECK(request_data.transferred_request_child_id != -1 || |
| 1213 request_data.transferred_request_request_id != -1); | 1221 request_data.transferred_request_request_id != -1); |
| 1214 | 1222 |
| 1215 bool is_navigational_request = | 1223 bool is_navigational_request = |
| 1216 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME || | 1224 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME || |
| 1217 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; | 1225 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; |
| 1218 if (!is_navigational_request) { | 1226 if (!is_navigational_request) { |
| 1219 // Transfers apply only to navigational requests - the renderer seems to | 1227 // Transfers apply only to navigational requests - the renderer seems to |
| 1220 // have sent bogus IPC data. | 1228 // have sent bogus IPC data. |
| 1221 bad_message::ReceivedBadMessage( | 1229 bad_message::ReceivedBadMessage( |
| 1222 filter_, bad_message::RDH_TRANSFERRING_NONNAVIGATIONAL_REQUEST); | 1230 requester_info->filter(), |
| 1231 bad_message::RDH_TRANSFERRING_NONNAVIGATIONAL_REQUEST); |
| 1223 return; | 1232 return; |
| 1224 } | 1233 } |
| 1225 | 1234 |
| 1226 // Attempt to find a loader associated with the deferred transfer request. | 1235 // Attempt to find a loader associated with the deferred transfer request. |
| 1227 LoaderMap::iterator it = pending_loaders_.find( | 1236 LoaderMap::iterator it = pending_loaders_.find( |
| 1228 GlobalRequestID(request_data.transferred_request_child_id, | 1237 GlobalRequestID(request_data.transferred_request_child_id, |
| 1229 request_data.transferred_request_request_id)); | 1238 request_data.transferred_request_request_id)); |
| 1230 if (it == pending_loaders_.end()) { | 1239 if (it == pending_loaders_.end()) { |
| 1231 // Renderer sent transferred_request_request_id and/or | 1240 // Renderer sent transferred_request_request_id and/or |
| 1232 // transferred_request_child_id that doesn't have a corresponding entry on | 1241 // transferred_request_child_id that doesn't have a corresponding entry on |
| 1233 // the browser side. | 1242 // the browser side. |
| 1234 // TODO(lukasza): https://crbug.com/659613: Need to understand the scenario | 1243 // TODO(lukasza): https://crbug.com/659613: Need to understand the scenario |
| 1235 // that can lead here (and then attempt to reintroduce a renderer kill | 1244 // that can lead here (and then attempt to reintroduce a renderer kill |
| 1236 // below). | 1245 // below). |
| 1237 return; | 1246 return; |
| 1238 } | 1247 } |
| 1239 ResourceLoader* pending_loader = it->second.get(); | 1248 ResourceLoader* pending_loader = it->second.get(); |
| 1240 | 1249 |
| 1241 if (!pending_loader->is_transferring()) { | 1250 if (!pending_loader->is_transferring()) { |
| 1242 // Renderer sent transferred_request_request_id and/or | 1251 // Renderer sent transferred_request_request_id and/or |
| 1243 // transferred_request_child_id that doesn't correspond to an actually | 1252 // transferred_request_child_id that doesn't correspond to an actually |
| 1244 // transferring loader on the browser side. | 1253 // transferring loader on the browser side. |
| 1245 base::debug::Alias(pending_loader); | 1254 base::debug::Alias(pending_loader); |
| 1246 bad_message::ReceivedBadMessage(filter_, | 1255 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1247 bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1256 bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
| 1248 return; | 1257 return; |
| 1249 } | 1258 } |
| 1250 | 1259 |
| 1251 // If the request is transferring to a new process, we can update our | 1260 // If the request is transferring to a new process, we can update our |
| 1252 // state and let it resume with its existing ResourceHandlers. | 1261 // state and let it resume with its existing ResourceHandlers. |
| 1253 UpdateRequestForTransfer(filter_->child_id(), route_id, request_id, | 1262 UpdateRequestForTransfer(requester_info, route_id, request_id, request_data, |
| 1254 request_data, it, std::move(mojo_request), | 1263 it, std::move(mojo_request), |
| 1255 std::move(url_loader_client)); | 1264 std::move(url_loader_client)); |
| 1256 pending_loader->CompleteTransfer(); | 1265 pending_loader->CompleteTransfer(); |
| 1257 } | 1266 } |
| 1258 | 1267 |
| 1259 void ResourceDispatcherHostImpl::BeginRequest( | 1268 void ResourceDispatcherHostImpl::BeginRequest( |
| 1269 ResourceRequesterInfo* requester_info, |
| 1260 int request_id, | 1270 int request_id, |
| 1261 const ResourceRequest& request_data, | 1271 const ResourceRequest& request_data, |
| 1262 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1272 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 1263 int route_id, | 1273 int route_id, |
| 1264 mojom::URLLoaderAssociatedRequest mojo_request, | 1274 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1265 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1275 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1266 int process_type = filter_->process_type(); | 1276 DCHECK(requester_info->IsRenderer()); |
| 1267 int child_id = filter_->child_id(); | 1277 int child_id = requester_info->child_id(); |
| 1268 | 1278 |
| 1269 // Reject request id that's currently in use. | 1279 // Reject request id that's currently in use. |
| 1270 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1280 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
| 1271 bad_message::ReceivedBadMessage(filter_, | 1281 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1272 bad_message::RDH_INVALID_REQUEST_ID); | 1282 bad_message::RDH_INVALID_REQUEST_ID); |
| 1273 return; | 1283 return; |
| 1274 } | 1284 } |
| 1275 | 1285 |
| 1276 // PlzNavigate: reject invalid renderer main resource request. | 1286 // PlzNavigate: reject invalid renderer main resource request. |
| 1277 bool is_navigation_stream_request = | 1287 bool is_navigation_stream_request = |
| 1278 IsBrowserSideNavigationEnabled() && | 1288 IsBrowserSideNavigationEnabled() && |
| 1279 IsResourceTypeFrame(request_data.resource_type); | 1289 IsResourceTypeFrame(request_data.resource_type); |
| 1280 // The process_type check is to ensure that unittests are not blocked from | 1290 if (is_navigation_stream_request && |
| 1281 // issuing http requests. | 1291 !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { |
| 1282 if ((process_type == PROCESS_TYPE_RENDERER) && is_navigation_stream_request | 1292 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1283 && !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { | 1293 bad_message::RDH_INVALID_URL); |
| 1284 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_INVALID_URL); | |
| 1285 return; | 1294 return; |
| 1286 } | 1295 } |
| 1287 | 1296 |
| 1288 // Reject invalid priority. | 1297 // Reject invalid priority. |
| 1289 if (request_data.priority < net::MINIMUM_PRIORITY || | 1298 if (request_data.priority < net::MINIMUM_PRIORITY || |
| 1290 request_data.priority > net::MAXIMUM_PRIORITY) { | 1299 request_data.priority > net::MAXIMUM_PRIORITY) { |
| 1291 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_INVALID_PRIORITY); | 1300 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1301 bad_message::RDH_INVALID_PRIORITY); |
| 1292 return; | 1302 return; |
| 1293 } | 1303 } |
| 1294 | 1304 |
| 1295 // If we crash here, figure out what URL the renderer was requesting. | 1305 // If we crash here, figure out what URL the renderer was requesting. |
| 1296 // http://crbug.com/91398 | 1306 // http://crbug.com/91398 |
| 1297 char url_buf[128]; | 1307 char url_buf[128]; |
| 1298 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1308 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
| 1299 base::debug::Alias(url_buf); | 1309 base::debug::Alias(url_buf); |
| 1300 | 1310 |
| 1301 // If the request that's coming in is being transferred from another process, | 1311 // If the request that's coming in is being transferred from another process, |
| 1302 // we want to reuse and resume the old loader rather than start a new one. | 1312 // we want to reuse and resume the old loader rather than start a new one. |
| 1303 if (request_data.transferred_request_child_id != -1 || | 1313 if (request_data.transferred_request_child_id != -1 || |
| 1304 request_data.transferred_request_request_id != -1) { | 1314 request_data.transferred_request_request_id != -1) { |
| 1305 CompleteTransfer(request_id, request_data, route_id, | 1315 CompleteTransfer(requester_info, request_id, request_data, route_id, |
| 1306 std::move(mojo_request), std::move(url_loader_client)); | 1316 std::move(mojo_request), std::move(url_loader_client)); |
| 1307 return; | 1317 return; |
| 1308 } | 1318 } |
| 1309 | 1319 |
| 1310 ResourceContext* resource_context = NULL; | 1320 ResourceContext* resource_context = NULL; |
| 1311 net::URLRequestContext* request_context = NULL; | 1321 net::URLRequestContext* request_context = NULL; |
| 1312 filter_->GetContexts(request_data.resource_type, &resource_context, | 1322 requester_info->GetContexts(request_data.resource_type, &resource_context, |
| 1313 &request_context); | 1323 &request_context); |
| 1314 | 1324 |
| 1315 // Parse the headers before calling ShouldServiceRequest, so that they are | 1325 // Parse the headers before calling ShouldServiceRequest, so that they are |
| 1316 // available to be validated. | 1326 // available to be validated. |
| 1317 net::HttpRequestHeaders headers; | 1327 net::HttpRequestHeaders headers; |
| 1318 headers.AddHeadersFromString(request_data.headers); | 1328 headers.AddHeadersFromString(request_data.headers); |
| 1319 | 1329 |
| 1320 if (is_shutdown_ || | 1330 if (is_shutdown_ || |
| 1321 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1331 !ShouldServiceRequest(child_id, request_data, headers, requester_info, |
| 1322 filter_, resource_context)) { | 1332 resource_context)) { |
| 1323 AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id, | 1333 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, |
| 1324 std::move(url_loader_client)); | 1334 request_id, std::move(url_loader_client)); |
| 1325 return; | 1335 return; |
| 1326 } | 1336 } |
| 1327 // Check if we have a registered interceptor for the headers passed in. If | 1337 // Check if we have a registered interceptor for the headers passed in. If |
| 1328 // yes then we need to mark the current request as pending and wait for the | 1338 // yes then we need to mark the current request as pending and wait for the |
| 1329 // interceptor to invoke the callback with a status code indicating whether | 1339 // interceptor to invoke the callback with a status code indicating whether |
| 1330 // the request needs to be aborted or continued. | 1340 // the request needs to be aborted or continued. |
| 1331 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { | 1341 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { |
| 1332 HeaderInterceptorMap::iterator index = | 1342 HeaderInterceptorMap::iterator index = |
| 1333 http_header_interceptor_map_.find(it.name()); | 1343 http_header_interceptor_map_.find(it.name()); |
| 1334 if (index != http_header_interceptor_map_.end()) { | 1344 if (index != http_header_interceptor_map_.end()) { |
| 1335 HeaderInterceptorInfo& interceptor_info = index->second; | 1345 HeaderInterceptorInfo& interceptor_info = index->second; |
| 1336 | 1346 |
| 1337 bool call_interceptor = true; | 1347 bool call_interceptor = true; |
| 1338 if (!interceptor_info.starts_with.empty()) { | 1348 if (!interceptor_info.starts_with.empty()) { |
| 1339 call_interceptor = | 1349 call_interceptor = |
| 1340 base::StartsWith(it.value(), interceptor_info.starts_with, | 1350 base::StartsWith(it.value(), interceptor_info.starts_with, |
| 1341 base::CompareCase::INSENSITIVE_ASCII); | 1351 base::CompareCase::INSENSITIVE_ASCII); |
| 1342 } | 1352 } |
| 1343 if (call_interceptor) { | 1353 if (call_interceptor) { |
| 1344 interceptor_info.interceptor.Run( | 1354 interceptor_info.interceptor.Run( |
| 1345 it.name(), it.value(), child_id, resource_context, | 1355 it.name(), it.value(), child_id, resource_context, |
| 1346 base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest, | 1356 base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest, |
| 1347 base::Unretained(this), request_id, request_data, | 1357 base::Unretained(this), requester_info, request_id, |
| 1348 sync_result_handler, route_id, headers, | 1358 request_data, sync_result_handler, route_id, headers, |
| 1349 base::Passed(std::move(mojo_request)), | 1359 base::Passed(std::move(mojo_request)), |
| 1350 base::Passed(std::move(url_loader_client)))); | 1360 base::Passed(std::move(url_loader_client)))); |
| 1351 return; | 1361 return; |
| 1352 } | 1362 } |
| 1353 } | 1363 } |
| 1354 } | 1364 } |
| 1355 ContinuePendingBeginRequest(request_id, request_data, sync_result_handler, | 1365 ContinuePendingBeginRequest( |
| 1356 route_id, headers, std::move(mojo_request), | 1366 requester_info, request_id, request_data, sync_result_handler, route_id, |
| 1357 std::move(url_loader_client), true, 0); | 1367 headers, std::move(mojo_request), std::move(url_loader_client), true, 0); |
| 1358 } | 1368 } |
| 1359 | 1369 |
| 1360 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( | 1370 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( |
| 1371 scoped_refptr<ResourceRequesterInfo> requester_info, |
| 1361 int request_id, | 1372 int request_id, |
| 1362 const ResourceRequest& request_data, | 1373 const ResourceRequest& request_data, |
| 1363 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1374 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 1364 int route_id, | 1375 int route_id, |
| 1365 const net::HttpRequestHeaders& headers, | 1376 const net::HttpRequestHeaders& headers, |
| 1366 mojom::URLLoaderAssociatedRequest mojo_request, | 1377 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1367 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 1378 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
| 1368 bool continue_request, | 1379 bool continue_request, |
| 1369 int error_code) { | 1380 int error_code) { |
| 1381 DCHECK(requester_info->IsRenderer()); |
| 1370 if (!continue_request) { | 1382 if (!continue_request) { |
| 1371 // TODO(ananta): Find a way to specify the right error code here. Passing | 1383 // TODO(ananta): Find a way to specify the right error code here. Passing |
| 1372 // in a non-content error code is not safe. | 1384 // in a non-content error code is not safe. |
| 1373 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_ILLEGAL_ORIGIN); | 1385 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1374 AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id, | 1386 bad_message::RDH_ILLEGAL_ORIGIN); |
| 1375 std::move(url_loader_client)); | 1387 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, |
| 1388 request_id, std::move(url_loader_client)); |
| 1376 return; | 1389 return; |
| 1377 } | 1390 } |
| 1378 | 1391 int child_id = requester_info->child_id(); |
| 1379 int process_type = filter_->process_type(); | |
| 1380 int child_id = filter_->child_id(); | |
| 1381 | 1392 |
| 1382 bool is_navigation_stream_request = | 1393 bool is_navigation_stream_request = |
| 1383 IsBrowserSideNavigationEnabled() && | 1394 IsBrowserSideNavigationEnabled() && |
| 1384 IsResourceTypeFrame(request_data.resource_type) && | 1395 IsResourceTypeFrame(request_data.resource_type); |
| 1385 process_type == PROCESS_TYPE_RENDERER; | |
| 1386 | 1396 |
| 1387 ResourceContext* resource_context = NULL; | 1397 ResourceContext* resource_context = NULL; |
| 1388 net::URLRequestContext* request_context = NULL; | 1398 net::URLRequestContext* request_context = NULL; |
| 1389 filter_->GetContexts(request_data.resource_type, &resource_context, | 1399 requester_info->GetContexts(request_data.resource_type, &resource_context, |
| 1390 &request_context); | 1400 &request_context); |
| 1391 | 1401 |
| 1392 // Allow the observer to block/handle the request. | 1402 // Allow the observer to block/handle the request. |
| 1393 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1403 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
| 1394 request_data.url, | 1404 request_data.url, |
| 1395 request_data.resource_type, | 1405 request_data.resource_type, |
| 1396 resource_context)) { | 1406 resource_context)) { |
| 1397 AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id, | 1407 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, |
| 1398 std::move(url_loader_client)); | 1408 request_id, std::move(url_loader_client)); |
| 1399 return; | 1409 return; |
| 1400 } | 1410 } |
| 1401 | 1411 |
| 1402 // Construct the request. | 1412 // Construct the request. |
| 1403 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 1413 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( |
| 1404 is_navigation_stream_request ? request_data.resource_body_stream_url | 1414 is_navigation_stream_request ? request_data.resource_body_stream_url |
| 1405 : request_data.url, | 1415 : request_data.url, |
| 1406 request_data.priority, nullptr); | 1416 request_data.priority, nullptr); |
| 1407 | 1417 |
| 1408 // PlzNavigate: Always set the method to GET when gaining access to the | 1418 // PlzNavigate: Always set the method to GET when gaining access to the |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 // ComputeReferrerForRedirect). | 1453 // ComputeReferrerForRedirect). |
| 1444 if (!is_navigation_stream_request) { | 1454 if (!is_navigation_stream_request) { |
| 1445 const Referrer referrer( | 1455 const Referrer referrer( |
| 1446 request_data.referrer, request_data.referrer_policy); | 1456 request_data.referrer, request_data.referrer_policy); |
| 1447 SetReferrerForRequest(new_request.get(), referrer); | 1457 SetReferrerForRequest(new_request.get(), referrer); |
| 1448 } | 1458 } |
| 1449 | 1459 |
| 1450 new_request->SetExtraRequestHeaders(headers); | 1460 new_request->SetExtraRequestHeaders(headers); |
| 1451 | 1461 |
| 1452 storage::BlobStorageContext* blob_context = | 1462 storage::BlobStorageContext* blob_context = |
| 1453 GetBlobStorageContext(filter_->blob_storage_context()); | 1463 GetBlobStorageContext(requester_info->blob_storage_context()); |
| 1454 // Resolve elements from request_body and prepare upload data. | 1464 // Resolve elements from request_body and prepare upload data. |
| 1455 if (request_data.request_body.get()) { | 1465 if (request_data.request_body.get()) { |
| 1456 // |blob_context| could be null when the request is from the plugins because | 1466 // |blob_context| could be null when the request is from the plugins because |
| 1457 // ResourceMessageFilters created in PluginProcessHost don't have the blob | 1467 // ResourceMessageFilters created in PluginProcessHost don't have the blob |
| 1458 // context. | 1468 // context. |
| 1459 if (blob_context) { | 1469 if (blob_context) { |
| 1460 // Attaches the BlobDataHandles to request_body not to free the blobs and | 1470 // Attaches the BlobDataHandles to request_body not to free the blobs and |
| 1461 // any attached shareable files until upload completion. These data will | 1471 // any attached shareable files until upload completion. These data will |
| 1462 // be used in UploadDataStream and ServiceWorkerURLRequestJob. | 1472 // be used in UploadDataStream and ServiceWorkerURLRequestJob. |
| 1463 AttachRequestBodyBlobDataHandles( | 1473 AttachRequestBodyBlobDataHandles( |
| 1464 request_data.request_body.get(), | 1474 request_data.request_body.get(), |
| 1465 blob_context); | 1475 blob_context); |
| 1466 } | 1476 } |
| 1467 new_request->set_upload(UploadDataStreamBuilder::Build( | 1477 new_request->set_upload(UploadDataStreamBuilder::Build( |
| 1468 request_data.request_body.get(), blob_context, | 1478 request_data.request_body.get(), blob_context, |
| 1469 filter_->file_system_context(), | 1479 requester_info->file_system_context(), |
| 1470 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); | 1480 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); |
| 1471 } | 1481 } |
| 1472 | 1482 |
| 1473 bool allow_download = request_data.allow_download && | 1483 bool allow_download = request_data.allow_download && |
| 1474 IsResourceTypeFrame(request_data.resource_type); | 1484 IsResourceTypeFrame(request_data.resource_type); |
| 1475 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login; | 1485 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login; |
| 1476 bool is_sync_load = !!sync_result_handler; | 1486 bool is_sync_load = !!sync_result_handler; |
| 1477 | 1487 |
| 1478 // Raw headers are sensitive, as they include Cookie/Set-Cookie, so only | 1488 // Raw headers are sensitive, as they include Cookie/Set-Cookie, so only |
| 1479 // allow requesting them if requester has ReadRawCookies permission. | 1489 // allow requesting them if requester has ReadRawCookies permission. |
| 1480 ChildProcessSecurityPolicyImpl* policy = | 1490 ChildProcessSecurityPolicyImpl* policy = |
| 1481 ChildProcessSecurityPolicyImpl::GetInstance(); | 1491 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 1482 bool report_raw_headers = request_data.report_raw_headers; | 1492 bool report_raw_headers = request_data.report_raw_headers; |
| 1483 if (report_raw_headers && !policy->CanReadRawCookies(child_id)) { | 1493 if (report_raw_headers && !policy->CanReadRawCookies(child_id)) { |
| 1484 // TODO: crbug.com/523063 can we call bad_message::ReceivedBadMessage here? | 1494 // TODO: crbug.com/523063 can we call bad_message::ReceivedBadMessage here? |
| 1485 VLOG(1) << "Denied unauthorized request for raw headers"; | 1495 VLOG(1) << "Denied unauthorized request for raw headers"; |
| 1486 report_raw_headers = false; | 1496 report_raw_headers = false; |
| 1487 } | 1497 } |
| 1488 int load_flags = | 1498 int load_flags = BuildLoadFlagsForRequest(request_data, is_sync_load); |
| 1489 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); | |
| 1490 if (request_data.resource_type == RESOURCE_TYPE_PREFETCH || | 1499 if (request_data.resource_type == RESOURCE_TYPE_PREFETCH || |
| 1491 request_data.resource_type == RESOURCE_TYPE_FAVICON) { | 1500 request_data.resource_type == RESOURCE_TYPE_FAVICON) { |
| 1492 do_not_prompt_for_login = true; | 1501 do_not_prompt_for_login = true; |
| 1493 } | 1502 } |
| 1494 if (request_data.resource_type == RESOURCE_TYPE_IMAGE && | 1503 if (request_data.resource_type == RESOURCE_TYPE_IMAGE && |
| 1495 HTTP_AUTH_RELATION_BLOCKED_CROSS == | 1504 HTTP_AUTH_RELATION_BLOCKED_CROSS == |
| 1496 HttpAuthRelationTypeOf(request_data.url, | 1505 HttpAuthRelationTypeOf(request_data.url, |
| 1497 request_data.first_party_for_cookies)) { | 1506 request_data.first_party_for_cookies)) { |
| 1498 // Prevent third-party image content from prompting for login, as this | 1507 // Prevent third-party image content from prompting for login, as this |
| 1499 // is often a scam to extract credentials for another domain from the user. | 1508 // is often a scam to extract credentials for another domain from the user. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1519 if (is_sync_load) { | 1528 if (is_sync_load) { |
| 1520 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); | 1529 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); |
| 1521 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1530 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
| 1522 } else { | 1531 } else { |
| 1523 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1532 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
| 1524 } | 1533 } |
| 1525 new_request->SetLoadFlags(load_flags); | 1534 new_request->SetLoadFlags(load_flags); |
| 1526 | 1535 |
| 1527 // Make extra info and read footer (contains request ID). | 1536 // Make extra info and read footer (contains request ID). |
| 1528 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( | 1537 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( |
| 1529 process_type, child_id, route_id, | 1538 requester_info, route_id, |
| 1530 -1, // frame_tree_node_id | 1539 -1, // frame_tree_node_id |
| 1531 request_data.origin_pid, request_id, request_data.render_frame_id, | 1540 request_data.origin_pid, request_id, request_data.render_frame_id, |
| 1532 request_data.is_main_frame, request_data.parent_is_main_frame, | 1541 request_data.is_main_frame, request_data.parent_is_main_frame, |
| 1533 request_data.resource_type, request_data.transition_type, | 1542 request_data.resource_type, request_data.transition_type, |
| 1534 request_data.should_replace_current_entry, | 1543 request_data.should_replace_current_entry, |
| 1535 false, // is download | 1544 false, // is download |
| 1536 false, // is stream | 1545 false, // is stream |
| 1537 allow_download, request_data.has_user_gesture, | 1546 allow_download, request_data.has_user_gesture, |
| 1538 request_data.enable_load_timing, request_data.enable_upload_progress, | 1547 request_data.enable_load_timing, request_data.enable_upload_progress, |
| 1539 do_not_prompt_for_login, request_data.referrer_policy, | 1548 do_not_prompt_for_login, request_data.referrer_policy, |
| 1540 request_data.visibility_state, resource_context, filter_->GetWeakPtr(), | 1549 request_data.visibility_state, resource_context, report_raw_headers, |
| 1541 report_raw_headers, !is_sync_load, | 1550 !is_sync_load, |
| 1542 IsUsingLoFi(request_data.lofi_state, delegate_, *new_request, | 1551 IsUsingLoFi(request_data.lofi_state, delegate_, *new_request, |
| 1543 resource_context, | 1552 resource_context, |
| 1544 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), | 1553 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), |
| 1545 support_async_revalidation ? request_data.headers : std::string(), | 1554 support_async_revalidation ? request_data.headers : std::string(), |
| 1546 request_data.request_body, request_data.initiated_in_secure_context); | 1555 request_data.request_body, request_data.initiated_in_secure_context); |
| 1547 // Request takes ownership. | 1556 // Request takes ownership. |
| 1548 extra_info->AssociateWithRequest(new_request.get()); | 1557 extra_info->AssociateWithRequest(new_request.get()); |
| 1549 | 1558 |
| 1550 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1559 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
| 1551 // Hang on to a reference to ensure the blob is not released prior | 1560 // Hang on to a reference to ensure the blob is not released prior |
| 1552 // to the job being started. | 1561 // to the job being started. |
| 1553 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1562 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
| 1554 new_request.get(), | 1563 new_request.get(), requester_info->blob_storage_context() |
| 1555 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( | 1564 ->context() |
| 1556 new_request->url())); | 1565 ->GetBlobDataFromPublicURL(new_request->url())); |
| 1557 } | 1566 } |
| 1558 | 1567 |
| 1559 // Initialize the service worker handler for the request. We don't use | 1568 // Initialize the service worker handler for the request. We don't use |
| 1560 // ServiceWorker for synchronous loads to avoid renderer deadlocks. | 1569 // ServiceWorker for synchronous loads to avoid renderer deadlocks. |
| 1561 const SkipServiceWorker should_skip_service_worker = | 1570 const SkipServiceWorker should_skip_service_worker = |
| 1562 is_sync_load ? SkipServiceWorker::ALL : request_data.skip_service_worker; | 1571 is_sync_load ? SkipServiceWorker::ALL : request_data.skip_service_worker; |
| 1563 ServiceWorkerRequestHandler::InitializeHandler( | 1572 ServiceWorkerRequestHandler::InitializeHandler( |
| 1564 new_request.get(), filter_->service_worker_context(), blob_context, | 1573 new_request.get(), requester_info->service_worker_context(), blob_context, |
| 1565 child_id, request_data.service_worker_provider_id, | 1574 child_id, request_data.service_worker_provider_id, |
| 1566 should_skip_service_worker != SkipServiceWorker::NONE, | 1575 should_skip_service_worker != SkipServiceWorker::NONE, |
| 1567 request_data.fetch_request_mode, request_data.fetch_credentials_mode, | 1576 request_data.fetch_request_mode, request_data.fetch_credentials_mode, |
| 1568 request_data.fetch_redirect_mode, request_data.resource_type, | 1577 request_data.fetch_redirect_mode, request_data.resource_type, |
| 1569 request_data.fetch_request_context_type, request_data.fetch_frame_type, | 1578 request_data.fetch_request_context_type, request_data.fetch_frame_type, |
| 1570 request_data.request_body); | 1579 request_data.request_body); |
| 1571 | 1580 |
| 1572 ForeignFetchRequestHandler::InitializeHandler( | 1581 ForeignFetchRequestHandler::InitializeHandler( |
| 1573 new_request.get(), filter_->service_worker_context(), blob_context, | 1582 new_request.get(), requester_info->service_worker_context(), blob_context, |
| 1574 child_id, request_data.service_worker_provider_id, | 1583 child_id, request_data.service_worker_provider_id, |
| 1575 should_skip_service_worker, request_data.fetch_request_mode, | 1584 should_skip_service_worker, request_data.fetch_request_mode, |
| 1576 request_data.fetch_credentials_mode, request_data.fetch_redirect_mode, | 1585 request_data.fetch_credentials_mode, request_data.fetch_redirect_mode, |
| 1577 request_data.resource_type, request_data.fetch_request_context_type, | 1586 request_data.resource_type, request_data.fetch_request_context_type, |
| 1578 request_data.fetch_frame_type, request_data.request_body, | 1587 request_data.fetch_frame_type, request_data.request_body, |
| 1579 request_data.initiated_in_secure_context); | 1588 request_data.initiated_in_secure_context); |
| 1580 | 1589 |
| 1581 // Have the appcache associate its extra info with the request. | 1590 // Have the appcache associate its extra info with the request. |
| 1582 AppCacheInterceptor::SetExtraRequestInfo( | 1591 AppCacheInterceptor::SetExtraRequestInfo( |
| 1583 new_request.get(), filter_->appcache_service(), child_id, | 1592 new_request.get(), requester_info->appcache_service(), child_id, |
| 1584 request_data.appcache_host_id, request_data.resource_type, | 1593 request_data.appcache_host_id, request_data.resource_type, |
| 1585 request_data.should_reset_appcache); | 1594 request_data.should_reset_appcache); |
| 1586 | 1595 |
| 1587 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1596 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
| 1588 new_request.get(), request_data, sync_result_handler, route_id, | 1597 requester_info.get(), new_request.get(), request_data, |
| 1589 process_type, child_id, resource_context, std::move(mojo_request), | 1598 sync_result_handler, route_id, child_id, resource_context, |
| 1590 std::move(url_loader_client))); | 1599 std::move(mojo_request), std::move(url_loader_client))); |
| 1591 | 1600 |
| 1592 if (handler) | 1601 if (handler) |
| 1593 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1602 BeginRequestInternal(std::move(new_request), std::move(handler)); |
| 1594 } | 1603 } |
| 1595 | 1604 |
| 1596 std::unique_ptr<ResourceHandler> | 1605 std::unique_ptr<ResourceHandler> |
| 1597 ResourceDispatcherHostImpl::CreateResourceHandler( | 1606 ResourceDispatcherHostImpl::CreateResourceHandler( |
| 1607 ResourceRequesterInfo* requester_info, |
| 1598 net::URLRequest* request, | 1608 net::URLRequest* request, |
| 1599 const ResourceRequest& request_data, | 1609 const ResourceRequest& request_data, |
| 1600 const SyncLoadResultCallback& sync_result_handler, | 1610 const SyncLoadResultCallback& sync_result_handler, |
| 1601 int route_id, | 1611 int route_id, |
| 1602 int process_type, | |
| 1603 int child_id, | 1612 int child_id, |
| 1604 ResourceContext* resource_context, | 1613 ResourceContext* resource_context, |
| 1605 mojom::URLLoaderAssociatedRequest mojo_request, | 1614 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1606 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1615 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1616 DCHECK(requester_info->IsRenderer()); |
| 1607 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1617 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1608 tracked_objects::ScopedTracker tracking_profile( | 1618 tracked_objects::ScopedTracker tracking_profile( |
| 1609 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1619 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1610 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1620 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
| 1611 // Construct the IPC resource handler. | 1621 // Construct the IPC resource handler. |
| 1612 std::unique_ptr<ResourceHandler> handler; | 1622 std::unique_ptr<ResourceHandler> handler; |
| 1613 if (sync_result_handler) { | 1623 if (sync_result_handler) { |
| 1614 // download_to_file is not supported for synchronous requests. | 1624 // download_to_file is not supported for synchronous requests. |
| 1615 if (request_data.download_to_file) { | 1625 if (request_data.download_to_file) { |
| 1616 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1626 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1627 bad_message::RDH_BAD_DOWNLOAD); |
| 1617 return std::unique_ptr<ResourceHandler>(); | 1628 return std::unique_ptr<ResourceHandler>(); |
| 1618 } | 1629 } |
| 1619 | 1630 |
| 1620 DCHECK(!mojo_request.is_pending()); | 1631 DCHECK(!mojo_request.is_pending()); |
| 1621 DCHECK(!url_loader_client); | 1632 DCHECK(!url_loader_client); |
| 1622 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); | 1633 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); |
| 1623 } else { | 1634 } else { |
| 1624 if (mojo_request.is_pending()) { | 1635 if (mojo_request.is_pending()) { |
| 1625 handler.reset(new MojoAsyncResourceHandler(request, this, | 1636 handler.reset(new MojoAsyncResourceHandler(request, this, |
| 1626 std::move(mojo_request), | 1637 std::move(mojo_request), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1645 std::unique_ptr<DetachableResourceHandler> detachable_handler = | 1656 std::unique_ptr<DetachableResourceHandler> detachable_handler = |
| 1646 base::MakeUnique<DetachableResourceHandler>( | 1657 base::MakeUnique<DetachableResourceHandler>( |
| 1647 request, | 1658 request, |
| 1648 base::TimeDelta::FromMilliseconds(kDefaultDetachableCancelDelayMs), | 1659 base::TimeDelta::FromMilliseconds(kDefaultDetachableCancelDelayMs), |
| 1649 std::move(handler)); | 1660 std::move(handler)); |
| 1650 if (start_detached) | 1661 if (start_detached) |
| 1651 detachable_handler->Detach(); | 1662 detachable_handler->Detach(); |
| 1652 handler = std::move(detachable_handler); | 1663 handler = std::move(detachable_handler); |
| 1653 } | 1664 } |
| 1654 | 1665 |
| 1655 return AddStandardHandlers( | 1666 // PlzNavigate: do not add ResourceThrottles for main resource requests from |
| 1656 request, request_data.resource_type, resource_context, | 1667 // the renderer. Decisions about the navigation should have been done in the |
| 1657 request_data.fetch_request_context_type, filter_->appcache_service(), | 1668 // initial request. |
| 1658 child_id, route_id, std::move(handler)); | 1669 if (IsBrowserSideNavigationEnabled() && |
| 1670 IsResourceTypeFrame(request_data.resource_type)) { |
| 1671 DCHECK(request->url().SchemeIs(url::kBlobScheme)); |
| 1672 return handler; |
| 1673 } |
| 1674 |
| 1675 return AddStandardHandlers(request, request_data.resource_type, |
| 1676 resource_context, |
| 1677 request_data.fetch_request_context_type, |
| 1678 requester_info->appcache_service(), child_id, |
| 1679 route_id, std::move(handler)); |
| 1659 } | 1680 } |
| 1660 | 1681 |
| 1661 std::unique_ptr<ResourceHandler> | 1682 std::unique_ptr<ResourceHandler> |
| 1662 ResourceDispatcherHostImpl::AddStandardHandlers( | 1683 ResourceDispatcherHostImpl::AddStandardHandlers( |
| 1663 net::URLRequest* request, | 1684 net::URLRequest* request, |
| 1664 ResourceType resource_type, | 1685 ResourceType resource_type, |
| 1665 ResourceContext* resource_context, | 1686 ResourceContext* resource_context, |
| 1666 RequestContextType fetch_request_context_type, | 1687 RequestContextType fetch_request_context_type, |
| 1667 AppCacheService* appcache_service, | 1688 AppCacheService* appcache_service, |
| 1668 int child_id, | 1689 int child_id, |
| 1669 int route_id, | 1690 int route_id, |
| 1670 std::unique_ptr<ResourceHandler> handler) { | 1691 std::unique_ptr<ResourceHandler> handler) { |
| 1671 // PlzNavigate: do not add ResourceThrottles for main resource requests from | |
| 1672 // the renderer. Decisions about the navigation should have been done in the | |
| 1673 // initial request. | |
| 1674 bool is_renderer = | |
| 1675 filter_ ? (filter_->process_type() == PROCESS_TYPE_RENDERER) : false; | |
| 1676 if (is_renderer && IsBrowserSideNavigationEnabled() && | |
| 1677 IsResourceTypeFrame(resource_type)) { | |
| 1678 DCHECK(request->url().SchemeIs(url::kBlobScheme)); | |
| 1679 return handler; | |
| 1680 } | |
| 1681 | |
| 1682 // The InterceptingResourceHandler will replace its next handler with an | 1692 // The InterceptingResourceHandler will replace its next handler with an |
| 1683 // appropriate one based on the MIME type of the response if needed. It | 1693 // appropriate one based on the MIME type of the response if needed. It |
| 1684 // should be placed at the end of the chain, just before |handler|. | 1694 // should be placed at the end of the chain, just before |handler|. |
| 1685 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); | 1695 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); |
| 1686 InterceptingResourceHandler* intercepting_handler = | 1696 InterceptingResourceHandler* intercepting_handler = |
| 1687 static_cast<InterceptingResourceHandler*>(handler.get()); | 1697 static_cast<InterceptingResourceHandler*>(handler.get()); |
| 1688 | 1698 |
| 1689 ScopedVector<ResourceThrottle> throttles; | 1699 ScopedVector<ResourceThrottle> throttles; |
| 1690 | 1700 |
| 1691 // Add a NavigationResourceThrottle for navigations. | 1701 // Add a NavigationResourceThrottle for navigations. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 std::move(handler), this, plugin_service, intercepting_handler, request, | 1759 std::move(handler), this, plugin_service, intercepting_handler, request, |
| 1750 fetch_request_context_type)); | 1760 fetch_request_context_type)); |
| 1751 | 1761 |
| 1752 // Add the pre mime sniffing throttles. | 1762 // Add the pre mime sniffing throttles. |
| 1753 handler.reset(new ThrottlingResourceHandler( | 1763 handler.reset(new ThrottlingResourceHandler( |
| 1754 std::move(handler), request, std::move(pre_mime_sniffing_throttles))); | 1764 std::move(handler), request, std::move(pre_mime_sniffing_throttles))); |
| 1755 | 1765 |
| 1756 return handler; | 1766 return handler; |
| 1757 } | 1767 } |
| 1758 | 1768 |
| 1759 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { | 1769 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile( |
| 1760 UnregisterDownloadedTempFile(filter_->child_id(), request_id); | 1770 ResourceRequesterInfo* requester_info, |
| 1771 int request_id) { |
| 1772 UnregisterDownloadedTempFile(requester_info->child_id(), request_id); |
| 1761 } | 1773 } |
| 1762 | 1774 |
| 1763 void ResourceDispatcherHostImpl::OnDidChangePriority( | 1775 void ResourceDispatcherHostImpl::OnDidChangePriority( |
| 1776 ResourceRequesterInfo* requester_info, |
| 1764 int request_id, | 1777 int request_id, |
| 1765 net::RequestPriority new_priority, | 1778 net::RequestPriority new_priority, |
| 1766 int intra_priority_value) { | 1779 int intra_priority_value) { |
| 1767 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); | 1780 ResourceLoader* loader = GetLoader(requester_info->child_id(), request_id); |
| 1768 // The request may go away before processing this message, so |loader| can | 1781 // The request may go away before processing this message, so |loader| can |
| 1769 // legitimately be null. | 1782 // legitimately be null. |
| 1770 if (!loader) | 1783 if (!loader) |
| 1771 return; | 1784 return; |
| 1772 | 1785 |
| 1773 scheduler_->ReprioritizeRequest(loader->request(), new_priority, | 1786 scheduler_->ReprioritizeRequest(loader->request(), new_priority, |
| 1774 intra_priority_value); | 1787 intra_priority_value); |
| 1775 } | 1788 } |
| 1776 | 1789 |
| 1777 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile( | 1790 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1808 | 1821 |
| 1809 // Note that we don't remove the security bits here. This will be done | 1822 // Note that we don't remove the security bits here. This will be done |
| 1810 // when all file refs are deleted (see RegisterDownloadedTempFile). | 1823 // when all file refs are deleted (see RegisterDownloadedTempFile). |
| 1811 } | 1824 } |
| 1812 | 1825 |
| 1813 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { | 1826 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { |
| 1814 delete message; | 1827 delete message; |
| 1815 return false; | 1828 return false; |
| 1816 } | 1829 } |
| 1817 | 1830 |
| 1818 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) { | 1831 void ResourceDispatcherHostImpl::OnCancelRequest( |
| 1819 CancelRequestFromRenderer(GlobalRequestID(filter_->child_id(), request_id)); | 1832 ResourceRequesterInfo* requester_info, |
| 1833 int request_id) { |
| 1834 CancelRequestFromRenderer( |
| 1835 GlobalRequestID(requester_info->child_id(), request_id)); |
| 1820 } | 1836 } |
| 1821 | 1837 |
| 1822 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( | 1838 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( |
| 1823 int child_id, | 1839 int child_id, |
| 1824 int render_view_route_id, | 1840 int render_view_route_id, |
| 1825 int render_frame_route_id, | 1841 int render_frame_route_id, |
| 1826 bool download, | 1842 bool download, |
| 1827 ResourceContext* context) { | 1843 ResourceContext* context) { |
| 1828 return new ResourceRequestInfoImpl( | 1844 return new ResourceRequestInfoImpl( |
| 1829 PROCESS_TYPE_RENDERER, child_id, render_view_route_id, | 1845 ResourceRequesterInfo::CreateForDownloadOrPageSave(child_id), |
| 1846 render_view_route_id, |
| 1830 -1, // frame_tree_node_id | 1847 -1, // frame_tree_node_id |
| 1831 0, MakeRequestID(), render_frame_route_id, | 1848 0, MakeRequestID(), render_frame_route_id, |
| 1832 false, // is_main_frame | 1849 false, // is_main_frame |
| 1833 false, // parent_is_main_frame | 1850 false, // parent_is_main_frame |
| 1834 RESOURCE_TYPE_SUB_RESOURCE, ui::PAGE_TRANSITION_LINK, | 1851 RESOURCE_TYPE_SUB_RESOURCE, ui::PAGE_TRANSITION_LINK, |
| 1835 false, // should_replace_current_entry | 1852 false, // should_replace_current_entry |
| 1836 download, // is_download | 1853 download, // is_download |
| 1837 false, // is_stream | 1854 false, // is_stream |
| 1838 download, // allow_download | 1855 download, // allow_download |
| 1839 false, // has_user_gesture | 1856 false, // has_user_gesture |
| 1840 false, // enable_load_timing | 1857 false, // enable_load_timing |
| 1841 false, // enable_upload_progress | 1858 false, // enable_upload_progress |
| 1842 false, // do_not_prompt_for_login | 1859 false, // do_not_prompt_for_login |
| 1843 blink::WebReferrerPolicyDefault, blink::WebPageVisibilityStateVisible, | 1860 blink::WebReferrerPolicyDefault, blink::WebPageVisibilityStateVisible, |
| 1844 context, | 1861 context, |
| 1845 base::WeakPtr<ResourceMessageFilter>(), // filter | 1862 false, // report_raw_headers |
| 1846 false, // report_raw_headers | 1863 true, // is_async |
| 1847 true, // is_async | 1864 false, // is_using_lofi |
| 1848 false, // is_using_lofi | 1865 std::string(), // original_headers |
| 1849 std::string(), // original_headers | 1866 nullptr, // body |
| 1850 nullptr, // body | 1867 false); // initiated_in_secure_context |
| 1851 false); // initiated_in_secure_context | |
| 1852 } | 1868 } |
| 1853 | 1869 |
| 1854 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1870 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
| 1855 int route_id) { | 1871 int route_id) { |
| 1856 scheduler_->OnClientCreated(child_id, route_id); | 1872 scheduler_->OnClientCreated(child_id, route_id); |
| 1857 } | 1873 } |
| 1858 | 1874 |
| 1859 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, | 1875 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, |
| 1860 int route_id) { | 1876 int route_id) { |
| 1861 scheduler_->OnClientDeleted(child_id, route_id); | 1877 scheduler_->OnClientDeleted(child_id, route_id); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2181 body, blob_context, | 2197 body, blob_context, |
| 2182 nullptr, // file_system_context | 2198 nullptr, // file_system_context |
| 2183 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); | 2199 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); |
| 2184 } | 2200 } |
| 2185 | 2201 |
| 2186 // Make extra info and read footer (contains request ID). | 2202 // Make extra info and read footer (contains request ID). |
| 2187 // | 2203 // |
| 2188 // TODO(davidben): Associate the request with the FrameTreeNode and/or tab so | 2204 // TODO(davidben): Associate the request with the FrameTreeNode and/or tab so |
| 2189 // that IO thread -> UI thread hops will work. | 2205 // that IO thread -> UI thread hops will work. |
| 2190 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( | 2206 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( |
| 2191 PROCESS_TYPE_BROWSER, | 2207 ResourceRequesterInfo::CreateForBrowserSideNavigation( |
| 2192 -1, // child_id | 2208 service_worker_handle_core |
| 2209 ? service_worker_handle_core->context_wrapper() |
| 2210 : scoped_refptr<ServiceWorkerContextWrapper>()), |
| 2193 -1, // route_id | 2211 -1, // route_id |
| 2194 info.frame_tree_node_id, | 2212 info.frame_tree_node_id, |
| 2195 -1, // request_data.origin_pid, | 2213 -1, // request_data.origin_pid, |
| 2196 MakeRequestID(), | 2214 MakeRequestID(), |
| 2197 -1, // request_data.render_frame_id, | 2215 -1, // request_data.render_frame_id, |
| 2198 info.is_main_frame, info.parent_is_main_frame, resource_type, | 2216 info.is_main_frame, info.parent_is_main_frame, resource_type, |
| 2199 info.common_params.transition, | 2217 info.common_params.transition, |
| 2200 // should_replace_current_entry. This was only maintained at layer for | 2218 // should_replace_current_entry. This was only maintained at layer for |
| 2201 // request transfers and isn't needed for browser-side navigations. | 2219 // request transfers and isn't needed for browser-side navigations. |
| 2202 false, | 2220 false, |
| 2203 false, // is download | 2221 false, // is download |
| 2204 false, // is stream | 2222 false, // is stream |
| 2205 info.common_params.allow_download, info.begin_params.has_user_gesture, | 2223 info.common_params.allow_download, info.begin_params.has_user_gesture, |
| 2206 true, // enable_load_timing | 2224 true, // enable_load_timing |
| 2207 false, // enable_upload_progress | 2225 false, // enable_upload_progress |
| 2208 false, // do_not_prompt_for_login | 2226 false, // do_not_prompt_for_login |
| 2209 info.common_params.referrer.policy, | 2227 info.common_params.referrer.policy, |
| 2210 // TODO(davidben): This is only used for prerenders. Replace | 2228 // TODO(davidben): This is only used for prerenders. Replace |
| 2211 // is_showing with something for that. Or maybe it just comes from the | 2229 // is_showing with something for that. Or maybe it just comes from the |
| 2212 // same mechanism as the cookie one. | 2230 // same mechanism as the cookie one. |
| 2213 blink::WebPageVisibilityStateVisible, resource_context, | 2231 blink::WebPageVisibilityStateVisible, resource_context, |
| 2214 base::WeakPtr<ResourceMessageFilter>(), // filter | |
| 2215 info.report_raw_headers, | 2232 info.report_raw_headers, |
| 2216 true, // is_async | 2233 true, // is_async |
| 2217 IsUsingLoFi(info.common_params.lofi_state, delegate_, *new_request, | 2234 IsUsingLoFi(info.common_params.lofi_state, delegate_, *new_request, |
| 2218 resource_context, info.is_main_frame), | 2235 resource_context, info.is_main_frame), |
| 2219 // The original_headers field is for stale-while-revalidate but the | 2236 // The original_headers field is for stale-while-revalidate but the |
| 2220 // feature doesn't work with PlzNavigate, so it's just a placeholder | 2237 // feature doesn't work with PlzNavigate, so it's just a placeholder |
| 2221 // here. | 2238 // here. |
| 2222 // TODO(ricea): Make the feature work with stale-while-revalidate | 2239 // TODO(ricea): Make the feature work with stale-while-revalidate |
| 2223 // and clean this up. | 2240 // and clean this up. |
| 2224 std::string(), // original_headers | 2241 std::string(), // original_headers |
| 2225 info.common_params.post_data, | 2242 info.common_params.post_data, |
| 2226 // TODO(mek): Currently initiated_in_secure_context is only used for | 2243 // TODO(mek): Currently initiated_in_secure_context is only used for |
| 2227 // subresource requests, so it doesn't matter what value it gets here. | 2244 // subresource requests, so it doesn't matter what value it gets here. |
| 2228 // If in the future this changes this should be updated to somehow get a | 2245 // If in the future this changes this should be updated to somehow get a |
| 2229 // meaningful value. | 2246 // meaningful value. |
| 2230 false); // initiated_in_secure_context | 2247 false); // initiated_in_secure_context |
| 2231 extra_info->set_navigation_ui_data(std::move(navigation_ui_data)); | 2248 extra_info->set_navigation_ui_data(std::move(navigation_ui_data)); |
| 2232 | 2249 |
| 2233 if (service_worker_handle_core) { | |
| 2234 extra_info->set_service_worker_context( | |
| 2235 service_worker_handle_core->context_wrapper()); | |
| 2236 } | |
| 2237 | |
| 2238 // Request takes ownership. | 2250 // Request takes ownership. |
| 2239 extra_info->AssociateWithRequest(new_request.get()); | 2251 extra_info->AssociateWithRequest(new_request.get()); |
| 2240 | 2252 |
| 2241 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 2253 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
| 2242 // Hang on to a reference to ensure the blob is not released prior | 2254 // Hang on to a reference to ensure the blob is not released prior |
| 2243 // to the job being started. | 2255 // to the job being started. |
| 2244 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 2256 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
| 2245 new_request.get(), | 2257 new_request.get(), |
| 2246 blob_context->GetBlobDataFromPublicURL(new_request->url())); | 2258 blob_context->GetBlobDataFromPublicURL(new_request->url())); |
| 2247 } | 2259 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2283 LoaderDelegate* loader_delegate) { | 2295 LoaderDelegate* loader_delegate) { |
| 2284 loader_delegate_ = loader_delegate; | 2296 loader_delegate_ = loader_delegate; |
| 2285 } | 2297 } |
| 2286 | 2298 |
| 2287 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( | 2299 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( |
| 2288 const GlobalFrameRoutingId& global_routing_id) { | 2300 const GlobalFrameRoutingId& global_routing_id) { |
| 2289 CancelRequestsForRoute(global_routing_id); | 2301 CancelRequestsForRoute(global_routing_id); |
| 2290 } | 2302 } |
| 2291 | 2303 |
| 2292 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( | 2304 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( |
| 2305 ResourceRequesterInfo* requester_info, |
| 2293 int routing_id, | 2306 int routing_id, |
| 2294 int request_id, | 2307 int request_id, |
| 2295 const ResourceRequest& request, | 2308 const ResourceRequest& request, |
| 2296 mojom::URLLoaderAssociatedRequest mojo_request, | 2309 mojom::URLLoaderAssociatedRequest mojo_request, |
| 2297 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 2310 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 2298 ResourceMessageFilter* filter) { | 2311 OnRequestResourceInternal(requester_info, routing_id, request_id, request, |
| 2299 filter_ = filter; | |
| 2300 OnRequestResourceInternal(routing_id, request_id, request, | |
| 2301 std::move(mojo_request), | 2312 std::move(mojo_request), |
| 2302 std::move(url_loader_client)); | 2313 std::move(url_loader_client)); |
| 2303 filter_ = nullptr; | |
| 2304 } | 2314 } |
| 2305 | 2315 |
| 2306 void ResourceDispatcherHostImpl::OnSyncLoadWithMojo( | 2316 void ResourceDispatcherHostImpl::OnSyncLoadWithMojo( |
| 2317 ResourceRequesterInfo* requester_info, |
| 2307 int routing_id, | 2318 int routing_id, |
| 2308 int request_id, | 2319 int request_id, |
| 2309 const ResourceRequest& request_data, | 2320 const ResourceRequest& request_data, |
| 2310 ResourceMessageFilter* filter, | |
| 2311 const SyncLoadResultCallback& result_handler) { | 2321 const SyncLoadResultCallback& result_handler) { |
| 2312 filter_ = filter; | 2322 BeginRequest(requester_info, request_id, request_data, result_handler, |
| 2313 BeginRequest(request_id, request_data, result_handler, routing_id, | 2323 routing_id, nullptr, nullptr); |
| 2314 nullptr, nullptr); | |
| 2315 filter_ = nullptr; | |
| 2316 } | 2324 } |
| 2317 | 2325 |
| 2318 // static | 2326 // static |
| 2319 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2327 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
| 2320 net::URLRequest* request) { | 2328 net::URLRequest* request) { |
| 2321 // The following fields should be a minor size contribution (experimentally | 2329 // The following fields should be a minor size contribution (experimentally |
| 2322 // on the order of 100). However since they are variable length, it could | 2330 // on the order of 100). However since they are variable length, it could |
| 2323 // in theory be a sizeable contribution. | 2331 // in theory be a sizeable contribution. |
| 2324 int strings_cost = 0; | 2332 int strings_cost = 0; |
| 2325 for (net::HttpRequestHeaders::Iterator it(request->extra_request_headers()); | 2333 for (net::HttpRequestHeaders::Iterator it(request->extra_request_headers()); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2704 DCHECK(it->second->HasObserver(delegate)); | 2712 DCHECK(it->second->HasObserver(delegate)); |
| 2705 it->second->RemoveObserver(delegate); | 2713 it->second->RemoveObserver(delegate); |
| 2706 if (!it->second->might_have_observers()) { | 2714 if (!it->second->might_have_observers()) { |
| 2707 delete it->second; | 2715 delete it->second; |
| 2708 delegate_map_.erase(it); | 2716 delegate_map_.erase(it); |
| 2709 } | 2717 } |
| 2710 } | 2718 } |
| 2711 | 2719 |
| 2712 int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest( | 2720 int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest( |
| 2713 const ResourceRequest& request_data, | 2721 const ResourceRequest& request_data, |
| 2714 int child_id, | |
| 2715 bool is_sync_load) { | 2722 bool is_sync_load) { |
| 2716 int load_flags = request_data.load_flags; | 2723 int load_flags = request_data.load_flags; |
| 2717 | 2724 |
| 2718 // Although EV status is irrelevant to sub-frames and sub-resources, we have | 2725 // Although EV status is irrelevant to sub-frames and sub-resources, we have |
| 2719 // to perform EV certificate verification on all resources because an HTTP | 2726 // to perform EV certificate verification on all resources because an HTTP |
| 2720 // keep-alive connection created to load a sub-frame or a sub-resource could | 2727 // keep-alive connection created to load a sub-frame or a sub-resource could |
| 2721 // be reused to load a main frame. | 2728 // be reused to load a main frame. |
| 2722 load_flags |= net::LOAD_VERIFY_EV_CERT; | 2729 load_flags |= net::LOAD_VERIFY_EV_CERT; |
| 2723 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { | 2730 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { |
| 2724 load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED; | 2731 load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED; |
| 2725 } else if (request_data.resource_type == RESOURCE_TYPE_PREFETCH) { | 2732 } else if (request_data.resource_type == RESOURCE_TYPE_PREFETCH) { |
| 2726 load_flags |= net::LOAD_PREFETCH; | 2733 load_flags |= net::LOAD_PREFETCH; |
| 2727 } | 2734 } |
| 2728 | 2735 |
| 2729 if (is_sync_load) | 2736 if (is_sync_load) |
| 2730 load_flags |= net::LOAD_IGNORE_LIMITS; | 2737 load_flags |= net::LOAD_IGNORE_LIMITS; |
| 2731 | 2738 |
| 2732 return load_flags; | 2739 return load_flags; |
| 2733 } | 2740 } |
| 2734 | 2741 |
| 2735 bool ResourceDispatcherHostImpl::ShouldServiceRequest( | 2742 bool ResourceDispatcherHostImpl::ShouldServiceRequest( |
| 2736 int process_type, | |
| 2737 int child_id, | 2743 int child_id, |
| 2738 const ResourceRequest& request_data, | 2744 const ResourceRequest& request_data, |
| 2739 const net::HttpRequestHeaders& headers, | 2745 const net::HttpRequestHeaders& headers, |
| 2740 ResourceMessageFilter* filter, | 2746 ResourceRequesterInfo* requester_info, |
| 2741 ResourceContext* resource_context) { | 2747 ResourceContext* resource_context) { |
| 2742 ChildProcessSecurityPolicyImpl* policy = | 2748 ChildProcessSecurityPolicyImpl* policy = |
| 2743 ChildProcessSecurityPolicyImpl::GetInstance(); | 2749 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 2744 | 2750 |
| 2745 // Check if the renderer is permitted to request the requested URL. | 2751 // Check if the renderer is permitted to request the requested URL. |
| 2746 if (!policy->CanRequestURL(child_id, request_data.url)) { | 2752 if (!policy->CanRequestURL(child_id, request_data.url)) { |
| 2747 VLOG(1) << "Denied unauthorized request for " | 2753 VLOG(1) << "Denied unauthorized request for " |
| 2748 << request_data.url.possibly_invalid_spec(); | 2754 << request_data.url.possibly_invalid_spec(); |
| 2749 return false; | 2755 return false; |
| 2750 } | 2756 } |
| 2751 | 2757 |
| 2752 // Check if the renderer is using an illegal Origin header. If so, kill it. | 2758 // Check if the renderer is using an illegal Origin header. If so, kill it. |
| 2753 std::string origin_string; | 2759 std::string origin_string; |
| 2754 bool has_origin = | 2760 bool has_origin = |
| 2755 headers.GetHeader("Origin", &origin_string) && origin_string != "null"; | 2761 headers.GetHeader("Origin", &origin_string) && origin_string != "null"; |
| 2756 if (has_origin) { | 2762 if (has_origin) { |
| 2757 GURL origin(origin_string); | 2763 GURL origin(origin_string); |
| 2758 if (!policy->CanSetAsOriginHeader(child_id, origin)) { | 2764 if (!policy->CanSetAsOriginHeader(child_id, origin)) { |
| 2759 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; | 2765 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; |
| 2760 bad_message::ReceivedBadMessage(filter, bad_message::RDH_ILLEGAL_ORIGIN); | 2766 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 2767 bad_message::RDH_ILLEGAL_ORIGIN); |
| 2761 return false; | 2768 return false; |
| 2762 } | 2769 } |
| 2763 } | 2770 } |
| 2764 | 2771 |
| 2765 // Check if the renderer is permitted to upload the requested files. | 2772 // Check if the renderer is permitted to upload the requested files. |
| 2766 if (request_data.request_body.get()) { | 2773 if (request_data.request_body.get()) { |
| 2767 const std::vector<ResourceRequestBodyImpl::Element>* uploads = | 2774 const std::vector<ResourceRequestBodyImpl::Element>* uploads = |
| 2768 request_data.request_body->elements(); | 2775 request_data.request_body->elements(); |
| 2769 std::vector<ResourceRequestBodyImpl::Element>::const_iterator iter; | 2776 std::vector<ResourceRequestBodyImpl::Element>::const_iterator iter; |
| 2770 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { | 2777 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { |
| 2771 if (iter->type() == ResourceRequestBodyImpl::Element::TYPE_FILE && | 2778 if (iter->type() == ResourceRequestBodyImpl::Element::TYPE_FILE && |
| 2772 !policy->CanReadFile(child_id, iter->path())) { | 2779 !policy->CanReadFile(child_id, iter->path())) { |
| 2773 NOTREACHED() << "Denied unauthorized upload of " | 2780 NOTREACHED() << "Denied unauthorized upload of " |
| 2774 << iter->path().value(); | 2781 << iter->path().value(); |
| 2775 return false; | 2782 return false; |
| 2776 } | 2783 } |
| 2777 if (iter->type() == | 2784 if (iter->type() == |
| 2778 ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { | 2785 ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { |
| 2779 storage::FileSystemURL url = | 2786 storage::FileSystemURL url = |
| 2780 filter->file_system_context()->CrackURL(iter->filesystem_url()); | 2787 requester_info->file_system_context()->CrackURL( |
| 2788 iter->filesystem_url()); |
| 2781 if (!policy->CanReadFileSystemFile(child_id, url)) { | 2789 if (!policy->CanReadFileSystemFile(child_id, url)) { |
| 2782 NOTREACHED() << "Denied unauthorized upload of " | 2790 NOTREACHED() << "Denied unauthorized upload of " |
| 2783 << iter->filesystem_url().spec(); | 2791 << iter->filesystem_url().spec(); |
| 2784 return false; | 2792 return false; |
| 2785 } | 2793 } |
| 2786 } | 2794 } |
| 2787 } | 2795 } |
| 2788 } | 2796 } |
| 2789 return true; | 2797 return true; |
| 2790 } | 2798 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2805 &throttles); | 2813 &throttles); |
| 2806 if (!throttles.empty()) { | 2814 if (!throttles.empty()) { |
| 2807 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2815 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
| 2808 std::move(throttles))); | 2816 std::move(throttles))); |
| 2809 } | 2817 } |
| 2810 } | 2818 } |
| 2811 return handler; | 2819 return handler; |
| 2812 } | 2820 } |
| 2813 | 2821 |
| 2814 } // namespace content | 2822 } // namespace content |
| OLD | NEW |