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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 virtual bool handleItem(const String& value, const String& key, Headers*) | 37 virtual bool handleItem(const String& value, const String& key, Headers*) |
38 { | 38 { |
39 m_webRequest->setHeader(key, value); | 39 m_webRequest->setHeader(key, value); |
40 return true; | 40 return true; |
41 } | 41 } |
42 | 42 |
43 private: | 43 private: |
44 WebServiceWorkerRequest* m_webRequest; | 44 WebServiceWorkerRequest* m_webRequest; |
45 }; | 45 }; |
46 | 46 |
47 Request* createRequestWithRequestData(FetchRequestData* request, const RequestIn
it& init, FetchRequestData::Mode mode, FetchRequestData::Credentials credentials
, ExceptionState& exceptionState) | 47 Request* createRequestWithRequestData(ExecutionContext* context, FetchRequestDat
a* request, const RequestInit& init, FetchRequestData::Mode mode, FetchRequestDa
ta::Credentials credentials, ExceptionState& exceptionState) |
48 { | 48 { |
49 // "6. Let |mode| be |init|'s mode member if it is present, and | 49 // "6. Let |mode| be |init|'s mode member if it is present, and |
50 // |fallbackMode| otherwise." | 50 // |fallbackMode| otherwise." |
51 // "7. If |mode| is non-null, set |request|'s mode to |mode|." | 51 // "7. If |mode| is non-null, set |request|'s mode to |mode|." |
52 if (init.mode == "same-origin") { | 52 if (init.mode == "same-origin") { |
53 request->setMode(FetchRequestData::SameOriginMode); | 53 request->setMode(FetchRequestData::SameOriginMode); |
54 } else if (init.mode == "no-cors") { | 54 } else if (init.mode == "no-cors") { |
55 request->setMode(mode = FetchRequestData::NoCORSMode); | 55 request->setMode(mode = FetchRequestData::NoCORSMode); |
56 } else if (init.mode == "cors") { | 56 } else if (init.mode == "cors") { |
57 request->setMode(FetchRequestData::CORSMode); | 57 request->setMode(FetchRequestData::CORSMode); |
(...skipping 29 matching lines...) Expand all Loading... |
87 } | 87 } |
88 if (!isValidHTTPToken(init.method)) { | 88 if (!isValidHTTPToken(init.method)) { |
89 exceptionState.throwTypeError("'" + init.method + "' is not a valid
HTTP method."); | 89 exceptionState.throwTypeError("'" + init.method + "' is not a valid
HTTP method."); |
90 return 0; | 90 return 0; |
91 } | 91 } |
92 // FIXME: "2. Add case correction as in XMLHttpRequest?" | 92 // FIXME: "2. Add case correction as in XMLHttpRequest?" |
93 // "3. Set |request|'s method to |method|." | 93 // "3. Set |request|'s method to |method|." |
94 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString
(init.method))); | 94 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString
(init.method))); |
95 } | 95 } |
96 // "11. Let |r| be a new Request object associated with |request|, Headers | 96 // "11. Let |r| be a new Request object associated with |request|, Headers |
97 // object, and FetchBodyStream object." | 97 // object." |
98 Request* r = Request::create(request); | 98 Request* r = Request::create(context, request); |
99 | 99 |
100 // "12. Let |headers| be a copy of |r|'s Headers object." | 100 // "12. Let |headers| be a copy of |r|'s Headers object." |
101 // "13. If |init|'s headers member is present, set |headers| to |init|'s | 101 // "13. If |init|'s headers member is present, set |headers| to |init|'s |
102 // headers member." | 102 // headers member." |
103 // We don't create a copy of r's Headers object when init's headers member | 103 // We don't create a copy of r's Headers object when init's headers member |
104 // is present. | 104 // is present. |
105 Headers* headers = 0; | 105 Headers* headers = 0; |
106 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 106 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
107 headers = r->headers()->createCopy(); | 107 headers = r->headers()->createCopy(); |
108 } | 108 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // contains no header named `Content-Type`, append | 142 // contains no header named `Content-Type`, append |
143 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any | 143 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
144 // exception." | 144 // exception." |
145 r->setBodyBlobHandle(init.bodyBlobHandle); | 145 r->setBodyBlobHandle(init.bodyBlobHandle); |
146 if (!init.bodyBlobHandle->type().isEmpty() && !r->headers()->has("Conten
t-Type", exceptionState)) { | 146 if (!init.bodyBlobHandle->type().isEmpty() && !r->headers()->has("Conten
t-Type", exceptionState)) { |
147 r->headers()->append("Content-Type", init.bodyBlobHandle->type(), ex
ceptionState); | 147 r->headers()->append("Content-Type", init.bodyBlobHandle->type(), ex
ceptionState); |
148 } | 148 } |
149 if (exceptionState.hadException()) | 149 if (exceptionState.hadException()) |
150 return 0; | 150 return 0; |
151 } | 151 } |
152 // "18. Set |r|'s FetchBodyStream object's MIME type to the result of | 152 // "18. Set |r|'s MIME type to the result of extracting a MIME type from |
153 // extracting a MIME type from |r|'s request's header list." | 153 // |r|'s request's header list." |
154 // FIXME: We don't have MIME type in FetchBodyStream object yet. | 154 // FIXME: We don't have MIME type in Request object yet. |
155 | 155 |
156 // "19. Return |r|." | 156 // "19. Return |r|." |
157 return r; | 157 return r; |
158 } | 158 } |
159 | 159 |
160 } // namespace | 160 } // namespace |
161 | 161 |
162 Request* Request::create(ExecutionContext* context, const String& input, Excepti
onState& exceptionState) | 162 Request* Request::create(ExecutionContext* context, const String& input, Excepti
onState& exceptionState) |
163 { | 163 { |
164 return create(context, input, Dictionary(), exceptionState); | 164 return create(context, input, Dictionary(), exceptionState); |
(...skipping 12 matching lines...) Expand all Loading... |
177 KURL parsedURL = context->completeURL(input); | 177 KURL parsedURL = context->completeURL(input); |
178 // "2. If |parsedURL| is failure, throw a TypeError." | 178 // "2. If |parsedURL| is failure, throw a TypeError." |
179 if (!parsedURL.isValid()) { | 179 if (!parsedURL.isValid()) { |
180 exceptionState.throwTypeError("Invalid URL"); | 180 exceptionState.throwTypeError("Invalid URL"); |
181 return 0; | 181 return 0; |
182 } | 182 } |
183 // "3. Set |request|'s url to |parsedURL|." | 183 // "3. Set |request|'s url to |parsedURL|." |
184 request->setURL(parsedURL); | 184 request->setURL(parsedURL); |
185 // "4. Set |fallbackMode| to CORS." | 185 // "4. Set |fallbackMode| to CORS." |
186 // "5. Set |fallbackCredentials| to omit." | 186 // "5. Set |fallbackCredentials| to omit." |
187 return createRequestWithRequestData(request, RequestInit(context, init, exce
ptionState), FetchRequestData::CORSMode, FetchRequestData::OmitCredentials, exce
ptionState); | 187 return createRequestWithRequestData(context, request, RequestInit(context, i
nit, exceptionState), FetchRequestData::CORSMode, FetchRequestData::OmitCredenti
als, exceptionState); |
188 } | 188 } |
189 | 189 |
190 Request* Request::create(ExecutionContext* context, Request* input, ExceptionSta
te& exceptionState) | 190 Request* Request::create(ExecutionContext* context, Request* input, ExceptionSta
te& exceptionState) |
191 { | 191 { |
192 return create(context, input, Dictionary(), exceptionState); | 192 return create(context, input, Dictionary(), exceptionState); |
193 } | 193 } |
194 | 194 |
195 Request* Request::create(ExecutionContext* context, Request* input, const Dictio
nary& init, ExceptionState& exceptionState) | 195 Request* Request::create(ExecutionContext* context, Request* input, const Dictio
nary& init, ExceptionState& exceptionState) |
196 { | 196 { |
197 // "1. Let |request| be |input|'s associated request, if |input| is a | 197 // "1. Let |request| be |input|'s associated request, if |input| is a |
198 // Request object, and a new request otherwise." | 198 // Request object, and a new request otherwise." |
199 // "2. Set |request| to a restricted copy of itself." | 199 // "2. Set |request| to a restricted copy of itself." |
200 FetchRequestData* request(input->request()->createRestrictedCopy(context, Se
curityOrigin::create(context->url()))); | 200 FetchRequestData* request(input->request()->createRestrictedCopy(context, Se
curityOrigin::create(context->url()))); |
201 // "3. Let |fallbackMode| be null." | 201 // "3. Let |fallbackMode| be null." |
202 // "4. Let |fallbackCredentials| be null." | 202 // "4. Let |fallbackCredentials| be null." |
203 // Instead of using null as a special fallback value, just pass the current | 203 // Instead of using null as a special fallback value, just pass the current |
204 // mode and credentials; it has the same effect. | 204 // mode and credentials; it has the same effect. |
205 const FetchRequestData::Mode currentMode = request->mode(); | 205 const FetchRequestData::Mode currentMode = request->mode(); |
206 const FetchRequestData::Credentials currentCredentials = request->credential
s(); | 206 const FetchRequestData::Credentials currentCredentials = request->credential
s(); |
207 return createRequestWithRequestData(request, RequestInit(context, init, exce
ptionState), currentMode, currentCredentials, exceptionState); | 207 return createRequestWithRequestData(context, request, RequestInit(context, i
nit, exceptionState), currentMode, currentCredentials, exceptionState); |
208 } | 208 } |
209 | 209 |
210 Request* Request::create(FetchRequestData* request) | 210 Request* Request::create(ExecutionContext* context, FetchRequestData* request) |
211 { | 211 { |
212 return new Request(request); | 212 Request* r = new Request(context, request); |
| 213 r->suspendIfNeeded(); |
| 214 return r; |
213 } | 215 } |
214 | 216 |
215 Request::Request(FetchRequestData* request) | 217 Request::Request(ExecutionContext* context, FetchRequestData* request) |
216 : m_request(request) | 218 : Body(context) |
| 219 , m_request(request) |
217 , m_headers(Headers::create(m_request->headerList())) | 220 , m_headers(Headers::create(m_request->headerList())) |
218 { | 221 { |
219 m_headers->setGuard(Headers::RequestGuard); | 222 m_headers->setGuard(Headers::RequestGuard); |
220 } | 223 } |
221 | 224 |
222 Request* Request::create(const WebServiceWorkerRequest& webRequest) | 225 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques
t& webRequest) |
223 { | 226 { |
224 return new Request(webRequest); | 227 Request* r = new Request(context, webRequest); |
| 228 r->suspendIfNeeded(); |
| 229 return r; |
225 } | 230 } |
226 | 231 |
227 Request::Request(const WebServiceWorkerRequest& webRequest) | 232 Request::Request(ExecutionContext* context, const WebServiceWorkerRequest& webRe
quest) |
228 : m_request(FetchRequestData::create(webRequest)) | 233 : Body(context) |
| 234 , m_request(FetchRequestData::create(webRequest)) |
229 , m_headers(Headers::create(m_request->headerList())) | 235 , m_headers(Headers::create(m_request->headerList())) |
230 { | 236 { |
231 m_headers->setGuard(Headers::RequestGuard); | 237 m_headers->setGuard(Headers::RequestGuard); |
232 } | 238 } |
233 | 239 |
234 String Request::method() const | 240 String Request::method() const |
235 { | 241 { |
236 // "The method attribute's getter must return request's method." | 242 // "The method attribute's getter must return request's method." |
237 return m_request->method(); | 243 return m_request->method(); |
238 } | 244 } |
239 | 245 |
240 String Request::url() const | 246 String Request::url() const |
241 { | 247 { |
242 // The url attribute's getter must return request's url, serialized with the
exclude fragment flag set. | 248 // The url attribute's getter must return request's url, serialized with the
exclude fragment flag set. |
243 if (!m_request->url().hasFragmentIdentifier()) | 249 if (!m_request->url().hasFragmentIdentifier()) |
244 return m_request->url(); | 250 return m_request->url(); |
245 KURL url(m_request->url()); | 251 KURL url(m_request->url()); |
246 url.removeFragmentIdentifier(); | 252 url.removeFragmentIdentifier(); |
247 return url; | 253 return url; |
248 } | 254 } |
249 | 255 |
250 FetchBodyStream* Request::body(ExecutionContext* context) | |
251 { | |
252 if (!m_request->blobDataHandle()) | |
253 return 0; | |
254 if (!m_fetchBodyStream) | |
255 m_fetchBodyStream = FetchBodyStream::create(context, m_request->blobData
Handle()); | |
256 return m_fetchBodyStream; | |
257 } | |
258 | |
259 | |
260 String Request::referrer() const | 256 String Request::referrer() const |
261 { | 257 { |
262 // "The referrer attribute's getter must return the empty string if | 258 // "The referrer attribute's getter must return the empty string if |
263 // request's referrer is none, and request's referrer, serialized, | 259 // request's referrer is none, and request's referrer, serialized, |
264 // otherwise." | 260 // otherwise." |
265 return m_request->referrer().referrer().referrer; | 261 return m_request->referrer().referrer().referrer; |
266 } | 262 } |
267 | 263 |
268 String Request::mode() const | 264 String Request::mode() const |
269 { | 265 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) | 298 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) |
303 { | 299 { |
304 webRequest.setMethod(method()); | 300 webRequest.setMethod(method()); |
305 webRequest.setURL(m_request->url()); | 301 webRequest.setURL(m_request->url()); |
306 m_headers->forEach(adoptPtrWillBeNoop(new FillWebRequestHeaders(&webRequest)
)); | 302 m_headers->forEach(adoptPtrWillBeNoop(new FillWebRequestHeaders(&webRequest)
)); |
307 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas
t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); | 303 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas
t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); |
308 // FIXME: How can we set isReload properly? What is the correct place to loa
d it in to the Request object? We should investigate the right way | 304 // FIXME: How can we set isReload properly? What is the correct place to loa
d it in to the Request object? We should investigate the right way |
309 // to plumb this information in to here. | 305 // to plumb this information in to here. |
310 } | 306 } |
311 | 307 |
312 void Request::setBodyBlobHandle(PassRefPtr<BlobDataHandle>blobHandle) | 308 void Request::setBodyBlobHandle(PassRefPtr<BlobDataHandle> blobDataHandle) |
313 { | 309 { |
314 m_request->setBlobDataHandle(blobHandle); | 310 m_request->setBlobDataHandle(blobDataHandle); |
| 311 } |
| 312 |
| 313 PassRefPtr<BlobDataHandle> Request::blobDataHandle() |
| 314 { |
| 315 return m_request->blobDataHandle(); |
315 } | 316 } |
316 | 317 |
317 void Request::trace(Visitor* visitor) | 318 void Request::trace(Visitor* visitor) |
318 { | 319 { |
| 320 Body::trace(visitor); |
319 visitor->trace(m_request); | 321 visitor->trace(m_request); |
320 visitor->trace(m_headers); | 322 visitor->trace(m_headers); |
321 visitor->trace(m_fetchBodyStream); | |
322 } | 323 } |
323 | 324 |
324 } // namespace blink | 325 } // namespace blink |
OLD | NEW |