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

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

Powered by Google App Engine
This is Rietveld 408576698