| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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(PassRefPtrWillBeRawPtr<DOMFormData>); | 40 static unsigned long long beaconSize(DOMFormData*); |
| 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(PassRefPtrWillBeRawPtr<DOMFormData>, ResourceRequest&,
int, int&); | 45 static bool serialize(DOMFormData*, 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, PassRefPtrWillBeRawPtr<DOMFormData> data, int& payloadLength) | 120 bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
onURL, DOMFormData* 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 RefPtr<FormData> entityBody = FormData::create(data->baseAddress(), data->by
teLength()); | 212 RefPtr<FormData> entityBody = FormData::create(data->baseAddress(), data->by
teLength()); |
| 213 request.setHTTPBody(entityBody.release()); | 213 request.setHTTPBody(entityBody.release()); |
| 214 | 214 |
| 215 // FIXME: a reasonable choice, but not in the spec; should it give a default
? | 215 // FIXME: a reasonable choice, but not in the spec; should it give a default
? |
| 216 AtomicString contentType = AtomicString("application/octet-stream"); | 216 AtomicString contentType = AtomicString("application/octet-stream"); |
| 217 request.setHTTPContentType(contentType); | 217 request.setHTTPContentType(contentType); |
| 218 | 218 |
| 219 return true; | 219 return true; |
| 220 } | 220 } |
| 221 | 221 |
| 222 unsigned long long Beacon::beaconSize(PassRefPtrWillBeRawPtr<DOMFormData> data) | 222 unsigned long long Beacon::beaconSize(DOMFormData* data) |
| 223 { | 223 { |
| 224 // DOMFormData's size cannot be determined until serialized. | 224 // DOMFormData's size cannot be determined until serialized. |
| 225 return 0; | 225 return 0; |
| 226 } | 226 } |
| 227 | 227 |
| 228 bool Beacon::serialize(PassRefPtrWillBeRawPtr<DOMFormData> data, ResourceRequest
& request, int allowance, int& payloadLength) | 228 bool Beacon::serialize(DOMFormData* data, ResourceRequest& request, int allowanc
e, int& payloadLength) |
| 229 { | 229 { |
| 230 ASSERT(data); | 230 ASSERT(data); |
| 231 RefPtr<FormData> entityBody = data->createMultiPartFormData(); | 231 RefPtr<FormData> entityBody = data->createMultiPartFormData(); |
| 232 unsigned long long entitySize = entityBody->sizeInBytes(); | 232 unsigned long long entitySize = entityBody->sizeInBytes(); |
| 233 if (allowance > 0 && static_cast<unsigned long long>(allowance) < entitySize
) | 233 if (allowance > 0 && static_cast<unsigned long long>(allowance) < entitySize
) |
| 234 return false; | 234 return false; |
| 235 | 235 |
| 236 AtomicString contentType = AtomicString("multipart/form-data; boundary=", At
omicString::ConstructFromLiteral) + entityBody->boundary().data(); | 236 AtomicString contentType = AtomicString("multipart/form-data; boundary=", At
omicString::ConstructFromLiteral) + entityBody->boundary().data(); |
| 237 request.setHTTPBody(entityBody.release()); | 237 request.setHTTPBody(entityBody.release()); |
| 238 request.setHTTPContentType(contentType); | 238 request.setHTTPContentType(contentType); |
| 239 | 239 |
| 240 payloadLength = entitySize; | 240 payloadLength = entitySize; |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace | 244 } // namespace |
| 245 | 245 |
| 246 } // namespace blink | 246 } // namespace blink |
| OLD | NEW |