| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 case RESOURCE_TYPE_CSP_REPORT: | 219 case RESOURCE_TYPE_CSP_REPORT: |
| 219 return true; | 220 return true; |
| 220 default: | 221 default: |
| 221 return false; | 222 return false; |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 | 225 |
| 225 // Aborts a request before an URLRequest has actually been created. | 226 // Aborts a request before an URLRequest has actually been created. |
| 226 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, | 227 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, |
| 227 IPC::Message* sync_result, | 228 IPC::Message* sync_result, |
| 228 int request_id) { | 229 int request_id, |
| 230 mojom::URLLoaderClientPtr url_loader_client) { |
| 229 if (sync_result) { | 231 if (sync_result) { |
| 230 SyncLoadResult result; | 232 SyncLoadResult result; |
| 231 result.error_code = net::ERR_ABORTED; | 233 result.error_code = net::ERR_ABORTED; |
| 232 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); | 234 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); |
| 233 filter->Send(sync_result); | 235 filter->Send(sync_result); |
| 234 } else { | 236 } else { |
| 235 // Tell the renderer that this request was disallowed. | 237 // Tell the renderer that this request was disallowed. |
| 236 ResourceRequestCompletionStatus request_complete_data; | 238 ResourceRequestCompletionStatus request_complete_data; |
| 237 request_complete_data.error_code = net::ERR_ABORTED; | 239 request_complete_data.error_code = net::ERR_ABORTED; |
| 238 request_complete_data.was_ignored_by_handler = false; | 240 request_complete_data.was_ignored_by_handler = false; |
| 239 request_complete_data.exists_in_cache = false; | 241 request_complete_data.exists_in_cache = false; |
| 240 // No security info needed, connection not established. | 242 // No security info needed, connection not established. |
| 241 request_complete_data.completion_time = base::TimeTicks(); | 243 request_complete_data.completion_time = base::TimeTicks(); |
| 242 request_complete_data.encoded_data_length = 0; | 244 request_complete_data.encoded_data_length = 0; |
| 243 filter->Send(new ResourceMsg_RequestComplete( | 245 if (url_loader_client) { |
| 244 request_id, request_complete_data)); | 246 url_loader_client->OnComplete(request_complete_data); |
| 247 } else { |
| 248 filter->Send( |
| 249 new ResourceMsg_RequestComplete(request_id, request_complete_data)); |
| 250 } |
| 245 } | 251 } |
| 246 } | 252 } |
| 247 | 253 |
| 248 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { | 254 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { |
| 249 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 255 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 250 if (!referrer.url.is_valid() || | 256 if (!referrer.url.is_valid() || |
| 251 command_line->HasSwitch(switches::kNoReferrers)) { | 257 command_line->HasSwitch(switches::kNoReferrers)) { |
| 252 request->SetReferrer(std::string()); | 258 request->SetReferrer(std::string()); |
| 253 } else { | 259 } else { |
| 254 request->SetReferrer(referrer.url.spec()); | 260 request->SetReferrer(referrer.url.spec()); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 // navigation becomes the default. crbug.com/561610 | 557 // navigation becomes the default. crbug.com/561610 |
| 552 if (!IsBrowserSideNavigationEnabled() && | 558 if (!IsBrowserSideNavigationEnabled() && |
| 553 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { | 559 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { |
| 554 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 560 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
| 555 } | 561 } |
| 556 } | 562 } |
| 557 | 563 |
| 558 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 564 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
| 559 DCHECK(outstanding_requests_stats_map_.empty()); | 565 DCHECK(outstanding_requests_stats_map_.empty()); |
| 560 DCHECK(g_resource_dispatcher_host); | 566 DCHECK(g_resource_dispatcher_host); |
| 567 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 561 g_resource_dispatcher_host = NULL; | 568 g_resource_dispatcher_host = NULL; |
| 562 } | 569 } |
| 563 | 570 |
| 564 // static | 571 // static |
| 565 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 572 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
| 566 return g_resource_dispatcher_host; | 573 return g_resource_dispatcher_host; |
| 567 } | 574 } |
| 568 | 575 |
| 569 // static | 576 // static |
| 570 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( | 577 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 for (const auto& routing_id : ids) { | 1117 for (const auto& routing_id : ids) { |
| 1111 CancelBlockedRequestsForRoute(routing_id); | 1118 CancelBlockedRequestsForRoute(routing_id); |
| 1112 } | 1119 } |
| 1113 | 1120 |
| 1114 scheduler_.reset(); | 1121 scheduler_.reset(); |
| 1115 } | 1122 } |
| 1116 | 1123 |
| 1117 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1124 bool ResourceDispatcherHostImpl::OnMessageReceived( |
| 1118 const IPC::Message& message, | 1125 const IPC::Message& message, |
| 1119 ResourceMessageFilter* filter) { | 1126 ResourceMessageFilter* filter) { |
| 1127 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1120 filter_ = filter; | 1128 filter_ = filter; |
| 1121 bool handled = true; | 1129 bool handled = true; |
| 1122 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) | 1130 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
| 1123 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 1131 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
| 1124 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) | 1132 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) |
| 1125 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 1133 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
| 1126 OnReleaseDownloadedFile) | 1134 OnReleaseDownloadedFile) |
| 1127 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) | 1135 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) |
| 1128 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 1136 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
| 1129 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) | 1137 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1151 } | 1159 } |
| 1152 | 1160 |
| 1153 filter_ = NULL; | 1161 filter_ = NULL; |
| 1154 return handled; | 1162 return handled; |
| 1155 } | 1163 } |
| 1156 | 1164 |
| 1157 void ResourceDispatcherHostImpl::OnRequestResource( | 1165 void ResourceDispatcherHostImpl::OnRequestResource( |
| 1158 int routing_id, | 1166 int routing_id, |
| 1159 int request_id, | 1167 int request_id, |
| 1160 const ResourceRequest& request_data) { | 1168 const ResourceRequest& request_data) { |
| 1169 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, |
| 1170 nullptr); |
| 1171 } |
| 1172 |
| 1173 void ResourceDispatcherHostImpl::OnRequestResourceInternal( |
| 1174 int routing_id, |
| 1175 int request_id, |
| 1176 const ResourceRequest& request_data, |
| 1177 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 1178 mojom::URLLoaderClientPtr url_loader_client) { |
| 1161 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1179 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 1162 tracked_objects::ScopedTracker tracking_profile( | 1180 tracked_objects::ScopedTracker tracking_profile( |
| 1163 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1181 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1164 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1182 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
| 1165 // When logging time-to-network only care about main frame and non-transfer | 1183 // When logging time-to-network only care about main frame and non-transfer |
| 1166 // navigations. | 1184 // navigations. |
| 1167 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1185 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
| 1168 // instead. | 1186 // instead. |
| 1169 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1187 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
| 1170 request_data.transferred_request_request_id == -1 && | 1188 request_data.transferred_request_request_id == -1 && |
| 1171 !IsBrowserSideNavigationEnabled()) { | 1189 !IsBrowserSideNavigationEnabled()) { |
| 1172 BrowserThread::PostTask( | 1190 BrowserThread::PostTask( |
| 1173 BrowserThread::UI, | 1191 BrowserThread::UI, |
| 1174 FROM_HERE, | 1192 FROM_HERE, |
| 1175 base::Bind(&LogResourceRequestTimeOnUI, | 1193 base::Bind(&LogResourceRequestTimeOnUI, |
| 1176 TimeTicks::Now(), | 1194 TimeTicks::Now(), |
| 1177 filter_->child_id(), | 1195 filter_->child_id(), |
| 1178 request_data.render_frame_id, | 1196 request_data.render_frame_id, |
| 1179 request_data.url)); | 1197 request_data.url)); |
| 1180 } | 1198 } |
| 1181 BeginRequest(request_id, request_data, NULL, routing_id); | 1199 BeginRequest(request_id, request_data, NULL, routing_id, |
| 1200 std::move(mojo_request), std::move(url_loader_client)); |
| 1182 } | 1201 } |
| 1183 | 1202 |
| 1184 // Begins a resource request with the given params on behalf of the specified | 1203 // Begins a resource request with the given params on behalf of the specified |
| 1185 // child process. Responses will be dispatched through the given receiver. The | 1204 // child process. Responses will be dispatched through the given receiver. The |
| 1186 // process ID is used to lookup WebContentsImpl from routing_id's in the case of | 1205 // process ID is used to lookup WebContentsImpl from routing_id's in the case of |
| 1187 // a request from a renderer. request_context is the cookie/cache context to be | 1206 // a request from a renderer. request_context is the cookie/cache context to be |
| 1188 // used for this request. | 1207 // used for this request. |
| 1189 // | 1208 // |
| 1190 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1209 // If sync_result is non-null, then a SyncLoad reply will be generated, else |
| 1191 // a normal asynchronous set of response messages will be generated. | 1210 // a normal asynchronous set of response messages will be generated. |
| 1192 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, | 1211 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, |
| 1193 const ResourceRequest& request_data, | 1212 const ResourceRequest& request_data, |
| 1194 IPC::Message* sync_result) { | 1213 IPC::Message* sync_result) { |
| 1195 BeginRequest(request_id, request_data, sync_result, | 1214 BeginRequest(request_id, request_data, sync_result, sync_result->routing_id(), |
| 1196 sync_result->routing_id()); | 1215 nullptr, nullptr); |
| 1197 } | 1216 } |
| 1198 | 1217 |
| 1199 bool ResourceDispatcherHostImpl::IsRequestIDInUse( | 1218 bool ResourceDispatcherHostImpl::IsRequestIDInUse( |
| 1200 const GlobalRequestID& id) const { | 1219 const GlobalRequestID& id) const { |
| 1201 if (pending_loaders_.find(id) != pending_loaders_.end()) | 1220 if (pending_loaders_.find(id) != pending_loaders_.end()) |
| 1202 return true; | 1221 return true; |
| 1203 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1222 for (const auto& blocked_loaders : blocked_loaders_map_) { |
| 1204 for (const auto& loader : *blocked_loaders.second.get()) { | 1223 for (const auto& loader : *blocked_loaders.second.get()) { |
| 1205 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1224 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 1206 if (info->GetGlobalRequestID() == id) | 1225 if (info->GetGlobalRequestID() == id) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 } | 1320 } |
| 1302 | 1321 |
| 1303 // We should have a CrossSiteResourceHandler to finish the transfer. | 1322 // We should have a CrossSiteResourceHandler to finish the transfer. |
| 1304 DCHECK(info->cross_site_handler()); | 1323 DCHECK(info->cross_site_handler()); |
| 1305 } | 1324 } |
| 1306 | 1325 |
| 1307 void ResourceDispatcherHostImpl::BeginRequest( | 1326 void ResourceDispatcherHostImpl::BeginRequest( |
| 1308 int request_id, | 1327 int request_id, |
| 1309 const ResourceRequest& request_data, | 1328 const ResourceRequest& request_data, |
| 1310 IPC::Message* sync_result, // only valid for sync | 1329 IPC::Message* sync_result, // only valid for sync |
| 1311 int route_id) { | 1330 int route_id, |
| 1331 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 1332 mojom::URLLoaderClientPtr url_loader_client) { |
| 1312 int process_type = filter_->process_type(); | 1333 int process_type = filter_->process_type(); |
| 1313 int child_id = filter_->child_id(); | 1334 int child_id = filter_->child_id(); |
| 1314 | 1335 |
| 1315 // Reject request id that's currently in use. | 1336 // Reject request id that's currently in use. |
| 1316 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1337 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
| 1317 bad_message::ReceivedBadMessage(filter_, | 1338 bad_message::ReceivedBadMessage(filter_, |
| 1318 bad_message::RDH_INVALID_REQUEST_ID); | 1339 bad_message::RDH_INVALID_REQUEST_ID); |
| 1319 return; | 1340 return; |
| 1320 } | 1341 } |
| 1321 | 1342 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1341 char url_buf[128]; | 1362 char url_buf[128]; |
| 1342 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1363 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
| 1343 base::debug::Alias(url_buf); | 1364 base::debug::Alias(url_buf); |
| 1344 | 1365 |
| 1345 // If the request that's coming in is being transferred from another process, | 1366 // If the request that's coming in is being transferred from another process, |
| 1346 // we want to reuse and resume the old loader rather than start a new one. | 1367 // we want to reuse and resume the old loader rather than start a new one. |
| 1347 LoaderMap::iterator it = pending_loaders_.find( | 1368 LoaderMap::iterator it = pending_loaders_.find( |
| 1348 GlobalRequestID(request_data.transferred_request_child_id, | 1369 GlobalRequestID(request_data.transferred_request_child_id, |
| 1349 request_data.transferred_request_request_id)); | 1370 request_data.transferred_request_request_id)); |
| 1350 if (it != pending_loaders_.end()) { | 1371 if (it != pending_loaders_.end()) { |
| 1372 // TODO(yhirano): Make mojo work for this case. |
| 1373 DCHECK(!url_loader_client); |
| 1374 |
| 1351 // If the request is transferring to a new process, we can update our | 1375 // If the request is transferring to a new process, we can update our |
| 1352 // state and let it resume with its existing ResourceHandlers. | 1376 // state and let it resume with its existing ResourceHandlers. |
| 1353 if (it->second->is_transferring()) { | 1377 if (it->second->is_transferring()) { |
| 1354 ResourceLoader* deferred_loader = it->second.get(); | 1378 ResourceLoader* deferred_loader = it->second.get(); |
| 1355 UpdateRequestForTransfer(child_id, route_id, request_id, | 1379 UpdateRequestForTransfer(child_id, route_id, request_id, |
| 1356 request_data, it); | 1380 request_data, it); |
| 1357 deferred_loader->CompleteTransfer(); | 1381 deferred_loader->CompleteTransfer(); |
| 1358 } else { | 1382 } else { |
| 1359 bad_message::ReceivedBadMessage( | 1383 bad_message::ReceivedBadMessage( |
| 1360 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1384 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
| 1361 } | 1385 } |
| 1362 return; | 1386 return; |
| 1363 } | 1387 } |
| 1364 | 1388 |
| 1365 ResourceContext* resource_context = NULL; | 1389 ResourceContext* resource_context = NULL; |
| 1366 net::URLRequestContext* request_context = NULL; | 1390 net::URLRequestContext* request_context = NULL; |
| 1367 filter_->GetContexts(request_data.resource_type, &resource_context, | 1391 filter_->GetContexts(request_data.resource_type, &resource_context, |
| 1368 &request_context); | 1392 &request_context); |
| 1369 | 1393 |
| 1370 // Parse the headers before calling ShouldServiceRequest, so that they are | 1394 // Parse the headers before calling ShouldServiceRequest, so that they are |
| 1371 // available to be validated. | 1395 // available to be validated. |
| 1372 net::HttpRequestHeaders headers; | 1396 net::HttpRequestHeaders headers; |
| 1373 headers.AddHeadersFromString(request_data.headers); | 1397 headers.AddHeadersFromString(request_data.headers); |
| 1374 | 1398 |
| 1375 if (is_shutdown_ || | 1399 if (is_shutdown_ || |
| 1376 !ShouldServiceRequest(process_type, child_id, request_data, headers, | 1400 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
| 1377 filter_, resource_context)) { | 1401 filter_, resource_context)) { |
| 1378 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1402 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
| 1403 std::move(url_loader_client)); |
| 1379 return; | 1404 return; |
| 1380 } | 1405 } |
| 1381 | 1406 |
| 1382 // Allow the observer to block/handle the request. | 1407 // Allow the observer to block/handle the request. |
| 1383 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1408 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
| 1384 request_data.url, | 1409 request_data.url, |
| 1385 request_data.resource_type, | 1410 request_data.resource_type, |
| 1386 resource_context)) { | 1411 resource_context)) { |
| 1387 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1412 AbortRequestBeforeItStarts(filter_, sync_result, request_id, |
| 1413 std::move(url_loader_client)); |
| 1388 return; | 1414 return; |
| 1389 } | 1415 } |
| 1390 | 1416 |
| 1391 // Construct the request. | 1417 // Construct the request. |
| 1392 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( | 1418 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( |
| 1393 is_navigation_stream_request ? request_data.resource_body_stream_url | 1419 is_navigation_stream_request ? request_data.resource_body_stream_url |
| 1394 : request_data.url, | 1420 : request_data.url, |
| 1395 request_data.priority, nullptr); | 1421 request_data.priority, nullptr); |
| 1396 | 1422 |
| 1397 // PlzNavigate: Always set the method to GET when gaining access to the | 1423 // PlzNavigate: Always set the method to GET when gaining access to the |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 } | 1583 } |
| 1558 | 1584 |
| 1559 // Have the appcache associate its extra info with the request. | 1585 // Have the appcache associate its extra info with the request. |
| 1560 AppCacheInterceptor::SetExtraRequestInfo( | 1586 AppCacheInterceptor::SetExtraRequestInfo( |
| 1561 new_request.get(), filter_->appcache_service(), child_id, | 1587 new_request.get(), filter_->appcache_service(), child_id, |
| 1562 request_data.appcache_host_id, request_data.resource_type, | 1588 request_data.appcache_host_id, request_data.resource_type, |
| 1563 request_data.should_reset_appcache); | 1589 request_data.should_reset_appcache); |
| 1564 | 1590 |
| 1565 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1591 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
| 1566 new_request.get(), request_data, sync_result, route_id, process_type, | 1592 new_request.get(), request_data, sync_result, route_id, process_type, |
| 1567 child_id, resource_context)); | 1593 child_id, resource_context, std::move(mojo_request), |
| 1594 std::move(url_loader_client))); |
| 1568 | 1595 |
| 1569 if (handler) | 1596 if (handler) |
| 1570 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1597 BeginRequestInternal(std::move(new_request), std::move(handler)); |
| 1571 } | 1598 } |
| 1572 | 1599 |
| 1573 std::unique_ptr<ResourceHandler> | 1600 std::unique_ptr<ResourceHandler> |
| 1574 ResourceDispatcherHostImpl::CreateResourceHandler( | 1601 ResourceDispatcherHostImpl::CreateResourceHandler( |
| 1575 net::URLRequest* request, | 1602 net::URLRequest* request, |
| 1576 const ResourceRequest& request_data, | 1603 const ResourceRequest& request_data, |
| 1577 IPC::Message* sync_result, | 1604 IPC::Message* sync_result, |
| 1578 int route_id, | 1605 int route_id, |
| 1579 int process_type, | 1606 int process_type, |
| 1580 int child_id, | 1607 int child_id, |
| 1581 ResourceContext* resource_context) { | 1608 ResourceContext* resource_context, |
| 1609 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 1610 mojom::URLLoaderClientPtr url_loader_client) { |
| 1582 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1611 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1583 tracked_objects::ScopedTracker tracking_profile( | 1612 tracked_objects::ScopedTracker tracking_profile( |
| 1584 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1613 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1585 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1614 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
| 1586 // Construct the IPC resource handler. | 1615 // Construct the IPC resource handler. |
| 1587 std::unique_ptr<ResourceHandler> handler; | 1616 std::unique_ptr<ResourceHandler> handler; |
| 1588 if (sync_result) { | 1617 if (sync_result) { |
| 1589 // download_to_file is not supported for synchronous requests. | 1618 // download_to_file is not supported for synchronous requests. |
| 1590 if (request_data.download_to_file) { | 1619 if (request_data.download_to_file) { |
| 1591 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1620 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
| 1592 return std::unique_ptr<ResourceHandler>(); | 1621 return std::unique_ptr<ResourceHandler>(); |
| 1593 } | 1622 } |
| 1594 | 1623 |
| 1624 DCHECK(!mojo_request.is_pending()); |
| 1625 DCHECK(!url_loader_client); |
| 1595 handler.reset(new SyncResourceHandler(request, sync_result, this)); | 1626 handler.reset(new SyncResourceHandler(request, sync_result, this)); |
| 1596 } else { | 1627 } else { |
| 1597 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 } |
| 1598 | 1635 |
| 1599 // The RedirectToFileResourceHandler depends on being next in the chain. | 1636 // The RedirectToFileResourceHandler depends on being next in the chain. |
| 1600 if (request_data.download_to_file) { | 1637 if (request_data.download_to_file) { |
| 1601 handler.reset( | 1638 handler.reset( |
| 1602 new RedirectToFileResourceHandler(std::move(handler), request)); | 1639 new RedirectToFileResourceHandler(std::move(handler), request)); |
| 1603 } | 1640 } |
| 1604 } | 1641 } |
| 1605 | 1642 |
| 1606 // Prefetches and <a ping> requests outlive their child process. | 1643 // Prefetches and <a ping> requests outlive their child process. |
| 1607 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { | 1644 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | 2306 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
| 2270 if (!async_revalidation_manager_) | 2307 if (!async_revalidation_manager_) |
| 2271 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 2308 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
| 2272 } | 2309 } |
| 2273 | 2310 |
| 2274 void ResourceDispatcherHostImpl::SetLoaderDelegate( | 2311 void ResourceDispatcherHostImpl::SetLoaderDelegate( |
| 2275 LoaderDelegate* loader_delegate) { | 2312 LoaderDelegate* loader_delegate) { |
| 2276 loader_delegate_ = loader_delegate; | 2313 loader_delegate_ = loader_delegate; |
| 2277 } | 2314 } |
| 2278 | 2315 |
| 2316 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( |
| 2317 int routing_id, |
| 2318 int request_id, |
| 2319 const ResourceRequest& request, |
| 2320 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 2321 mojom::URLLoaderClientPtr url_loader_client, |
| 2322 ResourceMessageFilter* filter) { |
| 2323 filter_ = filter; |
| 2324 OnRequestResourceInternal(routing_id, request_id, request, |
| 2325 std::move(mojo_request), |
| 2326 std::move(url_loader_client)); |
| 2327 filter_ = nullptr; |
| 2328 } |
| 2329 |
| 2279 // static | 2330 // static |
| 2280 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2331 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
| 2281 net::URLRequest* request) { | 2332 net::URLRequest* request) { |
| 2282 // The following fields should be a minor size contribution (experimentally | 2333 // The following fields should be a minor size contribution (experimentally |
| 2283 // on the order of 100). However since they are variable length, it could | 2334 // on the order of 100). However since they are variable length, it could |
| 2284 // in theory be a sizeable contribution. | 2335 // in theory be a sizeable contribution. |
| 2285 int strings_cost = request->extra_request_headers().ToString().size() + | 2336 int strings_cost = request->extra_request_headers().ToString().size() + |
| 2286 request->original_url().spec().size() + | 2337 request->original_url().spec().size() + |
| 2287 request->referrer().size() + | 2338 request->referrer().size() + |
| 2288 request->method().size(); | 2339 request->method().size(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2647 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
| 2597 response->head.security_info = SerializeSecurityInfo(ssl); | 2648 response->head.security_info = SerializeSecurityInfo(ssl); |
| 2598 } | 2649 } |
| 2599 | 2650 |
| 2600 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2651 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
| 2601 return cert_store_for_testing_ ? cert_store_for_testing_ | 2652 return cert_store_for_testing_ ? cert_store_for_testing_ |
| 2602 : CertStore::GetInstance(); | 2653 : CertStore::GetInstance(); |
| 2603 } | 2654 } |
| 2604 | 2655 |
| 2605 } // namespace content | 2656 } // namespace content |
| OLD | NEW |