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" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 Document* document = toDocument(executionContext); | 39 Document* document = toDocument(executionContext); |
| 40 if (!document->frame()) | 40 if (!document->frame()) |
| 41 return nullptr; | 41 return nullptr; |
| 42 PresentationController* controller = | 42 PresentationController* controller = |
| 43 PresentationController::from(*document->frame()); | 43 PresentationController::from(*document->frame()); |
| 44 return controller ? controller->client() : nullptr; | 44 return controller ? controller->client() : nullptr; |
| 45 } | 45 } |
| 46 | 46 |
| 47 const AtomicString& connectionStateToString( | 47 const AtomicString& connectionStateToString( |
| 48 WebPresentationConnectionState state) { | 48 WebPresentationConnectionState state) { |
| 49 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); | |
| 49 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); | 50 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); |
| 50 DEFINE_STATIC_LOCAL(const AtomicString, closedValue, ("closed")); | 51 DEFINE_STATIC_LOCAL(const AtomicString, closedValue, ("closed")); |
| 51 DEFINE_STATIC_LOCAL(const AtomicString, terminatedValue, ("terminated")); | 52 DEFINE_STATIC_LOCAL(const AtomicString, terminatedValue, ("terminated")); |
| 52 | 53 |
| 53 switch (state) { | 54 switch (state) { |
| 55 case WebPresentationConnectionState::Connecting: | |
| 56 return connectingValue; | |
| 54 case WebPresentationConnectionState::Connected: | 57 case WebPresentationConnectionState::Connected: |
| 55 return connectedValue; | 58 return connectedValue; |
| 56 case WebPresentationConnectionState::Closed: | 59 case WebPresentationConnectionState::Closed: |
| 57 return closedValue; | 60 return closedValue; |
| 58 case WebPresentationConnectionState::Terminated: | 61 case WebPresentationConnectionState::Terminated: |
| 59 return terminatedValue; | 62 return terminatedValue; |
| 60 } | 63 } |
| 61 | 64 |
| 62 ASSERT_NOT_REACHED(); | 65 ASSERT_NOT_REACHED(); |
| 63 return terminatedValue; | 66 return terminatedValue; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 Member<PresentationConnection> m_PresentationConnection; | 144 Member<PresentationConnection> m_PresentationConnection; |
| 142 std::unique_ptr<FileReaderLoader> m_loader; | 145 std::unique_ptr<FileReaderLoader> m_loader; |
| 143 }; | 146 }; |
| 144 | 147 |
| 145 PresentationConnection::PresentationConnection(LocalFrame* frame, | 148 PresentationConnection::PresentationConnection(LocalFrame* frame, |
| 146 const String& id, | 149 const String& id, |
| 147 const KURL& url) | 150 const KURL& url) |
| 148 : DOMWindowProperty(frame), | 151 : DOMWindowProperty(frame), |
| 149 m_id(id), | 152 m_id(id), |
| 150 m_url(url), | 153 m_url(url), |
| 154 // TODO(zhaobin): change initial state to Connecting | |
|
mlamouri (slow - plz ping)
2016/10/25 17:43:37
bug number?
zhaobin
2016/10/26 20:12:59
Done.
| |
| 151 m_state(WebPresentationConnectionState::Connected), | 155 m_state(WebPresentationConnectionState::Connected), |
| 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, |
| (...skipping 206 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::Connecting && |
| 382 m_state != WebPresentationConnectionState::Connected) { | |
| 378 return; | 383 return; |
| 384 } | |
| 379 WebPresentationClient* client = presentationClient(getExecutionContext()); | 385 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 380 if (client) | 386 if (client) |
| 381 client->closeSession(m_url, m_id); | 387 client->closeSession(m_url, m_id); |
| 382 | 388 |
| 383 tearDown(); | 389 tearDown(); |
| 384 } | 390 } |
| 385 | 391 |
| 386 void PresentationConnection::terminate() { | 392 void PresentationConnection::terminate() { |
| 387 if (m_state != WebPresentationConnectionState::Connected) | 393 if (m_state != WebPresentationConnectionState::Connected) |
| 388 return; | 394 return; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 399 m_id == static_cast<String>(client->getId()); | 405 m_id == static_cast<String>(client->getId()); |
| 400 } | 406 } |
| 401 | 407 |
| 402 void PresentationConnection::didChangeState( | 408 void PresentationConnection::didChangeState( |
| 403 WebPresentationConnectionState state) { | 409 WebPresentationConnectionState state) { |
| 404 if (m_state == state) | 410 if (m_state == state) |
| 405 return; | 411 return; |
| 406 | 412 |
| 407 m_state = state; | 413 m_state = state; |
| 408 switch (m_state) { | 414 switch (m_state) { |
| 415 case WebPresentationConnectionState::Connecting: | |
| 416 NOTREACHED(); | |
| 417 return; | |
| 409 case WebPresentationConnectionState::Connected: | 418 case WebPresentationConnectionState::Connected: |
| 410 dispatchEvent(Event::create(EventTypeNames::connect)); | 419 dispatchEvent(Event::create(EventTypeNames::connect)); |
| 411 return; | 420 return; |
| 412 case WebPresentationConnectionState::Terminated: | 421 case WebPresentationConnectionState::Terminated: |
| 413 dispatchEvent(Event::create(EventTypeNames::terminate)); | 422 dispatchEvent(Event::create(EventTypeNames::terminate)); |
| 414 return; | 423 return; |
| 415 // Closed state is handled in |didClose()|. | 424 // Closed state is handled in |didClose()|. |
| 416 case WebPresentationConnectionState::Closed: | 425 case WebPresentationConnectionState::Closed: |
| 426 NOTREACHED(); | |
| 417 return; | 427 return; |
| 418 } | 428 } |
| 419 ASSERT_NOT_REACHED(); | 429 NOTREACHED(); |
| 420 } | 430 } |
| 421 | 431 |
| 422 void PresentationConnection::didClose( | 432 void PresentationConnection::didClose( |
| 423 WebPresentationConnectionCloseReason reason, | 433 WebPresentationConnectionCloseReason reason, |
| 424 const String& message) { | 434 const String& message) { |
| 425 if (m_state == WebPresentationConnectionState::Closed) | 435 if (m_state == WebPresentationConnectionState::Closed) |
| 426 return; | 436 return; |
| 427 | 437 |
| 428 m_state = WebPresentationConnectionState::Closed; | 438 m_state = WebPresentationConnectionState::Closed; |
| 429 dispatchEvent(PresentationConnectionCloseEvent::create( | 439 dispatchEvent(PresentationConnectionCloseEvent::create( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 458 void PresentationConnection::tearDown() { | 468 void PresentationConnection::tearDown() { |
| 459 // Cancel current Blob loading if any. | 469 // Cancel current Blob loading if any. |
| 460 if (m_blobLoader) { | 470 if (m_blobLoader) { |
| 461 m_blobLoader->cancel(); | 471 m_blobLoader->cancel(); |
| 462 m_blobLoader.clear(); | 472 m_blobLoader.clear(); |
| 463 } | 473 } |
| 464 m_messages.clear(); | 474 m_messages.clear(); |
| 465 } | 475 } |
| 466 | 476 |
| 467 } // namespace blink | 477 } // namespace blink |
| OLD | NEW |