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 "bindings/core/v8/V8PrivateProperty.h" | 8 #include "bindings/core/v8/V8PrivateProperty.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" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 if (!request->integrity().isEmpty()) { | 325 if (!request->integrity().isEmpty()) { |
326 exceptionState.throwTypeError( | 326 exceptionState.throwTypeError( |
327 "The integrity attribute is unsupported in no-cors mode."); | 327 "The integrity attribute is unsupported in no-cors mode."); |
328 return nullptr; | 328 return nullptr; |
329 } | 329 } |
330 // "Set |r|'s Headers object's guard to "request-no-cors"." | 330 // "Set |r|'s Headers object's guard to "request-no-cors"." |
331 r->getHeaders()->setGuard(Headers::RequestNoCORSGuard); | 331 r->getHeaders()->setGuard(Headers::RequestNoCORSGuard); |
332 } | 332 } |
333 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." | 333 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." |
334 if (init.headers) { | 334 if (init.headers) { |
335 ASSERT(init.headersDictionary.isUndefinedOrNull()); | 335 DCHECK(init.headersDictionary.isUndefinedOrNull()); |
336 r->getHeaders()->fillWith(init.headers.get(), exceptionState); | 336 r->getHeaders()->fillWith(init.headers.get(), exceptionState); |
337 } else if (!init.headersDictionary.isUndefinedOrNull()) { | 337 } else if (!init.headersDictionary.isUndefinedOrNull()) { |
338 r->getHeaders()->fillWith(init.headersDictionary, exceptionState); | 338 r->getHeaders()->fillWith(init.headersDictionary, exceptionState); |
339 } else { | 339 } else { |
340 ASSERT(headers); | 340 DCHECK(headers); |
341 r->getHeaders()->fillWith(headers, exceptionState); | 341 r->getHeaders()->fillWith(headers, exceptionState); |
342 } | 342 } |
343 if (exceptionState.hadException()) | 343 if (exceptionState.hadException()) |
344 return nullptr; | 344 return nullptr; |
345 | 345 |
346 // "If either |init|'s body member is present or |temporaryBody| is | 346 // "If either |init|'s body member is present or |temporaryBody| is |
347 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. | 347 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. |
348 if (init.body || temporaryBody || | 348 if (init.body || temporaryBody || |
349 request->credentials() == WebURLRequest::FetchCredentialsModePassword) { | 349 request->credentials() == WebURLRequest::FetchCredentialsModePassword) { |
350 if (request->method() == HTTPNames::GET || | 350 if (request->method() == HTTPNames::GET || |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 } | 419 } |
420 | 420 |
421 // "Return |r|." | 421 // "Return |r|." |
422 return r; | 422 return r; |
423 } | 423 } |
424 | 424 |
425 Request* Request::create(ScriptState* scriptState, | 425 Request* Request::create(ScriptState* scriptState, |
426 const RequestInfo& input, | 426 const RequestInfo& input, |
427 const Dictionary& init, | 427 const Dictionary& init, |
428 ExceptionState& exceptionState) { | 428 ExceptionState& exceptionState) { |
429 ASSERT(!input.isNull()); | 429 DCHECK(!input.isNull()); |
430 if (input.isUSVString()) | 430 if (input.isUSVString()) |
431 return create(scriptState, input.getAsUSVString(), init, exceptionState); | 431 return create(scriptState, input.getAsUSVString(), init, exceptionState); |
432 return create(scriptState, input.getAsRequest(), init, exceptionState); | 432 return create(scriptState, input.getAsRequest(), init, exceptionState); |
433 } | 433 } |
434 | 434 |
435 Request* Request::create(ScriptState* scriptState, | 435 Request* Request::create(ScriptState* scriptState, |
436 const String& input, | 436 const String& input, |
437 ExceptionState& exceptionState) { | 437 ExceptionState& exceptionState) { |
438 return create(scriptState, input, Dictionary(), exceptionState); | 438 return create(scriptState, input, Dictionary(), exceptionState); |
439 } | 439 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 return "xslt"; | 570 return "xslt"; |
571 } | 571 } |
572 ASSERT_NOT_REACHED(); | 572 ASSERT_NOT_REACHED(); |
573 return ""; | 573 return ""; |
574 } | 574 } |
575 | 575 |
576 String Request::referrer() const { | 576 String Request::referrer() const { |
577 // "The referrer attribute's getter must return the empty string if | 577 // "The referrer attribute's getter must return the empty string if |
578 // request's referrer is no referrer, "about:client" if request's referrer | 578 // request's referrer is no referrer, "about:client" if request's referrer |
579 // is client and request's referrer, serialized, otherwise." | 579 // is client and request's referrer, serialized, otherwise." |
580 ASSERT(FetchRequestData::noReferrerString() == AtomicString()); | 580 DCHECK(FetchRequestData::noReferrerString() == AtomicString()); |
tkent
2017/04/08 02:29:54
Use DCHECK_EQ if it doesn't cause a build failure.
| |
581 ASSERT(FetchRequestData::clientReferrerString() == | 581 DCHECK(FetchRequestData::clientReferrerString() == |
tkent
2017/04/08 02:29:54
Use DCHECK_EQ if it doesn't cause a build failure.
| |
582 AtomicString("about:client")); | 582 AtomicString("about:client")); |
583 return m_request->referrerString(); | 583 return m_request->referrerString(); |
584 } | 584 } |
585 | 585 |
586 String Request::getReferrerPolicy() const { | 586 String Request::getReferrerPolicy() const { |
587 switch (m_request->getReferrerPolicy()) { | 587 switch (m_request->getReferrerPolicy()) { |
588 case ReferrerPolicyAlways: | 588 case ReferrerPolicyAlways: |
589 return "unsafe-url"; | 589 return "unsafe-url"; |
590 case ReferrerPolicyDefault: | 590 case ReferrerPolicyDefault: |
591 return ""; | 591 return ""; |
592 case ReferrerPolicyNoReferrerWhenDowngrade: | 592 case ReferrerPolicyNoReferrerWhenDowngrade: |
593 return "no-referrer-when-downgrade"; | 593 return "no-referrer-when-downgrade"; |
594 case ReferrerPolicyNever: | 594 case ReferrerPolicyNever: |
595 return "no-referrer"; | 595 return "no-referrer"; |
596 case ReferrerPolicyOrigin: | 596 case ReferrerPolicyOrigin: |
597 return "origin"; | 597 return "origin"; |
598 case ReferrerPolicyOriginWhenCrossOrigin: | 598 case ReferrerPolicyOriginWhenCrossOrigin: |
599 return "origin-when-cross-origin"; | 599 return "origin-when-cross-origin"; |
600 case ReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin: | 600 case ReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin: |
601 ASSERT(RuntimeEnabledFeatures::reducedReferrerGranularityEnabled()); | 601 DCHECK(RuntimeEnabledFeatures::reducedReferrerGranularityEnabled()); |
602 return "no-referrer-when-downgrade-origin-when-cross-origin"; | 602 return "no-referrer-when-downgrade-origin-when-cross-origin"; |
603 } | 603 } |
604 ASSERT_NOT_REACHED(); | 604 ASSERT_NOT_REACHED(); |
605 return String(); | 605 return String(); |
606 } | 606 } |
607 | 607 |
608 String Request::mode() const { | 608 String Request::mode() const { |
609 // "The mode attribute's getter must return the value corresponding to the | 609 // "The mode attribute's getter must return the value corresponding to the |
610 // first matching statement, switching on request's mode:" | 610 // first matching statement, switching on request's mode:" |
611 switch (m_request->mode()) { | 611 switch (m_request->mode()) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 } | 667 } |
668 | 668 |
669 FetchRequestData* request = m_request->clone(scriptState); | 669 FetchRequestData* request = m_request->clone(scriptState); |
670 refreshBody(scriptState); | 670 refreshBody(scriptState); |
671 Headers* headers = Headers::create(request->headerList()); | 671 Headers* headers = Headers::create(request->headerList()); |
672 headers->setGuard(m_headers->getGuard()); | 672 headers->setGuard(m_headers->getGuard()); |
673 return new Request(scriptState, request, headers); | 673 return new Request(scriptState, request, headers); |
674 } | 674 } |
675 | 675 |
676 FetchRequestData* Request::passRequestData(ScriptState* scriptState) { | 676 FetchRequestData* Request::passRequestData(ScriptState* scriptState) { |
677 ASSERT(!bodyUsed()); | 677 DCHECK(!bodyUsed()); |
678 FetchRequestData* data = m_request->pass(scriptState); | 678 FetchRequestData* data = m_request->pass(scriptState); |
679 refreshBody(scriptState); | 679 refreshBody(scriptState); |
680 // |data|'s buffer('s js wrapper) has no retainer, but it's OK because | 680 // |data|'s buffer('s js wrapper) has no retainer, but it's OK because |
681 // the only caller is the fetch function and it uses the body buffer | 681 // the only caller is the fetch function and it uses the body buffer |
682 // immediately. | 682 // immediately. |
683 return data; | 683 return data; |
684 } | 684 } |
685 | 685 |
686 bool Request::hasBody() const { | 686 bool Request::hasBody() const { |
687 return bodyBuffer(); | 687 return bodyBuffer(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 .set(request.As<v8::Object>(), bodyBuffer); | 732 .set(request.As<v8::Object>(), bodyBuffer); |
733 } | 733 } |
734 | 734 |
735 DEFINE_TRACE(Request) { | 735 DEFINE_TRACE(Request) { |
736 Body::trace(visitor); | 736 Body::trace(visitor); |
737 visitor->trace(m_request); | 737 visitor->trace(m_request); |
738 visitor->trace(m_headers); | 738 visitor->trace(m_headers); |
739 } | 739 } |
740 | 740 |
741 } // namespace blink | 741 } // namespace blink |
OLD | NEW |