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/CrossOriginAccessControl.h" | 10 #include "core/fetch/CrossOriginAccessControl.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 "core/xml/XMLHttpRequest.h" | 13 #include "core/xml/XMLHttpRequest.h" |
14 #include "modules/serviceworkers/FetchManager.h" | 14 #include "modules/serviceworkers/FetchManager.h" |
15 #include "modules/serviceworkers/RequestInit.h" | 15 #include "modules/serviceworkers/RequestInit.h" |
16 #include "platform/NotImplemented.h" | 16 #include "platform/NotImplemented.h" |
17 #include "platform/network/HTTPParsers.h" | 17 #include "platform/network/HTTPParsers.h" |
18 #include "platform/network/ResourceRequest.h" | 18 #include "platform/network/ResourceRequest.h" |
19 #include "platform/weborigin/Referrer.h" | 19 #include "platform/weborigin/Referrer.h" |
20 #include "public/platform/WebServiceWorkerRequest.h" | 20 #include "public/platform/WebServiceWorkerRequest.h" |
21 #include "public/platform/WebURLRequest.h" | 21 #include "public/platform/WebURLRequest.h" |
22 | 22 |
23 namespace WebCore { | 23 namespace WebCore { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 PassRefPtr<Request> createRequestWithRequestData(PassRefPtr<FetchRequestData> re
quest, const RequestInit& init, FetchRequestData::Mode mode, FetchRequestData::C
redentials credentials, ExceptionState& exceptionState) | 27 PassRefPtrWillBeRawPtr<Request> createRequestWithRequestData(PassRefPtrWillBeRaw
Ptr<FetchRequestData> request, const RequestInit& init, FetchRequestData::Mode m
ode, FetchRequestData::Credentials credentials, ExceptionState& exceptionState) |
28 { | 28 { |
29 // "6. Let |mode| be |init|'s mode member if it is present, and | 29 // "6. Let |mode| be |init|'s mode member if it is present, and |
30 // |fallbackMode| otherwise." | 30 // |fallbackMode| otherwise." |
31 // "7. If |mode| is non-null, set |request|'s mode to |mode|." | 31 // "7. If |mode| is non-null, set |request|'s mode to |mode|." |
32 if (init.mode == "same-origin") { | 32 if (init.mode == "same-origin") { |
33 request->setMode(FetchRequestData::SameOriginMode); | 33 request->setMode(FetchRequestData::SameOriginMode); |
34 } else if (init.mode == "no-cors") { | 34 } else if (init.mode == "no-cors") { |
35 request->setMode(mode = FetchRequestData::NoCORSMode); | 35 request->setMode(mode = FetchRequestData::NoCORSMode); |
36 } else if (init.mode == "cors") { | 36 } else if (init.mode == "cors") { |
37 request->setMode(FetchRequestData::CORSMode); | 37 request->setMode(FetchRequestData::CORSMode); |
(...skipping 30 matching lines...) Expand all Loading... |
68 if (!isValidHTTPToken(init.method)) { | 68 if (!isValidHTTPToken(init.method)) { |
69 exceptionState.throwTypeError("'" + init.method + "' is not a valid
HTTP method."); | 69 exceptionState.throwTypeError("'" + init.method + "' is not a valid
HTTP method."); |
70 return nullptr; | 70 return nullptr; |
71 } | 71 } |
72 // FIXME: "2. Add case correction as in XMLHttpRequest?" | 72 // FIXME: "2. Add case correction as in XMLHttpRequest?" |
73 // "3. Set |request|'s method to |method|." | 73 // "3. Set |request|'s method to |method|." |
74 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString
(init.method))); | 74 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString
(init.method))); |
75 } | 75 } |
76 // "11. Let |r| be a new Request object associated with |request|, Headers | 76 // "11. Let |r| be a new Request object associated with |request|, Headers |
77 // object, and FetchBodyStream object." | 77 // object, and FetchBodyStream object." |
78 RefPtr<Request> r = Request::create(request); | 78 RefPtrWillBeRawPtr<Request> r = Request::create(request); |
79 | 79 |
80 // "12. Let |headers| be a copy of |r|'s Headers object." | 80 // "12. Let |headers| be a copy of |r|'s Headers object." |
81 // "13. If |init|'s headers member is present, set |headers| to |init|'s | 81 // "13. If |init|'s headers member is present, set |headers| to |init|'s |
82 // headers member." | 82 // headers member." |
83 // We don't create a copy of r's Headers object when init's headers member | 83 // We don't create a copy of r's Headers object when init's headers member |
84 // is present. | 84 // is present. |
85 RefPtr<Headers> headers; | 85 RefPtrWillBeRawPtr<Headers> headers = nullptr; |
86 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 86 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
87 headers = r->headers()->createCopy(); | 87 headers = r->headers()->createCopy(); |
88 } | 88 } |
89 // "14. Empty |r|'s request's header list." | 89 // "14. Empty |r|'s request's header list." |
90 r->request()->headerList()->clearList(); | 90 r->request()->headerList()->clearList(); |
91 | 91 |
92 // "15. If |r|'s request's mode is no CORS, run these substeps: | 92 // "15. If |r|'s request's mode is no CORS, run these substeps: |
93 if (r->request()->mode() == FetchRequestData::NoCORSMode) { | 93 if (r->request()->mode() == FetchRequestData::NoCORSMode) { |
94 // "1. If |r|'s request's method is not a simple method, throw a | 94 // "1. If |r|'s request's method is not a simple method, throw a |
95 // TypeError." | 95 // TypeError." |
(...skipping 18 matching lines...) Expand all Loading... |
114 if (exceptionState.hadException()) | 114 if (exceptionState.hadException()) |
115 return nullptr; | 115 return nullptr; |
116 // FIXME: Support body. | 116 // FIXME: Support body. |
117 // "20. Return |r|." | 117 // "20. Return |r|." |
118 return r.release(); | 118 return r.release(); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 } // namespace | 122 } // namespace |
123 | 123 |
124 PassRefPtr<Request> Request::create(ExecutionContext* context, const String& inp
ut, ExceptionState& exceptionState) | 124 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Request); |
| 125 |
| 126 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, ExceptionState& exceptionState) |
125 { | 127 { |
126 return create(context, input, Dictionary(), exceptionState); | 128 return create(context, input, Dictionary(), exceptionState); |
127 } | 129 } |
128 | 130 |
129 PassRefPtr<Request> Request::create(ExecutionContext* context, const String& inp
ut, const Dictionary& init, ExceptionState& exceptionState) | 131 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, const Dictionary& init, ExceptionState& exceptionState) |
130 { | 132 { |
131 // "1. Let |request| be |input|'s associated request, if |input| is a | 133 // "1. Let |request| be |input|'s associated request, if |input| is a |
132 // Request object, and a new request otherwise." | 134 // Request object, and a new request otherwise." |
133 RefPtr<FetchRequestData> request(FetchRequestData::create(context)); | 135 RefPtrWillBeRawPtr<FetchRequestData> request(FetchRequestData::create(contex
t)); |
134 // "2. Set |request| to a restricted copy of itself." | 136 // "2. Set |request| to a restricted copy of itself." |
135 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont
ext->url())); | 137 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont
ext->url())); |
136 // "5. If |input| is a string, run these substeps:" | 138 // "5. If |input| is a string, run these substeps:" |
137 // "1. Let |parsedURL| be the result of parsing |input| with entry settings | 139 // "1. Let |parsedURL| be the result of parsing |input| with entry settings |
138 // object's API base URL." | 140 // object's API base URL." |
139 KURL parsedURL = context->completeURL(input); | 141 KURL parsedURL = context->completeURL(input); |
140 // "2. If |parsedURL| is failure, throw a TypeError." | 142 // "2. If |parsedURL| is failure, throw a TypeError." |
141 if (!parsedURL.isValid()) { | 143 if (!parsedURL.isValid()) { |
142 exceptionState.throwTypeError("Invalid URL"); | 144 exceptionState.throwTypeError("Invalid URL"); |
143 return nullptr; | 145 return nullptr; |
144 } | 146 } |
145 // "3. Set |request|'s url to |parsedURL|." | 147 // "3. Set |request|'s url to |parsedURL|." |
146 request->setURL(parsedURL); | 148 request->setURL(parsedURL); |
147 // "4. Set |fallbackMode| to CORS." | 149 // "4. Set |fallbackMode| to CORS." |
148 // "5. Set |fallbackCredentials| to omit." | 150 // "5. Set |fallbackCredentials| to omit." |
149 return createRequestWithRequestData(request.release(), RequestInit(init), Fe
tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); | 151 return createRequestWithRequestData(request.release(), RequestInit(init), Fe
tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); |
150 } | 152 } |
151 | 153 |
152 | 154 |
153 PassRefPtr<Request> Request::create(ExecutionContext* context, Request* input, E
xceptionState& exceptionState) | 155 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, ExceptionState& exceptionState) |
154 { | 156 { |
155 return create(context, input, Dictionary(), exceptionState); | 157 return create(context, input, Dictionary(), exceptionState); |
156 } | 158 } |
157 | 159 |
158 PassRefPtr<Request> Request::create(ExecutionContext* context, Request* input, c
onst Dictionary& init, ExceptionState& exceptionState) | 160 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, const Dictionary& init, ExceptionState& exceptionState) |
159 { | 161 { |
160 // "1. Let |request| be |input|'s associated request, if |input| is a | 162 // "1. Let |request| be |input|'s associated request, if |input| is a |
161 // Request object, and a new request otherwise." | 163 // Request object, and a new request otherwise." |
162 // "2. Set |request| to a restricted copy of itself." | 164 // "2. Set |request| to a restricted copy of itself." |
163 RefPtr<FetchRequestData> request(input->request()->createRestrictedCopy(cont
ext, SecurityOrigin::create(context->url()))); | 165 RefPtrWillBeRawPtr<FetchRequestData> request(input->request()->createRestric
tedCopy(context, SecurityOrigin::create(context->url()))); |
164 // "3. Let |fallbackMode| be null." | 166 // "3. Let |fallbackMode| be null." |
165 // "4. Let |fallbackCredentials| be null." | 167 // "4. Let |fallbackCredentials| be null." |
166 // Instead of using null as a special fallback value, just pass the current | 168 // Instead of using null as a special fallback value, just pass the current |
167 // mode and credentials; it has the same effect. | 169 // mode and credentials; it has the same effect. |
168 const FetchRequestData::Mode currentMode = request->mode(); | 170 const FetchRequestData::Mode currentMode = request->mode(); |
169 const FetchRequestData::Credentials currentCredentials = request->credential
s(); | 171 const FetchRequestData::Credentials currentCredentials = request->credential
s(); |
170 return createRequestWithRequestData(request.release(), RequestInit(init), cu
rrentMode, currentCredentials, exceptionState); | 172 return createRequestWithRequestData(request.release(), RequestInit(init), cu
rrentMode, currentCredentials, exceptionState); |
171 } | 173 } |
172 | 174 |
173 PassRefPtr<Request> Request::create(PassRefPtr<FetchRequestData> request) | 175 PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequ
estData> request) |
174 { | 176 { |
175 return adoptRef(new Request(request)); | 177 return adoptRefWillBeNoop(new Request(request)); |
176 } | 178 } |
177 | 179 |
178 Request::Request(PassRefPtr<FetchRequestData> request) | 180 Request::Request(PassRefPtrWillBeRawPtr<FetchRequestData> request) |
179 : m_request(request) | 181 : m_request(request) |
180 , m_headers(Headers::create(m_request->headerList())) | 182 , m_headers(Headers::create(m_request->headerList())) |
181 { | 183 { |
182 m_headers->setGuard(Headers::RequestGuard); | 184 m_headers->setGuard(Headers::RequestGuard); |
183 ScriptWrappable::init(this); | 185 ScriptWrappable::init(this); |
184 } | 186 } |
185 | 187 |
186 PassRefPtr<Request> Request::create(const blink::WebServiceWorkerRequest& webReq
uest) | 188 PassRefPtrWillBeRawPtr<Request> Request::create(const blink::WebServiceWorkerReq
uest& webRequest) |
187 { | 189 { |
188 return adoptRef(new Request(webRequest)); | 190 return adoptRefWillBeNoop(new Request(webRequest)); |
189 } | 191 } |
190 | 192 |
191 Request::Request(const blink::WebServiceWorkerRequest& webRequest) | 193 Request::Request(const blink::WebServiceWorkerRequest& webRequest) |
192 : m_request(FetchRequestData::create(webRequest)) | 194 : m_request(FetchRequestData::create(webRequest)) |
193 , m_headers(Headers::create(m_request->headerList())) | 195 , m_headers(Headers::create(m_request->headerList())) |
194 { | 196 { |
195 m_headers->setGuard(Headers::RequestGuard); | 197 m_headers->setGuard(Headers::RequestGuard); |
196 ScriptWrappable::init(this); | 198 ScriptWrappable::init(this); |
197 } | 199 } |
198 | 200 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 258 |
257 PassOwnPtr<ResourceRequest> Request::createResourceRequest() const | 259 PassOwnPtr<ResourceRequest> Request::createResourceRequest() const |
258 { | 260 { |
259 OwnPtr<ResourceRequest> request = adoptPtr(new ResourceRequest(url())); | 261 OwnPtr<ResourceRequest> request = adoptPtr(new ResourceRequest(url())); |
260 request->setRequestContext(blink::WebURLRequest::RequestContextFetch); | 262 request->setRequestContext(blink::WebURLRequest::RequestContextFetch); |
261 request->setHTTPMethod("GET"); | 263 request->setHTTPMethod("GET"); |
262 // FIXME: Fill more info. | 264 // FIXME: Fill more info. |
263 return request.release(); | 265 return request.release(); |
264 } | 266 } |
265 | 267 |
| 268 void Request::trace(Visitor* visitor) |
| 269 { |
| 270 visitor->trace(m_request); |
| 271 visitor->trace(m_headers); |
| 272 } |
| 273 |
266 } // namespace WebCore | 274 } // namespace WebCore |
OLD | NEW |