| 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 "The integrity attribute is unsupported in no-cors mode."); | 341 "The integrity attribute is unsupported in no-cors mode."); |
| 342 return nullptr; | 342 return nullptr; |
| 343 } | 343 } |
| 344 // "Set |r|'s Headers object's guard to "request-no-cors"." | 344 // "Set |r|'s Headers object's guard to "request-no-cors"." |
| 345 r->getHeaders()->SetGuard(Headers::kRequestNoCORSGuard); | 345 r->getHeaders()->SetGuard(Headers::kRequestNoCORSGuard); |
| 346 } | 346 } |
| 347 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." | 347 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." |
| 348 if (init.headers) { | 348 if (init.headers) { |
| 349 r->getHeaders()->FillWith(init.headers.Get(), exception_state); | 349 r->getHeaders()->FillWith(init.headers.Get(), exception_state); |
| 350 } else { | 350 } else { |
| 351 ASSERT(headers); | 351 DCHECK(headers); |
| 352 r->getHeaders()->FillWith(headers, exception_state); | 352 r->getHeaders()->FillWith(headers, exception_state); |
| 353 } | 353 } |
| 354 if (exception_state.HadException()) | 354 if (exception_state.HadException()) |
| 355 return nullptr; | 355 return nullptr; |
| 356 | 356 |
| 357 // "If either |init|'s body member is present or |temporaryBody| is | 357 // "If either |init|'s body member is present or |temporaryBody| is |
| 358 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. | 358 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. |
| 359 if (init.body || temporary_body || | 359 if (init.body || temporary_body || |
| 360 request->Credentials() == WebURLRequest::kFetchCredentialsModePassword) { | 360 request->Credentials() == WebURLRequest::kFetchCredentialsModePassword) { |
| 361 if (request->Method() == HTTPNames::GET || | 361 if (request->Method() == HTTPNames::GET || |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 430 } |
| 431 | 431 |
| 432 // "Return |r|." | 432 // "Return |r|." |
| 433 return r; | 433 return r; |
| 434 } | 434 } |
| 435 | 435 |
| 436 Request* Request::Create(ScriptState* script_state, | 436 Request* Request::Create(ScriptState* script_state, |
| 437 const RequestInfo& input, | 437 const RequestInfo& input, |
| 438 const Dictionary& init, | 438 const Dictionary& init, |
| 439 ExceptionState& exception_state) { | 439 ExceptionState& exception_state) { |
| 440 ASSERT(!input.isNull()); | 440 DCHECK(!input.isNull()); |
| 441 if (input.isUSVString()) | 441 if (input.isUSVString()) |
| 442 return Create(script_state, input.getAsUSVString(), init, exception_state); | 442 return Create(script_state, input.getAsUSVString(), init, exception_state); |
| 443 return Create(script_state, input.getAsRequest(), init, exception_state); | 443 return Create(script_state, input.getAsRequest(), init, exception_state); |
| 444 } | 444 } |
| 445 | 445 |
| 446 Request* Request::Create(ScriptState* script_state, | 446 Request* Request::Create(ScriptState* script_state, |
| 447 const String& input, | 447 const String& input, |
| 448 ExceptionState& exception_state) { | 448 ExceptionState& exception_state) { |
| 449 return Create(script_state, input, Dictionary(), exception_state); | 449 return Create(script_state, input, Dictionary(), exception_state); |
| 450 } | 450 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 return "xslt"; | 582 return "xslt"; |
| 583 } | 583 } |
| 584 ASSERT_NOT_REACHED(); | 584 ASSERT_NOT_REACHED(); |
| 585 return ""; | 585 return ""; |
| 586 } | 586 } |
| 587 | 587 |
| 588 String Request::referrer() const { | 588 String Request::referrer() const { |
| 589 // "The referrer attribute's getter must return the empty string if | 589 // "The referrer attribute's getter must return the empty string if |
| 590 // request's referrer is no referrer, "about:client" if request's referrer | 590 // request's referrer is no referrer, "about:client" if request's referrer |
| 591 // is client and request's referrer, serialized, otherwise." | 591 // is client and request's referrer, serialized, otherwise." |
| 592 ASSERT(FetchRequestData::NoReferrerString() == AtomicString()); | 592 DCHECK_EQ(FetchRequestData::NoReferrerString(), AtomicString()); |
| 593 ASSERT(FetchRequestData::ClientReferrerString() == | 593 DCHECK_EQ(FetchRequestData::ClientReferrerString(), |
| 594 AtomicString("about:client")); | 594 AtomicString("about:client")); |
| 595 return request_->ReferrerString(); | 595 return request_->ReferrerString(); |
| 596 } | 596 } |
| 597 | 597 |
| 598 String Request::getReferrerPolicy() const { | 598 String Request::getReferrerPolicy() const { |
| 599 switch (request_->GetReferrerPolicy()) { | 599 switch (request_->GetReferrerPolicy()) { |
| 600 case kReferrerPolicyAlways: | 600 case kReferrerPolicyAlways: |
| 601 return "unsafe-url"; | 601 return "unsafe-url"; |
| 602 case kReferrerPolicyDefault: | 602 case kReferrerPolicyDefault: |
| 603 return ""; | 603 return ""; |
| 604 case kReferrerPolicyNoReferrerWhenDowngrade: | 604 case kReferrerPolicyNoReferrerWhenDowngrade: |
| 605 return "no-referrer-when-downgrade"; | 605 return "no-referrer-when-downgrade"; |
| 606 case kReferrerPolicyNever: | 606 case kReferrerPolicyNever: |
| 607 return "no-referrer"; | 607 return "no-referrer"; |
| 608 case kReferrerPolicyOrigin: | 608 case kReferrerPolicyOrigin: |
| 609 return "origin"; | 609 return "origin"; |
| 610 case kReferrerPolicyOriginWhenCrossOrigin: | 610 case kReferrerPolicyOriginWhenCrossOrigin: |
| 611 return "origin-when-cross-origin"; | 611 return "origin-when-cross-origin"; |
| 612 case kReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin: | 612 case kReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin: |
| 613 ASSERT(RuntimeEnabledFeatures::reducedReferrerGranularityEnabled()); | 613 DCHECK(RuntimeEnabledFeatures::reducedReferrerGranularityEnabled()); |
| 614 return "no-referrer-when-downgrade-origin-when-cross-origin"; | 614 return "no-referrer-when-downgrade-origin-when-cross-origin"; |
| 615 } | 615 } |
| 616 ASSERT_NOT_REACHED(); | 616 ASSERT_NOT_REACHED(); |
| 617 return String(); | 617 return String(); |
| 618 } | 618 } |
| 619 | 619 |
| 620 String Request::mode() const { | 620 String Request::mode() const { |
| 621 // "The mode attribute's getter must return the value corresponding to the | 621 // "The mode attribute's getter must return the value corresponding to the |
| 622 // first matching statement, switching on request's mode:" | 622 // first matching statement, switching on request's mode:" |
| 623 switch (request_->Mode()) { | 623 switch (request_->Mode()) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 } | 699 } |
| 700 | 700 |
| 701 FetchRequestData* request = request_->Clone(script_state); | 701 FetchRequestData* request = request_->Clone(script_state); |
| 702 RefreshBody(script_state); | 702 RefreshBody(script_state); |
| 703 Headers* headers = Headers::Create(request->HeaderList()); | 703 Headers* headers = Headers::Create(request->HeaderList()); |
| 704 headers->SetGuard(headers_->GetGuard()); | 704 headers->SetGuard(headers_->GetGuard()); |
| 705 return new Request(script_state, request, headers); | 705 return new Request(script_state, request, headers); |
| 706 } | 706 } |
| 707 | 707 |
| 708 FetchRequestData* Request::PassRequestData(ScriptState* script_state) { | 708 FetchRequestData* Request::PassRequestData(ScriptState* script_state) { |
| 709 ASSERT(!bodyUsed()); | 709 DCHECK(!bodyUsed()); |
| 710 FetchRequestData* data = request_->Pass(script_state); | 710 FetchRequestData* data = request_->Pass(script_state); |
| 711 RefreshBody(script_state); | 711 RefreshBody(script_state); |
| 712 // |data|'s buffer('s js wrapper) has no retainer, but it's OK because | 712 // |data|'s buffer('s js wrapper) has no retainer, but it's OK because |
| 713 // the only caller is the fetch function and it uses the body buffer | 713 // the only caller is the fetch function and it uses the body buffer |
| 714 // immediately. | 714 // immediately. |
| 715 return data; | 715 return data; |
| 716 } | 716 } |
| 717 | 717 |
| 718 bool Request::HasBody() const { | 718 bool Request::HasBody() const { |
| 719 return BodyBuffer(); | 719 return BodyBuffer(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 .Set(request.As<v8::Object>(), body_buffer); | 764 .Set(request.As<v8::Object>(), body_buffer); |
| 765 } | 765 } |
| 766 | 766 |
| 767 DEFINE_TRACE(Request) { | 767 DEFINE_TRACE(Request) { |
| 768 Body::Trace(visitor); | 768 Body::Trace(visitor); |
| 769 visitor->Trace(request_); | 769 visitor->Trace(request_); |
| 770 visitor->Trace(headers_); | 770 visitor->Trace(headers_); |
| 771 } | 771 } |
| 772 | 772 |
| 773 } // namespace blink | 773 } // namespace blink |
| OLD | NEW |