Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

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

Powered by Google App Engine
This is Rietveld 408576698