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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "content/browser/download/save_file_manager.h" | 43 #include "content/browser/download/save_file_manager.h" |
44 #include "content/browser/download/save_file_resource_handler.h" | 44 #include "content/browser/download/save_file_resource_handler.h" |
45 #include "content/browser/frame_host/frame_tree.h" | 45 #include "content/browser/frame_host/frame_tree.h" |
46 #include "content/browser/frame_host/navigation_request_info.h" | 46 #include "content/browser/frame_host/navigation_request_info.h" |
47 #include "content/browser/frame_host/navigator.h" | 47 #include "content/browser/frame_host/navigator.h" |
48 #include "content/browser/loader/async_resource_handler.h" | 48 #include "content/browser/loader/async_resource_handler.h" |
49 #include "content/browser/loader/async_revalidation_manager.h" | 49 #include "content/browser/loader/async_revalidation_manager.h" |
50 #include "content/browser/loader/cross_site_resource_handler.h" | 50 #include "content/browser/loader/cross_site_resource_handler.h" |
51 #include "content/browser/loader/detachable_resource_handler.h" | 51 #include "content/browser/loader/detachable_resource_handler.h" |
52 #include "content/browser/loader/mime_type_resource_handler.h" | 52 #include "content/browser/loader/mime_type_resource_handler.h" |
| 53 #include "content/browser/loader/mojo_async_resource_handler.h" |
53 #include "content/browser/loader/navigation_resource_handler.h" | 54 #include "content/browser/loader/navigation_resource_handler.h" |
54 #include "content/browser/loader/navigation_resource_throttle.h" | 55 #include "content/browser/loader/navigation_resource_throttle.h" |
55 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 56 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
56 #include "content/browser/loader/power_save_block_resource_throttle.h" | 57 #include "content/browser/loader/power_save_block_resource_throttle.h" |
57 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 58 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
58 #include "content/browser/loader/resource_message_filter.h" | 59 #include "content/browser/loader/resource_message_filter.h" |
59 #include "content/browser/loader/resource_request_info_impl.h" | 60 #include "content/browser/loader/resource_request_info_impl.h" |
60 #include "content/browser/loader/stream_resource_handler.h" | 61 #include "content/browser/loader/stream_resource_handler.h" |
61 #include "content/browser/loader/sync_resource_handler.h" | 62 #include "content/browser/loader/sync_resource_handler.h" |
62 #include "content/browser/loader/throttling_resource_handler.h" | 63 #include "content/browser/loader/throttling_resource_handler.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 case RESOURCE_TYPE_CSP_REPORT: | 223 case RESOURCE_TYPE_CSP_REPORT: |
223 return true; | 224 return true; |
224 default: | 225 default: |
225 return false; | 226 return false; |
226 } | 227 } |
227 } | 228 } |
228 | 229 |
229 // Aborts a request before an URLRequest has actually been created. | 230 // Aborts a request before an URLRequest has actually been created. |
230 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, | 231 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, |
231 IPC::Message* sync_result, | 232 IPC::Message* sync_result, |
232 int request_id) { | 233 int request_id, |
| 234 mojom::URLLoaderClientPtr url_loader_client) { |
233 if (sync_result) { | 235 if (sync_result) { |
234 SyncLoadResult result; | 236 SyncLoadResult result; |
235 result.error_code = net::ERR_ABORTED; | 237 result.error_code = net::ERR_ABORTED; |
236 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); | 238 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); |
237 filter->Send(sync_result); | 239 filter->Send(sync_result); |
238 } else { | 240 } else { |
239 // Tell the renderer that this request was disallowed. | 241 // Tell the renderer that this request was disallowed. |
240 ResourceRequestCompletionStatus request_complete_data; | 242 ResourceRequestCompletionStatus request_complete_data; |
241 request_complete_data.error_code = net::ERR_ABORTED; | 243 request_complete_data.error_code = net::ERR_ABORTED; |
242 request_complete_data.was_ignored_by_handler = false; | 244 request_complete_data.was_ignored_by_handler = false; |
243 request_complete_data.exists_in_cache = false; | 245 request_complete_data.exists_in_cache = false; |
244 // No security info needed, connection not established. | 246 // No security info needed, connection not established. |
245 request_complete_data.completion_time = base::TimeTicks(); | 247 request_complete_data.completion_time = base::TimeTicks(); |
246 request_complete_data.encoded_data_length = 0; | 248 request_complete_data.encoded_data_length = 0; |
247 filter->Send(new ResourceMsg_RequestComplete( | 249 if (url_loader_client) { |
248 request_id, request_complete_data)); | 250 url_loader_client->OnComplete(request_complete_data); |
| 251 } else { |
| 252 filter->Send( |
| 253 new ResourceMsg_RequestComplete(request_id, request_complete_data)); |
| 254 } |
249 } | 255 } |
250 } | 256 } |
251 | 257 |
252 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { | 258 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { |
253 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 259 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
254 if (!referrer.url.is_valid() || | 260 if (!referrer.url.is_valid() || |
255 command_line->HasSwitch(switches::kNoReferrers)) { | 261 command_line->HasSwitch(switches::kNoReferrers)) { |
256 request->SetReferrer(std::string()); | 262 request->SetReferrer(std::string()); |
257 } else { | 263 } else { |
258 request->SetReferrer(referrer.url.spec()); | 264 request->SetReferrer(referrer.url.spec()); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 // navigation becomes the default. crbug.com/561610 | 583 // navigation becomes the default. crbug.com/561610 |
578 if (!IsBrowserSideNavigationEnabled() && | 584 if (!IsBrowserSideNavigationEnabled() && |
579 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { | 585 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { |
580 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 586 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
581 } | 587 } |
582 } | 588 } |
583 | 589 |
584 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 590 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
585 DCHECK(outstanding_requests_stats_map_.empty()); | 591 DCHECK(outstanding_requests_stats_map_.empty()); |
586 DCHECK(g_resource_dispatcher_host); | 592 DCHECK(g_resource_dispatcher_host); |
| 593 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
587 g_resource_dispatcher_host = NULL; | 594 g_resource_dispatcher_host = NULL; |
588 } | 595 } |
589 | 596 |
590 // static | 597 // static |
591 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 598 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
592 return g_resource_dispatcher_host; | 599 return g_resource_dispatcher_host; |
593 } | 600 } |
594 | 601 |
595 // static | 602 // static |
596 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( | 603 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 for (const auto& routing_id : ids) { | 1178 for (const auto& routing_id : ids) { |
1172 CancelBlockedRequestsForRoute(routing_id); | 1179 CancelBlockedRequestsForRoute(routing_id); |
1173 } | 1180 } |
1174 | 1181 |
1175 scheduler_.reset(); | 1182 scheduler_.reset(); |
1176 } | 1183 } |
1177 | 1184 |
1178 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1185 bool ResourceDispatcherHostImpl::OnMessageReceived( |
1179 const IPC::Message& message, | 1186 const IPC::Message& message, |
1180 ResourceMessageFilter* filter) { | 1187 ResourceMessageFilter* filter) { |
| 1188 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1181 filter_ = filter; | 1189 filter_ = filter; |
1182 bool handled = true; | 1190 bool handled = true; |
1183 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) | 1191 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
1184 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 1192 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
1185 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) | 1193 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) |
1186 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 1194 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
1187 OnReleaseDownloadedFile) | 1195 OnReleaseDownloadedFile) |
1188 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) | 1196 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) |
1189 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 1197 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
1190 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) | 1198 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) |
(...skipping 21 matching lines...) Expand all Loading... |
1212 } | 1220 } |
1213 | 1221 |
1214 filter_ = NULL; | 1222 filter_ = NULL; |
1215 return handled; | 1223 return handled; |
1216 } | 1224 } |
1217 | 1225 |
1218 void ResourceDispatcherHostImpl::OnRequestResource( | 1226 void ResourceDispatcherHostImpl::OnRequestResource( |
1219 int routing_id, | 1227 int routing_id, |
1220 int request_id, | 1228 int request_id, |
1221 const ResourceRequest& request_data) { | 1229 const ResourceRequest& request_data) { |
| 1230 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, |
| 1231 nullptr); |
| 1232 } |
| 1233 |
| 1234 void ResourceDispatcherHostImpl::OnRequestResourceInternal( |
| 1235 int routing_id, |
| 1236 int request_id, |
| 1237 const ResourceRequest& request_data, |
| 1238 std::unique_ptr<mojom::URLLoader> url_loader, |
| 1239 mojom::URLLoaderClientPtr url_loader_client) { |
1222 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1240 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
1223 tracked_objects::ScopedTracker tracking_profile( | 1241 tracked_objects::ScopedTracker tracking_profile( |
1224 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1242 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1225 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1243 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
1226 // When logging time-to-network only care about main frame and non-transfer | 1244 // When logging time-to-network only care about main frame and non-transfer |
1227 // navigations. | 1245 // navigations. |
1228 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1246 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
1229 // instead. | 1247 // instead. |
1230 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1248 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
1231 request_data.transferred_request_request_id == -1 && | 1249 request_data.transferred_request_request_id == -1 && |
1232 !IsBrowserSideNavigationEnabled()) { | 1250 !IsBrowserSideNavigationEnabled()) { |
1233 BrowserThread::PostTask( | 1251 BrowserThread::PostTask( |
1234 BrowserThread::UI, | 1252 BrowserThread::UI, |
1235 FROM_HERE, | 1253 FROM_HERE, |
1236 base::Bind(&LogResourceRequestTimeOnUI, | 1254 base::Bind(&LogResourceRequestTimeOnUI, |
1237 TimeTicks::Now(), | 1255 TimeTicks::Now(), |
1238 filter_->child_id(), | 1256 filter_->child_id(), |
1239 request_data.render_frame_id, | 1257 request_data.render_frame_id, |
1240 request_data.url)); | 1258 request_data.url)); |
1241 } | 1259 } |
1242 BeginRequest(request_id, request_data, NULL, routing_id); | 1260 BeginRequest(request_id, request_data, NULL, routing_id, |
| 1261 std::move(url_loader), std::move(url_loader_client)); |
1243 } | 1262 } |
1244 | 1263 |
1245 // Begins a resource request with the given params on behalf of the specified | 1264 // Begins a resource request with the given params on behalf of the specified |
1246 // child process. Responses will be dispatched through the given receiver. The | 1265 // child process. Responses will be dispatched through the given receiver. The |
1247 // process ID is used to lookup WebContentsImpl from routing_id's in the case of | 1266 // process ID is used to lookup WebContentsImpl from routing_id's in the case of |
1248 // a request from a renderer. request_context is the cookie/cache context to be | 1267 // a request from a renderer. request_context is the cookie/cache context to be |
1249 // used for this request. | 1268 // used for this request. |
1250 // | 1269 // |
1251 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1270 // If sync_result is non-null, then a SyncLoad reply will be generated, else |
1252 // a normal asynchronous set of response messages will be generated. | 1271 // a normal asynchronous set of response messages will be generated. |
1253 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, | 1272 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, |
1254 const ResourceRequest& request_data, | 1273 const ResourceRequest& request_data, |
1255 IPC::Message* sync_result) { | 1274 IPC::Message* sync_result) { |
1256 BeginRequest(request_id, request_data, sync_result, | 1275 BeginRequest(request_id, request_data, sync_result, sync_result->routing_id(), |
1257 sync_result->routing_id()); | 1276 nullptr, nullptr); |
1258 } | 1277 } |
1259 | 1278 |
1260 bool ResourceDispatcherHostImpl::IsRequestIDInUse( | 1279 bool ResourceDispatcherHostImpl::IsRequestIDInUse( |
1261 const GlobalRequestID& id) const { | 1280 const GlobalRequestID& id) const { |
1262 if (pending_loaders_.find(id) != pending_loaders_.end()) | 1281 if (pending_loaders_.find(id) != pending_loaders_.end()) |
1263 return true; | 1282 return true; |
1264 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1283 for (const auto& blocked_loaders : blocked_loaders_map_) { |
1265 for (const auto& loader : *blocked_loaders.second.get()) { | 1284 for (const auto& loader : *blocked_loaders.second.get()) { |
1266 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1285 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
1267 if (info->GetGlobalRequestID() == id) | 1286 if (info->GetGlobalRequestID() == id) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 } | 1381 } |
1363 | 1382 |
1364 // We should have a CrossSiteResourceHandler to finish the transfer. | 1383 // We should have a CrossSiteResourceHandler to finish the transfer. |
1365 DCHECK(info->cross_site_handler()); | 1384 DCHECK(info->cross_site_handler()); |
1366 } | 1385 } |
1367 | 1386 |
1368 void ResourceDispatcherHostImpl::BeginRequest( | 1387 void ResourceDispatcherHostImpl::BeginRequest( |
1369 int request_id, | 1388 int request_id, |
1370 const ResourceRequest& request_data, | 1389 const ResourceRequest& request_data, |
1371 IPC::Message* sync_result, // only valid for sync | 1390 IPC::Message* sync_result, // only valid for sync |
1372 int route_id) { | 1391 int route_id, |
| 1392 std::unique_ptr<mojom::URLLoader> url_loader, |
| 1393 mojom::URLLoaderClientPtr url_loader_client) { |
1373 int process_type = filter_->process_type(); | 1394 int process_type = filter_->process_type(); |
1374 int child_id = filter_->child_id(); | 1395 int child_id = filter_->child_id(); |
1375 | 1396 |
1376 // Reject request id that's currently in use. | 1397 // Reject request id that's currently in use. |
1377 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1398 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
1378 bad_message::ReceivedBadMessage(filter_, | 1399 bad_message::ReceivedBadMessage(filter_, |
1379 bad_message::RDH_INVALID_REQUEST_ID); | 1400 bad_message::RDH_INVALID_REQUEST_ID); |
1380 return; | 1401 return; |
1381 } | 1402 } |
1382 | 1403 |
(...skipping 19 matching lines...) Expand all Loading... |
1402 char url_buf[128]; | 1423 char url_buf[128]; |
1403 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1424 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
1404 base::debug::Alias(url_buf); | 1425 base::debug::Alias(url_buf); |
1405 | 1426 |
1406 // If the request that's coming in is being transferred from another process, | 1427 // If the request that's coming in is being transferred from another process, |
1407 // we want to reuse and resume the old loader rather than start a new one. | 1428 // we want to reuse and resume the old loader rather than start a new one. |
1408 LoaderMap::iterator it = pending_loaders_.find( | 1429 LoaderMap::iterator it = pending_loaders_.find( |
1409 GlobalRequestID(request_data.transferred_request_child_id, | 1430 GlobalRequestID(request_data.transferred_request_child_id, |
1410 request_data.transferred_request_request_id)); | 1431 request_data.transferred_request_request_id)); |
1411 if (it != pending_loaders_.end()) { | 1432 if (it != pending_loaders_.end()) { |
| 1433 // TODO(yhirano): Make mojo work for this case. |
| 1434 DCHECK(!url_loader); |
| 1435 DCHECK(!url_loader_client); |
| 1436 |
1412 // If the request is transferring to a new process, we can update our | 1437 // If the request is transferring to a new process, we can update our |
1413 // state and let it resume with its existing ResourceHandlers. | 1438 // state and let it resume with its existing ResourceHandlers. |
1414 if (it->second->is_transferring()) { | 1439 if (it->second->is_transferring()) { |
1415 ResourceLoader* deferred_loader = it->second.get(); | 1440 ResourceLoader* deferred_loader = it->second.get(); |
1416 UpdateRequestForTransfer(child_id, route_id, request_id, | 1441 UpdateRequestForTransfer(child_id, route_id, request_id, |
1417 request_data, it); | 1442 request_data, it); |
1418 deferred_loader->CompleteTransfer(); | 1443 deferred_loader->CompleteTransfer(); |
1419 } else { | 1444 } else { |
1420 bad_message::ReceivedBadMessage( | 1445 bad_message::ReceivedBadMessage( |
1421 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1446 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
1422 } | 1447 } |
1423 return; | 1448 return; |
1424 } | 1449 } |
1425 | 1450 |
1426 ResourceContext* resource_context = NULL; | 1451 ResourceContext* resource_context = NULL; |
1427 net::URLRequestContext* request_context = NULL; | 1452 net::URLRequestContext* request_context = NULL; |
1428 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, | 1453 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, |
1429 &resource_context, &request_context); | 1454 &resource_context, &request_context); |
1430 // http://crbug.com/90971 | 1455 // http://crbug.com/90971 |
1431 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | 1456 CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
1432 | 1457 |
1433 // Parse the headers before calling ShouldServiceRequest, so that they are | 1458 // Parse the headers before calling ShouldServiceRequest, so that they are |
1434 // available to be validated. | 1459 // available to be validated. |
1435 net::HttpRequestHeaders headers; | 1460 net::HttpRequestHeaders headers; |
1436 headers.AddHeadersFromString(request_data.headers); | 1461 headers.AddHeadersFromString(request_data.headers); |
1437 | 1462 |
1438 if (is_shutdown_ || | 1463 if (is_shutdown_ || |
1439 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1464 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
1440 filter_, resource_context)) { | 1465 filter_, resource_context)) { |
1441 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1466 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
| 1467 std::move(url_loader_client)); |
1442 return; | 1468 return; |
1443 } | 1469 } |
1444 | 1470 |
1445 // Allow the observer to block/handle the request. | 1471 // Allow the observer to block/handle the request. |
1446 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1472 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
1447 request_data.url, | 1473 request_data.url, |
1448 request_data.resource_type, | 1474 request_data.resource_type, |
1449 resource_context)) { | 1475 resource_context)) { |
1450 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1476 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
| 1477 std::move(url_loader_client)); |
1451 return; | 1478 return; |
1452 } | 1479 } |
1453 | 1480 |
1454 // Construct the request. | 1481 // Construct the request. |
1455 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 1482 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( |
1456 is_navigation_stream_request ? request_data.resource_body_stream_url | 1483 is_navigation_stream_request ? request_data.resource_body_stream_url |
1457 : request_data.url, | 1484 : request_data.url, |
1458 request_data.priority, nullptr); | 1485 request_data.priority, nullptr); |
1459 | 1486 |
1460 // PlzNavigate: Always set the method to GET when gaining access to the | 1487 // PlzNavigate: Always set the method to GET when gaining access to the |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 } | 1649 } |
1623 | 1650 |
1624 // Have the appcache associate its extra info with the request. | 1651 // Have the appcache associate its extra info with the request. |
1625 AppCacheInterceptor::SetExtraRequestInfo( | 1652 AppCacheInterceptor::SetExtraRequestInfo( |
1626 new_request.get(), filter_->appcache_service(), child_id, | 1653 new_request.get(), filter_->appcache_service(), child_id, |
1627 request_data.appcache_host_id, request_data.resource_type, | 1654 request_data.appcache_host_id, request_data.resource_type, |
1628 request_data.should_reset_appcache); | 1655 request_data.should_reset_appcache); |
1629 | 1656 |
1630 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1657 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
1631 new_request.get(), request_data, sync_result, route_id, process_type, | 1658 new_request.get(), request_data, sync_result, route_id, process_type, |
1632 child_id, resource_context)); | 1659 child_id, resource_context, std::move(url_loader), |
| 1660 std::move(url_loader_client))); |
1633 | 1661 |
1634 if (handler) | 1662 if (handler) |
1635 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1663 BeginRequestInternal(std::move(new_request), std::move(handler)); |
1636 } | 1664 } |
1637 | 1665 |
1638 std::unique_ptr<ResourceHandler> | 1666 std::unique_ptr<ResourceHandler> |
1639 ResourceDispatcherHostImpl::CreateResourceHandler( | 1667 ResourceDispatcherHostImpl::CreateResourceHandler( |
1640 net::URLRequest* request, | 1668 net::URLRequest* request, |
1641 const ResourceRequest& request_data, | 1669 const ResourceRequest& request_data, |
1642 IPC::Message* sync_result, | 1670 IPC::Message* sync_result, |
1643 int route_id, | 1671 int route_id, |
1644 int process_type, | 1672 int process_type, |
1645 int child_id, | 1673 int child_id, |
1646 ResourceContext* resource_context) { | 1674 ResourceContext* resource_context, |
| 1675 std::unique_ptr<mojom::URLLoader> url_loader, |
| 1676 mojom::URLLoaderClientPtr url_loader_client) { |
1647 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1677 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
1648 tracked_objects::ScopedTracker tracking_profile( | 1678 tracked_objects::ScopedTracker tracking_profile( |
1649 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1679 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1650 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1680 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
1651 // Construct the IPC resource handler. | 1681 // Construct the IPC resource handler. |
1652 std::unique_ptr<ResourceHandler> handler; | 1682 std::unique_ptr<ResourceHandler> handler; |
1653 if (sync_result) { | 1683 if (sync_result) { |
1654 // download_to_file is not supported for synchronous requests. | 1684 // download_to_file is not supported for synchronous requests. |
1655 if (request_data.download_to_file) { | 1685 if (request_data.download_to_file) { |
1656 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1686 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
1657 return std::unique_ptr<ResourceHandler>(); | 1687 return std::unique_ptr<ResourceHandler>(); |
1658 } | 1688 } |
1659 | 1689 |
| 1690 DCHECK(!url_loader); |
| 1691 DCHECK(!url_loader_client); |
1660 handler.reset(new SyncResourceHandler(request, sync_result, this)); | 1692 handler.reset(new SyncResourceHandler(request, sync_result, this)); |
1661 } else { | 1693 } else { |
1662 handler.reset(new AsyncResourceHandler(request, this)); | 1694 if (url_loader) { |
| 1695 handler.reset(new MojoAsyncResourceHandler( |
| 1696 request, this, std::move(url_loader), std::move(url_loader_client))); |
| 1697 } else { |
| 1698 handler.reset(new AsyncResourceHandler(request, this)); |
| 1699 } |
1663 | 1700 |
1664 // The RedirectToFileResourceHandler depends on being next in the chain. | 1701 // The RedirectToFileResourceHandler depends on being next in the chain. |
1665 if (request_data.download_to_file) { | 1702 if (request_data.download_to_file) { |
1666 handler.reset( | 1703 handler.reset( |
1667 new RedirectToFileResourceHandler(std::move(handler), request)); | 1704 new RedirectToFileResourceHandler(std::move(handler), request)); |
1668 } | 1705 } |
1669 } | 1706 } |
1670 | 1707 |
1671 // Prefetches and <a ping> requests outlive their child process. | 1708 // Prefetches and <a ping> requests outlive their child process. |
1672 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { | 1709 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2347 std::move(handler)); | 2384 std::move(handler)); |
2348 | 2385 |
2349 BeginRequestInternal(std::move(new_request), std::move(handler)); | 2386 BeginRequestInternal(std::move(new_request), std::move(handler)); |
2350 } | 2387 } |
2351 | 2388 |
2352 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | 2389 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
2353 if (!async_revalidation_manager_) | 2390 if (!async_revalidation_manager_) |
2354 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 2391 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
2355 } | 2392 } |
2356 | 2393 |
| 2394 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( |
| 2395 int routing_id, |
| 2396 int request_id, |
| 2397 const ResourceRequest& request, |
| 2398 std::unique_ptr<mojom::URLLoader> url_loader, |
| 2399 mojom::URLLoaderClientPtr url_loader_client, |
| 2400 ResourceMessageFilter* filter) { |
| 2401 filter_ = filter; |
| 2402 OnRequestResourceInternal(routing_id, request_id, request, |
| 2403 std::move(url_loader), |
| 2404 std::move(url_loader_client)); |
| 2405 filter_ = nullptr; |
| 2406 } |
| 2407 |
2357 // static | 2408 // static |
2358 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2409 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
2359 net::URLRequest* request) { | 2410 net::URLRequest* request) { |
2360 // The following fields should be a minor size contribution (experimentally | 2411 // The following fields should be a minor size contribution (experimentally |
2361 // on the order of 100). However since they are variable length, it could | 2412 // on the order of 100). However since they are variable length, it could |
2362 // in theory be a sizeable contribution. | 2413 // in theory be a sizeable contribution. |
2363 int strings_cost = request->extra_request_headers().ToString().size() + | 2414 int strings_cost = request->extra_request_headers().ToString().size() + |
2364 request->original_url().spec().size() + | 2415 request->original_url().spec().size() + |
2365 request->referrer().size() + | 2416 request->referrer().size() + |
2366 request->method().size(); | 2417 request->method().size(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2693 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2744 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
2694 response->head.security_info = SerializeSecurityInfo(ssl); | 2745 response->head.security_info = SerializeSecurityInfo(ssl); |
2695 } | 2746 } |
2696 | 2747 |
2697 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2748 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
2698 return cert_store_for_testing_ ? cert_store_for_testing_ | 2749 return cert_store_for_testing_ ? cert_store_for_testing_ |
2699 : CertStore::GetInstance(); | 2750 : CertStore::GetInstance(); |
2700 } | 2751 } |
2701 | 2752 |
2702 } // namespace content | 2753 } // namespace content |
OLD | NEW |