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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 { | 73 { |
74 m_loader.start(m_PresentationConnection->executionContext(), blobDataHan
dle); | 74 m_loader.start(m_PresentationConnection->executionContext(), blobDataHan
dle); |
75 } | 75 } |
76 ~BlobLoader() override { } | 76 ~BlobLoader() override { } |
77 | 77 |
78 // FileReaderLoaderClient functions. | 78 // FileReaderLoaderClient functions. |
79 void didStartLoading() override { } | 79 void didStartLoading() override { } |
80 void didReceiveData() override { } | 80 void didReceiveData() override { } |
81 void didFinishLoading() override | 81 void didFinishLoading() override |
82 { | 82 { |
83 m_PresentationConnection->didFinishLoadingBlob(m_loader.arrayBufferResul
t()); | 83 m_PresentationConnection->didFinishLoadingBlob(m_loader.arrayBufferResul
tOrNull()); |
84 } | 84 } |
85 void didFail(FileError::ErrorCode errorCode) override | 85 void didFail(FileError::ErrorCode errorCode) override |
86 { | 86 { |
87 m_PresentationConnection->didFailLoadingBlob(errorCode); | 87 m_PresentationConnection->didFailLoadingBlob(errorCode); |
88 } | 88 } |
89 | 89 |
90 void cancel() | 90 void cancel() |
91 { | 91 { |
92 m_loader.cancel(); | 92 m_loader.cancel(); |
93 } | 93 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
207 if (!canSendMessage(exceptionState)) | 207 if (!canSendMessage(exceptionState)) |
208 return; | 208 return; |
209 | 209 |
210 m_messages.append(adoptPtr(new Message(arrayBufferView->buffer()))); | 210 RefPtr<DOMArrayBuffer> buffer = arrayBufferView->buffer(); |
| 211 m_messages.append(adoptPtr(new Message(buffer))); |
211 handleMessageQueue(); | 212 handleMessageQueue(); |
212 } | 213 } |
213 | 214 |
214 void PresentationConnection::send(Blob* data, ExceptionState& exceptionState) | 215 void PresentationConnection::send(Blob* data, ExceptionState& exceptionState) |
215 { | 216 { |
216 ASSERT(data); | 217 ASSERT(data); |
217 if (!canSendMessage(exceptionState)) | 218 if (!canSendMessage(exceptionState)) |
218 return; | 219 return; |
219 | 220 |
220 m_messages.append(adoptPtr(new Message(data->blobDataHandle()))); | 221 m_messages.append(adoptPtr(new Message(data->blobDataHandle()))); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 298 |
298 switch (m_binaryType) { | 299 switch (m_binaryType) { |
299 case BinaryTypeBlob: { | 300 case BinaryTypeBlob: { |
300 OwnPtr<BlobData> blobData = BlobData::create(); | 301 OwnPtr<BlobData> blobData = BlobData::create(); |
301 blobData->appendBytes(data, length); | 302 blobData->appendBytes(data, length); |
302 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len
gth)); | 303 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len
gth)); |
303 dispatchEvent(MessageEvent::create(blob)); | 304 dispatchEvent(MessageEvent::create(blob)); |
304 return; | 305 return; |
305 } | 306 } |
306 case BinaryTypeArrayBuffer: | 307 case BinaryTypeArrayBuffer: |
307 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); | 308 // TODO(junov): crbug.com/536816 |
| 309 // Use createOrNull instead of deprecatedCReateOrCrash. Requires |
| 310 // determining an acceptable alternative to crashing when buffer |
| 311 // allocation fails. Should we just drop the event? Dispatch |
| 312 // an event with null data? Dispatch some kind of error code? |
| 313 // Behavior needs to be defined in the spec. |
| 314 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::deprecatedCreateOrCrash(
data, length); |
308 dispatchEvent(MessageEvent::create(buffer.release())); | 315 dispatchEvent(MessageEvent::create(buffer.release())); |
309 return; | 316 return; |
310 } | 317 } |
311 ASSERT_NOT_REACHED(); | 318 ASSERT_NOT_REACHED(); |
312 } | 319 } |
313 | 320 |
314 void PresentationConnection::close() | 321 void PresentationConnection::close() |
315 { | 322 { |
316 if (m_state != WebPresentationConnectionState::Connected) | 323 if (m_state != WebPresentationConnectionState::Connected) |
317 return; | 324 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 { | 369 { |
363 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; | 370 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; |
364 // FIXME: generate error message? | 371 // FIXME: generate error message? |
365 // Ignore the current failed blob item and continue with next items. | 372 // Ignore the current failed blob item and continue with next items. |
366 m_messages.removeFirst(); | 373 m_messages.removeFirst(); |
367 m_blobLoader.clear(); | 374 m_blobLoader.clear(); |
368 handleMessageQueue(); | 375 handleMessageQueue(); |
369 } | 376 } |
370 | 377 |
371 } // namespace blink | 378 } // namespace blink |
OLD | NEW |