| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // The connection can send a message if there is a client available. | 308 // The connection can send a message if there is a client available. |
| 309 return !!presentationClient(getExecutionContext()); | 309 return !!presentationClient(getExecutionContext()); |
| 310 } | 310 } |
| 311 | 311 |
| 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.front().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.pop_front(); | 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()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 m_state = WebPresentationConnectionState::Closed; | 466 m_state = WebPresentationConnectionState::Closed; |
| 467 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create( | 467 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create( |
| 468 EventTypeNames::close, connectionCloseReasonToString(reason), message)); | 468 EventTypeNames::close, connectionCloseReasonToString(reason), message)); |
| 469 } | 469 } |
| 470 | 470 |
| 471 void PresentationConnection::didClose() { | 471 void PresentationConnection::didClose() { |
| 472 didClose(WebPresentationConnectionCloseReason::Closed, ""); | 472 didClose(WebPresentationConnectionCloseReason::Closed, ""); |
| 473 } | 473 } |
| 474 | 474 |
| 475 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { | 475 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { |
| 476 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 476 ASSERT(!m_messages.isEmpty() && m_messages.front()->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.pop_front(); | 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.front()->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.pop_front(); | 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, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 |