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 18 matching lines...) Expand all Loading... | |
1401 // http://crbug.com/91398 | 1422 // http://crbug.com/91398 |
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()) { |
mmenke
2016/05/26 15:18:49
This case isn't being handled.
yhirano
2016/05/27 11:30:34
Added a TODO comment.
| |
1412 // If the request is transferring to a new process, we can update our | 1433 // If the request is transferring to a new process, we can update our |
1413 // state and let it resume with its existing ResourceHandlers. | 1434 // state and let it resume with its existing ResourceHandlers. |
1414 if (it->second->is_transferring()) { | 1435 if (it->second->is_transferring()) { |
1415 ResourceLoader* deferred_loader = it->second.get(); | 1436 ResourceLoader* deferred_loader = it->second.get(); |
1416 UpdateRequestForTransfer(child_id, route_id, request_id, | 1437 UpdateRequestForTransfer(child_id, route_id, request_id, |
1417 request_data, it); | 1438 request_data, it); |
1418 deferred_loader->CompleteTransfer(); | 1439 deferred_loader->CompleteTransfer(); |
1419 } else { | 1440 } else { |
1420 bad_message::ReceivedBadMessage( | 1441 bad_message::ReceivedBadMessage( |
1421 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1442 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
1422 } | 1443 } |
1423 return; | 1444 return; |
1424 } | 1445 } |
1425 | 1446 |
1426 ResourceContext* resource_context = NULL; | 1447 ResourceContext* resource_context = NULL; |
1427 net::URLRequestContext* request_context = NULL; | 1448 net::URLRequestContext* request_context = NULL; |
1428 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, | 1449 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, |
1429 &resource_context, &request_context); | 1450 &resource_context, &request_context); |
1430 // http://crbug.com/90971 | 1451 // http://crbug.com/90971 |
1431 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | 1452 CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
1432 | 1453 |
1433 // Parse the headers before calling ShouldServiceRequest, so that they are | 1454 // Parse the headers before calling ShouldServiceRequest, so that they are |
1434 // available to be validated. | 1455 // available to be validated. |
1435 net::HttpRequestHeaders headers; | 1456 net::HttpRequestHeaders headers; |
1436 headers.AddHeadersFromString(request_data.headers); | 1457 headers.AddHeadersFromString(request_data.headers); |
1437 | 1458 |
1438 if (is_shutdown_ || | 1459 if (is_shutdown_ || |
1439 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1460 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
1440 filter_, resource_context)) { | 1461 filter_, resource_context)) { |
1441 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1462 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
1463 std::move(url_loader_client)); | |
1442 return; | 1464 return; |
1443 } | 1465 } |
1444 | 1466 |
1445 // Allow the observer to block/handle the request. | 1467 // Allow the observer to block/handle the request. |
1446 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1468 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
1447 request_data.url, | 1469 request_data.url, |
1448 request_data.resource_type, | 1470 request_data.resource_type, |
1449 resource_context)) { | 1471 resource_context)) { |
1450 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1472 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
1473 std::move(url_loader_client)); | |
1451 return; | 1474 return; |
1452 } | 1475 } |
1453 | 1476 |
1454 // Construct the request. | 1477 // Construct the request. |
1455 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 1478 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( |
1456 is_navigation_stream_request ? request_data.resource_body_stream_url | 1479 is_navigation_stream_request ? request_data.resource_body_stream_url |
1457 : request_data.url, | 1480 : request_data.url, |
1458 request_data.priority, nullptr); | 1481 request_data.priority, nullptr); |
1459 | 1482 |
1460 // PlzNavigate: Always set the method to GET when gaining access to the | 1483 // PlzNavigate: Always set the method to GET when gaining access to the |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1621 } | 1644 } |
1622 | 1645 |
1623 // Have the appcache associate its extra info with the request. | 1646 // Have the appcache associate its extra info with the request. |
1624 AppCacheInterceptor::SetExtraRequestInfo( | 1647 AppCacheInterceptor::SetExtraRequestInfo( |
1625 new_request.get(), filter_->appcache_service(), child_id, | 1648 new_request.get(), filter_->appcache_service(), child_id, |
1626 request_data.appcache_host_id, request_data.resource_type, | 1649 request_data.appcache_host_id, request_data.resource_type, |
1627 request_data.should_reset_appcache); | 1650 request_data.should_reset_appcache); |
1628 | 1651 |
1629 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1652 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
1630 new_request.get(), request_data, sync_result, route_id, process_type, | 1653 new_request.get(), request_data, sync_result, route_id, process_type, |
1631 child_id, resource_context)); | 1654 child_id, resource_context, std::move(url_loader), |
1655 std::move(url_loader_client))); | |
1632 | 1656 |
1633 if (handler) | 1657 if (handler) |
1634 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1658 BeginRequestInternal(std::move(new_request), std::move(handler)); |
1635 } | 1659 } |
1636 | 1660 |
1637 std::unique_ptr<ResourceHandler> | 1661 std::unique_ptr<ResourceHandler> |
1638 ResourceDispatcherHostImpl::CreateResourceHandler( | 1662 ResourceDispatcherHostImpl::CreateResourceHandler( |
1639 net::URLRequest* request, | 1663 net::URLRequest* request, |
1640 const ResourceRequest& request_data, | 1664 const ResourceRequest& request_data, |
1641 IPC::Message* sync_result, | 1665 IPC::Message* sync_result, |
1642 int route_id, | 1666 int route_id, |
1643 int process_type, | 1667 int process_type, |
1644 int child_id, | 1668 int child_id, |
1645 ResourceContext* resource_context) { | 1669 ResourceContext* resource_context, |
1670 std::unique_ptr<mojom::URLLoader> url_loader, | |
1671 mojom::URLLoaderClientPtr url_loader_client) { | |
1646 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1672 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
1647 tracked_objects::ScopedTracker tracking_profile( | 1673 tracked_objects::ScopedTracker tracking_profile( |
1648 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1674 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1649 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1675 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
1650 // Construct the IPC resource handler. | 1676 // Construct the IPC resource handler. |
1651 std::unique_ptr<ResourceHandler> handler; | 1677 std::unique_ptr<ResourceHandler> handler; |
1652 if (sync_result) { | 1678 if (sync_result) { |
1653 // download_to_file is not supported for synchronous requests. | 1679 // download_to_file is not supported for synchronous requests. |
1654 if (request_data.download_to_file) { | 1680 if (request_data.download_to_file) { |
1655 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1681 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
1656 return std::unique_ptr<ResourceHandler>(); | 1682 return std::unique_ptr<ResourceHandler>(); |
1657 } | 1683 } |
1658 | 1684 |
1685 DCHECK(!url_loader); | |
1686 DCHECK(!url_loader_client); | |
1659 handler.reset(new SyncResourceHandler(request, sync_result, this)); | 1687 handler.reset(new SyncResourceHandler(request, sync_result, this)); |
1660 } else { | 1688 } else { |
1661 handler.reset(new AsyncResourceHandler(request, this)); | 1689 if (url_loader) { |
1690 handler.reset(new MojoAsyncResourceHandler( | |
1691 request, this, std::move(url_loader), std::move(url_loader_client))); | |
1692 } else { | |
1693 handler.reset(new AsyncResourceHandler(request, this)); | |
1694 } | |
1662 | 1695 |
1663 // The RedirectToFileResourceHandler depends on being next in the chain. | 1696 // The RedirectToFileResourceHandler depends on being next in the chain. |
1664 if (request_data.download_to_file) { | 1697 if (request_data.download_to_file) { |
1665 handler.reset( | 1698 handler.reset( |
1666 new RedirectToFileResourceHandler(std::move(handler), request)); | 1699 new RedirectToFileResourceHandler(std::move(handler), request)); |
1667 } | 1700 } |
1668 } | 1701 } |
1669 | 1702 |
1670 // Prefetches and <a ping> requests outlive their child process. | 1703 // Prefetches and <a ping> requests outlive their child process. |
1671 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { | 1704 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2057 // blocked_loaders_map_, as blocking requests modifies the map. | 2090 // blocked_loaders_map_, as blocking requests modifies the map. |
2058 std::set<GlobalFrameRoutingId> routing_ids; | 2091 std::set<GlobalFrameRoutingId> routing_ids; |
2059 for (const auto& blocked_loaders : blocked_loaders_map_) { | 2092 for (const auto& blocked_loaders : blocked_loaders_map_) { |
2060 if (blocked_loaders.first.child_id == child_id) | 2093 if (blocked_loaders.first.child_id == child_id) |
2061 routing_ids.insert(blocked_loaders.first); | 2094 routing_ids.insert(blocked_loaders.first); |
2062 } | 2095 } |
2063 for (const GlobalFrameRoutingId& route_id : routing_ids) { | 2096 for (const GlobalFrameRoutingId& route_id : routing_ids) { |
2064 CancelBlockedRequestsForRoute(route_id); | 2097 CancelBlockedRequestsForRoute(route_id); |
2065 } | 2098 } |
2066 } | 2099 } |
2100 | |
2101 // Unstarted URLLoader has no routing ID, so it should be deleted only when | |
2102 // cancel_all_routes is specified. | |
2103 if (cancel_all_routes) { | |
2104 auto it = unstarted_url_loaders_.begin(); | |
2105 while (it != unstarted_url_loaders_.end()) { | |
2106 if (it->second.first == child_id) { | |
2107 it = unstarted_url_loaders_.erase(it); | |
2108 } else { | |
2109 ++it; | |
2110 } | |
2111 } | |
2112 } | |
2067 } | 2113 } |
2068 | 2114 |
2069 // Cancels the request and removes it from the list. | 2115 // Cancels the request and removes it from the list. |
2070 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 2116 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
2071 int request_id) { | 2117 int request_id) { |
2072 LoaderMap::iterator i = pending_loaders_.find( | 2118 LoaderMap::iterator i = pending_loaders_.find( |
2073 GlobalRequestID(child_id, request_id)); | 2119 GlobalRequestID(child_id, request_id)); |
2074 if (i == pending_loaders_.end()) { | 2120 if (i == pending_loaders_.end()) { |
2075 NOTREACHED() << "Trying to remove a request that's not here"; | 2121 NOTREACHED() << "Trying to remove a request that's not here"; |
2076 return; | 2122 return; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2344 std::move(handler)); | 2390 std::move(handler)); |
2345 | 2391 |
2346 BeginRequestInternal(std::move(new_request), std::move(handler)); | 2392 BeginRequestInternal(std::move(new_request), std::move(handler)); |
2347 } | 2393 } |
2348 | 2394 |
2349 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | 2395 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
2350 if (!async_revalidation_manager_) | 2396 if (!async_revalidation_manager_) |
2351 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 2397 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
2352 } | 2398 } |
2353 | 2399 |
2400 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( | |
2401 int routing_id, | |
2402 int request_id, | |
2403 const ResourceRequest& request, | |
2404 std::unique_ptr<mojom::URLLoader> url_loader, | |
2405 mojom::URLLoaderClientPtr url_loader_client, | |
2406 ResourceMessageFilter* filter) { | |
2407 filter_ = filter; | |
2408 OnRequestResourceInternal(routing_id, request_id, request, | |
2409 std::move(url_loader), | |
2410 std::move(url_loader_client)); | |
2411 filter_ = nullptr; | |
2412 } | |
2413 | |
2414 void ResourceDispatcherHostImpl::AddUnstartedURLLoader( | |
2415 int child_id, | |
2416 std::unique_ptr<mojom::URLLoader> loader) { | |
2417 mojom::URLLoader* raw = loader.get(); | |
2418 unstarted_url_loaders_.insert( | |
2419 std::make_pair(raw, std::make_pair(child_id, std::move(loader)))); | |
2420 } | |
2421 | |
2422 std::unique_ptr<mojom::URLLoader> | |
2423 ResourceDispatcherHostImpl::TakeUnstartedURLLoader(mojom::URLLoader* loader) { | |
2424 auto it = unstarted_url_loaders_.find(loader); | |
2425 if (it == unstarted_url_loaders_.end()) | |
2426 return nullptr; | |
2427 std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second); | |
2428 unstarted_url_loaders_.erase(it); | |
2429 return result; | |
2430 } | |
2431 | |
2354 // static | 2432 // static |
2355 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2433 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
2356 net::URLRequest* request) { | 2434 net::URLRequest* request) { |
2357 // The following fields should be a minor size contribution (experimentally | 2435 // The following fields should be a minor size contribution (experimentally |
2358 // on the order of 100). However since they are variable length, it could | 2436 // on the order of 100). However since they are variable length, it could |
2359 // in theory be a sizeable contribution. | 2437 // in theory be a sizeable contribution. |
2360 int strings_cost = request->extra_request_headers().ToString().size() + | 2438 int strings_cost = request->extra_request_headers().ToString().size() + |
2361 request->original_url().spec().size() + | 2439 request->original_url().spec().size() + |
2362 request->referrer().size() + | 2440 request->referrer().size() + |
2363 request->method().size(); | 2441 request->method().size(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2768 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
2691 response->head.security_info = SerializeSecurityInfo(ssl); | 2769 response->head.security_info = SerializeSecurityInfo(ssl); |
2692 } | 2770 } |
2693 | 2771 |
2694 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2772 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
2695 return cert_store_for_testing_ ? cert_store_for_testing_ | 2773 return cert_store_for_testing_ ? cert_store_for_testing_ |
2696 : CertStore::GetInstance(); | 2774 : CertStore::GetInstance(); |
2697 } | 2775 } |
2698 | 2776 |
2699 } // namespace content | 2777 } // namespace content |
OLD | NEW |