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

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp

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

Powered by Google App Engine
This is Rietveld 408576698