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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/presentation/PresentationSession.cpp
diff --git a/Source/modules/presentation/PresentationSession.cpp b/Source/modules/presentation/PresentationSession.cpp
index 4727bebdb9c0397281ff4af261da66203d9597eb..47ba6253b3d33c471419808f6e6918b48f272bdd 100644
--- a/Source/modules/presentation/PresentationSession.cpp
+++ b/Source/modules/presentation/PresentationSession.cpp
@@ -6,21 +6,43 @@
#include "modules/presentation/PresentationSession.h"
#include "core/dom/Document.h"
+#include "core/events/Event.h"
#include "core/frame/LocalFrame.h"
#include "modules/EventTargetModules.h"
#include "modules/presentation/Presentation.h"
#include "modules/presentation/PresentationController.h"
-#include "public/platform/WebString.h"
#include "public/platform/modules/presentation/WebPresentationSessionClient.h"
+#include "wtf/Assertions.h"
#include "wtf/OwnPtr.h"
+#include "wtf/text/AtomicString.h"
namespace blink {
-PresentationSession::PresentationSession(LocalFrame* frame, const WebString& id, const WebString& url)
+namespace {
+
+const AtomicString& SessionStateToString(WebPresentationSessionState state)
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected", AtomicString::ConstructFromLiteral));
+
+ switch (state) {
+ case WebPresentationSessionState::Connected:
+ return connectedValue;
+ case WebPresentationSessionState::Disconnected:
+ return disconnectedValue;
+ }
+
+ ASSERT_NOT_REACHED();
+ return disconnectedValue;
+}
+
+} // namespace
+
+PresentationSession::PresentationSession(LocalFrame* frame, const String& id, const String& url)
: DOMWindowProperty(frame)
, m_id(id)
, m_url(url)
- , m_state("disconnected")
+ , m_state(WebPresentationSessionState::Disconnected)
{
}
@@ -63,19 +85,38 @@ DEFINE_TRACE(PresentationSession)
DOMWindowProperty::trace(visitor);
}
+const AtomicString& PresentationSession::state() const
+{
+ return SessionStateToString(m_state);
+}
+
void PresentationSession::postMessage(const String& message)
{
}
void PresentationSession::close()
{
- if (m_state != "connected")
+ if (m_state != WebPresentationSessionState::Connected)
return;
PresentationController* controller = presentationController();
if (controller)
controller->closeSession(m_url, m_id);
}
+bool PresentationSession::matches(WebPresentationSessionClient* client) const
+{
+ return client && m_url == static_cast<String>(client->getUrl()) && m_id == static_cast<String>(client->getId());
+}
+
+void PresentationSession::didChangeState(WebPresentationSessionState state)
+{
+ if (m_state == state)
+ return;
+
+ m_state = state;
+ dispatchEvent(Event::create(EventTypeNames::statechange));
+}
+
PresentationController* PresentationSession::presentationController()
{
if (!frame())
« 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