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 "config.h" | 5 #include "config.h" |
6 #include "modules/fetch/Request.h" | 6 #include "modules/fetch/Request.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.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 17 matching lines...) Expand all Loading... | |
28 request->setMethod(original->method()); | 28 request->setMethod(original->method()); |
29 request->setHeaderList(original->headerList()->clone()); | 29 request->setHeaderList(original->headerList()->clone()); |
30 request->setUnsafeRequestFlag(true); | 30 request->setUnsafeRequestFlag(true); |
31 // FIXME: Set client. | 31 // FIXME: Set client. |
32 request->setOrigin(SecurityOrigin::create(context->url())); | 32 request->setOrigin(SecurityOrigin::create(context->url())); |
33 // FIXME: Set ForceOriginHeaderFlag. | 33 // FIXME: Set ForceOriginHeaderFlag. |
34 request->setSameOriginDataURLFlag(true); | 34 request->setSameOriginDataURLFlag(true); |
35 request->mutableReferrer()->setClient(); | 35 request->mutableReferrer()->setClient(); |
36 request->setMode(original->mode()); | 36 request->setMode(original->mode()); |
37 request->setCredentials(original->credentials()); | 37 request->setCredentials(original->credentials()); |
38 request->setRedirect(original->redirect()); | |
38 // FIXME: Set cache mode. | 39 // FIXME: Set cache mode. |
39 // TODO(yhirano): Set redirect mode. | |
40 return request; | 40 return request; |
41 } | 41 } |
42 | 42 |
43 Request* Request::createRequestWithRequestOrString(ExecutionContext* context, Re quest* inputRequest, const String& inputString, const RequestInit& init, Excepti onState& exceptionState) | 43 Request* Request::createRequestWithRequestOrString(ExecutionContext* context, Re quest* inputRequest, const String& inputString, const RequestInit& init, Excepti onState& exceptionState) |
44 { | 44 { |
45 // "1. Let |temporaryBody| be null." | 45 // "1. Let |temporaryBody| be null." |
46 RefPtr<BlobDataHandle> temporaryBody; | 46 RefPtr<BlobDataHandle> temporaryBody; |
47 | 47 |
48 // "2. If |input| is a Request object and |input|'s body is non-null, run | 48 // "2. If |input| is a Request object and |input|'s body is non-null, run |
49 // these substeps:" | 49 // these substeps:" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); | 133 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); |
134 } else { | 134 } else { |
135 if (!inputRequest) | 135 if (!inputRequest) |
136 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); | 136 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); |
137 } | 137 } |
138 | 138 |
139 // FIXME: "14. Let |cache| be |init|'s cache member if it is present, and | 139 // FIXME: "14. Let |cache| be |init|'s cache member if it is present, and |
140 // |fallbackCache| otherwise." | 140 // |fallbackCache| otherwise." |
141 // FIXME: "15. If |cache| is non-null, set |request|'s cache mode to | 141 // FIXME: "15. If |cache| is non-null, set |request|'s cache mode to |
142 // |cache|." | 142 // |cache|." |
143 | |
143 // TODO(yhirano): "16. If |init|'s redirect member is present and its is | 144 // TODO(yhirano): "16. If |init|'s redirect member is present and its is |
yhirano
2015/05/25 06:30:52
Please delete this TODO as you implement it.
shiva.jm
2015/05/25 12:01:57
Done.
| |
144 // manual, throw a TypeError." | 145 // manual, throw a TypeError." |
146 if (init.redirect == "manual") { | |
147 exceptionState.throwTypeError("'" + init.redirect + "' manual redirect m ethod is unsupported."); | |
148 return nullptr; | |
149 } | |
150 | |
145 // TODO(yhirano): "17. Let |redirect| be |init|'s redirect member if it is | 151 // TODO(yhirano): "17. Let |redirect| be |init|'s redirect member if it is |
yhirano
2015/05/25 06:30:53
ditto
shiva.jm
2015/05/25 12:01:57
Done.
| |
146 // present, and |fallbackRedirect| otherwise." | 152 // present, and |fallbackRedirect| otherwise." |
147 // TODO(yhirano): "18 If |redirect| is non-null, set |request|'s redirect | 153 // TODO(yhirano): "18 If |redirect| is non-null, set |request|'s redirect |
yhirano
2015/05/25 06:30:52
ditto
shiva.jm
2015/05/25 12:01:57
Done.
| |
148 // mode to |redirect|." | 154 // mode to |redirect|." |
149 // TODO(yhirano): "19 If |request|'s redirect mode is manual, set it to | 155 // TODO(yhirano): "19 If |request|'s redirect mode is manual, set it to |
yhirano
2015/05/25 06:30:52
ditto
shiva.jm
2015/05/25 12:01:57
Done.
| |
150 // follow." | 156 // follow." |
157 if (init.redirect == "follow") { | |
158 request->setRedirect(WebURLRequest::FetchRedirectModeFollow); | |
159 } else if (init.redirect == "manual") { | |
160 request->setRedirect(WebURLRequest::FetchRedirectModeFollow); | |
161 } else if (init.redirect == "error") { | |
162 request->setRedirect(WebURLRequest::FetchRedirectModeError); | |
163 } else { | |
164 if (!inputRequest) | |
165 request->setRedirect(WebURLRequest::FetchRedirectModeFollow); | |
166 } | |
151 | 167 |
152 // "20. If |init|'s method member is present, let |method| be it and run | 168 // "20. If |init|'s method member is present, let |method| be it and run |
153 // these substeps:" | 169 // these substeps:" |
154 if (!init.method.isNull()) { | 170 if (!init.method.isNull()) { |
155 // "1. If |method| is not a method or method is a forbidden method, | 171 // "1. If |method| is not a method or method is a forbidden method, |
156 // throw a TypeError." | 172 // throw a TypeError." |
157 if (!isValidHTTPToken(init.method)) { | 173 if (!isValidHTTPToken(init.method)) { |
158 exceptionState.throwTypeError("'" + init.method + "' is not a valid HTTP method."); | 174 exceptionState.throwTypeError("'" + init.method + "' is not a valid HTTP method."); |
159 return nullptr; | 175 return nullptr; |
160 } | 176 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 return "omit"; | 459 return "omit"; |
444 case WebURLRequest::FetchCredentialsModeSameOrigin: | 460 case WebURLRequest::FetchCredentialsModeSameOrigin: |
445 return "same-origin"; | 461 return "same-origin"; |
446 case WebURLRequest::FetchCredentialsModeInclude: | 462 case WebURLRequest::FetchCredentialsModeInclude: |
447 return "include"; | 463 return "include"; |
448 } | 464 } |
449 ASSERT_NOT_REACHED(); | 465 ASSERT_NOT_REACHED(); |
450 return ""; | 466 return ""; |
451 } | 467 } |
452 | 468 |
469 String Request::redirect() const | |
470 { | |
471 // "The redirect attribute's getter must return request's redirect mode." | |
472 switch (m_request->redirect()) { | |
473 case WebURLRequest::FetchRedirectModeFollow: | |
474 return "follow"; | |
475 case WebURLRequest::FetchRedirectModeError: | |
476 return "error"; | |
477 case WebURLRequest::FetchRedirectModeManual: | |
478 return "manual"; | |
479 } | |
480 ASSERT_NOT_REACHED(); | |
481 return ""; | |
482 } | |
483 | |
453 Request* Request::clone(ExceptionState& exceptionState) const | 484 Request* Request::clone(ExceptionState& exceptionState) const |
454 { | 485 { |
455 if (bodyUsed()) { | 486 if (bodyUsed()) { |
456 exceptionState.throwTypeError("Request body is already used"); | 487 exceptionState.throwTypeError("Request body is already used"); |
457 return nullptr; | 488 return nullptr; |
458 } | 489 } |
459 | 490 |
460 FetchRequestData* request = m_request->clone(); | 491 FetchRequestData* request = m_request->clone(); |
461 if (blobDataHandle() && isBodyConsumed()) { | 492 if (blobDataHandle() && isBodyConsumed()) { |
462 // Currently the only methods that can consume body data without | 493 // Currently the only methods that can consume body data without |
(...skipping 17 matching lines...) Expand all Loading... | |
480 { | 511 { |
481 ASSERT(!bodyUsed()); | 512 ASSERT(!bodyUsed()); |
482 lockBody(PassBody); | 513 lockBody(PassBody); |
483 return m_request->pass(); | 514 return m_request->pass(); |
484 } | 515 } |
485 | 516 |
486 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const | 517 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const |
487 { | 518 { |
488 webRequest.setMethod(method()); | 519 webRequest.setMethod(method()); |
489 webRequest.setRequestContext(m_request->context()); | 520 webRequest.setRequestContext(m_request->context()); |
521 webRequest.setRedirectMode(m_request->redirect()); | |
490 // This strips off the fragment part. | 522 // This strips off the fragment part. |
491 webRequest.setURL(url()); | 523 webRequest.setURL(url()); |
492 | 524 |
493 const FetchHeaderList* headerList = m_headers->headerList(); | 525 const FetchHeaderList* headerList = m_headers->headerList(); |
494 for (size_t i = 0, size = headerList->size(); i < size; ++i) { | 526 for (size_t i = 0, size = headerList->size(); i < size; ++i) { |
495 const FetchHeaderList::Header& header = headerList->entry(i); | 527 const FetchHeaderList::Header& header = headerList->entry(i); |
496 webRequest.appendHeader(header.first, header.second); | 528 webRequest.appendHeader(header.first, header.second); |
497 } | 529 } |
498 | 530 |
499 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); | 531 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); |
(...skipping 29 matching lines...) Expand all Loading... | |
529 } | 561 } |
530 | 562 |
531 DEFINE_TRACE(Request) | 563 DEFINE_TRACE(Request) |
532 { | 564 { |
533 Body::trace(visitor); | 565 Body::trace(visitor); |
534 visitor->trace(m_request); | 566 visitor->trace(m_request); |
535 visitor->trace(m_headers); | 567 visitor->trace(m_headers); |
536 } | 568 } |
537 | 569 |
538 } // namespace blink | 570 } // namespace blink |
OLD | NEW |