| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/PresentationReceiver.h" | 5 #include "modules/presentation/PresentationReceiver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.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/frame/LocalDOMWindow.h" |
| 12 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
| 13 #include "core/frame/UseCounter.h" | 14 #include "core/frame/UseCounter.h" |
| 14 #include "modules/presentation/PresentationConnection.h" | 15 #include "modules/presentation/PresentationConnection.h" |
| 15 #include "modules/presentation/PresentationConnectionList.h" | 16 #include "modules/presentation/PresentationConnectionList.h" |
| 16 #include "public/platform/modules/presentation/WebPresentationClient.h" | 17 #include "public/platform/modules/presentation/WebPresentationClient.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 PresentationReceiver::PresentationReceiver(LocalFrame* frame, | 21 PresentationReceiver::PresentationReceiver(LocalFrame* frame, |
| 21 WebPresentationClient* client) | 22 WebPresentationClient* client) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 ScriptPromisePropertyBase::Pending) { | 56 ScriptPromisePropertyBase::Pending) { |
| 56 m_connectionListProperty->resolve(m_connectionList); | 57 m_connectionListProperty->resolve(m_connectionList); |
| 57 } else if (m_connectionListProperty->getState() == | 58 } else if (m_connectionListProperty->getState() == |
| 58 ScriptPromisePropertyBase::Resolved) { | 59 ScriptPromisePropertyBase::Resolved) { |
| 59 m_connectionList->dispatchConnectionAvailableEvent(connection); | 60 m_connectionList->dispatchConnectionAvailableEvent(connection); |
| 60 } | 61 } |
| 61 | 62 |
| 62 return connection; | 63 return connection; |
| 63 } | 64 } |
| 64 | 65 |
| 66 void PresentationReceiver::didChangeSessionState( |
| 67 WebPresentationConnectionState state) { |
| 68 // TODO(zhaobin): remove or modify DCHECK when receiver supports more |
| 69 // connection state change. |
| 70 DCHECK(state == WebPresentationConnectionState::Terminated); |
| 71 |
| 72 for (auto connection : m_connectionList->connections()) |
| 73 connection->didChangeState(state, false /* shouldDispatchEvent */); |
| 74 } |
| 75 |
| 76 void PresentationReceiver::terminateConnection() { |
| 77 if (!frame()) |
| 78 return; |
| 79 |
| 80 auto* window = frame()->domWindow(); |
| 81 if (!window || window->closed()) |
| 82 return; |
| 83 |
| 84 window->close(frame()->document()); |
| 85 } |
| 86 |
| 65 void PresentationReceiver::registerConnection( | 87 void PresentationReceiver::registerConnection( |
| 66 PresentationConnection* connection) { | 88 PresentationConnection* connection) { |
| 67 DCHECK(m_connectionList); | 89 DCHECK(m_connectionList); |
| 68 m_connectionList->addConnection(connection); | 90 m_connectionList->addConnection(connection); |
| 69 } | 91 } |
| 70 | 92 |
| 71 void PresentationReceiver::recordOriginTypeAccess(Document* document) const { | 93 void PresentationReceiver::recordOriginTypeAccess(Document* document) const { |
| 72 DCHECK(document); | 94 DCHECK(document); |
| 73 if (document->isSecureContext()) { | 95 if (document->isSecureContext()) { |
| 74 UseCounter::count(document, UseCounter::PresentationReceiverSecureOrigin); | 96 UseCounter::count(document, UseCounter::PresentationReceiverSecureOrigin); |
| 75 } else { | 97 } else { |
| 76 UseCounter::count(document, UseCounter::PresentationReceiverInsecureOrigin); | 98 UseCounter::count(document, UseCounter::PresentationReceiverInsecureOrigin); |
| 77 } | 99 } |
| 78 } | 100 } |
| 79 | 101 |
| 80 DEFINE_TRACE(PresentationReceiver) { | 102 DEFINE_TRACE(PresentationReceiver) { |
| 81 visitor->trace(m_connectionList); | 103 visitor->trace(m_connectionList); |
| 82 visitor->trace(m_connectionListProperty); | 104 visitor->trace(m_connectionListProperty); |
| 83 ContextClient::trace(visitor); | 105 ContextClient::trace(visitor); |
| 84 } | 106 } |
| 85 | 107 |
| 86 } // namespace blink | 108 } // namespace blink |
| OLD | NEW |