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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "content/browser/streams/stream.h" | 69 #include "content/browser/streams/stream.h" |
70 #include "content/browser/streams/stream_context.h" | 70 #include "content/browser/streams/stream_context.h" |
71 #include "content/browser/streams/stream_registry.h" | 71 #include "content/browser/streams/stream_registry.h" |
72 #include "content/common/navigation_params.h" | 72 #include "content/common/navigation_params.h" |
73 #include "content/common/net/url_request_service_worker_data.h" | 73 #include "content/common/net/url_request_service_worker_data.h" |
74 #include "content/common/resource_messages.h" | 74 #include "content/common/resource_messages.h" |
75 #include "content/common/resource_request.h" | 75 #include "content/common/resource_request.h" |
76 #include "content/common/resource_request_body_impl.h" | 76 #include "content/common/resource_request_body_impl.h" |
77 #include "content/common/resource_request_completion_status.h" | 77 #include "content/common/resource_request_completion_status.h" |
78 #include "content/common/site_isolation_policy.h" | 78 #include "content/common/site_isolation_policy.h" |
79 #include "content/common/ssl_status_serialization.h" | |
80 #include "content/common/view_messages.h" | 79 #include "content/common/view_messages.h" |
81 #include "content/public/browser/browser_thread.h" | 80 #include "content/public/browser/browser_thread.h" |
82 #include "content/public/browser/global_request_id.h" | 81 #include "content/public/browser/global_request_id.h" |
83 #include "content/public/browser/plugin_service.h" | 82 #include "content/public/browser/plugin_service.h" |
84 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 83 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
85 #include "content/public/browser/resource_request_details.h" | 84 #include "content/public/browser/resource_request_details.h" |
86 #include "content/public/browser/resource_throttle.h" | 85 #include "content/public/browser/resource_throttle.h" |
87 #include "content/public/browser/stream_handle.h" | 86 #include "content/public/browser/stream_handle.h" |
88 #include "content/public/browser/stream_info.h" | 87 #include "content/public/browser/stream_info.h" |
89 #include "content/public/common/browser_side_navigation_policy.h" | 88 #include "content/public/common/browser_side_navigation_policy.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 routing_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); | 416 routing_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); |
418 } | 417 } |
419 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 418 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
420 base::Bind(&NotifyForRouteSetOnIO, frame_callback, | 419 base::Bind(&NotifyForRouteSetOnIO, frame_callback, |
421 base::Passed(std::move(routing_ids)))); | 420 base::Passed(std::move(routing_ids)))); |
422 } | 421 } |
423 | 422 |
424 void UpdateSSLStatus(int render_process_id, | 423 void UpdateSSLStatus(int render_process_id, |
425 int render_frame_host_id, | 424 int render_frame_host_id, |
426 const GURL& url, | 425 const GURL& url, |
427 int new_cert_id) { | 426 CertStore* cert_store) { |
428 RenderFrameHostImpl* render_frame_host = | 427 RenderFrameHostImpl* render_frame_host = |
429 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 428 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
430 if (!render_frame_host) | 429 if (!render_frame_host) |
431 return; | 430 return; |
432 | 431 |
433 NavigationHandleImpl* navigation_handle = | 432 NavigationHandleImpl* navigation_handle = |
434 render_frame_host->navigation_handle(); | 433 render_frame_host->navigation_handle(); |
435 if (navigation_handle && navigation_handle->GetURL() == url) | 434 if (!navigation_handle || navigation_handle->GetURL() != url) |
436 navigation_handle->UpdateSSLCertId(new_cert_id); | 435 return; |
| 436 |
| 437 scoped_refptr<net::X509Certificate> cert; |
| 438 if (!cert_store->RetrieveCert( |
| 439 navigation_handle->ssl_status().cert_id, &cert)) { |
| 440 NOTREACHED() << "Must have set an SSL certificate already."; |
| 441 return; |
| 442 } |
| 443 |
| 444 int new_cert_id = cert_store->StoreCert(cert.get(), render_process_id); |
| 445 navigation_handle->UpdateSSLCertId(new_cert_id); |
437 } | 446 } |
438 | 447 |
439 } // namespace | 448 } // namespace |
440 | 449 |
441 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo() {} | 450 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo() {} |
442 | 451 |
443 ResourceDispatcherHostImpl::HeaderInterceptorInfo::~HeaderInterceptorInfo() {} | 452 ResourceDispatcherHostImpl::HeaderInterceptorInfo::~HeaderInterceptorInfo() {} |
444 | 453 |
445 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo( | 454 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo( |
446 const HeaderInterceptorInfo& other) {} | 455 const HeaderInterceptorInfo& other) {} |
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 | 2308 |
2300 // If enqueing/starting this request will exceed our per-process memory | 2309 // If enqueing/starting this request will exceed our per-process memory |
2301 // bound, abort it right away. | 2310 // bound, abort it right away. |
2302 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); | 2311 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); |
2303 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { | 2312 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { |
2304 // We call "CancelWithError()" as a way of setting the net::URLRequest's | 2313 // We call "CancelWithError()" as a way of setting the net::URLRequest's |
2305 // status -- it has no effect beyond this, since the request hasn't started. | 2314 // status -- it has no effect beyond this, since the request hasn't started. |
2306 request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); | 2315 request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
2307 | 2316 |
2308 bool defer = false; | 2317 bool defer = false; |
2309 handler->OnResponseCompleted(request->status(), std::string(), &defer); | 2318 handler->OnResponseCompleted(request->status(), &defer); |
2310 if (defer) { | 2319 if (defer) { |
2311 // TODO(darin): The handler is not ready for us to kill the request. Oops! | 2320 // TODO(darin): The handler is not ready for us to kill the request. Oops! |
2312 NOTREACHED(); | 2321 NOTREACHED(); |
2313 } | 2322 } |
2314 | 2323 |
2315 IncrementOutstandingRequestsMemory(-1, *info); | 2324 IncrementOutstandingRequestsMemory(-1, *info); |
2316 | 2325 |
2317 // A ResourceHandler must not outlive its associated URLRequest. | 2326 // A ResourceHandler must not outlive its associated URLRequest. |
2318 handler.reset(); | 2327 handler.reset(); |
2319 return; | 2328 return; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2623 load_flags |= net::LOAD_IGNORE_LIMITS; | 2632 load_flags |= net::LOAD_IGNORE_LIMITS; |
2624 | 2633 |
2625 return load_flags; | 2634 return load_flags; |
2626 } | 2635 } |
2627 | 2636 |
2628 void ResourceDispatcherHostImpl::UpdateResponseCertificateForTransfer( | 2637 void ResourceDispatcherHostImpl::UpdateResponseCertificateForTransfer( |
2629 ResourceResponse* response, | 2638 ResourceResponse* response, |
2630 net::URLRequest* request, | 2639 net::URLRequest* request, |
2631 ResourceRequestInfoImpl* info) { | 2640 ResourceRequestInfoImpl* info) { |
2632 const net::SSLInfo& ssl_info = request->ssl_info(); | 2641 const net::SSLInfo& ssl_info = request->ssl_info(); |
2633 if (!ssl_info.cert) | 2642 if (info->GetResourceType() != RESOURCE_TYPE_MAIN_FRAME || !ssl_info.cert) |
2634 return; | 2643 return; |
2635 SSLStatus ssl; | 2644 int render_process_id, render_frame_id; |
2636 // DeserializeSecurityInfo() often takes security info sent by a | 2645 if (info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) { |
2637 // renderer as input, in which case it's important to check that the | 2646 BrowserThread::PostTask(BrowserThread::UI, |
2638 // security info deserializes properly and kill the renderer if | 2647 FROM_HERE, |
2639 // not. In this case, however, the security info has been provided by | 2648 base::Bind(UpdateSSLStatus, |
2640 // the ResourceLoader, so it does not need to be treated as untrusted | 2649 render_process_id, |
2641 // data. | 2650 render_frame_id, |
2642 bool deserialized = | 2651 request->url(), |
2643 DeserializeSecurityInfo(response->head.security_info, &ssl); | 2652 GetCertStore())); |
2644 DCHECK(deserialized); | |
2645 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), | |
2646 info->GetChildID()); | |
2647 response->head.security_info = SerializeSecurityInfo(ssl); | |
2648 | |
2649 if (info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME) { | |
2650 int render_process_id, render_frame_id; | |
2651 if (info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) { | |
2652 BrowserThread::PostTask(BrowserThread::UI, | |
2653 FROM_HERE, | |
2654 base::Bind(UpdateSSLStatus, | |
2655 render_process_id, | |
2656 render_frame_id, | |
2657 request->url(), | |
2658 ssl.cert_id)); | |
2659 } | |
2660 } | 2653 } |
2661 } | 2654 } |
2662 | 2655 |
2663 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2656 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
2664 return cert_store_for_testing_ ? cert_store_for_testing_ | 2657 return cert_store_for_testing_ ? cert_store_for_testing_ |
2665 : CertStore::GetInstance(); | 2658 : CertStore::GetInstance(); |
2666 } | 2659 } |
2667 | 2660 |
2668 bool ResourceDispatcherHostImpl::ShouldServiceRequest( | 2661 bool ResourceDispatcherHostImpl::ShouldServiceRequest( |
2669 int process_type, | 2662 int process_type, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2737 request_info->GetRouteID(), is_content_initiated, true, &throttles); | 2730 request_info->GetRouteID(), is_content_initiated, true, &throttles); |
2738 if (!throttles.empty()) { | 2731 if (!throttles.empty()) { |
2739 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2732 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2740 std::move(throttles))); | 2733 std::move(throttles))); |
2741 } | 2734 } |
2742 } | 2735 } |
2743 return handler; | 2736 return handler; |
2744 } | 2737 } |
2745 | 2738 |
2746 } // namespace content | 2739 } // namespace content |
OLD | NEW |