| 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 "modules/fetch/Request.h" | 5 #include "modules/fetch/Request.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/fetch/FetchUtils.h" | 10 #include "core/fetch/FetchUtils.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // "If |init|'s body member is present, run these substeps:" | 375 // "If |init|'s body member is present, run these substeps:" |
| 376 if (init.body) { | 376 if (init.body) { |
| 377 // Perform the following steps: | 377 // Perform the following steps: |
| 378 // - "Let |stream| and |Content-Type| be the result of extracting | 378 // - "Let |stream| and |Content-Type| be the result of extracting |
| 379 // |init|'s body member." | 379 // |init|'s body member." |
| 380 // - "Set |temporaryBody| to |stream|. | 380 // - "Set |temporaryBody| to |stream|. |
| 381 // - "If |Content-Type| is non-null and |r|'s request's header list | 381 // - "If |Content-Type| is non-null and |r|'s request's header list |
| 382 // contains no header named `Content-Type`, append | 382 // contains no header named `Content-Type`, append |
| 383 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any | 383 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
| 384 // exception." | 384 // exception." |
| 385 temporaryBody = new BodyStreamBuffer(scriptState, std::move(init.body)); | 385 temporaryBody = BodyStreamBuffer::create(scriptState, std::move(init.body)); |
| 386 if (!init.contentType.isEmpty() && | 386 if (!init.contentType.isEmpty() && |
| 387 !r->getHeaders()->has(HTTPNames::Content_Type, exceptionState)) { | 387 !r->getHeaders()->has(HTTPNames::Content_Type, exceptionState)) { |
| 388 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, | 388 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, |
| 389 exceptionState); | 389 exceptionState); |
| 390 } | 390 } |
| 391 if (exceptionState.hadException()) | 391 if (exceptionState.hadException()) |
| 392 return nullptr; | 392 return nullptr; |
| 393 } | 393 } |
| 394 | 394 |
| 395 // "Set |r|'s request's body to |temporaryBody|. | 395 // "Set |r|'s request's body to |temporaryBody|. |
| 396 if (temporaryBody) { | 396 if (temporaryBody) { |
| 397 r->m_request->setBuffer(temporaryBody); | 397 r->m_request->setBuffer(temporaryBody); |
| 398 r->refreshBody(scriptState); | 398 r->refreshBody(scriptState); |
| 399 } | 399 } |
| 400 | 400 |
| 401 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s | 401 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s |
| 402 // request's header list." | 402 // request's header list." |
| 403 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 403 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 404 | 404 |
| 405 // "If |input| is a Request object and |input|'s request's body is | 405 // "If |input| is a Request object and |input|'s request's body is |
| 406 // non-null, run these substeps:" | 406 // non-null, run these substeps:" |
| 407 if (inputRequest && inputRequest->bodyBuffer()) { | 407 if (inputRequest && inputRequest->bodyBuffer()) { |
| 408 // "Let |dummyStream| be an empty ReadableStream object." | 408 // "Let |dummyStream| be an empty ReadableStream object." |
| 409 auto dummyStream = | 409 auto dummyStream = |
| 410 new BodyStreamBuffer(scriptState, BytesConsumer::createClosed()); | 410 BodyStreamBuffer::create(scriptState, BytesConsumer::createClosed()); |
| 411 // "Set |input|'s request's body to a new body whose stream is | 411 // "Set |input|'s request's body to a new body whose stream is |
| 412 // |dummyStream|." | 412 // |dummyStream|." |
| 413 inputRequest->m_request->setBuffer(dummyStream); | 413 inputRequest->m_request->setBuffer(dummyStream); |
| 414 inputRequest->refreshBody(scriptState); | 414 inputRequest->refreshBody(scriptState); |
| 415 // "Let |reader| be the result of getting reader from |dummyStream|." | 415 // "Let |reader| be the result of getting reader from |dummyStream|." |
| 416 // "Read all bytes from |dummyStream| with |reader|." | 416 // "Read all bytes from |dummyStream| with |reader|." |
| 417 inputRequest->bodyBuffer()->closeAndLockAndDisturb(); | 417 inputRequest->bodyBuffer()->closeAndLockAndDisturb(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 // "Return |r|." | 420 // "Return |r|." |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 return createRequestWithRequestOrString(scriptState, input, String(), | 462 return createRequestWithRequestOrString(scriptState, input, String(), |
| 463 requestInit, exceptionState); | 463 requestInit, exceptionState); |
| 464 } | 464 } |
| 465 | 465 |
| 466 Request* Request::create(ScriptState* scriptState, FetchRequestData* request) { | 466 Request* Request::create(ScriptState* scriptState, FetchRequestData* request) { |
| 467 return new Request(scriptState, request); | 467 return new Request(scriptState, request); |
| 468 } | 468 } |
| 469 | 469 |
| 470 Request* Request::create(ScriptState* scriptState, | 470 Request* Request::create(ScriptState* scriptState, |
| 471 const WebServiceWorkerRequest& webRequest) { | 471 const WebServiceWorkerRequest& webRequest) { |
| 472 return new Request(scriptState, webRequest); | 472 FetchRequestData* request = FetchRequestData::create(scriptState, webRequest); |
| 473 return new Request(scriptState, request); |
| 473 } | 474 } |
| 474 | 475 |
| 475 Request::Request(ScriptState* scriptState, | 476 Request::Request(ScriptState* scriptState, |
| 476 FetchRequestData* request, | 477 FetchRequestData* request, |
| 477 Headers* headers) | 478 Headers* headers) |
| 478 : Body(scriptState->getExecutionContext()), | 479 : Body(scriptState->getExecutionContext()), |
| 479 m_request(request), | 480 m_request(request), |
| 480 m_headers(headers) { | 481 m_headers(headers) { |
| 481 refreshBody(scriptState); | 482 refreshBody(scriptState); |
| 482 } | 483 } |
| 483 | 484 |
| 484 Request::Request(ScriptState* scriptState, FetchRequestData* request) | 485 Request::Request(ScriptState* scriptState, FetchRequestData* request) |
| 485 : Request(scriptState, request, Headers::create(request->headerList())) { | 486 : Request(scriptState, request, Headers::create(request->headerList())) { |
| 486 m_headers->setGuard(Headers::RequestGuard); | 487 m_headers->setGuard(Headers::RequestGuard); |
| 487 } | 488 } |
| 488 | 489 |
| 489 Request::Request(ScriptState* scriptState, | |
| 490 const WebServiceWorkerRequest& request) | |
| 491 : Request(scriptState, FetchRequestData::create(scriptState, request)) {} | |
| 492 | |
| 493 String Request::method() const { | 490 String Request::method() const { |
| 494 // "The method attribute's getter must return request's method." | 491 // "The method attribute's getter must return request's method." |
| 495 return m_request->method(); | 492 return m_request->method(); |
| 496 } | 493 } |
| 497 | 494 |
| 498 KURL Request::url() const { | 495 KURL Request::url() const { |
| 499 // The url attribute's getter must return request's url, serialized with the | 496 // The url attribute's getter must return request's url, serialized with the |
| 500 // exclude fragment flag set. | 497 // exclude fragment flag set. |
| 501 if (!m_request->url().hasFragmentIdentifier()) | 498 if (!m_request->url().hasFragmentIdentifier()) |
| 502 return m_request->url(); | 499 return m_request->url(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); | 733 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); |
| 737 } | 734 } |
| 738 | 735 |
| 739 DEFINE_TRACE(Request) { | 736 DEFINE_TRACE(Request) { |
| 740 Body::trace(visitor); | 737 Body::trace(visitor); |
| 741 visitor->trace(m_request); | 738 visitor->trace(m_request); |
| 742 visitor->trace(m_headers); | 739 visitor->trace(m_headers); |
| 743 } | 740 } |
| 744 | 741 |
| 745 } // namespace blink | 742 } // namespace blink |
| OLD | NEW |