From e4099c06837e4b955a23ff815fa6e318af7dc133 Mon Sep 17 00:00:00 2001 From: alwu Date: Tue, 29 Oct 2019 23:46:36 +0000 Subject: [PATCH] Bug 1591620 - part1 : make 'MediaControlKeysEventListener' as a pure interface. r=chunmin If the web extention also needs to implement its listener, they would definitely not need the current implementation in `KeyPressed()` for controlling media controller. Therefore, we should make `MediaControlKeysEventListener` as a pure interface and let inherited class to define their own `KeyPressed()`. Differential Revision: https://phabricator.services.mozilla.com/D50686 --HG-- extra : moz-landing-system : lando --- .../mediacontrol/MediaControlKeysEvent.cpp | 3 +-- .../mediacontrol/MediaControlKeysEvent.h | 19 ++++++++++++++----- .../mediacontrol/MediaControlKeysManager.cpp | 2 +- .../tests/gtest/TestMediaKeysEvent.cpp | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/dom/media/mediacontrol/MediaControlKeysEvent.cpp b/dom/media/mediacontrol/MediaControlKeysEvent.cpp index f877b515418a..fb1f8f46a0fe 100644 --- a/dom/media/mediacontrol/MediaControlKeysEvent.cpp +++ b/dom/media/mediacontrol/MediaControlKeysEvent.cpp @@ -42,8 +42,7 @@ static const char* ToMediaControlKeysEventStr(MediaControlKeysEvent aKeyEvent) { ToMediaControlKeysEventStr(key), ##__VA_ARGS__)); \ } -void MediaControlKeysEventListener::OnKeyPressed( - MediaControlKeysEvent aKeyEvent) { +void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) { LOG_KEY("OnKeyPressed '%s'", aKeyEvent); switch (aKeyEvent) { case MediaControlKeysEvent::ePlayPause: { diff --git a/dom/media/mediacontrol/MediaControlKeysEvent.h b/dom/media/mediacontrol/MediaControlKeysEvent.h index 38354a215cdc..1763cf1f901a 100644 --- a/dom/media/mediacontrol/MediaControlKeysEvent.h +++ b/dom/media/mediacontrol/MediaControlKeysEvent.h @@ -14,22 +14,31 @@ namespace dom { enum class MediaControlKeysEvent { ePlayPause, ePrev, eNext, eNone }; /** - * MediaControlKeysEventListener is used to monitor MediaControlKeysEvent, we - * can add it onto the MediaControlKeysEventSource, and then everytime when - * the media key events occur, `OnKeyPressed` will be called so that we can do - * related handling. + * MediaControlKeysEventListener is a pure interface, which is used to monitor + * MediaControlKeysEvent, we can add it onto the MediaControlKeysEventSource, + * and then everytime when the media key events occur, `OnKeyPressed` will be + * called so that we can do related handling. */ class MediaControlKeysEventListener { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaControlKeysEventListener); MediaControlKeysEventListener() = default; - virtual void OnKeyPressed(MediaControlKeysEvent aKeyEvent); + virtual void OnKeyPressed(MediaControlKeysEvent aKeyEvent) = 0; protected: virtual ~MediaControlKeysEventListener() = default; }; +/** + * MediaControlKeysHandler is used to operate media controller by corresponding + * received media control key events. + */ +class MediaControlKeysHandler final : public MediaControlKeysEventListener { + public: + void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override; +}; + /** * MediaControlKeysEventSource is a base class which is used to implement * transporting media control keys event to all its listeners when media keys diff --git a/dom/media/mediacontrol/MediaControlKeysManager.cpp b/dom/media/mediacontrol/MediaControlKeysManager.cpp index 19aec02709f1..f9c911c7f1e1 100644 --- a/dom/media/mediacontrol/MediaControlKeysManager.cpp +++ b/dom/media/mediacontrol/MediaControlKeysManager.cpp @@ -36,7 +36,7 @@ void MediaControlKeysManager::StartMonitoringControlKeys() { } CreateEventSource(); if (mEventSource) { - mEventSource->AddListener(new MediaControlKeysEventListener()); + mEventSource->AddListener(new MediaControlKeysHandler()); } } diff --git a/dom/media/mediacontrol/tests/gtest/TestMediaKeysEvent.cpp b/dom/media/mediacontrol/tests/gtest/TestMediaKeysEvent.cpp index b0682224978f..1c9e1c16ea5c 100644 --- a/dom/media/mediacontrol/tests/gtest/TestMediaKeysEvent.cpp +++ b/dom/media/mediacontrol/tests/gtest/TestMediaKeysEvent.cpp @@ -14,7 +14,7 @@ TEST(MediaControlKeysEvent, TestAddOrRemoveListener) ASSERT_TRUE(source->GetListenersNum() == 0); RefPtr listener = - new MediaControlKeysEventListener(); + new MediaControlKeysHandler(); source->AddListener(listener); ASSERT_TRUE(source->GetListenersNum() == 1);