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 "modules/push_messaging/PushMessageData.h" | 5 #include "modules/push_messaging/PushMessageData.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
10 #include "bindings/modules/v8/ArrayBufferOrArrayBufferViewOrUSVString.h" | 10 #include "bindings/modules/v8/ArrayBufferOrArrayBufferViewOrUSVString.h" |
11 #include "core/dom/DOMArrayBuffer.h" | 11 #include "core/dom/DOMArrayBuffer.h" |
12 #include "core/fileapi/Blob.h" | 12 #include "core/fileapi/Blob.h" |
13 #include "platform/blob/BlobData.h" | 13 #include "platform/blob/BlobData.h" |
14 #include "wtf/Assertions.h" | 14 #include "wtf/Assertions.h" |
15 #include "wtf/text/TextEncoding.h" | 15 #include "wtf/text/TextEncoding.h" |
16 | 16 #include <memory> |
17 #include <v8.h> | 17 #include <v8.h> |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 | 20 |
21 PushMessageData* PushMessageData::create(const String& messageString) | 21 PushMessageData* PushMessageData::create(const String& messageString) |
22 { | 22 { |
23 // The standard supports both an empty but valid message and a null message. | 23 // The standard supports both an empty but valid message and a null message. |
24 // In case the message is explicitly null, return a null pointer which will | 24 // In case the message is explicitly null, return a null pointer which will |
25 // be set in the PushEvent. | 25 // be set in the PushEvent. |
26 if (messageString.isNull()) | 26 if (messageString.isNull()) |
(...skipping 29 matching lines...) Expand all Loading... |
56 { | 56 { |
57 } | 57 } |
58 | 58 |
59 DOMArrayBuffer* PushMessageData::arrayBuffer() const | 59 DOMArrayBuffer* PushMessageData::arrayBuffer() const |
60 { | 60 { |
61 return DOMArrayBuffer::create(m_data.data(), m_data.size()); | 61 return DOMArrayBuffer::create(m_data.data(), m_data.size()); |
62 } | 62 } |
63 | 63 |
64 Blob* PushMessageData::blob() const | 64 Blob* PushMessageData::blob() const |
65 { | 65 { |
66 OwnPtr<BlobData> blobData = BlobData::create(); | 66 std::unique_ptr<BlobData> blobData = BlobData::create(); |
67 blobData->appendBytes(m_data.data(), m_data.size()); | 67 blobData->appendBytes(m_data.data(), m_data.size()); |
68 | 68 |
69 // Note that the content type of the Blob object is deliberately not being | 69 // Note that the content type of the Blob object is deliberately not being |
70 // provided, following the specification. | 70 // provided, following the specification. |
71 | 71 |
72 const long long byteLength = blobData->length(); | 72 const long long byteLength = blobData->length(); |
73 return Blob::create(BlobDataHandle::create(std::move(blobData), byteLength))
; | 73 return Blob::create(BlobDataHandle::create(std::move(blobData), byteLength))
; |
74 } | 74 } |
75 | 75 |
76 ScriptValue PushMessageData::json(ScriptState* scriptState, ExceptionState& exce
ptionState) const | 76 ScriptValue PushMessageData::json(ScriptState* scriptState, ExceptionState& exce
ptionState) const |
(...skipping 16 matching lines...) Expand all Loading... |
93 String PushMessageData::text() const | 93 String PushMessageData::text() const |
94 { | 94 { |
95 return UTF8Encoding().decode(m_data.data(), m_data.size()); | 95 return UTF8Encoding().decode(m_data.data(), m_data.size()); |
96 } | 96 } |
97 | 97 |
98 DEFINE_TRACE(PushMessageData) | 98 DEFINE_TRACE(PushMessageData) |
99 { | 99 { |
100 } | 100 } |
101 | 101 |
102 } // namespace blink | 102 } // namespace blink |
OLD | NEW |