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 2c909379aa49f3c1ed6526496fea06ee59cebce0..6c91cf55f22318676b917bdc4e348936726df6a4 100644 |
--- a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp |
+++ b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp |
@@ -7,6 +7,7 @@ |
#include "bindings/core/v8/ScriptState.h" |
#include "core/dom/Document.h" |
#include "core/dom/ExecutionContext.h" |
+#include "core/events/Event.h" |
#include "core/frame/LocalFrame.h" |
#include "modules/EventTargetModules.h" |
#include "modules/mediasession/MediaMetadata.h" |
@@ -17,7 +18,7 @@ |
namespace blink { |
MediaSession::MediaSession(ScriptState* scriptState) |
- : m_scriptState(scriptState) {} |
+ : m_scriptState(scriptState), m_clientBinding(this) {} |
MediaSession* MediaSession::create(ScriptState* scriptState) { |
return new MediaSession(scriptState); |
@@ -55,18 +56,23 @@ mojom::blink::MediaSessionService* MediaSession::getService( |
if (interfaceProvider) |
interfaceProvider->getInterface(mojo::GetProxy(&m_service)); |
+ |
+ m_service->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); |
} |
return m_service.get(); |
} |
-// TODO(zqzhang): register listener to MediaSessionService. See |
-// https://crbug.com/xxxxxx |
-#define DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
- EventListener* MediaSession::on##attribute() { \ |
- return getAttributeEventListener(EventTypeNames::attribute); \ |
- } \ |
- void MediaSession::setOn##attribute(EventListener* listener) { \ |
- setAttributeEventListener(EventTypeNames::attribute, listener); \ |
+#define DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
+ EventListener* MediaSession::on##attribute() { \ |
+ return getAttributeEventListener(EventTypeNames::attribute); \ |
+ } \ |
+ void MediaSession::setOn##attribute(EventListener* listener) { \ |
+ setAttributeEventListener(EventTypeNames::attribute, listener); \ |
+ if (mojom::blink::MediaSessionService* service = \ |
+ getService(m_scriptState.get())) { \ |
+ service->DidSetEventHandlerForAction(EventTypeNames::attribute, \ |
+ static_cast<bool>(listener)); \ |
+ } \ |
} |
DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(play); |
@@ -77,6 +83,11 @@ DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(nexttrack); |
DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekforward); |
DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekbackward); |
+void MediaSession::DidReceivedAction(const WTF::String& action) { |
+ StringView view(action); |
+ dispatchEvent(Event::create(view.toAtomicString())); |
+} |
+ |
DEFINE_TRACE(MediaSession) { |
visitor->trace(m_metadata); |
EventTargetWithInlineData::trace(visitor); |