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

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationConnection.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/presentation/PresentationConnection.h" 5 #include "modules/presentation/PresentationConnection.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "core/dom/DOMArrayBuffer.h" 8 #include "core/dom/DOMArrayBuffer.h"
9 #include "core/dom/DOMArrayBufferView.h" 9 #include "core/dom/DOMArrayBufferView.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return errorValue; 81 return errorValue;
82 } 82 }
83 83
84 void throwPresentationDisconnectedError(ExceptionState& exceptionState) 84 void throwPresentationDisconnectedError(ExceptionState& exceptionState)
85 { 85 {
86 exceptionState.throwDOMException(InvalidStateError, "Presentation connection is disconnected."); 86 exceptionState.throwDOMException(InvalidStateError, "Presentation connection is disconnected.");
87 } 87 }
88 88
89 } // namespace 89 } // namespace
90 90
91 class PresentationConnection::Message final : public GarbageCollectedFinalized<P resentationConnection::Message> {
92 public:
93 Message(const String& text)
94 : type(MessageTypeText)
95 , text(text)
96 {
97 }
98
99 Message(DOMArrayBuffer* arrayBuffer)
100 : type(MessageTypeArrayBuffer)
101 , arrayBuffer(arrayBuffer)
102 {
103 }
104
105 Message(PassRefPtr<BlobDataHandle> blobDataHandle)
106 : type(MessageTypeBlob)
107 , blobDataHandle(blobDataHandle)
108 {
109 }
110
111 DEFINE_INLINE_TRACE()
112 {
113 visitor->trace(arrayBuffer);
114 }
115
116 MessageType type;
117 String text;
118 Member<DOMArrayBuffer> arrayBuffer;
119 RefPtr<BlobDataHandle> blobDataHandle;
120 };
121
91 class PresentationConnection::BlobLoader final : public GarbageCollectedFinalize d<PresentationConnection::BlobLoader>, public FileReaderLoaderClient { 122 class PresentationConnection::BlobLoader final : public GarbageCollectedFinalize d<PresentationConnection::BlobLoader>, public FileReaderLoaderClient {
92 public: 123 public:
93 BlobLoader(PassRefPtr<BlobDataHandle> blobDataHandle, PresentationConnection * PresentationConnection) 124 BlobLoader(PassRefPtr<BlobDataHandle> blobDataHandle, PresentationConnection * PresentationConnection)
94 : m_PresentationConnection(PresentationConnection) 125 : m_PresentationConnection(PresentationConnection)
95 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) 126 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this)
96 { 127 {
97 m_loader.start(m_PresentationConnection->getExecutionContext(), blobData Handle); 128 m_loader.start(m_PresentationConnection->getExecutionContext(), blobData Handle);
98 } 129 }
99 ~BlobLoader() override { } 130 ~BlobLoader() override { }
100 131
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect ionTerminateEventListener); 226 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect ionTerminateEventListener);
196 else if (eventType == EventTypeNames::message) 227 else if (eventType == EventTypeNames::message)
197 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect ionMessageEventListener); 228 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect ionMessageEventListener);
198 229
199 return EventTarget::addEventListenerInternal(eventType, listener, options); 230 return EventTarget::addEventListenerInternal(eventType, listener, options);
200 } 231 }
201 232
202 DEFINE_TRACE(PresentationConnection) 233 DEFINE_TRACE(PresentationConnection)
203 { 234 {
204 visitor->trace(m_blobLoader); 235 visitor->trace(m_blobLoader);
236 visitor->trace(m_messages);
205 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationConnection>: :trace(visitor); 237 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationConnection>: :trace(visitor);
206 DOMWindowProperty::trace(visitor); 238 DOMWindowProperty::trace(visitor);
207 } 239 }
208 240
209 const AtomicString& PresentationConnection::state() const 241 const AtomicString& PresentationConnection::state() const
210 { 242 {
211 return connectionStateToString(m_state); 243 return connectionStateToString(m_state);
212 } 244 }
213 245
214 void PresentationConnection::send(const String& message, ExceptionState& excepti onState) 246 void PresentationConnection::send(const String& message, ExceptionState& excepti onState)
215 { 247 {
216 if (!canSendMessage(exceptionState)) 248 if (!canSendMessage(exceptionState))
217 return; 249 return;
218 250
219 m_messages.append(adoptPtr(new Message(message))); 251 m_messages.append(new Message(message));
220 handleMessageQueue(); 252 handleMessageQueue();
221 } 253 }
222 254
223 void PresentationConnection::send(PassRefPtr<DOMArrayBuffer> arrayBuffer, Except ionState& exceptionState) 255 void PresentationConnection::send(DOMArrayBuffer* arrayBuffer, ExceptionState& e xceptionState)
224 { 256 {
225 ASSERT(arrayBuffer && arrayBuffer->buffer()); 257 ASSERT(arrayBuffer && arrayBuffer->buffer());
226 if (!canSendMessage(exceptionState)) 258 if (!canSendMessage(exceptionState))
227 return; 259 return;
228 260
229 m_messages.append(adoptPtr(new Message(arrayBuffer))); 261 m_messages.append(new Message(arrayBuffer));
230 handleMessageQueue(); 262 handleMessageQueue();
231 } 263 }
232 264
233 void PresentationConnection::send(PassRefPtr<DOMArrayBufferView> arrayBufferView , ExceptionState& exceptionState) 265 void PresentationConnection::send(DOMArrayBufferView* arrayBufferView, Exception State& exceptionState)
234 { 266 {
235 ASSERT(arrayBufferView); 267 ASSERT(arrayBufferView);
236 if (!canSendMessage(exceptionState)) 268 if (!canSendMessage(exceptionState))
237 return; 269 return;
238 270
239 m_messages.append(adoptPtr(new Message(arrayBufferView->buffer()))); 271 m_messages.append(new Message(arrayBufferView->buffer()));
240 handleMessageQueue(); 272 handleMessageQueue();
241 } 273 }
242 274
243 void PresentationConnection::send(Blob* data, ExceptionState& exceptionState) 275 void PresentationConnection::send(Blob* data, ExceptionState& exceptionState)
244 { 276 {
245 ASSERT(data); 277 ASSERT(data);
246 if (!canSendMessage(exceptionState)) 278 if (!canSendMessage(exceptionState))
247 return; 279 return;
248 280
249 m_messages.append(adoptPtr(new Message(data->blobDataHandle()))); 281 m_messages.append(new Message(data->blobDataHandle()));
250 handleMessageQueue(); 282 handleMessageQueue();
251 } 283 }
252 284
253 bool PresentationConnection::canSendMessage(ExceptionState& exceptionState) 285 bool PresentationConnection::canSendMessage(ExceptionState& exceptionState)
254 { 286 {
255 if (m_state != WebPresentationConnectionState::Connected) { 287 if (m_state != WebPresentationConnectionState::Connected) {
256 throwPresentationDisconnectedError(exceptionState); 288 throwPresentationDisconnectedError(exceptionState);
257 return false; 289 return false;
258 } 290 }
259 291
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 358
327 switch (m_binaryType) { 359 switch (m_binaryType) {
328 case BinaryTypeBlob: { 360 case BinaryTypeBlob: {
329 OwnPtr<BlobData> blobData = BlobData::create(); 361 OwnPtr<BlobData> blobData = BlobData::create();
330 blobData->appendBytes(data, length); 362 blobData->appendBytes(data, length);
331 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth)); 363 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth));
332 dispatchEvent(MessageEvent::create(blob)); 364 dispatchEvent(MessageEvent::create(blob));
333 return; 365 return;
334 } 366 }
335 case BinaryTypeArrayBuffer: 367 case BinaryTypeArrayBuffer:
336 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); 368 DOMArrayBuffer* buffer = DOMArrayBuffer::create(data, length);
337 dispatchEvent(MessageEvent::create(buffer.release())); 369 dispatchEvent(MessageEvent::create(buffer));
338 return; 370 return;
339 } 371 }
340 ASSERT_NOT_REACHED(); 372 ASSERT_NOT_REACHED();
341 } 373 }
342 374
343 void PresentationConnection::close() 375 void PresentationConnection::close()
344 { 376 {
345 if (m_state != WebPresentationConnectionState::Connected) 377 if (m_state != WebPresentationConnectionState::Connected)
346 return; 378 return;
347 WebPresentationClient* client = presentationClient(getExecutionContext()); 379 WebPresentationClient* client = presentationClient(getExecutionContext());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 422
391 void PresentationConnection::didClose(WebPresentationConnectionCloseReason reaso n, const String& message) 423 void PresentationConnection::didClose(WebPresentationConnectionCloseReason reaso n, const String& message)
392 { 424 {
393 if (m_state == WebPresentationConnectionState::Closed) 425 if (m_state == WebPresentationConnectionState::Closed)
394 return; 426 return;
395 427
396 m_state = WebPresentationConnectionState::Closed; 428 m_state = WebPresentationConnectionState::Closed;
397 dispatchEvent(PresentationConnectionCloseEvent::create(EventTypeNames::close , connectionCloseReasonToString(reason), message)); 429 dispatchEvent(PresentationConnectionCloseEvent::create(EventTypeNames::close , connectionCloseReasonToString(reason), message));
398 } 430 }
399 431
400 void PresentationConnection::didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer> buf fer) 432 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer)
401 { 433 {
402 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob) ; 434 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob) ;
403 ASSERT(buffer && buffer->buffer()); 435 ASSERT(buffer && buffer->buffer());
404 // Send the loaded blob immediately here and continue processing the queue. 436 // Send the loaded blob immediately here and continue processing the queue.
405 WebPresentationClient* client = presentationClient(getExecutionContext()); 437 WebPresentationClient* client = presentationClient(getExecutionContext());
406 if (client) 438 if (client)
407 client->sendBlobData(m_url, m_id, static_cast<const uint8_t*>(buffer->da ta()), buffer->byteLength()); 439 client->sendBlobData(m_url, m_id, static_cast<const uint8_t*>(buffer->da ta()), buffer->byteLength());
408 440
409 m_messages.removeFirst(); 441 m_messages.removeFirst();
410 m_blobLoader.clear(); 442 m_blobLoader.clear();
(...skipping 10 matching lines...) Expand all
421 handleMessageQueue(); 453 handleMessageQueue();
422 } 454 }
423 455
424 void PresentationConnection::tearDown() 456 void PresentationConnection::tearDown()
425 { 457 {
426 // Cancel current Blob loading if any. 458 // Cancel current Blob loading if any.
427 if (m_blobLoader) { 459 if (m_blobLoader) {
428 m_blobLoader->cancel(); 460 m_blobLoader->cancel();
429 m_blobLoader.clear(); 461 m_blobLoader.clear();
430 } 462 }
431 463 m_messages.clear();
432 // Clear message queue.
433 Deque<OwnPtr<Message>> empty;
434 m_messages.swap(empty);
435 } 464 }
436 465
437 } // namespace blink 466 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698