| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 if (FetchUtils::isForbiddenMethod(init.method)) { | 262 if (FetchUtils::isForbiddenMethod(init.method)) { |
| 263 exceptionState.throwTypeError("'" + init.method + "' HTTP method is
unsupported."); | 263 exceptionState.throwTypeError("'" + init.method + "' HTTP method is
unsupported."); |
| 264 return nullptr; | 264 return nullptr; |
| 265 } | 265 } |
| 266 // "Normalize |method|." | 266 // "Normalize |method|." |
| 267 // "Set |request|'s method to |method|." | 267 // "Set |request|'s method to |method|." |
| 268 request->setMethod(FetchUtils::normalizeMethod(AtomicString(init.method)
)); | 268 request->setMethod(FetchUtils::normalizeMethod(AtomicString(init.method)
)); |
| 269 } | 269 } |
| 270 // "Let |r| be a new Request object associated with |request| and a new | 270 // "Let |r| be a new Request object associated with |request| and a new |
| 271 // Headers object whose guard is "request"." | 271 // Headers object whose guard is "request"." |
| 272 Request* r = Request::create(scriptState->getExecutionContext(), request); | 272 Request* r = Request::create(scriptState, request); |
| 273 // Perform the following steps: | 273 // Perform the following steps: |
| 274 // - "Let |headers| be a copy of |r|'s Headers object." | 274 // - "Let |headers| be a copy of |r|'s Headers object." |
| 275 // - "If |init|'s headers member is present, set |headers| to |init|'s | 275 // - "If |init|'s headers member is present, set |headers| to |init|'s |
| 276 // headers member." | 276 // headers member." |
| 277 // | 277 // |
| 278 // We don't create a copy of r's Headers object when init's headers member | 278 // We don't create a copy of r's Headers object when init's headers member |
| 279 // is present. | 279 // is present. |
| 280 Headers* headers = nullptr; | 280 Headers* headers = nullptr; |
| 281 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 281 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
| 282 headers = r->getHeaders()->clone(); | 282 headers = r->getHeaders()->clone(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // "If |init|'s body member is present, run these substeps:" | 337 // "If |init|'s body member is present, run these substeps:" |
| 338 if (init.body) { | 338 if (init.body) { |
| 339 // Perform the following steps: | 339 // Perform the following steps: |
| 340 // - "Let |stream| and |Content-Type| be the result of extracting | 340 // - "Let |stream| and |Content-Type| be the result of extracting |
| 341 // |init|'s body member." | 341 // |init|'s body member." |
| 342 // - "Set |temporaryBody| to |stream|. | 342 // - "Set |temporaryBody| to |stream|. |
| 343 // - "If |Content-Type| is non-null and |r|'s request's header list | 343 // - "If |Content-Type| is non-null and |r|'s request's header list |
| 344 // contains no header named `Content-Type`, append | 344 // contains no header named `Content-Type`, append |
| 345 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any | 345 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
| 346 // exception." | 346 // exception." |
| 347 temporaryBody = new BodyStreamBuffer(init.body.release()); | 347 temporaryBody = new BodyStreamBuffer(scriptState, init.body.release()); |
| 348 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont
ent_Type, exceptionState)) { | 348 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont
ent_Type, exceptionState)) { |
| 349 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e
xceptionState); | 349 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e
xceptionState); |
| 350 } | 350 } |
| 351 if (exceptionState.hadException()) | 351 if (exceptionState.hadException()) |
| 352 return nullptr; | 352 return nullptr; |
| 353 } | 353 } |
| 354 | 354 |
| 355 // "Set |r|'s request's body to |temporaryBody|. | 355 // "Set |r|'s request's body to |temporaryBody|. |
| 356 if (temporaryBody) | 356 if (temporaryBody) |
| 357 r->m_request->setBuffer(temporaryBody); | 357 r->m_request->setBuffer(temporaryBody); |
| 358 | 358 |
| 359 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s | 359 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s |
| 360 // request's header list." | 360 // request's header list." |
| 361 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 361 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 362 | 362 |
| 363 // "If |input| is a Request object and |input|'s request's body is | 363 // "If |input| is a Request object and |input|'s request's body is |
| 364 // non-null, run these substeps:" | 364 // non-null, run these substeps:" |
| 365 if (inputRequest && inputRequest->bodyBuffer()) { | 365 if (inputRequest && inputRequest->bodyBuffer()) { |
| 366 // "Set |input|'s body to an empty byte stream." | 366 // "Set |input|'s body to an empty byte stream." |
| 367 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC
onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); | 367 inputRequest->m_request->setBuffer(new BodyStreamBuffer(scriptState, cre
ateFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
| 368 // "Set |input|'s disturbed flag." | 368 // "Set |input|'s disturbed flag." |
| 369 inputRequest->bodyBuffer()->stream()->setIsDisturbed(); | 369 inputRequest->bodyBuffer()->setDisturbed(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 // "Return |r|." | 372 // "Return |r|." |
| 373 return r; | 373 return r; |
| 374 } | 374 } |
| 375 | 375 |
| 376 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con
st Dictionary& init, ExceptionState& exceptionState) | 376 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con
st Dictionary& init, ExceptionState& exceptionState) |
| 377 { | 377 { |
| 378 ASSERT(!input.isNull()); | 378 ASSERT(!input.isNull()); |
| 379 if (input.isUSVString()) | 379 if (input.isUSVString()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 396 { | 396 { |
| 397 return create(scriptState, input, Dictionary(), exceptionState); | 397 return create(scriptState, input, Dictionary(), exceptionState); |
| 398 } | 398 } |
| 399 | 399 |
| 400 Request* Request::create(ScriptState* scriptState, Request* input, const Diction
ary& init, ExceptionState& exceptionState) | 400 Request* Request::create(ScriptState* scriptState, Request* input, const Diction
ary& init, ExceptionState& exceptionState) |
| 401 { | 401 { |
| 402 RequestInit requestInit(scriptState->getExecutionContext(), init, exceptionS
tate); | 402 RequestInit requestInit(scriptState->getExecutionContext(), init, exceptionS
tate); |
| 403 return createRequestWithRequestOrString(scriptState, input, String(), reques
tInit, exceptionState); | 403 return createRequestWithRequestOrString(scriptState, input, String(), reques
tInit, exceptionState); |
| 404 } | 404 } |
| 405 | 405 |
| 406 Request* Request::create(ExecutionContext* context, FetchRequestData* request) | 406 Request* Request::create(ScriptState* scriptState, FetchRequestData* request) |
| 407 { | 407 { |
| 408 return new Request(context, request); | 408 return new Request(scriptState, request); |
| 409 } | 409 } |
| 410 | 410 |
| 411 Request::Request(ExecutionContext* context, FetchRequestData* request) | 411 Request* Request::create(ScriptState* scriptState, const WebServiceWorkerRequest
& webRequest) |
| 412 : Body(context) | 412 { |
| 413 return new Request(scriptState, webRequest); |
| 414 } |
| 415 |
| 416 Request::Request(ScriptState* scriptState, FetchRequestData* request, Headers* h
eaders) |
| 417 : Body(scriptState->getExecutionContext()) |
| 413 , m_request(request) | 418 , m_request(request) |
| 414 , m_headers(Headers::create(m_request->headerList())) | 419 , m_headers(headers) |
| 420 { |
| 421 } |
| 422 |
| 423 Request::Request(ScriptState* scriptState, FetchRequestData* request) |
| 424 : Request(scriptState, request, Headers::create(request->headerList())) |
| 415 { | 425 { |
| 416 m_headers->setGuard(Headers::RequestGuard); | 426 m_headers->setGuard(Headers::RequestGuard); |
| 417 } | 427 } |
| 418 | 428 |
| 419 Request::Request(ExecutionContext* context, FetchRequestData* request, Headers*
headers) | 429 Request::Request(ScriptState* scriptState, const WebServiceWorkerRequest& reques
t) |
| 420 : Body(context) , m_request(request) , m_headers(headers) {} | 430 : Request(scriptState, FetchRequestData::create(scriptState, request)) |
| 421 | |
| 422 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques
t& webRequest) | |
| 423 { | 431 { |
| 424 return new Request(context, webRequest); | |
| 425 } | |
| 426 | |
| 427 Request::Request(ExecutionContext* context, const WebServiceWorkerRequest& webRe
quest) | |
| 428 : Body(context) | |
| 429 , m_request(FetchRequestData::create(context, webRequest)) | |
| 430 , m_headers(Headers::create(m_request->headerList())) | |
| 431 { | |
| 432 m_headers->setGuard(Headers::RequestGuard); | |
| 433 } | 432 } |
| 434 | 433 |
| 435 String Request::method() const | 434 String Request::method() const |
| 436 { | 435 { |
| 437 // "The method attribute's getter must return request's method." | 436 // "The method attribute's getter must return request's method." |
| 438 return m_request->method(); | 437 return m_request->method(); |
| 439 } | 438 } |
| 440 | 439 |
| 441 KURL Request::url() const | 440 KURL Request::url() const |
| 442 { | 441 { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 } | 608 } |
| 610 ASSERT_NOT_REACHED(); | 609 ASSERT_NOT_REACHED(); |
| 611 return ""; | 610 return ""; |
| 612 } | 611 } |
| 613 | 612 |
| 614 String Request::integrity() const | 613 String Request::integrity() const |
| 615 { | 614 { |
| 616 return m_request->integrity(); | 615 return m_request->integrity(); |
| 617 } | 616 } |
| 618 | 617 |
| 619 Request* Request::clone(ExceptionState& exceptionState) | 618 Request* Request::clone(ScriptState* scriptState, ExceptionState& exceptionState
) |
| 620 { | 619 { |
| 621 if (isBodyLocked() || bodyUsed()) { | 620 if (isBodyLocked() || bodyUsed()) { |
| 622 exceptionState.throwTypeError("Request body is already used"); | 621 exceptionState.throwTypeError("Request body is already used"); |
| 623 return nullptr; | 622 return nullptr; |
| 624 } | 623 } |
| 625 | 624 |
| 626 FetchRequestData* request = m_request->clone(getExecutionContext()); | 625 FetchRequestData* request = m_request->clone(scriptState); |
| 627 Headers* headers = Headers::create(request->headerList()); | 626 Headers* headers = Headers::create(request->headerList()); |
| 628 headers->setGuard(m_headers->getGuard()); | 627 headers->setGuard(m_headers->getGuard()); |
| 629 return new Request(getExecutionContext(), request, headers); | 628 return new Request(scriptState, request, headers); |
| 630 } | 629 } |
| 631 | 630 |
| 632 FetchRequestData* Request::passRequestData() | 631 FetchRequestData* Request::passRequestData(ScriptState* scriptState) |
| 633 { | 632 { |
| 634 ASSERT(!bodyUsed()); | 633 ASSERT(!bodyUsed()); |
| 635 return m_request->pass(getExecutionContext()); | 634 return m_request->pass(scriptState); |
| 636 } | 635 } |
| 637 | 636 |
| 638 bool Request::hasBody() const | 637 bool Request::hasBody() const |
| 639 { | 638 { |
| 640 return bodyBuffer(); | 639 return bodyBuffer(); |
| 641 } | 640 } |
| 642 | 641 |
| 643 void Request::stop() | |
| 644 { | |
| 645 if (bodyBuffer()) | |
| 646 bodyBuffer()->stop(); | |
| 647 } | |
| 648 | |
| 649 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) const | 642 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) const |
| 650 { | 643 { |
| 651 webRequest.setMethod(method()); | 644 webRequest.setMethod(method()); |
| 652 webRequest.setRequestContext(m_request->context()); | 645 webRequest.setRequestContext(m_request->context()); |
| 653 // This strips off the fragment part. | 646 // This strips off the fragment part. |
| 654 webRequest.setURL(url()); | 647 webRequest.setURL(url()); |
| 655 | 648 |
| 656 const FetchHeaderList* headerList = m_headers->headerList(); | 649 const FetchHeaderList* headerList = m_headers->headerList(); |
| 657 for (size_t i = 0, size = headerList->size(); i < size; ++i) { | 650 for (size_t i = 0, size = headerList->size(); i < size; ++i) { |
| 658 const FetchHeaderList::Header& header = headerList->entry(i); | 651 const FetchHeaderList::Header& header = headerList->entry(i); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 670 } | 663 } |
| 671 | 664 |
| 672 DEFINE_TRACE(Request) | 665 DEFINE_TRACE(Request) |
| 673 { | 666 { |
| 674 Body::trace(visitor); | 667 Body::trace(visitor); |
| 675 visitor->trace(m_request); | 668 visitor->trace(m_request); |
| 676 visitor->trace(m_headers); | 669 visitor->trace(m_headers); |
| 677 } | 670 } |
| 678 | 671 |
| 679 } // namespace blink | 672 } // namespace blink |
| OLD | NEW |