Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 39 Document* document = toDocument(executionContext); | 40 Document* document = toDocument(executionContext); |
| 40 if (!document->frame()) | 41 if (!document->frame()) |
| 41 return nullptr; | 42 return nullptr; |
| 42 PresentationController* controller = | 43 PresentationController* controller = |
| 43 PresentationController::from(*document->frame()); | 44 PresentationController::from(*document->frame()); |
| 44 return controller ? controller->client() : nullptr; | 45 return controller ? controller->client() : nullptr; |
| 45 } | 46 } |
| 46 | 47 |
| 47 const AtomicString& connectionStateToString( | 48 const AtomicString& connectionStateToString( |
| 48 WebPresentationConnectionState state) { | 49 WebPresentationConnectionState state) { |
| 50 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); | |
| 49 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); | 51 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); |
| 50 DEFINE_STATIC_LOCAL(const AtomicString, closedValue, ("closed")); | 52 DEFINE_STATIC_LOCAL(const AtomicString, closedValue, ("closed")); |
| 51 DEFINE_STATIC_LOCAL(const AtomicString, terminatedValue, ("terminated")); | 53 DEFINE_STATIC_LOCAL(const AtomicString, terminatedValue, ("terminated")); |
| 52 | 54 |
| 53 switch (state) { | 55 switch (state) { |
| 56 case WebPresentationConnectionState::Connecting: | |
| 57 return connectingValue; | |
| 54 case WebPresentationConnectionState::Connected: | 58 case WebPresentationConnectionState::Connected: |
| 55 return connectedValue; | 59 return connectedValue; |
| 56 case WebPresentationConnectionState::Closed: | 60 case WebPresentationConnectionState::Closed: |
| 57 return closedValue; | 61 return closedValue; |
| 58 case WebPresentationConnectionState::Terminated: | 62 case WebPresentationConnectionState::Terminated: |
| 59 return terminatedValue; | 63 return terminatedValue; |
| 60 } | 64 } |
| 61 | 65 |
| 62 ASSERT_NOT_REACHED(); | 66 ASSERT_NOT_REACHED(); |
| 63 return terminatedValue; | 67 return terminatedValue; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 Member<PresentationConnection> m_PresentationConnection; | 145 Member<PresentationConnection> m_PresentationConnection; |
| 142 std::unique_ptr<FileReaderLoader> m_loader; | 146 std::unique_ptr<FileReaderLoader> m_loader; |
| 143 }; | 147 }; |
| 144 | 148 |
| 145 PresentationConnection::PresentationConnection(LocalFrame* frame, | 149 PresentationConnection::PresentationConnection(LocalFrame* frame, |
| 146 const String& id, | 150 const String& id, |
| 147 const KURL& url) | 151 const KURL& url) |
| 148 : DOMWindowProperty(frame), | 152 : DOMWindowProperty(frame), |
| 149 m_id(id), | 153 m_id(id), |
| 150 m_url(url), | 154 m_url(url), |
| 151 m_state(WebPresentationConnectionState::Connected), | 155 m_state(WebPresentationConnectionState::Connected), |
|
imcheng
2016/10/21 23:58:15
Add a TODO to change this to connecting?
zhaobin
2016/10/24 19:42:39
Done.
| |
| 152 m_binaryType(BinaryTypeBlob) {} | 156 m_binaryType(BinaryTypeBlob) {} |
| 153 | 157 |
| 154 PresentationConnection::~PresentationConnection() { | 158 PresentationConnection::~PresentationConnection() { |
| 155 ASSERT(!m_blobLoader); | 159 ASSERT(!m_blobLoader); |
| 156 } | 160 } |
| 157 | 161 |
| 158 // static | 162 // static |
| 159 PresentationConnection* PresentationConnection::take( | 163 PresentationConnection* PresentationConnection::take( |
| 160 ScriptPromiseResolver* resolver, | 164 ScriptPromiseResolver* resolver, |
| 161 std::unique_ptr<WebPresentationConnectionClient> client, | 165 std::unique_ptr<WebPresentationConnectionClient> client, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 } | 371 } |
| 368 case BinaryTypeArrayBuffer: | 372 case BinaryTypeArrayBuffer: |
| 369 DOMArrayBuffer* buffer = DOMArrayBuffer::create(data, length); | 373 DOMArrayBuffer* buffer = DOMArrayBuffer::create(data, length); |
| 370 dispatchEvent(MessageEvent::create(buffer)); | 374 dispatchEvent(MessageEvent::create(buffer)); |
| 371 return; | 375 return; |
| 372 } | 376 } |
| 373 ASSERT_NOT_REACHED(); | 377 ASSERT_NOT_REACHED(); |
| 374 } | 378 } |
| 375 | 379 |
| 376 void PresentationConnection::close() { | 380 void PresentationConnection::close() { |
| 377 if (m_state != WebPresentationConnectionState::Connected) | 381 if (m_state != WebPresentationConnectionState::Connected) |
|
imcheng
2016/10/21 23:58:15
do we allow close()/terminate() on a PresentationC
mark a. foltz
2016/10/24 18:28:16
close() is allowed.
terminate() is a no-op in a c
zhaobin
2016/10/24 19:42:39
Done.
| |
| 378 return; | 382 return; |
| 379 WebPresentationClient* client = presentationClient(getExecutionContext()); | 383 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 380 if (client) | 384 if (client) |
| 381 client->closeSession(m_url, m_id); | 385 client->closeSession(m_url, m_id); |
| 382 | 386 |
| 383 tearDown(); | 387 tearDown(); |
| 384 } | 388 } |
| 385 | 389 |
| 386 void PresentationConnection::terminate() { | 390 void PresentationConnection::terminate() { |
| 387 if (m_state != WebPresentationConnectionState::Connected) | 391 if (m_state != WebPresentationConnectionState::Connected) |
| 388 return; | 392 return; |
| 389 WebPresentationClient* client = presentationClient(getExecutionContext()); | 393 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 390 if (client) | 394 if (client) |
| 391 client->terminateSession(m_url, m_id); | 395 client->terminateSession(m_url, m_id); |
| 392 | 396 |
| 393 tearDown(); | 397 tearDown(); |
| 394 } | 398 } |
| 395 | 399 |
| 396 bool PresentationConnection::matches( | 400 bool PresentationConnection::matches( |
| 397 WebPresentationConnectionClient* client) const { | 401 WebPresentationConnectionClient* client) const { |
| 398 return client && m_url == KURL(client->getUrl()) && | 402 return client && m_url == KURL(client->getUrl()) && |
| 399 m_id == static_cast<String>(client->getId()); | 403 m_id == static_cast<String>(client->getId()); |
| 400 } | 404 } |
| 401 | 405 |
| 402 void PresentationConnection::didChangeState( | 406 void PresentationConnection::didChangeState( |
| 403 WebPresentationConnectionState state) { | 407 WebPresentationConnectionState state) { |
| 404 if (m_state == state) | 408 if (m_state == state) |
| 405 return; | 409 return; |
| 406 | 410 |
| 407 m_state = state; | 411 getExecutionContext()->postTask( |
| 408 switch (m_state) { | 412 BLINK_FROM_HERE, |
| 409 case WebPresentationConnectionState::Connected: | 413 createSameThreadTask(&PresentationConnection::didChangeStateInternal, |
| 410 dispatchEvent(Event::create(EventTypeNames::connect)); | 414 wrapPersistent(this), state)); |
|
mlamouri (slow - plz ping)
2016/10/21 09:58:12
Why are you making this asynchronous?
mark a. foltz
2016/10/24 18:28:16
I believe this is to ensure the connect event is d
zhaobin
2016/10/24 19:42:39
Reverted. We used to make this async to dispatch c
zhaobin
2016/10/24 19:42:39
reverted.
| |
| 411 return; | |
| 412 case WebPresentationConnectionState::Terminated: | |
| 413 dispatchEvent(Event::create(EventTypeNames::terminate)); | |
| 414 return; | |
| 415 // Closed state is handled in |didClose()|. | |
| 416 case WebPresentationConnectionState::Closed: | |
| 417 return; | |
| 418 } | |
| 419 ASSERT_NOT_REACHED(); | |
| 420 } | 415 } |
| 421 | 416 |
| 422 void PresentationConnection::didClose( | 417 void PresentationConnection::didClose( |
| 423 WebPresentationConnectionCloseReason reason, | 418 WebPresentationConnectionCloseReason reason, |
| 424 const String& message) { | 419 const String& message) { |
| 425 if (m_state == WebPresentationConnectionState::Closed) | 420 if (m_state == WebPresentationConnectionState::Closed) |
| 426 return; | 421 return; |
| 427 | 422 |
| 428 m_state = WebPresentationConnectionState::Closed; | 423 m_state = WebPresentationConnectionState::Closed; |
| 429 dispatchEvent(PresentationConnectionCloseEvent::create( | 424 dispatchEvent(PresentationConnectionCloseEvent::create( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 448 void PresentationConnection::didFailLoadingBlob( | 443 void PresentationConnection::didFailLoadingBlob( |
| 449 FileError::ErrorCode errorCode) { | 444 FileError::ErrorCode errorCode) { |
| 450 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 445 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
| 451 // FIXME: generate error message? | 446 // FIXME: generate error message? |
| 452 // Ignore the current failed blob item and continue with next items. | 447 // Ignore the current failed blob item and continue with next items. |
| 453 m_messages.removeFirst(); | 448 m_messages.removeFirst(); |
| 454 m_blobLoader.clear(); | 449 m_blobLoader.clear(); |
| 455 handleMessageQueue(); | 450 handleMessageQueue(); |
| 456 } | 451 } |
| 457 | 452 |
| 453 void PresentationConnection::didChangeStateInternal( | |
| 454 WebPresentationConnectionState state) { | |
| 455 if (m_state == state) | |
| 456 return; | |
| 457 | |
| 458 m_state = state; | |
| 459 switch (m_state) { | |
| 460 case WebPresentationConnectionState::Connecting: | |
| 461 return; | |
|
mlamouri (slow - plz ping)
2016/10/21 09:58:12
NOTREACHED() ?
zhaobin
2016/10/24 19:42:39
Done.
| |
| 462 case WebPresentationConnectionState::Connected: | |
| 463 dispatchEvent(Event::create(EventTypeNames::connect)); | |
| 464 return; | |
| 465 case WebPresentationConnectionState::Terminated: | |
| 466 dispatchEvent(Event::create(EventTypeNames::terminate)); | |
| 467 return; | |
| 468 // Closed state is handled in |didClose()|. | |
| 469 case WebPresentationConnectionState::Closed: | |
| 470 return; | |
|
mlamouri (slow - plz ping)
2016/10/21 09:58:12
NOTREACHED() ?
zhaobin
2016/10/24 19:42:39
Done.
| |
| 471 } | |
| 472 NOTREACHED(); | |
| 473 } | |
| 474 | |
| 458 void PresentationConnection::tearDown() { | 475 void PresentationConnection::tearDown() { |
| 459 // Cancel current Blob loading if any. | 476 // Cancel current Blob loading if any. |
| 460 if (m_blobLoader) { | 477 if (m_blobLoader) { |
| 461 m_blobLoader->cancel(); | 478 m_blobLoader->cancel(); |
| 462 m_blobLoader.clear(); | 479 m_blobLoader.clear(); |
| 463 } | 480 } |
| 464 m_messages.clear(); | 481 m_messages.clear(); |
| 465 } | 482 } |
| 466 | 483 |
| 467 } // namespace blink | 484 } // namespace blink |
| OLD | NEW |