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 "modules/presentation/PresentationConnection.h" | 6 #include "modules/presentation/PresentationConnection.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/DOMArrayBufferView.h" | 10 #include "core/dom/DOMArrayBufferView.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 ASSERT(arrayBuffer && arrayBuffer->buffer()); | 196 ASSERT(arrayBuffer && arrayBuffer->buffer()); |
197 if (!canSendMessage(exceptionState)) | 197 if (!canSendMessage(exceptionState)) |
198 return; | 198 return; |
199 | 199 |
200 m_messages.append(adoptPtr(new Message(arrayBuffer))); | 200 m_messages.append(adoptPtr(new Message(arrayBuffer))); |
201 handleMessageQueue(); | 201 handleMessageQueue(); |
202 } | 202 } |
203 | 203 |
204 void PresentationConnection::send(PassRefPtr<DOMArrayBufferView> arrayBufferView
, ExceptionState& exceptionState) | 204 void PresentationConnection::send(PassRefPtr<DOMArrayBufferView> arrayBufferView
, ExceptionState& exceptionState) |
205 { | 205 { |
206 ASSERT(arrayBufferView); | 206 ASSERT(arrayBufferView && arrayBufferView->bufferOrNull()); |
207 if (!canSendMessage(exceptionState)) | 207 if (!canSendMessage(exceptionState)) |
208 return; | 208 return; |
209 | 209 |
210 m_messages.append(adoptPtr(new Message(arrayBufferView->buffer()))); | 210 m_messages.append(adoptPtr(new Message(arrayBufferView->bufferOrNull()))); |
211 handleMessageQueue(); | 211 handleMessageQueue(); |
212 } | 212 } |
213 | 213 |
214 void PresentationConnection::send(Blob* data, ExceptionState& exceptionState) | 214 void PresentationConnection::send(Blob* data, ExceptionState& exceptionState) |
215 { | 215 { |
216 ASSERT(data); | 216 ASSERT(data); |
217 if (!canSendMessage(exceptionState)) | 217 if (!canSendMessage(exceptionState)) |
218 return; | 218 return; |
219 | 219 |
220 m_messages.append(adoptPtr(new Message(data->blobDataHandle()))); | 220 m_messages.append(adoptPtr(new Message(data->blobDataHandle()))); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 297 |
298 switch (m_binaryType) { | 298 switch (m_binaryType) { |
299 case BinaryTypeBlob: { | 299 case BinaryTypeBlob: { |
300 OwnPtr<BlobData> blobData = BlobData::create(); | 300 OwnPtr<BlobData> blobData = BlobData::create(); |
301 blobData->appendBytes(data, length); | 301 blobData->appendBytes(data, length); |
302 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len
gth)); | 302 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len
gth)); |
303 dispatchEvent(MessageEvent::create(blob)); | 303 dispatchEvent(MessageEvent::create(blob)); |
304 return; | 304 return; |
305 } | 305 } |
306 case BinaryTypeArrayBuffer: | 306 case BinaryTypeArrayBuffer: |
307 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); | 307 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::createOrNull(data, lengt
h); |
308 dispatchEvent(MessageEvent::create(buffer.release())); | 308 // Can't throw a RangeError exception from here, so being out |
309 return; | 309 // of memory will fail silently by dropping the message. |
| 310 if (buffer) |
| 311 dispatchEvent(MessageEvent::create(buffer.release())); |
310 } | 312 } |
311 ASSERT_NOT_REACHED(); | 313 ASSERT_NOT_REACHED(); |
312 } | 314 } |
313 | 315 |
314 void PresentationConnection::close() | 316 void PresentationConnection::close() |
315 { | 317 { |
316 if (m_state != WebPresentationConnectionState::Connected) | 318 if (m_state != WebPresentationConnectionState::Connected) |
317 return; | 319 return; |
318 WebPresentationClient* client = presentationClient(executionContext()); | 320 WebPresentationClient* client = presentationClient(executionContext()); |
319 if (client) | 321 if (client) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 { | 364 { |
363 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; | 365 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; |
364 // FIXME: generate error message? | 366 // FIXME: generate error message? |
365 // Ignore the current failed blob item and continue with next items. | 367 // Ignore the current failed blob item and continue with next items. |
366 m_messages.removeFirst(); | 368 m_messages.removeFirst(); |
367 m_blobLoader.clear(); | 369 m_blobLoader.clear(); |
368 handleMessageQueue(); | 370 handleMessageQueue(); |
369 } | 371 } |
370 | 372 |
371 } // namespace blink | 373 } // namespace blink |
OLD | NEW |