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 DCHECK(requester_info->IsRenderer()); | |
mmenke
2016/12/01 15:26:11
Think this is worth an explanation (Preloads have
horo
2016/12/02 03:41:52
Done.
| |
1281 bad_message::ReceivedBadMessage(requester_info->filter(), | 1282 bad_message::ReceivedBadMessage(requester_info->filter(), |
1282 bad_message::RDH_INVALID_REQUEST_ID); | 1283 bad_message::RDH_INVALID_REQUEST_ID); |
1283 return; | 1284 return; |
1284 } | 1285 } |
1285 | 1286 |
1286 // PlzNavigate: reject invalid renderer main resource request. | 1287 // PlzNavigate: reject invalid renderer main resource request. |
1287 bool is_navigation_stream_request = | 1288 bool is_navigation_stream_request = |
1288 IsBrowserSideNavigationEnabled() && | 1289 IsBrowserSideNavigationEnabled() && |
1289 IsResourceTypeFrame(request_data.resource_type); | 1290 IsResourceTypeFrame(request_data.resource_type); |
1290 if (is_navigation_stream_request && | 1291 if (is_navigation_stream_request && |
1291 !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { | 1292 !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { |
1293 DCHECK(requester_info->IsRenderer()); | |
mmenke
2016/12/01 15:26:11
Explanation? This isn't obvious.
horo
2016/12/02 03:41:52
Done.
| |
1292 bad_message::ReceivedBadMessage(requester_info->filter(), | 1294 bad_message::ReceivedBadMessage(requester_info->filter(), |
1293 bad_message::RDH_INVALID_URL); | 1295 bad_message::RDH_INVALID_URL); |
1294 return; | 1296 return; |
1295 } | 1297 } |
1296 | 1298 |
1297 // Reject invalid priority. | 1299 // Reject invalid priority. |
1298 if (request_data.priority < net::MINIMUM_PRIORITY || | 1300 if (request_data.priority < net::MINIMUM_PRIORITY || |
1299 request_data.priority > net::MAXIMUM_PRIORITY) { | 1301 request_data.priority > net::MAXIMUM_PRIORITY) { |
1302 DCHECK(requester_info->IsRenderer()); | |
1300 bad_message::ReceivedBadMessage(requester_info->filter(), | 1303 bad_message::ReceivedBadMessage(requester_info->filter(), |
1301 bad_message::RDH_INVALID_PRIORITY); | 1304 bad_message::RDH_INVALID_PRIORITY); |
1302 return; | 1305 return; |
1303 } | 1306 } |
1304 | 1307 |
1305 // If we crash here, figure out what URL the renderer was requesting. | 1308 // If we crash here, figure out what URL the renderer was requesting. |
1306 // http://crbug.com/91398 | 1309 // http://crbug.com/91398 |
1307 char url_buf[128]; | 1310 char url_buf[128]; |
1308 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1311 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
1309 base::debug::Alias(url_buf); | 1312 base::debug::Alias(url_buf); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1371 scoped_refptr<ResourceRequesterInfo> requester_info, | 1374 scoped_refptr<ResourceRequesterInfo> requester_info, |
1372 int request_id, | 1375 int request_id, |
1373 const ResourceRequest& request_data, | 1376 const ResourceRequest& request_data, |
1374 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1377 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
1375 int route_id, | 1378 int route_id, |
1376 const net::HttpRequestHeaders& headers, | 1379 const net::HttpRequestHeaders& headers, |
1377 mojom::URLLoaderAssociatedRequest mojo_request, | 1380 mojom::URLLoaderAssociatedRequest mojo_request, |
1378 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 1381 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
1379 bool continue_request, | 1382 bool continue_request, |
1380 int error_code) { | 1383 int error_code) { |
1381 DCHECK(requester_info->IsRenderer()); | 1384 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1382 if (!continue_request) { | 1385 if (!continue_request) { |
1386 DCHECK(requester_info->IsRenderer()); | |
mmenke
2016/12/01 15:26:11
I don't think this is right? We call out to "regi
mmenke
2016/12/01 15:26:51
Why they couldn't, rather
horo
2016/12/02 03:41:52
Ah, yes. This could be a navigation preload reques
| |
1383 // TODO(ananta): Find a way to specify the right error code here. Passing | 1387 // TODO(ananta): Find a way to specify the right error code here. Passing |
1384 // in a non-content error code is not safe. | 1388 // in a non-content error code is not safe. |
1385 bad_message::ReceivedBadMessage(requester_info->filter(), | 1389 bad_message::ReceivedBadMessage(requester_info->filter(), |
1386 bad_message::RDH_ILLEGAL_ORIGIN); | 1390 bad_message::RDH_ILLEGAL_ORIGIN); |
1387 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, | 1391 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, |
1388 request_id, std::move(url_loader_client)); | 1392 request_id, std::move(url_loader_client)); |
1389 return; | 1393 return; |
1390 } | 1394 } |
1391 int child_id = requester_info->child_id(); | 1395 int child_id = requester_info->child_id(); |
1392 | 1396 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 ResourceDispatcherHostImpl::CreateResourceHandler( | 1610 ResourceDispatcherHostImpl::CreateResourceHandler( |
1607 ResourceRequesterInfo* requester_info, | 1611 ResourceRequesterInfo* requester_info, |
1608 net::URLRequest* request, | 1612 net::URLRequest* request, |
1609 const ResourceRequest& request_data, | 1613 const ResourceRequest& request_data, |
1610 const SyncLoadResultCallback& sync_result_handler, | 1614 const SyncLoadResultCallback& sync_result_handler, |
1611 int route_id, | 1615 int route_id, |
1612 int child_id, | 1616 int child_id, |
1613 ResourceContext* resource_context, | 1617 ResourceContext* resource_context, |
1614 mojom::URLLoaderAssociatedRequest mojo_request, | 1618 mojom::URLLoaderAssociatedRequest mojo_request, |
1615 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1619 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
1616 DCHECK(requester_info->IsRenderer()); | 1620 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); |
1617 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1621 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
1618 tracked_objects::ScopedTracker tracking_profile( | 1622 tracked_objects::ScopedTracker tracking_profile( |
1619 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1623 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1620 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1624 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
1621 // Construct the IPC resource handler. | 1625 // Construct the IPC resource handler. |
1622 std::unique_ptr<ResourceHandler> handler; | 1626 std::unique_ptr<ResourceHandler> handler; |
1623 if (sync_result_handler) { | 1627 if (sync_result_handler) { |
1624 // download_to_file is not supported for synchronous requests. | 1628 // download_to_file is not supported for synchronous requests. |
1625 if (request_data.download_to_file) { | 1629 if (request_data.download_to_file) { |
1630 DCHECK(requester_info->IsRenderer()); | |
1626 bad_message::ReceivedBadMessage(requester_info->filter(), | 1631 bad_message::ReceivedBadMessage(requester_info->filter(), |
1627 bad_message::RDH_BAD_DOWNLOAD); | 1632 bad_message::RDH_BAD_DOWNLOAD); |
1628 return std::unique_ptr<ResourceHandler>(); | 1633 return std::unique_ptr<ResourceHandler>(); |
1629 } | 1634 } |
1630 | 1635 |
1631 DCHECK(!mojo_request.is_pending()); | 1636 DCHECK(!mojo_request.is_pending()); |
1632 DCHECK(!url_loader_client); | 1637 DCHECK(!url_loader_client); |
1633 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); | 1638 handler.reset(new SyncResourceHandler(request, sync_result_handler, this)); |
1634 } else { | 1639 } else { |
1635 if (mojo_request.is_pending()) { | 1640 if (mojo_request.is_pending()) { |
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2813 &throttles); | 2818 &throttles); |
2814 if (!throttles.empty()) { | 2819 if (!throttles.empty()) { |
2815 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2820 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2816 std::move(throttles))); | 2821 std::move(throttles))); |
2817 } | 2822 } |
2818 } | 2823 } |
2819 return handler; | 2824 return handler; |
2820 } | 2825 } |
2821 | 2826 |
2822 } // namespace content | 2827 } // namespace content |
OLD | NEW |