Bug 1632301 - part3 : use MediaAudibleState to replace boolean value. r=bryce

This patch will do :
- replace `boolean` with enum class `MediaAudibleState`

The advantage of doing so :
- It's easier to understand what actually meaning of the parameter we set

Differential Revision: https://phabricator.services.mozilla.com/D72058
This commit is contained in:
alwu 2020-04-28 07:14:05 +00:00
Родитель db7bb9c21e
Коммит d1cbaeb672
10 изменённых файлов: 46 добавлений и 24 удалений

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

@ -447,7 +447,7 @@ class HTMLMediaElement::MediaControlEventListener final
// the state, because notifying `inaudible` should always come after
// notifying `audible`.
if (mIsOwnerAudible) {
NotifyAudibleStateChanged(true);
NotifyAudibleStateChanged(MediaAudibleState::eAudible);
}
}
}
@ -459,7 +459,7 @@ class HTMLMediaElement::MediaControlEventListener final
NotifyMediaStateChanged(ControlledMediaState::ePaused);
// As media are going to be paused, so no sound is possible to be heard.
if (mIsOwnerAudible) {
NotifyAudibleStateChanged(false);
NotifyAudibleStateChanged(MediaAudibleState::eInaudible);
}
}
}
@ -477,7 +477,9 @@ class HTMLMediaElement::MediaControlEventListener final
// audible state. Therefore, in that case we would noitfy the audible state
// when media starts playing.
if (mState == ControlledMediaState::ePlayed) {
NotifyAudibleStateChanged(mIsOwnerAudible);
NotifyAudibleStateChanged(mIsOwnerAudible
? MediaAudibleState::eAudible
: MediaAudibleState::eInaudible);
}
}
@ -539,10 +541,10 @@ class HTMLMediaElement::MediaControlEventListener final
mControlAgent->NotifyMediaStateChanged(this, mState);
}
void NotifyAudibleStateChanged(bool aIsOwnerAudible) {
void NotifyAudibleStateChanged(MediaAudibleState aState) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsStarted());
mControlAgent->NotifyAudibleStateChanged(this, aIsOwnerAudible);
mControlAgent->NotifyAudibleStateChanged(this, aState);
}
ControlledMediaState mState = ControlledMediaState::eStopped;

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

@ -5802,13 +5802,13 @@ mozilla::ipc::IPCResult ContentParent::RecvNotifyMediaStateChanged(
}
mozilla::ipc::IPCResult ContentParent::RecvNotifyMediaAudibleChanged(
const MaybeDiscarded<BrowsingContext>& aContext, bool aAudible) {
const MaybeDiscarded<BrowsingContext>& aContext, MediaAudibleState aState) {
if (aContext.IsNullOrDiscarded()) {
return IPC_OK();
}
if (RefPtr<MediaController> controller =
aContext.get_canonical()->GetMediaController()) {
controller->NotifyMediaAudibleChanged(aAudible);
controller->NotifyMediaAudibleChanged(aState);
}
return IPC_OK();
}

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

@ -1248,7 +1248,8 @@ class ContentParent final
ControlledMediaState aState);
mozilla::ipc::IPCResult RecvNotifyMediaAudibleChanged(
const MaybeDiscarded<BrowsingContext>& aContext, bool aAudible);
const MaybeDiscarded<BrowsingContext>& aContext,
MediaAudibleState aState);
mozilla::ipc::IPCResult RecvNotifyPictureInPictureModeChanged(
const MaybeDiscarded<BrowsingContext>& aContext, bool aEnabled);

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

@ -118,6 +118,7 @@ using gfxSparseBitSet from "gfxFontUtils.h";
using FontVisibility from "gfxFontEntry.h";
using mozilla::dom::MediaControlKeysEvent from "ipc/MediaControlIPC.h";
using mozilla::dom::ControlledMediaState from "ipc/MediaControlIPC.h";
using mozilla::dom::MediaAudibleState from "ipc/MediaControlIPC.h";
using mozilla::dom::MaybeMediaMetadataBase from "mozilla/dom/MediaSessionIPCUtils.h";
using mozilla::dom::MediaSessionPlaybackState from "mozilla/dom/MediaSessionBinding.h";
using refcounted class nsDocShellLoadState from "nsDocShellLoadState.h";
@ -1515,7 +1516,7 @@ parent:
* notify chrome process in order to which tab is audible.
*/
async NotifyMediaAudibleChanged(MaybeDiscardedBrowsingContext aContext,
bool aAudible);
MediaAudibleState aState);
/**
* When media enabled or disabled the Picture-in-Picture mode, we have to

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

@ -120,7 +120,7 @@ void ContentMediaController::NotifyMediaStateChanged(
}
void ContentMediaController::NotifyAudibleStateChanged(
const ContentControlKeyEventReceiver* aMedia, bool aAudible) {
const ContentControlKeyEventReceiver* aMedia, MediaAudibleState aState) {
MOZ_ASSERT(NS_IsMainThread());
if (!mReceivers.Contains(aMedia)) {
return;
@ -132,16 +132,17 @@ void ContentMediaController::NotifyAudibleStateChanged(
}
LOG("Notify media became %s in BC %" PRId64,
aAudible ? "audible" : "inaudible", bc->Id());
aState == MediaAudibleState::eAudible ? "audible" : "inaudible",
bc->Id());
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaAudibleChanged(bc, aAudible);
Unused << contentChild->SendNotifyMediaAudibleChanged(bc, aState);
} else {
// Currently this only happen when we disable e10s, otherwise all controlled
// media would be run in the content process.
if (RefPtr<MediaController> controller =
bc->Canonical()->GetMediaController()) {
controller->NotifyMediaAudibleChanged(aAudible);
controller->NotifyMediaAudibleChanged(aState);
}
}
}

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

@ -33,6 +33,15 @@ enum class ControlledMediaState : uint32_t {
eStopped,
};
/**
* This enum is used to update controlled media audible audible state to the
* media controller in the chrome process.
*/
enum class MediaAudibleState : bool {
eInaudible = false,
eAudible = true,
};
/**
* ContentControlKeyEventReceiver is an interface which is used to receive media
* control key events sent from the chrome process, this class MUST only be used
@ -94,7 +103,8 @@ class ContentMediaAgent {
// (X) `audible` -> `audible` [notify `audible` twice]
// (X) `audible` -> (media pauses) [forgot to notify `inaudible`]
virtual void NotifyAudibleStateChanged(
const ContentControlKeyEventReceiver* aMedia, bool aAudible) = 0;
const ContentControlKeyEventReceiver* aMedia,
MediaAudibleState aState) = 0;
// Use this method to update the picture in picture mode state of controlled
// media, and it's safe to notify same state again.
@ -136,7 +146,7 @@ class ContentMediaController final : public ContentMediaAgent,
void NotifyMediaStateChanged(const ContentControlKeyEventReceiver* aMedia,
ControlledMediaState aState) override;
void NotifyAudibleStateChanged(const ContentControlKeyEventReceiver* aMedia,
bool aAudible) override;
MediaAudibleState aState) override;
void NotifyPictureInPictureModeChanged(
const ContentControlKeyEventReceiver* aMedia, bool aEnabled) override;

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

@ -27,6 +27,13 @@ struct ParamTraits<mozilla::dom::ControlledMediaState>
mozilla::dom::ControlledMediaState::eStarted,
mozilla::dom::ControlledMediaState::eStopped> {};
template <>
struct ParamTraits<mozilla::dom::MediaAudibleState>
: public ContiguousEnumSerializerInclusive<
mozilla::dom::MediaAudibleState,
mozilla::dom::MediaAudibleState::eInaudible,
mozilla::dom::MediaAudibleState::eAudible> {};
} // namespace IPC
#endif // mozilla_MediaControlIPC_hh

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

@ -138,14 +138,14 @@ void MediaController::NotifyMediaStateChanged(ControlledMediaState aState) {
}
}
void MediaController::NotifyMediaAudibleChanged(bool aAudible) {
void MediaController::NotifyMediaAudibleChanged(MediaAudibleState aState) {
if (mShutdown) {
return;
}
mAudible = aAudible;
mAudibleState = aState;
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(service);
if (mAudible) {
if (mAudibleState == MediaAudibleState::eAudible) {
service->GetAudioFocusManager().RequestAudioFocus(this);
} else {
service->GetAudioFocusManager().RevokeAudioFocus(this);
@ -276,7 +276,7 @@ MediaSessionPlaybackState MediaController::GetState() const {
bool MediaController::IsAudible() const {
return mGuessedPlaybackState == MediaSessionPlaybackState::Playing &&
mAudible;
mAudibleState == MediaAudibleState::eAudible;
}
uint64_t MediaController::ControlledMediaNum() const {

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

@ -84,7 +84,7 @@ class MediaController final
// These methods are only being used to notify the state changes of controlled
// media in ContentParent or MediaControlUtils.
void NotifyMediaStateChanged(ControlledMediaState aState);
void NotifyMediaAudibleChanged(bool aAudible);
void NotifyMediaAudibleChanged(MediaAudibleState aState);
private:
~MediaController();
@ -106,7 +106,7 @@ class MediaController final
// to know if we need to update the virtual control interface.
void UpdateActualPlaybackState();
bool mAudible = false;
MediaAudibleState mAudibleState = MediaAudibleState::eInaudible;
bool mIsRegisteredToService = false;
int64_t mControlledMediaNum = 0;
int64_t mPlayingControlledMediaNum = 0;

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

@ -59,10 +59,10 @@ TEST(MediaController, AudibleChanged)
controller->Play();
ASSERT_TRUE(!controller->IsAudible());
controller->NotifyMediaAudibleChanged(true);
controller->NotifyMediaAudibleChanged(MediaAudibleState::eAudible);
ASSERT_TRUE(controller->IsAudible());
controller->NotifyMediaAudibleChanged(false);
controller->NotifyMediaAudibleChanged(MediaAudibleState::eInaudible);
ASSERT_TRUE(!controller->IsAudible());
}
@ -71,7 +71,7 @@ TEST(MediaController, AlwaysInaudibleIfControllerIsNotPlaying)
RefPtr<MediaController> controller = new MediaController(CONTROLLER_ID);
ASSERT_TRUE(!controller->IsAudible());
controller->NotifyMediaAudibleChanged(true);
controller->NotifyMediaAudibleChanged(MediaAudibleState::eAudible);
ASSERT_TRUE(!controller->IsAudible());
controller->Play();