Bug 1640998 - part9 : use `MediaControlKey` to replace `MediaControlKeysEvent` r=chunmin,agi,geckoview-reviewers

This patch will
- remove `MediaControlKeysEvent` and use `MediaControlKey` to replace it
- rename names for all `MediaControlKey` related methods, functions, classes and descriptions

The advantage of doing so are
- remove the duplicated type so that we only need to maintain `MediaControlKey`

Differential Revision: https://phabricator.services.mozilla.com/D78140
This commit is contained in:
alwu 2020-06-09 02:59:57 +00:00
Родитель 1b2d8c78ce
Коммит 934302cd0d
50 изменённых файлов: 510 добавлений и 632 удалений

Просмотреть файл

@ -356,11 +356,10 @@ uint32_t CanonicalBrowsingContext::CountSiteOrigins(
return uniqueSiteOrigins.Count();
}
void CanonicalBrowsingContext::UpdateMediaControlKeysEvent(
MediaControlKeysEvent aEvent) {
ContentMediaActionHandler::HandleMediaControlKeysEvent(this, aEvent);
void CanonicalBrowsingContext::UpdateMediaControlKey(MediaControlKey aKey) {
ContentMediaControlKeyHandler::HandleMediaControlKey(this, aKey);
Group()->EachParent([&](ContentParent* aParent) {
Unused << aParent->SendUpdateMediaControlKeysEvent(this, aEvent);
Unused << aParent->SendUpdateMediaControlKey(this, aKey);
});
}

Просмотреть файл

@ -8,7 +8,7 @@
#define mozilla_dom_CanonicalBrowsingContext_h
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/RefPtr.h"
#include "mozilla/MozPromise.h"
#include "nsCycleCollectionParticipant.h"
@ -122,9 +122,9 @@ class CanonicalBrowsingContext final : public BrowsingContext {
GlobalObject& aGlobal,
const Sequence<mozilla::OwningNonNull<BrowsingContext>>& aRoots);
// This function would update the media action for the current outer window
// This function would update media control key for the current outer window
// and propogate the action to other browsing contexts in content processes.
void UpdateMediaControlKeysEvent(MediaControlKeysEvent aEvent);
void UpdateMediaControlKey(MediaControlKey aKey);
// Triggers a load in the process
using BrowsingContext::LoadURI;

Просмотреть файл

@ -1294,12 +1294,11 @@ void ChromeUtils::PrivateNoteIntentionalCrash(const GlobalObject& aGlobal,
}
/* static */
void ChromeUtils::GenerateMediaControlKeysTestEvent(
const GlobalObject& aGlobal, MediaControlKeysTestEvent aEvent) {
void ChromeUtils::GenerateMediaControlKey(const GlobalObject& aGlobal,
MediaControlKey aKey) {
RefPtr<MediaControlService> service = MediaControlService::GetService();
if (service) {
service->GenerateMediaControlKeysTestEvent(
ConvertMediaControlKeysTestEventToMediaControlKeysEvent(aEvent));
service->GenerateTestMediaControlKey(aKey);
}
}

Просмотреть файл

@ -215,8 +215,8 @@ class ChromeUtils {
static void PrivateNoteIntentionalCrash(const GlobalObject& aGlobal,
ErrorResult& aError);
static void GenerateMediaControlKeysTestEvent(
const GlobalObject& aGlobal, MediaControlKeysTestEvent aEvent);
static void GenerateMediaControlKey(const GlobalObject& aGlobal,
MediaControlKey aKey);
static nsIContentChild* GetContentChild(const GlobalObject&);

Просмотреть файл

@ -474,7 +474,7 @@ partial namespace ChromeUtils {
// This is used to generate fake media control keys event in testing.
[ChromeOnly]
void generateMediaControlKeysTestEvent(MediaControlKeysTestEvent aEvent);
void generateMediaControlKey(MediaControlKey aKey);
/**
* ContentChild of the current process.
@ -733,19 +733,6 @@ enum PopupBlockerState {
"openOverridden",
};
// Keep this in sync with MediaControlKeysEvent in MediaControlKeysEvent.h!
enum MediaControlKeysTestEvent {
"focus",
"play",
"pause",
"playPause",
"previoustrack",
"nexttrack",
"seekbackward",
"seekforward",
"stop",
};
// Keep this in sync with MediaSessionPlaybackState in MediaSession.webidl!
// The reason we create an new enum MediaSessionPlaybackTestState is because of
// building issue. If we use MediaSessionPlaybackState directly, then the

Просмотреть файл

@ -380,7 +380,7 @@ class nsSourceErrorEventRunner : public nsMediaEvent {
};
/**
* We use MediaControlEventListener to listen MediaControlKeysEvent in order to
* We use MediaControlKeyListener to listen to media control key in order to
* play and pause media element when user press media control keys and update
* media's playback and audible state to the media controller.
*
@ -388,12 +388,12 @@ class nsSourceErrorEventRunner : public nsMediaEvent {
* event. In addition, notifying any change to media controller MUST be done
* after successfully calling `Start()`.
*/
class HTMLMediaElement::MediaControlEventListener final
: public ContentControlKeyEventReceiver {
class HTMLMediaElement::MediaControlKeyListener final
: public ContentMediaControlKeyReceiver {
public:
NS_INLINE_DECL_REFCOUNTING(MediaControlEventListener, override)
NS_INLINE_DECL_REFCOUNTING(MediaControlKeyListener, override)
MOZ_INIT_OUTSIDE_CTOR explicit MediaControlEventListener(
MOZ_INIT_OUTSIDE_CTOR explicit MediaControlKeyListener(
HTMLMediaElement* aElement)
: mElement(aElement) {
MOZ_ASSERT(NS_IsMainThread());
@ -495,14 +495,14 @@ class HTMLMediaElement::MediaControlEventListener final
mIsPictureInPictureEnabled);
}
void HandleEvent(MediaControlKeysEvent aEvent) override {
void HandleMediaKey(MediaControlKey aKey) override {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsStarted());
MEDIACONTROL_LOG("HandleEvent '%s'", ToMediaControlKeysEventStr(aEvent));
if (aEvent == MediaControlKeysEvent::ePlay && Owner()->Paused()) {
MEDIACONTROL_LOG("HandleEvent '%s'", ToMediaControlKeyStr(aKey));
if (aKey == MediaControlKey::Play && Owner()->Paused()) {
Owner()->Play();
} else if ((aEvent == MediaControlKeysEvent::ePause ||
aEvent == MediaControlKeysEvent::eStop) &&
} else if ((aKey == MediaControlKey::Pause ||
aKey == MediaControlKey::Stop) &&
!Owner()->Paused()) {
Owner()->Pause();
}
@ -539,7 +539,7 @@ class HTMLMediaElement::MediaControlEventListener final
}
private:
~MediaControlEventListener() = default;
~MediaControlKeyListener() = default;
// The media can be moved around different browsing contexts, so this context
// might be different from the one that we used to initialize
@ -1952,9 +1952,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement,
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingPlayPromises)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSeekDOMPromise)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSetMediaKeysDOMPromise)
if (tmp->mMediaControlEventListener) {
tmp->StopListeningMediaControlEventIfNeeded();
tmp->mMediaControlEventListener = nullptr;
if (tmp->mMediaControlKeyListener) {
tmp->StopListeningMediaControlKeyIfNeeded();
tmp->mMediaControlKeyListener = nullptr;
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_PTR
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@ -4194,8 +4194,8 @@ HTMLMediaElement::~HTMLMediaElement() {
mResumeDelayedPlaybackAgent = nullptr;
}
StopListeningMediaControlEventIfNeeded();
mMediaControlEventListener = nullptr;
StopListeningMediaControlKeyIfNeeded();
mMediaControlKeyListener = nullptr;
WakeLockRelease();
ReportPlayedTimeAfterBlockedTelemetry();
@ -4395,7 +4395,7 @@ void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
UpdatePreloadAction();
UpdateSrcMediaStreamPlaying();
StartListeningMediaControlEventIfNeeded();
StartListeningMediaControlKeyIfNeeded();
// Once play() has been called in a user generated event handler,
// it is allowed to autoplay. Note: we can reach here when not in
@ -4690,8 +4690,8 @@ nsresult HTMLMediaElement::BindToTree(BindContext& aContext, nsINode& aParent) {
}
NotifyDecoderActivityChanges();
if (mMediaControlEventListener) {
mMediaControlEventListener->UpdateOwnerBrowsingContextIfNeeded();
if (mMediaControlKeyListener) {
mMediaControlKeyListener->UpdateOwnerBrowsingContextIfNeeded();
}
return rv;
@ -6136,7 +6136,7 @@ void HTMLMediaElement::CheckAutoplayDataReady() {
UpdateSrcMediaStreamPlaying();
UpdateAudioChannelPlayingState();
StartListeningMediaControlEventIfNeeded();
StartListeningMediaControlKeyIfNeeded();
if (mDecoder) {
SetPlayedOrSeeked(true);
@ -6471,7 +6471,7 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aSuspendElement) {
mEventDeliveryPaused = true;
// We won't want to resume media element from the bfcache.
ClearResumeDelayedMediaPlaybackAgentIfNeeded();
StopListeningMediaControlEventIfNeeded();
StopListeningMediaControlKeyIfNeeded();
} else {
if (!mPaused) {
mCurrentLoadPlayTime.Start();
@ -6497,9 +6497,8 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aSuspendElement) {
}
// If we stopped listening to the event when we suspended media element,
// then we should restart to listen to the event if we haven't done so yet.
if (mMediaControlEventListener &&
!mMediaControlEventListener->IsStarted()) {
StartListeningMediaControlEventIfNeeded();
if (mMediaControlKeyListener && !mMediaControlKeyListener->IsStarted()) {
StartListeningMediaControlKeyIfNeeded();
}
}
if (StaticPrefs::media_testing_only_events()) {
@ -7348,8 +7347,8 @@ void HTMLMediaElement::NotifyAudioPlaybackChanged(
if (mAudioChannelWrapper) {
mAudioChannelWrapper->NotifyAudioPlaybackChanged(aReason);
}
if (mMediaControlEventListener && mMediaControlEventListener->IsStarted()) {
mMediaControlEventListener->UpdateMediaAudibleState(IsAudible());
if (mMediaControlKeyListener && mMediaControlKeyListener->IsStarted()) {
mMediaControlKeyListener->UpdateMediaAudibleState(IsAudible());
}
// only request wake lock for audible media.
UpdateWakeLock();
@ -7789,17 +7788,17 @@ void HTMLMediaElement::ClearResumeDelayedMediaPlaybackAgentIfNeeded() {
}
void HTMLMediaElement::NotifyMediaControlPlaybackStateChanged() {
if (!mMediaControlEventListener || !mMediaControlEventListener->IsStarted()) {
if (!mMediaControlKeyListener || !mMediaControlKeyListener->IsStarted()) {
return;
}
if (mPaused) {
mMediaControlEventListener->NotifyMediaStoppedPlaying();
mMediaControlKeyListener->NotifyMediaStoppedPlaying();
} else {
mMediaControlEventListener->NotifyMediaStartedPlaying();
mMediaControlKeyListener->NotifyMediaStartedPlaying();
}
}
void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
void HTMLMediaElement::StartListeningMediaControlKeyIfNeeded() {
if (mPaused) {
MEDIACONTROL_LOG("Not listening because media is paused");
return;
@ -7819,12 +7818,12 @@ void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
// should clear the timer, which is used to stop listening to the event.
ClearStopMediaControlTimerIfNeeded();
if (!mMediaControlEventListener) {
mMediaControlEventListener = new MediaControlEventListener(this);
if (!mMediaControlKeyListener) {
mMediaControlKeyListener = new MediaControlKeyListener(this);
}
if (mMediaControlEventListener->IsStarted() ||
!mMediaControlEventListener->Start()) {
if (mMediaControlKeyListener->IsStarted() ||
!mMediaControlKeyListener->Start()) {
return;
}
@ -7837,17 +7836,17 @@ void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
// `UpdateMediaAudibleState()` could only be used after we start the listener,
// but the audible state update could happen before that. Therefore, we have
// to manually update media's audible state as well.
mMediaControlEventListener->UpdateMediaAudibleState(IsAudible());
mMediaControlKeyListener->UpdateMediaAudibleState(IsAudible());
// Picture-in-Picture mode can be enabled before we start the listener so we
// manually update the status here in case not to forgot to propagate that.
mMediaControlEventListener->SetPictureInPictureModeEnabled(
mMediaControlKeyListener->SetPictureInPictureModeEnabled(
IsBeingUsedInPictureInPictureMode());
}
void HTMLMediaElement::StopListeningMediaControlEventIfNeeded() {
if (mMediaControlEventListener && mMediaControlEventListener->IsStarted()) {
mMediaControlEventListener->Stop();
void HTMLMediaElement::StopListeningMediaControlKeyIfNeeded() {
if (mMediaControlKeyListener && mMediaControlKeyListener->IsStarted()) {
mMediaControlKeyListener->Stop();
}
}
@ -7858,16 +7857,16 @@ void HTMLMediaElement::StopMediaControlTimerCallback(nsITimer* aTimer,
auto element = static_cast<HTMLMediaElement*>(aClosure);
CONTROLLER_TIMER_LOG(element,
"Runnning stop media control timmer callback function");
element->StopListeningMediaControlEventIfNeeded();
element->StopListeningMediaControlKeyIfNeeded();
element->mStopMediaControlTimer = nullptr;
}
void HTMLMediaElement::CreateStopMediaControlTimerIfNeeded() {
MOZ_ASSERT(NS_IsMainThread());
// We would create timer only when `mMediaControlEventListener` exists and has
// We would create timer only when `mMediaControlKeyListener` exists and has
// been started.
if (mStopMediaControlTimer || !mMediaControlEventListener ||
!mMediaControlEventListener->IsStarted()) {
if (mStopMediaControlTimer || !mMediaControlKeyListener ||
!mMediaControlKeyListener->IsStarted()) {
return;
}
@ -7903,13 +7902,13 @@ void HTMLMediaElement::ClearStopMediaControlTimerIfNeeded() {
void HTMLMediaElement::UpdateMediaControlAfterPictureInPictureModeChanged() {
// Hasn't started to connect with media control, no need to update anything.
if (!mMediaControlEventListener || !mMediaControlEventListener->IsStarted()) {
if (!mMediaControlKeyListener || !mMediaControlKeyListener->IsStarted()) {
return;
}
if (IsBeingUsedInPictureInPictureMode()) {
mMediaControlEventListener->SetPictureInPictureModeEnabled(true);
mMediaControlKeyListener->SetPictureInPictureModeEnabled(true);
} else {
mMediaControlEventListener->SetPictureInPictureModeEnabled(false);
mMediaControlKeyListener->SetPictureInPictureModeEnabled(false);
CreateStopMediaControlTimerIfNeeded();
}
}

Просмотреть файл

@ -21,7 +21,6 @@
#include "mozilla/StateWatching.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/dom/HTMLMediaElementBinding.h"
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaDebugInfoBinding.h"
#include "mozilla/dom/MediaKeys.h"
#include "mozilla/dom/TextTrackManager.h"
@ -765,7 +764,7 @@ class HTMLMediaElement : public nsGenericHTMLElement,
class MediaStreamTrackListener;
class FirstFrameListener;
class ShutdownObserver;
class MediaControlEventListener;
class MediaControlKeyListener;
MediaDecoderOwner::NextFrameStatus NextFrameStatus();
@ -1934,11 +1933,11 @@ class HTMLMediaElement : public nsGenericHTMLElement,
MozPromiseRequestHolder<ResumeDelayedPlaybackAgent::ResumePromise>
mResumePlaybackRequest;
// We use MediaControlEventListener to listen media control keys event, which
// would play or pause media element according to different events.
void StartListeningMediaControlEventIfNeeded();
void StopListeningMediaControlEventIfNeeded();
RefPtr<MediaControlEventListener> mMediaControlEventListener;
// We use MediaControlKeyListener to listen media control key, by which we
// would play or pause media element.
void StartListeningMediaControlKeyIfNeeded();
void StopListeningMediaControlKeyIfNeeded();
RefPtr<MediaControlKeyListener> mMediaControlKeyListener;
// Return true if the media element is being used in picture in picture mode.
bool IsBeingUsedInPictureInPictureMode() const;

Просмотреть файл

@ -248,7 +248,7 @@
#endif
#include "mozilla/dom/File.h"
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/dom/PPresentationChild.h"
#include "mozilla/dom/PresentationIPCService.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
@ -3482,15 +3482,13 @@ mozilla::ipc::IPCResult ContentChild::RecvStartDelayedAutoplayMediaComponents(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvUpdateMediaControlKeysEvent(
const MaybeDiscarded<BrowsingContext>& aContext,
MediaControlKeysEvent aEvent) {
mozilla::ipc::IPCResult ContentChild::RecvUpdateMediaControlKey(
const MaybeDiscarded<BrowsingContext>& aContext, MediaControlKey aKey) {
if (NS_WARN_IF(aContext.IsNullOrDiscarded())) {
return IPC_OK();
}
ContentMediaActionHandler::HandleMediaControlKeysEvent(aContext.get(),
aEvent);
ContentMediaControlKeyHandler::HandleMediaControlKey(aContext.get(), aKey);
return IPC_OK();
}

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/dom/BrowserBridgeChild.h"
#include "mozilla/dom/ProcessActor.h"
#include "mozilla/dom/JSProcessActorChild.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/dom/PContentChild.h"
#include "mozilla/dom/RemoteBrowser.h"
#include "mozilla/StaticPtr.h"
@ -71,7 +72,6 @@ class ClonedMessageData;
class BrowserChild;
class GetFilesHelperChild;
class TabContext;
enum class MediaControlKeysEvent : uint32_t;
class ContentChild final : public PContentChild,
public nsIContentChild,
@ -631,9 +631,8 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvStartDelayedAutoplayMediaComponents(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvUpdateMediaControlKeysEvent(
const MaybeDiscarded<BrowsingContext>& aContext,
MediaControlKeysEvent aEvent);
mozilla::ipc::IPCResult RecvUpdateMediaControlKey(
const MaybeDiscarded<BrowsingContext>& aContext, MediaControlKey aKey);
void HoldBrowsingContextGroup(BrowsingContextGroup* aBCG);
void ReleaseBrowsingContextGroup(BrowsingContextGroup* aBCG);

Просмотреть файл

@ -112,7 +112,7 @@ using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasi
using mozilla::fontlist::Pointer from "SharedFontList.h";
using gfxSparseBitSet from "gfxFontUtils.h";
using FontVisibility from "gfxFontEntry.h";
using mozilla::dom::MediaControlKeysEvent from "ipc/MediaControlIPC.h";
using mozilla::dom::MediaControlKey from "ipc/MediaControlIPC.h";
using mozilla::dom::MediaPlaybackState from "ipc/MediaControlIPC.h";
using mozilla::dom::MediaAudibleState from "ipc/MediaControlIPC.h";
using mozilla::dom::MaybeMediaMetadataBase from "mozilla/dom/MediaSessionIPCUtils.h";
@ -854,11 +854,11 @@ child:
async StartDelayedAutoplayMediaComponents(MaybeDiscardedBrowsingContext aContext);
/**
* This method is used to dispatch MediaControlKeysEvent to content process
* in order to control media within a specific browsing context tree.
* This method is used to dispatch MediaControlKey to content process in
* order to control media within a specific browsing context tree.
*/
async UpdateMediaControlKeysEvent(MaybeDiscardedBrowsingContext aContext,
MediaControlKeysEvent aEvent);
async UpdateMediaControlKey(MaybeDiscardedBrowsingContext aContext,
MediaControlKey aKey);
// Begin subscribing to a new BrowsingContextGroup, sending down the current
// value for every individual BrowsingContext.

Просмотреть файл

@ -52,13 +52,13 @@ GetContentMediaControllerFromBrowsingContext(
}
/* static */
ContentControlKeyEventReceiver* ContentControlKeyEventReceiver::Get(
ContentMediaControlKeyReceiver* ContentMediaControlKeyReceiver::Get(
BrowsingContext* aBC) {
MOZ_ASSERT(NS_IsMainThread());
RefPtr<ContentMediaController> controller =
GetContentMediaControllerFromBrowsingContext(aBC);
return controller
? static_cast<ContentControlKeyEventReceiver*>(controller.get())
? static_cast<ContentMediaControlKeyReceiver*>(controller.get())
: nullptr;
}
@ -270,13 +270,13 @@ ContentMediaController::ContentMediaController(uint64_t aId)
: mTopLevelBrowsingContextId(aId) {}
void ContentMediaController::AddReceiver(
ContentControlKeyEventReceiver* aListener) {
ContentMediaControlKeyReceiver* aListener) {
MOZ_ASSERT(NS_IsMainThread());
mReceivers.AppendElement(aListener);
}
void ContentMediaController::RemoveReceiver(
ContentControlKeyEventReceiver* aListener) {
ContentMediaControlKeyReceiver* aListener) {
MOZ_ASSERT(NS_IsMainThread());
mReceivers.RemoveElement(aListener);
// No more media needs to be controlled, so we can release this and recreate
@ -287,12 +287,12 @@ void ContentMediaController::RemoveReceiver(
}
}
void ContentMediaController::HandleEvent(MediaControlKeysEvent aEvent) {
void ContentMediaController::HandleMediaKey(MediaControlKey aKey) {
MOZ_ASSERT(NS_IsMainThread());
LOG("Handle '%s' event, receiver num=%zu", ToMediaControlKeysEventStr(aEvent),
LOG("Handle '%s' event, receiver num=%zu", ToMediaControlKeyStr(aKey),
mReceivers.Length());
for (auto& receiver : mReceivers) {
receiver->HandleEvent(aEvent);
receiver->HandleMediaKey(aKey);
}
}

Просмотреть файл

@ -5,7 +5,7 @@
#ifndef DOM_MEDIA_MEDIACONTROL_CONTENTMEDIACONTROLLER_H_
#define DOM_MEDIA_MEDIACONTROL_CONTENTMEDIACONTROLLER_H_
#include "MediaControlKeysEvent.h"
#include "MediaControlKeySource.h"
#include "MediaStatusManager.h"
namespace mozilla {
@ -14,36 +14,35 @@ namespace dom {
class BrowsingContext;
/**
* ContentControlKeyEventReceiver is an interface which is used to receive media
* control key events sent from the chrome process, this class MUST only be used
* ContentMediaControlKeyReceiver is an interface which is used to receive media
* control key sent from the chrome process, this class MUST only be used
* in PlaybackController.
*
* Each browsing context tree would only have one ContentControlKeyEventReceiver
* that is used to handle media control key events for that browsing context
* tree.
* Each browsing context tree would only have one ContentMediaControlKeyReceiver
* that is used to handle media control key for that browsing context tree.
*/
class ContentControlKeyEventReceiver {
class ContentMediaControlKeyReceiver {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
// Return nullptr if the top level browsing context is no longer alive.
static ContentControlKeyEventReceiver* Get(BrowsingContext* aBC);
static ContentMediaControlKeyReceiver* Get(BrowsingContext* aBC);
// Use this method to handle the event from `ContentMediaAgent`.
virtual void HandleEvent(MediaControlKeysEvent aKeyEvent) = 0;
virtual void HandleMediaKey(MediaControlKey aKey) = 0;
};
/**
* ContentMediaAgent is an interface which we use to (1) propoagate media
* related information from the content process to the chrome process (2) act an
* event source to dispatch control key events to its listeners.
* event source to dispatch media control key to its listeners.
*
* If the media would like to know the media control key events, then media
* MUST inherit from ContentControlKeyEventReceiver, and register themselves to
* ContentMediaAgent. Whenever media key events occur, ContentMediaAgent would
* notify all its receivers. In addition, whenever controlled media changes its
* playback status or audible state, they should update their status update via
* ContentMediaAgent.
* If the media would like to know the media control key, then media MUST
* inherit from ContentMediaControlKeyReceiver, and register themselves to
* ContentMediaAgent. Whenever media control key delivers, ContentMediaAgent
* would notify all its receivers. In addition, whenever controlled media
* changes its playback status or audible state, they should update their status
* update via ContentMediaAgent.
*
* Each browsing context tree would only have one ContentMediaAgent that is used
* to update controlled media status existing in that browsing context tree.
@ -71,10 +70,10 @@ class ContentMediaAgent : public IMediaInfoUpdater {
void DisableAction(uint64_t aBrowsingContextId,
MediaSessionAction aAction) override;
// Use these methods to register/unregister `ContentControlKeyEventReceiver`
// Use these methods to register/unregister `ContentMediaControlKeyReceiver`
// in order to listen to media control key events.
virtual void AddReceiver(ContentControlKeyEventReceiver* aReceiver) = 0;
virtual void RemoveReceiver(ContentControlKeyEventReceiver* aReceiver) = 0;
virtual void AddReceiver(ContentMediaControlKeyReceiver* aReceiver) = 0;
virtual void RemoveReceiver(ContentMediaControlKeyReceiver* aReceiver) = 0;
};
/**
@ -95,22 +94,22 @@ class ContentMediaAgent : public IMediaInfoUpdater {
* ContentMediaController in each process to manage media.
*/
class ContentMediaController final : public ContentMediaAgent,
public ContentControlKeyEventReceiver {
public ContentMediaControlKeyReceiver {
public:
NS_INLINE_DECL_REFCOUNTING(ContentMediaController, override)
explicit ContentMediaController(uint64_t aId);
// ContentMediaAgent methods
void AddReceiver(ContentControlKeyEventReceiver* aListener) override;
void RemoveReceiver(ContentControlKeyEventReceiver* aListener) override;
void AddReceiver(ContentMediaControlKeyReceiver* aListener) override;
void RemoveReceiver(ContentMediaControlKeyReceiver* aListener) override;
// ContentControlKeyEventReceiver method
void HandleEvent(MediaControlKeysEvent aEvent) override;
// ContentMediaControlKeyReceiver method
void HandleMediaKey(MediaControlKey aKey) override;
private:
~ContentMediaController() = default;
nsTArray<RefPtr<ContentControlKeyEventReceiver>> mReceivers;
nsTArray<RefPtr<ContentMediaControlKeyReceiver>> mReceivers;
uint64_t mTopLevelBrowsingContextId;
};

Просмотреть файл

@ -35,12 +35,12 @@ MediaSession* ContentPlaybackController::GetMediaSession() const {
: nullptr;
}
void ContentPlaybackController::NotifyContentControlKeyEventReceiver(
MediaControlKeysEvent aEvent) {
if (RefPtr<ContentControlKeyEventReceiver> receiver =
ContentControlKeyEventReceiver::Get(mBC)) {
LOG("Handle '%s' in default behavior", ToMediaControlKeysEventStr(aEvent));
receiver->HandleEvent(aEvent);
void ContentPlaybackController::NotifyContentMediaControlKeyReceiver(
MediaControlKey aKey) {
if (RefPtr<ContentMediaControlKeyReceiver> receiver =
ContentMediaControlKeyReceiver::Get(mBC)) {
LOG("Handle '%s' in default behavior", ToMediaControlKeyStr(aKey));
receiver->HandleMediaKey(aKey);
}
}
@ -78,7 +78,7 @@ void ContentPlaybackController::Play() {
if (IsMediaSessionActionSupported(action)) {
NotifyMediaSession(action);
} else {
NotifyContentControlKeyEventReceiver(MediaControlKeysEvent::ePlay);
NotifyContentMediaControlKeyReceiver(MediaControlKey::Play);
}
}
@ -87,7 +87,7 @@ void ContentPlaybackController::Pause() {
if (IsMediaSessionActionSupported(action)) {
NotifyMediaSession(action);
} else {
NotifyContentControlKeyEventReceiver(MediaControlKeysEvent::ePause);
NotifyContentMediaControlKeyReceiver(MediaControlKey::Pause);
}
}
@ -118,7 +118,7 @@ void ContentPlaybackController::Stop() {
if (IsMediaSessionActionSupported(action)) {
NotifyMediaSession(action);
} else {
NotifyContentControlKeyEventReceiver(MediaControlKeysEvent::eStop);
NotifyContentMediaControlKeyReceiver(MediaControlKey::Stop);
}
}
@ -128,32 +128,32 @@ void ContentPlaybackController::SeekTo() {
return;
}
void ContentMediaActionHandler::HandleMediaControlKeysEvent(
BrowsingContext* aContext, MediaControlKeysEvent aEvent) {
void ContentMediaControlKeyHandler::HandleMediaControlKey(
BrowsingContext* aContext, MediaControlKey aKey) {
ContentPlaybackController controller(aContext);
switch (aEvent) {
case MediaControlKeysEvent::eFocus:
switch (aKey) {
case MediaControlKey::Focus:
controller.Focus();
return;
case MediaControlKeysEvent::ePlay:
case MediaControlKey::Play:
controller.Play();
return;
case MediaControlKeysEvent::ePause:
case MediaControlKey::Pause:
controller.Pause();
return;
case MediaControlKeysEvent::eStop:
case MediaControlKey::Stop:
controller.Stop();
return;
case MediaControlKeysEvent::ePrevTrack:
case MediaControlKey::Previoustrack:
controller.PreviousTrack();
return;
case MediaControlKeysEvent::eNextTrack:
case MediaControlKey::Nexttrack:
controller.NextTrack();
return;
case MediaControlKeysEvent::eSeekBackward:
case MediaControlKey::Seekbackward:
controller.SeekBackward();
return;
case MediaControlKeysEvent::eSeekForward:
case MediaControlKey::Seekforward:
controller.SeekForward();
return;
default:

Просмотреть файл

@ -5,7 +5,7 @@
#ifndef DOM_MEDIA_MEDIACONTROL_CONTENTPLAYBACKCONTROLLER_H_
#define DOM_MEDIA_MEDIACONTROL_CONTENTPLAYBACKCONTROLLER_H_
#include "MediaControlKeysEvent.h"
#include "MediaControlKeySource.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/BrowsingContext.h"
@ -51,7 +51,7 @@ class MOZ_STACK_CLASS ContentPlaybackController {
void SeekTo();
private:
void NotifyContentControlKeyEventReceiver(MediaControlKeysEvent aEvent);
void NotifyContentMediaControlKeyReceiver(MediaControlKey aKey);
void NotifyMediaSession(MediaSessionAction aAction);
void NotifyMediaSessionWhenActionIsSupported(MediaSessionAction aAction);
bool IsMediaSessionActionSupported(MediaSessionAction aAction) const;
@ -60,10 +60,10 @@ class MOZ_STACK_CLASS ContentPlaybackController {
RefPtr<BrowsingContext> mBC;
};
class ContentMediaActionHandler {
class ContentMediaControlKeyHandler {
public:
static void HandleMediaControlKeysEvent(BrowsingContext* aContext,
MediaControlKeysEvent aEvent);
static void HandleMediaControlKey(BrowsingContext* aContext,
MediaControlKey aKey);
};
} // namespace dom

Просмотреть файл

@ -9,16 +9,15 @@
#include "ipc/IPCMessageUtils.h"
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaStatusManager.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/dom/MediaPlaybackStatus.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::dom::MediaControlKeysEvent>
struct ParamTraits<mozilla::dom::MediaControlKey>
: public ContiguousEnumSerializerInclusive<
mozilla::dom::MediaControlKeysEvent,
mozilla::dom::MediaControlKeysEvent::eFocus,
mozilla::dom::MediaControlKeysEvent::eStop> {};
mozilla::dom::MediaControlKey, mozilla::dom::MediaControlKey::Focus,
mozilla::dom::MediaControlKey::Stop> {};
template <>
struct ParamTraits<mozilla::dom::MediaPlaybackState>

Просмотреть файл

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaControlKeysManager.h"
#include "MediaControlKeyManager.h"
#include "MediaControlUtils.h"
#include "MediaControlService.h"
@ -15,18 +15,18 @@
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlKeysManager=%p, " msg, this, ##__VA_ARGS__))
("MediaControlKeyManager=%p, " msg, this, ##__VA_ARGS__))
#undef LOG_INFO
#define LOG_INFO(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Info, \
("MediaControlKeysManager=%p, " msg, this, ##__VA_ARGS__))
("MediaControlKeyManager=%p, " msg, this, ##__VA_ARGS__))
namespace mozilla {
namespace dom {
bool MediaControlKeysManager::IsOpened() const {
// As MediaControlKeysManager represents a platform-indenpendent event source,
bool MediaControlKeyManager::IsOpened() const {
// As MediaControlKeyManager represents a platform-indenpendent event source,
// which we can use to add other listeners to moniter media key events, we
// would always return true even if we fail to open the real media key event
// source, because we still have chances to open the source again when there
@ -34,28 +34,28 @@ bool MediaControlKeysManager::IsOpened() const {
return true;
}
bool MediaControlKeysManager::Open() {
bool MediaControlKeyManager::Open() {
mControllerAmountChangedListener =
MediaControlService::GetService()
->MediaControllerAmountChangedEvent()
.Connect(AbstractThread::MainThread(), this,
&MediaControlKeysManager::ControllerAmountChanged);
&MediaControlKeyManager::ControllerAmountChanged);
return true;
}
MediaControlKeysManager::~MediaControlKeysManager() {
MediaControlKeyManager::~MediaControlKeyManager() {
StopMonitoringControlKeys();
mEventSource = nullptr;
mControllerAmountChangedListener.DisconnectIfExists();
}
void MediaControlKeysManager::StartMonitoringControlKeys() {
void MediaControlKeyManager::StartMonitoringControlKeys() {
if (!StaticPrefs::media_hardwaremediakeys_enabled()) {
return;
}
if (!mEventSource) {
mEventSource = widget::CreateMediaControlKeysEventSource();
mEventSource = widget::CreateMediaControlKeySource();
}
// When cross-compiling with MinGW, we cannot use the related WinAPI, thus
@ -72,14 +72,14 @@ void MediaControlKeysManager::StartMonitoringControlKeys() {
}
}
void MediaControlKeysManager::StopMonitoringControlKeys() {
void MediaControlKeyManager::StopMonitoringControlKeys() {
if (mEventSource && mEventSource->IsOpened()) {
LOG_INFO("StopMonitoringControlKeys");
mEventSource->Close();
}
}
void MediaControlKeysManager::ControllerAmountChanged(
void MediaControlKeyManager::ControllerAmountChanged(
uint64_t aControllerAmount) {
LOG("Controller amount changed=%" PRId64, aControllerAmount);
if (aControllerAmount > 0) {
@ -89,13 +89,13 @@ void MediaControlKeysManager::ControllerAmountChanged(
}
}
void MediaControlKeysManager::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
void MediaControlKeyManager::OnKeyPressed(MediaControlKey aKey) {
for (auto listener : mListeners) {
listener->OnKeyPressed(aKeyEvent);
listener->OnKeyPressed(aKey);
}
}
void MediaControlKeysManager::SetPlaybackState(
void MediaControlKeyManager::SetPlaybackState(
MediaSessionPlaybackState aState) {
if (mEventSource && mEventSource->IsOpened()) {
mEventSource->SetPlaybackState(aState);
@ -110,13 +110,13 @@ void MediaControlKeysManager::SetPlaybackState(
}
}
MediaSessionPlaybackState MediaControlKeysManager::GetPlaybackState() const {
MediaSessionPlaybackState MediaControlKeyManager::GetPlaybackState() const {
return (mEventSource && mEventSource->IsOpened())
? mEventSource->GetPlaybackState()
: mPlaybackState;
}
void MediaControlKeysManager::SetMediaMetadata(
void MediaControlKeyManager::SetMediaMetadata(
const MediaMetadataBase& aMetadata) {
if (mEventSource && mEventSource->IsOpened()) {
mEventSource->SetMediaMetadata(aMetadata);
@ -134,11 +134,11 @@ void MediaControlKeysManager::SetMediaMetadata(
}
}
void MediaControlKeysManager::SetSupportedMediaKeys(
void MediaControlKeyManager::SetSupportedMediaKeys(
const MediaKeysArray& aSupportedKeys) {
mSupportedKeys.Clear();
for (const auto& key : aSupportedKeys) {
LOG_INFO("Supported keys=%s", ToMediaControlKeysEventStr(key));
LOG_INFO("Supported keys=%s", ToMediaControlKeyStr(key));
mSupportedKeys.AppendElement(key);
}
if (mEventSource && mEventSource->IsOpened()) {

Просмотреть файл

@ -2,39 +2,39 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSMANAGER_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSMANAGER_H_
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYMANAGER_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYMANAGER_H_
#include "MediaControlKeysEvent.h"
#include "MediaControlKeySource.h"
#include "MediaEventSource.h"
namespace mozilla {
namespace dom {
/**
* MediaControlKeysManager is a wrapper of MediaControlKeysEventSource, which
* MediaControlKeyManager is a wrapper of MediaControlKeySource, which
* is used to manage creating and destroying a real media keys event source.
*
* It monitors the amount of the media controller in MediaService, and would
* create the event source when there is any existing controller and destroy it
* when there is no controller.
*/
class MediaControlKeysManager final : public MediaControlKeysEventSource,
public MediaControlKeysEventListener {
class MediaControlKeyManager final : public MediaControlKeySource,
public MediaControlKeyListener {
public:
NS_INLINE_DECL_REFCOUNTING(MediaControlKeysManager, override)
NS_INLINE_DECL_REFCOUNTING(MediaControlKeyManager, override)
MediaControlKeysManager() = default;
MediaControlKeyManager() = default;
// MediaControlKeysEventSource methods
// MediaControlKeySource methods
bool Open() override;
bool IsOpened() const override;
void SetPlaybackState(MediaSessionPlaybackState aState) override;
MediaSessionPlaybackState GetPlaybackState() const override;
// MediaControlKeysEventListener methods
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override;
// MediaControlKeyListener methods
void OnKeyPressed(MediaControlKey aKey) override;
// The callback function for monitoring the media controller amount changed
// event.
@ -44,13 +44,13 @@ class MediaControlKeysManager final : public MediaControlKeysEventSource,
void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override;
private:
~MediaControlKeysManager();
~MediaControlKeyManager();
void StartMonitoringControlKeys();
void StopMonitoringControlKeys();
RefPtr<MediaControlKeysEventSource> mEventSource;
RefPtr<MediaControlKeySource> mEventSource;
MediaEventListener mControllerAmountChangedListener;
MediaMetadataBase mMetadata;
nsTArray<MediaControlKeysEvent> mSupportedKeys;
nsTArray<MediaControlKey> mSupportedKeys;
};
} // namespace dom

Просмотреть файл

@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaControlKeysEvent.h"
#include "MediaControlKeySource.h"
#include "MediaController.h"
#include "MediaControlUtils.h"
@ -18,16 +18,16 @@ namespace dom {
#undef LOG_SOURCE
#define LOG_SOURCE(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlKeysEventSource=%p, " msg, this, ##__VA_ARGS__))
("MediaControlKeySource=%p, " msg, this, ##__VA_ARGS__))
#undef LOG_KEY
#define LOG_KEY(msg, key, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlKeysHandler=%p, " msg, this, \
ToMediaControlKeysEventStr(key), ##__VA_ARGS__));
#define LOG_KEY(msg, key, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlKeyHandler=%p, " msg, this, ToMediaControlKeyStr(key), \
##__VA_ARGS__));
void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
LOG_KEY("OnKeyPressed '%s'", aKeyEvent);
void MediaControlKeyHandler::OnKeyPressed(MediaControlKey aKey) {
LOG_KEY("OnKeyPressed '%s'", aKey);
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(service);
@ -36,17 +36,17 @@ void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
return;
}
switch (aKeyEvent) {
case MediaControlKeysEvent::eFocus:
switch (aKey) {
case MediaControlKey::Focus:
controller->Focus();
return;
case MediaControlKeysEvent::ePlay:
case MediaControlKey::Play:
controller->Play();
return;
case MediaControlKeysEvent::ePause:
case MediaControlKey::Pause:
controller->Pause();
return;
case MediaControlKeysEvent::ePlayPause: {
case MediaControlKey::Playpause: {
if (controller->IsPlaying()) {
controller->Pause();
} else {
@ -54,55 +54,52 @@ void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
}
return;
}
case MediaControlKeysEvent::ePrevTrack:
case MediaControlKey::Previoustrack:
controller->PrevTrack();
return;
case MediaControlKeysEvent::eNextTrack:
case MediaControlKey::Nexttrack:
controller->NextTrack();
return;
case MediaControlKeysEvent::eSeekBackward:
case MediaControlKey::Seekbackward:
controller->SeekBackward();
return;
case MediaControlKeysEvent::eSeekForward:
case MediaControlKey::Seekforward:
controller->SeekForward();
return;
case MediaControlKeysEvent::eStop:
case MediaControlKey::Stop:
controller->Stop();
return;
default:
MOZ_ASSERT_UNREACHABLE("Error : undefined event!");
MOZ_ASSERT_UNREACHABLE("Error : undefined media key!");
return;
}
}
MediaControlKeysEventSource::MediaControlKeysEventSource()
MediaControlKeySource::MediaControlKeySource()
: mPlaybackState(MediaSessionPlaybackState::None) {}
void MediaControlKeysEventSource::AddListener(
MediaControlKeysEventListener* aListener) {
void MediaControlKeySource::AddListener(MediaControlKeyListener* aListener) {
MOZ_ASSERT(aListener);
LOG_SOURCE("Add listener %p", aListener);
mListeners.AppendElement(aListener);
}
void MediaControlKeysEventSource::RemoveListener(
MediaControlKeysEventListener* aListener) {
void MediaControlKeySource::RemoveListener(MediaControlKeyListener* aListener) {
MOZ_ASSERT(aListener);
LOG_SOURCE("Remove listener %p", aListener);
mListeners.RemoveElement(aListener);
}
size_t MediaControlKeysEventSource::GetListenersNum() const {
size_t MediaControlKeySource::GetListenersNum() const {
return mListeners.Length();
}
void MediaControlKeysEventSource::Close() {
void MediaControlKeySource::Close() {
LOG_SOURCE("Close source");
mListeners.Clear();
}
void MediaControlKeysEventSource::SetPlaybackState(
MediaSessionPlaybackState aState) {
void MediaControlKeySource::SetPlaybackState(MediaSessionPlaybackState aState) {
if (mPlaybackState == aState) {
return;
}
@ -110,8 +107,7 @@ void MediaControlKeysEventSource::SetPlaybackState(
mPlaybackState = aState;
}
MediaSessionPlaybackState MediaControlKeysEventSource::GetPlaybackState()
const {
MediaSessionPlaybackState MediaControlKeySource::GetPlaybackState() const {
return mPlaybackState;
}

Просмотреть файл

@ -0,0 +1,88 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSOURCE_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSOURCE_H_
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/dom/MediaMetadata.h"
#include "mozilla/dom/MediaSessionBinding.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
/**
* MediaControlKeyListener is a pure interface, which is used to monitor
* MediaControlKey, we can add it onto the MediaControlKeySource,
* and then everytime when the media key events occur, `OnKeyPressed` will be
* called so that we can do related handling.
*/
class MediaControlKeyListener {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
MediaControlKeyListener() = default;
virtual void OnKeyPressed(MediaControlKey aKey) = 0;
protected:
virtual ~MediaControlKeyListener() = default;
};
/**
* MediaControlKeyHandler is used to operate media controller by corresponding
* received media control key events.
*/
class MediaControlKeyHandler final : public MediaControlKeyListener {
public:
NS_INLINE_DECL_REFCOUNTING(MediaControlKeyHandler, override)
void OnKeyPressed(MediaControlKey aKey) override;
private:
virtual ~MediaControlKeyHandler() = default;
};
/**
* MediaControlKeySource is an abstract class which is used to implement
* transporting media control keys event to all its listeners when media keys
* event happens.
*/
class MediaControlKeySource {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
MediaControlKeySource();
using MediaKeysArray = nsTArray<MediaControlKey>;
virtual void AddListener(MediaControlKeyListener* aListener);
virtual void RemoveListener(MediaControlKeyListener* aListener);
size_t GetListenersNum() const;
// Return true if the initialization of the source succeeds, and inherited
// sources should implement this method to handle the initialization fails.
virtual bool Open() = 0;
virtual void Close();
virtual bool IsOpened() const = 0;
virtual void SetPlaybackState(MediaSessionPlaybackState aState);
virtual MediaSessionPlaybackState GetPlaybackState() const;
// Override this method if the event source needs to handle the metadata.
virtual void SetMediaMetadata(const MediaMetadataBase& aMetadata) {}
// Set the supported media keys which the event source can use to determine
// what kinds of buttons should be shown on the UI.
virtual void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) = 0;
protected:
virtual ~MediaControlKeySource() = default;
nsTArray<RefPtr<MediaControlKeyListener>> mListeners;
MediaSessionPlaybackState mPlaybackState;
};
} // namespace dom
} // namespace mozilla
#endif

Просмотреть файл

@ -1,107 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSEVENT_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSEVENT_H_
#include "mozilla/dom/MediaMetadata.h"
#include "mozilla/dom/MediaSessionBinding.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
/**
* MediaControlKeysEvent represents all possible control buttons in controller
* interface, no matter it's physical one, such as keyboard, headset, or a
* virtual one, such as the interface provided by Android MediaController.
* Note. keep this sync with `MediaControlKeysTestEvent` in ChromeUtils.webidl.
*/
enum class MediaControlKeysEvent : uint32_t {
eFocus,
ePlay,
ePause,
ePlayPause,
ePrevTrack,
eNextTrack,
eSeekBackward,
eSeekForward,
// Keep this the last element, or you have to modify the serialized structure
// in `MediaControlIPC.h` when you use other element as the last one.
eStop,
};
/**
* 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_PURE_VIRTUAL_REFCOUNTING
MediaControlKeysEventListener() = default;
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:
NS_INLINE_DECL_REFCOUNTING(MediaControlKeysHandler, override)
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override;
private:
virtual ~MediaControlKeysHandler() = default;
};
/**
* MediaControlKeysEventSource is an abstract class which is used to implement
* transporting media control keys event to all its listeners when media keys
* event happens.
*/
class MediaControlKeysEventSource {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
MediaControlKeysEventSource();
using MediaKeysArray = nsTArray<MediaControlKeysEvent>;
virtual void AddListener(MediaControlKeysEventListener* aListener);
virtual void RemoveListener(MediaControlKeysEventListener* aListener);
size_t GetListenersNum() const;
// Return true if the initialization of the source succeeds, and inherited
// sources should implement this method to handle the initialization fails.
virtual bool Open() = 0;
virtual void Close();
virtual bool IsOpened() const = 0;
virtual void SetPlaybackState(MediaSessionPlaybackState aState);
virtual MediaSessionPlaybackState GetPlaybackState() const;
// Override this method if the event source needs to handle the metadata.
virtual void SetMediaMetadata(const MediaMetadataBase& aMetadata) {}
// Set the supported media keys which the event source can use to determine
// what kinds of buttons should be shown on the UI.
virtual void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) = 0;
protected:
virtual ~MediaControlKeysEventSource() = default;
nsTArray<RefPtr<MediaControlKeysEventListener>> mListeners;
MediaSessionPlaybackState mPlaybackState;
};
} // namespace dom
} // namespace mozilla
#endif

Просмотреть файл

@ -65,11 +65,11 @@ MediaControlService::MediaControlService() {
}
void MediaControlService::Init() {
mMediaKeysHandler = new MediaControlKeysHandler();
mMediaControlKeysManager = new MediaControlKeysManager();
mMediaControlKeysManager->Open();
MOZ_ASSERT(mMediaControlKeysManager->IsOpened());
mMediaControlKeysManager->AddListener(mMediaKeysHandler.get());
mMediaKeysHandler = new MediaControlKeyHandler();
mMediaControlKeyManager = new MediaControlKeyManager();
mMediaControlKeyManager->Open();
MOZ_ASSERT(mMediaControlKeyManager->IsOpened());
mMediaControlKeyManager->AddListener(mMediaKeysHandler.get());
mControllerManager = MakeUnique<ControllerManager>(this);
}
@ -97,7 +97,7 @@ MediaControlService::Observe(nsISupports* aSubject, const char* aTopic,
void MediaControlService::Shutdown() {
mControllerManager->Shutdown();
mMediaControlKeysManager->RemoveListener(mMediaKeysHandler.get());
mMediaControlKeyManager->RemoveListener(mMediaKeysHandler.get());
}
bool MediaControlService::RegisterActiveMediaController(
@ -191,12 +191,11 @@ MediaController* MediaControlService::GetMainController() const {
return mControllerManager->GetMainController();
}
void MediaControlService::GenerateMediaControlKeysTestEvent(
MediaControlKeysEvent aEvent) {
void MediaControlService::GenerateTestMediaControlKey(MediaControlKey aKey) {
if (!StaticPrefs::media_mediacontrol_testingevents_enabled()) {
return;
}
mMediaKeysHandler->OnKeyPressed(aEvent);
mMediaKeysHandler->OnKeyPressed(aKey);
}
MediaMetadataBase MediaControlService::GetMainControllerMediaMetadata() const {
@ -220,7 +219,7 @@ MediaSessionPlaybackState MediaControlService::GetMainControllerPlaybackState()
// Following functions belong to ControllerManager
MediaControlService::ControllerManager::ControllerManager(
MediaControlService* aService)
: mSource(aService->GetMediaControlKeysEventSource()) {
: mSource(aService->GetMediaControlKeySource()) {
MOZ_ASSERT(mSource);
}

Просмотреть файл

@ -9,8 +9,8 @@
#include "AudioFocusManager.h"
#include "MediaController.h"
#include "MediaControlKeysManager.h"
#include "MediaEventSource.h"
#include "MediaControlKeyManager.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "nsDataHashtable.h"
#include "nsIObserver.h"
#include "nsTArray.h"
@ -37,8 +37,8 @@ class MediaControlService final : public nsIObserver {
static RefPtr<MediaControlService> GetService();
AudioFocusManager& GetAudioFocusManager() { return mAudioFocusManager; }
MediaControlKeysEventSource* GetMediaControlKeysEventSource() {
return mMediaControlKeysManager;
MediaControlKeySource* GetMediaControlKeySource() {
return mMediaControlKeyManager;
}
// Use these functions to register/unresgister controller to/from the active
@ -71,7 +71,7 @@ class MediaControlService final : public nsIObserver {
* generate fake media control key events, get the media metadata and playback
* state from the main controller.
*/
void GenerateMediaControlKeysTestEvent(MediaControlKeysEvent aEvent);
void GenerateTestMediaControlKey(MediaControlKey aKey);
MediaMetadataBase GetMainControllerMediaMetadata() const;
MediaSessionPlaybackState GetMainControllerPlaybackState() const;
@ -100,7 +100,7 @@ class MediaControlService final : public nsIObserver {
explicit ControllerManager(MediaControlService* aService);
~ControllerManager() = default;
using MediaKeysArray = nsTArray<MediaControlKeysEvent>;
using MediaKeysArray = nsTArray<MediaControlKey>;
using LinkedListControllerPtr = LinkedListElement<RefPtr<MediaController>>*;
using ConstLinkedListControllerPtr =
const LinkedListElement<RefPtr<MediaController>>*;
@ -142,7 +142,7 @@ class MediaControlService final : public nsIObserver {
// These member are use to listen main controller's play state changes and
// update the playback state to the event source.
RefPtr<MediaControlKeysEventSource> mSource;
RefPtr<MediaControlKeySource> mSource;
MediaEventListener mMetadataChangedListener;
MediaEventListener mSupportedKeysChangedListener;
};
@ -151,8 +151,8 @@ class MediaControlService final : public nsIObserver {
void Shutdown();
AudioFocusManager mAudioFocusManager;
RefPtr<MediaControlKeysManager> mMediaControlKeysManager;
RefPtr<MediaControlKeysEventListener> mMediaKeysHandler;
RefPtr<MediaControlKeyManager> mMediaControlKeyManager;
RefPtr<MediaControlKeyListener> mMediaKeysHandler;
MediaEventProducer<uint64_t> mMediaControllerAmountChangedEvent;
UniquePtr<ControllerManager> mControllerManager;
};

Просмотреть файл

@ -8,7 +8,6 @@
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLUTILS_H_
#include "MediaController.h"
#include "MediaControlKeysEvent.h"
#include "mozilla/dom/ChromeUtilsBinding.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/Logging.h"
@ -18,25 +17,25 @@ extern mozilla::LazyLogModule gMediaControlLog;
namespace mozilla {
namespace dom {
inline const char* ToMediaControlKeysEventStr(MediaControlKeysEvent aKeyEvent) {
switch (aKeyEvent) {
case MediaControlKeysEvent::eFocus:
inline const char* ToMediaControlKeyStr(MediaControlKey aKey) {
switch (aKey) {
case MediaControlKey::Focus:
return "Focus";
case MediaControlKeysEvent::ePause:
case MediaControlKey::Pause:
return "Pause";
case MediaControlKeysEvent::ePlay:
case MediaControlKey::Play:
return "Play";
case MediaControlKeysEvent::ePlayPause:
case MediaControlKey::Playpause:
return "Play & pause";
case MediaControlKeysEvent::ePrevTrack:
case MediaControlKey::Previoustrack:
return "Previous track";
case MediaControlKeysEvent::eNextTrack:
case MediaControlKey::Nexttrack:
return "Next track";
case MediaControlKeysEvent::eSeekBackward:
case MediaControlKey::Seekbackward:
return "Seek backward";
case MediaControlKeysEvent::eSeekForward:
case MediaControlKey::Seekforward:
return "Seek forward";
case MediaControlKeysEvent::eStop:
case MediaControlKey::Stop:
return "Stop";
default:
MOZ_ASSERT_UNREACHABLE("Invalid action.");
@ -44,32 +43,6 @@ inline const char* ToMediaControlKeysEventStr(MediaControlKeysEvent aKeyEvent) {
}
}
inline MediaControlKeysEvent
ConvertMediaControlKeysTestEventToMediaControlKeysEvent(
MediaControlKeysTestEvent aEvent) {
switch (aEvent) {
case MediaControlKeysTestEvent::Play:
return MediaControlKeysEvent::ePlay;
case MediaControlKeysTestEvent::Pause:
return MediaControlKeysEvent::ePause;
case MediaControlKeysTestEvent::PlayPause:
return MediaControlKeysEvent::ePlayPause;
case MediaControlKeysTestEvent::Previoustrack:
return MediaControlKeysEvent::ePrevTrack;
case MediaControlKeysTestEvent::Nexttrack:
return MediaControlKeysEvent::eNextTrack;
case MediaControlKeysTestEvent::Seekbackward:
return MediaControlKeysEvent::eSeekBackward;
case MediaControlKeysTestEvent::Seekforward:
return MediaControlKeysEvent::eSeekForward;
case MediaControlKeysTestEvent::Focus:
return MediaControlKeysEvent::eFocus;
default:
MOZ_ASSERT(aEvent == MediaControlKeysTestEvent::Stop);
return MediaControlKeysEvent::eStop;
}
}
inline const char* ToMediaSessionActionStr(MediaSessionAction aAction) {
switch (aAction) {
case MediaSessionAction::Play:
@ -90,24 +63,24 @@ inline const char* ToMediaSessionActionStr(MediaSessionAction aAction) {
}
}
inline MediaControlKeysEvent ConvertMediaSessionActionToControlKey(
inline MediaControlKey ConvertMediaSessionActionToControlKey(
MediaSessionAction aAction) {
switch (aAction) {
case MediaSessionAction::Play:
return MediaControlKeysEvent::ePlay;
return MediaControlKey::Play;
case MediaSessionAction::Pause:
return MediaControlKeysEvent::ePause;
return MediaControlKey::Pause;
case MediaSessionAction::Seekbackward:
return MediaControlKeysEvent::eSeekBackward;
return MediaControlKey::Seekbackward;
case MediaSessionAction::Seekforward:
return MediaControlKeysEvent::eSeekForward;
return MediaControlKey::Seekforward;
case MediaSessionAction::Previoustrack:
return MediaControlKeysEvent::ePrevTrack;
return MediaControlKey::Previoustrack;
case MediaSessionAction::Nexttrack:
return MediaControlKeysEvent::eNextTrack;
return MediaControlKey::Nexttrack;
default:
MOZ_ASSERT(aAction == MediaSessionAction::Stop);
return MediaControlKeysEvent::eStop;
return MediaControlKey::Stop;
}
}
@ -129,32 +102,6 @@ inline MediaSessionAction ConvertToMediaSessionAction(uint8_t aActionValue) {
return static_cast<MediaSessionAction>(aActionValue);
}
// TODO : merge `MediaControlKeysEvent` and `MediaControlKey`
inline MediaControlKey ConvertToMediaControlKey(
MediaControlKeysEvent aKeyEvent) {
switch (aKeyEvent) {
case MediaControlKeysEvent::eFocus:
return MediaControlKey::Focus;
case MediaControlKeysEvent::ePause:
return MediaControlKey::Pause;
case MediaControlKeysEvent::ePlay:
return MediaControlKey::Play;
case MediaControlKeysEvent::ePlayPause:
return MediaControlKey::Playpause;
case MediaControlKeysEvent::ePrevTrack:
return MediaControlKey::Previoustrack;
case MediaControlKeysEvent::eNextTrack:
return MediaControlKey::Nexttrack;
case MediaControlKeysEvent::eSeekBackward:
return MediaControlKey::Seekbackward;
case MediaControlKeysEvent::eSeekForward:
return MediaControlKey::Seekforward;
default:
MOZ_ASSERT(aKeyEvent == MediaControlKeysEvent::eStop);
return MediaControlKey::Stop;
}
}
inline const char* ToMediaPlaybackStateStr(MediaPlaybackState aState) {
switch (aState) {
case MediaPlaybackState::eStarted:

Просмотреть файл

@ -43,18 +43,16 @@ void MediaController::GetSupportedKeys(
nsTArray<MediaControlKey>& aRetVal) const {
aRetVal.Clear();
for (const auto& key : mSupportedKeys) {
// TODO : merge `MediaControlKey` and `MediaControlKeysEvent`.
aRetVal.AppendElement(ConvertToMediaControlKey(key));
aRetVal.AppendElement(key);
}
}
static const MediaControlKeysEvent sDefaultSupportedKeys[] = {
MediaControlKeysEvent::eFocus, MediaControlKeysEvent::ePlay,
MediaControlKeysEvent::ePause, MediaControlKeysEvent::ePlayPause,
MediaControlKeysEvent::eStop,
static const MediaControlKey sDefaultSupportedKeys[] = {
MediaControlKey::Focus, MediaControlKey::Play, MediaControlKey::Pause,
MediaControlKey::Playpause, MediaControlKey::Stop,
};
static void GetDefaultSupportedKeys(nsTArray<MediaControlKeysEvent>& aKeys) {
static void GetDefaultSupportedKeys(nsTArray<MediaControlKey>& aKeys) {
for (const auto& key : sDefaultSupportedKeys) {
aKeys.AppendElement(key);
}
@ -80,50 +78,42 @@ MediaController::~MediaController() {
void MediaController::Focus() {
LOG("Focus");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::eFocus);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Focus);
}
void MediaController::Play() {
LOG("Play");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::ePlay);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Play);
}
void MediaController::Pause() {
LOG("Pause");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::ePause);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Pause);
}
void MediaController::PrevTrack() {
LOG("Prev Track");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::ePrevTrack);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Previoustrack);
}
void MediaController::NextTrack() {
LOG("Next Track");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::eNextTrack);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Nexttrack);
}
void MediaController::SeekBackward() {
LOG("Seek Backward");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::eSeekBackward);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Seekbackward);
}
void MediaController::SeekForward() {
LOG("Seek Forward");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::eSeekForward);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Seekforward);
}
void MediaController::Stop() {
LOG("Stop");
UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent::eStop);
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Stop);
}
uint64_t MediaController::Id() const { return mTopLevelBrowsingContextId; }
@ -132,8 +122,8 @@ bool MediaController::IsAudible() const { return IsMediaAudible(); }
bool MediaController::IsPlaying() const { return IsMediaPlaying(); }
void MediaController::UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent aEvent) {
void MediaController::UpdateMediaControlKeyToContentMediaIfNeeded(
MediaControlKey aKey) {
// There is no controlled media existing or controller has been shutdown, we
// have no need to update media action to the content process.
if (!IsAnyMediaBeingControlled() || mShutdown) {
@ -148,7 +138,7 @@ void MediaController::UpdateMediaControlKeysEventToContentMediaIfNeeded(
? BrowsingContext::Get(*mActiveMediaSessionContextId)
: BrowsingContext::Get(Id());
if (context && !context->IsDiscarded()) {
context->Canonical()->UpdateMediaControlKeysEvent(aEvent);
context->Canonical()->UpdateMediaControlKey(aKey);
}
}
@ -271,10 +261,10 @@ void MediaController::HandleSupportedMediaSessionActionsChanged(
const nsTArray<MediaSessionAction>& aSupportedAction) {
// Convert actions to keys, some of them have been included in the supported
// keys, such as "play", "pause" and "stop".
nsTArray<MediaControlKeysEvent> newSupportedKeys;
nsTArray<MediaControlKey> newSupportedKeys;
GetDefaultSupportedKeys(newSupportedKeys);
for (const auto& action : aSupportedAction) {
MediaControlKeysEvent key = ConvertMediaSessionActionToControlKey(action);
MediaControlKey key = ConvertMediaSessionActionToControlKey(action);
if (!newSupportedKeys.Contains(key)) {
newSupportedKeys.AppendElement(key);
}
@ -293,8 +283,7 @@ void MediaController::HandleSupportedMediaSessionActionsChanged(
MediaController_Binding::ClearCachedSupportedKeysValue(this);
}
CopyableTArray<MediaControlKeysEvent> MediaController::GetSupportedMediaKeys()
const {
CopyableTArray<MediaControlKey> MediaController::GetSupportedMediaKeys() const {
return mSupportedKeys;
}

Просмотреть файл

@ -20,7 +20,6 @@ namespace mozilla {
namespace dom {
class BrowsingContext;
enum class MediaControlKeysEvent : uint32_t;
/**
* IMediaController is an interface which includes control related methods and
@ -116,18 +115,16 @@ class MediaController final : public DOMEventTargetHelper,
// This event would be notified media controller's supported media keys
// change.
MediaEventSource<nsTArray<MediaControlKeysEvent>>&
SupportedKeysChangedEvent() {
MediaEventSource<nsTArray<MediaControlKey>>& SupportedKeysChangedEvent() {
return mSupportedKeysChangedEvent;
}
CopyableTArray<MediaControlKeysEvent> GetSupportedMediaKeys() const;
CopyableTArray<MediaControlKey> GetSupportedMediaKeys() const;
private:
~MediaController();
void HandleActualPlaybackStateChanged() override;
void UpdateMediaControlKeysEventToContentMediaIfNeeded(
MediaControlKeysEvent aEvent);
void UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey aKey);
void HandleSupportedMediaSessionActionsChanged(
const nsTArray<MediaSessionAction>& aSupportedAction);
@ -149,11 +146,10 @@ class MediaController final : public DOMEventTargetHelper,
// We would monitor the change of media session actions and convert them to
// the media keys, then determine the supported media keys.
MediaEventListener mSupportedActionsChangedListener;
MediaEventProducer<nsTArray<MediaControlKeysEvent>>
mSupportedKeysChangedEvent;
MediaEventProducer<nsTArray<MediaControlKey>> mSupportedKeysChangedEvent;
// Use copyable array so that we can use the result as a parameter for the
// media event.
CopyableTArray<MediaControlKeysEvent> mSupportedKeys;
CopyableTArray<MediaControlKey> mSupportedKeys;
};
} // namespace dom

Просмотреть файл

@ -5,7 +5,7 @@
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIASTATUSMANAGER_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIASTATUSMANAGER_H_
#include "MediaControlKeysEvent.h"
#include "MediaControlKeySource.h"
#include "MediaEventSource.h"
#include "MediaPlaybackStatus.h"
#include "mozilla/dom/MediaMetadata.h"

Просмотреть файл

@ -8,8 +8,8 @@ EXPORTS.mozilla.dom += [
'ContentMediaController.h',
'ContentPlaybackController.h',
'FetchImageHelper.h',
'MediaControlKeysEvent.h',
'MediaControlKeysManager.h',
'MediaControlKeyManager.h',
'MediaControlKeySource.h',
'MediaController.h',
'MediaControlService.h',
'MediaControlUtils.h',
@ -26,8 +26,8 @@ UNIFIED_SOURCES += [
'ContentMediaController.cpp',
'ContentPlaybackController.cpp',
'FetchImageHelper.cpp',
'MediaControlKeysEvent.cpp',
'MediaControlKeysManager.cpp',
'MediaControlKeyManager.cpp',
'MediaControlKeySource.cpp',
'MediaController.cpp',
'MediaControlService.cpp',
'MediaControlUtils.cpp',

Просмотреть файл

@ -20,15 +20,15 @@ add_task(async function testPlayPauseAndStop() {
await playMedia(tab, testVideoId);
info(`pressing 'pause' key`);
await generateMediaControlKeyEvent("pause");
await generateMediaControlKey("pause");
await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
info(`pressing 'play' key`);
await generateMediaControlKeyEvent("play");
await generateMediaControlKey("play");
await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
info(`pressing 'stop' key`);
await generateMediaControlKeyEvent("stop");
await generateMediaControlKey("stop");
await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
info(`remove tab`);
@ -41,11 +41,11 @@ add_task(async function testPlayPause() {
await playMedia(tab, testVideoId);
info(`pressing 'playPause' key, media should stop`);
await generateMediaControlKeyEvent("playPause");
await generateMediaControlKey("playpause");
await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
info(`pressing 'playPause' key, media should start`);
await generateMediaControlKeyEvent("playPause");
await generateMediaControlKey("playpause");
await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
info(`remove tab`);
@ -55,8 +55,8 @@ add_task(async function testPlayPause() {
/**
* The following are helper functions.
*/
function generateMediaControlKeyEvent(event) {
function generateMediaControlKey(event) {
const playbackStateChanged = waitUntilDisplayedPlaybackChanged();
ChromeUtils.generateMediaControlKeysTestEvent(event);
ChromeUtils.generateMediaControlKey(event);
return playbackStateChanged;
}

Просмотреть файл

@ -38,7 +38,7 @@ add_task(async function testPlayPauseAndStop() {
await checkIfMediaIsStillPlaying(tab, elementId);
info(`- simulate pressing 'pause' media control key -`);
ChromeUtils.generateMediaControlKeysTestEvent("pause");
ChromeUtils.generateMediaControlKey("pause");
info(`- non eligible media won't be controlled by media control -`);
await checkIfMediaIsStillPlaying(tab, elementId);
@ -48,7 +48,7 @@ add_task(async function testPlayPauseAndStop() {
await makeElementEligible(tab, elementId);
info(`- simulate pressing 'pause' media control key -`);
ChromeUtils.generateMediaControlKeysTestEvent("pause");
ChromeUtils.generateMediaControlKey("pause");
info(`- audible media should be controlled by media control -`);
await waitUntilMediaPaused(tab, elementId);

Просмотреть файл

@ -1,40 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIAHARDWAREKEYSEVENTLISTENERTEST_H_
#define DOM_MEDIA_MEDIAHARDWAREKEYSEVENTLISTENERTEST_H_
#include "MediaControlKeysEvent.h"
#include "mozilla/Maybe.h"
namespace mozilla {
namespace dom {
class MediaHardwareKeysEventListenerTest
: public MediaControlKeysEventListener {
public:
NS_INLINE_DECL_REFCOUNTING(MediaHardwareKeysEventListenerTest, override)
void Clear() { mReceivedEvent = mozilla::Nothing(); }
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override {
mReceivedEvent = mozilla::Some(aKeyEvent);
}
bool IsResultEqualTo(MediaControlKeysEvent aResult) const {
if (mReceivedEvent) {
return *mReceivedEvent == aResult;
}
return false;
}
bool IsReceivedResult() const { return mReceivedEvent.isSome(); }
private:
~MediaHardwareKeysEventListenerTest() = default;
mozilla::Maybe<MediaControlKeysEvent> mReceivedEvent;
};
} // namespace dom
} // namespace mozilla
#endif // DOM_MEDIA_MEDIAHARDWAREKEYSEVENTLISTENERTEST_H_

Просмотреть файл

@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIAKEYLISTENERTEST_H_
#define DOM_MEDIA_MEDIAKEYLISTENERTEST_H_
#include "MediaControlKeySource.h"
#include "mozilla/Maybe.h"
namespace mozilla {
namespace dom {
class MediaKeyListenerTest : public MediaControlKeyListener {
public:
NS_INLINE_DECL_REFCOUNTING(MediaKeyListenerTest, override)
void Clear() { mReceivedKey = mozilla::Nothing(); }
void OnKeyPressed(MediaControlKey aKey) override {
mReceivedKey = mozilla::Some(aKey);
}
bool IsResultEqualTo(MediaControlKey aResult) const {
if (mReceivedKey) {
return *mReceivedKey == aResult;
}
return false;
}
bool IsReceivedResult() const { return mReceivedKey.isSome(); }
private:
~MediaKeyListenerTest() = default;
mozilla::Maybe<MediaControlKey> mReceivedKey;
};
} // namespace dom
} // namespace mozilla
#endif // DOM_MEDIA_MEDIAKEYLISTENERTEST_H_

Просмотреть файл

@ -4,29 +4,27 @@
#include "gtest/gtest.h"
#include "MediaController.h"
#include "MediaControlKeysEvent.h"
#include "MediaControlKeySource.h"
using namespace mozilla::dom;
class MediaControlKeysEventSourceTestImpl : public MediaControlKeysEventSource {
class MediaControlKeySourceTestImpl : public MediaControlKeySource {
public:
NS_INLINE_DECL_REFCOUNTING(MediaControlKeysEventSourceTestImpl, override)
NS_INLINE_DECL_REFCOUNTING(MediaControlKeySourceTestImpl, override)
bool Open() override { return true; }
bool IsOpened() const override { return true; }
void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override {}
private:
~MediaControlKeysEventSourceTestImpl() = default;
~MediaControlKeySourceTestImpl() = default;
};
TEST(MediaControlKeysEvent, TestAddOrRemoveListener)
TEST(MediaControlKey, TestAddOrRemoveListener)
{
RefPtr<MediaControlKeysEventSource> source =
new MediaControlKeysEventSourceTestImpl();
RefPtr<MediaControlKeySource> source = new MediaControlKeySourceTestImpl();
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaControlKeysEventListener> listener =
new MediaControlKeysHandler();
RefPtr<MediaControlKeyListener> listener = new MediaControlKeyHandler();
source->AddListener(listener);
ASSERT_TRUE(source->GetListenersNum() == 1);
@ -35,10 +33,9 @@ TEST(MediaControlKeysEvent, TestAddOrRemoveListener)
ASSERT_TRUE(source->GetListenersNum() == 0);
}
TEST(MediaControlKeysEvent, SetSourcePlaybackState)
TEST(MediaControlKey, SetSourcePlaybackState)
{
RefPtr<MediaControlKeysEventSource> source =
new MediaControlKeysEventSourceTestImpl();
RefPtr<MediaControlKeySource> source = new MediaControlKeySourceTestImpl();
ASSERT_TRUE(source->GetPlaybackState() == MediaSessionPlaybackState::None);
source->SetPlaybackState(MediaSessionPlaybackState::Playing);

Просмотреть файл

@ -10,7 +10,7 @@
#include "gtest/gtest.h"
#include "MediaHardwareKeysEventSourceMac.h"
#include "MediaHardwareKeysEventListenerTest.h"
#include "MediaKeyListenerTest.h"
#include "mozilla/Maybe.h"
using namespace mozilla::dom;
@ -31,42 +31,42 @@ static void SendFakeEvent(RefPtr<MediaHardwareKeysEventSourceMac>& aSource, int
aSource->EventTapCallback(nullptr, static_cast<CGEventType>(0), [event CGEvent], aSource.get());
}
static void NotifyFakeNonMediaKeysEvent(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
bool aIsKeyPressed) {
static void NotifyFakeNonMediaKey(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
bool aIsKeyPressed) {
int keyData = 0 | ((aIsKeyPressed ? 0xA : 0xB) << 8);
SendFakeEvent(aSource, keyData);
}
static void NotifyFakeMediaKeysEvent(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
MediaControlKeysEvent aEvent, bool aIsKeyPressed) {
static void NotifyFakeMediaControlKey(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
MediaControlKey aEvent, bool aIsKeyPressed) {
int keyData = 0;
if (aEvent == MediaControlKeysEvent::ePlayPause) {
if (aEvent == MediaControlKey::Playpause) {
keyData = NX_KEYTYPE_PLAY << 16;
} else if (aEvent == MediaControlKeysEvent::eNextTrack) {
} else if (aEvent == MediaControlKey::Nexttrack) {
keyData = NX_KEYTYPE_NEXT << 16;
} else if (aEvent == MediaControlKeysEvent::ePrevTrack) {
} else if (aEvent == MediaControlKey::Previoustrack) {
keyData = NX_KEYTYPE_PREVIOUS << 16;
}
keyData |= ((aIsKeyPressed ? 0xA : 0xB) << 8);
SendFakeEvent(aSource, keyData);
}
static void NotifyKeyPressedMediaKeysEvent(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
MediaControlKeysEvent aEvent) {
NotifyFakeMediaKeysEvent(aSource, aEvent, true /* key pressed */);
static void NotifyKeyPressedMediaKey(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
MediaControlKey aEvent) {
NotifyFakeMediaControlKey(aSource, aEvent, true /* key pressed */);
}
static void NotifyKeyReleasedMediaKeysEvent(RefPtr<MediaHardwareKeysEventSourceMac>& aSource,
MediaControlKeysEvent aEvent) {
NotifyFakeMediaKeysEvent(aSource, aEvent, false /* key released */);
MediaControlKey aEvent) {
NotifyFakeMediaControlKey(aSource, aEvent, false /* key released */);
}
static void NotifyKeyPressedNonMediaKeysEvents(RefPtr<MediaHardwareKeysEventSourceMac>& aSource) {
NotifyFakeNonMediaKeysEvent(aSource, true /* key pressed */);
NotifyFakeNonMediaKey(aSource, true /* key pressed */);
}
static void NotifyKeyReleasedNonMediaKeysEvents(RefPtr<MediaHardwareKeysEventSourceMac>& aSource) {
NotifyFakeNonMediaKeysEvent(aSource, false /* key released */);
NotifyFakeNonMediaKey(aSource, false /* key released */);
}
TEST(MediaHardwareKeysEventSourceMac, TestKeyPressedMediaKeysEvent)
@ -74,19 +74,19 @@ TEST(MediaHardwareKeysEventSourceMac, TestKeyPressedMediaKeysEvent)
RefPtr<MediaHardwareKeysEventSourceMac> source = new MediaHardwareKeysEventSourceMac();
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
source->AddListener(listener.get());
ASSERT_TRUE(source->GetListenersNum() == 1);
ASSERT_TRUE(!listener->IsReceivedResult());
NotifyKeyPressedMediaKeysEvent(source, MediaControlKeysEvent::ePlayPause);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePlayPause));
NotifyKeyPressedMediaKey(source, MediaControlKey::Playpause);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Playpause));
NotifyKeyPressedMediaKeysEvent(source, MediaControlKeysEvent::eNextTrack);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::eNextTrack));
NotifyKeyPressedMediaKey(source, MediaControlKey::Nexttrack);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Nexttrack));
NotifyKeyPressedMediaKeysEvent(source, MediaControlKeysEvent::ePrevTrack);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePrevTrack));
NotifyKeyPressedMediaKey(source, MediaControlKey::Previoustrack);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Previoustrack));
source->RemoveListener(listener);
ASSERT_TRUE(source->GetListenersNum() == 0);
@ -97,18 +97,18 @@ TEST(MediaHardwareKeysEventSourceMac, TestKeyReleasedMediaKeysEvent)
RefPtr<MediaHardwareKeysEventSourceMac> source = new MediaHardwareKeysEventSourceMac();
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
source->AddListener(listener.get());
ASSERT_TRUE(source->GetListenersNum() == 1);
ASSERT_TRUE(!listener->IsReceivedResult());
NotifyKeyReleasedMediaKeysEvent(source, MediaControlKeysEvent::ePlayPause);
NotifyKeyReleasedMediaKeysEvent(source, MediaControlKey::Playpause);
ASSERT_TRUE(!listener->IsReceivedResult());
NotifyKeyReleasedMediaKeysEvent(source, MediaControlKeysEvent::eNextTrack);
NotifyKeyReleasedMediaKeysEvent(source, MediaControlKey::Nexttrack);
ASSERT_TRUE(!listener->IsReceivedResult());
NotifyKeyReleasedMediaKeysEvent(source, MediaControlKeysEvent::ePrevTrack);
NotifyKeyReleasedMediaKeysEvent(source, MediaControlKey::Previoustrack);
ASSERT_TRUE(!listener->IsReceivedResult());
source->RemoveListener(listener);
@ -120,7 +120,7 @@ TEST(MediaHardwareKeysEventSourceMac, TestNonMediaKeysEvent)
RefPtr<MediaHardwareKeysEventSourceMac> source = new MediaHardwareKeysEventSourceMac();
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
source->AddListener(listener.get());
ASSERT_TRUE(source->GetListenersNum() == 1);
ASSERT_TRUE(!listener->IsReceivedResult());

Просмотреть файл

@ -4,7 +4,7 @@
#import "MediaPlayerWrapper.h"
#include "MediaHardwareKeysEventSourceMacMediaCenter.h"
#include "MediaHardwareKeysEventListenerTest.h"
#include "MediaKeyListenerTest.h"
#include "nsCocoaFeatures.h"
extern _Nullable Class mpNowPlayingInfoCenterClass;
@ -26,7 +26,7 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPlayPauseEvent)
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
MPNowPlayingInfoCenter* center =
(MPNowPlayingInfoCenter*)[mpNowPlayingInfoCenterClass defaultCenter];
@ -43,14 +43,14 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPlayPauseEvent)
playPauseHandler(nil);
ASSERT_TRUE(center.playbackState == MPNowPlayingPlaybackStatePaused);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePlayPause));
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Playpause));
listener->Clear(); // Reset stored media key
playPauseHandler(nil);
ASSERT_TRUE(center.playbackState == MPNowPlayingPlaybackStatePlaying);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePlayPause));
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Playpause));
MediaPlayerWrapperClose();
}
}
@ -64,7 +64,7 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPlayEvent)
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
MPNowPlayingInfoCenter* center =
(MPNowPlayingInfoCenter*)[mpNowPlayingInfoCenterClass defaultCenter];
@ -84,7 +84,7 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPlayEvent)
playHandler(nil);
ASSERT_TRUE(center.playbackState == MPNowPlayingPlaybackStatePlaying);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePlay));
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Play));
MediaPlayerWrapperClose();
}
}
@ -98,7 +98,7 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPauseEvent)
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
MPNowPlayingInfoCenter* center =
(MPNowPlayingInfoCenter*)[mpNowPlayingInfoCenterClass defaultCenter];
@ -116,7 +116,7 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPauseEvent)
pauseHandler(nil);
ASSERT_TRUE(center.playbackState == MPNowPlayingPlaybackStatePaused);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePause));
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Pause));
MediaPlayerWrapperClose();
}
}
@ -130,7 +130,7 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPrevNextEvent)
ASSERT_TRUE(source->GetListenersNum() == 0);
RefPtr<MediaHardwareKeysEventListenerTest> listener = new MediaHardwareKeysEventListenerTest();
RefPtr<MediaKeyListenerTest> listener = new MediaKeyListenerTest();
source->AddListener(listener.get());
@ -140,13 +140,13 @@ TEST(MediaHardwareKeysEventSourceMacMediaCenter, TestMediaCenterPrevNextEvent)
nextHandler(nil);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::eNextTrack));
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Nexttrack));
MediaCenterEventHandler previousHandler = source->CreatePreviousTrackHandler();
previousHandler(nil);
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKeysEvent::ePrevTrack));
ASSERT_TRUE(listener->IsResultEqualTo(MediaControlKey::Previoustrack));
MediaPlayerWrapperClose();
}
}

Просмотреть файл

@ -31,7 +31,7 @@ async function createTabAndLoad(url, inputWindow = null) {
*/
function generateMediaControlKeyEvent(event) {
const playbackStateChanged = waitUntilDisplayedPlaybackChanged();
ChromeUtils.generateMediaControlKeysTestEvent(event);
ChromeUtils.generateMediaControlKey(event);
return playbackStateChanged;
}

Просмотреть файл

@ -27,7 +27,7 @@ add_task(async function testActiveSessionWhenClosingTab() {
await startMediaPlayback(tab1);
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab1 should become active session`);
await checkIfActionReceived(tab1, ACTION);
@ -37,7 +37,7 @@ add_task(async function testActiveSessionWhenClosingTab() {
await startMediaPlayback(tab2);
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab2 should become active session`);
await checkIfActionReceived(tab2, ACTION);
@ -49,7 +49,7 @@ add_task(async function testActiveSessionWhenClosingTab() {
await controllerChanged;
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab1 should become active session again`);
await checkIfActionReceived(tab1, ACTION);
@ -69,7 +69,7 @@ add_task(async function testActiveSessionWhenNavigatingTab() {
await startMediaPlayback(tab1);
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab1 should become active session`);
await checkIfActionReceived(tab1, ACTION);
@ -79,7 +79,7 @@ add_task(async function testActiveSessionWhenNavigatingTab() {
await startMediaPlayback(tab2);
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab2 should become active session`);
await checkIfActionReceived(tab2, ACTION);
@ -91,7 +91,7 @@ add_task(async function testActiveSessionWhenNavigatingTab() {
await controllerChanged;
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab1 should become active session`);
await checkIfActionReceived(tab1, ACTION);
@ -112,7 +112,7 @@ add_task(async function testCreatingSessionWithoutPlayingMedia() {
await startMediaPlayback(tab1);
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(`session in tab1 should become active session`);
await checkIfActionReceived(tab1, ACTION);
@ -121,7 +121,7 @@ add_task(async function testCreatingSessionWithoutPlayingMedia() {
const tab2 = await createTabAndLoad(PAGE);
info(`pressing '${ACTION}' key`);
ChromeUtils.generateMediaControlKeysTestEvent(ACTION);
ChromeUtils.generateMediaControlKey(ACTION);
info(
`session in tab1 is still an active session because there is no media playing in tab2`

Просмотреть файл

@ -1195,7 +1195,7 @@ class SpecialPowersParent extends JSWindowActorParent {
}
case "SPGenerateMediaControlKeyTestEvent": {
ChromeUtils.generateMediaControlKeysTestEvent(aMessage.data.event);
ChromeUtils.generateMediaControlKey(aMessage.data.event);
return undefined;
}

Просмотреть файл

@ -7,7 +7,7 @@
namespace mozilla {
namespace dom {
class MediaControlKeysEventSource;
class MediaControlKeySource;
} // namespace dom
} // namespace mozilla
@ -16,8 +16,7 @@ namespace widget {
// This function declaration is used to create a media keys event source on
// different platforms, each platform should have their own implementation.
extern mozilla::dom::MediaControlKeysEventSource*
CreateMediaControlKeysEventSource();
extern mozilla::dom::MediaControlKeySource* CreateMediaControlKeySource();
} // namespace widget
} // namespace mozilla

Просмотреть файл

@ -7,7 +7,7 @@
namespace mozilla {
namespace widget {
mozilla::dom::MediaControlKeysEventSource* CreateMediaControlKeysEventSource() {
mozilla::dom::MediaControlKeySource* CreateMediaControlKeySource() {
// TODO : will implement this in bug 1601510.
return nullptr;
}

Просмотреть файл

@ -8,14 +8,14 @@
#import <ApplicationServices/ApplicationServices.h>
#import <CoreFoundation/CoreFoundation.h>
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaControlKeySource.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace widget {
class MediaHardwareKeysEventSourceMac final
: public mozilla::dom::MediaControlKeysEventSource {
: public mozilla::dom::MediaControlKeySource {
public:
NS_INLINE_DECL_REFCOUNTING(MediaHardwareKeysEventSourceMac, override)
MediaHardwareKeysEventSourceMac() = default;

Просмотреть файл

@ -37,7 +37,7 @@ static const char* ToMediaControlKeyStr(int aKeyCode) {
case NX_KEYTYPE_REWIND:
return "Rewind";
default:
MOZ_ASSERT_UNREACHABLE("Invalid action.");
MOZ_ASSERT_UNREACHABLE("Invalid key code.");
return "UNKNOWN";
}
}
@ -52,18 +52,18 @@ static bool IsSupportedKeyCode(int aKeyCode) {
aKeyCode == NX_KEYTYPE_REWIND;
}
static MediaControlKeysEvent ToMediaControlKeysEvent(int aKeyCode) {
static MediaControlKey ToMediaControlKey(int aKeyCode) {
MOZ_ASSERT(IsSupportedKeyCode(aKeyCode));
switch (aKeyCode) {
case NX_KEYTYPE_NEXT:
case NX_KEYTYPE_FAST:
return MediaControlKeysEvent::eNextTrack;
return MediaControlKey::Nexttrack;
case NX_KEYTYPE_PREVIOUS:
case NX_KEYTYPE_REWIND:
return MediaControlKeysEvent::ePrevTrack;
return MediaControlKey::Previoustrack;
default:
MOZ_ASSERT(aKeyCode == NX_KEYTYPE_PLAY);
return MediaControlKeysEvent::ePlayPause;
return MediaControlKey::Playpause;
}
}
@ -80,7 +80,7 @@ bool MediaHardwareKeysEventSourceMac::Open() {
void MediaHardwareKeysEventSourceMac::Close() {
LOG("Close MediaHardwareKeysEventSourceMac");
StopEventTap();
MediaControlKeysEventSource::Close();
MediaControlKeySource::Close();
}
bool MediaHardwareKeysEventSourceMac::StartEventTap() {
@ -174,7 +174,7 @@ CGEventRef MediaHardwareKeysEventSourceMac::EventTapCallback(CGEventTapProxy pro
LOG2("Get media key %s", source, ToMediaControlKeyStr(keyCode));
for (auto iter = source->mListeners.begin(); iter != source->mListeners.end(); ++iter) {
(*iter)->OnKeyPressed(ToMediaControlKeysEvent(keyCode));
(*iter)->OnKeyPressed(ToMediaControlKey(keyCode));
}
return event;
}

Просмотреть файл

@ -5,7 +5,7 @@
#ifndef WIDGET_COCOA_MEDIAHARDWAREKEYSEVENTSOURCEMACMEDIACENTER_H_
#define WIDGET_COCOA_MEDIAHARDWAREKEYSEVENTSOURCEMACMEDIACENTER_H_
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaControlKeySource.h"
#ifdef __OBJC__
@class MPRemoteCommandEvent;
@ -20,7 +20,7 @@ namespace widget {
typedef MPRemoteCommandHandlerStatus (^MediaCenterEventHandler)(MPRemoteCommandEvent* event);
class MediaHardwareKeysEventSourceMacMediaCenter final
: public mozilla::dom::MediaControlKeysEventSource {
: public mozilla::dom::MediaControlKeySource {
public:
NS_INLINE_DECL_REFCOUNTING(MediaHardwareKeysEventSourceMacMediaCenter, override)
MediaHardwareKeysEventSourceMacMediaCenter();
@ -42,7 +42,7 @@ class MediaHardwareKeysEventSourceMacMediaCenter final
~MediaHardwareKeysEventSourceMacMediaCenter();
void BeginListeningForEvents();
void EndListeningForEvents();
void HandleEvent(dom::MediaControlKeysEvent aEvent);
void HandleEvent(dom::MediaControlKey aKey);
bool mOpened = false;

Просмотреть файл

@ -31,21 +31,21 @@ MediaCenterEventHandler MediaHardwareKeysEventSourceMacMediaCenter::CreatePlayPa
center.playbackState = center.playbackState == MPNowPlayingPlaybackStatePlaying
? MPNowPlayingPlaybackStatePaused
: MPNowPlayingPlaybackStatePlaying;
HandleEvent(MediaControlKeysEvent::ePlayPause);
HandleEvent(MediaControlKey::Playpause);
return MPRemoteCommandHandlerStatusSuccess;
});
}
MediaCenterEventHandler MediaHardwareKeysEventSourceMacMediaCenter::CreateNextTrackHandler() {
return Block_copy(^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent* event) {
HandleEvent(MediaControlKeysEvent::eNextTrack);
HandleEvent(MediaControlKey::Nexttrack);
return MPRemoteCommandHandlerStatusSuccess;
});
}
MediaCenterEventHandler MediaHardwareKeysEventSourceMacMediaCenter::CreatePreviousTrackHandler() {
return Block_copy(^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent* event) {
HandleEvent(MediaControlKeysEvent::ePrevTrack);
HandleEvent(MediaControlKey::Previoustrack);
return MPRemoteCommandHandlerStatusSuccess;
});
}
@ -57,7 +57,7 @@ MediaCenterEventHandler MediaHardwareKeysEventSourceMacMediaCenter::CreatePlayHa
if (center.playbackState != MPNowPlayingPlaybackStatePlaying) {
center.playbackState = MPNowPlayingPlaybackStatePlaying;
}
HandleEvent(MediaControlKeysEvent::ePlay);
HandleEvent(MediaControlKey::Play);
return MPRemoteCommandHandlerStatusSuccess;
});
}
@ -69,7 +69,7 @@ MediaCenterEventHandler MediaHardwareKeysEventSourceMacMediaCenter::CreatePauseH
if (center.playbackState != MPNowPlayingPlaybackStatePaused) {
center.playbackState = MPNowPlayingPlaybackStatePaused;
}
HandleEvent(MediaControlKeysEvent::ePause);
HandleEvent(MediaControlKey::Pause);
return MPRemoteCommandHandlerStatusSuccess;
});
}
@ -139,12 +139,12 @@ void MediaHardwareKeysEventSourceMacMediaCenter::Close() {
LOG("Close MediaHardwareKeysEventSourceMacMediaCenter");
EndListeningForEvents();
mOpened = false;
MediaControlKeysEventSource::Close();
MediaControlKeySource::Close();
}
bool MediaHardwareKeysEventSourceMacMediaCenter::IsOpened() const { return mOpened; }
void MediaHardwareKeysEventSourceMacMediaCenter::HandleEvent(MediaControlKeysEvent aEvent) {
void MediaHardwareKeysEventSourceMacMediaCenter::HandleEvent(MediaControlKey aEvent) {
for (auto iter = mListeners.begin(); iter != mListeners.end(); ++iter) {
(*iter)->OnKeyPressed(aEvent);
}
@ -161,7 +161,7 @@ void MediaHardwareKeysEventSourceMacMediaCenter::SetPlaybackState(
} else if (aState == MediaSessionPlaybackState::None) {
center.playbackState = MPNowPlayingPlaybackStateStopped;
}
MediaControlKeysEventSource::SetPlaybackState(aState);
MediaControlKeySource::SetPlaybackState(aState);
}
}

Просмотреть файл

@ -11,7 +11,7 @@
namespace mozilla {
namespace widget {
mozilla::dom::MediaControlKeysEventSource* CreateMediaControlKeysEventSource() {
mozilla::dom::MediaControlKeySource* CreateMediaControlKeySource() {
if (nsCocoaFeatures::IsAtLeastVersion(10, 12, 2)) {
return new MediaHardwareKeysEventSourceMacMediaCenter();
} else {

Просмотреть файл

@ -460,7 +460,7 @@ void MPRISServiceHandler::Close() {
}
mInitialized = false;
MediaControlKeysEventSource::Close();
MediaControlKeySource::Close();
}
bool MPRISServiceHandler::IsOpened() const { return mInitialized; }
@ -560,7 +560,7 @@ void MPRISServiceHandler::SetPlaybackState(
return;
}
MediaControlKeysEventSource::SetPlaybackState(aState);
MediaControlKeySource::SetPlaybackState(aState);
if (!mConnection) {
return; // No D-Bus Connection, no event
@ -661,45 +661,45 @@ GVariant* MPRISServiceHandler::GetMetadataAsGVariant() const {
return g_variant_builder_end(&builder);
}
void MPRISServiceHandler::EmitEvent(mozilla::dom::MediaControlKeysEvent event) {
void MPRISServiceHandler::EmitEvent(mozilla::dom::MediaControlKey aKey) {
for (auto& listener : mListeners) {
listener->OnKeyPressed(event);
listener->OnKeyPressed(aKey);
}
}
void MPRISServiceHandler::Raise() {
LOG("Raise");
EmitEvent(mozilla::dom::MediaControlKeysEvent::eFocus);
EmitEvent(mozilla::dom::MediaControlKey::Focus);
}
void MPRISServiceHandler::Next() {
LOG("Next");
EmitEvent(mozilla::dom::MediaControlKeysEvent::eNextTrack);
EmitEvent(mozilla::dom::MediaControlKey::Nexttrack);
}
void MPRISServiceHandler::Previous() {
LOG("Previous");
EmitEvent(mozilla::dom::MediaControlKeysEvent::ePrevTrack);
EmitEvent(mozilla::dom::MediaControlKey::Previoustrack);
}
void MPRISServiceHandler::Pause() {
LOG("Pause");
EmitEvent(mozilla::dom::MediaControlKeysEvent::ePause);
EmitEvent(mozilla::dom::MediaControlKey::Pause);
}
void MPRISServiceHandler::PlayPause() {
LOG("PlayPause");
EmitEvent(mozilla::dom::MediaControlKeysEvent::ePlayPause);
EmitEvent(mozilla::dom::MediaControlKey::Playpause);
}
void MPRISServiceHandler::Stop() {
LOG("Stop");
EmitEvent(mozilla::dom::MediaControlKeysEvent::eStop);
EmitEvent(mozilla::dom::MediaControlKey::Stop);
}
void MPRISServiceHandler::Play() {
LOG("Play");
EmitEvent(mozilla::dom::MediaControlKeysEvent::ePlay);
EmitEvent(mozilla::dom::MediaControlKey::Play);
}
// Caution, Seek can really be negative, like -1000000 during testing

Просмотреть файл

@ -8,7 +8,7 @@
#define WIDGET_GTK_MPRIS_SERVICE_HANDLER_H_
#include <gio/gio.h>
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/dom/MediaControlKeySource.h"
#include "mozilla/Attributes.h"
#include "nsString.h"
@ -47,7 +47,7 @@ namespace widget {
* media available for playback?)
* and thus aren't a constexpr but merely a const method.
*/
class MPRISServiceHandler final : public dom::MediaControlKeysEventSource {
class MPRISServiceHandler final : public dom::MediaControlKeySource {
NS_INLINE_DECL_REFCOUNTING(MPRISServiceHandler, override)
public:
// Note that this constructor does NOT initialize the MPRIS Service but only
@ -161,7 +161,7 @@ class MPRISServiceHandler final : public dom::MediaControlKeysEventSource {
static void OnBusAcquiredStatic(GDBusConnection* aConnection,
const gchar* aName, gpointer aUserData);
void EmitEvent(dom::MediaControlKeysEvent event);
void EmitEvent(dom::MediaControlKey aKey);
};
} // namespace widget

Просмотреть файл

@ -7,7 +7,7 @@
namespace mozilla::widget {
mozilla::dom::MediaControlKeysEventSource* CreateMediaControlKeysEventSource() {
mozilla::dom::MediaControlKeySource* CreateMediaControlKeySource() {
return new MPRISServiceHandler();
}

Просмотреть файл

@ -8,7 +8,7 @@
namespace mozilla {
namespace widget {
mozilla::dom::MediaControlKeysEventSource* CreateMediaControlKeysEventSource() {
mozilla::dom::MediaControlKeySource* CreateMediaControlKeySource() {
#ifndef __MINGW32__
return new WindowsSMTCProvider();
#else

Просмотреть файл

@ -91,23 +91,23 @@ WindowsSMTCProvider::~WindowsSMTCProvider() {
}
}
static inline Maybe<mozilla::dom::MediaControlKeysEvent> TranslateKeycode(
static inline Maybe<mozilla::dom::MediaControlKey> TranslateKeycode(
SystemMediaTransportControlsButton keycode) {
switch (keycode) {
case SystemMediaTransportControlsButton_Play:
return Some(mozilla::dom::MediaControlKeysEvent::ePlay);
return Some(mozilla::dom::MediaControlKey::Play);
case SystemMediaTransportControlsButton_Pause:
return Some(mozilla::dom::MediaControlKeysEvent::ePause);
return Some(mozilla::dom::MediaControlKey::Pause);
case SystemMediaTransportControlsButton_Next:
return Some(mozilla::dom::MediaControlKeysEvent::eNextTrack);
return Some(mozilla::dom::MediaControlKey::Nexttrack);
case SystemMediaTransportControlsButton_Previous:
return Some(mozilla::dom::MediaControlKeysEvent::ePrevTrack);
return Some(mozilla::dom::MediaControlKey::Previoustrack);
case SystemMediaTransportControlsButton_Stop:
return Some(mozilla::dom::MediaControlKeysEvent::eStop);
return Some(mozilla::dom::MediaControlKey::Stop);
case SystemMediaTransportControlsButton_FastForward:
return Some(mozilla::dom::MediaControlKeysEvent::eSeekForward);
return Some(mozilla::dom::MediaControlKey::Seekforward);
case SystemMediaTransportControlsButton_Rewind:
return Some(mozilla::dom::MediaControlKeysEvent::eSeekBackward);
return Some(mozilla::dom::MediaControlKey::Seekbackward);
default:
return Nothing(); // Not supported Button
}
@ -131,8 +131,7 @@ bool WindowsSMTCProvider::RegisterEvents() {
return S_OK; // Propagating the error probably wouldn't help.
}
Maybe<mozilla::dom::MediaControlKeysEvent> keyCode =
TranslateKeycode(btn);
Maybe<mozilla::dom::MediaControlKey> keyCode = TranslateKeycode(btn);
if (keyCode.isSome() && IsOpened()) {
OnButtonPressed(keyCode.value());
}
@ -228,7 +227,7 @@ bool WindowsSMTCProvider::Open() {
bool WindowsSMTCProvider::IsOpened() const { return mInitialized; }
void WindowsSMTCProvider::Close() {
MediaControlKeysEventSource::Close();
MediaControlKeySource::Close();
if (mInitialized) { // Prevent calling Set methods when init failed
SetPlaybackState(mozilla::dom::MediaSessionPlaybackState::None);
SetControlAttributes(SMTCControlAttributes::DisableAll());
@ -241,7 +240,7 @@ void WindowsSMTCProvider::Close() {
void WindowsSMTCProvider::SetPlaybackState(
mozilla::dom::MediaSessionPlaybackState aState) {
MOZ_ASSERT(mInitialized);
MediaControlKeysEventSource::SetPlaybackState(aState);
MediaControlKeySource::SetPlaybackState(aState);
HRESULT hr;
@ -400,10 +399,9 @@ void WindowsSMTCProvider::SetMediaMetadata(
Update();
}
void WindowsSMTCProvider::OnButtonPressed(
mozilla::dom::MediaControlKeysEvent aEvent) {
void WindowsSMTCProvider::OnButtonPressed(mozilla::dom::MediaControlKey aKey) {
for (auto& listener : mListeners) {
listener->OnKeyPressed(aEvent);
listener->OnKeyPressed(aKey);
}
}

Просмотреть файл

@ -13,7 +13,7 @@
# include <wrl.h>
# include "mozilla\dom\MediaController.h"
# include "mozilla\dom\MediaControlKeysEvent.h"
# include "mozilla\dom\MediaControlKeySource.h"
# include "mozilla\Maybe.h"
using ISMTC = ABI::Windows::Media::ISystemMediaTransportControls;
@ -35,8 +35,7 @@ struct SMTCControlAttributes {
}
};
class WindowsSMTCProvider final
: public mozilla::dom::MediaControlKeysEventSource {
class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource {
NS_INLINE_DECL_REFCOUNTING(WindowsSMTCProvider, override)
public:
@ -75,7 +74,7 @@ class WindowsSMTCProvider final
void UnregisterEvents();
bool RegisterEvents();
bool InitDisplayAndControls();
void OnButtonPressed(mozilla::dom::MediaControlKeysEvent aEvent);
void OnButtonPressed(mozilla::dom::MediaControlKey aKey);
// This method flushes the changed Media Metadata to the OS.
bool Update();