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 "core/loader/BeaconLoader.h" | 6 #include "core/loader/BeaconLoader.h" |
7 | 7 |
8 #include "core/dom/DOMArrayBufferView.h" | 8 #include "core/dom/DOMArrayBufferView.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/fetch/CrossOriginAccessControl.h" | 10 #include "core/fetch/CrossOriginAccessControl.h" |
11 #include "core/fetch/FetchContext.h" | 11 #include "core/fetch/FetchContext.h" |
12 #include "core/fetch/FetchInitiatorTypeNames.h" | 12 #include "core/fetch/FetchInitiatorTypeNames.h" |
13 #include "core/fetch/ResourceFetcher.h" | 13 #include "core/fetch/ResourceFetcher.h" |
14 #include "core/fileapi/File.h" | 14 #include "core/fileapi/File.h" |
15 #include "core/frame/LocalFrame.h" | 15 #include "core/frame/LocalFrame.h" |
16 #include "core/html/DOMFormData.h" | 16 #include "core/html/DOMFormData.h" |
17 #include "core/inspector/ConsoleMessage.h" | 17 #include "core/inspector/ConsoleMessage.h" |
18 #include "core/loader/MixedContentChecker.h" | 18 #include "core/loader/MixedContentChecker.h" |
19 #include "platform/exported/WrappedResourceRequest.h" | 19 #include "platform/exported/WrappedResourceRequest.h" |
20 #include "platform/exported/WrappedResourceResponse.h" | 20 #include "platform/exported/WrappedResourceResponse.h" |
21 #include "platform/network/FormData.h" | 21 #include "platform/network/EncodedFormData.h" |
22 #include "platform/network/ParsedContentType.h" | 22 #include "platform/network/ParsedContentType.h" |
23 #include "platform/network/ResourceRequest.h" | 23 #include "platform/network/ResourceRequest.h" |
24 #include "public/platform/WebURLRequest.h" | 24 #include "public/platform/WebURLRequest.h" |
25 #include "wtf/Functional.h" | 25 #include "wtf/Functional.h" |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 class Beacon { | 31 class Beacon { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 namespace { | 163 namespace { |
164 | 164 |
165 unsigned long long Beacon::beaconSize(const String& data) | 165 unsigned long long Beacon::beaconSize(const String& data) |
166 { | 166 { |
167 return data.sizeInBytes(); | 167 return data.sizeInBytes(); |
168 } | 168 } |
169 | 169 |
170 bool Beacon::serialize(const String& data, ResourceRequest& request, int, int&) | 170 bool Beacon::serialize(const String& data, ResourceRequest& request, int, int&) |
171 { | 171 { |
172 RefPtr<FormData> entityBody = FormData::create(data.utf8()); | 172 RefPtr<EncodedFormData> entityBody = EncodedFormData::create(data.utf8()); |
173 request.setHTTPBody(entityBody); | 173 request.setHTTPBody(entityBody); |
174 request.setHTTPContentType("text/plain;charset=UTF-8"); | 174 request.setHTTPContentType("text/plain;charset=UTF-8"); |
175 return true; | 175 return true; |
176 } | 176 } |
177 | 177 |
178 unsigned long long Beacon::beaconSize(Blob* data) | 178 unsigned long long Beacon::beaconSize(Blob* data) |
179 { | 179 { |
180 return data->size(); | 180 return data->size(); |
181 } | 181 } |
182 | 182 |
183 bool Beacon::serialize(Blob* data, ResourceRequest& request, int, int&) | 183 bool Beacon::serialize(Blob* data, ResourceRequest& request, int, int&) |
184 { | 184 { |
185 ASSERT(data); | 185 ASSERT(data); |
186 RefPtr<FormData> entityBody = FormData::create(); | 186 RefPtr<EncodedFormData> entityBody = EncodedFormData::create(); |
187 if (data->hasBackingFile()) | 187 if (data->hasBackingFile()) |
188 entityBody->appendFile(toFile(data)->path()); | 188 entityBody->appendFile(toFile(data)->path()); |
189 else | 189 else |
190 entityBody->appendBlob(data->uuid(), data->blobDataHandle()); | 190 entityBody->appendBlob(data->uuid(), data->blobDataHandle()); |
191 | 191 |
192 request.setHTTPBody(entityBody.release()); | 192 request.setHTTPBody(entityBody.release()); |
193 | 193 |
194 const String& blobType = data->type(); | 194 const String& blobType = data->type(); |
195 if (!blobType.isEmpty() && isValidContentType(blobType)) | 195 if (!blobType.isEmpty() && isValidContentType(blobType)) |
196 request.setHTTPContentType(AtomicString(blobType)); | 196 request.setHTTPContentType(AtomicString(blobType)); |
197 | 197 |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 unsigned long long Beacon::beaconSize(PassRefPtr<DOMArrayBufferView> data) | 201 unsigned long long Beacon::beaconSize(PassRefPtr<DOMArrayBufferView> data) |
202 { | 202 { |
203 return data->byteLength(); | 203 return data->byteLength(); |
204 } | 204 } |
205 | 205 |
206 bool Beacon::serialize(PassRefPtr<DOMArrayBufferView> data, ResourceRequest& req
uest, int, int&) | 206 bool Beacon::serialize(PassRefPtr<DOMArrayBufferView> data, ResourceRequest& req
uest, int, int&) |
207 { | 207 { |
208 ASSERT(data); | 208 ASSERT(data); |
209 RefPtr<FormData> entityBody = FormData::create(data->baseAddress(), data->by
teLength()); | 209 RefPtr<EncodedFormData> entityBody = EncodedFormData::create(data->baseAddre
ss(), data->byteLength()); |
210 request.setHTTPBody(entityBody.release()); | 210 request.setHTTPBody(entityBody.release()); |
211 | 211 |
212 // FIXME: a reasonable choice, but not in the spec; should it give a default
? | 212 // FIXME: a reasonable choice, but not in the spec; should it give a default
? |
213 AtomicString contentType = AtomicString("application/octet-stream"); | 213 AtomicString contentType = AtomicString("application/octet-stream"); |
214 request.setHTTPContentType(contentType); | 214 request.setHTTPContentType(contentType); |
215 | 215 |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 unsigned long long Beacon::beaconSize(DOMFormData* data) | 219 unsigned long long Beacon::beaconSize(DOMFormData* data) |
220 { | 220 { |
221 // DOMFormData's size cannot be determined until serialized. | 221 // DOMFormData's size cannot be determined until serialized. |
222 return 0; | 222 return 0; |
223 } | 223 } |
224 | 224 |
225 bool Beacon::serialize(DOMFormData* data, ResourceRequest& request, int allowanc
e, int& payloadLength) | 225 bool Beacon::serialize(DOMFormData* data, ResourceRequest& request, int allowanc
e, int& payloadLength) |
226 { | 226 { |
227 ASSERT(data); | 227 ASSERT(data); |
228 RefPtr<FormData> entityBody = data->createMultiPartFormData(); | 228 RefPtr<EncodedFormData> entityBody = data->createMultiPartFormData(); |
229 unsigned long long entitySize = entityBody->sizeInBytes(); | 229 unsigned long long entitySize = entityBody->sizeInBytes(); |
230 if (allowance > 0 && static_cast<unsigned long long>(allowance) < entitySize
) | 230 if (allowance > 0 && static_cast<unsigned long long>(allowance) < entitySize
) |
231 return false; | 231 return false; |
232 | 232 |
233 AtomicString contentType = AtomicString("multipart/form-data; boundary=", At
omicString::ConstructFromLiteral) + entityBody->boundary().data(); | 233 AtomicString contentType = AtomicString("multipart/form-data; boundary=", At
omicString::ConstructFromLiteral) + entityBody->boundary().data(); |
234 request.setHTTPBody(entityBody.release()); | 234 request.setHTTPBody(entityBody.release()); |
235 request.setHTTPContentType(contentType); | 235 request.setHTTPContentType(contentType); |
236 | 236 |
237 payloadLength = entitySize; | 237 payloadLength = entitySize; |
238 return true; | 238 return true; |
239 } | 239 } |
240 | 240 |
241 } // namespace | 241 } // namespace |
242 | 242 |
243 } // namespace blink | 243 } // namespace blink |
OLD | NEW |