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

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

Issue 2829923004: Fail when uploading blob is non-existant (Closed)
Patch Set: reworked to be exactly the same, logically Created 3 years, 6 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
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1150
1151 if (is_shutdown_ || 1151 if (is_shutdown_ ||
1152 !ShouldServiceRequest(child_id, request_data, headers, requester_info, 1152 !ShouldServiceRequest(child_id, request_data, headers, requester_info,
1153 resource_context)) { 1153 resource_context)) {
1154 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, 1154 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler,
1155 request_id, std::move(url_loader_client)); 1155 request_id, std::move(url_loader_client));
1156 return; 1156 return;
1157 } 1157 }
1158 1158
1159 if (!is_navigation_stream_request) { 1159 if (!is_navigation_stream_request) {
1160 storage::BlobStorageContext* blob_context =
1161 GetBlobStorageContext(requester_info->blob_storage_context());
1162 // Resolve elements from request_body and prepare upload data.
1163 if (request_data.request_body.get()) {
1164 // |blob_context| could be null when the request is from the plugins
1165 // because ResourceMessageFilters created in PluginProcessHost don't have
1166 // the blob context.
1167 if (blob_context) {
1168 // Attaches the BlobDataHandles to request_body not to free the blobs
1169 // and any attached shareable files until upload completion. These data
1170 // will be used in UploadDataStream and ServiceWorkerURLRequestJob.
1171 bool blobs_alive = AttachRequestBodyBlobDataHandles(
1172 request_data.request_body.get(), resource_context);
1173 if (!blobs_alive) {
1174 AbortRequestBeforeItStarts(requester_info->filter(),
1175 sync_result_handler, request_id,
1176 std::move(url_loader_client));
1177 return;
1178 }
1179 }
1180 }
1181
1160 // Check if we have a registered interceptor for the headers passed in. If 1182 // Check if we have a registered interceptor for the headers passed in. If
1161 // yes then we need to mark the current request as pending and wait for the 1183 // yes then we need to mark the current request as pending and wait for the
1162 // interceptor to invoke the callback with a status code indicating whether 1184 // interceptor to invoke the callback with a status code indicating whether
1163 // the request needs to be aborted or continued. 1185 // the request needs to be aborted or continued.
1164 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { 1186 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) {
1165 HeaderInterceptorMap::iterator index = 1187 HeaderInterceptorMap::iterator index =
1166 http_header_interceptor_map_.find(it.name()); 1188 http_header_interceptor_map_.find(it.name());
1167 if (index != http_header_interceptor_map_.end()) { 1189 if (index != http_header_interceptor_map_.end()) {
1168 HeaderInterceptorInfo& interceptor_info = index->second; 1190 HeaderInterceptorInfo& interceptor_info = index->second;
1169 1191
1170 bool call_interceptor = true; 1192 bool call_interceptor = true;
1171 if (!interceptor_info.starts_with.empty()) { 1193 if (!interceptor_info.starts_with.empty()) {
1172 call_interceptor = 1194 call_interceptor =
1173 base::StartsWith(it.value(), interceptor_info.starts_with, 1195 base::StartsWith(it.value(), interceptor_info.starts_with,
1174 base::CompareCase::INSENSITIVE_ASCII); 1196 base::CompareCase::INSENSITIVE_ASCII);
1175 } 1197 }
1176 if (call_interceptor) { 1198 if (call_interceptor) {
1177 interceptor_info.interceptor.Run( 1199 interceptor_info.interceptor.Run(
1178 it.name(), it.value(), child_id, resource_context, 1200 it.name(), it.value(), child_id, resource_context,
1179 base::Bind( 1201 base::Bind(
1180 &ResourceDispatcherHostImpl::ContinuePendingBeginRequest, 1202 &ResourceDispatcherHostImpl::ContinuePendingBeginRequest,
1181 base::Unretained(this), requester_info, request_id, 1203 base::Unretained(this), requester_info, request_id,
1182 request_data, sync_result_handler, route_id, headers, 1204 request_data, sync_result_handler, route_id, headers,
1183 base::Passed(std::move(mojo_request)), 1205 base::Passed(std::move(mojo_request)),
1184 base::Passed(std::move(url_loader_client)))); 1206 base::Passed(std::move(url_loader_client)), blob_context));
1185 return; 1207 return;
1186 } 1208 }
1187 } 1209 }
1188 } 1210 }
1189 } 1211 }
1190 ContinuePendingBeginRequest( 1212 ContinuePendingBeginRequest(
1191 requester_info, request_id, request_data, sync_result_handler, route_id, 1213 requester_info, request_id, request_data, sync_result_handler, route_id,
1192 headers, std::move(mojo_request), std::move(url_loader_client), 1214 headers, std::move(mojo_request), std::move(url_loader_client), nullptr,
michaeln 2017/06/02 21:36:37 it's crashing because of this nullptr
1193 HeaderInterceptorResult::CONTINUE); 1215 HeaderInterceptorResult::CONTINUE);
1194 } 1216 }
1195 1217
1196 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( 1218 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
1197 scoped_refptr<ResourceRequesterInfo> requester_info, 1219 scoped_refptr<ResourceRequesterInfo> requester_info,
1198 int request_id, 1220 int request_id,
1199 const ResourceRequest& request_data, 1221 const ResourceRequest& request_data,
1200 const SyncLoadResultCallback& sync_result_handler, // only valid for sync 1222 const SyncLoadResultCallback& sync_result_handler, // only valid for sync
1201 int route_id, 1223 int route_id,
1202 const net::HttpRequestHeaders& headers, 1224 const net::HttpRequestHeaders& headers,
1203 mojom::URLLoaderRequest mojo_request, 1225 mojom::URLLoaderRequest mojo_request,
1204 mojom::URLLoaderClientPtr url_loader_client, 1226 mojom::URLLoaderClientPtr url_loader_client,
1227 storage::BlobStorageContext* blob_context,
1205 HeaderInterceptorResult interceptor_result) { 1228 HeaderInterceptorResult interceptor_result) {
1206 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload()); 1229 DCHECK(requester_info->IsRenderer() || requester_info->IsNavigationPreload());
1207 if (interceptor_result != HeaderInterceptorResult::CONTINUE) { 1230 if (interceptor_result != HeaderInterceptorResult::CONTINUE) {
1208 if (requester_info->IsRenderer() && 1231 if (requester_info->IsRenderer() &&
1209 interceptor_result == HeaderInterceptorResult::KILL) { 1232 interceptor_result == HeaderInterceptorResult::KILL) {
1210 // TODO(ananta): Find a way to specify the right error code here. Passing 1233 // TODO(ananta): Find a way to specify the right error code here. Passing
1211 // in a non-content error code is not safe, but future header interceptors 1234 // in a non-content error code is not safe, but future header interceptors
1212 // might say to kill for reasons other than illegal origins. 1235 // might say to kill for reasons other than illegal origins.
1213 bad_message::ReceivedBadMessage(requester_info->filter(), 1236 bad_message::ReceivedBadMessage(requester_info->filter(),
1214 bad_message::RDH_ILLEGAL_ORIGIN); 1237 bad_message::RDH_ILLEGAL_ORIGIN);
1215 } 1238 }
1216 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler, 1239 AbortRequestBeforeItStarts(requester_info->filter(), sync_result_handler,
1217 request_id, std::move(url_loader_client)); 1240 request_id, std::move(url_loader_client));
1218 return; 1241 return;
1219 } 1242 }
1220 int child_id = requester_info->child_id(); 1243 int child_id = requester_info->child_id();
1221 storage::BlobStorageContext* blob_context = nullptr;
1222 bool allow_download = false; 1244 bool allow_download = false;
1223 bool do_not_prompt_for_login = false; 1245 bool do_not_prompt_for_login = false;
1224 bool report_raw_headers = false; 1246 bool report_raw_headers = false;
1225 bool is_sync_load = !!sync_result_handler; 1247 bool is_sync_load = !!sync_result_handler;
1226 int load_flags = BuildLoadFlagsForRequest(request_data, is_sync_load); 1248 int load_flags = BuildLoadFlagsForRequest(request_data, is_sync_load);
1227 bool is_navigation_stream_request = 1249 bool is_navigation_stream_request =
1228 IsBrowserSideNavigationEnabled() && 1250 IsBrowserSideNavigationEnabled() &&
1229 IsResourceTypeFrame(request_data.resource_type); 1251 IsResourceTypeFrame(request_data.resource_type);
1230 1252
1231 ResourceContext* resource_context = NULL; 1253 ResourceContext* resource_context = NULL;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 // checked previously. So don't set the referrer for this stream request, or 1315 // checked previously. So don't set the referrer for this stream request, or
1294 // else it will fail for SSL redirects since net/ will think the blob:https 1316 // else it will fail for SSL redirects since net/ will think the blob:https
1295 // for the stream is not a secure scheme (specifically, in the call to 1317 // for the stream is not a secure scheme (specifically, in the call to
1296 // ComputeReferrerForRedirect). 1318 // ComputeReferrerForRedirect).
1297 const Referrer referrer( 1319 const Referrer referrer(
1298 request_data.referrer, request_data.referrer_policy); 1320 request_data.referrer, request_data.referrer_policy);
1299 Referrer::SetReferrerForRequest(new_request.get(), referrer); 1321 Referrer::SetReferrerForRequest(new_request.get(), referrer);
1300 1322
1301 new_request->SetExtraRequestHeaders(headers); 1323 new_request->SetExtraRequestHeaders(headers);
1302 1324
1303 blob_context =
1304 GetBlobStorageContext(requester_info->blob_storage_context());
michaeln 2017/06/02 21:36:37 you could retain the local variable and avoid the
dmurph 2017/06/02 23:00:33 Done.
1305 // Resolve elements from request_body and prepare upload data. 1325 // Resolve elements from request_body and prepare upload data.
1306 if (request_data.request_body.get()) { 1326 if (request_data.request_body.get()) {
1307 // |blob_context| could be null when the request is from the plugins
1308 // because ResourceMessageFilters created in PluginProcessHost don't have
1309 // the blob context.
1310 if (blob_context) {
1311 // Attaches the BlobDataHandles to request_body not to free the blobs
1312 // and any attached shareable files until upload completion. These data
1313 // will be used in UploadDataStream and ServiceWorkerURLRequestJob.
1314 AttachRequestBodyBlobDataHandles(request_data.request_body.get(),
1315 resource_context);
1316 }
1317 new_request->set_upload(UploadDataStreamBuilder::Build( 1327 new_request->set_upload(UploadDataStreamBuilder::Build(
1318 request_data.request_body.get(), blob_context, 1328 request_data.request_body.get(), blob_context,
1319 requester_info->file_system_context(), 1329 requester_info->file_system_context(),
1320 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); 1330 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()));
1321 } 1331 }
1322 1332
1323 allow_download = request_data.allow_download && 1333 allow_download = request_data.allow_download &&
1324 IsResourceTypeFrame(request_data.resource_type); 1334 IsResourceTypeFrame(request_data.resource_type);
1325 do_not_prompt_for_login = request_data.do_not_prompt_for_login; 1335 do_not_prompt_for_login = request_data.do_not_prompt_for_login;
1326 1336
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 new_request->SetExtraRequestHeaders(headers); 2074 new_request->SetExtraRequestHeaders(headers);
2065 2075
2066 new_request->SetLoadFlags(load_flags); 2076 new_request->SetLoadFlags(load_flags);
2067 2077
2068 storage::BlobStorageContext* blob_context = GetBlobStorageContext( 2078 storage::BlobStorageContext* blob_context = GetBlobStorageContext(
2069 GetChromeBlobStorageContextForResourceContext(resource_context)); 2079 GetChromeBlobStorageContextForResourceContext(resource_context));
2070 2080
2071 // Resolve elements from request_body and prepare upload data. 2081 // Resolve elements from request_body and prepare upload data.
2072 ResourceRequestBodyImpl* body = info.common_params.post_data.get(); 2082 ResourceRequestBodyImpl* body = info.common_params.post_data.get();
2073 if (body) { 2083 if (body) {
2074 AttachRequestBodyBlobDataHandles(body, resource_context); 2084 bool blobs_alive = AttachRequestBodyBlobDataHandles(body, resource_context);
2085 if (!blobs_alive) {
2086 new_request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
2087 loader->NotifyRequestFailed(false, net::ERR_ABORTED);
2088 return;
2089 }
2075 new_request->set_upload(UploadDataStreamBuilder::Build( 2090 new_request->set_upload(UploadDataStreamBuilder::Build(
2076 body, blob_context, upload_file_system_context, 2091 body, blob_context, upload_file_system_context,
2077 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); 2092 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()));
2078 } 2093 }
2079 2094
2080 // Make extra info and read footer (contains request ID). 2095 // Make extra info and read footer (contains request ID).
2081 // 2096 //
2082 // TODO(davidben): Associate the request with the FrameTreeNode and/or tab so 2097 // TODO(davidben): Associate the request with the FrameTreeNode and/or tab so
2083 // that IO thread -> UI thread hops will work. 2098 // that IO thread -> UI thread hops will work.
2084 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( 2099 ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl(
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
2686 &throttles); 2701 &throttles);
2687 if (!throttles.empty()) { 2702 if (!throttles.empty()) {
2688 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, 2703 handler.reset(new ThrottlingResourceHandler(std::move(handler), request,
2689 std::move(throttles))); 2704 std::move(throttles)));
2690 } 2705 }
2691 } 2706 }
2692 return handler; 2707 return handler;
2693 } 2708 }
2694 2709
2695 } // namespace content 2710 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698