| 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 "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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 void PresentationConnection::handleMessageQueue() { | 312 void PresentationConnection::handleMessageQueue() { |
| 313 WebPresentationClient* client = presentationClient(getExecutionContext()); | 313 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 314 if (!client || !m_proxy) | 314 if (!client || !m_proxy) |
| 315 return; | 315 return; |
| 316 | 316 |
| 317 while (!m_messages.isEmpty() && !m_blobLoader) { | 317 while (!m_messages.isEmpty() && !m_blobLoader) { |
| 318 Message* message = m_messages.first().get(); | 318 Message* message = m_messages.first().get(); |
| 319 switch (message->type) { | 319 switch (message->type) { |
| 320 case MessageTypeText: | 320 case MessageTypeText: |
| 321 client->sendString(m_url, m_id, message->text, m_proxy.get()); | 321 client->sendString(m_url, m_id, message->text, m_proxy.get()); |
| 322 m_messages.removeFirst(); | 322 m_messages.pop_front(); |
| 323 break; | 323 break; |
| 324 case MessageTypeArrayBuffer: | 324 case MessageTypeArrayBuffer: |
| 325 client->sendArrayBuffer( | 325 client->sendArrayBuffer( |
| 326 m_url, m_id, | 326 m_url, m_id, |
| 327 static_cast<const uint8_t*>(message->arrayBuffer->data()), | 327 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 328 message->arrayBuffer->byteLength(), m_proxy.get()); | 328 message->arrayBuffer->byteLength(), m_proxy.get()); |
| 329 m_messages.removeFirst(); | 329 m_messages.pop_front(); |
| 330 break; | 330 break; |
| 331 case MessageTypeBlob: | 331 case MessageTypeBlob: |
| 332 ASSERT(!m_blobLoader); | 332 ASSERT(!m_blobLoader); |
| 333 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 333 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 334 break; | 334 break; |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 String PresentationConnection::binaryType() const { | 339 String PresentationConnection::binaryType() const { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 476 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
| 477 ASSERT(buffer && buffer->buffer()); | 477 ASSERT(buffer && buffer->buffer()); |
| 478 // Send the loaded blob immediately here and continue processing the queue. | 478 // Send the loaded blob immediately here and continue processing the queue. |
| 479 WebPresentationClient* client = presentationClient(getExecutionContext()); | 479 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 480 if (client) { | 480 if (client) { |
| 481 client->sendBlobData(m_url, m_id, | 481 client->sendBlobData(m_url, m_id, |
| 482 static_cast<const uint8_t*>(buffer->data()), | 482 static_cast<const uint8_t*>(buffer->data()), |
| 483 buffer->byteLength(), m_proxy.get()); | 483 buffer->byteLength(), m_proxy.get()); |
| 484 } | 484 } |
| 485 | 485 |
| 486 m_messages.removeFirst(); | 486 m_messages.pop_front(); |
| 487 m_blobLoader.clear(); | 487 m_blobLoader.clear(); |
| 488 handleMessageQueue(); | 488 handleMessageQueue(); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void PresentationConnection::didFailLoadingBlob( | 491 void PresentationConnection::didFailLoadingBlob( |
| 492 FileError::ErrorCode errorCode) { | 492 FileError::ErrorCode errorCode) { |
| 493 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 493 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
| 494 // FIXME: generate error message? | 494 // FIXME: generate error message? |
| 495 // Ignore the current failed blob item and continue with next items. | 495 // Ignore the current failed blob item and continue with next items. |
| 496 m_messages.removeFirst(); | 496 m_messages.pop_front(); |
| 497 m_blobLoader.clear(); | 497 m_blobLoader.clear(); |
| 498 handleMessageQueue(); | 498 handleMessageQueue(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void PresentationConnection::dispatchStateChangeEvent(Event* event) { | 501 void PresentationConnection::dispatchStateChangeEvent(Event* event) { |
| 502 TaskRunnerHelper::get(TaskType::Presentation, getExecutionContext()) | 502 TaskRunnerHelper::get(TaskType::Presentation, getExecutionContext()) |
| 503 ->postTask(BLINK_FROM_HERE, | 503 ->postTask(BLINK_FROM_HERE, |
| 504 WTF::bind(&PresentationConnection::dispatchEventAsync, | 504 WTF::bind(&PresentationConnection::dispatchEventAsync, |
| 505 wrapPersistent(this), wrapPersistent(event))); | 505 wrapPersistent(this), wrapPersistent(event))); |
| 506 } | 506 } |
| 507 | 507 |
| 508 // static | 508 // static |
| 509 void PresentationConnection::dispatchEventAsync(EventTarget* target, | 509 void PresentationConnection::dispatchEventAsync(EventTarget* target, |
| 510 Event* event) { | 510 Event* event) { |
| 511 DCHECK(target); | 511 DCHECK(target); |
| 512 DCHECK(event); | 512 DCHECK(event); |
| 513 target->dispatchEvent(event); | 513 target->dispatchEvent(event); |
| 514 } | 514 } |
| 515 | 515 |
| 516 void PresentationConnection::tearDown() { | 516 void PresentationConnection::tearDown() { |
| 517 // Cancel current Blob loading if any. | 517 // Cancel current Blob loading if any. |
| 518 if (m_blobLoader) { | 518 if (m_blobLoader) { |
| 519 m_blobLoader->cancel(); | 519 m_blobLoader->cancel(); |
| 520 m_blobLoader.clear(); | 520 m_blobLoader.clear(); |
| 521 } | 521 } |
| 522 m_messages.clear(); | 522 m_messages.clear(); |
| 523 } | 523 } |
| 524 | 524 |
| 525 } // namespace blink | 525 } // namespace blink |
| OLD | NEW |