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/FormData.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/EncodedFormData.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 { |
32 public: | 32 public: |
33 virtual bool serialize(ResourceRequest&, int, int&) const = 0; | 33 virtual bool serialize(ResourceRequest&, int, int&) const = 0; |
34 virtual unsigned long long size() const = 0; | 34 virtual unsigned long long size() const = 0; |
35 | 35 |
36 protected: | 36 protected: |
37 static unsigned long long beaconSize(const String&); | 37 static unsigned long long beaconSize(const String&); |
38 static unsigned long long beaconSize(Blob*); | 38 static unsigned long long beaconSize(Blob*); |
39 static unsigned long long beaconSize(PassRefPtr<DOMArrayBufferView>); | 39 static unsigned long long beaconSize(PassRefPtr<DOMArrayBufferView>); |
40 static unsigned long long beaconSize(DOMFormData*); | 40 static unsigned long long beaconSize(FormData*); |
41 | 41 |
42 static bool serialize(const String&, ResourceRequest&, int, int&); | 42 static bool serialize(const String&, ResourceRequest&, int, int&); |
43 static bool serialize(Blob*, ResourceRequest&, int, int&); | 43 static bool serialize(Blob*, ResourceRequest&, int, int&); |
44 static bool serialize(PassRefPtr<DOMArrayBufferView>, ResourceRequest&, int,
int&); | 44 static bool serialize(PassRefPtr<DOMArrayBufferView>, ResourceRequest&, int,
int&); |
45 static bool serialize(DOMFormData*, ResourceRequest&, int, int&); | 45 static bool serialize(FormData*, ResourceRequest&, int, int&); |
46 }; | 46 }; |
47 | 47 |
48 template<typename Payload> | 48 template<typename Payload> |
49 class BeaconData final : public Beacon { | 49 class BeaconData final : public Beacon { |
50 public: | 50 public: |
51 BeaconData(const Payload& data) | 51 BeaconData(const Payload& data) |
52 : m_data(data) | 52 : m_data(data) |
53 { | 53 { |
54 } | 54 } |
55 | 55 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 BeaconData<decltype(data)> beacon(data); | 110 BeaconData<decltype(data)> beacon(data); |
111 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); | 111 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); |
112 } | 112 } |
113 | 113 |
114 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, PassRefPtr<DOMArrayBufferView> data, int& payloadLength) | 114 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, PassRefPtr<DOMArrayBufferView> data, int& payloadLength) |
115 { | 115 { |
116 BeaconData<decltype(data)> beacon(data); | 116 BeaconData<decltype(data)> beacon(data); |
117 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); | 117 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); |
118 } | 118 } |
119 | 119 |
120 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, DOMFormData* data, int& payloadLength) | 120 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, FormData* data, int& payloadLength) |
121 { | 121 { |
122 BeaconData<decltype(data)> beacon(data); | 122 BeaconData<decltype(data)> beacon(data); |
123 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); | 123 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); |
124 } | 124 } |
125 | 125 |
126 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, Blob* data, int& payloadLength) | 126 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, Blob* data, int& payloadLength) |
127 { | 127 { |
128 BeaconData<decltype(data)> beacon(data); | 128 BeaconData<decltype(data)> beacon(data); |
129 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); | 129 return Sender::send(frame, allowance, beaconURL, beacon, payloadLength); |
130 } | 130 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 RefPtr<EncodedFormData> entityBody = EncodedFormData::create(data->baseAddre
ss(), data->byteLength()); | 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(FormData*) |
220 { | 220 { |
221 // DOMFormData's size cannot be determined until serialized. | 221 // FormData'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(FormData* data, ResourceRequest& request, int allowance,
int& payloadLength) |
226 { | 226 { |
227 ASSERT(data); | 227 ASSERT(data); |
228 RefPtr<EncodedFormData> 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 |