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

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

Issue 1391583002: Introduce "navigate" mode in Requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 // TODO(yhirano): "3. If |parsedURL| includes credentials, throw a 114 // TODO(yhirano): "3. If |parsedURL| includes credentials, throw a
115 // TypeError." 115 // TypeError."
116 // "4. Set |request|'s url to |parsedURL|." 116 // "4. Set |request|'s url to |parsedURL|."
117 request->setURL(parsedURL); 117 request->setURL(parsedURL);
118 // "5. Set |fallbackMode| to CORS." 118 // "5. Set |fallbackMode| to CORS."
119 // "6. Set |fallbackCredentials| to omit." 119 // "6. Set |fallbackCredentials| to omit."
120 // We don't use fallback values. We set these flags directly in below. 120 // We don't use fallback values. We set these flags directly in below.
121 } 121 }
122 122
123 // 14. If any of |init|'s members are present, set |request|'s referrer 123 // "14. If any of |init|'s members are present, run these substeps:"
124 // to client, and |request|'s referrer policy to the empty string. 124 if (init.areAnyMembersSet) {
125 // => RequestInit::RequestInit. 125 // "1. If |request|'s |mode| is "navigate", throw a TypeError."
126 if (request->mode() == WebURLRequest::FetchRequestModeNavigate) {
127 exceptionState.throwTypeError("Cannot construct a Request from a Req uest having mode set as 'navigate' with RequestInit members being set and mode ' navigate' cannot be specified in Request constructor.");
yhirano 2015/11/06 07:50:24 [optional] "Cannot construct a Request with a Requ
shiva.jm 2015/11/09 07:15:47 Done.
128 return nullptr;
129 }
130 // "2. Unset |request|'s omit-Origin-header flag."
131 // "3. Set |request|'s referrer to "client"."
132 // "4. Set |request|'s referrer policy to the empty string."
133 // => RequestInit::RequestInit.
134 }
135
126 // 15. If |init|'s referrer member is present, run these substeps: 136 // 15. If |init|'s referrer member is present, run these substeps:
127 // Note that JS null and undefined are encoded as an empty string and thus 137 // Note that JS null and undefined are encoded as an empty string and thus
128 // a null string means referrer member is not set. 138 // a null string means referrer member is not set.
129 // 16. If |init|'s referrerPolicy member is present, set |request|'s 139 // 16. If |init|'s referrerPolicy member is present, set |request|'s
130 // referrer policy to it. 140 // referrer policy to it.
131 if (init.isReferrerSet) { 141 // areAnyMembersSet will be True, if any members in RequestInit are set and
142 // hence the referrer member
143 if (init.areAnyMembersSet) {
132 // 1. Let |referrer| be |init|'s referrer member. 144 // 1. Let |referrer| be |init|'s referrer member.
133 if (init.referrer.referrer.isEmpty()) { 145 if (init.referrer.referrer.isEmpty()) {
134 // 2. if |referrer| is the empty string, set |request|'s referrer to 146 // 2. if |referrer| is the empty string, set |request|'s referrer to
135 // "no-referrer" and terminate these substeps. 147 // "no-referrer" and terminate these substeps.
136 request->setReferrerString(FetchRequestData::noReferrerString()); 148 request->setReferrerString(FetchRequestData::noReferrerString());
137 } else { 149 } else {
138 // 3. Let |parsedReferrer| be the result of parsing |referrer| with 150 // 3. Let |parsedReferrer| be the result of parsing |referrer| with
139 // |baseURL|. 151 // |baseURL|.
140 KURL parsedReferrer = scriptState->executionContext()->completeURL(i nit.referrer.referrer); 152 KURL parsedReferrer = scriptState->executionContext()->completeURL(i nit.referrer.referrer);
141 if (!parsedReferrer.isValid()) { 153 if (!parsedReferrer.isValid()) {
(...skipping 12 matching lines...) Expand all
154 exceptionState.throwTypeError("The origin of '" + init.referrer. referrer + "' should be same as '" + origin->toString() + "'"); 166 exceptionState.throwTypeError("The origin of '" + init.referrer. referrer + "' should be same as '" + origin->toString() + "'");
155 return nullptr; 167 return nullptr;
156 } else { 168 } else {
157 // 7. Set |request|'s referrer to |parsedReferrer|. 169 // 7. Set |request|'s referrer to |parsedReferrer|.
158 request->setReferrerString(AtomicString(parsedReferrer.string()) ); 170 request->setReferrerString(AtomicString(parsedReferrer.string()) );
159 } 171 }
160 } 172 }
161 request->setReferrerPolicy(init.referrer.referrerPolicy); 173 request->setReferrerPolicy(init.referrer.referrerPolicy);
162 } 174 }
163 175
164 176 // "16. Let |mode| be |init|'s mode member if it is present, and
165 // "17. Let |mode| be |init|'s mode member if it is present, and
166 // |fallbackMode| otherwise." 177 // |fallbackMode| otherwise."
178 // "17. If |mode| is "navigate", throw a TypeError.
167 // "18. If |mode| is non-null, set |request|'s mode to |mode|." 179 // "18. If |mode| is non-null, set |request|'s mode to |mode|."
180 if (init.mode == "navigate") {
181 exceptionState.throwTypeError("Cannot construct a Request from a Request having mode set as 'navigate' with RequestInit members being set and mode 'navi gate' cannot be specified in Request constructor.");
yhirano 2015/11/06 07:50:24 "Cannot construct a Request with a RequestInit who
shiva.jm 2015/11/09 07:15:47 Done.
182 return nullptr;
183 }
168 if (init.mode == "same-origin") { 184 if (init.mode == "same-origin") {
169 request->setMode(WebURLRequest::FetchRequestModeSameOrigin); 185 request->setMode(WebURLRequest::FetchRequestModeSameOrigin);
170 } else if (init.mode == "no-cors") { 186 } else if (init.mode == "no-cors") {
171 request->setMode(WebURLRequest::FetchRequestModeNoCORS); 187 request->setMode(WebURLRequest::FetchRequestModeNoCORS);
172 } else if (init.mode == "cors") { 188 } else if (init.mode == "cors") {
173 request->setMode(WebURLRequest::FetchRequestModeCORS); 189 request->setMode(WebURLRequest::FetchRequestModeCORS);
174 } else { 190 } else {
175 if (!inputRequest) 191 if (!inputRequest)
176 request->setMode(WebURLRequest::FetchRequestModeCORS); 192 request->setMode(WebURLRequest::FetchRequestModeCORS);
177 } 193 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // "The mode attribute's getter must return the value corresponding to the 506 // "The mode attribute's getter must return the value corresponding to the
491 // first matching statement, switching on request's mode:" 507 // first matching statement, switching on request's mode:"
492 switch (m_request->mode()) { 508 switch (m_request->mode()) {
493 case WebURLRequest::FetchRequestModeSameOrigin: 509 case WebURLRequest::FetchRequestModeSameOrigin:
494 return "same-origin"; 510 return "same-origin";
495 case WebURLRequest::FetchRequestModeNoCORS: 511 case WebURLRequest::FetchRequestModeNoCORS:
496 return "no-cors"; 512 return "no-cors";
497 case WebURLRequest::FetchRequestModeCORS: 513 case WebURLRequest::FetchRequestModeCORS:
498 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: 514 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight:
499 return "cors"; 515 return "cors";
516 case WebURLRequest::FetchRequestModeNavigate:
517 return "navigate";
500 } 518 }
501 ASSERT_NOT_REACHED(); 519 ASSERT_NOT_REACHED();
502 return ""; 520 return "";
503 } 521 }
504 522
505 String Request::credentials() const 523 String Request::credentials() const
506 { 524 {
507 // "The credentials attribute's getter must return the value corresponding 525 // "The credentials attribute's getter must return the value corresponding
508 // to the first matching statement, switching on request's credentials 526 // to the first matching statement, switching on request's credentials
509 // mode:" 527 // mode:"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 607 }
590 608
591 DEFINE_TRACE(Request) 609 DEFINE_TRACE(Request)
592 { 610 {
593 Body::trace(visitor); 611 Body::trace(visitor);
594 visitor->trace(m_request); 612 visitor->trace(m_request);
595 visitor->trace(m_headers); 613 visitor->trace(m_headers);
596 } 614 }
597 615
598 } // namespace blink 616 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698