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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/Request.cpp

Issue 1418813004: [Fetch API] Reflect spec changes of bodyUsed property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 "config.h" 5 #include "config.h"
6 #include "modules/fetch/Request.h" 6 #include "modules/fetch/Request.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
11 #include "core/fetch/FetchUtils.h" 11 #include "core/fetch/FetchUtils.h"
12 #include "core/fetch/ResourceLoaderOptions.h" 12 #include "core/fetch/ResourceLoaderOptions.h"
13 #include "core/loader/ThreadableLoader.h" 13 #include "core/loader/ThreadableLoader.h"
14 #include "modules/fetch/BodyStreamBuffer.h" 14 #include "modules/fetch/BodyStreamBuffer.h"
15 #include "modules/fetch/DataConsumerHandleUtil.h"
15 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 16 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
16 #include "modules/fetch/FetchManager.h" 17 #include "modules/fetch/FetchManager.h"
17 #include "modules/fetch/RequestInit.h" 18 #include "modules/fetch/RequestInit.h"
18 #include "platform/network/HTTPParsers.h" 19 #include "platform/network/HTTPParsers.h"
19 #include "platform/network/ResourceRequest.h" 20 #include "platform/network/ResourceRequest.h"
20 #include "platform/weborigin/Referrer.h" 21 #include "platform/weborigin/Referrer.h"
21 #include "public/platform/WebURLRequest.h" 22 #include "public/platform/WebURLRequest.h"
22 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" 23 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
23 24
24 namespace blink { 25 namespace blink {
(...skipping 18 matching lines...) Expand all
43 request->setCredentials(original->credentials()); 44 request->setCredentials(original->credentials());
44 request->setRedirect(original->redirect()); 45 request->setRedirect(original->redirect());
45 request->setIntegrity(original->integrity()); 46 request->setIntegrity(original->integrity());
46 // FIXME: Set cache mode. 47 // FIXME: Set cache mode.
47 // TODO(yhirano): Set redirect mode. 48 // TODO(yhirano): Set redirect mode.
48 return request; 49 return request;
49 } 50 }
50 51
51 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, RequestInit& init, ExceptionState & exceptionState) 52 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, RequestInit& init, ExceptionState & exceptionState)
52 { 53 {
53 // "1. Let |temporaryBody| be null." 54 // "1. If |input| is a Request object and it is disturbed, throw a
54 BodyStreamBuffer* temporaryBody = nullptr; 55 // TypeError.
55 56 if (inputRequest && inputRequest->bodyUsed()) {
56 if (inputRequest) { 57 exceptionState.throwTypeError("Cannot construct a Request with a Request object that has already been used.");
57 // We check bodyUsed even when the body is null in spite of the 58 return nullptr;
58 // spec. See https://github.com/whatwg/fetch/issues/61 for details.
59 if (inputRequest->bodyUsed()) {
60 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used.");
61 return nullptr;
62 }
63 } 59 }
64 60
65 // "2. If |input| is a Request object and |input|'s body is non-null, run 61 // "2. Let |temporaryBody| be |input|'s request's body if |input| is a
66 // these substeps:" 62 // Request object, and null otherwise.
67 if (inputRequest && inputRequest->hasBody()) { 63 BodyStreamBuffer* temporaryBody = inputRequest ? inputRequest->bodyBuffer() : nullptr;
68 // "1. If |input|'s used flag is set, throw a TypeError."
69 // "2. Set |temporaryBody| to |input|'s body."
70 if (inputRequest->bodyUsed()) {
71 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used.");
72 return nullptr;
73 }
74 temporaryBody = inputRequest->bodyBuffer();
75 }
76 64
77 // "3. Let |request| be |input|'s request, if |input| is a Request object, 65 // "3. Let |request| be |input|'s request, if |input| is a Request object,
78 // and a new request otherwise." 66 // and a new request otherwise."
79 // "4. Let origin be entry settings object's origin." 67 // "4. Let origin be entry settings object's origin."
80 RefPtr<SecurityOrigin> origin = scriptState->executionContext()->securityOri gin(); 68 RefPtr<SecurityOrigin> origin = scriptState->executionContext()->securityOri gin();
81 69
82 // TODO(yhirano): 70 // TODO(yhirano):
83 // "5. Let window be client." 71 // "5. Let window be client."
84 // "6. If request's window is an environment settings object and its 72 // "6. If request's window is an environment settings object and its
85 // origin is same origin with origin, set window to request's window." 73 // origin is same origin with origin, set window to request's window."
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 r->headers()->append("Content-Type", init.contentType, exceptionStat e); 281 r->headers()->append("Content-Type", init.contentType, exceptionStat e);
294 } 282 }
295 if (exceptionState.hadException()) 283 if (exceptionState.hadException())
296 return nullptr; 284 return nullptr;
297 } 285 }
298 286
299 // "33. Set |r|'s body to |temporaryBody|. 287 // "33. Set |r|'s body to |temporaryBody|.
300 if (temporaryBody) 288 if (temporaryBody)
301 r->m_request->setBuffer(temporaryBody); 289 r->m_request->setBuffer(temporaryBody);
302 290
303 // https://w3c.github.io/webappsec/specs/credentialmanagement/#monkey-patchi ng-fetch-2 291 // https://w3c.github.io/webappsec-credential-management/#monkey-patching-fe tch-2
304 if (init.opaque || (inputRequest && inputRequest->opaque())) 292 if (init.opaque || (inputRequest && inputRequest->opaque()))
305 r->makeOpaque(); 293 r->makeOpaque();
306 294
307 // "34. Set |r|'s MIME type to the result of extracting a MIME type from 295 // "34. Set |r|'s MIME type to the result of extracting a MIME type from
308 // |r|'s request's header list." 296 // |r|'s request's header list."
309 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); 297 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType());
310 298
311 // "35. If |input| is a Request object and |input|'s body is non-null, run 299 // "35. If |input| is a Request object and |input|'s body is non-null, run
312 // these substeps:" 300 // these substeps:"
313 // We set bodyUsed even when the body is null in spite of the 301 if (inputRequest && inputRequest->bodyBuffer()) {
314 // spec. See https://github.com/whatwg/fetch/issues/61 for details. 302 // "1. Set |input|'s body to an empty byte stream."
315 if (inputRequest) { 303 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC onsumerHandleFromWebHandle(createDoneDataConsumerHandle())));
316 // "1. Set |input|'s body to null." 304 // "2. Set |input|'s disturbed flag."
317 inputRequest->m_request->setBuffer(nullptr); 305 inputRequest->bodyBuffer()->stream()->setIsDisturbed();
318 // "2. Set |input|'s used flag."
319 inputRequest->setBodyPassed();
320 } 306 }
321 307
322 // "36. Return |r|." 308 // "36. Return |r|."
323 return r; 309 return r;
324 } 310 }
325 311
326 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState) 312 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState)
327 { 313 {
328 ASSERT(!input.isNull()); 314 ASSERT(!input.isNull());
329 if (input.isUSVString()) 315 if (input.isUSVString())
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 534
549 FetchRequestData* request = m_request->clone(executionContext()); 535 FetchRequestData* request = m_request->clone(executionContext());
550 Headers* headers = Headers::create(request->headerList()); 536 Headers* headers = Headers::create(request->headerList());
551 headers->setGuard(m_headers->guard()); 537 headers->setGuard(m_headers->guard());
552 return new Request(executionContext(), request, headers); 538 return new Request(executionContext(), request, headers);
553 } 539 }
554 540
555 FetchRequestData* Request::passRequestData() 541 FetchRequestData* Request::passRequestData()
556 { 542 {
557 ASSERT(!bodyUsed()); 543 ASSERT(!bodyUsed());
558 setBodyPassed(); 544 return m_request->pass(executionContext());
559 FetchRequestData* newRequestData = m_request->pass(executionContext());
560 return newRequestData;
561 } 545 }
562 546
563 bool Request::hasBody() const 547 bool Request::hasBody() const
564 { 548 {
565 return bodyBuffer(); 549 return bodyBuffer();
566 } 550 }
567 551
568 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const 552 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const
569 { 553 {
570 webRequest.setMethod(method()); 554 webRequest.setMethod(method());
(...skipping 18 matching lines...) Expand all
589 } 573 }
590 574
591 DEFINE_TRACE(Request) 575 DEFINE_TRACE(Request)
592 { 576 {
593 Body::trace(visitor); 577 Body::trace(visitor);
594 visitor->trace(m_request); 578 visitor->trace(m_request);
595 visitor->trace(m_headers); 579 visitor->trace(m_headers);
596 } 580 }
597 581
598 } // namespace blink 582 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698