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

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: 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"
15 #include "wtf/OwnPtr.h" 14 #include "wtf/OwnPtr.h"
16 15
17 namespace blink { 16 namespace blink {
18 17
18 namespace {
19
20 const AtomicString SessionStateToString(WebPresentationSessionClient::SessionSta te state)
Peter Beverloo 2015/03/20 19:07:40 Why do you return an AtomicString here and not jus
mlamouri (slow - plz ping) 2015/03/23 17:54:16 I think using an AtomicString is fine. However, co
whywhat 2015/03/23 21:12:16 Done.
whywhat 2015/03/23 21:12:16 To avoid extra conversion (from String to AtomicSt
21 {
22 switch (state) {
23 case WebPresentationSessionClient::SessionStateConnected:
24 return "connected";
25 case WebPresentationSessionClient::SessionStateDisconnected:
26 default:
27 return "disconnected";
28 }
29 }
30
31 } // namespace
32
19 PresentationSession::PresentationSession(LocalFrame* frame, const WebString& id, const WebString& url) 33 PresentationSession::PresentationSession(LocalFrame* frame, const WebString& id, const WebString& url)
20 : DOMWindowProperty(frame) 34 : DOMWindowProperty(frame)
21 , m_id(id) 35 , m_id(id)
22 , m_url(url) 36 , m_url(url)
23 , m_state("disconnected") 37 , m_state(WebPresentationSessionClient::SessionStateDisconnected)
24 { 38 {
25 } 39 }
26 40
27 PresentationSession::~PresentationSession() 41 PresentationSession::~PresentationSession()
28 { 42 {
29 } 43 }
30 44
31 // static 45 // static
32 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli entRaw, Presentation* presentation) 46 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli entRaw, Presentation* presentation)
33 { 47 {
(...skipping 22 matching lines...) Expand all
56 if (!frame()) 70 if (!frame())
57 return nullptr; 71 return nullptr;
58 return frame()->document();} 72 return frame()->document();}
59 73
60 DEFINE_TRACE(PresentationSession) 74 DEFINE_TRACE(PresentationSession)
61 { 75 {
62 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr ace(visitor); 76 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr ace(visitor);
63 DOMWindowProperty::trace(visitor); 77 DOMWindowProperty::trace(visitor);
64 } 78 }
65 79
80 const AtomicString PresentationSession::state() const
mark a. foltz 2015/03/20 20:40:22 Why is this returning a string instead of the enum
mlamouri (slow - plz ping) 2015/03/23 17:54:16 I would guess that ::state() is being used by the
whywhat 2015/03/23 21:12:16 As I understand it, that's how WebIDL enum values
whywhat 2015/03/23 21:12:16 Acknowledged.
81 {
82 return SessionStateToString(m_state);
83 }
84
66 void PresentationSession::postMessage(const String& message) 85 void PresentationSession::postMessage(const String& message)
67 { 86 {
68 } 87 }
69 88
70 void PresentationSession::close() 89 void PresentationSession::close()
71 { 90 {
72 if (m_state != "connected") 91 if (m_state != WebPresentationSessionClient::SessionStateConnected)
73 return; 92 return;
74 PresentationController* controller = presentationController(); 93 PresentationController* controller = presentationController();
75 if (controller) 94 if (controller)
76 controller->closeSession(m_url, m_id); 95 controller->closeSession(m_url, m_id);
77 } 96 }
78 97
98 bool PresentationSession::matches(WebPresentationSessionClient* client) const
99 {
100 return client && client->getUrl() == m_url && client->getId() == m_id;
mark a. foltz 2015/03/20 20:40:22 The match between a PresentationSession and |clien
whywhat 2015/03/23 21:12:16 I expected the list to be fairy small. We could us
101 }
102
103 void PresentationSession::didChangeState(WebPresentationSessionClient::SessionSt ate state)
104 {
105 m_state = state;
mark a. foltz 2015/03/20 20:40:22 What if m_state == state? We don't need to dispat
whywhat 2015/03/23 21:12:16 Done.
106 dispatchEvent(Event::create(EventTypeNames::statechange));
107 }
108
79 PresentationController* PresentationSession::presentationController() 109 PresentationController* PresentationSession::presentationController()
80 { 110 {
81 if (!frame()) 111 if (!frame())
82 return nullptr; 112 return nullptr;
83 return PresentationController::from(*frame()); 113 return PresentationController::from(*frame());
84 } 114 }
85 115
86 } // namespace blink 116 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698