Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/loader_delegate.h" 52 #include "content/browser/loader/loader_delegate.h"
53 #include "content/browser/loader/mime_type_resource_handler.h" 53 #include "content/browser/loader/mime_type_resource_handler.h"
54 #include "content/browser/loader/mojo_async_resource_handler.h"
54 #include "content/browser/loader/navigation_resource_handler.h" 55 #include "content/browser/loader/navigation_resource_handler.h"
55 #include "content/browser/loader/navigation_resource_throttle.h" 56 #include "content/browser/loader/navigation_resource_throttle.h"
56 #include "content/browser/loader/navigation_url_loader_impl_core.h" 57 #include "content/browser/loader/navigation_url_loader_impl_core.h"
57 #include "content/browser/loader/power_save_block_resource_throttle.h" 58 #include "content/browser/loader/power_save_block_resource_throttle.h"
58 #include "content/browser/loader/redirect_to_file_resource_handler.h" 59 #include "content/browser/loader/redirect_to_file_resource_handler.h"
59 #include "content/browser/loader/resource_message_filter.h" 60 #include "content/browser/loader/resource_message_filter.h"
60 #include "content/browser/loader/resource_request_info_impl.h" 61 #include "content/browser/loader/resource_request_info_impl.h"
61 #include "content/browser/loader/stream_resource_handler.h" 62 #include "content/browser/loader/stream_resource_handler.h"
62 #include "content/browser/loader/sync_resource_handler.h" 63 #include "content/browser/loader/sync_resource_handler.h"
63 #include "content/browser/loader/throttling_resource_handler.h" 64 #include "content/browser/loader/throttling_resource_handler.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 case RESOURCE_TYPE_CSP_REPORT: 218 case RESOURCE_TYPE_CSP_REPORT:
218 return true; 219 return true;
219 default: 220 default:
220 return false; 221 return false;
221 } 222 }
222 } 223 }
223 224
224 // Aborts a request before an URLRequest has actually been created. 225 // Aborts a request before an URLRequest has actually been created.
225 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, 226 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
226 IPC::Message* sync_result, 227 IPC::Message* sync_result,
227 int request_id) { 228 int request_id,
229 mojom::URLLoaderClientPtr url_loader_client) {
228 if (sync_result) { 230 if (sync_result) {
229 SyncLoadResult result; 231 SyncLoadResult result;
230 result.error_code = net::ERR_ABORTED; 232 result.error_code = net::ERR_ABORTED;
231 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); 233 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result);
232 filter->Send(sync_result); 234 filter->Send(sync_result);
233 } else { 235 } else {
234 // Tell the renderer that this request was disallowed. 236 // Tell the renderer that this request was disallowed.
235 ResourceRequestCompletionStatus request_complete_data; 237 ResourceRequestCompletionStatus request_complete_data;
236 request_complete_data.error_code = net::ERR_ABORTED; 238 request_complete_data.error_code = net::ERR_ABORTED;
237 request_complete_data.was_ignored_by_handler = false; 239 request_complete_data.was_ignored_by_handler = false;
238 request_complete_data.exists_in_cache = false; 240 request_complete_data.exists_in_cache = false;
239 // No security info needed, connection not established. 241 // No security info needed, connection not established.
240 request_complete_data.completion_time = base::TimeTicks(); 242 request_complete_data.completion_time = base::TimeTicks();
241 request_complete_data.encoded_data_length = 0; 243 request_complete_data.encoded_data_length = 0;
242 filter->Send(new ResourceMsg_RequestComplete( 244 if (url_loader_client) {
243 request_id, request_complete_data)); 245 url_loader_client->OnComplete(request_complete_data);
246 } else {
247 filter->Send(
248 new ResourceMsg_RequestComplete(request_id, request_complete_data));
249 }
244 } 250 }
245 } 251 }
246 252
247 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { 253 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) {
248 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 254 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
249 if (!referrer.url.is_valid() || 255 if (!referrer.url.is_valid() ||
250 command_line->HasSwitch(switches::kNoReferrers)) { 256 command_line->HasSwitch(switches::kNoReferrers)) {
251 request->SetReferrer(std::string()); 257 request->SetReferrer(std::string());
252 } else { 258 } else {
253 request->SetReferrer(referrer.url.spec()); 259 request->SetReferrer(referrer.url.spec());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // navigation becomes the default. crbug.com/561610 474 // navigation becomes the default. crbug.com/561610
469 if (!IsBrowserSideNavigationEnabled() && 475 if (!IsBrowserSideNavigationEnabled() &&
470 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { 476 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) {
471 async_revalidation_manager_.reset(new AsyncRevalidationManager); 477 async_revalidation_manager_.reset(new AsyncRevalidationManager);
472 } 478 }
473 } 479 }
474 480
475 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { 481 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
476 DCHECK(outstanding_requests_stats_map_.empty()); 482 DCHECK(outstanding_requests_stats_map_.empty());
477 DCHECK(g_resource_dispatcher_host); 483 DCHECK(g_resource_dispatcher_host);
484 DCHECK_CURRENTLY_ON(BrowserThread::UI);
478 g_resource_dispatcher_host = NULL; 485 g_resource_dispatcher_host = NULL;
479 } 486 }
480 487
481 // static 488 // static
482 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 489 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
483 return g_resource_dispatcher_host; 490 return g_resource_dispatcher_host;
484 } 491 }
485 492
486 // static 493 // static
487 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( 494 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 for (const auto& routing_id : ids) { 1057 for (const auto& routing_id : ids) {
1051 CancelBlockedRequestsForRoute(routing_id); 1058 CancelBlockedRequestsForRoute(routing_id);
1052 } 1059 }
1053 1060
1054 scheduler_.reset(); 1061 scheduler_.reset();
1055 } 1062 }
1056 1063
1057 bool ResourceDispatcherHostImpl::OnMessageReceived( 1064 bool ResourceDispatcherHostImpl::OnMessageReceived(
1058 const IPC::Message& message, 1065 const IPC::Message& message,
1059 ResourceMessageFilter* filter) { 1066 ResourceMessageFilter* filter) {
1067 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1060 filter_ = filter; 1068 filter_ = filter;
1061 bool handled = true; 1069 bool handled = true;
1062 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1070 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1063 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1071 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1064 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1072 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
1065 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, 1073 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile,
1066 OnReleaseDownloadedFile) 1074 OnReleaseDownloadedFile)
1067 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) 1075 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
1068 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) 1076 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest)
1069 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) 1077 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority)
(...skipping 21 matching lines...) Expand all
1091 } 1099 }
1092 1100
1093 filter_ = NULL; 1101 filter_ = NULL;
1094 return handled; 1102 return handled;
1095 } 1103 }
1096 1104
1097 void ResourceDispatcherHostImpl::OnRequestResource( 1105 void ResourceDispatcherHostImpl::OnRequestResource(
1098 int routing_id, 1106 int routing_id,
1099 int request_id, 1107 int request_id,
1100 const ResourceRequest& request_data) { 1108 const ResourceRequest& request_data) {
1109 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr,
1110 nullptr);
1111 }
1112
1113 void ResourceDispatcherHostImpl::OnRequestResourceInternal(
1114 int routing_id,
1115 int request_id,
1116 const ResourceRequest& request_data,
1117 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1118 mojom::URLLoaderClientPtr url_loader_client) {
1101 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 1119 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
1102 tracked_objects::ScopedTracker tracking_profile( 1120 tracked_objects::ScopedTracker tracking_profile(
1103 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1121 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1104 "477117 ResourceDispatcherHostImpl::OnRequestResource")); 1122 "477117 ResourceDispatcherHostImpl::OnRequestResource"));
1105 // When logging time-to-network only care about main frame and non-transfer 1123 // When logging time-to-network only care about main frame and non-transfer
1106 // navigations. 1124 // navigations.
1107 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted 1125 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted
1108 // instead. 1126 // instead.
1109 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && 1127 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME &&
1110 request_data.transferred_request_request_id == -1 && 1128 request_data.transferred_request_request_id == -1 &&
1111 !IsBrowserSideNavigationEnabled()) { 1129 !IsBrowserSideNavigationEnabled()) {
1112 BrowserThread::PostTask( 1130 BrowserThread::PostTask(
1113 BrowserThread::UI, 1131 BrowserThread::UI,
1114 FROM_HERE, 1132 FROM_HERE,
1115 base::Bind(&LogResourceRequestTimeOnUI, 1133 base::Bind(&LogResourceRequestTimeOnUI,
1116 TimeTicks::Now(), 1134 TimeTicks::Now(),
1117 filter_->child_id(), 1135 filter_->child_id(),
1118 request_data.render_frame_id, 1136 request_data.render_frame_id,
1119 request_data.url)); 1137 request_data.url));
1120 } 1138 }
1121 BeginRequest(request_id, request_data, NULL, routing_id); 1139 BeginRequest(request_id, request_data, NULL, routing_id,
1140 std::move(mojo_request), std::move(url_loader_client));
1122 } 1141 }
1123 1142
1124 // Begins a resource request with the given params on behalf of the specified 1143 // Begins a resource request with the given params on behalf of the specified
1125 // child process. Responses will be dispatched through the given receiver. The 1144 // child process. Responses will be dispatched through the given receiver. The
1126 // process ID is used to lookup WebContentsImpl from routing_id's in the case of 1145 // process ID is used to lookup WebContentsImpl from routing_id's in the case of
1127 // a request from a renderer. request_context is the cookie/cache context to be 1146 // a request from a renderer. request_context is the cookie/cache context to be
1128 // used for this request. 1147 // used for this request.
1129 // 1148 //
1130 // If sync_result is non-null, then a SyncLoad reply will be generated, else 1149 // If sync_result is non-null, then a SyncLoad reply will be generated, else
1131 // a normal asynchronous set of response messages will be generated. 1150 // a normal asynchronous set of response messages will be generated.
1132 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, 1151 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id,
1133 const ResourceRequest& request_data, 1152 const ResourceRequest& request_data,
1134 IPC::Message* sync_result) { 1153 IPC::Message* sync_result) {
1135 BeginRequest(request_id, request_data, sync_result, 1154 BeginRequest(request_id, request_data, sync_result, sync_result->routing_id(),
1136 sync_result->routing_id()); 1155 nullptr, nullptr);
1137 } 1156 }
1138 1157
1139 bool ResourceDispatcherHostImpl::IsRequestIDInUse( 1158 bool ResourceDispatcherHostImpl::IsRequestIDInUse(
1140 const GlobalRequestID& id) const { 1159 const GlobalRequestID& id) const {
1141 if (pending_loaders_.find(id) != pending_loaders_.end()) 1160 if (pending_loaders_.find(id) != pending_loaders_.end())
1142 return true; 1161 return true;
1143 for (const auto& blocked_loaders : blocked_loaders_map_) { 1162 for (const auto& blocked_loaders : blocked_loaders_map_) {
1144 for (const auto& loader : *blocked_loaders.second.get()) { 1163 for (const auto& loader : *blocked_loaders.second.get()) {
1145 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1164 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1146 if (info->GetGlobalRequestID() == id) 1165 if (info->GetGlobalRequestID() == id)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 } 1260 }
1242 1261
1243 // We should have a CrossSiteResourceHandler to finish the transfer. 1262 // We should have a CrossSiteResourceHandler to finish the transfer.
1244 DCHECK(info->cross_site_handler()); 1263 DCHECK(info->cross_site_handler());
1245 } 1264 }
1246 1265
1247 void ResourceDispatcherHostImpl::BeginRequest( 1266 void ResourceDispatcherHostImpl::BeginRequest(
1248 int request_id, 1267 int request_id,
1249 const ResourceRequest& request_data, 1268 const ResourceRequest& request_data,
1250 IPC::Message* sync_result, // only valid for sync 1269 IPC::Message* sync_result, // only valid for sync
1251 int route_id) { 1270 int route_id,
1271 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1272 mojom::URLLoaderClientPtr url_loader_client) {
1252 int process_type = filter_->process_type(); 1273 int process_type = filter_->process_type();
1253 int child_id = filter_->child_id(); 1274 int child_id = filter_->child_id();
1254 1275
1255 // Reject request id that's currently in use. 1276 // Reject request id that's currently in use.
1256 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { 1277 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) {
1257 bad_message::ReceivedBadMessage(filter_, 1278 bad_message::ReceivedBadMessage(filter_,
1258 bad_message::RDH_INVALID_REQUEST_ID); 1279 bad_message::RDH_INVALID_REQUEST_ID);
1259 return; 1280 return;
1260 } 1281 }
1261 1282
(...skipping 19 matching lines...) Expand all
1281 char url_buf[128]; 1302 char url_buf[128];
1282 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); 1303 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf));
1283 base::debug::Alias(url_buf); 1304 base::debug::Alias(url_buf);
1284 1305
1285 // If the request that's coming in is being transferred from another process, 1306 // If the request that's coming in is being transferred from another process,
1286 // we want to reuse and resume the old loader rather than start a new one. 1307 // we want to reuse and resume the old loader rather than start a new one.
1287 LoaderMap::iterator it = pending_loaders_.find( 1308 LoaderMap::iterator it = pending_loaders_.find(
1288 GlobalRequestID(request_data.transferred_request_child_id, 1309 GlobalRequestID(request_data.transferred_request_child_id,
1289 request_data.transferred_request_request_id)); 1310 request_data.transferred_request_request_id));
1290 if (it != pending_loaders_.end()) { 1311 if (it != pending_loaders_.end()) {
1312 // TODO(yhirano): Make mojo work for this case.
1313 DCHECK(!url_loader_client);
1314
1291 // If the request is transferring to a new process, we can update our 1315 // If the request is transferring to a new process, we can update our
1292 // state and let it resume with its existing ResourceHandlers. 1316 // state and let it resume with its existing ResourceHandlers.
1293 if (it->second->is_transferring()) { 1317 if (it->second->is_transferring()) {
1294 ResourceLoader* deferred_loader = it->second.get(); 1318 ResourceLoader* deferred_loader = it->second.get();
1295 UpdateRequestForTransfer(child_id, route_id, request_id, 1319 UpdateRequestForTransfer(child_id, route_id, request_id,
1296 request_data, it); 1320 request_data, it);
1297 deferred_loader->CompleteTransfer(); 1321 deferred_loader->CompleteTransfer();
1298 } else { 1322 } else {
1299 bad_message::ReceivedBadMessage( 1323 bad_message::ReceivedBadMessage(
1300 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); 1324 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING);
1301 } 1325 }
1302 return; 1326 return;
1303 } 1327 }
1304 1328
1305 ResourceContext* resource_context = NULL; 1329 ResourceContext* resource_context = NULL;
1306 net::URLRequestContext* request_context = NULL; 1330 net::URLRequestContext* request_context = NULL;
1307 filter_->GetContexts(request_data.resource_type, &resource_context, 1331 filter_->GetContexts(request_data.resource_type, &resource_context,
1308 &request_context); 1332 &request_context);
1309 1333
1310 // Parse the headers before calling ShouldServiceRequest, so that they are 1334 // Parse the headers before calling ShouldServiceRequest, so that they are
1311 // available to be validated. 1335 // available to be validated.
1312 net::HttpRequestHeaders headers; 1336 net::HttpRequestHeaders headers;
1313 headers.AddHeadersFromString(request_data.headers); 1337 headers.AddHeadersFromString(request_data.headers);
1314 1338
1315 if (is_shutdown_ || 1339 if (is_shutdown_ ||
1316 !ShouldServiceRequest(process_type, child_id, request_data, headers, 1340 !ShouldServiceRequest(process_type, child_id, request_data, headers,
1317 filter_, resource_context)) { 1341 filter_, resource_context)) {
1318 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1342 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1343 std::move(url_loader_client));
1319 return; 1344 return;
1320 } 1345 }
1321 // Check if we have a registered interceptor for the headers passed in. If 1346 // Check if we have a registered interceptor for the headers passed in. If
1322 // yes then we need to mark the current request as pending and wait for the 1347 // yes then we need to mark the current request as pending and wait for the
1323 // interceptor to invoke the callback with a status code indicating whether 1348 // interceptor to invoke the callback with a status code indicating whether
1324 // the request needs to be aborted or continued. 1349 // the request needs to be aborted or continued.
1325 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { 1350 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) {
1326 HeaderInterceptorMap::iterator index = 1351 HeaderInterceptorMap::iterator index =
1327 http_header_interceptor_map_.find(it.name()); 1352 http_header_interceptor_map_.find(it.name());
1328 if (index != http_header_interceptor_map_.end()) { 1353 if (index != http_header_interceptor_map_.end()) {
1329 HeaderInterceptorInfo& interceptor_info = index->second; 1354 HeaderInterceptorInfo& interceptor_info = index->second;
1330 1355
1331 bool call_interceptor = true; 1356 bool call_interceptor = true;
1332 if (!interceptor_info.starts_with.empty()) { 1357 if (!interceptor_info.starts_with.empty()) {
1333 call_interceptor = 1358 call_interceptor =
1334 base::StartsWith(it.value(), interceptor_info.starts_with, 1359 base::StartsWith(it.value(), interceptor_info.starts_with,
1335 base::CompareCase::INSENSITIVE_ASCII); 1360 base::CompareCase::INSENSITIVE_ASCII);
1336 } 1361 }
1337 if (call_interceptor) { 1362 if (call_interceptor) {
1338 interceptor_info.interceptor.Run( 1363 interceptor_info.interceptor.Run(
1339 it.name(), it.value(), child_id, resource_context, 1364 it.name(), it.value(), child_id, resource_context,
1340 base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest, 1365 base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest,
1341 base::Unretained(this), request_id, request_data, 1366 base::Unretained(this), request_id, request_data,
1342 sync_result, route_id, headers)); 1367 sync_result, route_id, headers,
1368 base::Passed(std::move(mojo_request)),
1369 base::Passed(std::move(url_loader_client))));
1343 return; 1370 return;
1344 } 1371 }
1345 } 1372 }
1346 } 1373 }
1347 ContinuePendingBeginRequest(request_id, request_data, sync_result, route_id, 1374 ContinuePendingBeginRequest(request_id, request_data, sync_result, route_id,
1348 headers, true, 0); 1375 headers, std::move(mojo_request),
1376 std::move(url_loader_client), true, 0);
1349 } 1377 }
1350 1378
1351 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( 1379 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
1352 int request_id, 1380 int request_id,
1353 const ResourceRequest& request_data, 1381 const ResourceRequest& request_data,
1354 IPC::Message* sync_result, // only valid for sync 1382 IPC::Message* sync_result, // only valid for sync
1355 int route_id, 1383 int route_id,
1356 const net::HttpRequestHeaders& headers, 1384 const net::HttpRequestHeaders& headers,
1385 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1386 mojom::URLLoaderClientPtr url_loader_client,
1357 bool continue_request, 1387 bool continue_request,
1358 int error_code) { 1388 int error_code) {
1359 if (!continue_request) { 1389 if (!continue_request) {
1360 // TODO(ananta): Find a way to specify the right error code here. Passing 1390 // TODO(ananta): Find a way to specify the right error code here. Passing
1361 // in a non-content error code is not safe. 1391 // in a non-content error code is not safe.
1362 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_ILLEGAL_ORIGIN); 1392 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_ILLEGAL_ORIGIN);
1363 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1393 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1394 std::move(url_loader_client));
1364 return; 1395 return;
1365 } 1396 }
1366 1397
1367 int process_type = filter_->process_type(); 1398 int process_type = filter_->process_type();
1368 int child_id = filter_->child_id(); 1399 int child_id = filter_->child_id();
1369 1400
1370 bool is_navigation_stream_request = 1401 bool is_navigation_stream_request =
1371 IsBrowserSideNavigationEnabled() && 1402 IsBrowserSideNavigationEnabled() &&
1372 IsResourceTypeFrame(request_data.resource_type); 1403 IsResourceTypeFrame(request_data.resource_type);
1373 1404
1374 ResourceContext* resource_context = NULL; 1405 ResourceContext* resource_context = NULL;
1375 net::URLRequestContext* request_context = NULL; 1406 net::URLRequestContext* request_context = NULL;
1376 filter_->GetContexts(request_data.resource_type, &resource_context, 1407 filter_->GetContexts(request_data.resource_type, &resource_context,
1377 &request_context); 1408 &request_context);
1378 1409
1379 // Allow the observer to block/handle the request. 1410 // Allow the observer to block/handle the request.
1380 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, 1411 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method,
1381 request_data.url, 1412 request_data.url,
1382 request_data.resource_type, 1413 request_data.resource_type,
1383 resource_context)) { 1414 resource_context)) {
1384 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1415 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1416 std::move(url_loader_client));
1385 return; 1417 return;
1386 } 1418 }
1387 1419
1388 // Construct the request. 1420 // Construct the request.
1389 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( 1421 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest(
1390 is_navigation_stream_request ? request_data.resource_body_stream_url 1422 is_navigation_stream_request ? request_data.resource_body_stream_url
1391 : request_data.url, 1423 : request_data.url,
1392 request_data.priority, nullptr); 1424 request_data.priority, nullptr);
1393 1425
1394 // PlzNavigate: Always set the method to GET when gaining access to the 1426 // PlzNavigate: Always set the method to GET when gaining access to the
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 request_data.initiated_in_secure_context); 1583 request_data.initiated_in_secure_context);
1552 1584
1553 // Have the appcache associate its extra info with the request. 1585 // Have the appcache associate its extra info with the request.
1554 AppCacheInterceptor::SetExtraRequestInfo( 1586 AppCacheInterceptor::SetExtraRequestInfo(
1555 new_request.get(), filter_->appcache_service(), child_id, 1587 new_request.get(), filter_->appcache_service(), child_id,
1556 request_data.appcache_host_id, request_data.resource_type, 1588 request_data.appcache_host_id, request_data.resource_type,
1557 request_data.should_reset_appcache); 1589 request_data.should_reset_appcache);
1558 1590
1559 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( 1591 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
1560 new_request.get(), request_data, sync_result, route_id, process_type, 1592 new_request.get(), request_data, sync_result, route_id, process_type,
1561 child_id, resource_context)); 1593 child_id, resource_context, std::move(mojo_request),
1594 std::move(url_loader_client)));
1562 1595
1563 if (handler) 1596 if (handler)
1564 BeginRequestInternal(std::move(new_request), std::move(handler)); 1597 BeginRequestInternal(std::move(new_request), std::move(handler));
1565 } 1598 }
1566 1599
1567 std::unique_ptr<ResourceHandler> 1600 std::unique_ptr<ResourceHandler>
1568 ResourceDispatcherHostImpl::CreateResourceHandler( 1601 ResourceDispatcherHostImpl::CreateResourceHandler(
1569 net::URLRequest* request, 1602 net::URLRequest* request,
1570 const ResourceRequest& request_data, 1603 const ResourceRequest& request_data,
1571 IPC::Message* sync_result, 1604 IPC::Message* sync_result,
1572 int route_id, 1605 int route_id,
1573 int process_type, 1606 int process_type,
1574 int child_id, 1607 int child_id,
1575 ResourceContext* resource_context) { 1608 ResourceContext* resource_context,
1609 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1610 mojom::URLLoaderClientPtr url_loader_client) {
1576 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 1611 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
1577 tracked_objects::ScopedTracker tracking_profile( 1612 tracked_objects::ScopedTracker tracking_profile(
1578 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1613 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1579 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); 1614 "456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
1580 // Construct the IPC resource handler. 1615 // Construct the IPC resource handler.
1581 std::unique_ptr<ResourceHandler> handler; 1616 std::unique_ptr<ResourceHandler> handler;
1582 if (sync_result) { 1617 if (sync_result) {
1583 // download_to_file is not supported for synchronous requests. 1618 // download_to_file is not supported for synchronous requests.
1584 if (request_data.download_to_file) { 1619 if (request_data.download_to_file) {
1585 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); 1620 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
1586 return std::unique_ptr<ResourceHandler>(); 1621 return std::unique_ptr<ResourceHandler>();
1587 } 1622 }
1588 1623
1624 DCHECK(!mojo_request.is_pending());
1625 DCHECK(!url_loader_client);
1589 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1626 handler.reset(new SyncResourceHandler(request, sync_result, this));
1590 } else { 1627 } else {
1591 handler.reset(new AsyncResourceHandler(request, this)); 1628 if (mojo_request.is_pending()) {
1629 handler.reset(new MojoAsyncResourceHandler(request, this,
1630 std::move(mojo_request),
1631 std::move(url_loader_client)));
1632 } else {
1633 handler.reset(new AsyncResourceHandler(request, this));
1634 }
1592 1635
1593 // The RedirectToFileResourceHandler depends on being next in the chain. 1636 // The RedirectToFileResourceHandler depends on being next in the chain.
1594 if (request_data.download_to_file) { 1637 if (request_data.download_to_file) {
1595 handler.reset( 1638 handler.reset(
1596 new RedirectToFileResourceHandler(std::move(handler), request)); 1639 new RedirectToFileResourceHandler(std::move(handler), request));
1597 } 1640 }
1598 } 1641 }
1599 1642
1600 // Prefetches and <a ping> requests outlive their child process. 1643 // Prefetches and <a ping> requests outlive their child process.
1601 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { 1644 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) {
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 void ResourceDispatcherHostImpl::SetLoaderDelegate( 2324 void ResourceDispatcherHostImpl::SetLoaderDelegate(
2282 LoaderDelegate* loader_delegate) { 2325 LoaderDelegate* loader_delegate) {
2283 loader_delegate_ = loader_delegate; 2326 loader_delegate_ = loader_delegate;
2284 } 2327 }
2285 2328
2286 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( 2329 void ResourceDispatcherHostImpl::OnRenderFrameDeleted(
2287 const GlobalFrameRoutingId& global_routing_id) { 2330 const GlobalFrameRoutingId& global_routing_id) {
2288 CancelRequestsForRoute(global_routing_id); 2331 CancelRequestsForRoute(global_routing_id);
2289 } 2332 }
2290 2333
2334 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo(
2335 int routing_id,
2336 int request_id,
2337 const ResourceRequest& request,
2338 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
2339 mojom::URLLoaderClientPtr url_loader_client,
2340 ResourceMessageFilter* filter) {
2341 filter_ = filter;
2342 OnRequestResourceInternal(routing_id, request_id, request,
2343 std::move(mojo_request),
2344 std::move(url_loader_client));
2345 filter_ = nullptr;
2346 }
2347
2291 // static 2348 // static
2292 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2349 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2293 net::URLRequest* request) { 2350 net::URLRequest* request) {
2294 // The following fields should be a minor size contribution (experimentally 2351 // The following fields should be a minor size contribution (experimentally
2295 // on the order of 100). However since they are variable length, it could 2352 // on the order of 100). However since they are variable length, it could
2296 // in theory be a sizeable contribution. 2353 // in theory be a sizeable contribution.
2297 int strings_cost = request->extra_request_headers().ToString().size() + 2354 int strings_cost = request->extra_request_headers().ToString().size() +
2298 request->original_url().spec().size() + 2355 request->original_url().spec().size() +
2299 request->referrer().size() + 2356 request->referrer().size() +
2300 request->method().size(); 2357 request->method().size();
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2665 << iter->filesystem_url().spec(); 2722 << iter->filesystem_url().spec();
2666 return false; 2723 return false;
2667 } 2724 }
2668 } 2725 }
2669 } 2726 }
2670 } 2727 }
2671 return true; 2728 return true;
2672 } 2729 }
2673 2730
2674 } // namespace content 2731 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/resource_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698