| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 #include "content/browser/service_worker/link_header_support.h" | 68 #include "content/browser/service_worker/link_header_support.h" |
| 69 #include "content/browser/service_worker/service_worker_request_handler.h" | 69 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 70 #include "content/browser/streams/stream.h" | 70 #include "content/browser/streams/stream.h" |
| 71 #include "content/browser/streams/stream_context.h" | 71 #include "content/browser/streams/stream_context.h" |
| 72 #include "content/browser/streams/stream_registry.h" | 72 #include "content/browser/streams/stream_registry.h" |
| 73 #include "content/browser/web_contents/web_contents_impl.h" | 73 #include "content/browser/web_contents/web_contents_impl.h" |
| 74 #include "content/common/appcache_interfaces.h" | 74 #include "content/common/appcache_interfaces.h" |
| 75 #include "content/common/navigation_params.h" | 75 #include "content/common/navigation_params.h" |
| 76 #include "content/common/net/url_request_service_worker_data.h" | 76 #include "content/common/net/url_request_service_worker_data.h" |
| 77 #include "content/common/resource_messages.h" | 77 #include "content/common/resource_messages.h" |
| 78 #include "content/common/resource_request.h" |
| 79 #include "content/common/resource_request_completion_status.h" |
| 78 #include "content/common/site_isolation_policy.h" | 80 #include "content/common/site_isolation_policy.h" |
| 79 #include "content/common/ssl_status_serialization.h" | 81 #include "content/common/ssl_status_serialization.h" |
| 80 #include "content/common/view_messages.h" | 82 #include "content/common/view_messages.h" |
| 81 #include "content/public/browser/browser_thread.h" | 83 #include "content/public/browser/browser_thread.h" |
| 82 #include "content/public/browser/content_browser_client.h" | 84 #include "content/public/browser/content_browser_client.h" |
| 83 #include "content/public/browser/download_manager.h" | 85 #include "content/public/browser/download_manager.h" |
| 84 #include "content/public/browser/download_url_parameters.h" | 86 #include "content/public/browser/download_url_parameters.h" |
| 85 #include "content/public/browser/global_request_id.h" | 87 #include "content/public/browser/global_request_id.h" |
| 86 #include "content/public/browser/plugin_service.h" | 88 #include "content/public/browser/plugin_service.h" |
| 87 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 89 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, | 230 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, |
| 229 IPC::Message* sync_result, | 231 IPC::Message* sync_result, |
| 230 int request_id) { | 232 int request_id) { |
| 231 if (sync_result) { | 233 if (sync_result) { |
| 232 SyncLoadResult result; | 234 SyncLoadResult result; |
| 233 result.error_code = net::ERR_ABORTED; | 235 result.error_code = net::ERR_ABORTED; |
| 234 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); | 236 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); |
| 235 filter->Send(sync_result); | 237 filter->Send(sync_result); |
| 236 } else { | 238 } else { |
| 237 // Tell the renderer that this request was disallowed. | 239 // Tell the renderer that this request was disallowed. |
| 238 ResourceMsg_RequestCompleteData request_complete_data; | 240 ResourceRequestCompletionStatus request_complete_data; |
| 239 request_complete_data.error_code = net::ERR_ABORTED; | 241 request_complete_data.error_code = net::ERR_ABORTED; |
| 240 request_complete_data.was_ignored_by_handler = false; | 242 request_complete_data.was_ignored_by_handler = false; |
| 241 request_complete_data.exists_in_cache = false; | 243 request_complete_data.exists_in_cache = false; |
| 242 // No security info needed, connection not established. | 244 // No security info needed, connection not established. |
| 243 request_complete_data.completion_time = base::TimeTicks(); | 245 request_complete_data.completion_time = base::TimeTicks(); |
| 244 request_complete_data.encoded_data_length = 0; | 246 request_complete_data.encoded_data_length = 0; |
| 245 filter->Send(new ResourceMsg_RequestComplete( | 247 filter->Send(new ResourceMsg_RequestComplete( |
| 246 request_id, request_complete_data)); | 248 request_id, request_complete_data)); |
| 247 } | 249 } |
| 248 } | 250 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 289 } |
| 288 request->set_referrer_policy(net_referrer_policy); | 290 request->set_referrer_policy(net_referrer_policy); |
| 289 } | 291 } |
| 290 | 292 |
| 291 // Consults the RendererSecurity policy to determine whether the | 293 // Consults the RendererSecurity policy to determine whether the |
| 292 // ResourceDispatcherHostImpl should service this request. A request might be | 294 // ResourceDispatcherHostImpl should service this request. A request might be |
| 293 // disallowed if the renderer is not authorized to retrieve the request URL or | 295 // disallowed if the renderer is not authorized to retrieve the request URL or |
| 294 // if the renderer is attempting to upload an unauthorized file. | 296 // if the renderer is attempting to upload an unauthorized file. |
| 295 bool ShouldServiceRequest(int process_type, | 297 bool ShouldServiceRequest(int process_type, |
| 296 int child_id, | 298 int child_id, |
| 297 const ResourceHostMsg_Request& request_data, | 299 const ResourceRequest& request_data, |
| 298 const net::HttpRequestHeaders& headers, | 300 const net::HttpRequestHeaders& headers, |
| 299 ResourceMessageFilter* filter, | 301 ResourceMessageFilter* filter, |
| 300 ResourceContext* resource_context) { | 302 ResourceContext* resource_context) { |
| 301 ChildProcessSecurityPolicyImpl* policy = | 303 ChildProcessSecurityPolicyImpl* policy = |
| 302 ChildProcessSecurityPolicyImpl::GetInstance(); | 304 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 303 | 305 |
| 304 // Check if the renderer is permitted to request the requested URL. | 306 // Check if the renderer is permitted to request the requested URL. |
| 305 if (!policy->CanRequestURL(child_id, request_data.url)) { | 307 if (!policy->CanRequestURL(child_id, request_data.url)) { |
| 306 VLOG(1) << "Denied unauthorized request for " | 308 VLOG(1) << "Denied unauthorized request for " |
| 307 << request_data.url.possibly_invalid_spec(); | 309 << request_data.url.possibly_invalid_spec(); |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 handled = true; | 1210 handled = true; |
| 1209 } | 1211 } |
| 1210 | 1212 |
| 1211 filter_ = NULL; | 1213 filter_ = NULL; |
| 1212 return handled; | 1214 return handled; |
| 1213 } | 1215 } |
| 1214 | 1216 |
| 1215 void ResourceDispatcherHostImpl::OnRequestResource( | 1217 void ResourceDispatcherHostImpl::OnRequestResource( |
| 1216 int routing_id, | 1218 int routing_id, |
| 1217 int request_id, | 1219 int request_id, |
| 1218 const ResourceHostMsg_Request& request_data) { | 1220 const ResourceRequest& request_data) { |
| 1219 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1221 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 1220 tracked_objects::ScopedTracker tracking_profile( | 1222 tracked_objects::ScopedTracker tracking_profile( |
| 1221 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1223 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1222 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1224 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
| 1223 // When logging time-to-network only care about main frame and non-transfer | 1225 // When logging time-to-network only care about main frame and non-transfer |
| 1224 // navigations. | 1226 // navigations. |
| 1225 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1227 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
| 1226 // instead. | 1228 // instead. |
| 1227 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1229 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
| 1228 request_data.transferred_request_request_id == -1 && | 1230 request_data.transferred_request_request_id == -1 && |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1240 } | 1242 } |
| 1241 | 1243 |
| 1242 // Begins a resource request with the given params on behalf of the specified | 1244 // Begins a resource request with the given params on behalf of the specified |
| 1243 // child process. Responses will be dispatched through the given receiver. The | 1245 // child process. Responses will be dispatched through the given receiver. The |
| 1244 // process ID is used to lookup WebContentsImpl from routing_id's in the case of | 1246 // process ID is used to lookup WebContentsImpl from routing_id's in the case of |
| 1245 // a request from a renderer. request_context is the cookie/cache context to be | 1247 // a request from a renderer. request_context is the cookie/cache context to be |
| 1246 // used for this request. | 1248 // used for this request. |
| 1247 // | 1249 // |
| 1248 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1250 // If sync_result is non-null, then a SyncLoad reply will be generated, else |
| 1249 // a normal asynchronous set of response messages will be generated. | 1251 // a normal asynchronous set of response messages will be generated. |
| 1250 void ResourceDispatcherHostImpl::OnSyncLoad( | 1252 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, |
| 1251 int request_id, | 1253 const ResourceRequest& request_data, |
| 1252 const ResourceHostMsg_Request& request_data, | 1254 IPC::Message* sync_result) { |
| 1253 IPC::Message* sync_result) { | |
| 1254 BeginRequest(request_id, request_data, sync_result, | 1255 BeginRequest(request_id, request_data, sync_result, |
| 1255 sync_result->routing_id()); | 1256 sync_result->routing_id()); |
| 1256 } | 1257 } |
| 1257 | 1258 |
| 1258 bool ResourceDispatcherHostImpl::IsRequestIDInUse( | 1259 bool ResourceDispatcherHostImpl::IsRequestIDInUse( |
| 1259 const GlobalRequestID& id) const { | 1260 const GlobalRequestID& id) const { |
| 1260 if (pending_loaders_.find(id) != pending_loaders_.end()) | 1261 if (pending_loaders_.find(id) != pending_loaders_.end()) |
| 1261 return true; | 1262 return true; |
| 1262 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1263 for (const auto& blocked_loaders : blocked_loaders_map_) { |
| 1263 for (const auto& loader : *blocked_loaders.second.get()) { | 1264 for (const auto& loader : *blocked_loaders.second.get()) { |
| 1264 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1265 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 1265 if (info->GetGlobalRequestID() == id) | 1266 if (info->GetGlobalRequestID() == id) |
| 1266 return true; | 1267 return true; |
| 1267 } | 1268 } |
| 1268 } | 1269 } |
| 1269 return false; | 1270 return false; |
| 1270 } | 1271 } |
| 1271 | 1272 |
| 1272 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( | 1273 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
| 1273 int child_id, | 1274 int child_id, |
| 1274 int route_id, | 1275 int route_id, |
| 1275 int request_id, | 1276 int request_id, |
| 1276 const ResourceHostMsg_Request& request_data, | 1277 const ResourceRequest& request_data, |
| 1277 LoaderMap::iterator iter) { | 1278 LoaderMap::iterator iter) { |
| 1278 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); | 1279 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); |
| 1279 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, | 1280 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
| 1280 info->GetRenderFrameID()); | 1281 info->GetRenderFrameID()); |
| 1281 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1282 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
| 1282 request_data.transferred_request_request_id); | 1283 request_data.transferred_request_request_id); |
| 1283 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); | 1284 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
| 1284 GlobalRequestID new_request_id(child_id, request_id); | 1285 GlobalRequestID new_request_id(child_id, request_id); |
| 1285 | 1286 |
| 1286 // Clear out data that depends on |info| before updating it. | 1287 // Clear out data that depends on |info| before updating it. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 child_id, request_data.service_worker_provider_id); | 1359 child_id, request_data.service_worker_provider_id); |
| 1359 } | 1360 } |
| 1360 } | 1361 } |
| 1361 | 1362 |
| 1362 // We should have a CrossSiteResourceHandler to finish the transfer. | 1363 // We should have a CrossSiteResourceHandler to finish the transfer. |
| 1363 DCHECK(info->cross_site_handler()); | 1364 DCHECK(info->cross_site_handler()); |
| 1364 } | 1365 } |
| 1365 | 1366 |
| 1366 void ResourceDispatcherHostImpl::BeginRequest( | 1367 void ResourceDispatcherHostImpl::BeginRequest( |
| 1367 int request_id, | 1368 int request_id, |
| 1368 const ResourceHostMsg_Request& request_data, | 1369 const ResourceRequest& request_data, |
| 1369 IPC::Message* sync_result, // only valid for sync | 1370 IPC::Message* sync_result, // only valid for sync |
| 1370 int route_id) { | 1371 int route_id) { |
| 1371 int process_type = filter_->process_type(); | 1372 int process_type = filter_->process_type(); |
| 1372 int child_id = filter_->child_id(); | 1373 int child_id = filter_->child_id(); |
| 1373 | 1374 |
| 1374 // Reject request id that's currently in use. | 1375 // Reject request id that's currently in use. |
| 1375 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1376 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
| 1376 bad_message::ReceivedBadMessage(filter_, | 1377 bad_message::ReceivedBadMessage(filter_, |
| 1377 bad_message::RDH_INVALID_REQUEST_ID); | 1378 bad_message::RDH_INVALID_REQUEST_ID); |
| 1378 return; | 1379 return; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 new_request.get(), request_data, sync_result, route_id, process_type, | 1629 new_request.get(), request_data, sync_result, route_id, process_type, |
| 1629 child_id, resource_context)); | 1630 child_id, resource_context)); |
| 1630 | 1631 |
| 1631 if (handler) | 1632 if (handler) |
| 1632 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1633 BeginRequestInternal(std::move(new_request), std::move(handler)); |
| 1633 } | 1634 } |
| 1634 | 1635 |
| 1635 std::unique_ptr<ResourceHandler> | 1636 std::unique_ptr<ResourceHandler> |
| 1636 ResourceDispatcherHostImpl::CreateResourceHandler( | 1637 ResourceDispatcherHostImpl::CreateResourceHandler( |
| 1637 net::URLRequest* request, | 1638 net::URLRequest* request, |
| 1638 const ResourceHostMsg_Request& request_data, | 1639 const ResourceRequest& request_data, |
| 1639 IPC::Message* sync_result, | 1640 IPC::Message* sync_result, |
| 1640 int route_id, | 1641 int route_id, |
| 1641 int process_type, | 1642 int process_type, |
| 1642 int child_id, | 1643 int child_id, |
| 1643 ResourceContext* resource_context) { | 1644 ResourceContext* resource_context) { |
| 1644 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1645 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1645 tracked_objects::ScopedTracker tracking_profile( | 1646 tracked_objects::ScopedTracker tracking_profile( |
| 1646 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1647 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1647 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1648 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
| 1648 // Construct the IPC resource handler. | 1649 // Construct the IPC resource handler. |
| (...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2640 DelegateMap::iterator it = delegate_map_.find(id); | 2641 DelegateMap::iterator it = delegate_map_.find(id); |
| 2641 DCHECK(it->second->HasObserver(delegate)); | 2642 DCHECK(it->second->HasObserver(delegate)); |
| 2642 it->second->RemoveObserver(delegate); | 2643 it->second->RemoveObserver(delegate); |
| 2643 if (!it->second->might_have_observers()) { | 2644 if (!it->second->might_have_observers()) { |
| 2644 delete it->second; | 2645 delete it->second; |
| 2645 delegate_map_.erase(it); | 2646 delegate_map_.erase(it); |
| 2646 } | 2647 } |
| 2647 } | 2648 } |
| 2648 | 2649 |
| 2649 int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest( | 2650 int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest( |
| 2650 const ResourceHostMsg_Request& request_data, | 2651 const ResourceRequest& request_data, |
| 2651 int child_id, | 2652 int child_id, |
| 2652 bool is_sync_load) { | 2653 bool is_sync_load) { |
| 2653 int load_flags = request_data.load_flags; | 2654 int load_flags = request_data.load_flags; |
| 2654 | 2655 |
| 2655 // Although EV status is irrelevant to sub-frames and sub-resources, we have | 2656 // Although EV status is irrelevant to sub-frames and sub-resources, we have |
| 2656 // to perform EV certificate verification on all resources because an HTTP | 2657 // to perform EV certificate verification on all resources because an HTTP |
| 2657 // keep-alive connection created to load a sub-frame or a sub-resource could | 2658 // keep-alive connection created to load a sub-frame or a sub-resource could |
| 2658 // be reused to load a main frame. | 2659 // be reused to load a main frame. |
| 2659 load_flags |= net::LOAD_VERIFY_EV_CERT; | 2660 load_flags |= net::LOAD_VERIFY_EV_CERT; |
| 2660 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { | 2661 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2688 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2689 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
| 2689 response->head.security_info = SerializeSecurityInfo(ssl); | 2690 response->head.security_info = SerializeSecurityInfo(ssl); |
| 2690 } | 2691 } |
| 2691 | 2692 |
| 2692 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2693 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
| 2693 return cert_store_for_testing_ ? cert_store_for_testing_ | 2694 return cert_store_for_testing_ ? cert_store_for_testing_ |
| 2694 : CertStore::GetInstance(); | 2695 : CertStore::GetInstance(); |
| 2695 } | 2696 } |
| 2696 | 2697 |
| 2697 } // namespace content | 2698 } // namespace content |
| OLD | NEW |