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

Side by Side Diff: content/child/web_url_request_util.cc

Issue 2012913002: Deduping conversions between ResourceRequestBody/WebHTTPBody/ExplodedHttpBody. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@get-rid-of-exploded-http-body
Patch Set: Calling ResourceRequestBody::AppendFileRange with optional_body_file_path. Created 4 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/child/web_url_request_util.h ('k') | content/common/page_state_serialization.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/child/web_url_request_util.h" 5 #include "content/child/web_url_request_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "third_party/WebKit/public/platform/FilePathConversion.h" 16 #include "third_party/WebKit/public/platform/FilePathConversion.h"
17 #include "third_party/WebKit/public/platform/WebCachePolicy.h" 17 #include "third_party/WebKit/public/platform/WebCachePolicy.h"
18 #include "third_party/WebKit/public/platform/WebData.h"
18 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" 19 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
19 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebURL.h" 21 #include "third_party/WebKit/public/platform/WebURL.h"
21 #include "third_party/WebKit/public/platform/WebURLError.h" 22 #include "third_party/WebKit/public/platform/WebURLError.h"
22 #include "third_party/WebKit/public/platform/WebURLRequest.h" 23 #include "third_party/WebKit/public/platform/WebURLRequest.h"
23 24
24 using blink::WebCachePolicy; 25 using blink::WebCachePolicy;
26 using blink::WebData;
25 using blink::WebHTTPBody; 27 using blink::WebHTTPBody;
26 using blink::WebString; 28 using blink::WebString;
27 using blink::WebURLRequest; 29 using blink::WebURLRequest;
28 30
29 namespace content { 31 namespace content {
30 32
31 namespace { 33 namespace {
32 34
33 const char kThrottledErrorDescription[] = 35 const char kThrottledErrorDescription[] =
34 "Request throttled. Visit http://dev.chromium.org/throttling for more " 36 "Request throttled. Visit http://dev.chromium.org/throttling for more "
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES; 212 load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES;
211 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES; 213 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES;
212 } 214 }
213 215
214 if (!request.allowStoredCredentials()) 216 if (!request.allowStoredCredentials())
215 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; 217 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA;
216 218
217 return load_flags; 219 return load_flags;
218 } 220 }
219 221
222 WebHTTPBody GetWebHTTPBodyForRequestBody(
223 const scoped_refptr<ResourceRequestBody>& input) {
224 WebHTTPBody http_body;
225 http_body.initialize();
226 http_body.setIdentifier(input->identifier());
227 for (const auto& element : *input->elements()) {
228 switch (element.type()) {
229 case ResourceRequestBody::Element::TYPE_BYTES:
230 http_body.appendData(WebData(element.bytes(), element.length()));
231 break;
232 case ResourceRequestBody::Element::TYPE_FILE:
233 http_body.appendFileRange(
234 element.path().AsUTF16Unsafe(), element.offset(),
235 (element.length() != std::numeric_limits<uint64_t>::max())
236 ? element.length()
237 : -1,
238 element.expected_modification_time().ToDoubleT());
239 break;
240 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM:
241 http_body.appendFileSystemURLRange(
242 element.filesystem_url(), element.offset(),
243 (element.length() != std::numeric_limits<uint64_t>::max())
244 ? element.length()
245 : -1,
246 element.expected_modification_time().ToDoubleT());
247 break;
248 case ResourceRequestBody::Element::TYPE_BLOB:
249 http_body.appendBlob(WebString::fromUTF8(element.blob_uuid()));
250 break;
251 case ResourceRequestBody::Element::TYPE_BYTES_DESCRIPTION:
252 case ResourceRequestBody::Element::TYPE_DISK_CACHE_ENTRY:
253 default:
254 NOTREACHED();
255 break;
256 }
257 }
258 return http_body;
259 }
260
220 scoped_refptr<ResourceRequestBody> GetRequestBodyForWebURLRequest( 261 scoped_refptr<ResourceRequestBody> GetRequestBodyForWebURLRequest(
221 const blink::WebURLRequest& request) { 262 const blink::WebURLRequest& request) {
222 scoped_refptr<ResourceRequestBody> request_body; 263 scoped_refptr<ResourceRequestBody> request_body;
223 264
224 if (request.httpBody().isNull()) { 265 if (request.httpBody().isNull()) {
225 return request_body; 266 return request_body;
226 } 267 }
227 268
228 const std::string& method = request.httpMethod().latin1(); 269 const std::string& method = request.httpMethod().latin1();
229 // GET and HEAD requests shouldn't have http bodies. 270 // GET and HEAD requests shouldn't have http bodies.
230 DCHECK(method != "GET" && method != "HEAD"); 271 DCHECK(method != "GET" && method != "HEAD");
231 272
232 const WebHTTPBody& httpBody = request.httpBody(); 273 return GetRequestBodyForWebHTTPBody(request.httpBody());
233 request_body = new ResourceRequestBody(); 274 }
275
276 scoped_refptr<ResourceRequestBody> GetRequestBodyForWebHTTPBody(
277 const blink::WebHTTPBody& httpBody) {
278 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody();
234 size_t i = 0; 279 size_t i = 0;
235 WebHTTPBody::Element element; 280 WebHTTPBody::Element element;
236 while (httpBody.elementAt(i++, element)) { 281 while (httpBody.elementAt(i++, element)) {
237 switch (element.type) { 282 switch (element.type) {
238 case WebHTTPBody::Element::TypeData: 283 case WebHTTPBody::Element::TypeData:
239 if (!element.data.isEmpty()) { 284 if (!element.data.isEmpty()) {
240 // Blink sometimes gives empty data to append. These aren't 285 // Blink sometimes gives empty data to append. These aren't
241 // necessary so they are just optimized out here. 286 // necessary so they are just optimized out here.
242 request_body->AppendBytes( 287 request_body->AppendBytes(
243 element.data.data(), static_cast<int>(element.data.size())); 288 element.data.data(), static_cast<int>(element.data.size()));
(...skipping 21 matching lines...) Expand all
265 base::Time::FromDoubleT(element.modificationTime)); 310 base::Time::FromDoubleT(element.modificationTime));
266 break; 311 break;
267 } 312 }
268 case WebHTTPBody::Element::TypeBlob: 313 case WebHTTPBody::Element::TypeBlob:
269 request_body->AppendBlob(element.blobUUID.utf8()); 314 request_body->AppendBlob(element.blobUUID.utf8());
270 break; 315 break;
271 default: 316 default:
272 NOTREACHED(); 317 NOTREACHED();
273 } 318 }
274 } 319 }
275 request_body->set_identifier(request.httpBody().identifier()); 320 request_body->set_identifier(httpBody.identifier());
276 return request_body; 321 return request_body;
277 } 322 }
278 323
279 #define STATIC_ASSERT_ENUM(a, b) \ 324 #define STATIC_ASSERT_ENUM(a, b) \
280 static_assert(static_cast<int>(a) == static_cast<int>(b), \ 325 static_assert(static_cast<int>(a) == static_cast<int>(b), \
281 "mismatching enums: " #a) 326 "mismatching enums: " #a)
282 327
283 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_SAME_ORIGIN, 328 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_SAME_ORIGIN,
284 WebURLRequest::FetchRequestModeSameOrigin); 329 WebURLRequest::FetchRequestModeSameOrigin);
285 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_NO_CORS, 330 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_NO_CORS,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 bool stale_copy_in_cache, 479 bool stale_copy_in_cache,
435 int reason, 480 int reason,
436 bool was_ignored_by_handler) { 481 bool was_ignored_by_handler) {
437 blink::WebURLError error = 482 blink::WebURLError error =
438 CreateWebURLError(unreachable_url, stale_copy_in_cache, reason); 483 CreateWebURLError(unreachable_url, stale_copy_in_cache, reason);
439 error.wasIgnoredByHandler = was_ignored_by_handler; 484 error.wasIgnoredByHandler = was_ignored_by_handler;
440 return error; 485 return error;
441 } 486 }
442 487
443 } // namespace content 488 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_url_request_util.h ('k') | content/common/page_state_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698