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 21 matching lines...) Expand all Loading... |
32 #include "base/profiler/scoped_tracker.h" | 32 #include "base/profiler/scoped_tracker.h" |
33 #include "base/stl_util.h" | 33 #include "base/stl_util.h" |
34 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
35 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 35 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
36 #include "base/threading/thread_task_runner_handle.h" | 36 #include "base/threading/thread_task_runner_handle.h" |
37 #include "base/timer/timer.h" | 37 #include "base/timer/timer.h" |
38 #include "content/browser/appcache/appcache_interceptor.h" | 38 #include "content/browser/appcache/appcache_interceptor.h" |
39 #include "content/browser/appcache/appcache_navigation_handle_core.h" | 39 #include "content/browser/appcache/appcache_navigation_handle_core.h" |
40 #include "content/browser/appcache/chrome_appcache_service.h" | 40 #include "content/browser/appcache/chrome_appcache_service.h" |
41 #include "content/browser/bad_message.h" | 41 #include "content/browser/bad_message.h" |
42 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | |
43 #include "content/browser/browsing_data/clear_site_data_throttle.h" | 42 #include "content/browser/browsing_data/clear_site_data_throttle.h" |
44 #include "content/browser/child_process_security_policy_impl.h" | 43 #include "content/browser/child_process_security_policy_impl.h" |
45 #include "content/browser/frame_host/navigation_request_info.h" | 44 #include "content/browser/frame_host/navigation_request_info.h" |
46 #include "content/browser/loader/async_resource_handler.h" | 45 #include "content/browser/loader/async_resource_handler.h" |
47 #include "content/browser/loader/detachable_resource_handler.h" | 46 #include "content/browser/loader/detachable_resource_handler.h" |
48 #include "content/browser/loader/intercepting_resource_handler.h" | 47 #include "content/browser/loader/intercepting_resource_handler.h" |
49 #include "content/browser/loader/loader_delegate.h" | 48 #include "content/browser/loader/loader_delegate.h" |
50 #include "content/browser/loader/mime_sniffing_resource_handler.h" | 49 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
51 #include "content/browser/loader/mojo_async_resource_handler.h" | 50 #include "content/browser/loader/mojo_async_resource_handler.h" |
52 #include "content/browser/loader/navigation_resource_handler.h" | 51 #include "content/browser/loader/navigation_resource_handler.h" |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 headers.AddHeadersFromString(request_data.headers); | 1151 headers.AddHeadersFromString(request_data.headers); |
1153 | 1152 |
1154 if (is_shutdown_ || | 1153 if (is_shutdown_ || |
1155 !ShouldServiceRequest(child_id, request_data, headers, requester_info, | 1154 !ShouldServiceRequest(child_id, request_data, headers, requester_info, |
1156 resource_context)) { | 1155 resource_context)) { |
1157 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, | 1156 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, |
1158 request_id, std::move(url_loader_client)); | 1157 request_id, std::move(url_loader_client)); |
1159 return; | 1158 return; |
1160 } | 1159 } |
1161 | 1160 |
| 1161 std::unique_ptr<BlobHandles> blob_handles; |
1162 if (!is_navigation_stream_request) { | 1162 if (!is_navigation_stream_request) { |
1163 storage::BlobStorageContext* blob_context = | 1163 storage::BlobStorageContext* blob_context = |
1164 GetBlobStorageContext(requester_info->blob_storage_context()); | 1164 GetBlobStorageContext(requester_info->blob_storage_context()); |
1165 // Resolve elements from request_body and prepare upload data. | 1165 // Resolve elements from request_body and prepare upload data. |
1166 if (request_data.request_body.get()) { | 1166 if (request_data.request_body.get()) { |
1167 // |blob_context| could be null when the request is from the plugins | 1167 // |blob_context| could be null when the request is from the plugins |
1168 // because ResourceMessageFilters created in PluginProcessHost don't have | 1168 // because ResourceMessageFilters created in PluginProcessHost don't have |
1169 // the blob context. | 1169 // the blob context. |
1170 if (blob_context) { | 1170 if (blob_context) { |
1171 // Attaches the BlobDataHandles to request_body not to free the blobs | 1171 // Attaches the BlobDataHandles to request_body not to free the blobs |
1172 // and any attached shareable files until upload completion. These data | 1172 // and any attached shareable files until upload completion. These data |
1173 // will be used in UploadDataStream and ServiceWorkerURLRequestJob. | 1173 // will be used in UploadDataStream and ServiceWorkerURLRequestJob. |
1174 bool blobs_alive = AttachRequestBodyBlobDataHandles( | 1174 blob_handles = GetBodyBlobDataHandles(request_data.request_body.get(), |
1175 request_data.request_body.get(), resource_context); | 1175 resource_context); |
1176 if (!blobs_alive) { | 1176 if (!blob_handles) { |
1177 AbortRequestBeforeItStarts(requester_info->filter(), | 1177 AbortRequestBeforeItStarts(requester_info->filter(), |
1178 sync_result_handler, request_id, | 1178 sync_result_handler, request_id, |
1179 std::move(url_loader_client)); | 1179 std::move(url_loader_client)); |
1180 return; | 1180 return; |
1181 } | 1181 } |
1182 } | 1182 } |
1183 } | 1183 } |
1184 | 1184 |
1185 // Check if we have a registered interceptor for the headers passed in. If | 1185 // Check if we have a registered interceptor for the headers passed in. If |
1186 // yes then we need to mark the current request as pending and wait for the | 1186 // yes then we need to mark the current request as pending and wait for the |
(...skipping 12 matching lines...) Expand all Loading... |
1199 base::CompareCase::INSENSITIVE_ASCII); | 1199 base::CompareCase::INSENSITIVE_ASCII); |
1200 } | 1200 } |
1201 if (call_interceptor) { | 1201 if (call_interceptor) { |
1202 interceptor_info.interceptor.Run( | 1202 interceptor_info.interceptor.Run( |
1203 it.name(), it.value(), child_id, resource_context, | 1203 it.name(), it.value(), child_id, resource_context, |
1204 base::Bind( | 1204 base::Bind( |
1205 &ResourceDispatcherHostImpl::ContinuePendingBeginRequest, | 1205 &ResourceDispatcherHostImpl::ContinuePendingBeginRequest, |
1206 base::Unretained(this), make_scoped_refptr(requester_info), | 1206 base::Unretained(this), make_scoped_refptr(requester_info), |
1207 request_id, request_data, sync_result_handler, route_id, | 1207 request_id, request_data, sync_result_handler, route_id, |
1208 headers, base::Passed(std::move(mojo_request)), | 1208 headers, base::Passed(std::move(mojo_request)), |
1209 base::Passed(std::move(url_loader_client)))); | 1209 base::Passed(std::move(url_loader_client)), |
| 1210 base::Passed(std::move(blob_handles)))); |
1210 return; | 1211 return; |
1211 } | 1212 } |
1212 } | 1213 } |
1213 } | 1214 } |
1214 } | 1215 } |
1215 ContinuePendingBeginRequest( | 1216 ContinuePendingBeginRequest( |
1216 requester_info, request_id, request_data, sync_result_handler, route_id, | 1217 requester_info, request_id, request_data, sync_result_handler, route_id, |
1217 headers, std::move(mojo_request), std::move(url_loader_client), | 1218 headers, std::move(mojo_request), std::move(url_loader_client), |
1218 HeaderInterceptorResult::CONTINUE); | 1219 std::move(blob_handles), HeaderInterceptorResult::CONTINUE); |
1219 } | 1220 } |
1220 | 1221 |
1221 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( | 1222 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( |
1222 scoped_refptr<ResourceRequesterInfo> requester_info, | 1223 scoped_refptr<ResourceRequesterInfo> requester_info, |
1223 int request_id, | 1224 int request_id, |
1224 const ResourceRequest& request_data, | 1225 const ResourceRequest& request_data, |
1225 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1226 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
1226 int route_id, | 1227 int route_id, |
1227 const net::HttpRequestHeaders& headers, | 1228 const net::HttpRequestHeaders& headers, |
1228 mojom::URLLoaderAssociatedRequest mojo_request, | 1229 mojom::URLLoaderAssociatedRequest mojo_request, |
1229 mojom::URLLoaderClientPtr url_loader_client, | 1230 mojom::URLLoaderClientPtr url_loader_client, |
| 1231 std::unique_ptr<BlobHandles> blob_handles, |
1230 HeaderInterceptorResult interceptor_result) { | 1232 HeaderInterceptorResult interceptor_result) { |
1231 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); | 1233 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1232 if (interceptor_result != HeaderInterceptorResult::CONTINUE) { | 1234 if (interceptor_result != HeaderInterceptorResult::CONTINUE) { |
1233 if (requester_info->IsRenderer() && | 1235 if (requester_info->IsRenderer() && |
1234 interceptor_result == HeaderInterceptorResult::KILL) { | 1236 interceptor_result == HeaderInterceptorResult::KILL) { |
1235 // TODO(ananta): Find a way to specify the right error code here. Passing | 1237 // TODO(ananta): Find a way to specify the right error code here. Passing |
1236 // in a non-content error code is not safe, but future header interceptors | 1238 // in a non-content error code is not safe, but future header interceptors |
1237 // might say to kill for reasons other than illegal origins. | 1239 // might say to kill for reasons other than illegal origins. |
1238 bad_message::ReceivedBadMessage(requester_info->filter(), | 1240 bad_message::ReceivedBadMessage(requester_info->filter(), |
1239 bad_message::RDH_ILLEGAL_ORIGIN); | 1241 bad_message::RDH_ILLEGAL_ORIGIN); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 false, // is stream | 1402 false, // is stream |
1401 allow_download, request_data.has_user_gesture, | 1403 allow_download, request_data.has_user_gesture, |
1402 request_data.enable_load_timing, request_data.enable_upload_progress, | 1404 request_data.enable_load_timing, request_data.enable_upload_progress, |
1403 do_not_prompt_for_login, request_data.referrer_policy, | 1405 do_not_prompt_for_login, request_data.referrer_policy, |
1404 request_data.visibility_state, resource_context, report_raw_headers, | 1406 request_data.visibility_state, resource_context, report_raw_headers, |
1405 !is_sync_load, | 1407 !is_sync_load, |
1406 GetPreviewsState(request_data.previews_state, delegate_, *new_request, | 1408 GetPreviewsState(request_data.previews_state, delegate_, *new_request, |
1407 resource_context, | 1409 resource_context, |
1408 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), | 1410 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME), |
1409 request_data.request_body, request_data.initiated_in_secure_context); | 1411 request_data.request_body, request_data.initiated_in_secure_context); |
| 1412 extra_info->SetBlobHandles(std::move(blob_handles)); |
1410 // Request takes ownership. | 1413 // Request takes ownership. |
1411 extra_info->AssociateWithRequest(new_request.get()); | 1414 extra_info->AssociateWithRequest(new_request.get()); |
1412 | 1415 |
1413 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1416 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1414 // Hang on to a reference to ensure the blob is not released prior | 1417 // Hang on to a reference to ensure the blob is not released prior |
1415 // to the job being started. | 1418 // to the job being started. |
1416 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1419 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1417 new_request.get(), requester_info->blob_storage_context() | 1420 new_request.get(), requester_info->blob_storage_context() |
1418 ->context() | 1421 ->context() |
1419 ->GetBlobDataFromPublicURL(new_request->url())); | 1422 ->GetBlobDataFromPublicURL(new_request->url())); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 headers.AddHeadersFromString(info.begin_params.headers); | 2111 headers.AddHeadersFromString(info.begin_params.headers); |
2109 new_request->SetExtraRequestHeaders(headers); | 2112 new_request->SetExtraRequestHeaders(headers); |
2110 | 2113 |
2111 new_request->SetLoadFlags(load_flags); | 2114 new_request->SetLoadFlags(load_flags); |
2112 | 2115 |
2113 storage::BlobStorageContext* blob_context = GetBlobStorageContext( | 2116 storage::BlobStorageContext* blob_context = GetBlobStorageContext( |
2114 GetChromeBlobStorageContextForResourceContext(resource_context)); | 2117 GetChromeBlobStorageContextForResourceContext(resource_context)); |
2115 | 2118 |
2116 // Resolve elements from request_body and prepare upload data. | 2119 // Resolve elements from request_body and prepare upload data. |
2117 ResourceRequestBodyImpl* body = info.common_params.post_data.get(); | 2120 ResourceRequestBodyImpl* body = info.common_params.post_data.get(); |
| 2121 std::unique_ptr<BlobHandles> blob_handles; |
2118 if (body) { | 2122 if (body) { |
2119 bool blobs_alive = AttachRequestBodyBlobDataHandles(body, resource_context); | 2123 blob_handles = GetBodyBlobDataHandles(body, resource_context); |
2120 if (!blobs_alive) { | 2124 if (!blob_handles) { |
2121 new_request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); | 2125 new_request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
2122 loader->NotifyRequestFailed(false, net::ERR_ABORTED); | 2126 loader->NotifyRequestFailed(false, net::ERR_ABORTED); |
2123 return; | 2127 return; |
2124 } | 2128 } |
2125 new_request->set_upload(UploadDataStreamBuilder::Build( | 2129 new_request->set_upload(UploadDataStreamBuilder::Build( |
2126 body, blob_context, upload_file_system_context, | 2130 body, blob_context, upload_file_system_context, |
2127 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); | 2131 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); |
2128 } | 2132 } |
2129 | 2133 |
2130 // Make extra info and read footer (contains request ID). | 2134 // Make extra info and read footer (contains request ID). |
(...skipping 25 matching lines...) Expand all Loading... |
2156 resource_context, info.report_raw_headers, | 2160 resource_context, info.report_raw_headers, |
2157 true, // is_async | 2161 true, // is_async |
2158 GetPreviewsState(info.common_params.previews_state, delegate_, | 2162 GetPreviewsState(info.common_params.previews_state, delegate_, |
2159 *new_request, resource_context, info.is_main_frame), | 2163 *new_request, resource_context, info.is_main_frame), |
2160 info.common_params.post_data, | 2164 info.common_params.post_data, |
2161 // TODO(mek): Currently initiated_in_secure_context is only used for | 2165 // TODO(mek): Currently initiated_in_secure_context is only used for |
2162 // subresource requests, so it doesn't matter what value it gets here. | 2166 // subresource requests, so it doesn't matter what value it gets here. |
2163 // If in the future this changes this should be updated to somehow get a | 2167 // If in the future this changes this should be updated to somehow get a |
2164 // meaningful value. | 2168 // meaningful value. |
2165 false); // initiated_in_secure_context | 2169 false); // initiated_in_secure_context |
| 2170 extra_info->SetBlobHandles(std::move(blob_handles)); |
2166 extra_info->set_navigation_ui_data(std::move(navigation_ui_data)); | 2171 extra_info->set_navigation_ui_data(std::move(navigation_ui_data)); |
2167 | 2172 |
2168 // Request takes ownership. | 2173 // Request takes ownership. |
2169 extra_info->AssociateWithRequest(new_request.get()); | 2174 extra_info->AssociateWithRequest(new_request.get()); |
2170 | 2175 |
2171 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 2176 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
2172 // Hang on to a reference to ensure the blob is not released prior | 2177 // Hang on to a reference to ensure the blob is not released prior |
2173 // to the job being started. | 2178 // to the job being started. |
2174 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 2179 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
2175 new_request.get(), | 2180 new_request.get(), |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 if (iter->second > 2) { | 2783 if (iter->second > 2) { |
2779 active_tabs++; | 2784 active_tabs++; |
2780 if (active_tabs >= 2) | 2785 if (active_tabs >= 2) |
2781 return true; | 2786 return true; |
2782 } | 2787 } |
2783 } | 2788 } |
2784 return false; | 2789 return false; |
2785 } | 2790 } |
2786 | 2791 |
2787 } // namespace content | 2792 } // namespace content |
OLD | NEW |