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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 static_cast<RenderFrameHostImpl*>(render_frame_host) | 537 static_cast<RenderFrameHostImpl*>(render_frame_host) |
532 ->GetGlobalFrameRoutingId(), | 538 ->GetGlobalFrameRoutingId(), |
533 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); | 539 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); |
534 } | 540 } |
535 | 541 |
536 // static | 542 // static |
537 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 543 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
538 return g_resource_dispatcher_host; | 544 return g_resource_dispatcher_host; |
539 } | 545 } |
540 | 546 |
547 // This is a helper class consisting of mojo-related functionalities used in | |
548 // ResourceDispatcherHostImpl. | |
549 class ResourceDispatcherHostImpl::MojoHelper final { | |
kinuko
2016/05/26 08:43:12
(At this point it may not make much sense to have
yhirano
2016/05/26 15:42:44
Done.
| |
550 public: | |
551 MojoHelper() {} | |
552 | |
553 // Adds |loader| as an uninitiated loader. | |
554 void AddUninitiatedURLLoader(int child_id, | |
555 std::unique_ptr<mojom::URLLoader> loader) { | |
556 mojom::URLLoader* raw = loader.get(); | |
557 uninitiated_url_loaders_.insert( | |
558 std::make_pair(raw, std::make_pair(child_id, std::move(loader)))); | |
559 } | |
560 | |
561 // Takes and returns the uninitiated loader whose address equals to |loader|. | |
562 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader( | |
563 mojom::URLLoader* loader) { | |
564 auto it = uninitiated_url_loaders_.find(loader); | |
565 if (it == uninitiated_url_loaders_.end()) | |
566 return nullptr; | |
567 std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second); | |
568 uninitiated_url_loaders_.erase(it); | |
569 return result; | |
570 } | |
571 | |
572 // Cancels all uninitiated loaders for |child_id|. | |
573 void CancelUninitiatedLoaders(int child_id) { | |
574 auto it = uninitiated_url_loaders_.begin(); | |
575 while (it != uninitiated_url_loaders_.end()) { | |
576 if (it->second.first == child_id) { | |
577 it = uninitiated_url_loaders_.erase(it); | |
578 } else { | |
579 ++it; | |
580 } | |
581 } | |
582 } | |
583 | |
584 private: | |
585 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>> | |
586 uninitiated_url_loaders_; | |
587 | |
588 DISALLOW_COPY_AND_ASSIGN(MojoHelper); | |
589 }; | |
590 | |
541 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() | 591 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
542 : save_file_manager_(new SaveFileManager()), | 592 : save_file_manager_(new SaveFileManager()), |
543 request_id_(-1), | 593 request_id_(-1), |
544 is_shutdown_(false), | 594 is_shutdown_(false), |
545 num_in_flight_requests_(0), | 595 num_in_flight_requests_(0), |
546 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 596 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
547 max_num_in_flight_requests_per_process_(static_cast<int>( | 597 max_num_in_flight_requests_per_process_(static_cast<int>( |
548 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 598 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
549 max_outstanding_requests_cost_per_process_( | 599 max_outstanding_requests_cost_per_process_( |
550 kMaxOutstandingRequestsCostPerProcess), | 600 kMaxOutstandingRequestsCostPerProcess), |
551 filter_(NULL), | 601 filter_(NULL), |
552 delegate_(NULL), | 602 delegate_(NULL), |
553 allow_cross_origin_auth_prompt_(false), | 603 allow_cross_origin_auth_prompt_(false), |
554 cert_store_for_testing_(nullptr) { | 604 cert_store_for_testing_(nullptr), |
605 mojo_helper_(new MojoHelper()) { | |
555 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 606 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
556 DCHECK(!g_resource_dispatcher_host); | 607 DCHECK(!g_resource_dispatcher_host); |
557 g_resource_dispatcher_host = this; | 608 g_resource_dispatcher_host = this; |
558 | 609 |
559 GetContentClient()->browser()->ResourceDispatcherHostCreated(); | 610 GetContentClient()->browser()->ResourceDispatcherHostCreated(); |
560 | 611 |
561 ANNOTATE_BENIGN_RACE( | 612 ANNOTATE_BENIGN_RACE( |
562 &last_user_gesture_time_, | 613 &last_user_gesture_time_, |
563 "We don't care about the precise value, see http://crbug.com/92889"); | 614 "We don't care about the precise value, see http://crbug.com/92889"); |
564 | 615 |
(...skipping 12 matching lines...) Expand all Loading... | |
577 // navigation becomes the default. crbug.com/561610 | 628 // navigation becomes the default. crbug.com/561610 |
578 if (!IsBrowserSideNavigationEnabled() && | 629 if (!IsBrowserSideNavigationEnabled() && |
579 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { | 630 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { |
580 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 631 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
581 } | 632 } |
582 } | 633 } |
583 | 634 |
584 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 635 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
585 DCHECK(outstanding_requests_stats_map_.empty()); | 636 DCHECK(outstanding_requests_stats_map_.empty()); |
586 DCHECK(g_resource_dispatcher_host); | 637 DCHECK(g_resource_dispatcher_host); |
638 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
587 g_resource_dispatcher_host = NULL; | 639 g_resource_dispatcher_host = NULL; |
588 } | 640 } |
589 | 641 |
590 // static | 642 // static |
591 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 643 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
592 return g_resource_dispatcher_host; | 644 return g_resource_dispatcher_host; |
593 } | 645 } |
594 | 646 |
595 // static | 647 // static |
596 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( | 648 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 for (const auto& routing_id : ids) { | 1223 for (const auto& routing_id : ids) { |
1172 CancelBlockedRequestsForRoute(routing_id); | 1224 CancelBlockedRequestsForRoute(routing_id); |
1173 } | 1225 } |
1174 | 1226 |
1175 scheduler_.reset(); | 1227 scheduler_.reset(); |
1176 } | 1228 } |
1177 | 1229 |
1178 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1230 bool ResourceDispatcherHostImpl::OnMessageReceived( |
1179 const IPC::Message& message, | 1231 const IPC::Message& message, |
1180 ResourceMessageFilter* filter) { | 1232 ResourceMessageFilter* filter) { |
1233 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
1181 filter_ = filter; | 1234 filter_ = filter; |
1182 bool handled = true; | 1235 bool handled = true; |
1183 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) | 1236 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
1184 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 1237 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
1185 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) | 1238 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) |
1186 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 1239 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
1187 OnReleaseDownloadedFile) | 1240 OnReleaseDownloadedFile) |
1188 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) | 1241 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) |
1189 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 1242 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
1190 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) | 1243 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) |
(...skipping 21 matching lines...) Expand all Loading... | |
1212 } | 1265 } |
1213 | 1266 |
1214 filter_ = NULL; | 1267 filter_ = NULL; |
1215 return handled; | 1268 return handled; |
1216 } | 1269 } |
1217 | 1270 |
1218 void ResourceDispatcherHostImpl::OnRequestResource( | 1271 void ResourceDispatcherHostImpl::OnRequestResource( |
1219 int routing_id, | 1272 int routing_id, |
1220 int request_id, | 1273 int request_id, |
1221 const ResourceRequest& request_data) { | 1274 const ResourceRequest& request_data) { |
1275 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, | |
1276 nullptr); | |
1277 } | |
1278 | |
1279 void ResourceDispatcherHostImpl::OnRequestResourceInternal( | |
1280 int routing_id, | |
1281 int request_id, | |
1282 const ResourceRequest& request_data, | |
1283 std::unique_ptr<mojom::URLLoader> url_loader, | |
1284 mojom::URLLoaderClientPtr url_loader_client) { | |
1222 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1285 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
1223 tracked_objects::ScopedTracker tracking_profile( | 1286 tracked_objects::ScopedTracker tracking_profile( |
1224 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1287 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1225 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1288 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
1226 // When logging time-to-network only care about main frame and non-transfer | 1289 // When logging time-to-network only care about main frame and non-transfer |
1227 // navigations. | 1290 // navigations. |
1228 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1291 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
1229 // instead. | 1292 // instead. |
1230 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1293 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
1231 request_data.transferred_request_request_id == -1 && | 1294 request_data.transferred_request_request_id == -1 && |
1232 !IsBrowserSideNavigationEnabled()) { | 1295 !IsBrowserSideNavigationEnabled()) { |
1233 BrowserThread::PostTask( | 1296 BrowserThread::PostTask( |
1234 BrowserThread::UI, | 1297 BrowserThread::UI, |
1235 FROM_HERE, | 1298 FROM_HERE, |
1236 base::Bind(&LogResourceRequestTimeOnUI, | 1299 base::Bind(&LogResourceRequestTimeOnUI, |
1237 TimeTicks::Now(), | 1300 TimeTicks::Now(), |
1238 filter_->child_id(), | 1301 filter_->child_id(), |
1239 request_data.render_frame_id, | 1302 request_data.render_frame_id, |
1240 request_data.url)); | 1303 request_data.url)); |
1241 } | 1304 } |
1242 BeginRequest(request_id, request_data, NULL, routing_id); | 1305 BeginRequest(request_id, request_data, NULL, routing_id, |
1306 std::move(url_loader), std::move(url_loader_client)); | |
1243 } | 1307 } |
1244 | 1308 |
1245 // Begins a resource request with the given params on behalf of the specified | 1309 // 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 | 1310 // 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 | 1311 // 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 | 1312 // a request from a renderer. request_context is the cookie/cache context to be |
1249 // used for this request. | 1313 // used for this request. |
1250 // | 1314 // |
1251 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1315 // 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. | 1316 // a normal asynchronous set of response messages will be generated. |
1253 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, | 1317 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, |
1254 const ResourceRequest& request_data, | 1318 const ResourceRequest& request_data, |
1255 IPC::Message* sync_result) { | 1319 IPC::Message* sync_result) { |
1256 BeginRequest(request_id, request_data, sync_result, | 1320 BeginRequest(request_id, request_data, sync_result, |
1257 sync_result->routing_id()); | 1321 sync_result->routing_id(), nullptr, nullptr); |
1258 } | 1322 } |
1259 | 1323 |
1260 bool ResourceDispatcherHostImpl::IsRequestIDInUse( | 1324 bool ResourceDispatcherHostImpl::IsRequestIDInUse( |
1261 const GlobalRequestID& id) const { | 1325 const GlobalRequestID& id) const { |
1262 if (pending_loaders_.find(id) != pending_loaders_.end()) | 1326 if (pending_loaders_.find(id) != pending_loaders_.end()) |
1263 return true; | 1327 return true; |
1264 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1328 for (const auto& blocked_loaders : blocked_loaders_map_) { |
1265 for (const auto& loader : *blocked_loaders.second.get()) { | 1329 for (const auto& loader : *blocked_loaders.second.get()) { |
1266 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1330 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
1267 if (info->GetGlobalRequestID() == id) | 1331 if (info->GetGlobalRequestID() == id) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1362 } | 1426 } |
1363 | 1427 |
1364 // We should have a CrossSiteResourceHandler to finish the transfer. | 1428 // We should have a CrossSiteResourceHandler to finish the transfer. |
1365 DCHECK(info->cross_site_handler()); | 1429 DCHECK(info->cross_site_handler()); |
1366 } | 1430 } |
1367 | 1431 |
1368 void ResourceDispatcherHostImpl::BeginRequest( | 1432 void ResourceDispatcherHostImpl::BeginRequest( |
1369 int request_id, | 1433 int request_id, |
1370 const ResourceRequest& request_data, | 1434 const ResourceRequest& request_data, |
1371 IPC::Message* sync_result, // only valid for sync | 1435 IPC::Message* sync_result, // only valid for sync |
1372 int route_id) { | 1436 int route_id, |
1437 std::unique_ptr<mojom::URLLoader> url_loader, | |
1438 mojom::URLLoaderClientPtr url_loader_client) { | |
1373 int process_type = filter_->process_type(); | 1439 int process_type = filter_->process_type(); |
1374 int child_id = filter_->child_id(); | 1440 int child_id = filter_->child_id(); |
1375 | 1441 |
1376 // Reject request id that's currently in use. | 1442 // Reject request id that's currently in use. |
1377 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1443 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
1378 bad_message::ReceivedBadMessage(filter_, | 1444 bad_message::ReceivedBadMessage(filter_, |
1379 bad_message::RDH_INVALID_REQUEST_ID); | 1445 bad_message::RDH_INVALID_REQUEST_ID); |
1380 return; | 1446 return; |
1381 } | 1447 } |
1382 | 1448 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1431 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | 1497 CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
1432 | 1498 |
1433 // Parse the headers before calling ShouldServiceRequest, so that they are | 1499 // Parse the headers before calling ShouldServiceRequest, so that they are |
1434 // available to be validated. | 1500 // available to be validated. |
1435 net::HttpRequestHeaders headers; | 1501 net::HttpRequestHeaders headers; |
1436 headers.AddHeadersFromString(request_data.headers); | 1502 headers.AddHeadersFromString(request_data.headers); |
1437 | 1503 |
1438 if (is_shutdown_ || | 1504 if (is_shutdown_ || |
1439 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1505 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
1440 filter_, resource_context)) { | 1506 filter_, resource_context)) { |
1441 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1507 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
1508 std::move(url_loader_client)); | |
1442 return; | 1509 return; |
1443 } | 1510 } |
1444 | 1511 |
1445 // Allow the observer to block/handle the request. | 1512 // Allow the observer to block/handle the request. |
1446 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1513 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
1447 request_data.url, | 1514 request_data.url, |
1448 request_data.resource_type, | 1515 request_data.resource_type, |
1449 resource_context)) { | 1516 resource_context)) { |
1450 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1517 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
1518 std::move(url_loader_client)); | |
1451 return; | 1519 return; |
1452 } | 1520 } |
1453 | 1521 |
1454 // Construct the request. | 1522 // Construct the request. |
1455 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 1523 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( |
1456 is_navigation_stream_request ? request_data.resource_body_stream_url | 1524 is_navigation_stream_request ? request_data.resource_body_stream_url |
1457 : request_data.url, | 1525 : request_data.url, |
1458 request_data.priority, nullptr); | 1526 request_data.priority, nullptr); |
1459 | 1527 |
1460 // PlzNavigate: Always set the method to GET when gaining access to the | 1528 // 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 } | 1689 } |
1622 | 1690 |
1623 // Have the appcache associate its extra info with the request. | 1691 // Have the appcache associate its extra info with the request. |
1624 AppCacheInterceptor::SetExtraRequestInfo( | 1692 AppCacheInterceptor::SetExtraRequestInfo( |
1625 new_request.get(), filter_->appcache_service(), child_id, | 1693 new_request.get(), filter_->appcache_service(), child_id, |
1626 request_data.appcache_host_id, request_data.resource_type, | 1694 request_data.appcache_host_id, request_data.resource_type, |
1627 request_data.should_reset_appcache); | 1695 request_data.should_reset_appcache); |
1628 | 1696 |
1629 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1697 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
1630 new_request.get(), request_data, sync_result, route_id, process_type, | 1698 new_request.get(), request_data, sync_result, route_id, process_type, |
1631 child_id, resource_context)); | 1699 child_id, resource_context, std::move(url_loader), |
1700 std::move(url_loader_client))); | |
1632 | 1701 |
1633 if (handler) | 1702 if (handler) |
1634 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1703 BeginRequestInternal(std::move(new_request), std::move(handler)); |
1635 } | 1704 } |
1636 | 1705 |
1637 std::unique_ptr<ResourceHandler> | 1706 std::unique_ptr<ResourceHandler> |
1638 ResourceDispatcherHostImpl::CreateResourceHandler( | 1707 ResourceDispatcherHostImpl::CreateResourceHandler( |
1639 net::URLRequest* request, | 1708 net::URLRequest* request, |
1640 const ResourceRequest& request_data, | 1709 const ResourceRequest& request_data, |
1641 IPC::Message* sync_result, | 1710 IPC::Message* sync_result, |
1642 int route_id, | 1711 int route_id, |
1643 int process_type, | 1712 int process_type, |
1644 int child_id, | 1713 int child_id, |
1645 ResourceContext* resource_context) { | 1714 ResourceContext* resource_context, |
1715 std::unique_ptr<mojom::URLLoader> url_loader, | |
1716 mojom::URLLoaderClientPtr url_loader_client) { | |
1646 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1717 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
1647 tracked_objects::ScopedTracker tracking_profile( | 1718 tracked_objects::ScopedTracker tracking_profile( |
1648 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1719 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1649 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1720 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
1650 // Construct the IPC resource handler. | 1721 // Construct the IPC resource handler. |
1651 std::unique_ptr<ResourceHandler> handler; | 1722 std::unique_ptr<ResourceHandler> handler; |
1652 if (sync_result) { | 1723 if (sync_result) { |
1653 // download_to_file is not supported for synchronous requests. | 1724 // download_to_file is not supported for synchronous requests. |
1654 if (request_data.download_to_file) { | 1725 if (request_data.download_to_file) { |
1655 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1726 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
1656 return std::unique_ptr<ResourceHandler>(); | 1727 return std::unique_ptr<ResourceHandler>(); |
1657 } | 1728 } |
1658 | 1729 |
1730 DCHECK(!url_loader); | |
1731 DCHECK(!url_loader_client); | |
1659 handler.reset(new SyncResourceHandler(request, sync_result, this)); | 1732 handler.reset(new SyncResourceHandler(request, sync_result, this)); |
1660 } else { | 1733 } else { |
1661 handler.reset(new AsyncResourceHandler(request, this)); | 1734 if (url_loader) { |
1735 handler.reset(new MojoAsyncResourceHandler( | |
1736 request, this, std::move(url_loader), std::move(url_loader_client))); | |
1737 } else { | |
1738 handler.reset(new AsyncResourceHandler(request, this)); | |
1739 } | |
1662 | 1740 |
1663 // The RedirectToFileResourceHandler depends on being next in the chain. | 1741 // The RedirectToFileResourceHandler depends on being next in the chain. |
1664 if (request_data.download_to_file) { | 1742 if (request_data.download_to_file) { |
1665 handler.reset( | 1743 handler.reset( |
1666 new RedirectToFileResourceHandler(std::move(handler), request)); | 1744 new RedirectToFileResourceHandler(std::move(handler), request)); |
1667 } | 1745 } |
1668 } | 1746 } |
1669 | 1747 |
1670 // Prefetches and <a ping> requests outlive their child process. | 1748 // Prefetches and <a ping> requests outlive their child process. |
1671 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { | 1749 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. | 2135 // blocked_loaders_map_, as blocking requests modifies the map. |
2058 std::set<GlobalFrameRoutingId> routing_ids; | 2136 std::set<GlobalFrameRoutingId> routing_ids; |
2059 for (const auto& blocked_loaders : blocked_loaders_map_) { | 2137 for (const auto& blocked_loaders : blocked_loaders_map_) { |
2060 if (blocked_loaders.first.child_id == child_id) | 2138 if (blocked_loaders.first.child_id == child_id) |
2061 routing_ids.insert(blocked_loaders.first); | 2139 routing_ids.insert(blocked_loaders.first); |
2062 } | 2140 } |
2063 for (const GlobalFrameRoutingId& route_id : routing_ids) { | 2141 for (const GlobalFrameRoutingId& route_id : routing_ids) { |
2064 CancelBlockedRequestsForRoute(route_id); | 2142 CancelBlockedRequestsForRoute(route_id); |
2065 } | 2143 } |
2066 } | 2144 } |
2145 | |
2146 // Uninitiated URLLoader has no routing ID, so it should be deleted only when | |
2147 // cancel_all_routes is specified. | |
2148 if (cancel_all_routes) | |
2149 mojo_helper_->CancelUninitiatedLoaders(child_id); | |
2067 } | 2150 } |
2068 | 2151 |
2069 // Cancels the request and removes it from the list. | 2152 // Cancels the request and removes it from the list. |
2070 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 2153 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
2071 int request_id) { | 2154 int request_id) { |
2072 LoaderMap::iterator i = pending_loaders_.find( | 2155 LoaderMap::iterator i = pending_loaders_.find( |
2073 GlobalRequestID(child_id, request_id)); | 2156 GlobalRequestID(child_id, request_id)); |
2074 if (i == pending_loaders_.end()) { | 2157 if (i == pending_loaders_.end()) { |
2075 NOTREACHED() << "Trying to remove a request that's not here"; | 2158 NOTREACHED() << "Trying to remove a request that's not here"; |
2076 return; | 2159 return; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2344 std::move(handler)); | 2427 std::move(handler)); |
2345 | 2428 |
2346 BeginRequestInternal(std::move(new_request), std::move(handler)); | 2429 BeginRequestInternal(std::move(new_request), std::move(handler)); |
2347 } | 2430 } |
2348 | 2431 |
2349 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | 2432 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
2350 if (!async_revalidation_manager_) | 2433 if (!async_revalidation_manager_) |
2351 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 2434 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
2352 } | 2435 } |
2353 | 2436 |
2437 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( | |
2438 int routing_id, | |
2439 int request_id, | |
2440 const ResourceRequest& request, | |
2441 std::unique_ptr<mojom::URLLoader> url_loader, | |
2442 mojom::URLLoaderClientPtr url_loader_client, | |
2443 ResourceMessageFilter* filter) { | |
2444 filter_ = filter; | |
2445 OnRequestResourceInternal(routing_id, request_id, request, | |
2446 std::move(url_loader), | |
2447 std::move(url_loader_client)); | |
2448 filter_ = nullptr; | |
2449 } | |
2450 | |
2451 void ResourceDispatcherHostImpl::AddUninitiatedURLLoader( | |
2452 int child_id, | |
2453 std::unique_ptr<mojom::URLLoader> loader) { | |
2454 mojo_helper_->AddUninitiatedURLLoader(child_id, std::move(loader)); | |
2455 } | |
2456 | |
2457 std::unique_ptr<mojom::URLLoader> | |
2458 ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) { | |
2459 return mojo_helper_->TakeUninitiatedURLLoader(loader); | |
2460 } | |
2461 | |
2354 // static | 2462 // static |
2355 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2463 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
2356 net::URLRequest* request) { | 2464 net::URLRequest* request) { |
2357 // The following fields should be a minor size contribution (experimentally | 2465 // The following fields should be a minor size contribution (experimentally |
2358 // on the order of 100). However since they are variable length, it could | 2466 // on the order of 100). However since they are variable length, it could |
2359 // in theory be a sizeable contribution. | 2467 // in theory be a sizeable contribution. |
2360 int strings_cost = request->extra_request_headers().ToString().size() + | 2468 int strings_cost = request->extra_request_headers().ToString().size() + |
2361 request->original_url().spec().size() + | 2469 request->original_url().spec().size() + |
2362 request->referrer().size() + | 2470 request->referrer().size() + |
2363 request->method().size(); | 2471 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); | 2798 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
2691 response->head.security_info = SerializeSecurityInfo(ssl); | 2799 response->head.security_info = SerializeSecurityInfo(ssl); |
2692 } | 2800 } |
2693 | 2801 |
2694 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2802 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
2695 return cert_store_for_testing_ ? cert_store_for_testing_ | 2803 return cert_store_for_testing_ ? cert_store_for_testing_ |
2696 : CertStore::GetInstance(); | 2804 : CertStore::GetInstance(); |
2697 } | 2805 } |
2698 | 2806 |
2699 } // namespace content | 2807 } // namespace content |
OLD | NEW |