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 "Request.h" | 6 #include "Request.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/fetch/FetchUtils.h" | 10 #include "core/fetch/FetchUtils.h" |
11 #include "core/fetch/ResourceLoaderOptions.h" | 11 #include "core/fetch/ResourceLoaderOptions.h" |
12 #include "core/loader/ThreadableLoader.h" | 12 #include "core/loader/ThreadableLoader.h" |
13 #include "modules/serviceworkers/FetchManager.h" | 13 #include "modules/serviceworkers/FetchManager.h" |
14 #include "modules/serviceworkers/RequestInit.h" | 14 #include "modules/serviceworkers/RequestInit.h" |
15 #include "platform/network/HTTPParsers.h" | 15 #include "platform/network/HTTPParsers.h" |
16 #include "platform/network/ResourceRequest.h" | 16 #include "platform/network/ResourceRequest.h" |
17 #include "platform/weborigin/Referrer.h" | 17 #include "platform/weborigin/Referrer.h" |
18 #include "public/platform/WebServiceWorkerRequest.h" | 18 #include "public/platform/WebServiceWorkerRequest.h" |
| 19 #include "public/platform/WebURLRequest.h" |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
22 Request* Request::createRequestWithRequestData(ExecutionContext* context, FetchR
equestData* request, const RequestInit& init, FetchRequestData::Mode mode, Fetch
RequestData::Credentials credentials, ExceptionState& exceptionState) | 23 Request* Request::createRequestWithRequestData(ExecutionContext* context, FetchR
equestData* request, const RequestInit& init, WebURLRequest::FetchRequestMode mo
de, WebURLRequest::FetchCredentialsMode credentials, ExceptionState& exceptionSt
ate) |
23 { | 24 { |
24 // "7. Let |mode| be |init|'s mode member if it is present, and | 25 // "7. Let |mode| be |init|'s mode member if it is present, and |
25 // |fallbackMode| otherwise." | 26 // |fallbackMode| otherwise." |
26 // "8. If |mode| is non-null, set |request|'s mode to |mode|." | 27 // "8. If |mode| is non-null, set |request|'s mode to |mode|." |
27 if (init.mode == "same-origin") { | 28 if (init.mode == "same-origin") { |
28 request->setMode(FetchRequestData::SameOriginMode); | 29 request->setMode(WebURLRequest::FetchRequestModeSameOrigin); |
29 } else if (init.mode == "no-cors") { | 30 } else if (init.mode == "no-cors") { |
30 request->setMode(mode = FetchRequestData::NoCORSMode); | 31 request->setMode(mode = WebURLRequest::FetchRequestModeNoCORS); |
31 } else if (init.mode == "cors") { | 32 } else if (init.mode == "cors") { |
32 request->setMode(FetchRequestData::CORSMode); | 33 request->setMode(WebURLRequest::FetchRequestModeCORS); |
33 } else { | 34 } else { |
34 // Instead of using null as a special fallback value, we pass the | 35 // Instead of using null as a special fallback value, we pass the |
35 // current mode in Request::create(). So we just set here. | 36 // current mode in Request::create(). So we just set here. |
36 request->setMode(mode); | 37 request->setMode(mode); |
37 } | 38 } |
38 | 39 |
39 // "9. Let |credentials| be |init|'s credentials member if it is present, | 40 // "9. Let |credentials| be |init|'s credentials member if it is present, |
40 // and |fallbackCredentials| otherwise." | 41 // and |fallbackCredentials| otherwise." |
41 // "10. If |credentials| is non-null, set |request|'s credentials mode to | 42 // "10. If |credentials| is non-null, set |request|'s credentials mode to |
42 // |credentials|. | 43 // |credentials|. |
43 if (init.credentials == "omit") { | 44 if (init.credentials == "omit") { |
44 request->setCredentials(FetchRequestData::OmitCredentials); | 45 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); |
45 } else if (init.credentials == "same-origin") { | 46 } else if (init.credentials == "same-origin") { |
46 request->setCredentials(FetchRequestData::SameOriginCredentials); | 47 request->setCredentials(WebURLRequest::FetchCredentialsModeSameOrigin); |
47 } else if (init.credentials == "include") { | 48 } else if (init.credentials == "include") { |
48 request->setCredentials(FetchRequestData::IncludeCredentials); | 49 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); |
49 } else { | 50 } else { |
50 // Instead of using null as a special fallback value, we pass the | 51 // Instead of using null as a special fallback value, we pass the |
51 // current credentials in Request::create(). So we just set here. | 52 // current credentials in Request::create(). So we just set here. |
52 request->setCredentials(credentials); | 53 request->setCredentials(credentials); |
53 } | 54 } |
54 | 55 |
55 // "11. If |init|'s method member is present, let |method| be it and run | 56 // "11. If |init|'s method member is present, let |method| be it and run |
56 // these substeps:" | 57 // these substeps:" |
57 if (!init.method.isEmpty()) { | 58 if (!init.method.isEmpty()) { |
58 // "1. If |method| is not a useful method, throw a TypeError." | 59 // "1. If |method| is not a useful method, throw a TypeError." |
(...skipping 19 matching lines...) Expand all Loading... |
78 // We don't create a copy of r's Headers object when init's headers member | 79 // We don't create a copy of r's Headers object when init's headers member |
79 // is present. | 80 // is present. |
80 Headers* headers = 0; | 81 Headers* headers = 0; |
81 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 82 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
82 headers = r->headers()->createCopy(); | 83 headers = r->headers()->createCopy(); |
83 } | 84 } |
84 // "15. Empty |r|'s request's header list." | 85 // "15. Empty |r|'s request's header list." |
85 r->clearHeaderList(); | 86 r->clearHeaderList(); |
86 | 87 |
87 // "16. If |r|'s request's mode is no CORS, run these substeps: | 88 // "16. If |r|'s request's mode is no CORS, run these substeps: |
88 if (r->request()->mode() == FetchRequestData::NoCORSMode) { | 89 if (r->request()->mode() == WebURLRequest::FetchRequestModeNoCORS) { |
89 // "1. If |r|'s request's method is not a simple method, throw a | 90 // "1. If |r|'s request's method is not a simple method, throw a |
90 // TypeError." | 91 // TypeError." |
91 if (!FetchUtils::isSimpleMethod(r->request()->method())) { | 92 if (!FetchUtils::isSimpleMethod(r->request()->method())) { |
92 exceptionState.throwTypeError("'" + r->request()->method() + "' is u
nsupported in no-cors mode."); | 93 exceptionState.throwTypeError("'" + r->request()->method() + "' is u
nsupported in no-cors mode."); |
93 return 0; | 94 return 0; |
94 } | 95 } |
95 // "Set |r|'s Headers object's guard to |request-no-CORS|. | 96 // "Set |r|'s Headers object's guard to |request-no-CORS|. |
96 r->headers()->setGuard(Headers::RequestNoCORSGuard); | 97 r->headers()->setGuard(Headers::RequestNoCORSGuard); |
97 } | 98 } |
98 | 99 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 KURL parsedURL = context->completeURL(input); | 151 KURL parsedURL = context->completeURL(input); |
151 // "2. If |parsedURL| is failure, throw a TypeError." | 152 // "2. If |parsedURL| is failure, throw a TypeError." |
152 if (!parsedURL.isValid()) { | 153 if (!parsedURL.isValid()) { |
153 exceptionState.throwTypeError("Invalid URL"); | 154 exceptionState.throwTypeError("Invalid URL"); |
154 return 0; | 155 return 0; |
155 } | 156 } |
156 // "3. Set |request|'s url to |parsedURL|." | 157 // "3. Set |request|'s url to |parsedURL|." |
157 request->setURL(parsedURL); | 158 request->setURL(parsedURL); |
158 // "4. Set |fallbackMode| to CORS." | 159 // "4. Set |fallbackMode| to CORS." |
159 // "5. Set |fallbackCredentials| to omit." | 160 // "5. Set |fallbackCredentials| to omit." |
160 return createRequestWithRequestData(context, request, RequestInit(context, i
nit, exceptionState), FetchRequestData::CORSMode, FetchRequestData::OmitCredenti
als, exceptionState); | 161 return createRequestWithRequestData(context, request, RequestInit(context, i
nit, exceptionState), WebURLRequest::FetchRequestModeCORS, WebURLRequest::FetchC
redentialsModeOmit, exceptionState); |
161 } | 162 } |
162 | 163 |
163 Request* Request::create(ExecutionContext* context, Request* input, ExceptionSta
te& exceptionState) | 164 Request* Request::create(ExecutionContext* context, Request* input, ExceptionSta
te& exceptionState) |
164 { | 165 { |
165 return create(context, input, Dictionary(), exceptionState); | 166 return create(context, input, Dictionary(), exceptionState); |
166 } | 167 } |
167 | 168 |
168 Request* Request::create(ExecutionContext* context, Request* input, const Dictio
nary& init, ExceptionState& exceptionState) | 169 Request* Request::create(ExecutionContext* context, Request* input, const Dictio
nary& init, ExceptionState& exceptionState) |
169 { | 170 { |
170 // "1. If input is a Request object, run these substeps:" | 171 // "1. If input is a Request object, run these substeps:" |
171 // " 1. If input's used flag is set, throw a TypeError." | 172 // " 1. If input's used flag is set, throw a TypeError." |
172 // " 2. Set input's used flag." | 173 // " 2. Set input's used flag." |
173 if (input->bodyUsed()) { | 174 if (input->bodyUsed()) { |
174 exceptionState.throwTypeError( | 175 exceptionState.throwTypeError( |
175 "Cannot construct a Request with a Request object that has already b
een used."); | 176 "Cannot construct a Request with a Request object that has already b
een used."); |
176 return 0; | 177 return 0; |
177 } | 178 } |
178 input->setBodyUsed(); | 179 input->setBodyUsed(); |
179 // "2. Let |request| be |input|'s associated request, if |input| is a | 180 // "2. Let |request| be |input|'s associated request, if |input| is a |
180 // Request object, and a new request otherwise." | 181 // Request object, and a new request otherwise." |
181 // "3. Set |request| to a restricted copy of itself." | 182 // "3. Set |request| to a restricted copy of itself." |
182 FetchRequestData* request(input->request()->createRestrictedCopy(context, Se
curityOrigin::create(context->url()))); | 183 FetchRequestData* request(input->request()->createRestrictedCopy(context, Se
curityOrigin::create(context->url()))); |
183 // "4. Let |fallbackMode| be null." | 184 // "4. Let |fallbackMode| be null." |
184 // "5. Let |fallbackCredentials| be null." | 185 // "5. Let |fallbackCredentials| be null." |
185 // Instead of using null as a special fallback value, just pass the current | 186 // Instead of using null as a special fallback value, just pass the current |
186 // mode and credentials; it has the same effect. | 187 // mode and credentials; it has the same effect. |
187 const FetchRequestData::Mode currentMode = request->mode(); | 188 const WebURLRequest::FetchRequestMode currentMode = request->mode(); |
188 const FetchRequestData::Credentials currentCredentials = request->credential
s(); | 189 const WebURLRequest::FetchCredentialsMode currentCredentials = request->cred
entials(); |
189 return createRequestWithRequestData(context, request, RequestInit(context, i
nit, exceptionState), currentMode, currentCredentials, exceptionState); | 190 return createRequestWithRequestData(context, request, RequestInit(context, i
nit, exceptionState), currentMode, currentCredentials, exceptionState); |
190 } | 191 } |
191 | 192 |
192 Request* Request::create(ExecutionContext* context, FetchRequestData* request) | 193 Request* Request::create(ExecutionContext* context, FetchRequestData* request) |
193 { | 194 { |
194 Request* r = new Request(context, request); | 195 Request* r = new Request(context, request); |
195 r->suspendIfNeeded(); | 196 r->suspendIfNeeded(); |
196 return r; | 197 return r; |
197 } | 198 } |
198 | 199 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // request's referrer is none, and request's referrer, serialized, | 257 // request's referrer is none, and request's referrer, serialized, |
257 // otherwise." | 258 // otherwise." |
258 return m_request->referrer().referrer().referrer; | 259 return m_request->referrer().referrer().referrer; |
259 } | 260 } |
260 | 261 |
261 String Request::mode() const | 262 String Request::mode() const |
262 { | 263 { |
263 // "The mode attribute's getter must return the value corresponding to the | 264 // "The mode attribute's getter must return the value corresponding to the |
264 // first matching statement, switching on request's mode:" | 265 // first matching statement, switching on request's mode:" |
265 switch (m_request->mode()) { | 266 switch (m_request->mode()) { |
266 case FetchRequestData::SameOriginMode: | 267 case WebURLRequest::FetchRequestModeSameOrigin: |
267 return "same-origin"; | 268 return "same-origin"; |
268 case FetchRequestData::NoCORSMode: | 269 case WebURLRequest::FetchRequestModeNoCORS: |
269 return "no-cors"; | 270 return "no-cors"; |
270 case FetchRequestData::CORSMode: | 271 case WebURLRequest::FetchRequestModeCORS: |
271 case FetchRequestData::CORSWithForcedPreflight: | 272 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: |
272 return "cors"; | 273 return "cors"; |
273 } | 274 } |
274 ASSERT_NOT_REACHED(); | 275 ASSERT_NOT_REACHED(); |
275 return ""; | 276 return ""; |
276 } | 277 } |
277 | 278 |
278 String Request::credentials() const | 279 String Request::credentials() const |
279 { | 280 { |
280 // "The credentials attribute's getter must return the value corresponding | 281 // "The credentials attribute's getter must return the value corresponding |
281 // to the first matching statement, switching on request's credentials | 282 // to the first matching statement, switching on request's credentials |
282 // mode:" | 283 // mode:" |
283 switch (m_request->credentials()) { | 284 switch (m_request->credentials()) { |
284 case FetchRequestData::OmitCredentials: | 285 case WebURLRequest::FetchCredentialsModeOmit: |
285 return "omit"; | 286 return "omit"; |
286 case FetchRequestData::SameOriginCredentials: | 287 case WebURLRequest::FetchCredentialsModeSameOrigin: |
287 return "same-origin"; | 288 return "same-origin"; |
288 case FetchRequestData::IncludeCredentials: | 289 case WebURLRequest::FetchCredentialsModeInclude: |
289 return "include"; | 290 return "include"; |
290 } | 291 } |
291 ASSERT_NOT_REACHED(); | 292 ASSERT_NOT_REACHED(); |
292 return ""; | 293 return ""; |
293 } | 294 } |
294 | 295 |
295 Request* Request::clone() const | 296 Request* Request::clone() const |
296 { | 297 { |
297 return Request::create(*this); | 298 return Request::create(*this); |
298 } | 299 } |
(...skipping 30 matching lines...) Expand all Loading... |
329 } | 330 } |
330 | 331 |
331 void Request::trace(Visitor* visitor) | 332 void Request::trace(Visitor* visitor) |
332 { | 333 { |
333 Body::trace(visitor); | 334 Body::trace(visitor); |
334 visitor->trace(m_request); | 335 visitor->trace(m_request); |
335 visitor->trace(m_headers); | 336 visitor->trace(m_headers); |
336 } | 337 } |
337 | 338 |
338 } // namespace blink | 339 } // namespace blink |
OLD | NEW |