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

Unified Diff: third_party/WebKit/Source/modules/mediasession/MediaSession.cpp

Issue 2428523002: Add media controls to MediaSession in Blink (Closed)
Patch Set: Created 4 years, 2 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: third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
diff --git a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
index 9396d06843e9e67f71baaef9ee3d97071b653a36..2c909379aa49f3c1ed6526496fea06ee59cebce0 100644
--- a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
+++ b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
@@ -8,6 +8,7 @@
#include "core/dom/Document.h"
#include "core/dom/ExecutionContext.h"
#include "core/frame/LocalFrame.h"
+#include "modules/EventTargetModules.h"
#include "modules/mediasession/MediaMetadata.h"
#include "modules/mediasession/MediaMetadataSanitizer.h"
#include "public/platform/InterfaceProvider.h"
@@ -15,25 +16,33 @@
namespace blink {
-MediaSession::MediaSession() = default;
+MediaSession::MediaSession(ScriptState* scriptState)
+ : m_scriptState(scriptState) {}
-MediaSession* MediaSession::create() {
- return new MediaSession();
+MediaSession* MediaSession::create(ScriptState* scriptState) {
+ return new MediaSession(scriptState);
}
-void MediaSession::setMetadata(ScriptState* scriptState,
- MediaMetadata* metadata) {
- if (getService(scriptState)) {
- getService(scriptState)
- ->SetMetadata(
- MediaMetadataSanitizer::sanitizeAndConvertToMojo(metadata));
+void MediaSession::setMetadata(MediaMetadata* metadata) {
+ if (mojom::blink::MediaSessionService* service =
+ getService(m_scriptState.get())) {
+ service->SetMetadata(
+ MediaMetadataSanitizer::sanitizeAndConvertToMojo(metadata));
}
}
-MediaMetadata* MediaSession::metadata(ScriptState*) const {
+MediaMetadata* MediaSession::metadata() const {
return m_metadata;
}
+const WTF::AtomicString& MediaSession::interfaceName() const {
+ return EventTargetNames::MediaSession;
+}
+
+ExecutionContext* MediaSession::getExecutionContext() const {
+ return m_scriptState->getExecutionContext();
+}
+
mojom::blink::MediaSessionService* MediaSession::getService(
ScriptState* scriptState) {
if (!m_service) {
@@ -50,8 +59,27 @@ mojom::blink::MediaSessionService* MediaSession::getService(
return m_service.get();
}
+// TODO(zqzhang): register listener to MediaSessionService. See
+// https://crbug.com/xxxxxx
whywhat 2016/10/17 15:32:34 The link gives me 404.
Zhiqiang Zhang (Slow) 2016/10/17 17:19:08 Fixed.
+#define DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(attribute) \
whywhat 2016/10/17 15:32:35 Ditto in the header.
Zhiqiang Zhang (Slow) 2016/10/17 17:19:08 Done.
+ EventListener* MediaSession::on##attribute() { \
+ return getAttributeEventListener(EventTypeNames::attribute); \
+ } \
+ void MediaSession::setOn##attribute(EventListener* listener) { \
+ setAttributeEventListener(EventTypeNames::attribute, listener); \
+ }
+
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(play);
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(pause);
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(playpause);
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(previoustrack);
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(nexttrack);
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekforward);
+DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekbackward);
+
DEFINE_TRACE(MediaSession) {
visitor->trace(m_metadata);
+ EventTargetWithInlineData::trace(visitor);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698