| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 if (FetchUtils::isForbiddenMethod(init.method)) { | 261 if (FetchUtils::isForbiddenMethod(init.method)) { |
| 262 exceptionState.throwTypeError("'" + init.method + "' HTTP method is
unsupported."); | 262 exceptionState.throwTypeError("'" + init.method + "' HTTP method is
unsupported."); |
| 263 return nullptr; | 263 return nullptr; |
| 264 } | 264 } |
| 265 // "Normalize |method|." | 265 // "Normalize |method|." |
| 266 // "Set |request|'s method to |method|." | 266 // "Set |request|'s method to |method|." |
| 267 request->setMethod(FetchUtils::normalizeMethod(AtomicString(init.method)
)); | 267 request->setMethod(FetchUtils::normalizeMethod(AtomicString(init.method)
)); |
| 268 } | 268 } |
| 269 // "Let |r| be a new Request object associated with |request| and a new | 269 // "Let |r| be a new Request object associated with |request| and a new |
| 270 // Headers object whose guard is "request"." | 270 // Headers object whose guard is "request"." |
| 271 Request* r = Request::create(scriptState->getExecutionContext(), request); | 271 Request* r = Request::create(scriptState, request); |
| 272 // Perform the following steps: | 272 // Perform the following steps: |
| 273 // - "Let |headers| be a copy of |r|'s Headers object." | 273 // - "Let |headers| be a copy of |r|'s Headers object." |
| 274 // - "If |init|'s headers member is present, set |headers| to |init|'s | 274 // - "If |init|'s headers member is present, set |headers| to |init|'s |
| 275 // headers member." | 275 // headers member." |
| 276 // | 276 // |
| 277 // We don't create a copy of r's Headers object when init's headers member | 277 // We don't create a copy of r's Headers object when init's headers member |
| 278 // is present. | 278 // is present. |
| 279 Headers* headers = nullptr; | 279 Headers* headers = nullptr; |
| 280 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 280 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
| 281 headers = r->getHeaders()->clone(); | 281 headers = r->getHeaders()->clone(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // "If |init|'s body member is present, run these substeps:" | 336 // "If |init|'s body member is present, run these substeps:" |
| 337 if (init.body) { | 337 if (init.body) { |
| 338 // Perform the following steps: | 338 // Perform the following steps: |
| 339 // - "Let |stream| and |Content-Type| be the result of extracting | 339 // - "Let |stream| and |Content-Type| be the result of extracting |
| 340 // |init|'s body member." | 340 // |init|'s body member." |
| 341 // - "Set |temporaryBody| to |stream|. | 341 // - "Set |temporaryBody| to |stream|. |
| 342 // - "If |Content-Type| is non-null and |r|'s request's header list | 342 // - "If |Content-Type| is non-null and |r|'s request's header list |
| 343 // contains no header named `Content-Type`, append | 343 // contains no header named `Content-Type`, append |
| 344 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any | 344 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
| 345 // exception." | 345 // exception." |
| 346 temporaryBody = new BodyStreamBuffer(init.body.release()); | 346 temporaryBody = new BodyStreamBuffer(scriptState, init.body.release()); |
| 347 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont
ent_Type, exceptionState)) { | 347 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont
ent_Type, exceptionState)) { |
| 348 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e
xceptionState); | 348 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e
xceptionState); |
| 349 } | 349 } |
| 350 if (exceptionState.hadException()) | 350 if (exceptionState.hadException()) |
| 351 return nullptr; | 351 return nullptr; |
| 352 } | 352 } |
| 353 | 353 |
| 354 // "Set |r|'s request's body to |temporaryBody|. | 354 // "Set |r|'s request's body to |temporaryBody|. |
| 355 if (temporaryBody) | 355 if (temporaryBody) |
| 356 r->m_request->setBuffer(temporaryBody); | 356 r->m_request->setBuffer(temporaryBody); |
| 357 | 357 |
| 358 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s | 358 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s |
| 359 // request's header list." | 359 // request's header list." |
| 360 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 360 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 361 | 361 |
| 362 // "If |input| is a Request object and |input|'s request's body is | 362 // "If |input| is a Request object and |input|'s request's body is |
| 363 // non-null, run these substeps:" | 363 // non-null, run these substeps:" |
| 364 if (inputRequest && inputRequest->bodyBuffer()) { | 364 if (inputRequest && inputRequest->bodyBuffer()) { |
| 365 // "Set |input|'s body to an empty byte stream." | 365 // "Set |input|'s body to an empty byte stream." |
| 366 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC
onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); | 366 inputRequest->m_request->setBuffer(new BodyStreamBuffer(scriptState, cre
ateFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
| 367 // "Set |input|'s disturbed flag." | 367 // "Set |input|'s disturbed flag." |
| 368 inputRequest->bodyBuffer()->stream()->setIsDisturbed(); | 368 inputRequest->bodyBuffer()->setDisturbed(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 // "Return |r|." | 371 // "Return |r|." |
| 372 return r; | 372 return r; |
| 373 } | 373 } |
| 374 | 374 |
| 375 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con
st Dictionary& init, ExceptionState& exceptionState) | 375 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con
st Dictionary& init, ExceptionState& exceptionState) |
| 376 { | 376 { |
| 377 ASSERT(!input.isNull()); | 377 ASSERT(!input.isNull()); |
| 378 if (input.isUSVString()) | 378 if (input.isUSVString()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 395 { | 395 { |
| 396 return create(scriptState, input, Dictionary(), exceptionState); | 396 return create(scriptState, input, Dictionary(), exceptionState); |
| 397 } | 397 } |
| 398 | 398 |
| 399 Request* Request::create(ScriptState* scriptState, Request* input, const Diction
ary& init, ExceptionState& exceptionState) | 399 Request* Request::create(ScriptState* scriptState, Request* input, const Diction
ary& init, ExceptionState& exceptionState) |
| 400 { | 400 { |
| 401 RequestInit requestInit(scriptState->getExecutionContext(), init, exceptionS
tate); | 401 RequestInit requestInit(scriptState->getExecutionContext(), init, exceptionS
tate); |
| 402 return createRequestWithRequestOrString(scriptState, input, String(), reques
tInit, exceptionState); | 402 return createRequestWithRequestOrString(scriptState, input, String(), reques
tInit, exceptionState); |
| 403 } | 403 } |
| 404 | 404 |
| 405 Request* Request::create(ExecutionContext* context, FetchRequestData* request) | 405 Request* Request::create(ScriptState* scriptState, FetchRequestData* request) |
| 406 { | 406 { |
| 407 return new Request(context, request); | 407 return new Request(scriptState, request); |
| 408 } | 408 } |
| 409 | 409 |
| 410 Request::Request(ExecutionContext* context, FetchRequestData* request) | 410 Request* Request::create(ScriptState* scriptState, const WebServiceWorkerRequest
& webRequest) |
| 411 : Body(context) | 411 { |
| 412 return new Request(scriptState, webRequest); |
| 413 } |
| 414 |
| 415 Request::Request(ScriptState* scriptState, FetchRequestData* request, Headers* h
eaders) |
| 416 : Body(scriptState->getExecutionContext()) |
| 412 , m_request(request) | 417 , m_request(request) |
| 413 , m_headers(Headers::create(m_request->headerList())) | 418 , m_headers(headers) |
| 419 { |
| 420 } |
| 421 |
| 422 Request::Request(ScriptState* scriptState, FetchRequestData* request) |
| 423 : Request(scriptState, request, Headers::create(request->headerList())) |
| 414 { | 424 { |
| 415 m_headers->setGuard(Headers::RequestGuard); | 425 m_headers->setGuard(Headers::RequestGuard); |
| 416 } | 426 } |
| 417 | 427 |
| 418 Request::Request(ExecutionContext* context, FetchRequestData* request, Headers*
headers) | 428 Request::Request(ScriptState* scriptState, const WebServiceWorkerRequest& reques
t) |
| 419 : Body(context) , m_request(request) , m_headers(headers) {} | 429 : Request(scriptState, FetchRequestData::create(scriptState, request)) |
| 420 | |
| 421 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques
t& webRequest) | |
| 422 { | 430 { |
| 423 return new Request(context, webRequest); | |
| 424 } | |
| 425 | |
| 426 Request::Request(ExecutionContext* context, const WebServiceWorkerRequest& webRe
quest) | |
| 427 : Body(context) | |
| 428 , m_request(FetchRequestData::create(context, webRequest)) | |
| 429 , m_headers(Headers::create(m_request->headerList())) | |
| 430 { | |
| 431 m_headers->setGuard(Headers::RequestGuard); | |
| 432 } | 431 } |
| 433 | 432 |
| 434 String Request::method() const | 433 String Request::method() const |
| 435 { | 434 { |
| 436 // "The method attribute's getter must return request's method." | 435 // "The method attribute's getter must return request's method." |
| 437 return m_request->method(); | 436 return m_request->method(); |
| 438 } | 437 } |
| 439 | 438 |
| 440 KURL Request::url() const | 439 KURL Request::url() const |
| 441 { | 440 { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 584 } |
| 586 ASSERT_NOT_REACHED(); | 585 ASSERT_NOT_REACHED(); |
| 587 return ""; | 586 return ""; |
| 588 } | 587 } |
| 589 | 588 |
| 590 String Request::integrity() const | 589 String Request::integrity() const |
| 591 { | 590 { |
| 592 return m_request->integrity(); | 591 return m_request->integrity(); |
| 593 } | 592 } |
| 594 | 593 |
| 595 Request* Request::clone(ExceptionState& exceptionState) | 594 Request* Request::clone(ScriptState* scriptState, ExceptionState& exceptionState
) |
| 596 { | 595 { |
| 597 if (isBodyLocked() || bodyUsed()) { | 596 if (isBodyLocked() || bodyUsed()) { |
| 598 exceptionState.throwTypeError("Request body is already used"); | 597 exceptionState.throwTypeError("Request body is already used"); |
| 599 return nullptr; | 598 return nullptr; |
| 600 } | 599 } |
| 601 | 600 |
| 602 FetchRequestData* request = m_request->clone(getExecutionContext()); | 601 FetchRequestData* request = m_request->clone(scriptState); |
| 603 Headers* headers = Headers::create(request->headerList()); | 602 Headers* headers = Headers::create(request->headerList()); |
| 604 headers->setGuard(m_headers->getGuard()); | 603 headers->setGuard(m_headers->getGuard()); |
| 605 return new Request(getExecutionContext(), request, headers); | 604 return new Request(scriptState, request, headers); |
| 606 } | 605 } |
| 607 | 606 |
| 608 FetchRequestData* Request::passRequestData() | 607 FetchRequestData* Request::passRequestData(ScriptState* scriptState) |
| 609 { | 608 { |
| 610 ASSERT(!bodyUsed()); | 609 ASSERT(!bodyUsed()); |
| 611 return m_request->pass(getExecutionContext()); | 610 return m_request->pass(scriptState); |
| 612 } | 611 } |
| 613 | 612 |
| 614 bool Request::hasBody() const | 613 bool Request::hasBody() const |
| 615 { | 614 { |
| 616 return bodyBuffer(); | 615 return bodyBuffer(); |
| 617 } | 616 } |
| 618 | 617 |
| 619 void Request::stop() | 618 void Request::stop() |
| 620 { | 619 { |
| 621 if (bodyBuffer()) | 620 if (bodyBuffer()) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 646 } | 645 } |
| 647 | 646 |
| 648 DEFINE_TRACE(Request) | 647 DEFINE_TRACE(Request) |
| 649 { | 648 { |
| 650 Body::trace(visitor); | 649 Body::trace(visitor); |
| 651 visitor->trace(m_request); | 650 visitor->trace(m_request); |
| 652 visitor->trace(m_headers); | 651 visitor->trace(m_headers); |
| 653 } | 652 } |
| 654 | 653 |
| 655 } // namespace blink | 654 } // namespace blink |
| OLD | NEW |