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, request); | 271 Request* r = Request::create(scriptState->getExecutionContext(), 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(scriptState, init.body.release()); | 346 temporaryBody = new BodyStreamBuffer(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(scriptState, cre
ateFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); | 366 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC
onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
367 // "Set |input|'s disturbed flag." | 367 // "Set |input|'s disturbed flag." |
368 inputRequest->bodyBuffer()->setDisturbed(); | 368 inputRequest->bodyBuffer()->stream()->setIsDisturbed(); |
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(ScriptState* scriptState, FetchRequestData* request) | 405 Request* Request::create(ExecutionContext* context, FetchRequestData* request) |
406 { | 406 { |
407 return new Request(scriptState, request); | 407 return new Request(context, request); |
408 } | 408 } |
409 | 409 |
410 Request* Request::create(ScriptState* scriptState, const WebServiceWorkerRequest
& webRequest) | 410 Request::Request(ExecutionContext* context, FetchRequestData* request) |
411 { | 411 : Body(context) |
412 return new Request(scriptState, webRequest); | |
413 } | |
414 | |
415 Request::Request(ScriptState* scriptState, FetchRequestData* request, Headers* h
eaders) | |
416 : Body(scriptState->getExecutionContext()) | |
417 , m_request(request) | 412 , m_request(request) |
418 , m_headers(headers) | 413 , m_headers(Headers::create(m_request->headerList())) |
419 { | |
420 } | |
421 | |
422 Request::Request(ScriptState* scriptState, FetchRequestData* request) | |
423 : Request(scriptState, request, Headers::create(request->headerList())) | |
424 { | 414 { |
425 m_headers->setGuard(Headers::RequestGuard); | 415 m_headers->setGuard(Headers::RequestGuard); |
426 } | 416 } |
427 | 417 |
428 Request::Request(ScriptState* scriptState, const WebServiceWorkerRequest& reques
t) | 418 Request::Request(ExecutionContext* context, FetchRequestData* request, Headers*
headers) |
429 : Request(scriptState, FetchRequestData::create(scriptState, request)) | 419 : Body(context) , m_request(request) , m_headers(headers) {} |
| 420 |
| 421 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques
t& webRequest) |
430 { | 422 { |
| 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); |
431 } | 432 } |
432 | 433 |
433 String Request::method() const | 434 String Request::method() const |
434 { | 435 { |
435 // "The method attribute's getter must return request's method." | 436 // "The method attribute's getter must return request's method." |
436 return m_request->method(); | 437 return m_request->method(); |
437 } | 438 } |
438 | 439 |
439 KURL Request::url() const | 440 KURL Request::url() const |
440 { | 441 { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 } | 585 } |
585 ASSERT_NOT_REACHED(); | 586 ASSERT_NOT_REACHED(); |
586 return ""; | 587 return ""; |
587 } | 588 } |
588 | 589 |
589 String Request::integrity() const | 590 String Request::integrity() const |
590 { | 591 { |
591 return m_request->integrity(); | 592 return m_request->integrity(); |
592 } | 593 } |
593 | 594 |
594 Request* Request::clone(ScriptState* scriptState, ExceptionState& exceptionState
) | 595 Request* Request::clone(ExceptionState& exceptionState) |
595 { | 596 { |
596 if (isBodyLocked() || bodyUsed()) { | 597 if (isBodyLocked() || bodyUsed()) { |
597 exceptionState.throwTypeError("Request body is already used"); | 598 exceptionState.throwTypeError("Request body is already used"); |
598 return nullptr; | 599 return nullptr; |
599 } | 600 } |
600 | 601 |
601 FetchRequestData* request = m_request->clone(scriptState); | 602 FetchRequestData* request = m_request->clone(getExecutionContext()); |
602 Headers* headers = Headers::create(request->headerList()); | 603 Headers* headers = Headers::create(request->headerList()); |
603 headers->setGuard(m_headers->getGuard()); | 604 headers->setGuard(m_headers->getGuard()); |
604 return new Request(scriptState, request, headers); | 605 return new Request(getExecutionContext(), request, headers); |
605 } | 606 } |
606 | 607 |
607 FetchRequestData* Request::passRequestData(ScriptState* scriptState) | 608 FetchRequestData* Request::passRequestData() |
608 { | 609 { |
609 ASSERT(!bodyUsed()); | 610 ASSERT(!bodyUsed()); |
610 return m_request->pass(scriptState); | 611 return m_request->pass(getExecutionContext()); |
611 } | 612 } |
612 | 613 |
613 bool Request::hasBody() const | 614 bool Request::hasBody() const |
614 { | 615 { |
615 return bodyBuffer(); | 616 return bodyBuffer(); |
616 } | 617 } |
617 | 618 |
618 void Request::stop() | 619 void Request::stop() |
619 { | 620 { |
620 if (bodyBuffer()) | 621 if (bodyBuffer()) |
(...skipping 24 matching lines...) Expand all Loading... |
645 } | 646 } |
646 | 647 |
647 DEFINE_TRACE(Request) | 648 DEFINE_TRACE(Request) |
648 { | 649 { |
649 Body::trace(visitor); | 650 Body::trace(visitor); |
650 visitor->trace(m_request); | 651 visitor->trace(m_request); |
651 visitor->trace(m_headers); | 652 visitor->trace(m_headers); |
652 } | 653 } |
653 | 654 |
654 } // namespace blink | 655 } // namespace blink |
OLD | NEW |