Chromium Code Reviews| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "content/browser/child_process_security_policy_impl.h" | 29 #include "content/browser/child_process_security_policy_impl.h" |
| 30 #include "content/browser/download/download_resource_handler.h" | 30 #include "content/browser/download/download_resource_handler.h" |
| 31 #include "content/browser/download/save_file_manager.h" | 31 #include "content/browser/download/save_file_manager.h" |
| 32 #include "content/browser/download/save_file_resource_handler.h" | 32 #include "content/browser/download/save_file_resource_handler.h" |
| 33 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 33 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 34 #include "content/browser/frame_host/navigation_request_info.h" | 34 #include "content/browser/frame_host/navigation_request_info.h" |
| 35 #include "content/browser/loader/async_resource_handler.h" | 35 #include "content/browser/loader/async_resource_handler.h" |
| 36 #include "content/browser/loader/buffered_resource_handler.h" | 36 #include "content/browser/loader/buffered_resource_handler.h" |
| 37 #include "content/browser/loader/cross_site_resource_handler.h" | 37 #include "content/browser/loader/cross_site_resource_handler.h" |
| 38 #include "content/browser/loader/detachable_resource_handler.h" | 38 #include "content/browser/loader/detachable_resource_handler.h" |
| 39 #include "content/browser/loader/navigation_resource_handler.h" | |
| 40 #include "content/browser/loader/navigation_url_loader_core.h" | |
| 39 #include "content/browser/loader/power_save_block_resource_throttle.h" | 41 #include "content/browser/loader/power_save_block_resource_throttle.h" |
| 40 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 42 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
| 41 #include "content/browser/loader/resource_message_filter.h" | 43 #include "content/browser/loader/resource_message_filter.h" |
| 42 #include "content/browser/loader/resource_request_info_impl.h" | 44 #include "content/browser/loader/resource_request_info_impl.h" |
| 43 #include "content/browser/loader/stream_resource_handler.h" | 45 #include "content/browser/loader/stream_resource_handler.h" |
| 44 #include "content/browser/loader/sync_resource_handler.h" | 46 #include "content/browser/loader/sync_resource_handler.h" |
| 45 #include "content/browser/loader/throttling_resource_handler.h" | 47 #include "content/browser/loader/throttling_resource_handler.h" |
| 46 #include "content/browser/loader/upload_data_stream_builder.h" | 48 #include "content/browser/loader/upload_data_stream_builder.h" |
| 47 #include "content/browser/renderer_host/render_view_host_delegate.h" | 49 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 48 #include "content/browser/renderer_host/render_view_host_impl.h" | 50 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 49 #include "content/browser/resource_context_impl.h" | 51 #include "content/browser/resource_context_impl.h" |
| 50 #include "content/browser/service_worker/service_worker_request_handler.h" | 52 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 51 #include "content/browser/streams/stream.h" | 53 #include "content/browser/streams/stream.h" |
| 52 #include "content/browser/streams/stream_context.h" | 54 #include "content/browser/streams/stream_context.h" |
| 53 #include "content/browser/streams/stream_registry.h" | 55 #include "content/browser/streams/stream_registry.h" |
| 54 #include "content/browser/web_contents/web_contents_impl.h" | 56 #include "content/browser/web_contents/web_contents_impl.h" |
| 55 #include "content/common/appcache_interfaces.h" | 57 #include "content/common/appcache_interfaces.h" |
| 56 #include "content/common/resource_messages.h" | 58 #include "content/common/resource_messages.h" |
| 57 #include "content/common/ssl_status_serialization.h" | 59 #include "content/common/ssl_status_serialization.h" |
| 58 #include "content/common/view_messages.h" | 60 #include "content/common/view_messages.h" |
| 59 #include "content/public/browser/browser_thread.h" | 61 #include "content/public/browser/browser_thread.h" |
| 60 #include "content/public/browser/content_browser_client.h" | 62 #include "content/public/browser/content_browser_client.h" |
| 61 #include "content/public/browser/download_manager.h" | 63 #include "content/public/browser/download_manager.h" |
| 62 #include "content/public/browser/download_url_parameters.h" | 64 #include "content/public/browser/download_url_parameters.h" |
| 63 #include "content/public/browser/global_request_id.h" | 65 #include "content/public/browser/global_request_id.h" |
| 64 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 66 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 65 #include "content/public/browser/resource_request_details.h" | 67 #include "content/public/browser/resource_request_details.h" |
| 66 #include "content/public/browser/resource_throttle.h" | 68 #include "content/public/browser/resource_throttle.h" |
| 67 #include "content/public/browser/stream_handle.h" | 69 #include "content/public/browser/stream_handle.h" |
| 70 #include "content/public/browser/stream_info.h" | |
| 68 #include "content/public/browser/user_metrics.h" | 71 #include "content/public/browser/user_metrics.h" |
| 69 #include "content/public/common/content_switches.h" | 72 #include "content/public/common/content_switches.h" |
| 70 #include "content/public/common/process_type.h" | 73 #include "content/public/common/process_type.h" |
| 71 #include "ipc/ipc_message_macros.h" | 74 #include "ipc/ipc_message_macros.h" |
| 72 #include "ipc/ipc_message_start.h" | 75 #include "ipc/ipc_message_start.h" |
| 73 #include "net/base/auth.h" | 76 #include "net/base/auth.h" |
| 74 #include "net/base/load_flags.h" | 77 #include "net/base/load_flags.h" |
| 75 #include "net/base/mime_util.h" | 78 #include "net/base/mime_util.h" |
| 76 #include "net/base/net_errors.h" | 79 #include "net/base/net_errors.h" |
| 77 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 80 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 return; | 299 return; |
| 297 web_contents->DidGetResourceResponseStart(*details.get()); | 300 web_contents->DidGetResourceResponseStart(*details.get()); |
| 298 } | 301 } |
| 299 | 302 |
| 300 bool IsValidatedSCT( | 303 bool IsValidatedSCT( |
| 301 const net::SignedCertificateTimestampAndStatus& sct_status) { | 304 const net::SignedCertificateTimestampAndStatus& sct_status) { |
| 302 return sct_status.status == net::ct::SCT_STATUS_OK; | 305 return sct_status.status == net::ct::SCT_STATUS_OK; |
| 303 } | 306 } |
| 304 | 307 |
| 305 storage::BlobStorageContext* GetBlobStorageContext( | 308 storage::BlobStorageContext* GetBlobStorageContext( |
| 306 ResourceMessageFilter* filter) { | 309 ChromeBlobStorageContext* blob_storage_context) { |
| 307 if (!filter->blob_storage_context()) | 310 if (!blob_storage_context) |
| 308 return NULL; | 311 return NULL; |
| 309 return filter->blob_storage_context()->context(); | 312 return blob_storage_context->context(); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void AttachRequestBodyBlobDataHandles( | 315 void AttachRequestBodyBlobDataHandles( |
| 313 ResourceRequestBody* body, | 316 ResourceRequestBody* body, |
| 314 storage::BlobStorageContext* blob_context) { | 317 storage::BlobStorageContext* blob_context) { |
| 315 DCHECK(blob_context); | 318 DCHECK(blob_context); |
| 316 for (size_t i = 0; i < body->elements()->size(); ++i) { | 319 for (size_t i = 0; i < body->elements()->size(); ++i) { |
| 317 const ResourceRequestBody::Element& element = (*body->elements())[i]; | 320 const ResourceRequestBody::Element& element = (*body->elements())[i]; |
| 318 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) | 321 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) |
| 319 continue; | 322 continue; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 delete loaders; | 463 delete loaders; |
| 461 } else { | 464 } else { |
| 462 ++i; | 465 ++i; |
| 463 } | 466 } |
| 464 } | 467 } |
| 465 | 468 |
| 466 #ifndef NDEBUG | 469 #ifndef NDEBUG |
| 467 for (LoaderList::iterator i = loaders_to_cancel.begin(); | 470 for (LoaderList::iterator i = loaders_to_cancel.begin(); |
| 468 i != loaders_to_cancel.end(); ++i) { | 471 i != loaders_to_cancel.end(); ++i) { |
| 469 // There is no strict requirement that this be the case, but currently | 472 // There is no strict requirement that this be the case, but currently |
| 470 // downloads, streams, detachable requests, and transferred requests are the | 473 // downloads, streams, detachable requests, transferred requests, and |
| 471 // only requests that aren't cancelled when the associated processes go | 474 // browser-owned requests are the only requests that aren't cancelled when |
| 472 // away. It may be OK for this invariant to change in the future, but if | 475 // the associated processes go away. It may be OK for this invariant to |
| 473 // this assertion fires without the invariant changing, then it's indicative | 476 // change in the future, but if this assertion fires without the invariant |
| 474 // of a leak. | 477 // changing, then it's indicative of a leak. |
| 475 DCHECK((*i)->GetRequestInfo()->IsDownload() || | 478 DCHECK((*i)->GetRequestInfo()->IsDownload() || |
| 476 (*i)->GetRequestInfo()->is_stream() || | 479 (*i)->GetRequestInfo()->is_stream() || |
| 477 ((*i)->GetRequestInfo()->detachable_handler() && | 480 ((*i)->GetRequestInfo()->detachable_handler() && |
| 478 (*i)->GetRequestInfo()->detachable_handler()->is_detached()) || | 481 (*i)->GetRequestInfo()->detachable_handler()->is_detached()) || |
| 482 (*i)->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER || | |
| 479 (*i)->is_transferring()); | 483 (*i)->is_transferring()); |
| 480 } | 484 } |
| 481 #endif | 485 #endif |
| 482 | 486 |
| 483 loaders_to_cancel.clear(); | 487 loaders_to_cancel.clear(); |
| 484 | 488 |
| 485 // Validate that no more requests for this context were added. | 489 // Validate that no more requests for this context were added. |
| 486 for (LoaderMap::const_iterator i = pending_loaders_.begin(); | 490 for (LoaderMap::const_iterator i = pending_loaders_.begin(); |
| 487 i != pending_loaders_.end(); ++i) { | 491 i != pending_loaders_.end(); ++i) { |
| 488 // http://crbug.com/90971 | 492 // http://crbug.com/90971 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 | 660 |
| 657 StreamContext* stream_context = | 661 StreamContext* stream_context = |
| 658 GetStreamContextForResourceContext(info->GetContext()); | 662 GetStreamContextForResourceContext(info->GetContext()); |
| 659 | 663 |
| 660 scoped_ptr<StreamResourceHandler> handler( | 664 scoped_ptr<StreamResourceHandler> handler( |
| 661 new StreamResourceHandler(request, | 665 new StreamResourceHandler(request, |
| 662 stream_context->registry(), | 666 stream_context->registry(), |
| 663 origin)); | 667 origin)); |
| 664 | 668 |
| 665 info->set_is_stream(true); | 669 info->set_is_stream(true); |
| 666 delegate_->OnStreamCreated( | 670 scoped_ptr<StreamInfo> stream_info(new StreamInfo); |
| 667 request, | 671 stream_info->handle = handler->stream()->CreateHandle(); |
| 668 handler->stream()->CreateHandle( | 672 stream_info->original_url = request->url(); |
| 669 request->url(), | 673 stream_info->mime_type = mime_type; |
| 670 mime_type, | 674 // Make a copy of the response headers so it is safe to pass across threads; |
| 671 response->head.headers)); | 675 // the old handler (AsyncResourceHandler) may modify it in parallel via the |
| 676 // ResourceDispatcherHostDelegate. | |
| 677 stream_info->response_headers = | |
| 678 new net::HttpResponseHeaders(response->head.headers->raw_headers()); | |
| 679 delegate_->OnStreamCreated(request, stream_info.Pass()); | |
| 672 return handler.PassAs<ResourceHandler>(); | 680 return handler.PassAs<ResourceHandler>(); |
| 673 } | 681 } |
| 674 | 682 |
| 675 void ResourceDispatcherHostImpl::ClearSSLClientAuthHandlerForRequest( | 683 void ResourceDispatcherHostImpl::ClearSSLClientAuthHandlerForRequest( |
| 676 net::URLRequest* request) { | 684 net::URLRequest* request) { |
| 677 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 685 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 678 if (info) { | 686 if (info) { |
| 679 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); | 687 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); |
| 680 if (loader) | 688 if (loader) |
| 681 loader->ClearSSLClientAuthHandler(); | 689 loader->ClearSSLClientAuthHandler(); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1074 const Referrer referrer(request_data.referrer, request_data.referrer_policy); | 1082 const Referrer referrer(request_data.referrer, request_data.referrer_policy); |
| 1075 SetReferrerForRequest(new_request.get(), referrer); | 1083 SetReferrerForRequest(new_request.get(), referrer); |
| 1076 | 1084 |
| 1077 net::HttpRequestHeaders headers; | 1085 net::HttpRequestHeaders headers; |
| 1078 headers.AddHeadersFromString(request_data.headers); | 1086 headers.AddHeadersFromString(request_data.headers); |
| 1079 new_request->SetExtraRequestHeaders(headers); | 1087 new_request->SetExtraRequestHeaders(headers); |
| 1080 | 1088 |
| 1081 new_request->SetLoadFlags(load_flags); | 1089 new_request->SetLoadFlags(load_flags); |
| 1082 | 1090 |
| 1083 storage::BlobStorageContext* blob_context = | 1091 storage::BlobStorageContext* blob_context = |
| 1084 GetBlobStorageContext(filter_); | 1092 GetBlobStorageContext(filter_->blob_storage_context()); |
| 1085 // Resolve elements from request_body and prepare upload data. | 1093 // Resolve elements from request_body and prepare upload data. |
| 1086 if (request_data.request_body.get()) { | 1094 if (request_data.request_body.get()) { |
| 1087 // Attaches the BlobDataHandles to request_body not to free the blobs and | 1095 // Attaches the BlobDataHandles to request_body not to free the blobs and |
| 1088 // any attached shareable files until upload completion. These data will be | 1096 // any attached shareable files until upload completion. These data will be |
| 1089 // used in UploadDataStream and ServiceWorkerURLRequestJob. | 1097 // used in UploadDataStream and ServiceWorkerURLRequestJob. |
| 1090 AttachRequestBodyBlobDataHandles( | 1098 AttachRequestBodyBlobDataHandles( |
| 1091 request_data.request_body.get(), | 1099 request_data.request_body.get(), |
| 1092 blob_context); | 1100 blob_context); |
| 1093 new_request->set_upload(UploadDataStreamBuilder::Build( | 1101 new_request->set_upload(UploadDataStreamBuilder::Build( |
| 1094 request_data.request_body.get(), | 1102 request_data.request_body.get(), |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 } | 1202 } |
| 1195 | 1203 |
| 1196 // Prefetches and <a ping> requests outlive their child process. | 1204 // Prefetches and <a ping> requests outlive their child process. |
| 1197 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { | 1205 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { |
| 1198 handler.reset(new DetachableResourceHandler( | 1206 handler.reset(new DetachableResourceHandler( |
| 1199 request, | 1207 request, |
| 1200 base::TimeDelta::FromMilliseconds(kDefaultDetachableCancelDelayMs), | 1208 base::TimeDelta::FromMilliseconds(kDefaultDetachableCancelDelayMs), |
| 1201 handler.Pass())); | 1209 handler.Pass())); |
| 1202 } | 1210 } |
| 1203 | 1211 |
| 1204 // Install a CrossSiteResourceHandler for all main frame requests. This will | 1212 // If using --enable-browser-side-navigation, the CrossSiteResourceHandler is |
| 1205 // let us check whether a transfer is required and pause for the unload | 1213 // not needed. |
| 1206 // handler either if so or if a cross-process navigation is already under way. | 1214 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1207 bool is_swappable_navigation = | 1215 switches::kEnableBrowserSideNavigation)) { |
| 1208 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME; | 1216 // Install a CrossSiteResourceHandler for all main frame requests. This |
| 1209 // If we are using --site-per-process, install it for subframes as well. | 1217 // will let us check whether a transfer is required and pause for the unload |
| 1210 if (!is_swappable_navigation && | 1218 // handler either if so or if a cross-process navigation is already under |
| 1211 base::CommandLine::ForCurrentProcess()->HasSwitch( | 1219 // way. |
| 1212 switches::kSitePerProcess)) { | 1220 bool is_swappable_navigation = |
| 1213 is_swappable_navigation = | 1221 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME; |
| 1214 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; | 1222 // If we are using --site-per-process, install it for subframes as well. |
| 1223 if (!is_swappable_navigation && | |
| 1224 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1225 switches::kSitePerProcess)) { | |
| 1226 is_swappable_navigation = | |
| 1227 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; | |
| 1228 } | |
| 1229 if (is_swappable_navigation && process_type == PROCESS_TYPE_RENDERER) | |
| 1230 handler.reset(new CrossSiteResourceHandler(handler.Pass(), request)); | |
| 1215 } | 1231 } |
| 1216 if (is_swappable_navigation && process_type == PROCESS_TYPE_RENDERER) | |
| 1217 handler.reset(new CrossSiteResourceHandler(handler.Pass(), request)); | |
| 1218 | 1232 |
| 1219 // Insert a buffered event handler before the actual one. | 1233 // Insert a buffered event handler before the actual one. |
| 1220 handler.reset( | 1234 handler.reset( |
| 1221 new BufferedResourceHandler(handler.Pass(), this, request)); | 1235 new BufferedResourceHandler(handler.Pass(), this, request)); |
| 1222 | 1236 |
| 1223 ScopedVector<ResourceThrottle> throttles; | 1237 ScopedVector<ResourceThrottle> throttles; |
| 1224 if (delegate_) { | 1238 if (delegate_) { |
| 1225 delegate_->RequestBeginning(request, | 1239 delegate_->RequestBeginning(request, |
| 1226 resource_context, | 1240 resource_context, |
| 1227 filter_->appcache_service(), | 1241 filter_->appcache_service(), |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1654 return true; | 1668 return true; |
| 1655 } | 1669 } |
| 1656 | 1670 |
| 1657 void ResourceDispatcherHostImpl::FinishedWithResourcesForRequest( | 1671 void ResourceDispatcherHostImpl::FinishedWithResourcesForRequest( |
| 1658 const net::URLRequest* request_) { | 1672 const net::URLRequest* request_) { |
| 1659 const ResourceRequestInfoImpl* info = | 1673 const ResourceRequestInfoImpl* info = |
| 1660 ResourceRequestInfoImpl::ForRequest(request_); | 1674 ResourceRequestInfoImpl::ForRequest(request_); |
| 1661 IncrementOutstandingRequestsCount(-1, *info); | 1675 IncrementOutstandingRequestsCount(-1, *info); |
| 1662 } | 1676 } |
| 1663 | 1677 |
| 1664 void ResourceDispatcherHostImpl::StartNavigationRequest( | 1678 void ResourceDispatcherHostImpl::BeginNavigationRequest( |
| 1679 ResourceContext* resource_context, | |
| 1680 int64 frame_tree_node_id, | |
| 1665 const NavigationRequestInfo& info, | 1681 const NavigationRequestInfo& info, |
| 1666 scoped_refptr<ResourceRequestBody> request_body, | 1682 scoped_refptr<ResourceRequestBody> request_body, |
| 1667 int64 navigation_request_id, | 1683 NavigationURLLoaderCore* loader) { |
| 1668 int64 frame_node_id) { | 1684 // BeginNavigationRequest currently should only be used for the browser-side |
| 1669 NOTIMPLEMENTED(); | 1685 // navigations project. |
| 1670 } | 1686 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1687 switches::kEnableBrowserSideNavigation)); | |
| 1671 | 1688 |
| 1672 void ResourceDispatcherHostImpl::CancelNavigationRequest( | 1689 ResourceType resource_type = info.is_main_frame ? |
| 1673 int64 navigation_request_id, | 1690 RESOURCE_TYPE_MAIN_FRAME : RESOURCE_TYPE_SUB_FRAME; |
| 1674 int64 frame_node_id) { | 1691 |
| 1675 NOTIMPLEMENTED(); | 1692 if (is_shutdown_ || |
| 1693 // TODO(davidben): Check ShouldServiceRequest here. This is important; it | |
| 1694 // needs to be checked relative to the child that /requested/ the | |
| 1695 // navigation. It's where file upload checks, etc., come in. | |
| 1696 (delegate_ && !delegate_->ShouldBeginRequest( | |
| 1697 info.navigation_params.method, | |
| 1698 info.navigation_params.url, | |
| 1699 resource_type, | |
| 1700 resource_context))) { | |
| 1701 loader->RequestFailedOnIOThread(net::ERR_ABORTED); | |
| 1702 return; | |
| 1703 } | |
| 1704 | |
| 1705 // http://crbug.com/90971 | |
| 1706 char url_buf[128]; | |
| 1707 base::strlcpy( | |
| 1708 url_buf, info.navigation_params.url.spec().c_str(), arraysize(url_buf)); | |
| 1709 base::debug::Alias(url_buf); | |
| 1710 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | |
| 1711 | |
| 1712 const net::URLRequestContext* request_context = | |
| 1713 resource_context->GetRequestContext(); | |
| 1714 | |
| 1715 int load_flags = info.navigation_params.load_flags; | |
| 1716 load_flags |= net::LOAD_VERIFY_EV_CERT; | |
| 1717 if (info.is_main_frame) { | |
| 1718 load_flags |= net::LOAD_MAIN_FRAME; | |
| 1719 } else { | |
| 1720 load_flags |= net::LOAD_SUB_FRAME; | |
| 1721 } | |
| 1722 // Add a flag to selectively bypass the data reduction proxy if the resource | |
| 1723 // type is not an image. | |
| 1724 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | |
| 1725 | |
| 1726 // TODO(davidben): BuildLoadFlagsForRequest includes logic for | |
| 1727 // CanSendCookiesForOrigin and CanReadRawCookies. Is this needed here? | |
| 1728 | |
| 1729 // Sync loads should have maximum priority and should be the only | |
| 1730 // requests that have the ignore limits flag set. | |
| 1731 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); | |
| 1732 | |
| 1733 // TODO(davidben): OverrideCookieStoreForRenderProcess handling for | |
| 1734 // prerender. There isn't a renderer process yet, so we need to use the | |
| 1735 // ResourceContext or something. | |
| 1736 scoped_ptr<net::URLRequest> new_request; | |
| 1737 new_request = request_context->CreateRequest( | |
| 1738 info.navigation_params.url, net::HIGHEST, NULL, NULL); | |
| 1739 | |
| 1740 new_request->set_method(info.navigation_params.method); | |
| 1741 new_request->set_first_party_for_cookies( | |
| 1742 info.first_party_for_cookies); | |
| 1743 if (info.is_main_frame) { | |
| 1744 new_request->set_first_party_url_policy( | |
| 1745 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); | |
| 1746 } | |
| 1747 | |
| 1748 SetReferrerForRequest(new_request.get(), info.navigation_params.referrer); | |
| 1749 | |
| 1750 net::HttpRequestHeaders headers; | |
| 1751 headers.AddHeadersFromString(info.navigation_params.headers); | |
| 1752 new_request->SetExtraRequestHeaders(headers); | |
| 1753 | |
| 1754 new_request->SetLoadFlags(load_flags); | |
| 1755 | |
| 1756 // Resolve elements from request_body and prepare upload data. | |
| 1757 if (info.navigation_params.request_body.get()) { | |
| 1758 storage::BlobStorageContext* blob_context = GetBlobStorageContext( | |
| 1759 GetChromeBlobStorageContextForResourceContext(resource_context)); | |
| 1760 AttachRequestBodyBlobDataHandles( | |
| 1761 info.navigation_params.request_body.get(), | |
| 1762 blob_context); | |
| 1763 // TODO(davidben): The FileSystemContext is NULL here. In the case where | |
| 1764 // another renderer requested this navigation, this should be the same | |
| 1765 // FileSystemContext passed into ShouldServiceRequest. | |
| 1766 new_request->set_upload(UploadDataStreamBuilder::Build( | |
| 1767 info.navigation_params.request_body.get(), | |
| 1768 blob_context, | |
| 1769 NULL, // file_system_context | |
| 1770 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | |
| 1771 .get())); | |
| 1772 } | |
| 1773 | |
| 1774 request_id_--; | |
| 1775 | |
| 1776 // Make extra info and read footer (contains request ID). | |
| 1777 // | |
| 1778 // TODO(davidben): Associate the request with the FrameTreeNode or tab so that | |
| 1779 // IO thread -> UI thread hops will work. | |
| 1780 ResourceRequestInfoImpl* extra_info = | |
| 1781 new ResourceRequestInfoImpl( | |
| 1782 PROCESS_TYPE_BROWSER, | |
| 1783 -1, // child_id | |
| 1784 -1, // route_id | |
| 1785 -1, // request_data.origin_pid, | |
| 1786 request_id_, | |
| 1787 -1, // request_data.render_frame_id, | |
| 1788 info.is_main_frame, | |
| 1789 info.parent_is_main_frame, | |
| 1790 -1, // request_data.parent_render_frame_id, | |
| 1791 resource_type, | |
| 1792 info.navigation_params.transition_type, | |
| 1793 info.navigation_params.should_replace_current_entry, | |
| 1794 false, // is download | |
| 1795 false, // is stream | |
| 1796 info.navigation_params.allow_download, | |
| 1797 info.navigation_params.has_user_gesture, | |
| 1798 true, | |
| 1799 info.navigation_params.referrer.policy, | |
| 1800 // TODO(davidben): This is only used for prerenders. Replace | |
| 1801 // is_showing with something for that. Or maybe it just comes from the | |
| 1802 // same mechanism as the cookie one. | |
| 1803 blink::WebPageVisibilityStateVisible, | |
| 1804 resource_context, | |
| 1805 base::WeakPtr<ResourceMessageFilter>(), // filter | |
| 1806 true); | |
| 1807 // Request takes ownership. | |
| 1808 extra_info->AssociateWithRequest(new_request.get()); | |
| 1809 | |
| 1810 if (new_request->url().SchemeIs(url::kBlobScheme)) { | |
| 1811 // Hang on to a reference to ensure the blob is not released prior | |
| 1812 // to the job being started. | |
| 1813 ChromeBlobStorageContext* blob_context = | |
| 1814 GetChromeBlobStorageContextForResourceContext(resource_context); | |
| 1815 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | |
| 1816 new_request.get(), | |
| 1817 blob_context->context()->GetBlobDataFromPublicURL(new_request->url())); | |
| 1818 } | |
| 1819 | |
| 1820 // TODO(davidben): Attach ServiceWorkerRequestHandler. | |
| 1821 | |
| 1822 // TODO(davidben): Attach AppCacheInterceptor. | |
| 1823 | |
| 1824 scoped_ptr<ResourceHandler> handler(new NavigationResourceHandler( | |
| 1825 new_request.get(), loader)); | |
| 1826 | |
| 1827 // Insert a buffered event handler before the actual one. | |
| 1828 handler.reset( | |
| 1829 new BufferedResourceHandler(handler.Pass(), this, new_request.get())); | |
| 1830 | |
| 1831 ScopedVector<ResourceThrottle> throttles; | |
| 1832 if (delegate_) { | |
| 1833 // TODO(davidben): appcache_service is currently NULL. | |
| 1834 delegate_->RequestBeginning(new_request.get(), | |
| 1835 resource_context, | |
| 1836 NULL, | |
| 1837 resource_type, | |
| 1838 &throttles); | |
| 1839 } | |
| 1840 | |
| 1841 if (new_request->has_upload()) { | |
| 1842 // Block power save while uploading data. | |
| 1843 throttles.push_back(new PowerSaveBlockResourceThrottle()); | |
| 1844 } | |
| 1845 | |
| 1846 // TODO(davidben): Attach ResourceScheduler's throttle. | |
| 1847 | |
| 1848 handler.reset(new ThrottlingResourceHandler( | |
| 1849 handler.Pass(), new_request.get(), throttles.Pass())); | |
| 1850 | |
| 1851 BeginRequestInternal(new_request.Pass(), handler.Pass()); | |
|
clamy
2014/09/22 21:11:01
nit: Do you think that the check that was removed
davidben
2014/09/22 21:19:56
Eh, probably don't need to bother; new ThrottlingR
| |
| 1676 } | 1852 } |
| 1677 | 1853 |
| 1678 // static | 1854 // static |
| 1679 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 1855 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
| 1680 net::URLRequest* request) { | 1856 net::URLRequest* request) { |
| 1681 // The following fields should be a minor size contribution (experimentally | 1857 // The following fields should be a minor size contribution (experimentally |
| 1682 // on the order of 100). However since they are variable length, it could | 1858 // on the order of 100). However since they are variable length, it could |
| 1683 // in theory be a sizeable contribution. | 1859 // in theory be a sizeable contribution. |
| 1684 int strings_cost = request->extra_request_headers().ToString().size() + | 1860 int strings_cost = request->extra_request_headers().ToString().size() + |
| 1685 request->original_url().spec().size() + | 1861 request->original_url().spec().size() + |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2049 | 2225 |
| 2050 // Add a flag to selectively bypass the data reduction proxy if the resource | 2226 // Add a flag to selectively bypass the data reduction proxy if the resource |
| 2051 // type is not an image. | 2227 // type is not an image. |
| 2052 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) | 2228 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) |
| 2053 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 2229 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 2054 | 2230 |
| 2055 return load_flags; | 2231 return load_flags; |
| 2056 } | 2232 } |
| 2057 | 2233 |
| 2058 } // namespace content | 2234 } // namespace content |
| OLD | NEW |