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