| OLD | NEW |
| 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 Loading... |
| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // "34. Set |r|'s MIME type to the result of extracting a MIME type from | 291 // "34. Set |r|'s MIME type to the result of extracting a MIME type from |
| 304 // |r|'s request's header list." | 292 // |r|'s request's header list." |
| 305 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 293 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 306 | 294 |
| 307 // "35. If |input| is a Request object and |input|'s body is non-null, run | 295 // "35. If |input| is a Request object and |input|'s body is non-null, run |
| 308 // these substeps:" | 296 // these substeps:" |
| 309 // We set bodyUsed even when the body is null in spite of the | 297 if (inputRequest && inputRequest->bodyBuffer()) { |
| 310 // spec. See https://github.com/whatwg/fetch/issues/61 for details. | 298 // "1. Set |input|'s body to an empty byte stream." |
| 311 if (inputRequest) { | 299 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC
onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
| 312 // "1. Set |input|'s body to null." | 300 // "2. Set |input|'s disturbed flag." |
| 313 inputRequest->m_request->setBuffer(nullptr); | 301 inputRequest->bodyBuffer()->stream()->setIsDisturbed(); |
| 314 // "2. Set |input|'s used flag." | |
| 315 inputRequest->setBodyPassed(); | |
| 316 } | 302 } |
| 317 | 303 |
| 318 // "36. Return |r|." | 304 // "36. Return |r|." |
| 319 return r; | 305 return r; |
| 320 } | 306 } |
| 321 | 307 |
| 322 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con
st Dictionary& init, ExceptionState& exceptionState) | 308 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con
st Dictionary& init, ExceptionState& exceptionState) |
| 323 { | 309 { |
| 324 ASSERT(!input.isNull()); | 310 ASSERT(!input.isNull()); |
| 325 if (input.isUSVString()) | 311 if (input.isUSVString()) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 530 |
| 545 FetchRequestData* request = m_request->clone(executionContext()); | 531 FetchRequestData* request = m_request->clone(executionContext()); |
| 546 Headers* headers = Headers::create(request->headerList()); | 532 Headers* headers = Headers::create(request->headerList()); |
| 547 headers->setGuard(m_headers->guard()); | 533 headers->setGuard(m_headers->guard()); |
| 548 return new Request(executionContext(), request, headers); | 534 return new Request(executionContext(), request, headers); |
| 549 } | 535 } |
| 550 | 536 |
| 551 FetchRequestData* Request::passRequestData() | 537 FetchRequestData* Request::passRequestData() |
| 552 { | 538 { |
| 553 ASSERT(!bodyUsed()); | 539 ASSERT(!bodyUsed()); |
| 554 setBodyPassed(); | 540 return m_request->pass(executionContext()); |
| 555 FetchRequestData* newRequestData = m_request->pass(executionContext()); | |
| 556 return newRequestData; | |
| 557 } | 541 } |
| 558 | 542 |
| 559 bool Request::hasBody() const | 543 bool Request::hasBody() const |
| 560 { | 544 { |
| 561 return bodyBuffer(); | 545 return bodyBuffer(); |
| 562 } | 546 } |
| 563 | 547 |
| 564 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) const | 548 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) const |
| 565 { | 549 { |
| 566 webRequest.setMethod(method()); | 550 webRequest.setMethod(method()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 585 } | 569 } |
| 586 | 570 |
| 587 DEFINE_TRACE(Request) | 571 DEFINE_TRACE(Request) |
| 588 { | 572 { |
| 589 Body::trace(visitor); | 573 Body::trace(visitor); |
| 590 visitor->trace(m_request); | 574 visitor->trace(m_request); |
| 591 visitor->trace(m_headers); | 575 visitor->trace(m_headers); |
| 592 } | 576 } |
| 593 | 577 |
| 594 } // namespace blink | 578 } // namespace blink |
| OLD | NEW |