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 "config.h" | 5 #include "config.h" |
6 #include "modules/presentation/PresentationSession.h" | 6 #include "modules/presentation/PresentationSession.h" |
7 | 7 |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/events/Event.h" |
9 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
10 #include "modules/EventTargetModules.h" | 11 #include "modules/EventTargetModules.h" |
11 #include "modules/presentation/Presentation.h" | 12 #include "modules/presentation/Presentation.h" |
12 #include "modules/presentation/PresentationController.h" | 13 #include "modules/presentation/PresentationController.h" |
13 #include "public/platform/WebString.h" | |
14 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" | 14 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" |
15 #include "wtf/OwnPtr.h" | 15 #include "wtf/OwnPtr.h" |
| 16 #include "wtf/text/AtomicString.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
| 20 namespace { |
| 21 |
| 22 const AtomicString& SessionStateToString(WebPresentationSessionState state) |
| 23 { |
| 24 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected", Atomic
String::ConstructFromLiteral)); |
| 25 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected",
AtomicString::ConstructFromLiteral)); |
| 26 |
| 27 switch (state) { |
| 28 case WebPresentationSessionState::Connected: |
| 29 return connectedValue; |
| 30 case WebPresentationSessionState::Disconnected: |
| 31 return disconnectedValue; |
| 32 } |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
19 PresentationSession::PresentationSession(LocalFrame* frame, const WebString& id,
const WebString& url) | 37 PresentationSession::PresentationSession(LocalFrame* frame, const WebString& id,
const WebString& url) |
20 : DOMWindowProperty(frame) | 38 : DOMWindowProperty(frame) |
21 , m_id(id) | 39 , m_id(id) |
22 , m_url(url) | 40 , m_url(url) |
23 , m_state("disconnected") | 41 , m_state(WebPresentationSessionState::Disconnected) |
24 { | 42 { |
25 } | 43 } |
26 | 44 |
27 PresentationSession::~PresentationSession() | 45 PresentationSession::~PresentationSession() |
28 { | 46 { |
29 } | 47 } |
30 | 48 |
31 // static | 49 // static |
32 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli
entRaw, Presentation* presentation) | 50 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli
entRaw, Presentation* presentation) |
33 { | 51 { |
(...skipping 22 matching lines...) Expand all Loading... |
56 if (!frame()) | 74 if (!frame()) |
57 return nullptr; | 75 return nullptr; |
58 return frame()->document();} | 76 return frame()->document();} |
59 | 77 |
60 DEFINE_TRACE(PresentationSession) | 78 DEFINE_TRACE(PresentationSession) |
61 { | 79 { |
62 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr
ace(visitor); | 80 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr
ace(visitor); |
63 DOMWindowProperty::trace(visitor); | 81 DOMWindowProperty::trace(visitor); |
64 } | 82 } |
65 | 83 |
| 84 const AtomicString& PresentationSession::state() const |
| 85 { |
| 86 return SessionStateToString(m_state); |
| 87 } |
| 88 |
66 void PresentationSession::postMessage(const String& message) | 89 void PresentationSession::postMessage(const String& message) |
67 { | 90 { |
68 } | 91 } |
69 | 92 |
70 void PresentationSession::close() | 93 void PresentationSession::close() |
71 { | 94 { |
72 if (m_state != "connected") | 95 if (m_state != WebPresentationSessionState::Connected) |
73 return; | 96 return; |
74 PresentationController* controller = presentationController(); | 97 PresentationController* controller = presentationController(); |
75 if (controller) | 98 if (controller) |
76 controller->closeSession(m_url, m_id); | 99 controller->closeSession(m_url, m_id); |
77 } | 100 } |
78 | 101 |
| 102 bool PresentationSession::matches(WebPresentationSessionClient* client) const |
| 103 { |
| 104 return client && client->getUrl() == m_url && client->getId() == m_id; |
| 105 } |
| 106 |
| 107 void PresentationSession::didChangeState(WebPresentationSessionState state) |
| 108 { |
| 109 if (m_state == state) |
| 110 return; |
| 111 |
| 112 m_state = state; |
| 113 dispatchEvent(Event::create(EventTypeNames::statechange)); |
| 114 } |
| 115 |
79 PresentationController* PresentationSession::presentationController() | 116 PresentationController* PresentationSession::presentationController() |
80 { | 117 { |
81 if (!frame()) | 118 if (!frame()) |
82 return nullptr; | 119 return nullptr; |
83 return PresentationController::from(*frame()); | 120 return PresentationController::from(*frame()); |
84 } | 121 } |
85 | 122 |
86 } // namespace blink | 123 } // namespace blink |
OLD | NEW |