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 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 request_data, nullptr, nullptr); | 1060 request_data, nullptr, nullptr); |
1061 } | 1061 } |
1062 | 1062 |
1063 void ResourceDispatcherHostImpl::OnRequestResourceInternal( | 1063 void ResourceDispatcherHostImpl::OnRequestResourceInternal( |
1064 ResourceRequesterInfo* requester_info, | 1064 ResourceRequesterInfo* requester_info, |
1065 int routing_id, | 1065 int routing_id, |
1066 int request_id, | 1066 int request_id, |
1067 const ResourceRequest& request_data, | 1067 const ResourceRequest& request_data, |
1068 mojom::URLLoaderAssociatedRequest mojo_request, | 1068 mojom::URLLoaderAssociatedRequest mojo_request, |
1069 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1069 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
1070 DCHECK(requester_info->IsRenderer()); | 1070 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1071 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1071 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
1072 tracked_objects::ScopedTracker tracking_profile( | 1072 tracked_objects::ScopedTracker tracking_profile( |
1073 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1073 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1074 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1074 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
1075 // When logging time-to-network only care about main frame and non-transfer | 1075 // When logging time-to-network only care about main frame and non-transfer |
1076 // navigations. | 1076 // navigations. |
1077 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1077 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
1078 // instead. | 1078 // instead. |
1079 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1079 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
1080 request_data.transferred_request_request_id == -1 && | 1080 request_data.transferred_request_request_id == -1 && |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 } | 1266 } |
1267 | 1267 |
1268 void ResourceDispatcherHostImpl::BeginRequest( | 1268 void ResourceDispatcherHostImpl::BeginRequest( |
1269 ResourceRequesterInfo* requester_info, | 1269 ResourceRequesterInfo* requester_info, |
1270 int request_id, | 1270 int request_id, |
1271 const ResourceRequest& request_data, | 1271 const ResourceRequest& request_data, |
1272 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1272 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
1273 int route_id, | 1273 int route_id, |
1274 mojom::URLLoaderAssociatedRequest mojo_request, | 1274 mojom::URLLoaderAssociatedRequest mojo_request, |
1275 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1275 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
1276 DCHECK(requester_info->IsRenderer()); | 1276 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1277 int child_id = requester_info->child_id(); | 1277 int child_id = requester_info->child_id(); |
1278 | 1278 |
1279 // Reject request id that's currently in use. | 1279 // Reject request id that's currently in use. |
1280 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1280 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
| 1281 // Navigation preload requests have child_id's of -1 and monotonically |
| 1282 // increasing request IDs allocated by MakeRequestID. |
| 1283 DCHECK(requester_info->IsRenderer()); |
1281 bad_message::ReceivedBadMessage(requester_info->filter(), | 1284 bad_message::ReceivedBadMessage(requester_info->filter(), |
1282 bad_message::RDH_INVALID_REQUEST_ID); | 1285 bad_message::RDH_INVALID_REQUEST_ID); |
1283 return; | 1286 return; |
1284 } | 1287 } |
1285 | 1288 |
1286 // PlzNavigate: reject invalid renderer main resource request. | 1289 // PlzNavigate: reject invalid renderer main resource request. |
1287 bool is_navigation_stream_request = | 1290 bool is_navigation_stream_request = |
1288 IsBrowserSideNavigationEnabled() && | 1291 IsBrowserSideNavigationEnabled() && |
1289 IsResourceTypeFrame(request_data.resource_type); | 1292 IsResourceTypeFrame(request_data.resource_type); |
1290 if (is_navigation_stream_request && | 1293 if (is_navigation_stream_request && |
1291 !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { | 1294 !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { |
| 1295 // The resource_type of navigation preload requests must be SUB_RESOURCE. |
| 1296 DCHECK(requester_info->IsRenderer()); |
1292 bad_message::ReceivedBadMessage(requester_info->filter(), | 1297 bad_message::ReceivedBadMessage(requester_info->filter(), |
1293 bad_message::RDH_INVALID_URL); | 1298 bad_message::RDH_INVALID_URL); |
1294 return; | 1299 return; |
1295 } | 1300 } |
1296 | 1301 |
1297 // Reject invalid priority. | 1302 // Reject invalid priority. |
1298 if (request_data.priority < net::MINIMUM_PRIORITY || | 1303 if (request_data.priority < net::MINIMUM_PRIORITY || |
1299 request_data.priority > net::MAXIMUM_PRIORITY) { | 1304 request_data.priority > net::MAXIMUM_PRIORITY) { |
| 1305 // The priority of navigation preload requests are copied from the original |
| 1306 // request priority which must be checked beforehand. |
| 1307 DCHECK(requester_info->IsRenderer()); |
1300 bad_message::ReceivedBadMessage(requester_info->filter(), | 1308 bad_message::ReceivedBadMessage(requester_info->filter(), |
1301 bad_message::RDH_INVALID_PRIORITY); | 1309 bad_message::RDH_INVALID_PRIORITY); |
1302 return; | 1310 return; |
1303 } | 1311 } |
1304 | 1312 |
1305 // If we crash here, figure out what URL the renderer was requesting. | 1313 // If we crash here, figure out what URL the renderer was requesting. |
1306 // http://crbug.com/91398 | 1314 // http://crbug.com/91398 |
1307 char url_buf[128]; | 1315 char url_buf[128]; |
1308 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1316 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
1309 base::debug::Alias(url_buf); | 1317 base::debug::Alias(url_buf); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 scoped_refptr<ResourceRequesterInfo> requester_info, | 1379 scoped_refptr<ResourceRequesterInfo> requester_info, |
1372 int request_id, | 1380 int request_id, |
1373 const ResourceRequest& request_data, | 1381 const ResourceRequest& request_data, |
1374 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1382 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
1375 int route_id, | 1383 int route_id, |
1376 const net::HttpRequestHeaders& headers, | 1384 const net::HttpRequestHeaders& headers, |
1377 mojom::URLLoaderAssociatedRequest mojo_request, | 1385 mojom::URLLoaderAssociatedRequest mojo_request, |
1378 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 1386 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
1379 bool continue_request, | 1387 bool continue_request, |
1380 int error_code) { | 1388 int error_code) { |
1381 DCHECK(requester_info->IsRenderer()); | 1389 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1382 if (!continue_request) { | 1390 if (!continue_request) { |
1383 // TODO(ananta): Find a way to specify the right error code here. Passing | 1391 if (requester_info->IsRenderer()) { |
1384 // in a non-content error code is not safe. | 1392 // TODO(ananta): Find a way to specify the right error code here. Passing |
1385 bad_message::ReceivedBadMessage(requester_info->filter(), | 1393 // in a non-content error code is not safe. |
1386 bad_message::RDH_ILLEGAL_ORIGIN); | 1394 bad_message::ReceivedBadMessage(requester_info->filter(), |
| 1395 bad_message::RDH_ILLEGAL_ORIGIN); |
| 1396 } |
1387 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, | 1397 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, |
1388 request_id, std::move(url_loader_client)); | 1398 request_id, std::move(url_loader_client)); |
1389 return; | 1399 return; |
1390 } | 1400 } |
1391 int child_id = requester_info->child_id(); | 1401 int child_id = requester_info->child_id(); |
1392 | 1402 |
1393 bool is_navigation_stream_request = | 1403 bool is_navigation_stream_request = |
1394 IsBrowserSideNavigationEnabled() && | 1404 IsBrowserSideNavigationEnabled() && |
1395 IsResourceTypeFrame(request_data.resource_type); | 1405 IsResourceTypeFrame(request_data.resource_type); |
1396 | 1406 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 ResourceDispatcherHostImpl::CreateResourceHandler( | 1616 ResourceDispatcherHostImpl::CreateResourceHandler( |
1607 ResourceRequesterInfo* requester_info, | 1617 ResourceRequesterInfo* requester_info, |
1608 net::URLRequest* request, | 1618 net::URLRequest* request, |
1609 const ResourceRequest& request_data, | 1619 const ResourceRequest& request_data, |
1610 const SyncLoadResultCallback& sync_result_handler, | 1620 const SyncLoadResultCallback& sync_result_handler, |
1611 int route_id, | 1621 int route_id, |
1612 int child_id, | 1622 int child_id, |
1613 ResourceContext* resource_context, | 1623 ResourceContext* resource_context, |
1614 mojom::URLLoaderAssociatedRequest mojo_request, | 1624 mojom::URLLoaderAssociatedRequest mojo_request, |
1615 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1625 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
1616 DCHECK(requester_info->IsRenderer()); | 1626 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1617 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1627 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
1618 tracked_objects::ScopedTracker tracking_profile( | 1628 tracked_objects::ScopedTracker tracking_profile( |
1619 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1629 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1620 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1630 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
1621 // Construct the IPC resource handler. | 1631 // Construct the IPC resource handler. |
1622 std::unique_ptr<ResourceHandler> handler; | 1632 std::unique_ptr<ResourceHandler> handler; |
1623 if (sync_result_handler) { | 1633 if (sync_result_handler) { |
1624 // download_to_file is not supported for synchronous requests. | 1634 // download_to_file is not supported for synchronous requests. |
1625 if (request_data.download_to_file) { | 1635 if (request_data.download_to_file) { |
| 1636 DCHECK(requester_info->IsRenderer()); |
1626 bad_message::ReceivedBadMessage(requester_info->filter(), | 1637 bad_message::ReceivedBadMessage(requester_info->filter(), |
1627 bad_message::RDH_BAD_DOWNLOAD); | 1638 bad_message::RDH_BAD_DOWNLOAD); |
1628 return std::unique_ptr<ResourceHandler>(); | 1639 return std::unique_ptr<ResourceHandler>(); |
1629 } | 1640 } |
1630 | 1641 |
1631 DCHECK(!mojo_request.is_pending()); | 1642 DCHECK(!mojo_request.is_pending()); |
1632 DCHECK(!url_loader_client); | 1643 DCHECK(!url_loader_client); |
1633 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); | 1644 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); |
1634 } else { | 1645 } else { |
1635 if (mojo_request.is_pending()) { | 1646 if (mojo_request.is_pending()) { |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2814 &throttles); | 2825 &throttles); |
2815 if (!throttles.empty()) { | 2826 if (!throttles.empty()) { |
2816 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2827 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2817 std::move(throttles))); | 2828 std::move(throttles))); |
2818 } | 2829 } |
2819 } | 2830 } |
2820 return handler; | 2831 return handler; |
2821 } | 2832 } |
2822 | 2833 |
2823 } // namespace content | 2834 } // namespace content |
OLD | NEW |