Chromium Code Reviews| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // "33. Set |r|'s body to |temporaryBody|. | 303 // "33. Set |r|'s body to |temporaryBody|. |
| 316 if (temporaryBody) | 304 if (temporaryBody) |
| 317 r->m_request->setBuffer(temporaryBody); | 305 r->m_request->setBuffer(temporaryBody); |
| 318 | 306 |
| 319 // "34. Set |r|'s MIME type to the result of extracting a MIME type from | 307 // "34. Set |r|'s MIME type to the result of extracting a MIME type from |
| 320 // |r|'s request's header list." | 308 // |r|'s request's header list." |
| 321 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 309 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 322 | 310 |
| 323 // "35. If |input| is a Request object and |input|'s body is non-null, run | 311 // "35. If |input| is a Request object and |input|'s body is non-null, run |
| 324 // these substeps:" | 312 // these substeps:" |
| 325 // We set bodyUsed even when the body is null in spite of the | 313 if (inputRequest && inputRequest->bodyBuffer()) { |
| 326 // spec. See https://github.com/whatwg/fetch/issues/61 for details. | 314 // "1. Set |input|'s body to an empty byte stream." |
| 327 if (inputRequest) { | 315 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
| 328 // "1. Set |input|'s body to null." | 316 // "2. Set |input|'s disturbed flag." |
| 329 inputRequest->m_request->setBuffer(nullptr); | 317 inputRequest->bodyBuffer()->stream()->setIsDisturbed(); |
| 330 // "2. Set |input|'s used flag." | |
| 331 inputRequest->setBodyPassed(); | |
| 332 } | 318 } |
| 333 | 319 |
| 334 // "36. Return |r|." | 320 // "36. Return |r|." |
| 335 return r; | 321 return r; |
| 336 } | 322 } |
| 337 | 323 |
| 338 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState) | 324 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState) |
| 339 { | 325 { |
| 340 ASSERT(!input.isNull()); | 326 ASSERT(!input.isNull()); |
| 341 if (input.isUSVString()) | 327 if (input.isUSVString()) |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 return ""; | 534 return ""; |
| 549 } | 535 } |
| 550 | 536 |
| 551 String Request::integrity() const | 537 String Request::integrity() const |
| 552 { | 538 { |
| 553 return m_request->integrity(); | 539 return m_request->integrity(); |
| 554 } | 540 } |
| 555 | 541 |
| 556 Request* Request::clone(ExceptionState& exceptionState) | 542 Request* Request::clone(ExceptionState& exceptionState) |
| 557 { | 543 { |
| 558 if (bodyUsed()) { | 544 if (bodyUsed() || isBodyLocked()) { |
|
hiroshige
2015/11/19 12:50:37
nit: we write "isBodyLocked() || bodyUsed()" in so
yhirano
2015/11/19 13:19:03
Done.
| |
| 559 exceptionState.throwTypeError("Request body is already used"); | 545 exceptionState.throwTypeError("Request body is already used"); |
| 560 return nullptr; | 546 return nullptr; |
| 561 } | 547 } |
| 562 | 548 |
| 563 FetchRequestData* request = m_request->clone(executionContext()); | 549 FetchRequestData* request = m_request->clone(executionContext()); |
| 564 Headers* headers = Headers::create(request->headerList()); | 550 Headers* headers = Headers::create(request->headerList()); |
| 565 headers->setGuard(m_headers->guard()); | 551 headers->setGuard(m_headers->guard()); |
| 566 return new Request(executionContext(), request, headers); | 552 return new Request(executionContext(), request, headers); |
| 567 } | 553 } |
| 568 | 554 |
| 569 FetchRequestData* Request::passRequestData() | 555 FetchRequestData* Request::passRequestData() |
| 570 { | 556 { |
| 571 ASSERT(!bodyUsed()); | 557 ASSERT(!bodyUsed()); |
| 572 setBodyPassed(); | 558 return m_request->pass(executionContext()); |
| 573 FetchRequestData* newRequestData = m_request->pass(executionContext()); | |
| 574 return newRequestData; | |
| 575 } | 559 } |
| 576 | 560 |
| 577 bool Request::hasBody() const | 561 bool Request::hasBody() const |
| 578 { | 562 { |
| 579 return bodyBuffer(); | 563 return bodyBuffer(); |
| 580 } | 564 } |
| 581 | 565 |
| 582 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const | 566 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const |
| 583 { | 567 { |
| 584 webRequest.setMethod(method()); | 568 webRequest.setMethod(method()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 603 } | 587 } |
| 604 | 588 |
| 605 DEFINE_TRACE(Request) | 589 DEFINE_TRACE(Request) |
| 606 { | 590 { |
| 607 Body::trace(visitor); | 591 Body::trace(visitor); |
| 608 visitor->trace(m_request); | 592 visitor->trace(m_request); |
| 609 visitor->trace(m_headers); | 593 visitor->trace(m_headers); |
| 610 } | 594 } |
| 611 | 595 |
| 612 } // namespace blink | 596 } // namespace blink |
| OLD | NEW |