Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: third_party/WebKit/Source/modules/push_messaging/PushMessageData.cpp

Issue 1878463002: Move DOMArrayBuffer, DOMArrayBufferViews and DataView to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tidy Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/UnionTypesModules.h" 10 #include "bindings/modules/v8/UnionTypesModules.h"
(...skipping 11 matching lines...) Expand all
22 // In case the message is explicitly null, return a null pointer which will 22 // In case the message is explicitly null, return a null pointer which will
23 // be set in the PushEvent. 23 // be set in the PushEvent.
24 if (messageString.isNull()) 24 if (messageString.isNull())
25 return nullptr; 25 return nullptr;
26 return PushMessageData::create(ArrayBufferOrArrayBufferViewOrUSVString::from USVString(messageString)); 26 return PushMessageData::create(ArrayBufferOrArrayBufferViewOrUSVString::from USVString(messageString));
27 } 27 }
28 28
29 PushMessageData* PushMessageData::create(const ArrayBufferOrArrayBufferViewOrUSV String& messageData) 29 PushMessageData* PushMessageData::create(const ArrayBufferOrArrayBufferViewOrUSV String& messageData)
30 { 30 {
31 if (messageData.isArrayBuffer() || messageData.isArrayBufferView()) { 31 if (messageData.isArrayBuffer() || messageData.isArrayBufferView()) {
32 RefPtr<DOMArrayBuffer> buffer = messageData.isArrayBufferView() 32 DOMArrayBuffer* buffer = messageData.isArrayBufferView()
33 ? messageData.getAsArrayBufferView()->buffer() 33 ? messageData.getAsArrayBufferView()->buffer()
34 : messageData.getAsArrayBuffer(); 34 : messageData.getAsArrayBuffer();
35 35
36 return new PushMessageData(static_cast<const char*>(buffer->data()), buf fer->byteLength()); 36 return new PushMessageData(static_cast<const char*>(buffer->data()), buf fer->byteLength());
37 } 37 }
38 38
39 if (messageData.isUSVString()) { 39 if (messageData.isUSVString()) {
40 CString encodedString = UTF8Encoding().encode(messageData.getAsUSVString (), WTF::EntitiesForUnencodables); 40 CString encodedString = UTF8Encoding().encode(messageData.getAsUSVString (), WTF::EntitiesForUnencodables);
41 return new PushMessageData(encodedString.data(), encodedString.length()) ; 41 return new PushMessageData(encodedString.data(), encodedString.length()) ;
42 } 42 }
43 43
44 ASSERT(messageData.isNull()); 44 ASSERT(messageData.isNull());
45 return nullptr; 45 return nullptr;
46 } 46 }
47 47
48 PushMessageData::PushMessageData(const char* data, unsigned bytesSize) 48 PushMessageData::PushMessageData(const char* data, unsigned bytesSize)
49 { 49 {
50 m_data.append(data, bytesSize); 50 m_data.append(data, bytesSize);
51 } 51 }
52 52
53 PushMessageData::~PushMessageData() 53 PushMessageData::~PushMessageData()
54 { 54 {
55 } 55 }
56 56
57 PassRefPtr<DOMArrayBuffer> PushMessageData::arrayBuffer() const 57 DOMArrayBuffer* PushMessageData::arrayBuffer() const
58 { 58 {
59 return DOMArrayBuffer::create(m_data.data(), m_data.size()); 59 return DOMArrayBuffer::create(m_data.data(), m_data.size());
60 } 60 }
61 61
62 Blob* PushMessageData::blob() const 62 Blob* PushMessageData::blob() const
63 { 63 {
64 OwnPtr<BlobData> blobData = BlobData::create(); 64 OwnPtr<BlobData> blobData = BlobData::create();
65 blobData->appendBytes(m_data.data(), m_data.size()); 65 blobData->appendBytes(m_data.data(), m_data.size());
66 66
67 // Note that the content type of the Blob object is deliberately not being 67 // Note that the content type of the Blob object is deliberately not being
(...skipping 23 matching lines...) Expand all
91 String PushMessageData::text() const 91 String PushMessageData::text() const
92 { 92 {
93 return UTF8Encoding().decode(m_data.data(), m_data.size()); 93 return UTF8Encoding().decode(m_data.data(), m_data.size());
94 } 94 }
95 95
96 DEFINE_TRACE(PushMessageData) 96 DEFINE_TRACE(PushMessageData)
97 { 97 {
98 } 98 }
99 99
100 } // namespace blink 100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698