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

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

Issue 2589893002: [Blink>MediaSession] Use setActionCallback() instead of event listeners for media control actions (Closed)
Patch Set: fixed tests Created 3 years, 11 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.h
diff --git a/third_party/WebKit/Source/modules/mediasession/MediaSession.h b/third_party/WebKit/Source/modules/mediasession/MediaSession.h
index afe12e4292d6811238bea5030dc886e6a8e6120e..e3ace93452aa5242f9383deed62f45a2fb9176a6 100644
--- a/third_party/WebKit/Source/modules/mediasession/MediaSession.h
+++ b/third_party/WebKit/Source/modules/mediasession/MediaSession.h
@@ -6,22 +6,25 @@
#define MediaSession_h
#include "bindings/core/v8/ScriptWrappable.h"
+#include "bindings/core/v8/TraceWrapperMember.h"
#include "core/dom/ContextLifecycleObserver.h"
-#include "core/events/EventTarget.h"
#include "modules/ModulesExport.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "platform/heap/Handle.h"
#include "public/platform/modules/mediasession/media_session.mojom-blink.h"
+#include "wtf/text/WTFString.h"
#include <memory>
namespace blink {
class ExecutionContext;
class MediaMetadata;
+class MediaSessionActionHandler;
class MODULES_EXPORT MediaSession final
- : public EventTargetWithInlineData,
+ : public GarbageCollectedFinalized<MediaSession>,
public ContextClient,
+ public ScriptWrappable,
blink::mojom::blink::MediaSessionClient {
USING_GARBAGE_COLLECTED_MIXIN(MediaSession);
DEFINE_WRAPPERTYPEINFO();
@@ -38,45 +41,41 @@ class MODULES_EXPORT MediaSession final
void setMetadata(MediaMetadata*);
MediaMetadata* metadata() const;
- // EventTarget implementation.
- const WTF::AtomicString& interfaceName() const override;
- ExecutionContext* getExecutionContext() const override;
+ void setActionHandler(const String& action, MediaSessionActionHandler*);
// Called by the MediaMetadata owned by |this| when it has updates. Also used
// internally when a new MediaMetadata object is set.
void onMetadataChanged();
- DEFINE_ATTRIBUTE_EVENT_LISTENER(play);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(pause);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(previoustrack);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(nexttrack);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(seekforward);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(seekbackward);
-
DECLARE_VIRTUAL_TRACE();
+ DECLARE_VIRTUAL_TRACE_WRAPPERS();
private:
+ friend class V8MediaSession;
friend class MediaSessionTest;
+ enum class ActionChangeType {
+ ActionEnabled,
+ ActionDisabled,
+ };
+
explicit MediaSession(ExecutionContext*);
- // EventTarget overrides
- bool addEventListenerInternal(
- const AtomicString& eventType,
- EventListener*,
- const AddEventListenerOptionsResolved&) override;
- bool removeEventListenerInternal(const AtomicString& eventType,
- const EventListener*,
- const EventListenerOptions&) override;
+ void notifyActionChange(const String& action, ActionChangeType);
// blink::mojom::blink::MediaSessionClient implementation.
void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override;
+ void setV8ReferencesForHandlers(v8::Isolate*,
+ const v8::Persistent<v8::Object>& wrapper);
+
// Returns null when the ExecutionContext is not document.
mojom::blink::MediaSessionService* getService();
mojom::blink::MediaSessionPlaybackState m_playbackState;
Member<MediaMetadata> m_metadata;
+ HeapHashMap<String, TraceWrapperMember<MediaSessionActionHandler>>
+ m_actionHandlers;
mojom::blink::MediaSessionServicePtr m_service;
mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding;
};

Powered by Google App Engine
This is Rietveld 408576698