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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 || |
351 request->method() == HTTPNames::HEAD) { | 351 request->method() == HTTPNames::HEAD) { |
352 exceptionState.throwTypeError( | 352 exceptionState.throwTypeError( |
353 "Request with GET/HEAD method cannot have body."); | 353 "Request with GET/HEAD method cannot have body."); |
354 return nullptr; | 354 return nullptr; |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 // TODO(mkwst): See the comment in RequestInit about serializing the attached
credential | 358 // TODO(mkwst): See the comment in RequestInit about serializing the attached |
359 // prior to hitting the Service Worker machinery. | 359 // credential prior to hitting the Service Worker machinery. |
360 if (request->credentials() == WebURLRequest::FetchCredentialsModePassword) { | 360 if (request->credentials() == WebURLRequest::FetchCredentialsModePassword) { |
361 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, | 361 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, |
362 exceptionState); | 362 exceptionState); |
363 | 363 |
364 const OriginAccessEntry accessEntry = | 364 const OriginAccessEntry accessEntry = |
365 OriginAccessEntry(r->url().protocol(), r->url().host(), | 365 OriginAccessEntry(r->url().protocol(), r->url().host(), |
366 OriginAccessEntry::AllowRegisterableDomains); | 366 OriginAccessEntry::AllowRegisterableDomains); |
367 if (accessEntry.matchesDomain(*origin) == | 367 if (accessEntry.matchesDomain(*origin) == |
368 OriginAccessEntry::DoesNotMatchOrigin) { | 368 OriginAccessEntry::DoesNotMatchOrigin) { |
369 exceptionState.throwTypeError( | 369 exceptionState.throwTypeError( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 Request::Request(ScriptState* scriptState, | 490 Request::Request(ScriptState* scriptState, |
491 const WebServiceWorkerRequest& request) | 491 const WebServiceWorkerRequest& request) |
492 : Request(scriptState, FetchRequestData::create(scriptState, request)) {} | 492 : Request(scriptState, FetchRequestData::create(scriptState, request)) {} |
493 | 493 |
494 String Request::method() const { | 494 String Request::method() const { |
495 // "The method attribute's getter must return request's method." | 495 // "The method attribute's getter must return request's method." |
496 return m_request->method(); | 496 return m_request->method(); |
497 } | 497 } |
498 | 498 |
499 KURL Request::url() const { | 499 KURL Request::url() const { |
500 // The url attribute's getter must return request's url, serialized with the e
xclude fragment flag set. | 500 // The url attribute's getter must return request's url, serialized with the |
| 501 // exclude fragment flag set. |
501 if (!m_request->url().hasFragmentIdentifier()) | 502 if (!m_request->url().hasFragmentIdentifier()) |
502 return m_request->url(); | 503 return m_request->url(); |
503 KURL url(m_request->url()); | 504 KURL url(m_request->url()); |
504 url.removeFragmentIdentifier(); | 505 url.removeFragmentIdentifier(); |
505 return url; | 506 return url; |
506 } | 507 } |
507 | 508 |
508 String Request::context() const { | 509 String Request::context() const { |
509 // "The context attribute's getter must return request's context" | 510 // "The context attribute's getter must return request's context" |
510 switch (m_request->context()) { | 511 switch (m_request->context()) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 | 705 |
705 const FetchHeaderList* headerList = m_headers->headerList(); | 706 const FetchHeaderList* headerList = m_headers->headerList(); |
706 for (size_t i = 0, size = headerList->size(); i < size; ++i) { | 707 for (size_t i = 0, size = headerList->size(); i < size; ++i) { |
707 const FetchHeaderList::Header& header = headerList->entry(i); | 708 const FetchHeaderList::Header& header = headerList->entry(i); |
708 webRequest.appendHeader(header.first, header.second); | 709 webRequest.appendHeader(header.first, header.second); |
709 } | 710 } |
710 | 711 |
711 webRequest.setReferrer( | 712 webRequest.setReferrer( |
712 m_request->referrerString(), | 713 m_request->referrerString(), |
713 static_cast<WebReferrerPolicy>(m_request->getReferrerPolicy())); | 714 static_cast<WebReferrerPolicy>(m_request->getReferrerPolicy())); |
714 // FIXME: How can we set isReload properly? What is the correct place to load
it in to the Request object? We should investigate the right way | 715 // FIXME: How can we set isReload properly? What is the correct place to load |
715 // to plumb this information in to here. | 716 // it in to the Request object? We should investigate the right way to plumb |
| 717 // this information in to here. |
716 } | 718 } |
717 | 719 |
718 String Request::mimeType() const { | 720 String Request::mimeType() const { |
719 return m_request->mimeType(); | 721 return m_request->mimeType(); |
720 } | 722 } |
721 | 723 |
722 void Request::refreshBody(ScriptState* scriptState) { | 724 void Request::refreshBody(ScriptState* scriptState) { |
723 v8::Local<v8::Value> bodyBuffer = toV8(this->bodyBuffer(), scriptState); | 725 v8::Local<v8::Value> bodyBuffer = toV8(this->bodyBuffer(), scriptState); |
724 v8::Local<v8::Value> request = toV8(this, scriptState); | 726 v8::Local<v8::Value> request = toV8(this, scriptState); |
725 if (request.IsEmpty()) { | 727 if (request.IsEmpty()) { |
726 // |toV8| can return an empty handle when the worker is terminating. | 728 // |toV8| can return an empty handle when the worker is terminating. |
727 // We don't want the renderer to crash in such cases. | 729 // We don't want the renderer to crash in such cases. |
728 // TODO(yhirano): Delete this block after the graceful shutdown | 730 // TODO(yhirano): Delete this block after the graceful shutdown |
729 // mechanism is introduced. | 731 // mechanism is introduced. |
730 return; | 732 return; |
731 } | 733 } |
732 DCHECK(request->IsObject()); | 734 DCHECK(request->IsObject()); |
733 V8HiddenValue::setHiddenValue( | 735 V8HiddenValue::setHiddenValue( |
734 scriptState, request.As<v8::Object>(), | 736 scriptState, request.As<v8::Object>(), |
735 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); | 737 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); |
736 } | 738 } |
737 | 739 |
738 DEFINE_TRACE(Request) { | 740 DEFINE_TRACE(Request) { |
739 Body::trace(visitor); | 741 Body::trace(visitor); |
740 visitor->trace(m_request); | 742 visitor->trace(m_request); |
741 visitor->trace(m_headers); | 743 visitor->trace(m_headers); |
742 } | 744 } |
743 | 745 |
744 } // namespace blink | 746 } // namespace blink |
OLD | NEW |