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

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 with a Req uest mode as navigate.");
hiroshige 2015/10/30 12:31:30 Making the message here and L177 will be better.
shiva.jm 2015/11/02 12:06:20 Done.
128 return nullptr;
129 }
130 }
131
126 // 15. If |init|'s referrer member is present, run these substeps: 132 // 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 133 // Note that JS null and undefined are encoded as an empty string and thus
128 // a null string means referrer member is not set. 134 // a null string means referrer member is not set.
129 // 16. If |init|'s referrerPolicy member is present, set |request|'s 135 // 16. If |init|'s referrerPolicy member is present, set |request|'s
130 // referrer policy to it. 136 // referrer policy to it.
131 if (init.isReferrerSet) { 137 // areAnyMembersSet will be True, if any members in RequestInit are set and
hiroshige 2015/10/30 12:31:30 nit: This comment (L137-138) is not needed. IIUC
yhirano 2015/10/30 13:18:41 - If no member is set on |init| => use |request|'s
shiva.jm 2015/11/02 12:06:20 These comment is needed, as discussed in: https://
shiva.jm 2015/11/02 12:06:20 Done, retained old comment, after line 129 in new
138 // hence the referrer member
139 if (init.areAnyMembersSet) {
132 // 1. Let |referrer| be |init|'s referrer member. 140 // 1. Let |referrer| be |init|'s referrer member.
133 if (init.referrer.referrer.isEmpty()) { 141 if (init.referrer.referrer.isEmpty()) {
134 // 2. if |referrer| is the empty string, set |request|'s referrer to 142 // 2. if |referrer| is the empty string, set |request|'s referrer to
135 // "no-referrer" and terminate these substeps. 143 // "no-referrer" and terminate these substeps.
136 request->setReferrerString(FetchRequestData::noReferrerString()); 144 request->setReferrerString(FetchRequestData::noReferrerString());
137 } else { 145 } else {
138 // 3. Let |parsedReferrer| be the result of parsing |referrer| with 146 // 3. Let |parsedReferrer| be the result of parsing |referrer| with
139 // |baseURL|. 147 // |baseURL|.
140 KURL parsedReferrer = scriptState->executionContext()->completeURL(i nit.referrer.referrer); 148 KURL parsedReferrer = scriptState->executionContext()->completeURL(i nit.referrer.referrer);
141 if (!parsedReferrer.isValid()) { 149 if (!parsedReferrer.isValid()) {
(...skipping 12 matching lines...) Expand all
154 exceptionState.throwTypeError("The origin of '" + init.referrer. referrer + "' should be same as '" + origin->toString() + "'"); 162 exceptionState.throwTypeError("The origin of '" + init.referrer. referrer + "' should be same as '" + origin->toString() + "'");
155 return nullptr; 163 return nullptr;
156 } else { 164 } else {
157 // 7. Set |request|'s referrer to |parsedReferrer|. 165 // 7. Set |request|'s referrer to |parsedReferrer|.
158 request->setReferrerString(AtomicString(parsedReferrer.string()) ); 166 request->setReferrerString(AtomicString(parsedReferrer.string()) );
159 } 167 }
160 } 168 }
161 request->setReferrerPolicy(init.referrer.referrerPolicy); 169 request->setReferrerPolicy(init.referrer.referrerPolicy);
162 } 170 }
163 171
164 172 // "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." 173 // |fallbackMode| otherwise."
174 // "17.If mode is "navigate", throw a TypeError.
hiroshige 2015/10/30 12:31:30 nit: a space between "17." and "If".
shiva.jm 2015/11/02 12:06:20 Done.
167 // "18. If |mode| is non-null, set |request|'s mode to |mode|." 175 // "18. If |mode| is non-null, set |request|'s mode to |mode|."
176 if (init.mode == "navigate") {
177 exceptionState.throwTypeError("Cannot construct a Request with a Request mode as navigate.");
178 return nullptr;
179 }
168 if (init.mode == "same-origin") { 180 if (init.mode == "same-origin") {
169 request->setMode(WebURLRequest::FetchRequestModeSameOrigin); 181 request->setMode(WebURLRequest::FetchRequestModeSameOrigin);
170 } else if (init.mode == "no-cors") { 182 } else if (init.mode == "no-cors") {
171 request->setMode(WebURLRequest::FetchRequestModeNoCORS); 183 request->setMode(WebURLRequest::FetchRequestModeNoCORS);
172 } else if (init.mode == "cors") { 184 } else if (init.mode == "cors") {
173 request->setMode(WebURLRequest::FetchRequestModeCORS); 185 request->setMode(WebURLRequest::FetchRequestModeCORS);
174 } else { 186 } else {
175 if (!inputRequest) 187 if (!inputRequest)
176 request->setMode(WebURLRequest::FetchRequestModeCORS); 188 request->setMode(WebURLRequest::FetchRequestModeCORS);
177 } 189 }
(...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 502 // "The mode attribute's getter must return the value corresponding to the
491 // first matching statement, switching on request's mode:" 503 // first matching statement, switching on request's mode:"
492 switch (m_request->mode()) { 504 switch (m_request->mode()) {
493 case WebURLRequest::FetchRequestModeSameOrigin: 505 case WebURLRequest::FetchRequestModeSameOrigin:
494 return "same-origin"; 506 return "same-origin";
495 case WebURLRequest::FetchRequestModeNoCORS: 507 case WebURLRequest::FetchRequestModeNoCORS:
496 return "no-cors"; 508 return "no-cors";
497 case WebURLRequest::FetchRequestModeCORS: 509 case WebURLRequest::FetchRequestModeCORS:
498 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: 510 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight:
499 return "cors"; 511 return "cors";
512 case WebURLRequest::FetchRequestModeNavigate:
513 return "navigate";
500 } 514 }
501 ASSERT_NOT_REACHED(); 515 ASSERT_NOT_REACHED();
502 return ""; 516 return "";
503 } 517 }
504 518
505 String Request::credentials() const 519 String Request::credentials() const
506 { 520 {
507 // "The credentials attribute's getter must return the value corresponding 521 // "The credentials attribute's getter must return the value corresponding
508 // to the first matching statement, switching on request's credentials 522 // to the first matching statement, switching on request's credentials
509 // mode:" 523 // mode:"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 603 }
590 604
591 DEFINE_TRACE(Request) 605 DEFINE_TRACE(Request)
592 { 606 {
593 Body::trace(visitor); 607 Body::trace(visitor);
594 visitor->trace(m_request); 608 visitor->trace(m_request);
595 visitor->trace(m_headers); 609 visitor->trace(m_headers);
596 } 610 }
597 611
598 } // namespace blink 612 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698