Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: Source/modules/presentation/PresentationSession.cpp

Issue 1020303004: [PresentationAPI] Plumbing |onstatechange| event for the PresentationSession from Blink to platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added a return statement for the conversion function Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/Assertions.h"
15 #include "wtf/OwnPtr.h" 16 #include "wtf/OwnPtr.h"
17 #include "wtf/text/AtomicString.h"
16 18
17 namespace blink { 19 namespace blink {
18 20
19 PresentationSession::PresentationSession(LocalFrame* frame, const WebString& id, const WebString& url) 21 namespace {
22
23 const AtomicString& SessionStateToString(WebPresentationSessionState state)
24 {
25 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected", Atomic String::ConstructFromLiteral));
26 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected", AtomicString::ConstructFromLiteral));
27
28 switch (state) {
29 case WebPresentationSessionState::Connected:
30 return connectedValue;
31 case WebPresentationSessionState::Disconnected:
32 return disconnectedValue;
33 }
34
35 ASSERT_NOT_REACHED();
36 return disconnectedValue;
37 }
38
39 } // namespace
40
41 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co nst String& url)
20 : DOMWindowProperty(frame) 42 : DOMWindowProperty(frame)
21 , m_id(id) 43 , m_id(id)
22 , m_url(url) 44 , m_url(url)
23 , m_state("disconnected") 45 , m_state(WebPresentationSessionState::Disconnected)
24 { 46 {
25 } 47 }
26 48
27 PresentationSession::~PresentationSession() 49 PresentationSession::~PresentationSession()
28 { 50 {
29 } 51 }
30 52
31 // static 53 // static
32 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli entRaw, Presentation* presentation) 54 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli entRaw, Presentation* presentation)
33 { 55 {
(...skipping 22 matching lines...) Expand all
56 if (!frame()) 78 if (!frame())
57 return nullptr; 79 return nullptr;
58 return frame()->document();} 80 return frame()->document();}
59 81
60 DEFINE_TRACE(PresentationSession) 82 DEFINE_TRACE(PresentationSession)
61 { 83 {
62 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr ace(visitor); 84 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr ace(visitor);
63 DOMWindowProperty::trace(visitor); 85 DOMWindowProperty::trace(visitor);
64 } 86 }
65 87
88 const AtomicString& PresentationSession::state() const
89 {
90 return SessionStateToString(m_state);
91 }
92
66 void PresentationSession::postMessage(const String& message) 93 void PresentationSession::postMessage(const String& message)
67 { 94 {
68 } 95 }
69 96
70 void PresentationSession::close() 97 void PresentationSession::close()
71 { 98 {
72 if (m_state != "connected") 99 if (m_state != WebPresentationSessionState::Connected)
73 return; 100 return;
74 PresentationController* controller = presentationController(); 101 PresentationController* controller = presentationController();
75 if (controller) 102 if (controller)
76 controller->closeSession(m_url, m_id); 103 controller->closeSession(m_url, m_id);
77 } 104 }
78 105
106 bool PresentationSession::matches(WebPresentationSessionClient* client) const
107 {
108 return client && m_url == static_cast<String>(client->getUrl()) && m_id == s tatic_cast<String>(client->getId());
109 }
110
111 void PresentationSession::didChangeState(WebPresentationSessionState state)
112 {
113 if (m_state == state)
114 return;
115
116 m_state = state;
117 dispatchEvent(Event::create(EventTypeNames::statechange));
118 }
119
79 PresentationController* PresentationSession::presentationController() 120 PresentationController* PresentationSession::presentationController()
80 { 121 {
81 if (!frame()) 122 if (!frame())
82 return nullptr; 123 return nullptr;
83 return PresentationController::from(*frame()); 124 return PresentationController::from(*frame());
84 } 125 }
85 126
86 } // namespace blink 127 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/presentation/PresentationSession.h ('k') | public/platform/modules/presentation/WebPresentationController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698