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

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 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 BodyStreamBuffer* temporaryBody = nullptr;
54
55 if (inputRequest) {
56 // We check bodyUsed even when the body is null in spite of the
57 // spec. See https://github.com/whatwg/fetch/issues/61 for details.
58 if (inputRequest->bodyUsed()) {
59 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used.");
60 return nullptr;
61 }
62 }
63
64 // - "If |input| is a Request object and it is disturbed, throw a 54 // - "If |input| is a Request object and it is disturbed, throw a
65 // TypeError." 55 // TypeError."
56 if (inputRequest && inputRequest->bodyUsed()) {
57 exceptionState.throwTypeError("Cannot construct a Request with a Request object that has already been used.");
58 return nullptr;
59 }
66 // - "Let |temporaryBody| be |input|'s request's body if |input| is a 60 // - "Let |temporaryBody| be |input|'s request's body if |input| is a
67 // Request object, and null otherwise." 61 // Request object, and null otherwise."
68 if (inputRequest && inputRequest->hasBody()) { 62 BodyStreamBuffer* temporaryBody = inputRequest ? inputRequest->bodyBuffer() : nullptr;
69 if (inputRequest->bodyUsed()) {
70 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used.");
71 return nullptr;
72 }
73 temporaryBody = inputRequest->bodyBuffer();
74 }
75 63
76 // "Let |request| be |input|'s request, if |input| is a Request object, 64 // "Let |request| be |input|'s request, if |input| is a Request object,
77 // and a new request otherwise." 65 // and a new request otherwise."
78 66
79 RefPtr<SecurityOrigin> origin = scriptState->executionContext()->securityOri gin(); 67 RefPtr<SecurityOrigin> origin = scriptState->executionContext()->securityOri gin();
80 68
81 // TODO(yhirano): Implement the following steps: 69 // TODO(yhirano): Implement the following steps:
82 // - "Let |window| be client." 70 // - "Let |window| be client."
83 // - "If |request|'s window is an environment settings object and its 71 // - "If |request|'s window is an environment settings object and its
84 // origin is same origin with entry settings object's origin, set 72 // origin is same origin with entry settings object's origin, set
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // "4. Set |r|'s opaque flag." 347 // "4. Set |r|'s opaque flag."
360 r->setOpaque(); 348 r->setOpaque();
361 } 349 }
362 350
363 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s 351 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s
364 // request's header list." 352 // request's header list."
365 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); 353 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType());
366 354
367 // "If |input| is a Request object and |input|'s request's body is 355 // "If |input| is a Request object and |input|'s request's body is
368 // non-null, run these substeps:" 356 // non-null, run these substeps:"
369 // 357 if (inputRequest && inputRequest->bodyBuffer()) {
370 // We set bodyUsed even when the body is null in spite of the
371 // spec. See https://github.com/whatwg/fetch/issues/61 for details.
372 if (inputRequest) {
373 // "Set |input|'s body to an empty byte stream." 358 // "Set |input|'s body to an empty byte stream."
374 inputRequest->m_request->setBuffer(nullptr); 359 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC onsumerHandleFromWebHandle(createDoneDataConsumerHandle())));
375 // "Set |input|'s disturbed flag." 360 // "Set |input|'s disturbed flag."
376 inputRequest->setBodyPassed(); 361 inputRequest->bodyBuffer()->stream()->setIsDisturbed();
377 } 362 }
378 363
379 // "Return |r|." 364 // "Return |r|."
380 return r; 365 return r;
381 } 366 }
382 367
383 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState) 368 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState)
384 { 369 {
385 ASSERT(!input.isNull()); 370 ASSERT(!input.isNull());
386 if (input.isUSVString()) 371 if (input.isUSVString())
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 return ""; 578 return "";
594 } 579 }
595 580
596 String Request::integrity() const 581 String Request::integrity() const
597 { 582 {
598 return m_request->integrity(); 583 return m_request->integrity();
599 } 584 }
600 585
601 Request* Request::clone(ExceptionState& exceptionState) 586 Request* Request::clone(ExceptionState& exceptionState)
602 { 587 {
603 if (bodyUsed()) { 588 if (isBodyLocked() || bodyUsed()) {
604 exceptionState.throwTypeError("Request body is already used"); 589 exceptionState.throwTypeError("Request body is already used");
605 return nullptr; 590 return nullptr;
606 } 591 }
607 592
608 FetchRequestData* request = m_request->clone(executionContext()); 593 FetchRequestData* request = m_request->clone(executionContext());
609 Headers* headers = Headers::create(request->headerList()); 594 Headers* headers = Headers::create(request->headerList());
610 headers->setGuard(m_headers->guard()); 595 headers->setGuard(m_headers->guard());
611 return new Request(executionContext(), request, headers); 596 return new Request(executionContext(), request, headers);
612 } 597 }
613 598
614 FetchRequestData* Request::passRequestData() 599 FetchRequestData* Request::passRequestData()
615 { 600 {
616 ASSERT(!bodyUsed()); 601 ASSERT(!bodyUsed());
617 setBodyPassed(); 602 return m_request->pass(executionContext());
618 FetchRequestData* newRequestData = m_request->pass(executionContext());
619 return newRequestData;
620 } 603 }
621 604
622 bool Request::hasBody() const 605 bool Request::hasBody() const
623 { 606 {
624 return bodyBuffer(); 607 return bodyBuffer();
625 } 608 }
626 609
627 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const 610 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const
628 { 611 {
629 webRequest.setMethod(method()); 612 webRequest.setMethod(method());
(...skipping 18 matching lines...) Expand all
648 } 631 }
649 632
650 DEFINE_TRACE(Request) 633 DEFINE_TRACE(Request)
651 { 634 {
652 Body::trace(visitor); 635 Body::trace(visitor);
653 visitor->trace(m_request); 636 visitor->trace(m_request);
654 visitor->trace(m_headers); 637 visitor->trace(m_headers);
655 } 638 }
656 639
657 } // namespace blink 640 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/FetchResponseData.cpp ('k') | third_party/WebKit/Source/modules/fetch/Response.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698