| 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" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContextTask.h" |
| 12 #include "core/events/Event.h" | 13 #include "core/events/Event.h" |
| 13 #include "core/events/MessageEvent.h" | 14 #include "core/events/MessageEvent.h" |
| 14 #include "core/fileapi/FileReaderLoader.h" | 15 #include "core/fileapi/FileReaderLoader.h" |
| 15 #include "core/fileapi/FileReaderLoaderClient.h" | 16 #include "core/fileapi/FileReaderLoaderClient.h" |
| 16 #include "core/frame/Deprecation.h" | 17 #include "core/frame/Deprecation.h" |
| 17 #include "core/frame/LocalFrame.h" | 18 #include "core/frame/LocalFrame.h" |
| 18 #include "core/frame/UseCounter.h" | 19 #include "core/frame/UseCounter.h" |
| 19 #include "modules/EventTargetModules.h" | 20 #include "modules/EventTargetModules.h" |
| 20 #include "modules/presentation/Presentation.h" | 21 #include "modules/presentation/Presentation.h" |
| 21 #include "modules/presentation/PresentationConnectionAvailableEvent.h" | 22 #include "modules/presentation/PresentationConnectionAvailableEvent.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 PresentationConnection* PresentationConnection::take( | 185 PresentationConnection* PresentationConnection::take( |
| 185 PresentationController* controller, | 186 PresentationController* controller, |
| 186 std::unique_ptr<WebPresentationConnectionClient> client, | 187 std::unique_ptr<WebPresentationConnectionClient> client, |
| 187 PresentationRequest* request) { | 188 PresentationRequest* request) { |
| 188 ASSERT(controller); | 189 ASSERT(controller); |
| 189 ASSERT(request); | 190 ASSERT(request); |
| 190 | 191 |
| 191 PresentationConnection* connection = new PresentationConnection( | 192 PresentationConnection* connection = new PresentationConnection( |
| 192 controller->frame(), client->getId(), client->getUrl()); | 193 controller->frame(), client->getId(), client->getUrl()); |
| 193 controller->registerConnection(connection); | 194 controller->registerConnection(connection); |
| 194 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | |
| 195 EventTypeNames::connectionavailable, connection)); | |
| 196 | |
| 197 return connection; | 195 return connection; |
| 198 } | 196 } |
| 199 | 197 |
| 200 // static | 198 // static |
| 201 PresentationConnection* PresentationConnection::take( | 199 PresentationConnection* PresentationConnection::take( |
| 202 PresentationReceiver* receiver, | 200 PresentationReceiver* receiver, |
| 203 std::unique_ptr<WebPresentationConnectionClient> client) { | 201 std::unique_ptr<WebPresentationConnectionClient> client) { |
| 204 DCHECK(receiver); | 202 DCHECK(receiver); |
| 205 DCHECK(client); | 203 DCHECK(client); |
| 206 | 204 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 WebPresentationConnectionState state) { | 406 WebPresentationConnectionState state) { |
| 409 if (m_state == state) | 407 if (m_state == state) |
| 410 return; | 408 return; |
| 411 | 409 |
| 412 m_state = state; | 410 m_state = state; |
| 413 switch (m_state) { | 411 switch (m_state) { |
| 414 case WebPresentationConnectionState::Connecting: | 412 case WebPresentationConnectionState::Connecting: |
| 415 NOTREACHED(); | 413 NOTREACHED(); |
| 416 return; | 414 return; |
| 417 case WebPresentationConnectionState::Connected: | 415 case WebPresentationConnectionState::Connected: |
| 418 dispatchEvent(Event::create(EventTypeNames::connect)); | 416 getExecutionContext()->postTask( |
| 417 BLINK_FROM_HERE, |
| 418 createSameThreadTask(&PresentationConnection::dispatchConnectEvent, |
| 419 wrapPersistent(this))); |
| 419 return; | 420 return; |
| 420 case WebPresentationConnectionState::Terminated: | 421 case WebPresentationConnectionState::Terminated: |
| 421 dispatchEvent(Event::create(EventTypeNames::terminate)); | 422 dispatchEvent(Event::create(EventTypeNames::terminate)); |
| 422 return; | 423 return; |
| 423 // Closed state is handled in |didClose()|. | 424 // Closed state is handled in |didClose()|. |
| 424 case WebPresentationConnectionState::Closed: | 425 case WebPresentationConnectionState::Closed: |
| 425 NOTREACHED(); | 426 NOTREACHED(); |
| 426 return; | 427 return; |
| 427 } | 428 } |
| 428 NOTREACHED(); | 429 NOTREACHED(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 457 void PresentationConnection::didFailLoadingBlob( | 458 void PresentationConnection::didFailLoadingBlob( |
| 458 FileError::ErrorCode errorCode) { | 459 FileError::ErrorCode errorCode) { |
| 459 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 460 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
| 460 // FIXME: generate error message? | 461 // FIXME: generate error message? |
| 461 // Ignore the current failed blob item and continue with next items. | 462 // Ignore the current failed blob item and continue with next items. |
| 462 m_messages.removeFirst(); | 463 m_messages.removeFirst(); |
| 463 m_blobLoader.clear(); | 464 m_blobLoader.clear(); |
| 464 handleMessageQueue(); | 465 handleMessageQueue(); |
| 465 } | 466 } |
| 466 | 467 |
| 468 void PresentationConnection::dispatchConnectEvent() { |
| 469 dispatchEvent(Event::create(EventTypeNames::connect)); |
| 470 } |
| 471 |
| 467 void PresentationConnection::tearDown() { | 472 void PresentationConnection::tearDown() { |
| 468 // Cancel current Blob loading if any. | 473 // Cancel current Blob loading if any. |
| 469 if (m_blobLoader) { | 474 if (m_blobLoader) { |
| 470 m_blobLoader->cancel(); | 475 m_blobLoader->cancel(); |
| 471 m_blobLoader.clear(); | 476 m_blobLoader.clear(); |
| 472 } | 477 } |
| 473 m_messages.clear(); | 478 m_messages.clear(); |
| 474 } | 479 } |
| 475 | 480 |
| 476 } // namespace blink | 481 } // namespace blink |
| OLD | NEW |