OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading |
6 | 6 |
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 if (pending_frame_host) | 416 if (pending_frame_host) |
416 routing_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); | 417 routing_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); |
417 } | 418 } |
418 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 419 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
419 base::Bind(&NotifyForRouteSetOnIO, frame_callback, | 420 base::Bind(&NotifyForRouteSetOnIO, frame_callback, |
420 base::Passed(std::move(routing_ids)))); | 421 base::Passed(std::move(routing_ids)))); |
421 } | 422 } |
422 | 423 |
423 // Sends back the result of a synchronous loading result to the renderer through | 424 // Sends back the result of a synchronous loading result to the renderer through |
424 // Chrome IPC. | 425 // Chrome IPC. |
425 void HandleSyncLoadResult(base::WeakPtr<ResourceMessageFilter> filter, | 426 void HandleSyncLoadResult(std::unique_ptr<ResourceRequesterInfo> requester_info, |
426 std::unique_ptr<IPC::Message> sync_result, | 427 std::unique_ptr<IPC::Message> sync_result, |
427 const SyncLoadResult* result) { | 428 const SyncLoadResult* result) { |
428 if (!filter) | 429 DCHECK(requester_info->IsRenderer()); |
430 if (!requester_info->filter()) | |
429 return; | 431 return; |
430 | 432 |
431 if (result) { | 433 if (result) { |
432 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result.get(), *result); | 434 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result.get(), *result); |
433 } else { | 435 } else { |
434 sync_result->set_reply_error(); | 436 sync_result->set_reply_error(); |
435 } | 437 } |
436 filter->Send(sync_result.release()); | 438 requester_info->filter()->Send(sync_result.release()); |
437 } | 439 } |
438 | 440 |
439 } // namespace | 441 } // namespace |
440 | 442 |
441 ResourceDispatcherHostImpl::LoadInfo::LoadInfo() {} | 443 ResourceDispatcherHostImpl::LoadInfo::LoadInfo() {} |
442 ResourceDispatcherHostImpl::LoadInfo::LoadInfo(const LoadInfo& other) = default; | 444 ResourceDispatcherHostImpl::LoadInfo::LoadInfo(const LoadInfo& other) = default; |
443 ResourceDispatcherHostImpl::LoadInfo::~LoadInfo() {} | 445 ResourceDispatcherHostImpl::LoadInfo::~LoadInfo() {} |
444 | 446 |
445 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo() {} | 447 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo() {} |
446 | 448 |
(...skipping 10 matching lines...) Expand all Loading... | |
457 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl( | 459 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl( |
458 CreateDownloadHandlerIntercept download_handler_intercept) | 460 CreateDownloadHandlerIntercept download_handler_intercept) |
459 : request_id_(-1), | 461 : request_id_(-1), |
460 is_shutdown_(false), | 462 is_shutdown_(false), |
461 num_in_flight_requests_(0), | 463 num_in_flight_requests_(0), |
462 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 464 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
463 max_num_in_flight_requests_per_process_(static_cast<int>( | 465 max_num_in_flight_requests_per_process_(static_cast<int>( |
464 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 466 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
465 max_outstanding_requests_cost_per_process_( | 467 max_outstanding_requests_cost_per_process_( |
466 kMaxOutstandingRequestsCostPerProcess), | 468 kMaxOutstandingRequestsCostPerProcess), |
467 filter_(nullptr), | |
468 delegate_(nullptr), | 469 delegate_(nullptr), |
469 loader_delegate_(nullptr), | 470 loader_delegate_(nullptr), |
470 allow_cross_origin_auth_prompt_(false), | 471 allow_cross_origin_auth_prompt_(false), |
471 create_download_handler_intercept_(download_handler_intercept) { | 472 create_download_handler_intercept_(download_handler_intercept) { |
472 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 473 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
473 DCHECK(!g_resource_dispatcher_host); | 474 DCHECK(!g_resource_dispatcher_host); |
474 g_resource_dispatcher_host = this; | 475 g_resource_dispatcher_host = this; |
475 | 476 |
476 ANNOTATE_BENIGN_RACE( | 477 ANNOTATE_BENIGN_RACE( |
477 &last_user_gesture_time_, | 478 &last_user_gesture_time_, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 } | 608 } |
608 | 609 |
609 #ifndef NDEBUG | 610 #ifndef NDEBUG |
610 for (const auto& loader : loaders_to_cancel) { | 611 for (const auto& loader : loaders_to_cancel) { |
611 // There is no strict requirement that this be the case, but currently | 612 // There is no strict requirement that this be the case, but currently |
612 // downloads, streams, detachable requests, transferred requests, and | 613 // downloads, streams, detachable requests, transferred requests, and |
613 // browser-owned requests are the only requests that aren't cancelled when | 614 // 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 | 615 // 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 | 616 // change in the future, but if this assertion fires without the invariant |
616 // changing, then it's indicative of a leak. | 617 // changing, then it's indicative of a leak. |
617 DCHECK(loader->GetRequestInfo()->IsDownload() || | 618 DCHECK( |
618 loader->GetRequestInfo()->is_stream() || | 619 loader->GetRequestInfo()->IsDownload() || |
619 (loader->GetRequestInfo()->detachable_handler() && | 620 loader->GetRequestInfo()->is_stream() || |
620 loader->GetRequestInfo()->detachable_handler()->is_detached()) || | 621 (loader->GetRequestInfo()->detachable_handler() && |
621 loader->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER || | 622 loader->GetRequestInfo()->detachable_handler()->is_detached()) || |
622 loader->is_transferring()); | 623 loader->GetRequestInfo()->requester_info().IsBrowserSideNavigation() || |
624 loader->is_transferring()); | |
623 } | 625 } |
624 #endif | 626 #endif |
625 | 627 |
626 loaders_to_cancel.clear(); | 628 loaders_to_cancel.clear(); |
627 | 629 |
628 if (async_revalidation_manager_) { | 630 if (async_revalidation_manager_) { |
629 // Cancelling async revalidations should not result in the creation of new | 631 // Cancelling async revalidations should not result in the creation of new |
630 // requests. Do it before the CHECKs to ensure this does not happen. | 632 // requests. Do it before the CHECKs to ensure this does not happen. |
631 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( | 633 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( |
632 context); | 634 context); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 CancelBlockedRequestsForRoute(routing_id); | 1002 CancelBlockedRequestsForRoute(routing_id); |
1001 } | 1003 } |
1002 | 1004 |
1003 scheduler_.reset(); | 1005 scheduler_.reset(); |
1004 } | 1006 } |
1005 | 1007 |
1006 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1008 bool ResourceDispatcherHostImpl::OnMessageReceived( |
1007 const IPC::Message& message, | 1009 const IPC::Message& message, |
1008 ResourceMessageFilter* filter) { | 1010 ResourceMessageFilter* filter) { |
1009 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1011 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1010 filter_ = filter; | 1012 requester_info_ = |
1013 ResourceRequesterInfo::CreateForRenderer(filter->GetWeakPtr()); | |
1011 bool handled = true; | 1014 bool handled = true; |
1012 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) | 1015 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
1013 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 1016 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
1014 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) | 1017 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) |
1015 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 1018 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
1016 OnReleaseDownloadedFile) | 1019 OnReleaseDownloadedFile) |
1017 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 1020 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
1018 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) | 1021 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) |
1019 IPC_MESSAGE_UNHANDLED(handled = false) | 1022 IPC_MESSAGE_UNHANDLED(handled = false) |
1020 IPC_END_MESSAGE_MAP() | 1023 IPC_END_MESSAGE_MAP() |
1021 | 1024 |
1022 if (!handled && IPC_MESSAGE_ID_CLASS(message.type()) == ResourceMsgStart) { | 1025 if (!handled && IPC_MESSAGE_ID_CLASS(message.type()) == ResourceMsgStart) { |
1023 base::PickleIterator iter(message); | 1026 base::PickleIterator iter(message); |
1024 int request_id = -1; | 1027 int request_id = -1; |
1025 bool ok = iter.ReadInt(&request_id); | 1028 bool ok = iter.ReadInt(&request_id); |
1026 DCHECK(ok); | 1029 DCHECK(ok); |
1027 GlobalRequestID id(filter_->child_id(), request_id); | 1030 GlobalRequestID id(requester_info_->child_id(), request_id); |
1028 DelegateMap::iterator it = delegate_map_.find(id); | 1031 DelegateMap::iterator it = delegate_map_.find(id); |
1029 if (it != delegate_map_.end()) { | 1032 if (it != delegate_map_.end()) { |
1030 for (auto& delegate : *it->second) { | 1033 for (auto& delegate : *it->second) { |
1031 if (delegate.OnMessageReceived(message)) { | 1034 if (delegate.OnMessageReceived(message)) { |
1032 handled = true; | 1035 handled = true; |
1033 break; | 1036 break; |
1034 } | 1037 } |
1035 } | 1038 } |
1036 } | 1039 } |
1037 | 1040 |
1038 // As the unhandled resource message effectively has no consumer, mark it as | 1041 // As the unhandled resource message effectively has no consumer, mark it as |
1039 // handled to prevent needless propagation through the filter pipeline. | 1042 // handled to prevent needless propagation through the filter pipeline. |
1040 handled = true; | 1043 handled = true; |
1041 } | 1044 } |
1042 | 1045 |
1043 filter_ = NULL; | 1046 requester_info_.reset(); |
1044 return handled; | 1047 return handled; |
1045 } | 1048 } |
1046 | 1049 |
1047 void ResourceDispatcherHostImpl::OnRequestResource( | 1050 void ResourceDispatcherHostImpl::OnRequestResource( |
1048 int routing_id, | 1051 int routing_id, |
1049 int request_id, | 1052 int request_id, |
1050 const ResourceRequest& request_data) { | 1053 const ResourceRequest& request_data) { |
1051 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, | 1054 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, |
1052 nullptr); | 1055 nullptr); |
1053 } | 1056 } |
1054 | 1057 |
1055 void ResourceDispatcherHostImpl::OnRequestResourceInternal( | 1058 void ResourceDispatcherHostImpl::OnRequestResourceInternal( |
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()); | |
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(request_id, request_data, SyncLoadResultCallback(), routing_id, |
1082 std::move(mojo_request), std::move(url_loader_client)); | 1083 std::move(mojo_request), std::move(url_loader_client)); |
1083 } | 1084 } |
1084 | 1085 |
1085 // Begins a resource request with the given params on behalf of the specified | 1086 // 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 | 1087 // 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 | 1088 // 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 | 1089 // a request from a renderer. request_context is the cookie/cache context to be |
1089 // used for this request. | 1090 // used for this request. |
1090 // | 1091 // |
1091 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1092 // 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. | 1093 // a normal asynchronous set of response messages will be generated. |
1093 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, | 1094 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, |
1094 const ResourceRequest& request_data, | 1095 const ResourceRequest& request_data, |
1095 IPC::Message* sync_result) { | 1096 IPC::Message* sync_result) { |
1096 SyncLoadResultCallback callback = base::Bind( | 1097 DCHECK(requester_info_->IsRenderer()); |
1097 &HandleSyncLoadResult, filter_->GetWeakPtr(), | 1098 SyncLoadResultCallback callback = |
1098 base::Passed(WrapUnique(sync_result))); | 1099 base::Bind(&HandleSyncLoadResult, base::Passed(requester_info_->clone()), |
1100 base::Passed(WrapUnique(sync_result))); | |
1099 BeginRequest(request_id, request_data, callback, sync_result->routing_id(), | 1101 BeginRequest(request_id, request_data, callback, sync_result->routing_id(), |
1100 nullptr, nullptr); | 1102 nullptr, nullptr); |
1101 } | 1103 } |
1102 | 1104 |
1103 bool ResourceDispatcherHostImpl::IsRequestIDInUse( | 1105 bool ResourceDispatcherHostImpl::IsRequestIDInUse( |
1104 const GlobalRequestID& id) const { | 1106 const GlobalRequestID& id) const { |
1105 if (pending_loaders_.find(id) != pending_loaders_.end()) | 1107 if (pending_loaders_.find(id) != pending_loaders_.end()) |
1106 return true; | 1108 return true; |
1107 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1109 for (const auto& blocked_loaders : blocked_loaders_map_) { |
1108 for (const auto& loader : *blocked_loaders.second.get()) { | 1110 for (const auto& loader : *blocked_loaders.second.get()) { |
1109 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1111 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
1110 if (info->GetGlobalRequestID() == id) | 1112 if (info->GetGlobalRequestID() == id) |
1111 return true; | 1113 return true; |
1112 } | 1114 } |
1113 } | 1115 } |
1114 return false; | 1116 return false; |
1115 } | 1117 } |
1116 | 1118 |
1117 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( | 1119 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
1118 int child_id, | 1120 int child_id, |
1119 int route_id, | 1121 int route_id, |
1120 int request_id, | 1122 int request_id, |
1121 const ResourceRequest& request_data, | 1123 const ResourceRequest& request_data, |
1122 LoaderMap::iterator iter) { | 1124 LoaderMap::iterator iter) { |
1125 DCHECK(requester_info_->IsRenderer()); | |
1123 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); | 1126 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); |
1124 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, | 1127 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
1125 info->GetRenderFrameID()); | 1128 info->GetRenderFrameID()); |
1126 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1129 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
1127 request_data.transferred_request_request_id); | 1130 request_data.transferred_request_request_id); |
1128 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); | 1131 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
1129 GlobalRequestID new_request_id(child_id, request_id); | 1132 GlobalRequestID new_request_id(child_id, request_id); |
1130 | 1133 |
1131 // Clear out data that depends on |info| before updating it. | 1134 // 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, | 1135 // 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 | 1136 // stats.num_requests is only tracked for some requests (those that require |
1134 // file descriptors for their shared memory buffer). | 1137 // file descriptors for their shared memory buffer). |
1135 IncrementOutstandingRequestsMemory(-1, *info); | 1138 IncrementOutstandingRequestsMemory(-1, *info); |
1136 bool should_update_count = info->counted_as_in_flight_request(); | 1139 bool should_update_count = info->counted_as_in_flight_request(); |
1137 if (should_update_count) | 1140 if (should_update_count) |
1138 IncrementOutstandingRequestsCount(-1, info); | 1141 IncrementOutstandingRequestsCount(-1, info); |
1139 | 1142 |
1140 DCHECK(pending_loaders_.find(old_request_id) == iter); | 1143 DCHECK(pending_loaders_.find(old_request_id) == iter); |
1141 std::unique_ptr<ResourceLoader> loader = std::move(iter->second); | 1144 std::unique_ptr<ResourceLoader> loader = std::move(iter->second); |
1142 ResourceLoader* loader_ptr = loader.get(); | 1145 ResourceLoader* loader_ptr = loader.get(); |
1143 pending_loaders_.erase(iter); | 1146 pending_loaders_.erase(iter); |
1144 | 1147 |
1145 // ResourceHandlers should always get state related to the request from the | 1148 // ResourceHandlers should always get state related to the request from the |
1146 // ResourceRequestInfo rather than caching it locally. This lets us update | 1149 // ResourceRequestInfo rather than caching it locally. This lets us update |
1147 // the info object when a transfer occurs. | 1150 // the info object when a transfer occurs. |
1148 info->UpdateForTransfer(child_id, route_id, request_data.render_frame_id, | 1151 info->UpdateForTransfer(route_id, request_data.render_frame_id, |
1149 request_data.origin_pid, request_id, | 1152 request_data.origin_pid, request_id, |
1150 filter_->GetWeakPtr()); | 1153 requester_info_->clone()); |
1151 | 1154 |
1152 // Update maps that used the old IDs, if necessary. Some transfers in tests | 1155 // 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. | 1156 // do not actually use a different ID, so not all maps need to be updated. |
1154 pending_loaders_[new_request_id] = std::move(loader); | 1157 pending_loaders_[new_request_id] = std::move(loader); |
1155 IncrementOutstandingRequestsMemory(1, *info); | 1158 IncrementOutstandingRequestsMemory(1, *info); |
1156 if (should_update_count) | 1159 if (should_update_count) |
1157 IncrementOutstandingRequestsCount(1, info); | 1160 IncrementOutstandingRequestsCount(1, info); |
1158 if (old_routing_id != new_routing_id) { | 1161 if (old_routing_id != new_routing_id) { |
1159 if (blocked_loaders_map_.find(old_routing_id) != | 1162 if (blocked_loaders_map_.find(old_routing_id) != |
1160 blocked_loaders_map_.end()) { | 1163 blocked_loaders_map_.end()) { |
1161 blocked_loaders_map_[new_routing_id] = | 1164 blocked_loaders_map_[new_routing_id] = |
1162 std::move(blocked_loaders_map_[old_routing_id]); | 1165 std::move(blocked_loaders_map_[old_routing_id]); |
1163 blocked_loaders_map_.erase(old_routing_id); | 1166 blocked_loaders_map_.erase(old_routing_id); |
1164 } | 1167 } |
1165 } | 1168 } |
1166 if (old_request_id != new_request_id) { | 1169 if (old_request_id != new_request_id) { |
1167 DelegateMap::iterator it = delegate_map_.find(old_request_id); | 1170 DelegateMap::iterator it = delegate_map_.find(old_request_id); |
1168 if (it != delegate_map_.end()) { | 1171 if (it != delegate_map_.end()) { |
1169 // Tell each delegate that the request ID has changed. | 1172 // Tell each delegate that the request ID has changed. |
1170 for (auto& delegate : *it->second) | 1173 for (auto& delegate : *it->second) |
1171 delegate.set_request_id(new_request_id); | 1174 delegate.set_request_id(new_request_id); |
1172 // Now store the observer list under the new request ID. | 1175 // Now store the observer list under the new request ID. |
1173 delegate_map_[new_request_id] = delegate_map_[old_request_id]; | 1176 delegate_map_[new_request_id] = delegate_map_[old_request_id]; |
1174 delegate_map_.erase(old_request_id); | 1177 delegate_map_.erase(old_request_id); |
1175 } | 1178 } |
1176 } | 1179 } |
1177 | 1180 |
1178 AppCacheInterceptor::CompleteCrossSiteTransfer( | 1181 AppCacheInterceptor::CompleteCrossSiteTransfer( |
1179 loader_ptr->request(), | 1182 loader_ptr->request(), child_id, request_data.appcache_host_id, |
1180 child_id, | 1183 requester_info_.get()); |
1181 request_data.appcache_host_id, | |
1182 filter_); | |
1183 | 1184 |
1184 ServiceWorkerRequestHandler* handler = | 1185 ServiceWorkerRequestHandler* handler = |
1185 ServiceWorkerRequestHandler::GetHandler(loader_ptr->request()); | 1186 ServiceWorkerRequestHandler::GetHandler(loader_ptr->request()); |
1186 if (handler) { | 1187 if (handler) { |
1187 if (!handler->SanityCheckIsSameContext(filter_->service_worker_context())) { | 1188 if (!handler->SanityCheckIsSameContext( |
1189 requester_info_->service_worker_context())) { | |
1188 bad_message::ReceivedBadMessage( | 1190 bad_message::ReceivedBadMessage( |
1189 filter_, bad_message::RDHI_WRONG_STORAGE_PARTITION); | 1191 requester_info_->filter(), bad_message::RDHI_WRONG_STORAGE_PARTITION); |
1190 } else { | 1192 } else { |
1191 handler->CompleteCrossSiteTransfer( | 1193 handler->CompleteCrossSiteTransfer( |
1192 child_id, request_data.service_worker_provider_id); | 1194 child_id, request_data.service_worker_provider_id); |
1193 } | 1195 } |
1194 } | 1196 } |
1195 } | 1197 } |
1196 | 1198 |
1197 void ResourceDispatcherHostImpl::CompleteTransfer( | 1199 void ResourceDispatcherHostImpl::CompleteTransfer( |
1198 int request_id, | 1200 int request_id, |
1199 const ResourceRequest& request_data, | 1201 const ResourceRequest& request_data, |
1200 int route_id) { | 1202 int route_id) { |
1203 DCHECK(requester_info_->IsRenderer()); | |
1201 // Caller should ensure that |request_data| is associated with a transfer. | 1204 // Caller should ensure that |request_data| is associated with a transfer. |
1202 DCHECK(request_data.transferred_request_child_id != -1 || | 1205 DCHECK(request_data.transferred_request_child_id != -1 || |
1203 request_data.transferred_request_request_id != -1); | 1206 request_data.transferred_request_request_id != -1); |
1204 | 1207 |
1205 bool is_navigational_request = | 1208 bool is_navigational_request = |
1206 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME || | 1209 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME || |
1207 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; | 1210 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; |
1208 if (!is_navigational_request) { | 1211 if (!is_navigational_request) { |
1209 // Transfers apply only to navigational requests - the renderer seems to | 1212 // Transfers apply only to navigational requests - the renderer seems to |
1210 // have sent bogus IPC data. | 1213 // have sent bogus IPC data. |
1211 bad_message::ReceivedBadMessage( | 1214 bad_message::ReceivedBadMessage( |
1212 filter_, bad_message::RDH_TRANSFERRING_NONNAVIGATIONAL_REQUEST); | 1215 requester_info_->filter(), |
1216 bad_message::RDH_TRANSFERRING_NONNAVIGATIONAL_REQUEST); | |
1213 return; | 1217 return; |
1214 } | 1218 } |
1215 | 1219 |
1216 // Attempt to find a loader associated with the deferred transfer request. | 1220 // Attempt to find a loader associated with the deferred transfer request. |
1217 LoaderMap::iterator it = pending_loaders_.find( | 1221 LoaderMap::iterator it = pending_loaders_.find( |
1218 GlobalRequestID(request_data.transferred_request_child_id, | 1222 GlobalRequestID(request_data.transferred_request_child_id, |
1219 request_data.transferred_request_request_id)); | 1223 request_data.transferred_request_request_id)); |
1220 if (it == pending_loaders_.end()) { | 1224 if (it == pending_loaders_.end()) { |
1221 // Renderer sent transferred_request_request_id and/or | 1225 // Renderer sent transferred_request_request_id and/or |
1222 // transferred_request_child_id that doesn't have a corresponding entry on | 1226 // transferred_request_child_id that doesn't have a corresponding entry on |
1223 // the browser side. | 1227 // the browser side. |
1224 // TODO(lukasza): https://crbug.com/659613: Need to understand the scenario | 1228 // TODO(lukasza): https://crbug.com/659613: Need to understand the scenario |
1225 // that can lead here (and then attempt to reintroduce a renderer kill | 1229 // that can lead here (and then attempt to reintroduce a renderer kill |
1226 // below). | 1230 // below). |
1227 return; | 1231 return; |
1228 } | 1232 } |
1229 ResourceLoader* pending_loader = it->second.get(); | 1233 ResourceLoader* pending_loader = it->second.get(); |
1230 | 1234 |
1231 if (!pending_loader->is_transferring()) { | 1235 if (!pending_loader->is_transferring()) { |
1232 // Renderer sent transferred_request_request_id and/or | 1236 // Renderer sent transferred_request_request_id and/or |
1233 // transferred_request_child_id that doesn't correspond to an actually | 1237 // transferred_request_child_id that doesn't correspond to an actually |
1234 // transferring loader on the browser side. | 1238 // transferring loader on the browser side. |
1235 base::debug::Alias(pending_loader); | 1239 base::debug::Alias(pending_loader); |
1236 bad_message::ReceivedBadMessage(filter_, | 1240 bad_message::ReceivedBadMessage(requester_info_->filter(), |
1237 bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1241 bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
1238 return; | 1242 return; |
1239 } | 1243 } |
1240 | 1244 |
1241 // If the request is transferring to a new process, we can update our | 1245 // If the request is transferring to a new process, we can update our |
1242 // state and let it resume with its existing ResourceHandlers. | 1246 // state and let it resume with its existing ResourceHandlers. |
1243 UpdateRequestForTransfer(filter_->child_id(), route_id, request_id, | 1247 UpdateRequestForTransfer(requester_info_->child_id(), route_id, request_id, |
1244 request_data, it); | 1248 request_data, it); |
1245 pending_loader->CompleteTransfer(); | 1249 pending_loader->CompleteTransfer(); |
1246 } | 1250 } |
1247 | 1251 |
1248 void ResourceDispatcherHostImpl::BeginRequest( | 1252 void ResourceDispatcherHostImpl::BeginRequest( |
1249 int request_id, | 1253 int request_id, |
1250 const ResourceRequest& request_data, | 1254 const ResourceRequest& request_data, |
1251 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1255 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
1252 int route_id, | 1256 int route_id, |
1253 mojom::URLLoaderAssociatedRequest mojo_request, | 1257 mojom::URLLoaderAssociatedRequest mojo_request, |
1254 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1258 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
1255 int process_type = filter_->process_type(); | 1259 DCHECK(requester_info_->IsRenderer()); |
1256 int child_id = filter_->child_id(); | 1260 int child_id = requester_info_->child_id(); |
1257 | 1261 |
1258 // Reject request id that's currently in use. | 1262 // Reject request id that's currently in use. |
1259 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1263 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
1260 bad_message::ReceivedBadMessage(filter_, | 1264 bad_message::ReceivedBadMessage(requester_info_->filter(), |
1261 bad_message::RDH_INVALID_REQUEST_ID); | 1265 bad_message::RDH_INVALID_REQUEST_ID); |
1262 return; | 1266 return; |
1263 } | 1267 } |
1264 | 1268 |
1265 // PlzNavigate: reject invalid renderer main resource request. | 1269 // PlzNavigate: reject invalid renderer main resource request. |
1266 bool is_navigation_stream_request = | 1270 bool is_navigation_stream_request = |
1267 IsBrowserSideNavigationEnabled() && | 1271 IsBrowserSideNavigationEnabled() && |
1268 IsResourceTypeFrame(request_data.resource_type); | 1272 IsResourceTypeFrame(request_data.resource_type); |
1269 // The process_type check is to ensure that unittests are not blocked from | 1273 if (is_navigation_stream_request && |
1270 // issuing http requests. | 1274 !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { |
1271 if ((process_type == PROCESS_TYPE_RENDERER) && is_navigation_stream_request | 1275 bad_message::ReceivedBadMessage(requester_info_->filter(), |
yhirano
2016/11/10 06:42:29
Does this change mean this |process_type| check is
horo
2016/11/10 14:46:33
These checks were added by this change https://cod
| |
1272 && !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { | 1276 bad_message::RDH_INVALID_URL); |
1273 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_INVALID_URL); | |
1274 return; | 1277 return; |
1275 } | 1278 } |
1276 | 1279 |
1277 // Reject invalid priority. | 1280 // Reject invalid priority. |
1278 if (request_data.priority < net::MINIMUM_PRIORITY || | 1281 if (request_data.priority < net::MINIMUM_PRIORITY || |
1279 request_data.priority > net::MAXIMUM_PRIORITY) { | 1282 request_data.priority > net::MAXIMUM_PRIORITY) { |
1280 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_INVALID_PRIORITY); | 1283 bad_message::ReceivedBadMessage(requester_info_->filter(), |
1284 bad_message::RDH_INVALID_PRIORITY); | |
1281 return; | 1285 return; |
1282 } | 1286 } |
1283 | 1287 |
1284 // If we crash here, figure out what URL the renderer was requesting. | 1288 // If we crash here, figure out what URL the renderer was requesting. |
1285 // http://crbug.com/91398 | 1289 // http://crbug.com/91398 |
1286 char url_buf[128]; | 1290 char url_buf[128]; |
1287 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1291 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
1288 base::debug::Alias(url_buf); | 1292 base::debug::Alias(url_buf); |
1289 | 1293 |
1290 // If the request that's coming in is being transferred from another process, | 1294 // 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. | 1295 // we want to reuse and resume the old loader rather than start a new one. |
1292 if (request_data.transferred_request_child_id != -1 || | 1296 if (request_data.transferred_request_child_id != -1 || |
1293 request_data.transferred_request_request_id != -1) { | 1297 request_data.transferred_request_request_id != -1) { |
1294 // TODO(yhirano): Make mojo work for this case. | 1298 // TODO(yhirano): Make mojo work for this case. |
1295 DCHECK(!url_loader_client); | 1299 DCHECK(!url_loader_client); |
1296 | 1300 |
1297 CompleteTransfer(request_id, request_data, route_id); | 1301 CompleteTransfer(request_id, request_data, route_id); |
1298 return; | 1302 return; |
1299 } | 1303 } |
1300 | 1304 |
1301 ResourceContext* resource_context = NULL; | 1305 ResourceContext* resource_context = NULL; |
1302 net::URLRequestContext* request_context = NULL; | 1306 net::URLRequestContext* request_context = NULL; |
1303 filter_->GetContexts(request_data.resource_type, &resource_context, | 1307 requester_info_->GetContexts(request_data.resource_type, &resource_context, |
1304 &request_context); | 1308 &request_context); |
1305 | 1309 |
1306 // Parse the headers before calling ShouldServiceRequest, so that they are | 1310 // Parse the headers before calling ShouldServiceRequest, so that they are |
1307 // available to be validated. | 1311 // available to be validated. |
1308 net::HttpRequestHeaders headers; | 1312 net::HttpRequestHeaders headers; |
1309 headers.AddHeadersFromString(request_data.headers); | 1313 headers.AddHeadersFromString(request_data.headers); |
1310 | 1314 |
1311 if (is_shutdown_ || | 1315 if (is_shutdown_ || |
1312 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1316 !ShouldServiceRequest(child_id, request_data, headers, |
1313 filter_, resource_context)) { | 1317 requester_info_.get(), resource_context)) { |
1314 AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id, | 1318 AbortRequestBeforeItStarts(requester_info_->filter(), sync_result_handler, |
1315 std::move(url_loader_client)); | 1319 request_id, std::move(url_loader_client)); |
1316 return; | 1320 return; |
1317 } | 1321 } |
1318 // Check if we have a registered interceptor for the headers passed in. If | 1322 // 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 | 1323 // 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 | 1324 // interceptor to invoke the callback with a status code indicating whether |
1321 // the request needs to be aborted or continued. | 1325 // the request needs to be aborted or continued. |
1322 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { | 1326 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { |
1323 HeaderInterceptorMap::iterator index = | 1327 HeaderInterceptorMap::iterator index = |
1324 http_header_interceptor_map_.find(it.name()); | 1328 http_header_interceptor_map_.find(it.name()); |
1325 if (index != http_header_interceptor_map_.end()) { | 1329 if (index != http_header_interceptor_map_.end()) { |
(...skipping 25 matching lines...) Expand all Loading... | |
1351 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( | 1355 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( |
1352 int request_id, | 1356 int request_id, |
1353 const ResourceRequest& request_data, | 1357 const ResourceRequest& request_data, |
1354 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1358 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
1355 int route_id, | 1359 int route_id, |
1356 const net::HttpRequestHeaders& headers, | 1360 const net::HttpRequestHeaders& headers, |
1357 mojom::URLLoaderAssociatedRequest mojo_request, | 1361 mojom::URLLoaderAssociatedRequest mojo_request, |
1358 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 1362 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
1359 bool continue_request, | 1363 bool continue_request, |
1360 int error_code) { | 1364 int error_code) { |
1365 DCHECK(requester_info_->IsRenderer()); | |
1361 if (!continue_request) { | 1366 if (!continue_request) { |
1362 // TODO(ananta): Find a way to specify the right error code here. Passing | 1367 // TODO(ananta): Find a way to specify the right error code here. Passing |
1363 // in a non-content error code is not safe. | 1368 // in a non-content error code is not safe. |
1364 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_ILLEGAL_ORIGIN); | 1369 bad_message::ReceivedBadMessage(requester_info_->filter(), |
1365 AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id, | 1370 bad_message::RDH_ILLEGAL_ORIGIN); |
1366 std::move(url_loader_client)); | 1371 AbortRequestBeforeItStarts(requester_info_->filter(), sync_result_handler, |
1372 request_id, std::move(url_loader_client)); | |
1367 return; | 1373 return; |
1368 } | 1374 } |
1369 | 1375 int child_id = requester_info_->child_id(); |
1370 int process_type = filter_->process_type(); | |
1371 int child_id = filter_->child_id(); | |
1372 | 1376 |
1373 bool is_navigation_stream_request = | 1377 bool is_navigation_stream_request = |
1374 IsBrowserSideNavigationEnabled() && | 1378 IsBrowserSideNavigationEnabled() && |
1375 IsResourceTypeFrame(request_data.resource_type) && | 1379 IsResourceTypeFrame(request_data.resource_type); |
1376 process_type == PROCESS_TYPE_RENDERER; | |
1377 | 1380 |
1378 ResourceContext* resource_context = NULL; | 1381 ResourceContext* resource_context = NULL; |
1379 net::URLRequestContext* request_context = NULL; | 1382 net::URLRequestContext* request_context = NULL; |
1380 filter_->GetContexts(request_data.resource_type, &resource_context, | 1383 requester_info_->GetContexts(request_data.resource_type, &resource_context, |
1381 &request_context); | 1384 &request_context); |
1382 | 1385 |
1383 // Allow the observer to block/handle the request. | 1386 // Allow the observer to block/handle the request. |
1384 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1387 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
1385 request_data.url, | 1388 request_data.url, |
1386 request_data.resource_type, | 1389 request_data.resource_type, |
1387 resource_context)) { | 1390 resource_context)) { |
1388 AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id, | 1391 AbortRequestBeforeItStarts(requester_info_->filter(), sync_result_handler, |
1389 std::move(url_loader_client)); | 1392 request_id, std::move(url_loader_client)); |
1390 return; | 1393 return; |
1391 } | 1394 } |
1392 | 1395 |
1393 // Construct the request. | 1396 // Construct the request. |
1394 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 1397 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( |
1395 is_navigation_stream_request ? request_data.resource_body_stream_url | 1398 is_navigation_stream_request ? request_data.resource_body_stream_url |
1396 : request_data.url, | 1399 : request_data.url, |
1397 request_data.priority, nullptr); | 1400 request_data.priority, nullptr); |
1398 | 1401 |
1399 // PlzNavigate: Always set the method to GET when gaining access to the | 1402 // PlzNavigate: Always set the method to GET when gaining access to the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1434 // ComputeReferrerForRedirect). | 1437 // ComputeReferrerForRedirect). |
1435 if (!is_navigation_stream_request) { | 1438 if (!is_navigation_stream_request) { |
1436 const Referrer referrer( | 1439 const Referrer referrer( |
1437 request_data.referrer, request_data.referrer_policy); | 1440 request_data.referrer, request_data.referrer_policy); |
1438 SetReferrerForRequest(new_request.get(), referrer); | 1441 SetReferrerForRequest(new_request.get(), referrer); |
1439 } | 1442 } |
1440 | 1443 |
1441 new_request->SetExtraRequestHeaders(headers); | 1444 new_request->SetExtraRequestHeaders(headers); |
1442 | 1445 |
1443 storage::BlobStorageContext* blob_context = | 1446 storage::BlobStorageContext* blob_context = |
1444 GetBlobStorageContext(filter_->blob_storage_context()); | 1447 GetBlobStorageContext(requester_info_->blob_storage_context()); |
1445 // Resolve elements from request_body and prepare upload data. | 1448 // Resolve elements from request_body and prepare upload data. |
1446 if (request_data.request_body.get()) { | 1449 if (request_data.request_body.get()) { |
1447 // |blob_context| could be null when the request is from the plugins because | 1450 // |blob_context| could be null when the request is from the plugins because |
1448 // ResourceMessageFilters created in PluginProcessHost don't have the blob | 1451 // ResourceMessageFilters created in PluginProcessHost don't have the blob |
1449 // context. | 1452 // context. |
1450 if (blob_context) { | 1453 if (blob_context) { |
1451 // Attaches the BlobDataHandles to request_body not to free the blobs and | 1454 // Attaches the BlobDataHandles to request_body not to free the blobs and |
1452 // any attached shareable files until upload completion. These data will | 1455 // any attached shareable files until upload completion. These data will |
1453 // be used in UploadDataStream and ServiceWorkerURLRequestJob. | 1456 // be used in UploadDataStream and ServiceWorkerURLRequestJob. |
1454 AttachRequestBodyBlobDataHandles( | 1457 AttachRequestBodyBlobDataHandles( |
1455 request_data.request_body.get(), | 1458 request_data.request_body.get(), |
1456 blob_context); | 1459 blob_context); |
1457 } | 1460 } |
1458 new_request->set_upload(UploadDataStreamBuilder::Build( | 1461 new_request->set_upload(UploadDataStreamBuilder::Build( |
1459 request_data.request_body.get(), blob_context, | 1462 request_data.request_body.get(), blob_context, |
1460 filter_->file_system_context(), | 1463 requester_info_->file_system_context(), |
1461 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); | 1464 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); |
1462 } | 1465 } |
1463 | 1466 |
1464 bool allow_download = request_data.allow_download && | 1467 bool allow_download = request_data.allow_download && |
1465 IsResourceTypeFrame(request_data.resource_type); | 1468 IsResourceTypeFrame(request_data.resource_type); |
1466 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login; | 1469 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login; |
1467 bool is_sync_load = !!sync_result_handler; | 1470 bool is_sync_load = !!sync_result_handler; |
1468 | 1471 |
1469 // Raw headers are sensitive, as they include Cookie/Set-Cookie, so only | 1472 // Raw headers are sensitive, as they include Cookie/Set-Cookie, so only |
1470 // allow requesting them if requester has ReadRawCookies permission. | 1473 // allow requesting them if requester has ReadRawCookies permission. |
1471 ChildProcessSecurityPolicyImpl* policy = | 1474 ChildProcessSecurityPolicyImpl* policy = |
1472 ChildProcessSecurityPolicyImpl::GetInstance(); | 1475 ChildProcessSecurityPolicyImpl::GetInstance(); |
1473 bool report_raw_headers = request_data.report_raw_headers; | 1476 bool report_raw_headers = request_data.report_raw_headers; |
1474 if (report_raw_headers && !policy->CanReadRawCookies(child_id)) { | 1477 if (report_raw_headers && !policy->CanReadRawCookies(child_id)) { |
1475 // TODO: crbug.com/523063 can we call bad_message::ReceivedBadMessage here? | 1478 // TODO: crbug.com/523063 can we call bad_message::ReceivedBadMessage here? |
1476 VLOG(1) << "Denied unauthorized request for raw headers"; | 1479 VLOG(1) << "Denied unauthorized request for raw headers"; |
1477 report_raw_headers = false; | 1480 report_raw_headers = false; |
1478 } | 1481 } |
1479 int load_flags = | 1482 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 || | 1483 if (request_data.resource_type == RESOURCE_TYPE_PREFETCH || |
1482 request_data.resource_type == RESOURCE_TYPE_FAVICON) { | 1484 request_data.resource_type == RESOURCE_TYPE_FAVICON) { |
1483 do_not_prompt_for_login = true; | 1485 do_not_prompt_for_login = true; |
1484 } | 1486 } |
1485 if (request_data.resource_type == RESOURCE_TYPE_IMAGE && | 1487 if (request_data.resource_type == RESOURCE_TYPE_IMAGE && |
1486 HTTP_AUTH_RELATION_BLOCKED_CROSS == | 1488 HTTP_AUTH_RELATION_BLOCKED_CROSS == |
1487 HttpAuthRelationTypeOf(request_data.url, | 1489 HttpAuthRelationTypeOf(request_data.url, |
1488 request_data.first_party_for_cookies)) { | 1490 request_data.first_party_for_cookies)) { |
1489 // Prevent third-party image content from prompting for login, as this | 1491 // 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. | 1492 // is often a scam to extract credentials for another domain from the user. |
(...skipping 19 matching lines...) Expand all Loading... | |
1510 if (is_sync_load) { | 1512 if (is_sync_load) { |
1511 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); | 1513 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); |
1512 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1514 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
1513 } else { | 1515 } else { |
1514 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1516 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
1515 } | 1517 } |
1516 new_request->SetLoadFlags(load_flags); | 1518 new_request->SetLoadFlags(load_flags); |
1517 | 1519 |
1518 // Make extra info and read footer (contains request ID). | 1520 // Make extra info and read footer (contains request ID). |
1519 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( | 1521 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( |
1520 process_type, child_id, route_id, | 1522 requester_info_->clone(), route_id, |
1521 -1, // frame_tree_node_id | 1523 -1, // frame_tree_node_id |
1522 request_data.origin_pid, request_id, request_data.render_frame_id, | 1524 request_data.origin_pid, request_id, request_data.render_frame_id, |
1523 request_data.is_main_frame, request_data.parent_is_main_frame, | 1525 request_data.is_main_frame, request_data.parent_is_main_frame, |
1524 request_data.resource_type, request_data.transition_type, | 1526 request_data.resource_type, request_data.transition_type, |
1525 request_data.should_replace_current_entry, | 1527 request_data.should_replace_current_entry, |
1526 false, // is download | 1528 false, // is download |
1527 false, // is stream | 1529 false, // is stream |
1528 allow_download, request_data.has_user_gesture, | 1530 allow_download, request_data.has_user_gesture, |
1529 request_data.enable_load_timing, request_data.enable_upload_progress, | 1531 request_data.enable_load_timing, request_data.enable_upload_progress, |
1530 do_not_prompt_for_login, request_data.referrer_policy, | 1532 do_not_prompt_for_login, request_data.referrer_policy, |
1531 request_data.visibility_state, resource_context, filter_->GetWeakPtr(), | 1533 request_data.visibility_state, resource_context, report_raw_headers, |
1532 report_raw_headers, !is_sync_load, | 1534 !is_sync_load, |
1533 IsUsingLoFi(request_data.lofi_state, delegate_, *new_request, | 1535 IsUsingLoFi(request_data.lofi_state, delegate_, *new_request, |
1534 resource_context, | 1536 resource_context, |
1535 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), | 1537 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), |
1536 support_async_revalidation ? request_data.headers : std::string(), | 1538 support_async_revalidation ? request_data.headers : std::string(), |
1537 request_data.request_body, request_data.initiated_in_secure_context); | 1539 request_data.request_body, request_data.initiated_in_secure_context); |
1538 // Request takes ownership. | 1540 // Request takes ownership. |
1539 extra_info->AssociateWithRequest(new_request.get()); | 1541 extra_info->AssociateWithRequest(new_request.get()); |
1540 | 1542 |
1541 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1543 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1542 // Hang on to a reference to ensure the blob is not released prior | 1544 // Hang on to a reference to ensure the blob is not released prior |
1543 // to the job being started. | 1545 // to the job being started. |
1544 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1546 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1545 new_request.get(), | 1547 new_request.get(), requester_info_->blob_storage_context() |
1546 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( | 1548 ->context() |
1547 new_request->url())); | 1549 ->GetBlobDataFromPublicURL(new_request->url())); |
1548 } | 1550 } |
1549 | 1551 |
1550 // Initialize the service worker handler for the request. We don't use | 1552 // Initialize the service worker handler for the request. We don't use |
1551 // ServiceWorker for synchronous loads to avoid renderer deadlocks. | 1553 // ServiceWorker for synchronous loads to avoid renderer deadlocks. |
1552 const SkipServiceWorker should_skip_service_worker = | 1554 const SkipServiceWorker should_skip_service_worker = |
1553 is_sync_load ? SkipServiceWorker::ALL : request_data.skip_service_worker; | 1555 is_sync_load ? SkipServiceWorker::ALL : request_data.skip_service_worker; |
1554 ServiceWorkerRequestHandler::InitializeHandler( | 1556 ServiceWorkerRequestHandler::InitializeHandler( |
1555 new_request.get(), filter_->service_worker_context(), blob_context, | 1557 new_request.get(), requester_info_->service_worker_context(), |
1556 child_id, request_data.service_worker_provider_id, | 1558 blob_context, child_id, request_data.service_worker_provider_id, |
1557 should_skip_service_worker != SkipServiceWorker::NONE, | 1559 should_skip_service_worker != SkipServiceWorker::NONE, |
1558 request_data.fetch_request_mode, request_data.fetch_credentials_mode, | 1560 request_data.fetch_request_mode, request_data.fetch_credentials_mode, |
1559 request_data.fetch_redirect_mode, request_data.resource_type, | 1561 request_data.fetch_redirect_mode, request_data.resource_type, |
1560 request_data.fetch_request_context_type, request_data.fetch_frame_type, | 1562 request_data.fetch_request_context_type, request_data.fetch_frame_type, |
1561 request_data.request_body); | 1563 request_data.request_body); |
1562 | 1564 |
1563 ForeignFetchRequestHandler::InitializeHandler( | 1565 ForeignFetchRequestHandler::InitializeHandler( |
1564 new_request.get(), filter_->service_worker_context(), blob_context, | 1566 new_request.get(), requester_info_->service_worker_context(), |
1565 child_id, request_data.service_worker_provider_id, | 1567 blob_context, child_id, request_data.service_worker_provider_id, |
1566 should_skip_service_worker, request_data.fetch_request_mode, | 1568 should_skip_service_worker, request_data.fetch_request_mode, |
1567 request_data.fetch_credentials_mode, request_data.fetch_redirect_mode, | 1569 request_data.fetch_credentials_mode, request_data.fetch_redirect_mode, |
1568 request_data.resource_type, request_data.fetch_request_context_type, | 1570 request_data.resource_type, request_data.fetch_request_context_type, |
1569 request_data.fetch_frame_type, request_data.request_body, | 1571 request_data.fetch_frame_type, request_data.request_body, |
1570 request_data.initiated_in_secure_context); | 1572 request_data.initiated_in_secure_context); |
1571 | 1573 |
1572 // Have the appcache associate its extra info with the request. | 1574 // Have the appcache associate its extra info with the request. |
1573 AppCacheInterceptor::SetExtraRequestInfo( | 1575 AppCacheInterceptor::SetExtraRequestInfo( |
1574 new_request.get(), filter_->appcache_service(), child_id, | 1576 new_request.get(), requester_info_->appcache_service(), child_id, |
1575 request_data.appcache_host_id, request_data.resource_type, | 1577 request_data.appcache_host_id, request_data.resource_type, |
1576 request_data.should_reset_appcache); | 1578 request_data.should_reset_appcache); |
1577 | 1579 |
1578 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1580 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
1579 new_request.get(), request_data, sync_result_handler, route_id, | 1581 new_request.get(), request_data, sync_result_handler, route_id, child_id, |
1580 process_type, child_id, resource_context, std::move(mojo_request), | 1582 resource_context, std::move(mojo_request), std::move(url_loader_client))); |
1581 std::move(url_loader_client))); | |
1582 | 1583 |
1583 if (handler) | 1584 if (handler) |
1584 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1585 BeginRequestInternal(std::move(new_request), std::move(handler)); |
1585 } | 1586 } |
1586 | 1587 |
1587 std::unique_ptr<ResourceHandler> | 1588 std::unique_ptr<ResourceHandler> |
1588 ResourceDispatcherHostImpl::CreateResourceHandler( | 1589 ResourceDispatcherHostImpl::CreateResourceHandler( |
1589 net::URLRequest* request, | 1590 net::URLRequest* request, |
1590 const ResourceRequest& request_data, | 1591 const ResourceRequest& request_data, |
1591 const SyncLoadResultCallback& sync_result_handler, | 1592 const SyncLoadResultCallback& sync_result_handler, |
1592 int route_id, | 1593 int route_id, |
1593 int process_type, | |
1594 int child_id, | 1594 int child_id, |
1595 ResourceContext* resource_context, | 1595 ResourceContext* resource_context, |
1596 mojom::URLLoaderAssociatedRequest mojo_request, | 1596 mojom::URLLoaderAssociatedRequest mojo_request, |
1597 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1597 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
1598 DCHECK(requester_info_->IsRenderer()); | |
1598 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1599 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
1599 tracked_objects::ScopedTracker tracking_profile( | 1600 tracked_objects::ScopedTracker tracking_profile( |
1600 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1601 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1601 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1602 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
1602 // Construct the IPC resource handler. | 1603 // Construct the IPC resource handler. |
1603 std::unique_ptr<ResourceHandler> handler; | 1604 std::unique_ptr<ResourceHandler> handler; |
1604 if (sync_result_handler) { | 1605 if (sync_result_handler) { |
1605 // download_to_file is not supported for synchronous requests. | 1606 // download_to_file is not supported for synchronous requests. |
1606 if (request_data.download_to_file) { | 1607 if (request_data.download_to_file) { |
1607 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1608 bad_message::ReceivedBadMessage(requester_info_->filter(), |
1609 bad_message::RDH_BAD_DOWNLOAD); | |
1608 return std::unique_ptr<ResourceHandler>(); | 1610 return std::unique_ptr<ResourceHandler>(); |
1609 } | 1611 } |
1610 | 1612 |
1611 DCHECK(!mojo_request.is_pending()); | 1613 DCHECK(!mojo_request.is_pending()); |
1612 DCHECK(!url_loader_client); | 1614 DCHECK(!url_loader_client); |
1613 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); | 1615 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); |
1614 } else { | 1616 } else { |
1615 if (mojo_request.is_pending()) { | 1617 if (mojo_request.is_pending()) { |
1616 handler.reset(new MojoAsyncResourceHandler(request, this, | 1618 handler.reset(new MojoAsyncResourceHandler(request, this, |
1617 std::move(mojo_request), | 1619 std::move(mojo_request), |
(...skipping 18 matching lines...) Expand all Loading... | |
1636 std::unique_ptr<DetachableResourceHandler> detachable_handler = | 1638 std::unique_ptr<DetachableResourceHandler> detachable_handler = |
1637 base::MakeUnique<DetachableResourceHandler>( | 1639 base::MakeUnique<DetachableResourceHandler>( |
1638 request, | 1640 request, |
1639 base::TimeDelta::FromMilliseconds(kDefaultDetachableCancelDelayMs), | 1641 base::TimeDelta::FromMilliseconds(kDefaultDetachableCancelDelayMs), |
1640 std::move(handler)); | 1642 std::move(handler)); |
1641 if (start_detached) | 1643 if (start_detached) |
1642 detachable_handler->Detach(); | 1644 detachable_handler->Detach(); |
1643 handler = std::move(detachable_handler); | 1645 handler = std::move(detachable_handler); |
1644 } | 1646 } |
1645 | 1647 |
1646 return AddStandardHandlers( | 1648 // PlzNavigate: do not add ResourceThrottles for main resource requests from |
1647 request, request_data.resource_type, resource_context, | 1649 // the renderer. Decisions about the navigation should have been done in the |
1648 request_data.fetch_request_context_type, filter_->appcache_service(), | 1650 // initial request. |
1649 child_id, route_id, std::move(handler)); | 1651 if (IsBrowserSideNavigationEnabled() && |
1652 IsResourceTypeFrame(request_data.resource_type)) { | |
1653 DCHECK(request->url().SchemeIs(url::kBlobScheme)); | |
1654 return handler; | |
1655 } | |
1656 | |
1657 return AddStandardHandlers(request, request_data.resource_type, | |
1658 resource_context, | |
1659 request_data.fetch_request_context_type, | |
1660 requester_info_->appcache_service(), child_id, | |
1661 route_id, std::move(handler)); | |
1650 } | 1662 } |
1651 | 1663 |
1652 std::unique_ptr<ResourceHandler> | 1664 std::unique_ptr<ResourceHandler> |
1653 ResourceDispatcherHostImpl::AddStandardHandlers( | 1665 ResourceDispatcherHostImpl::AddStandardHandlers( |
1654 net::URLRequest* request, | 1666 net::URLRequest* request, |
1655 ResourceType resource_type, | 1667 ResourceType resource_type, |
1656 ResourceContext* resource_context, | 1668 ResourceContext* resource_context, |
1657 RequestContextType fetch_request_context_type, | 1669 RequestContextType fetch_request_context_type, |
1658 AppCacheService* appcache_service, | 1670 AppCacheService* appcache_service, |
1659 int child_id, | 1671 int child_id, |
1660 int route_id, | 1672 int route_id, |
1661 std::unique_ptr<ResourceHandler> handler) { | 1673 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 | 1674 // The InterceptingResourceHandler will replace its next handler with an |
1674 // appropriate one based on the MIME type of the response if needed. It | 1675 // 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|. | 1676 // should be placed at the end of the chain, just before |handler|. |
1676 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); | 1677 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); |
1677 InterceptingResourceHandler* intercepting_handler = | 1678 InterceptingResourceHandler* intercepting_handler = |
1678 static_cast<InterceptingResourceHandler*>(handler.get()); | 1679 static_cast<InterceptingResourceHandler*>(handler.get()); |
1679 | 1680 |
1680 ScopedVector<ResourceThrottle> throttles; | 1681 ScopedVector<ResourceThrottle> throttles; |
1681 | 1682 |
1682 // Add a NavigationResourceThrottle for navigations. | 1683 // Add a NavigationResourceThrottle for navigations. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1741 fetch_request_context_type)); | 1742 fetch_request_context_type)); |
1742 | 1743 |
1743 // Add the pre mime sniffing throttles. | 1744 // Add the pre mime sniffing throttles. |
1744 handler.reset(new ThrottlingResourceHandler( | 1745 handler.reset(new ThrottlingResourceHandler( |
1745 std::move(handler), request, std::move(pre_mime_sniffing_throttles))); | 1746 std::move(handler), request, std::move(pre_mime_sniffing_throttles))); |
1746 | 1747 |
1747 return handler; | 1748 return handler; |
1748 } | 1749 } |
1749 | 1750 |
1750 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { | 1751 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { |
1751 UnregisterDownloadedTempFile(filter_->child_id(), request_id); | 1752 DCHECK(requester_info_->IsRenderer()); |
1753 UnregisterDownloadedTempFile(requester_info_->child_id(), request_id); | |
1752 } | 1754 } |
1753 | 1755 |
1754 void ResourceDispatcherHostImpl::OnDidChangePriority( | 1756 void ResourceDispatcherHostImpl::OnDidChangePriority( |
1755 int request_id, | 1757 int request_id, |
1756 net::RequestPriority new_priority, | 1758 net::RequestPriority new_priority, |
1757 int intra_priority_value) { | 1759 int intra_priority_value) { |
1758 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); | 1760 DCHECK(requester_info_->IsRenderer()); |
1761 ResourceLoader* loader = GetLoader(requester_info_->child_id(), request_id); | |
1759 // The request may go away before processing this message, so |loader| can | 1762 // The request may go away before processing this message, so |loader| can |
1760 // legitimately be null. | 1763 // legitimately be null. |
1761 if (!loader) | 1764 if (!loader) |
1762 return; | 1765 return; |
1763 | 1766 |
1764 scheduler_->ReprioritizeRequest(loader->request(), new_priority, | 1767 scheduler_->ReprioritizeRequest(loader->request(), new_priority, |
1765 intra_priority_value); | 1768 intra_priority_value); |
1766 } | 1769 } |
1767 | 1770 |
1768 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile( | 1771 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1802 } | 1805 } |
1803 | 1806 |
1804 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { | 1807 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { |
1805 delete message; | 1808 delete message; |
1806 return false; | 1809 return false; |
1807 } | 1810 } |
1808 | 1811 |
1809 // Note that this cancel is subtly different from the other | 1812 // Note that this cancel is subtly different from the other |
1810 // CancelRequest methods in this file, which also tear down the loader. | 1813 // CancelRequest methods in this file, which also tear down the loader. |
1811 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) { | 1814 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) { |
1812 int child_id = filter_->child_id(); | 1815 DCHECK(requester_info_->IsRenderer()); |
1816 int child_id = requester_info_->child_id(); | |
1813 | 1817 |
1814 // When the old renderer dies, it sends a message to us to cancel its | 1818 // When the old renderer dies, it sends a message to us to cancel its |
1815 // requests. | 1819 // requests. |
1816 if (IsTransferredNavigation(GlobalRequestID(child_id, request_id))) | 1820 if (IsTransferredNavigation(GlobalRequestID(child_id, request_id))) |
1817 return; | 1821 return; |
1818 | 1822 |
1819 ResourceLoader* loader = GetLoader(child_id, request_id); | 1823 ResourceLoader* loader = GetLoader(child_id, request_id); |
1820 | 1824 |
1821 // It is possible that the request has been completed and removed from the | 1825 // 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 | 1826 // loader queue but the client has not processed the request completed message |
1823 // before issuing a cancel. This happens frequently for beacons which are | 1827 // before issuing a cancel. This happens frequently for beacons which are |
1824 // canceled in the response received handler. | 1828 // canceled in the response received handler. |
1825 if (!loader) | 1829 if (!loader) |
1826 return; | 1830 return; |
1827 | 1831 |
1828 loader->CancelRequest(true); | 1832 loader->CancelRequest(true); |
1829 } | 1833 } |
1830 | 1834 |
1831 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( | 1835 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( |
1832 int child_id, | 1836 int child_id, |
1833 int render_view_route_id, | 1837 int render_view_route_id, |
1834 int render_frame_route_id, | 1838 int render_frame_route_id, |
1835 bool download, | 1839 bool download, |
1836 ResourceContext* context) { | 1840 ResourceContext* context) { |
1837 return new ResourceRequestInfoImpl( | 1841 return new ResourceRequestInfoImpl( |
1838 PROCESS_TYPE_RENDERER, child_id, render_view_route_id, | 1842 ResourceRequesterInfo::CreateForDownloadOrPageSave(child_id), |
1843 render_view_route_id, | |
1839 -1, // frame_tree_node_id | 1844 -1, // frame_tree_node_id |
1840 0, MakeRequestID(), render_frame_route_id, | 1845 0, MakeRequestID(), render_frame_route_id, |
1841 false, // is_main_frame | 1846 false, // is_main_frame |
1842 false, // parent_is_main_frame | 1847 false, // parent_is_main_frame |
1843 RESOURCE_TYPE_SUB_RESOURCE, ui::PAGE_TRANSITION_LINK, | 1848 RESOURCE_TYPE_SUB_RESOURCE, ui::PAGE_TRANSITION_LINK, |
1844 false, // should_replace_current_entry | 1849 false, // should_replace_current_entry |
1845 download, // is_download | 1850 download, // is_download |
1846 false, // is_stream | 1851 false, // is_stream |
1847 download, // allow_download | 1852 download, // allow_download |
1848 false, // has_user_gesture | 1853 false, // has_user_gesture |
1849 false, // enable_load_timing | 1854 false, // enable_load_timing |
1850 false, // enable_upload_progress | 1855 false, // enable_upload_progress |
1851 false, // do_not_prompt_for_login | 1856 false, // do_not_prompt_for_login |
1852 blink::WebReferrerPolicyDefault, blink::WebPageVisibilityStateVisible, | 1857 blink::WebReferrerPolicyDefault, blink::WebPageVisibilityStateVisible, |
1853 context, | 1858 context, |
1854 base::WeakPtr<ResourceMessageFilter>(), // filter | 1859 false, // report_raw_headers |
1855 false, // report_raw_headers | 1860 true, // is_async |
1856 true, // is_async | 1861 false, // is_using_lofi |
1857 false, // is_using_lofi | 1862 std::string(), // original_headers |
1858 std::string(), // original_headers | 1863 nullptr, // body |
1859 nullptr, // body | 1864 false); // initiated_in_secure_context |
1860 false); // initiated_in_secure_context | |
1861 } | 1865 } |
1862 | 1866 |
1863 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1867 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
1864 int route_id) { | 1868 int route_id) { |
1865 scheduler_->OnClientCreated(child_id, route_id); | 1869 scheduler_->OnClientCreated(child_id, route_id); |
1866 } | 1870 } |
1867 | 1871 |
1868 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, | 1872 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, |
1869 int route_id) { | 1873 int route_id) { |
1870 scheduler_->OnClientDeleted(child_id, route_id); | 1874 scheduler_->OnClientDeleted(child_id, route_id); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2190 body, blob_context, | 2194 body, blob_context, |
2191 nullptr, // file_system_context | 2195 nullptr, // file_system_context |
2192 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); | 2196 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); |
2193 } | 2197 } |
2194 | 2198 |
2195 // Make extra info and read footer (contains request ID). | 2199 // Make extra info and read footer (contains request ID). |
2196 // | 2200 // |
2197 // TODO(davidben): Associate the request with the FrameTreeNode and/or tab so | 2201 // TODO(davidben): Associate the request with the FrameTreeNode and/or tab so |
2198 // that IO thread -> UI thread hops will work. | 2202 // that IO thread -> UI thread hops will work. |
2199 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( | 2203 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( |
2200 PROCESS_TYPE_BROWSER, | 2204 ResourceRequesterInfo::CreateForBrowserSideNavigation( |
2201 -1, // child_id | 2205 service_worker_handle_core |
2206 ? service_worker_handle_core->context_wrapper() | |
2207 : scoped_refptr<ServiceWorkerContextWrapper>()), | |
2202 -1, // route_id | 2208 -1, // route_id |
2203 info.frame_tree_node_id, | 2209 info.frame_tree_node_id, |
2204 -1, // request_data.origin_pid, | 2210 -1, // request_data.origin_pid, |
2205 MakeRequestID(), | 2211 MakeRequestID(), |
2206 -1, // request_data.render_frame_id, | 2212 -1, // request_data.render_frame_id, |
2207 info.is_main_frame, info.parent_is_main_frame, resource_type, | 2213 info.is_main_frame, info.parent_is_main_frame, resource_type, |
2208 info.common_params.transition, | 2214 info.common_params.transition, |
2209 // should_replace_current_entry. This was only maintained at layer for | 2215 // should_replace_current_entry. This was only maintained at layer for |
2210 // request transfers and isn't needed for browser-side navigations. | 2216 // request transfers and isn't needed for browser-side navigations. |
2211 false, | 2217 false, |
2212 false, // is download | 2218 false, // is download |
2213 false, // is stream | 2219 false, // is stream |
2214 info.common_params.allow_download, info.begin_params.has_user_gesture, | 2220 info.common_params.allow_download, info.begin_params.has_user_gesture, |
2215 true, // enable_load_timing | 2221 true, // enable_load_timing |
2216 false, // enable_upload_progress | 2222 false, // enable_upload_progress |
2217 false, // do_not_prompt_for_login | 2223 false, // do_not_prompt_for_login |
2218 info.common_params.referrer.policy, | 2224 info.common_params.referrer.policy, |
2219 // TODO(davidben): This is only used for prerenders. Replace | 2225 // TODO(davidben): This is only used for prerenders. Replace |
2220 // is_showing with something for that. Or maybe it just comes from the | 2226 // is_showing with something for that. Or maybe it just comes from the |
2221 // same mechanism as the cookie one. | 2227 // same mechanism as the cookie one. |
2222 blink::WebPageVisibilityStateVisible, resource_context, | 2228 blink::WebPageVisibilityStateVisible, resource_context, |
2223 base::WeakPtr<ResourceMessageFilter>(), // filter | |
2224 info.report_raw_headers, | 2229 info.report_raw_headers, |
2225 true, // is_async | 2230 true, // is_async |
2226 IsUsingLoFi(info.common_params.lofi_state, delegate_, *new_request, | 2231 IsUsingLoFi(info.common_params.lofi_state, delegate_, *new_request, |
2227 resource_context, info.is_main_frame), | 2232 resource_context, info.is_main_frame), |
2228 // The original_headers field is for stale-while-revalidate but the | 2233 // The original_headers field is for stale-while-revalidate but the |
2229 // feature doesn't work with PlzNavigate, so it's just a placeholder | 2234 // feature doesn't work with PlzNavigate, so it's just a placeholder |
2230 // here. | 2235 // here. |
2231 // TODO(ricea): Make the feature work with stale-while-revalidate | 2236 // TODO(ricea): Make the feature work with stale-while-revalidate |
2232 // and clean this up. | 2237 // and clean this up. |
2233 std::string(), // original_headers | 2238 std::string(), // original_headers |
2234 info.common_params.post_data, | 2239 info.common_params.post_data, |
2235 // TODO(mek): Currently initiated_in_secure_context is only used for | 2240 // TODO(mek): Currently initiated_in_secure_context is only used for |
2236 // subresource requests, so it doesn't matter what value it gets here. | 2241 // 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 | 2242 // If in the future this changes this should be updated to somehow get a |
2238 // meaningful value. | 2243 // meaningful value. |
2239 false); // initiated_in_secure_context | 2244 false); // initiated_in_secure_context |
2240 extra_info->set_navigation_ui_data(std::move(navigation_ui_data)); | 2245 extra_info->set_navigation_ui_data(std::move(navigation_ui_data)); |
2241 | 2246 |
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. | 2247 // Request takes ownership. |
2248 extra_info->AssociateWithRequest(new_request.get()); | 2248 extra_info->AssociateWithRequest(new_request.get()); |
2249 | 2249 |
2250 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 2250 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
2251 // Hang on to a reference to ensure the blob is not released prior | 2251 // Hang on to a reference to ensure the blob is not released prior |
2252 // to the job being started. | 2252 // to the job being started. |
2253 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 2253 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
2254 new_request.get(), | 2254 new_request.get(), |
2255 blob_context->GetBlobDataFromPublicURL(new_request->url())); | 2255 blob_context->GetBlobDataFromPublicURL(new_request->url())); |
2256 } | 2256 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2297 const GlobalFrameRoutingId& global_routing_id) { | 2297 const GlobalFrameRoutingId& global_routing_id) { |
2298 CancelRequestsForRoute(global_routing_id); | 2298 CancelRequestsForRoute(global_routing_id); |
2299 } | 2299 } |
2300 | 2300 |
2301 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( | 2301 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( |
2302 int routing_id, | 2302 int routing_id, |
2303 int request_id, | 2303 int request_id, |
2304 const ResourceRequest& request, | 2304 const ResourceRequest& request, |
2305 mojom::URLLoaderAssociatedRequest mojo_request, | 2305 mojom::URLLoaderAssociatedRequest mojo_request, |
2306 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 2306 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
2307 ResourceMessageFilter* filter) { | 2307 std::unique_ptr<ResourceRequesterInfo> requester_info) { |
2308 filter_ = filter; | 2308 requester_info_ = std::move(requester_info); |
2309 OnRequestResourceInternal(routing_id, request_id, request, | 2309 OnRequestResourceInternal(routing_id, request_id, request, |
2310 std::move(mojo_request), | 2310 std::move(mojo_request), |
2311 std::move(url_loader_client)); | 2311 std::move(url_loader_client)); |
2312 filter_ = nullptr; | 2312 requester_info_.reset(); |
2313 } | 2313 } |
2314 | 2314 |
2315 void ResourceDispatcherHostImpl::OnSyncLoadWithMojo( | 2315 void ResourceDispatcherHostImpl::OnSyncLoadWithMojo( |
2316 int routing_id, | 2316 int routing_id, |
2317 int request_id, | 2317 int request_id, |
2318 const ResourceRequest& request_data, | 2318 const ResourceRequest& request_data, |
2319 ResourceMessageFilter* filter, | 2319 std::unique_ptr<ResourceRequesterInfo> requester_info, |
2320 const SyncLoadResultCallback& result_handler) { | 2320 const SyncLoadResultCallback& result_handler) { |
2321 filter_ = filter; | 2321 requester_info_ = std::move(requester_info); |
2322 BeginRequest(request_id, request_data, result_handler, routing_id, | 2322 BeginRequest(request_id, request_data, result_handler, routing_id, |
2323 nullptr, nullptr); | 2323 nullptr, nullptr); |
2324 filter_ = nullptr; | 2324 requester_info_.reset(); |
2325 } | 2325 } |
2326 | 2326 |
2327 // static | 2327 // static |
2328 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2328 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
2329 net::URLRequest* request) { | 2329 net::URLRequest* request) { |
2330 // The following fields should be a minor size contribution (experimentally | 2330 // The following fields should be a minor size contribution (experimentally |
2331 // on the order of 100). However since they are variable length, it could | 2331 // on the order of 100). However since they are variable length, it could |
2332 // in theory be a sizeable contribution. | 2332 // in theory be a sizeable contribution. |
2333 int strings_cost = request->extra_request_headers().ToString().size() + | 2333 int strings_cost = request->extra_request_headers().ToString().size() + |
2334 request->original_url().spec().size() + | 2334 request->original_url().spec().size() + |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 DCHECK(it->second->HasObserver(delegate)); | 2690 DCHECK(it->second->HasObserver(delegate)); |
2691 it->second->RemoveObserver(delegate); | 2691 it->second->RemoveObserver(delegate); |
2692 if (!it->second->might_have_observers()) { | 2692 if (!it->second->might_have_observers()) { |
2693 delete it->second; | 2693 delete it->second; |
2694 delegate_map_.erase(it); | 2694 delegate_map_.erase(it); |
2695 } | 2695 } |
2696 } | 2696 } |
2697 | 2697 |
2698 int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest( | 2698 int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest( |
2699 const ResourceRequest& request_data, | 2699 const ResourceRequest& request_data, |
2700 int child_id, | |
2701 bool is_sync_load) { | 2700 bool is_sync_load) { |
2702 int load_flags = request_data.load_flags; | 2701 int load_flags = request_data.load_flags; |
2703 | 2702 |
2704 // Although EV status is irrelevant to sub-frames and sub-resources, we have | 2703 // 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 | 2704 // 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 | 2705 // keep-alive connection created to load a sub-frame or a sub-resource could |
2707 // be reused to load a main frame. | 2706 // be reused to load a main frame. |
2708 load_flags |= net::LOAD_VERIFY_EV_CERT; | 2707 load_flags |= net::LOAD_VERIFY_EV_CERT; |
2709 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { | 2708 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { |
2710 load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED; | 2709 load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED; |
2711 } else if (request_data.resource_type == RESOURCE_TYPE_PREFETCH) { | 2710 } else if (request_data.resource_type == RESOURCE_TYPE_PREFETCH) { |
2712 load_flags |= net::LOAD_PREFETCH; | 2711 load_flags |= net::LOAD_PREFETCH; |
2713 } | 2712 } |
2714 | 2713 |
2715 if (is_sync_load) | 2714 if (is_sync_load) |
2716 load_flags |= net::LOAD_IGNORE_LIMITS; | 2715 load_flags |= net::LOAD_IGNORE_LIMITS; |
2717 | 2716 |
2718 return load_flags; | 2717 return load_flags; |
2719 } | 2718 } |
2720 | 2719 |
2721 bool ResourceDispatcherHostImpl::ShouldServiceRequest( | 2720 bool ResourceDispatcherHostImpl::ShouldServiceRequest( |
2722 int process_type, | |
2723 int child_id, | 2721 int child_id, |
2724 const ResourceRequest& request_data, | 2722 const ResourceRequest& request_data, |
2725 const net::HttpRequestHeaders& headers, | 2723 const net::HttpRequestHeaders& headers, |
2726 ResourceMessageFilter* filter, | 2724 ResourceRequesterInfo* requester_info, |
2727 ResourceContext* resource_context) { | 2725 ResourceContext* resource_context) { |
2728 ChildProcessSecurityPolicyImpl* policy = | 2726 ChildProcessSecurityPolicyImpl* policy = |
2729 ChildProcessSecurityPolicyImpl::GetInstance(); | 2727 ChildProcessSecurityPolicyImpl::GetInstance(); |
2730 | 2728 |
2731 // Check if the renderer is permitted to request the requested URL. | 2729 // Check if the renderer is permitted to request the requested URL. |
2732 if (!policy->CanRequestURL(child_id, request_data.url)) { | 2730 if (!policy->CanRequestURL(child_id, request_data.url)) { |
2733 VLOG(1) << "Denied unauthorized request for " | 2731 VLOG(1) << "Denied unauthorized request for " |
2734 << request_data.url.possibly_invalid_spec(); | 2732 << request_data.url.possibly_invalid_spec(); |
2735 return false; | 2733 return false; |
2736 } | 2734 } |
2737 | 2735 |
2738 // Check if the renderer is using an illegal Origin header. If so, kill it. | 2736 // Check if the renderer is using an illegal Origin header. If so, kill it. |
2739 std::string origin_string; | 2737 std::string origin_string; |
2740 bool has_origin = | 2738 bool has_origin = |
2741 headers.GetHeader("Origin", &origin_string) && origin_string != "null"; | 2739 headers.GetHeader("Origin", &origin_string) && origin_string != "null"; |
2742 if (has_origin) { | 2740 if (has_origin) { |
2743 GURL origin(origin_string); | 2741 GURL origin(origin_string); |
2744 if (!policy->CanSetAsOriginHeader(child_id, origin)) { | 2742 if (!policy->CanSetAsOriginHeader(child_id, origin)) { |
2745 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; | 2743 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; |
2746 bad_message::ReceivedBadMessage(filter, bad_message::RDH_ILLEGAL_ORIGIN); | 2744 bad_message::ReceivedBadMessage(requester_info->filter(), |
2745 bad_message::RDH_ILLEGAL_ORIGIN); | |
2747 return false; | 2746 return false; |
2748 } | 2747 } |
2749 } | 2748 } |
2750 | 2749 |
2751 // Check if the renderer is permitted to upload the requested files. | 2750 // Check if the renderer is permitted to upload the requested files. |
2752 if (request_data.request_body.get()) { | 2751 if (request_data.request_body.get()) { |
2753 const std::vector<ResourceRequestBodyImpl::Element>* uploads = | 2752 const std::vector<ResourceRequestBodyImpl::Element>* uploads = |
2754 request_data.request_body->elements(); | 2753 request_data.request_body->elements(); |
2755 std::vector<ResourceRequestBodyImpl::Element>::const_iterator iter; | 2754 std::vector<ResourceRequestBodyImpl::Element>::const_iterator iter; |
2756 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { | 2755 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { |
2757 if (iter->type() == ResourceRequestBodyImpl::Element::TYPE_FILE && | 2756 if (iter->type() == ResourceRequestBodyImpl::Element::TYPE_FILE && |
2758 !policy->CanReadFile(child_id, iter->path())) { | 2757 !policy->CanReadFile(child_id, iter->path())) { |
2759 NOTREACHED() << "Denied unauthorized upload of " | 2758 NOTREACHED() << "Denied unauthorized upload of " |
2760 << iter->path().value(); | 2759 << iter->path().value(); |
2761 return false; | 2760 return false; |
2762 } | 2761 } |
2763 if (iter->type() == | 2762 if (iter->type() == |
2764 ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { | 2763 ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { |
2765 storage::FileSystemURL url = | 2764 storage::FileSystemURL url = |
2766 filter->file_system_context()->CrackURL(iter->filesystem_url()); | 2765 requester_info->file_system_context()->CrackURL( |
2766 iter->filesystem_url()); | |
2767 if (!policy->CanReadFileSystemFile(child_id, url)) { | 2767 if (!policy->CanReadFileSystemFile(child_id, url)) { |
2768 NOTREACHED() << "Denied unauthorized upload of " | 2768 NOTREACHED() << "Denied unauthorized upload of " |
2769 << iter->filesystem_url().spec(); | 2769 << iter->filesystem_url().spec(); |
2770 return false; | 2770 return false; |
2771 } | 2771 } |
2772 } | 2772 } |
2773 } | 2773 } |
2774 } | 2774 } |
2775 return true; | 2775 return true; |
2776 } | 2776 } |
(...skipping 14 matching lines...) Expand all Loading... | |
2791 &throttles); | 2791 &throttles); |
2792 if (!throttles.empty()) { | 2792 if (!throttles.empty()) { |
2793 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2793 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2794 std::move(throttles))); | 2794 std::move(throttles))); |
2795 } | 2795 } |
2796 } | 2796 } |
2797 return handler; | 2797 return handler; |
2798 } | 2798 } |
2799 | 2799 |
2800 } // namespace content | 2800 } // namespace content |
OLD | NEW |