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

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

Issue 1847383003: CREDENTIAL: Rework the integration with Fetch (2/2) Base URL: https://chromium.googlesource.com/chromium/src.git@pass-serialized
Patch Set: unittest Created 4 years, 8 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 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>
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES; 222 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES;
223 } 223 }
224 224
225 if (!request.allowStoredCredentials()) 225 if (!request.allowStoredCredentials())
226 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; 226 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA;
227 227
228 return load_flags; 228 return load_flags;
229 } 229 }
230 230
231 scoped_refptr<ResourceRequestBody> GetRequestBodyForWebURLRequest( 231 scoped_refptr<ResourceRequestBody> GetRequestBodyForWebURLRequest(
232 const blink::WebURLRequest& request) { 232 const blink::WebURLRequest& request,
233 scoped_refptr<ResourceRequestBody> request_body; 233 RequestBodyType type) {
234 scoped_refptr<ResourceRequestBody> body_to_return;
234 235
235 if (request.httpBody().isNull()) { 236 const WebHTTPBody& body =
236 return request_body; 237 type == HTTP_BODY ? request.httpBody() : request.attachedCredentialBody();
237 } 238
239 if (body.isNull())
240 return body_to_return;
238 241
239 const std::string& method = request.httpMethod().latin1(); 242 const std::string& method = request.httpMethod().latin1();
240 // GET and HEAD requests shouldn't have http bodies. 243 // GET and HEAD requests shouldn't have http bodies.
241 DCHECK(method != "GET" && method != "HEAD"); 244 DCHECK(method != "GET" && method != "HEAD");
242 245
243 const WebHTTPBody& httpBody = request.httpBody(); 246 body_to_return = new ResourceRequestBody();
244 request_body = new ResourceRequestBody();
245 size_t i = 0; 247 size_t i = 0;
246 WebHTTPBody::Element element; 248 WebHTTPBody::Element element;
247 while (httpBody.elementAt(i++, element)) { 249 while (body.elementAt(i++, element)) {
248 switch (element.type) { 250 switch (element.type) {
249 case WebHTTPBody::Element::TypeData: 251 case WebHTTPBody::Element::TypeData:
250 if (!element.data.isEmpty()) { 252 if (!element.data.isEmpty()) {
251 // Blink sometimes gives empty data to append. These aren't 253 // Blink sometimes gives empty data to append. These aren't
252 // necessary so they are just optimized out here. 254 // necessary so they are just optimized out here.
253 request_body->AppendBytes( 255 body_to_return->AppendBytes(element.data.data(),
254 element.data.data(), static_cast<int>(element.data.size())); 256 static_cast<int>(element.data.size()));
255 } 257 }
256 break; 258 break;
257 case WebHTTPBody::Element::TypeFile: 259 case WebHTTPBody::Element::TypeFile:
258 if (element.fileLength == -1) { 260 if (element.fileLength == -1) {
259 request_body->AppendFileRange( 261 body_to_return->AppendFileRange(
260 blink::WebStringToFilePath(element.filePath), 0, 262 blink::WebStringToFilePath(element.filePath), 0,
261 std::numeric_limits<uint64_t>::max(), base::Time()); 263 std::numeric_limits<uint64_t>::max(), base::Time());
262 } else { 264 } else {
263 request_body->AppendFileRange( 265 body_to_return->AppendFileRange(
264 blink::WebStringToFilePath(element.filePath), 266 blink::WebStringToFilePath(element.filePath),
265 static_cast<uint64_t>(element.fileStart), 267 static_cast<uint64_t>(element.fileStart),
266 static_cast<uint64_t>(element.fileLength), 268 static_cast<uint64_t>(element.fileLength),
267 base::Time::FromDoubleT(element.modificationTime)); 269 base::Time::FromDoubleT(element.modificationTime));
268 } 270 }
269 break; 271 break;
270 case WebHTTPBody::Element::TypeFileSystemURL: { 272 case WebHTTPBody::Element::TypeFileSystemURL: {
271 GURL file_system_url = element.fileSystemURL; 273 GURL file_system_url = element.fileSystemURL;
272 DCHECK(file_system_url.SchemeIsFileSystem()); 274 DCHECK(file_system_url.SchemeIsFileSystem());
273 request_body->AppendFileSystemFileRange( 275 body_to_return->AppendFileSystemFileRange(
274 file_system_url, static_cast<uint64_t>(element.fileStart), 276 file_system_url, static_cast<uint64_t>(element.fileStart),
275 static_cast<uint64_t>(element.fileLength), 277 static_cast<uint64_t>(element.fileLength),
276 base::Time::FromDoubleT(element.modificationTime)); 278 base::Time::FromDoubleT(element.modificationTime));
277 break; 279 break;
278 } 280 }
279 case WebHTTPBody::Element::TypeBlob: 281 case WebHTTPBody::Element::TypeBlob:
280 request_body->AppendBlob(element.blobUUID.utf8()); 282 body_to_return->AppendBlob(element.blobUUID.utf8());
281 break; 283 break;
282 default: 284 default:
283 NOTREACHED(); 285 NOTREACHED();
284 } 286 }
285 } 287 }
286 request_body->set_identifier(request.httpBody().identifier()); 288 body_to_return->set_identifier(body.identifier());
287 return request_body; 289 return body_to_return;
288 } 290 }
289 291
290 #define STATIC_ASSERT_ENUM(a, b) \ 292 #define STATIC_ASSERT_ENUM(a, b) \
291 static_assert(static_cast<int>(a) == static_cast<int>(b), \ 293 static_assert(static_cast<int>(a) == static_cast<int>(b), \
292 "mismatching enums: " #a) 294 "mismatching enums: " #a)
293 295
294 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_SAME_ORIGIN, 296 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_SAME_ORIGIN,
295 WebURLRequest::FetchRequestModeSameOrigin); 297 WebURLRequest::FetchRequestModeSameOrigin);
296 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_NO_CORS, 298 STATIC_ASSERT_ENUM(FETCH_REQUEST_MODE_NO_CORS,
297 WebURLRequest::FetchRequestModeNoCORS); 299 WebURLRequest::FetchRequestModeNoCORS);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 bool stale_copy_in_cache, 447 bool stale_copy_in_cache,
446 int reason, 448 int reason,
447 bool was_ignored_by_handler) { 449 bool was_ignored_by_handler) {
448 blink::WebURLError error = 450 blink::WebURLError error =
449 CreateWebURLError(unreachable_url, stale_copy_in_cache, reason); 451 CreateWebURLError(unreachable_url, stale_copy_in_cache, reason);
450 error.wasIgnoredByHandler = was_ignored_by_handler; 452 error.wasIgnoredByHandler = was_ignored_by_handler;
451 return error; 453 return error;
452 } 454 }
453 455
454 } // namespace content 456 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698