| 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/renderer_host/resource_dispatcher_host_impl.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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/plugin_service_impl.h" | 34 #include "content/browser/plugin_service_impl.h" |
| 35 #include "content/browser/renderer_host/async_resource_handler.h" | 35 #include "content/browser/renderer_host/async_resource_handler.h" |
| 36 #include "content/browser/renderer_host/buffered_resource_handler.h" | 36 #include "content/browser/renderer_host/buffered_resource_handler.h" |
| 37 #include "content/browser/renderer_host/cross_site_resource_handler.h" | 37 #include "content/browser/renderer_host/cross_site_resource_handler.h" |
| 38 #include "content/browser/renderer_host/doomed_resource_handler.h" | 38 #include "content/browser/renderer_host/doomed_resource_handler.h" |
| 39 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" | 39 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" |
| 40 #include "content/browser/renderer_host/render_view_host_impl.h" | 40 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 41 #include "content/browser/renderer_host/resource_message_filter.h" | 41 #include "content/browser/renderer_host/resource_message_filter.h" |
| 42 #include "content/public/browser/resource_request_details.h" | 42 #include "content/browser/renderer_host/transfer_navigation_resource_throttle.h" |
| 43 #include "content/browser/renderer_host/resource_request_info_impl.h" | 43 #include "content/browser/renderer_host/resource_request_info_impl.h" |
| 44 #include "content/browser/renderer_host/sync_resource_handler.h" | 44 #include "content/browser/renderer_host/sync_resource_handler.h" |
| 45 #include "content/browser/renderer_host/throttling_resource_handler.h" | 45 #include "content/browser/renderer_host/throttling_resource_handler.h" |
| 46 #include "content/browser/resource_context_impl.h" | 46 #include "content/browser/resource_context_impl.h" |
| 47 #include "content/browser/ssl/ssl_client_auth_handler.h" | 47 #include "content/browser/ssl/ssl_client_auth_handler.h" |
| 48 #include "content/browser/ssl/ssl_manager.h" | 48 #include "content/browser/ssl/ssl_manager.h" |
| 49 #include "content/browser/worker_host/worker_service_impl.h" | 49 #include "content/browser/worker_host/worker_service_impl.h" |
| 50 #include "content/common/resource_messages.h" | 50 #include "content/common/resource_messages.h" |
| 51 #include "content/common/ssl_status_serialization.h" | 51 #include "content/common/ssl_status_serialization.h" |
| 52 #include "content/common/view_messages.h" | 52 #include "content/common/view_messages.h" |
| 53 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
| 54 #include "content/public/browser/content_browser_client.h" | 54 #include "content/public/browser/content_browser_client.h" |
| 55 #include "content/public/browser/download_manager.h" | 55 #include "content/public/browser/download_manager.h" |
| 56 #include "content/public/browser/global_request_id.h" | 56 #include "content/public/browser/global_request_id.h" |
| 57 #include "content/public/browser/notification_service.h" | 57 #include "content/public/browser/notification_service.h" |
| 58 #include "content/public/browser/render_view_host_delegate.h" | 58 #include "content/public/browser/render_view_host_delegate.h" |
| 59 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 59 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 60 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 60 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 61 #include "content/public/browser/resource_request_details.h" |
| 61 #include "content/public/browser/resource_throttle.h" | 62 #include "content/public/browser/resource_throttle.h" |
| 62 #include "content/public/common/content_switches.h" | 63 #include "content/public/common/content_switches.h" |
| 63 #include "content/public/common/process_type.h" | 64 #include "content/public/common/process_type.h" |
| 64 #include "content/public/common/url_constants.h" | 65 #include "content/public/common/url_constants.h" |
| 65 #include "net/base/auth.h" | 66 #include "net/base/auth.h" |
| 66 #include "net/base/cert_status_flags.h" | 67 #include "net/base/cert_status_flags.h" |
| 67 #include "net/base/load_flags.h" | 68 #include "net/base/load_flags.h" |
| 68 #include "net/base/mime_util.h" | 69 #include "net/base/mime_util.h" |
| 69 #include "net/base/net_errors.h" | 70 #include "net/base/net_errors.h" |
| 70 #include "net/base/registry_controlled_domain.h" | 71 #include "net/base/registry_controlled_domain.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 return net::OK; | 546 return net::OK; |
| 546 } | 547 } |
| 547 | 548 |
| 548 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( | 549 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( |
| 549 net::URLRequest* request) { | 550 net::URLRequest* request) { |
| 550 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 551 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 551 if (info) | 552 if (info) |
| 552 info->set_login_delegate(NULL); | 553 info->set_login_delegate(NULL); |
| 553 } | 554 } |
| 554 | 555 |
| 555 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( | |
| 556 net::URLRequest* transferred_request) { | |
| 557 ResourceRequestInfoImpl* info = | |
| 558 ResourceRequestInfoImpl::ForRequest(transferred_request); | |
| 559 | |
| 560 GlobalRequestID transferred_request_id(info->GetChildID(), | |
| 561 info->GetRequestID()); | |
| 562 transferred_navigations_[transferred_request_id] = transferred_request; | |
| 563 | |
| 564 // If a URLRequest is transferred to a new RenderViewHost, its | |
| 565 // ResourceHandler should not receive any notifications because it may | |
| 566 // depend on the state of the old RVH. We set a ResourceHandler that only | |
| 567 // allows canceling requests, because on shutdown of the RDH all pending | |
| 568 // requests are canceled. The RVH of requests that are being transferred may | |
| 569 // be gone by that time. If the request is resumed, the ResoureHandlers are | |
| 570 // substituted again. | |
| 571 scoped_refptr<ResourceHandler> transferred_resource_handler( | |
| 572 new DoomedResourceHandler(info->resource_handler())); | |
| 573 info->set_resource_handler(transferred_resource_handler.get()); | |
| 574 } | |
| 575 | |
| 576 void ResourceDispatcherHostImpl::Shutdown() { | 556 void ResourceDispatcherHostImpl::Shutdown() { |
| 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 578 BrowserThread::PostTask(BrowserThread::IO, | 558 BrowserThread::PostTask(BrowserThread::IO, |
| 579 FROM_HERE, | 559 FROM_HERE, |
| 580 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, | 560 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, |
| 581 base::Unretained(this))); | 561 base::Unretained(this))); |
| 582 } | 562 } |
| 583 | 563 |
| 584 scoped_refptr<ResourceHandler> | 564 scoped_refptr<ResourceHandler> |
| 585 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( | 565 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 CrossSiteRequestManager::GetInstance()-> | 871 CrossSiteRequestManager::GetInstance()-> |
| 892 HasPendingCrossSiteRequest(child_id, route_id)) { | 872 HasPendingCrossSiteRequest(child_id, route_id)) { |
| 893 // Wrap the event handler to be sure the current page's onunload handler | 873 // Wrap the event handler to be sure the current page's onunload handler |
| 894 // has a chance to run before we render the new page. | 874 // has a chance to run before we render the new page. |
| 895 handler = new CrossSiteResourceHandler(handler, child_id, route_id, this); | 875 handler = new CrossSiteResourceHandler(handler, child_id, route_id, this); |
| 896 } | 876 } |
| 897 | 877 |
| 898 // Insert a buffered event handler before the actual one. | 878 // Insert a buffered event handler before the actual one. |
| 899 handler = new BufferedResourceHandler(handler, this, request); | 879 handler = new BufferedResourceHandler(handler, this, request); |
| 900 | 880 |
| 881 ScopedVector<ResourceThrottle> throttles; |
| 901 if (delegate_) { | 882 if (delegate_) { |
| 902 bool is_continuation_of_transferred_request = | 883 bool is_continuation_of_transferred_request = |
| 903 (deferred_request != NULL); | 884 (deferred_request != NULL); |
| 904 | 885 |
| 905 ScopedVector<ResourceThrottle> throttles; | |
| 906 delegate_->RequestBeginning(request, | 886 delegate_->RequestBeginning(request, |
| 907 resource_context, | 887 resource_context, |
| 908 request_data.resource_type, | 888 request_data.resource_type, |
| 909 child_id, | 889 child_id, |
| 910 route_id, | 890 route_id, |
| 911 is_continuation_of_transferred_request, | 891 is_continuation_of_transferred_request, |
| 912 &throttles); | 892 &throttles); |
| 913 if (!throttles.empty()) { | 893 } |
| 914 handler = new ThrottlingResourceHandler(this, handler, child_id, | 894 |
| 915 request_id, throttles.Pass()); | 895 if (request_data.resource_type == ResourceType::MAIN_FRAME) { |
| 916 } | 896 throttles.insert( |
| 897 throttles.begin(), new TransferNavigationResourceThrottle(request)); |
| 898 } |
| 899 |
| 900 if (!throttles.empty()) { |
| 901 handler = new ThrottlingResourceHandler(this, handler, child_id, request_id, |
| 902 throttles.Pass()); |
| 917 } | 903 } |
| 918 | 904 |
| 919 bool allow_download = request_data.allow_download && | 905 bool allow_download = request_data.allow_download && |
| 920 ResourceType::IsFrame(request_data.resource_type); | 906 ResourceType::IsFrame(request_data.resource_type); |
| 921 // Make extra info and read footer (contains request ID). | 907 // Make extra info and read footer (contains request ID). |
| 922 ResourceRequestInfoImpl* extra_info = | 908 ResourceRequestInfoImpl* extra_info = |
| 923 new ResourceRequestInfoImpl( | 909 new ResourceRequestInfoImpl( |
| 924 handler, | 910 handler, |
| 925 process_type, | 911 process_type, |
| 926 child_id, | 912 child_id, |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 // We reached the max number of data messages that can be sent to | 1242 // We reached the max number of data messages that can be sent to |
| 1257 // the renderer for a given request. Pause the request and wait for | 1243 // the renderer for a given request. Pause the request and wait for |
| 1258 // the renderer to start processing them before resuming it. | 1244 // the renderer to start processing them before resuming it. |
| 1259 PauseRequest(child_id, request_id, true); | 1245 PauseRequest(child_id, request_id, true); |
| 1260 return false; | 1246 return false; |
| 1261 } | 1247 } |
| 1262 | 1248 |
| 1263 return true; | 1249 return true; |
| 1264 } | 1250 } |
| 1265 | 1251 |
| 1252 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( |
| 1253 net::URLRequest* transferred_request) { |
| 1254 ResourceRequestInfoImpl* info = |
| 1255 ResourceRequestInfoImpl::ForRequest(transferred_request); |
| 1256 |
| 1257 GlobalRequestID transferred_request_id(info->GetChildID(), |
| 1258 info->GetRequestID()); |
| 1259 transferred_navigations_[transferred_request_id] = transferred_request; |
| 1260 |
| 1261 // If a URLRequest is transferred to a new RenderViewHost, its |
| 1262 // ResourceHandler should not receive any notifications because it may |
| 1263 // depend on the state of the old RVH. We set a ResourceHandler that only |
| 1264 // allows canceling requests, because on shutdown of the RDH all pending |
| 1265 // requests are canceled. The RVH of requests that are being transferred may |
| 1266 // be gone by that time. If the request is resumed, the ResoureHandlers are |
| 1267 // substituted again. |
| 1268 scoped_refptr<ResourceHandler> transferred_resource_handler( |
| 1269 new DoomedResourceHandler(info->resource_handler())); |
| 1270 info->set_resource_handler(transferred_resource_handler.get()); |
| 1271 } |
| 1272 |
| 1266 int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost( | 1273 int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost( |
| 1267 int child_id) const { | 1274 int child_id) const { |
| 1268 OutstandingRequestsMemoryCostMap::const_iterator entry = | 1275 OutstandingRequestsMemoryCostMap::const_iterator entry = |
| 1269 outstanding_requests_memory_cost_map_.find(child_id); | 1276 outstanding_requests_memory_cost_map_.find(child_id); |
| 1270 return (entry == outstanding_requests_memory_cost_map_.end()) ? | 1277 return (entry == outstanding_requests_memory_cost_map_.end()) ? |
| 1271 0 : entry->second; | 1278 0 : entry->second; |
| 1272 } | 1279 } |
| 1273 | 1280 |
| 1274 // The object died, so cancel and detach all requests associated with it except | 1281 // The object died, so cancel and detach all requests associated with it except |
| 1275 // for downloads, which belong to the browser process even if initiated via a | 1282 // for downloads, which belong to the browser process even if initiated via a |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2353 return allow_cross_origin_auth_prompt_; | 2360 return allow_cross_origin_auth_prompt_; |
| 2354 } | 2361 } |
| 2355 | 2362 |
| 2356 bool ResourceDispatcherHostImpl::IsTransferredNavigation( | 2363 bool ResourceDispatcherHostImpl::IsTransferredNavigation( |
| 2357 const GlobalRequestID& transferred_request_id) const { | 2364 const GlobalRequestID& transferred_request_id) const { |
| 2358 return transferred_navigations_.find(transferred_request_id) != | 2365 return transferred_navigations_.find(transferred_request_id) != |
| 2359 transferred_navigations_.end(); | 2366 transferred_navigations_.end(); |
| 2360 } | 2367 } |
| 2361 | 2368 |
| 2362 } // namespace content | 2369 } // namespace content |
| OLD | NEW |