Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: Source/modules/fetch/Request.cpp

Issue 1143083002: Implement request's redirect mode and RequestRedirect for Fetch (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/fetch/Request.h ('k') | Source/modules/fetch/Request.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
32 DOMWrapperWorld& world = scriptState->world(); 32 DOMWrapperWorld& world = scriptState->world();
33 if (world.isIsolatedWorld()) 33 if (world.isIsolatedWorld())
34 request->setOrigin(world.isolatedWorldSecurityOrigin()); 34 request->setOrigin(world.isolatedWorldSecurityOrigin());
35 else 35 else
36 request->setOrigin(scriptState->executionContext()->securityOrigin()); 36 request->setOrigin(scriptState->executionContext()->securityOrigin());
37 // FIXME: Set ForceOriginHeaderFlag. 37 // FIXME: Set ForceOriginHeaderFlag.
38 request->setSameOriginDataURLFlag(true); 38 request->setSameOriginDataURLFlag(true);
39 request->mutableReferrer()->setClient(); 39 request->mutableReferrer()->setClient();
40 request->setMode(original->mode()); 40 request->setMode(original->mode());
41 request->setCredentials(original->credentials()); 41 request->setCredentials(original->credentials());
42 request->setRedirect(original->redirect());
42 // FIXME: Set cache mode. 43 // FIXME: Set cache mode.
43 // TODO(yhirano): Set redirect mode.
44 return request; 44 return request;
45 } 45 }
46 46
47 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, const RequestInit& init, Exceptio nState& exceptionState) 47 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, const RequestInit& init, Exceptio nState& exceptionState)
48 { 48 {
49 // "1. Let |temporaryBody| be null." 49 // "1. Let |temporaryBody| be null."
50 RefPtr<BlobDataHandle> temporaryBody; 50 RefPtr<BlobDataHandle> temporaryBody;
51 51
52 // "2. If |input| is a Request object and |input|'s body is non-null, run 52 // "2. If |input| is a Request object and |input|'s body is non-null, run
53 // these substeps:" 53 // these substeps:"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); 137 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude);
138 } else { 138 } else {
139 if (!inputRequest) 139 if (!inputRequest)
140 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); 140 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit);
141 } 141 }
142 142
143 // FIXME: "14. Let |cache| be |init|'s cache member if it is present, and 143 // FIXME: "14. Let |cache| be |init|'s cache member if it is present, and
144 // |fallbackCache| otherwise." 144 // |fallbackCache| otherwise."
145 // FIXME: "15. If |cache| is non-null, set |request|'s cache mode to 145 // FIXME: "15. If |cache| is non-null, set |request|'s cache mode to
146 // |cache|." 146 // |cache|."
147 // TODO(yhirano): "16. If |init|'s redirect member is present and its is 147
148 // manual, throw a TypeError." 148 if (init.redirect == "manual") {
149 // TODO(yhirano): "17. Let |redirect| be |init|'s redirect member if it is 149 exceptionState.throwTypeError("'" + init.redirect + "' manual redirect m ethod is unsupported.");
150 // present, and |fallbackRedirect| otherwise." 150 return nullptr;
151 // TODO(yhirano): "18 If |redirect| is non-null, set |request|'s redirect 151 }
152 // mode to |redirect|." 152
153 // TODO(yhirano): "19 If |request|'s redirect mode is manual, set it to 153 if (init.redirect == "follow") {
154 // follow." 154 request->setRedirect(WebURLRequest::FetchRedirectModeFollow);
155 } else if (init.redirect == "manual") {
156 request->setRedirect(WebURLRequest::FetchRedirectModeFollow);
157 } else if (init.redirect == "error") {
158 request->setRedirect(WebURLRequest::FetchRedirectModeError);
159 } else {
160 if (!inputRequest)
161 request->setRedirect(WebURLRequest::FetchRedirectModeFollow);
162 }
155 163
156 // "20. If |init|'s method member is present, let |method| be it and run 164 // "20. If |init|'s method member is present, let |method| be it and run
157 // these substeps:" 165 // these substeps:"
158 if (!init.method.isNull()) { 166 if (!init.method.isNull()) {
159 // "1. If |method| is not a method or method is a forbidden method, 167 // "1. If |method| is not a method or method is a forbidden method,
160 // throw a TypeError." 168 // throw a TypeError."
161 if (!isValidHTTPToken(init.method)) { 169 if (!isValidHTTPToken(init.method)) {
162 exceptionState.throwTypeError("'" + init.method + "' is not a valid HTTP method."); 170 exceptionState.throwTypeError("'" + init.method + "' is not a valid HTTP method.");
163 return nullptr; 171 return nullptr;
164 } 172 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return "omit"; 455 return "omit";
448 case WebURLRequest::FetchCredentialsModeSameOrigin: 456 case WebURLRequest::FetchCredentialsModeSameOrigin:
449 return "same-origin"; 457 return "same-origin";
450 case WebURLRequest::FetchCredentialsModeInclude: 458 case WebURLRequest::FetchCredentialsModeInclude:
451 return "include"; 459 return "include";
452 } 460 }
453 ASSERT_NOT_REACHED(); 461 ASSERT_NOT_REACHED();
454 return ""; 462 return "";
455 } 463 }
456 464
465 String Request::redirect() const
466 {
467 // "The redirect attribute's getter must return request's redirect mode."
468 switch (m_request->redirect()) {
469 case WebURLRequest::FetchRedirectModeFollow:
470 return "follow";
471 case WebURLRequest::FetchRedirectModeError:
472 return "error";
473 case WebURLRequest::FetchRedirectModeManual:
474 return "manual";
475 }
476 ASSERT_NOT_REACHED();
477 return "";
478 }
479
457 Request* Request::clone(ExceptionState& exceptionState) const 480 Request* Request::clone(ExceptionState& exceptionState) const
458 { 481 {
459 if (bodyUsed()) { 482 if (bodyUsed()) {
460 exceptionState.throwTypeError("Request body is already used"); 483 exceptionState.throwTypeError("Request body is already used");
461 return nullptr; 484 return nullptr;
462 } 485 }
463 486
464 FetchRequestData* request = m_request->clone(); 487 FetchRequestData* request = m_request->clone();
465 if (blobDataHandle() && isBodyConsumed()) { 488 if (blobDataHandle() && isBodyConsumed()) {
466 // Currently the only methods that can consume body data without 489 // Currently the only methods that can consume body data without
(...skipping 17 matching lines...) Expand all
484 { 507 {
485 ASSERT(!bodyUsed()); 508 ASSERT(!bodyUsed());
486 lockBody(PassBody); 509 lockBody(PassBody);
487 return m_request->pass(); 510 return m_request->pass();
488 } 511 }
489 512
490 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const 513 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const
491 { 514 {
492 webRequest.setMethod(method()); 515 webRequest.setMethod(method());
493 webRequest.setRequestContext(m_request->context()); 516 webRequest.setRequestContext(m_request->context());
517 webRequest.setRedirectMode(m_request->redirect());
494 // This strips off the fragment part. 518 // This strips off the fragment part.
495 webRequest.setURL(url()); 519 webRequest.setURL(url());
496 520
497 const FetchHeaderList* headerList = m_headers->headerList(); 521 const FetchHeaderList* headerList = m_headers->headerList();
498 for (size_t i = 0, size = headerList->size(); i < size; ++i) { 522 for (size_t i = 0, size = headerList->size(); i < size; ++i) {
499 const FetchHeaderList::Header& header = headerList->entry(i); 523 const FetchHeaderList::Header& header = headerList->entry(i);
500 webRequest.appendHeader(header.first, header.second); 524 webRequest.appendHeader(header.first, header.second);
501 } 525 }
502 526
503 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); 527 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy));
(...skipping 29 matching lines...) Expand all
533 } 557 }
534 558
535 DEFINE_TRACE(Request) 559 DEFINE_TRACE(Request)
536 { 560 {
537 Body::trace(visitor); 561 Body::trace(visitor);
538 visitor->trace(m_request); 562 visitor->trace(m_request);
539 visitor->trace(m_headers); 563 visitor->trace(m_headers);
540 } 564 }
541 565
542 } // namespace blink 566 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/fetch/Request.h ('k') | Source/modules/fetch/Request.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698