Chromium Code Reviews

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

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

Powered by Google App Engine