Chromium Code Reviews| 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, run these substeps:" | 123 // "If any of |init|'s members are present, run these substeps:" |
| 124 if (init.areAnyMembersSet) { | 124 if (init.areAnyMembersSet) { |
| 125 // "1. If |request|'s |mode| is "navigate", throw a TypeError." | 125 // "1. If |request|'s |mode| is "navigate", throw a TypeError." |
| 126 if (request->mode() == WebURLRequest::FetchRequestModeNavigate) { | 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."); | 127 exceptionState.throwTypeError("Cannot construct a Request with a Req uest whose mode is 'navigate' and a non-empty RequestInit."); |
| 128 return nullptr; | 128 return nullptr; |
| 129 } | 129 } |
| 130 // "2. Unset |request|'s omit-Origin-header flag." | 130 |
| 131 // "3. Set |request|'s referrer to "client"." | 131 // TODO(yhirano): Implement the following substep: |
| 132 // "4. Set |request|'s referrer policy to the empty string." | 132 // "Unset |request|'s omit-Origin-header flag." |
| 133 // => RequestInit::RequestInit. | 133 |
| 134 // The step "Set |request|'s referrer to "client"." is performed by the | |
| 135 // code below as follows: | |
| 136 // - |init.referrer.referrer| gets initialized by the RequestInit | |
| 137 // constructor to "about:client" when any of |options|'s member are | |
|
yhirano
2015/11/17 09:31:55
members
tyoshino (SeeGerritForStatus)
2015/11/18 13:42:51
Done.
| |
| 138 // present. | |
| 139 // - The code below does the equivalent as the step specified in the | |
| 140 // spec by processing the "about:client". | |
| 141 | |
| 142 // TODO(yhirano): Implement the following substep: | |
| 143 // "Set |request|'s referrer policy to the empty string." | |
|
yhirano
2015/11/17 09:31:54
This is implemented :)
tyoshino (SeeGerritForStatus)
2015/11/18 13:42:51
Fixed
| |
| 134 } | 144 } |
| 135 | 145 |
| 136 // 15. If |init|'s referrer member is present, run these substeps: | 146 // The following if-clause performs the following two steps: |
| 137 // Note that JS null and undefined are encoded as an empty string and thus | 147 // - "If |init|'s referrer member is present, run these substeps:" |
| 148 // - "If |init|'s referrerPolicy member is present, set |request|'s | |
|
yhirano
2015/11/17 09:31:54
This is not implemented :)
tyoshino (SeeGerritForStatus)
2015/11/18 13:42:51
Fixed
| |
| 149 // referrer policy to it." | |
| 150 // | |
| 151 // The condition "if any of |init|'s members are present" | |
| 152 // (areAnyMembersSet) is used for the if-clause instead of conditions | |
| 153 // indicating presence of each member as specified in the spec. This is to | |
| 154 // perform the substeps in the previous step together here. | |
| 155 | |
| 156 // Note that JS null and undefined are encoded as an empty string, and thus | |
|
yhirano
2015/11/17 09:31:54
redundant?
tyoshino (SeeGerritForStatus)
2015/11/18 13:42:51
Removed
| |
| 138 // a null string means referrer member is not set. | 157 // a null string means referrer member is not set. |
| 139 // 16. If |init|'s referrerPolicy member is present, set |request|'s | 158 |
| 140 // referrer policy to it. | |
| 141 // areAnyMembersSet will be True, if any members in RequestInit are set and | |
| 142 // hence the referrer member | |
| 143 if (init.areAnyMembersSet) { | 159 if (init.areAnyMembersSet) { |
| 144 // 1. Let |referrer| be |init|'s referrer member. | 160 // Nothing to do for the step "Let |referrer| be |init|'s referrer |
| 161 // member." | |
| 162 | |
| 145 if (init.referrer.referrer.isEmpty()) { | 163 if (init.referrer.referrer.isEmpty()) { |
| 146 // 2. if |referrer| is the empty string, set |request|'s referrer to | 164 // "If |referrer| is the empty string, set |request|'s referrer to |
| 147 // "no-referrer" and terminate these substeps. | 165 // "no-referrer" and terminate these substeps." |
| 148 request->setReferrerString(FetchRequestData::noReferrerString()); | 166 request->setReferrerString(FetchRequestData::noReferrerString()); |
| 149 } else { | 167 } else { |
| 150 // 3. Let |parsedReferrer| be the result of parsing |referrer| with | 168 // "Let |parsedReferrer| be the result of parsing |referrer| with |
| 151 // |baseURL|. | 169 // |baseURL|. |
|
yhirano
2015/11/17 09:31:55
+"
tyoshino (SeeGerritForStatus)
2015/11/18 13:42:51
Done.
| |
| 152 KURL parsedReferrer = scriptState->executionContext()->completeURL(i nit.referrer.referrer); | 170 KURL parsedReferrer = scriptState->executionContext()->completeURL(i nit.referrer.referrer); |
| 153 if (!parsedReferrer.isValid()) { | 171 if (!parsedReferrer.isValid()) { |
| 154 // 4. If |parsedReferrer| is failure, throw a TypeError. | 172 // "If |parsedReferrer| is failure, throw a TypeError." |
| 155 exceptionState.throwTypeError("Referrer '" + init.referrer.refer rer + "' is not a valid URL."); | 173 exceptionState.throwTypeError("Referrer '" + init.referrer.refer rer + "' is not a valid URL."); |
| 156 return nullptr; | 174 return nullptr; |
| 157 } | 175 } |
| 158 if (parsedReferrer.protocolIsAbout() && parsedReferrer.host().isEmpt y() && parsedReferrer.path() == "client") { | 176 if (parsedReferrer.protocolIsAbout() && parsedReferrer.host().isEmpt y() && parsedReferrer.path() == "client") { |
| 159 // 5. If |parsedReferrer|'s non-relative flag is set, scheme is | 177 // "If |parsedReferrer|'s non-relative flag is set, scheme is |
| 160 // "about", and path contains a single string "client", set | 178 // "about", and path contains a single string "client", set |
| 161 // request's referrer to "client" and terminate these substeps. | 179 // request's referrer to "client" and terminate these |
| 180 // substeps." | |
| 162 request->setReferrerString(FetchRequestData::clientReferrerStrin g()); | 181 request->setReferrerString(FetchRequestData::clientReferrerStrin g()); |
| 163 } else if (!origin->isSameSchemeHostPortAndSuborigin(SecurityOrigin: :create(parsedReferrer).get())) { | 182 } else if (!origin->isSameSchemeHostPortAndSuborigin(SecurityOrigin: :create(parsedReferrer).get())) { |
| 164 // 6. If |parsedReferrer|'s origin is not same origin with | 183 // "If |parsedReferrer|'s origin is not same origin with |
| 165 // |origin|, throw a TypeError. | 184 // |origin|, throw a TypeError." |
| 166 exceptionState.throwTypeError("The origin of '" + init.referrer. referrer + "' should be same as '" + origin->toString() + "'"); | 185 exceptionState.throwTypeError("The origin of '" + init.referrer. referrer + "' should be same as '" + origin->toString() + "'"); |
| 167 return nullptr; | 186 return nullptr; |
| 168 } else { | 187 } else { |
| 169 // 7. Set |request|'s referrer to |parsedReferrer|. | 188 // "Set |request|'s referrer to |parsedReferrer|." |
| 170 request->setReferrerString(AtomicString(parsedReferrer.string()) ); | 189 request->setReferrerString(AtomicString(parsedReferrer.string()) ); |
| 171 } | 190 } |
| 172 } | 191 } |
| 173 request->setReferrerPolicy(init.referrer.referrerPolicy); | 192 request->setReferrerPolicy(init.referrer.referrerPolicy); |
| 174 } | 193 } |
| 175 | 194 |
| 176 // "16. Let |mode| be |init|'s mode member if it is present, and | 195 // The following code performs the following steps: |
| 177 // |fallbackMode| otherwise." | 196 // - "Let |mode| be |init|'s mode member if it is present, and |
| 178 // "17. If |mode| is "navigate", throw a TypeError. | 197 // |fallbackMode| otherwise." |
| 179 // "18. If |mode| is non-null, set |request|'s mode to |mode|." | 198 // - "If |mode| is "navigate", throw a TypeError." |
| 199 // - "If |mode| is non-null, set |request|'s mode to |mode|." | |
| 180 if (init.mode == "navigate") { | 200 if (init.mode == "navigate") { |
| 181 exceptionState.throwTypeError("Cannot construct a Request with a Request Init whose mode member is set as 'navigate'."); | 201 exceptionState.throwTypeError("Cannot construct a Request with a Request Init whose mode member is set as 'navigate'."); |
| 182 return nullptr; | 202 return nullptr; |
| 183 } | 203 } |
| 184 if (init.mode == "same-origin") { | 204 if (init.mode == "same-origin") { |
| 185 request->setMode(WebURLRequest::FetchRequestModeSameOrigin); | 205 request->setMode(WebURLRequest::FetchRequestModeSameOrigin); |
| 186 } else if (init.mode == "no-cors") { | 206 } else if (init.mode == "no-cors") { |
| 187 request->setMode(WebURLRequest::FetchRequestModeNoCORS); | 207 request->setMode(WebURLRequest::FetchRequestModeNoCORS); |
| 188 } else if (init.mode == "cors") { | 208 } else if (init.mode == "cors") { |
| 189 request->setMode(WebURLRequest::FetchRequestModeCORS); | 209 request->setMode(WebURLRequest::FetchRequestModeCORS); |
| 190 } else { | 210 } else { |
| 211 // |inputRequest| is directly checked here instead of setting and | |
| 212 // checking |fallbackMode| as specified in the spec. | |
| 191 if (!inputRequest) | 213 if (!inputRequest) |
| 192 request->setMode(WebURLRequest::FetchRequestModeCORS); | 214 request->setMode(WebURLRequest::FetchRequestModeCORS); |
| 193 } | 215 } |
| 194 | 216 |
| 195 // "19. Let |credentials| be |init|'s credentials member if it is present, | 217 // "19. Let |credentials| be |init|'s credentials member if it is present, |
| 196 // and |fallbackCredentials| otherwise." | 218 // and |fallbackCredentials| otherwise." |
| 197 // "20. If |credentials| is non-null, set |request|'s credentials mode to | 219 // "20. If |credentials| is non-null, set |request|'s credentials mode to |
| 198 // |credentials|. | 220 // |credentials|. |
| 199 if (init.credentials == "omit") { | 221 if (init.credentials == "omit") { |
| 200 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); | 222 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 } | 625 } |
| 604 | 626 |
| 605 DEFINE_TRACE(Request) | 627 DEFINE_TRACE(Request) |
| 606 { | 628 { |
| 607 Body::trace(visitor); | 629 Body::trace(visitor); |
| 608 visitor->trace(m_request); | 630 visitor->trace(m_request); |
| 609 visitor->trace(m_headers); | 631 visitor->trace(m_headers); |
| 610 } | 632 } |
| 611 | 633 |
| 612 } // namespace blink | 634 } // namespace blink |
| OLD | NEW |