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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 whose mode is 'navigate' and a non-empty RequestInit."); |
| 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 Loading... |
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 with a Request
Init whose mode member is set as 'navigate'."); |
| 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // "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 |
487 // first matching statement, switching on request's mode:" | 503 // first matching statement, switching on request's mode:" |
488 switch (m_request->mode()) { | 504 switch (m_request->mode()) { |
489 case WebURLRequest::FetchRequestModeSameOrigin: | 505 case WebURLRequest::FetchRequestModeSameOrigin: |
490 return "same-origin"; | 506 return "same-origin"; |
491 case WebURLRequest::FetchRequestModeNoCORS: | 507 case WebURLRequest::FetchRequestModeNoCORS: |
492 return "no-cors"; | 508 return "no-cors"; |
493 case WebURLRequest::FetchRequestModeCORS: | 509 case WebURLRequest::FetchRequestModeCORS: |
494 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: | 510 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: |
495 return "cors"; | 511 return "cors"; |
| 512 case WebURLRequest::FetchRequestModeNavigate: |
| 513 return "navigate"; |
496 } | 514 } |
497 ASSERT_NOT_REACHED(); | 515 ASSERT_NOT_REACHED(); |
498 return ""; | 516 return ""; |
499 } | 517 } |
500 | 518 |
501 String Request::credentials() const | 519 String Request::credentials() const |
502 { | 520 { |
503 // "The credentials attribute's getter must return the value corresponding | 521 // "The credentials attribute's getter must return the value corresponding |
504 // to the first matching statement, switching on request's credentials | 522 // to the first matching statement, switching on request's credentials |
505 // mode:" | 523 // mode:" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 } | 603 } |
586 | 604 |
587 DEFINE_TRACE(Request) | 605 DEFINE_TRACE(Request) |
588 { | 606 { |
589 Body::trace(visitor); | 607 Body::trace(visitor); |
590 visitor->trace(m_request); | 608 visitor->trace(m_request); |
591 visitor->trace(m_headers); | 609 visitor->trace(m_headers); |
592 } | 610 } |
593 | 611 |
594 } // namespace blink | 612 } // namespace blink |
OLD | NEW |