Backed out 7 changesets (bug 1565689) for browser chrome failures CLOSED TREE

Backed out changeset 36ea91bf28f7 (bug 1565689)
Backed out changeset 278340adf69c (bug 1565689)
Backed out changeset 4f508252b015 (bug 1565689)
Backed out changeset faaa4e9ba8d3 (bug 1565689)
Backed out changeset 177f2b26c892 (bug 1565689)
Backed out changeset ba665f96330d (bug 1565689)
Backed out changeset 0de7b1db3ef9 (bug 1565689)
This commit is contained in:
Bogdan Tara 2019-08-06 04:09:19 +03:00
parent 9ae0346584
commit a252740d31
29 changed files with 0 additions and 1304 deletions

View File

@ -209,16 +209,6 @@ void CanonicalBrowsingContext::NotifyMediaMutedChanged(bool aMuted) {
});
}
void CanonicalBrowsingContext::UpdateMediaAction(MediaControlActions aAction) {
nsPIDOMWindowOuter* window = GetDOMWindow();
if (window) {
window->UpdateMediaAction(aAction);
}
Group()->EachParent([&](ContentParent* aParent) {
Unused << aParent->SendUpdateMediaAction(this, aAction);
});
}
void CanonicalBrowsingContext::SetFieldEpochsForChild(
ContentParent* aChild, const BrowsingContext::FieldEpochs& aEpochs) {
mChildFieldEpochs.Put(aChild->ChildID(), aEpochs);

View File

@ -8,7 +8,6 @@
#define mozilla_dom_CanonicalBrowsingContext_h
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/MediaController.h"
#include "mozilla/RefPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
@ -79,10 +78,6 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// other top level windows in other processes.
void NotifyMediaMutedChanged(bool aMuted);
// This function would update the media action for the current outer window
// and propogate the action to other browsing contexts in content processes.
void UpdateMediaAction(MediaControlActions aAction);
// Validate that the given process is allowed to perform the given
// transaction. aSource is |nullptr| if set in the parent process.
bool ValidateTransaction(const Transaction& aTransaction,

View File

@ -139,10 +139,6 @@ bool IsEnableAudioCompetingForAllAgents() {
namespace mozilla {
namespace dom {
extern void NotifyMediaStarted(uint64_t aWindowID);
extern void NotifyMediaStopped(uint64_t aWindowID);
extern void NotifyMediaAudibleChanged(uint64_t aWindowID, bool aAudible);
const char* SuspendTypeToStr(const nsSuspendedTypes& aSuspend) {
MOZ_ASSERT(aSuspend == nsISuspendedTypes::NONE_SUSPENDED ||
aSuspend == nsISuspendedTypes::SUSPENDED_PAUSE ||
@ -774,7 +770,6 @@ void AudioChannelService::AudioChannelWindow::AppendAgentAndIncreaseAgentsNum(
if (mConfig.mNumberOfAgents == 1) {
NotifyChannelActive(aAgent->WindowID(), true);
}
NotifyMediaStarted(aAgent->WindowID());
}
void AudioChannelService::AudioChannelWindow::RemoveAgentAndReduceAgentsNum(
@ -790,7 +785,6 @@ void AudioChannelService::AudioChannelWindow::RemoveAgentAndReduceAgentsNum(
if (mConfig.mNumberOfAgents == 0) {
NotifyChannelActive(aAgent->WindowID(), false);
}
NotifyMediaStopped(aAgent->WindowID());
}
void AudioChannelService::AudioChannelWindow::AudioCapturedChanged(
@ -830,7 +824,6 @@ void AudioChannelService::AudioChannelWindow::AppendAudibleAgentIfNotContained(
NotifyAudioAudibleChanged(aAgent->Window(), AudibleState::eAudible,
aReason);
}
NotifyMediaAudibleChanged(aAgent->WindowID(), true);
}
}
@ -844,7 +837,6 @@ void AudioChannelService::AudioChannelWindow::RemoveAudibleAgentIfContained(
NotifyAudioAudibleChanged(aAgent->Window(), AudibleState::eNotAudible,
aReason);
}
NotifyMediaAudibleChanged(aAgent->WindowID(), false);
}
}

View File

@ -30,8 +30,6 @@
#include "mozilla/dom/LSObject.h"
#include "mozilla/dom/Storage.h"
#include "mozilla/dom/MaybeCrossOriginObject.h"
#include "mozilla/dom/MediaController.h"
#include "mozilla/dom/MediaControlUtils.h"
#include "mozilla/dom/Performance.h"
#include "mozilla/dom/StorageEvent.h"
#include "mozilla/dom/StorageEventBinding.h"
@ -272,12 +270,6 @@ using mozilla::BasePrincipal;
using mozilla::OriginAttributes;
using mozilla::TimeStamp;
extern mozilla::LazyLogModule gMediaControlLog;
#define MC_LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("WindowOuter=%p, " msg, this, ##__VA_ARGS__))
#define FORWARD_TO_INNER(method, args, err_rval) \
PR_BEGIN_MACRO \
if (!mInnerWindow) { \
@ -2884,26 +2876,6 @@ SuspendTypes nsPIDOMWindowOuter::GetMediaSuspend() const {
return mMediaSuspend;
}
void nsPIDOMWindowOuter::UpdateMediaAction(const MediaControlActions aAction) {
// TODO : we now temporarily map MediaControlActions to nsISuspendedTypes in
// order to control media, but for long term goal in which we should not rely
// on nsISuspendedTypes and completely decouple them. See bug1571493.
MC_LOG("UpdateMediaAction %s", ToMediaControlActionsStr(aAction));
switch (aAction) {
case MediaControlActions::ePlay:
SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
break;
case MediaControlActions::ePause:
SetMediaSuspend(nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE);
break;
case MediaControlActions::eStop:
SetMediaSuspend(nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE);
break;
default:
MOZ_ASSERT_UNREACHABLE("Invalid action.");
};
}
void nsPIDOMWindowOuter::SetMediaSuspend(SuspendTypes aSuspend) {
if (!IsDisposableSuspend(aSuspend)) {
MaybeNotifyMediaResumedFromBlock(aSuspend);

View File

@ -70,7 +70,6 @@ class TimeoutManager;
class WindowGlobalChild;
class CustomElementRegistry;
enum class CallerType : uint32_t;
enum class MediaControlActions : uint32_t;
} // namespace dom
} // namespace mozilla
@ -757,8 +756,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
void MaybeActiveMediaComponents();
void UpdateMediaAction(const mozilla::dom::MediaControlActions aAction);
void SetServiceWorkersTestingEnabled(bool aEnabled);
bool GetServiceWorkersTestingEnabled();

View File

@ -227,7 +227,6 @@
#endif
#include "mozilla/dom/File.h"
#include "mozilla/dom/MediaController.h"
#include "mozilla/dom/PPresentationChild.h"
#include "mozilla/dom/PresentationIPCService.h"
#include "mozilla/ipc/InputStreamUtils.h"
@ -3741,16 +3740,6 @@ mozilla::ipc::IPCResult ContentChild::RecvSetMediaMuted(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvUpdateMediaAction(
BrowsingContext* aContext, MediaControlActions aAction) {
MOZ_ASSERT(aContext);
nsCOMPtr<nsPIDOMWindowOuter> window = aContext->GetDOMWindow();
if (window) {
window->UpdateMediaAction(aAction);
}
return IPC_OK();
}
already_AddRefed<nsIEventTarget> ContentChild::GetSpecificMessageEventTarget(
const Message& aMsg) {
switch (aMsg.type()) {

View File

@ -73,7 +73,6 @@ class ClonedMessageData;
class BrowserChild;
class GetFilesHelperChild;
class TabContext;
enum class MediaControlActions : uint32_t;
class ContentChild final : public PContentChild,
public nsIWindowProvider,
@ -689,9 +688,6 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvSetMediaMuted(BrowsingContext* aContext,
bool aMuted);
mozilla::ipc::IPCResult RecvUpdateMediaAction(BrowsingContext* aContext,
MediaControlActions aAction);
void HoldBrowsingContextGroup(BrowsingContextGroup* aBCG);
void ReleaseBrowsingContextGroup(BrowsingContextGroup* aBCG);

View File

@ -12,7 +12,6 @@
#include "ContentParent.h"
#include "ProcessUtils.h"
#include "BrowserParent.h"
#include "mozilla/dom/MediaControlService.h"
#if defined(ANDROID) || defined(LINUX)
# include <sys/time.h>
@ -5781,28 +5780,6 @@ mozilla::ipc::IPCResult ContentParent::RecvStoreUserInteractionAsPermission(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvNotifyMediaActiveChanged(
BrowsingContext* aContext, bool aActive) {
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(!aContext->GetParent(), "Should be top level browsing context!");
RefPtr<MediaController> controller =
service->GetOrCreateControllerById(aContext->Id());
controller->NotifyMediaActiveChanged(aActive);
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvNotifyMediaAudibleChanged(
BrowsingContext* aContext, bool aAudible) {
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(!aContext->GetParent(), "Should be top level browsing context!");
RefPtr<MediaController> controller =
service->GetControllerById(aContext->Id());
if (controller) {
controller->NotifyMediaAudibleChanged(aAudible);
}
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvAttachBrowsingContext(
BrowsingContext::IPCInitializer&& aInit) {
RefPtr<CanonicalBrowsingContext> parent;

View File

@ -1186,12 +1186,6 @@ class ContentParent final : public PContentParent,
mozilla::ipc::IPCResult RecvStoreUserInteractionAsPermission(
const Principal& aPrincipal);
mozilla::ipc::IPCResult RecvNotifyMediaActiveChanged(
BrowsingContext* aContext, bool aActive);
mozilla::ipc::IPCResult RecvNotifyMediaAudibleChanged(
BrowsingContext* aContext, bool aAudible);
// Notify the ContentChild to enable the input event prioritization when
// initializing.
void MaybeEnableRemoteInputEventQueue();

View File

@ -104,7 +104,6 @@ using base::SharedMemoryHandle from "base/shared_memory.h";
using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h";
using mozilla::fontlist::Pointer from "SharedFontList.h";
using gfxSparseBitSet from "gfxFontUtils.h";
using mozilla::dom::MediaControlActions from "ipc/MediaControlIPC.h";
union ChromeRegistryItem
{
@ -808,12 +807,6 @@ child:
*/
async SetMediaMuted(BrowsingContext aContext, bool aMuted);
/**
* This method is used to apply the media action to outer window in the
* content process, such as play, pause, stop ..e.t.c.
*/
async UpdateMediaAction(BrowsingContext aContext, MediaControlActions aAction);
// Begin subscribing to a new BrowsingContextGroup, sending down the current
// value for every individual BrowsingContext.
async RegisterBrowsingContextGroup(BrowsingContextInitializer[] aInits);
@ -1390,18 +1383,6 @@ parent:
async StoreUserInteractionAsPermission(Principal aPrincipal);
/**
* When media started or stopped in content process, we have to notify the
* chrome process in order to know which tab is playing media.
*/
async NotifyMediaActiveChanged(BrowsingContext aContext, bool aActive);
/**
* When media became audible or inaudible in content process, we have to
* notify chrome process in order to which tab is audible.
*/
async NotifyMediaAudibleChanged(BrowsingContext aContext, bool aAudible);
both:
async CommitBrowsingContextTransaction(BrowsingContext aContext,
BrowsingContextTransaction aTransaction,

View File

@ -1,74 +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/. */
#include "AudioFocusManager.h"
#include "MediaControlService.h"
#include "mozilla/Logging.h"
#include "mozilla/StaticPrefs_media.h"
extern mozilla::LazyLogModule gMediaControlLog;
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("AudioFocusManager=%p, " msg, this, ##__VA_ARGS__))
namespace mozilla {
namespace dom {
AudioFocusManager::AudioFocusManager(MediaControlService* aService)
: mService(aService) {}
void AudioFocusManager::RequestAudioFocus(uint64_t aId) {
if (mOwningFocusControllers.Contains(aId)) {
return;
}
LOG("Controller %" PRId64 " grants audio focus", aId);
mOwningFocusControllers.AppendElement(aId);
HandleAudioCompetition(aId);
}
void AudioFocusManager::RevokeAudioFocus(uint64_t aId) {
if (!mOwningFocusControllers.Contains(aId)) {
return;
}
LOG("Controller %" PRId64 " loses audio focus", aId);
mOwningFocusControllers.RemoveElement(aId);
}
void AudioFocusManager::HandleAudioCompetition(uint64_t aId) {
// Enable audio focus management will start the audio competition which is
// only allowing one controller playing at a time.
if (!StaticPrefs::media_audioFocus_management()) {
return;
}
for (size_t idx = 0; idx < mOwningFocusControllers.Length(); idx++) {
const uint64_t controllerId = mOwningFocusControllers[idx];
if (controllerId != aId) {
LOG("Controller %" PRId64 " loses audio focus in audio competitition",
controllerId);
RefPtr<MediaController> controller =
mService->GetControllerById(controllerId);
MOZ_ASSERT(controller);
controller->Stop();
}
}
mOwningFocusControllers.Clear();
mOwningFocusControllers.AppendElement(aId);
}
uint32_t AudioFocusManager::GetAudioFocusNums() const {
return mOwningFocusControllers.Length();
}
void AudioFocusManager::Shutdown() { mService = nullptr; }
} // namespace dom
} // namespace mozilla

View File

@ -1,47 +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 mozilla_dom_audiofocusmanager_h__
#define mozilla_dom_audiofocusmanager_h__
#include "base/basictypes.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class MediaControlService;
/**
* AudioFocusManager is used to assign the audio focus to different requester
* and decide which requester can own audio focus when audio competing happens.
* When the audio competing happens, the last request would be a winner who can
* still own the audio focus, and all the other requesters would lose the audio
* focus. Now MediaController is the onlt requester, it would request the audio
* focus when it becomes audible and revoke the audio focus when the controller
* is no longer active.
*/
class AudioFocusManager {
public:
void RequestAudioFocus(uint64_t aId);
void RevokeAudioFocus(uint64_t aId);
explicit AudioFocusManager(MediaControlService* aService);
~AudioFocusManager() = default;
uint32_t GetAudioFocusNums() const;
private:
friend class MediaControlService;
void Shutdown();
void HandleAudioCompetition(uint64_t aId);
RefPtr<MediaControlService> mService;
nsTArray<uint64_t> mOwningFocusControllers;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_audiofocusmanager_h__

View File

@ -1,24 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 ipc_MediaControlIPC_h
#define ipc_MediaControlIPC_h
#include "ipc/IPCMessageUtils.h"
#include "mozilla/dom/MediaController.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::dom::MediaControlActions>
: public ContiguousEnumSerializer<
mozilla::dom::MediaControlActions,
mozilla::dom::MediaControlActions::ePlay,
mozilla::dom::MediaControlActions(
mozilla::dom::MediaControlActions::eActionsNum)> {};
} // namespace IPC
#endif // mozilla_MediaControlIPC_hh

View File

@ -1,155 +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/. */
#include "MediaControlService.h"
#include "MediaController.h"
#include "mozilla/Assertions.h"
#include "mozilla/Logging.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "nsIObserverService.h"
#include "nsXULAppAPI.h"
extern mozilla::LazyLogModule gMediaControlLog;
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlService=%p, " msg, this, ##__VA_ARGS__))
namespace mozilla {
namespace dom {
StaticRefPtr<MediaControlService> gMediaControlService;
static bool sIsXPCOMShutdown = false;
/* static */
RefPtr<MediaControlService> MediaControlService::GetService() {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(),
"MediaControlService only runs on Chrome process!");
if (sIsXPCOMShutdown) {
return nullptr;
}
if (!gMediaControlService) {
gMediaControlService = new MediaControlService();
}
RefPtr<MediaControlService> service = gMediaControlService.get();
return service;
}
NS_INTERFACE_MAP_BEGIN(MediaControlService)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(MediaControlService)
NS_IMPL_RELEASE(MediaControlService)
MediaControlService::MediaControlService() : mAudioFocusManager(this) {
LOG("create media control service");
RefPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this, "xpcom-shutdown", false);
}
}
MediaControlService::~MediaControlService() {
LOG("destroy media control service");
Shutdown();
}
NS_IMETHODIMP
MediaControlService::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (!strcmp(aTopic, "xpcom-shutdown")) {
LOG("XPCOM shutdown");
sIsXPCOMShutdown = true;
MOZ_ASSERT(gMediaControlService);
RefPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, "xpcom-shutdown");
}
Shutdown();
gMediaControlService = nullptr;
}
return NS_OK;
}
void MediaControlService::Shutdown() {
mAudioFocusManager.Shutdown();
ShutdownAllControllers();
}
RefPtr<MediaController> MediaControlService::GetOrCreateControllerById(
const uint64_t aId) const {
RefPtr<MediaController> controller = mControllers.Get(aId);
if (!controller) {
controller = new TabMediaController(aId);
}
return controller;
}
RefPtr<MediaController> MediaControlService::GetControllerById(
const uint64_t aId) const {
return mControllers.Get(aId);
}
void MediaControlService::AddMediaController(
const RefPtr<MediaController>& aController) {
MOZ_DIAGNOSTIC_ASSERT(aController);
const uint64_t cId = aController->Id();
MOZ_DIAGNOSTIC_ASSERT(!mControllers.GetValue(cId),
"Controller has been added already!");
mControllers.Put(cId, aController);
LOG("Add media controller %" PRId64 ", currentNum=%" PRId64, cId,
GetControllersNum());
}
void MediaControlService::RemoveMediaController(
const RefPtr<MediaController>& aController) {
MOZ_DIAGNOSTIC_ASSERT(aController);
const uint64_t cId = aController->Id();
MOZ_DIAGNOSTIC_ASSERT(mControllers.GetValue(cId),
"Controller does not exist!");
mControllers.Remove(cId);
LOG("Remove media controller %" PRId64 ", currentNum=%" PRId64, cId,
GetControllersNum());
}
void MediaControlService::PlayAllControllers() const {
for (auto iter = mControllers.ConstIter(); !iter.Done(); iter.Next()) {
const RefPtr<MediaController>& controller = iter.Data();
controller->Play();
}
}
void MediaControlService::PauseAllControllers() const {
for (auto iter = mControllers.ConstIter(); !iter.Done(); iter.Next()) {
const RefPtr<MediaController>& controller = iter.Data();
controller->Pause();
}
}
void MediaControlService::StopAllControllers() const {
for (auto iter = mControllers.ConstIter(); !iter.Done(); iter.Next()) {
const RefPtr<MediaController>& controller = iter.Data();
controller->Stop();
}
}
void MediaControlService::ShutdownAllControllers() const {
for (auto iter = mControllers.ConstIter(); !iter.Done(); iter.Next()) {
const RefPtr<MediaController>& controller = iter.Data();
controller->Shutdown();
}
}
uint64_t MediaControlService::GetControllersNum() const {
return mControllers.Count();
}
} // namespace dom
} // namespace mozilla

View File

@ -1,63 +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 mozilla_dom_mediacontrolservice_h__
#define mozilla_dom_mediacontrolservice_h__
#include "mozilla/AlreadyAddRefed.h"
#include "AudioFocusManager.h"
#include "MediaController.h"
#include "nsDataHashtable.h"
#include "nsIObserver.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
/**
* MediaControlService is an interface to access controllers by providing
* controller Id. Everytime when controller becomes active, which means there is
* one or more media started in the corresponding browsing context, so now the
* controller is actually controlling something in the content process, so it
* would be added into the list of the MediaControlService. The controller would
* be removed from the list of the MediaControlService when it becomes inactive,
* which means no media is playing in the corresponding browsing context. Note
* that, a controller can't be added to or remove from the list twice. It should
* should have a responsibility to add and remove itself in the proper time.
*/
class MediaControlService final : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static RefPtr<MediaControlService> GetService();
RefPtr<MediaController> GetOrCreateControllerById(const uint64_t aId) const;
RefPtr<MediaController> GetControllerById(const uint64_t aId) const;
AudioFocusManager& GetAudioFocusManager() { return mAudioFocusManager; }
void AddMediaController(const RefPtr<MediaController>& aController);
void RemoveMediaController(const RefPtr<MediaController>& aController);
uint64_t GetControllersNum() const;
private:
MediaControlService();
~MediaControlService();
void Shutdown();
void PlayAllControllers() const;
void PauseAllControllers() const;
void StopAllControllers() const;
void ShutdownAllControllers() const;
nsDataHashtable<nsUint64HashKey, RefPtr<MediaController>> mControllers;
AudioFocusManager mAudioFocusManager;
};
} // namespace dom
} // namespace mozilla
#endif

View File

@ -1,110 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 mozilla_dom_MediaControlUtils_h
#define mozilla_dom_MediaControlUtils_h
#include "MediaController.h"
#include "MediaControlService.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "nsGlobalWindowOuter.h"
#include "nsXULAppAPI.h"
mozilla::LazyLogModule gMediaControlLog("MediaControl");
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlUtils, " msg, ##__VA_ARGS__))
namespace mozilla {
namespace dom {
static void NotifyMediaActiveChanged(const RefPtr<BrowsingContext>& aBc,
bool aActive) {
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaActiveChanged(aBc, aActive);
} else {
MediaControlService::GetService()
->GetOrCreateControllerById(aBc->Id())
->NotifyMediaActiveChanged(aActive);
}
}
static RefPtr<BrowsingContext> GetBrowingContextByWindowID(uint64_t aWindowID) {
RefPtr<nsGlobalWindowOuter> window =
nsGlobalWindowOuter::GetOuterWindowWithId(aWindowID);
if (!window) {
return nullptr;
}
return window->GetBrowsingContext();
}
const char* ToMediaControlActionsStr(
mozilla::dom::MediaControlActions aAction) {
switch (aAction) {
case MediaControlActions::ePlay:
return "Play";
case MediaControlActions::ePause:
return "Pause";
case MediaControlActions::eStop:
return "Stop";
default:
MOZ_ASSERT_UNREACHABLE("Invalid action.");
}
return "UNKNOWN";
}
void NotifyMediaStarted(uint64_t aWindowID) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc) {
return;
}
LOG("Notify media started in BC %" PRId64, bc->Id());
bc = bc->Top();
MOZ_ASSERT(bc->IsTopContent(), "Should use top level browsing context.");
NotifyMediaActiveChanged(bc, true);
}
void NotifyMediaStopped(uint64_t aWindowID) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc) {
return;
}
LOG("Notify media stopped in BC %" PRId64, bc->Id());
bc = bc->Top();
MOZ_ASSERT(bc->IsTopContent(), "Should use top level browsing context.");
NotifyMediaActiveChanged(bc, false);
}
void NotifyMediaAudibleChanged(uint64_t aWindowID, bool aAudible) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc) {
return;
}
LOG("Notify media became %s in BC %" PRId64,
aAudible ? "audible" : "inaudible", bc->Id());
bc = bc->Top();
MOZ_ASSERT(bc->IsTopContent(), "Should use top level browsing context.");
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaAudibleChanged(bc, aAudible);
} else {
RefPtr<MediaController> controller =
MediaControlService::GetService()->GetControllerById(bc->Id());
if (controller) {
controller->NotifyMediaAudibleChanged(aAudible);
}
}
}
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_MediaControlUtils_h

View File

@ -1,133 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "MediaController.h"
#include "MediaControlService.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
extern mozilla::LazyLogModule gMediaControlLog;
// avoid redefined macro in unified build
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("TabMediaController=%p, Id=%" PRId64 ", " msg, this, this->Id(), \
##__VA_ARGS__))
namespace mozilla {
namespace dom {
already_AddRefed<BrowsingContext> MediaController::GetContext() const {
return BrowsingContext::Get(mBrowsingContextId);
}
TabMediaController::TabMediaController(uint64_t aContextId)
: MediaController(aContextId) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(),
"MediaController only runs on Chrome process!");
LOG("Create controller %" PRId64, Id());
}
TabMediaController::~TabMediaController() {
LOG("Destroy controller %" PRId64, Id());
MOZ_DIAGNOSTIC_ASSERT(!mControlledMediaNum);
};
void TabMediaController::Play() {
LOG("Play");
mIsPlaying = true;
RefPtr<BrowsingContext> context = GetContext();
if (context) {
context->Canonical()->UpdateMediaAction(MediaControlActions::ePlay);
}
}
void TabMediaController::Pause() {
LOG("Pause");
mIsPlaying = false;
RefPtr<BrowsingContext> context = GetContext();
if (context) {
context->Canonical()->UpdateMediaAction(MediaControlActions::ePause);
}
}
void TabMediaController::Stop() {
LOG("Stop");
mIsPlaying = false;
RefPtr<BrowsingContext> context = GetContext();
if (context) {
context->Canonical()->UpdateMediaAction(MediaControlActions::eStop);
}
}
void TabMediaController::Shutdown() {
mIsPlaying = false;
mControlledMediaNum = 0;
RefPtr<MediaControlService> service = MediaControlService::GetService();
if (service->GetControllerById(Id())) {
service->RemoveMediaController(this);
service->GetAudioFocusManager().RevokeAudioFocus(Id());
}
}
bool TabMediaController::IsAudible() const { return mIsPlaying && mAudible; }
void TabMediaController::NotifyMediaActiveChanged(bool aActive) {
if (aActive) {
IncreaseControlledMediaNum();
} else {
DecreaseControlledMediaNum();
}
}
void TabMediaController::NotifyMediaAudibleChanged(bool aAudible) {
mAudible = aAudible;
if (mAudible) {
RefPtr<MediaControlService> service = MediaControlService::GetService();
service->GetAudioFocusManager().RequestAudioFocus(Id());
}
}
void TabMediaController::IncreaseControlledMediaNum() {
MOZ_DIAGNOSTIC_ASSERT(mControlledMediaNum >= 0);
mControlledMediaNum++;
LOG("Increase controlled media num to %" PRId64, mControlledMediaNum);
if (mControlledMediaNum == 1) {
Activate();
}
}
void TabMediaController::DecreaseControlledMediaNum() {
MOZ_DIAGNOSTIC_ASSERT(mControlledMediaNum >= 1);
mControlledMediaNum--;
LOG("Decrease controlled media num to %" PRId64, mControlledMediaNum);
if (mControlledMediaNum == 0) {
Deactivate();
}
}
// TODO : Use watchable to moniter mControlledMediaNum
void TabMediaController::Activate() {
mIsPlaying = true;
RefPtr<MediaControlService> service = MediaControlService::GetService();
service->AddMediaController(this);
}
void TabMediaController::Deactivate() {
mIsPlaying = false;
RefPtr<MediaControlService> service = MediaControlService::GetService();
service->RemoveMediaController(this);
service->GetAudioFocusManager().RevokeAudioFocus(Id());
}
uint64_t TabMediaController::ControlledMediaNum() const {
return mControlledMediaNum;
}
} // namespace dom
} // namespace mozilla

View File

@ -1,104 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 mozilla_dom_mediacontroller_h__
#define mozilla_dom_mediacontroller_h__
#include "nsDataHashtable.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace dom {
class BrowsingContext;
enum class MediaControlActions : uint32_t {
ePlay,
ePause,
eStop,
/* do not use this, it's used to indicate the last value of enum */
eActionsNum,
};
/**
* MediaController is a class which is used to control media in the content
* process. It's a basic interface class and you should implement you own class
* to inherit this class. Every controller would correspond to a browsing
* context. For example, TabMediaController corresponds to the top level
* browsing context. In the future, we might implement MediaSessionController
* which could correspond to any browsing context, depending on which browsing
* context has active media session.
*/
class MediaController {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaController);
explicit MediaController(uint64_t aContextId)
: mBrowsingContextId(aContextId) {}
virtual void Play() = 0;
virtual void Pause() = 0;
virtual void Stop() = 0;
virtual void Shutdown() = 0;
virtual void NotifyMediaActiveChanged(bool aActive) = 0;
virtual void NotifyMediaAudibleChanged(bool aAudible) = 0;
bool IsPlaying() const { return mIsPlaying; }
uint64_t Id() const { return mBrowsingContextId; }
virtual uint64_t ControlledMediaNum() const { return 0; }
virtual bool IsAudible() const { return false; }
protected:
virtual ~MediaController() = default;
already_AddRefed<BrowsingContext> GetContext() const;
uint64_t mBrowsingContextId;
bool mIsPlaying = false;
};
/**
* TabMediaController is used to control all media in a tab. It can only be used
* in Chrome process. Everytime media starts in the tab, it would increase the
* number of controlled media, and also would decrease the number when media
* stops. The media it controls might be in different content processes, so we
* keep tracking the top level browsing context in the tab, which can be used to
* propagate conmmands to remote content processes.
*/
class TabMediaController final : public MediaController {
public:
explicit TabMediaController(uint64_t aContextId);
void Play() override;
void Pause() override;
void Stop() override;
void Shutdown() override;
uint64_t ControlledMediaNum() const override;
bool IsAudible() const override;
void NotifyMediaActiveChanged(bool aActive) override;
void NotifyMediaAudibleChanged(bool aAudible) override;
protected:
~TabMediaController();
private:
void IncreaseControlledMediaNum();
void DecreaseControlledMediaNum();
void Activate();
void Deactivate();
int64_t mControlledMediaNum = 0;
bool mAudible = false;
};
} // namespace dom
} // namespace mozilla
#endif

View File

@ -1,28 +0,0 @@
# vim: set filetype=python:
# 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/.
EXPORTS.mozilla.dom += [
'AudioFocusManager.h',
'MediaController.h',
'MediaControlService.h',
'MediaControlUtils.h',
]
EXPORTS.ipc += [
'MediaControlIPC.h',
]
UNIFIED_SOURCES += [
'AudioFocusManager.cpp',
'MediaController.cpp',
'MediaControlService.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')
if CONFIG['ENABLE_TESTS']:
DIRS += ['tests/gtest']
FINAL_LIBRARY = 'xul'

View File

@ -1,7 +0,0 @@
[DEFAULT]
support-files =
file_autoplay.html
file_muted_autoplay.html
../../test/gizmo.mp4
[browser_audio_focus_management.js]

View File

@ -1,176 +0,0 @@
/* eslint-disable no-undef */
"use strict";
const PAGE_AUDIBLE =
"https://example.com/browser/dom/media/mediacontrol/tests/file_autoplay.html";
const PAGE_INAUDIBLE =
"https://example.com/browser/dom/media/mediacontrol/tests/file_muted_autoplay.html";
/**
* These tests are used to ensure that the audio focus management works correctly
* amongs different tabs no matter the pref is on or off. If the pref is on,
* there is only one tab which is allowed to play audio at a time, the last tab
* starting audio will immediately stop other tabs which own audio focus. But
* notice that playing inaudible media won't gain audio focus. If the pref is
* off, all audible tabs can own audio focus at the same time without
* interfering each others.
*/
add_task(async function testDisableAudioFocusManagement() {
await switchAudioFocusManagerment(false);
info(`open audible autoplay media in tab1`);
const tab1 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab1);
info(`open same page on another tab, which shouldn't cause audio competing`);
const tab2 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab2);
info(`media in tab1 should be playing still`);
await checkOrWaitUntilMediaStartedPlaying(tab1);
info(`remove tabs`);
await clearTabsAndResetPref([tab1, tab2]);
});
add_task(async function testEnableAudioFocusManagement() {
await switchAudioFocusManagerment(true);
info(`open audible autoplay media in tab1`);
const tab1 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab1);
info(`open same page on another tab, which should cause audio competing`);
const tab2 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab2);
info(`media in tab1 should be stopped`);
await checkOrWaitUntilMediaStoppedPlaying(tab1);
info(`remove tabs`);
await clearTabsAndResetPref([tab1, tab2]);
});
add_task(async function testMutedMediaWontInvolveAudioCompeting() {
await switchAudioFocusManagerment(true);
info(`open audible autoplay media in tab1`);
const tab1 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab1);
info(
`open inaudible media page on another tab, which shouldn't cause audio competing`
);
const tab2 = await createTabAndLoad(PAGE_INAUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab2);
info(`media in tab1 should be playing still`);
await checkOrWaitUntilMediaStartedPlaying(tab1);
info(
`open audible media page on the third tab, which should cause audio competing`
);
const tab3 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab3);
info(`media in tab1 should be stopped`);
await checkOrWaitUntilMediaStoppedPlaying(tab1);
info(`media in tab2 should not be affected because it's inaudible.`);
await checkOrWaitUntilMediaStartedPlaying(tab2);
info(`remove tabs`);
await clearTabsAndResetPref([tab1, tab2, tab3]);
});
add_task(async function testStopMultipleTabsWhenSwitchingPrefDynamically() {
await switchAudioFocusManagerment(false);
info(`open audible autoplay media in tab1`);
const tab1 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab1);
info(`open same page on another tab, which shouldn't cause audio competing`);
const tab2 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab2);
await switchAudioFocusManagerment(true);
info(`open same page on the third tab, which should cause audio competing`);
const tab3 = await createTabAndLoad(PAGE_AUDIBLE);
await checkOrWaitUntilMediaStartedPlaying(tab3);
info(`media in tab1 and tab2 should be stopped`);
await checkOrWaitUntilMediaStoppedPlaying(tab1);
await checkOrWaitUntilMediaStoppedPlaying(tab2);
info(`remove tabs`);
await clearTabsAndResetPref([tab1, tab2, tab3]);
});
/**
* The following are helper funcions.
*/
async function switchAudioFocusManagerment(enable) {
const state = enable ? "Enable" : "Disable";
info(`${state} audio focus management`);
await SpecialPowers.pushPrefEnv({
set: [["media.audioFocus.management", enable]],
});
}
async function createTabAndLoad(url) {
let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, url);
return tab;
}
async function checkOrWaitUntilMediaStartedPlaying(tab) {
await ContentTask.spawn(tab.linkedBrowser, null, () => {
return new Promise(resolve => {
const video = content.document.getElementById("autoplay");
if (!video) {
ok(false, `can't get the media element!`);
}
if (!video.paused) {
ok(true, `media started playing`);
resolve();
} else {
info(`wait until media starts playing`);
video.onplaying = () => {
video.onplaying = null;
ok(true, `media started playing`);
resolve();
};
}
});
});
}
async function checkOrWaitUntilMediaStoppedPlaying(tab) {
await ContentTask.spawn(tab.linkedBrowser, null, () => {
return new Promise(resolve => {
const video = content.document.getElementById("autoplay");
if (!video) {
ok(false, `can't get the media element!`);
}
if (video.paused) {
ok(true, `media stopped playing`);
resolve();
} else {
info(`wait until media stops playing`);
video.onpause = () => {
video.onpause = null;
ok(true, `media stopped playing`);
resolve();
};
}
});
});
}
async function clearTabsAndResetPref(tabs) {
info(`clear tabs and reset pref`);
for (let tab of tabs) {
BrowserTestUtils.removeTab(tab);
}
await switchAudioFocusManagerment(false);
}

View File

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Autoplay page</title>
</head>
<body>
<video id="autoplay" src="gizmo.mp4" autoplay loop></video>
</body>
</html>

View File

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Muted autoplay page</title>
</head>
<body>
<video id="autoplay" src="gizmo.mp4" autoplay loop muted></video>
</body>
</html>

View File

@ -1,79 +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/. */
#include "gtest/gtest.h"
#include "AudioFocusManager.h"
#include "MediaControlService.h"
using namespace mozilla::dom;
#define FIRST_CONTROLLER_ID 0
#define SECOND_CONTROLLER_ID 1
TEST(AudioFocusManager, TestMultipleAudioFocusNums)
{
AudioFocusManager manager(nullptr);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
manager.RequestAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
manager.RequestAudioFocus(SECOND_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 2);
manager.RevokeAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
manager.RevokeAudioFocus(SECOND_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
}
TEST(AudioFocusManager, TestRequestAudioFocusRepeatedly)
{
AudioFocusManager manager(nullptr);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
manager.RequestAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
manager.RequestAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
}
TEST(AudioFocusManager, TestRevokeAudioFocusRepeatedly)
{
AudioFocusManager manager(nullptr);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
manager.RequestAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
manager.RevokeAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
manager.RevokeAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
}
TEST(AudioFocusManager, TestRevokeAudioFocusWithoutRequestAudioFocus)
{
AudioFocusManager manager(nullptr);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
manager.RevokeAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
}
TEST(AudioFocusManager,
TestRevokeAudioFocusForControllerWithoutOwningAudioFocus)
{
AudioFocusManager manager(nullptr);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);
manager.RequestAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
manager.RevokeAudioFocus(SECOND_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);
}

View File

@ -1,35 +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/. */
#include "gtest/gtest.h"
#include "MediaControlService.h"
#include "MediaController.h"
using namespace mozilla::dom;
#define FIRST_CONTROLLER_ID 0
#define SECOND_CONTROLLER_ID 1
TEST(MediaControlService, TestAddOrRemoveControllers)
{
RefPtr<MediaControlService> service = MediaControlService::GetService();
ASSERT_TRUE(service->GetControllersNum() == 0);
RefPtr<MediaController> controller1 =
new TabMediaController(FIRST_CONTROLLER_ID);
RefPtr<MediaController> controller2 =
new TabMediaController(SECOND_CONTROLLER_ID);
service->AddMediaController(controller1);
ASSERT_TRUE(service->GetControllersNum() == 1);
service->AddMediaController(controller2);
ASSERT_TRUE(service->GetControllersNum() == 2);
service->RemoveMediaController(controller1);
ASSERT_TRUE(service->GetControllersNum() == 1);
service->RemoveMediaController(controller2);
ASSERT_TRUE(service->GetControllersNum() == 0);
}

View File

@ -1,104 +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/. */
#include "gtest/gtest.h"
#include "MediaControlService.h"
#include "MediaController.h"
using namespace mozilla::dom;
#define CONTROLLER_ID 0
TEST(MediaController, DefaultValueCheck)
{
RefPtr<MediaController> controller = new TabMediaController(CONTROLLER_ID);
ASSERT_TRUE(controller->ControlledMediaNum() == 0);
ASSERT_TRUE(controller->Id() == CONTROLLER_ID);
ASSERT_TRUE(!controller->IsPlaying());
ASSERT_TRUE(!controller->IsAudible());
}
TEST(MediaController, NotifyMediaActiveChanged)
{
RefPtr<MediaController> controller = new TabMediaController(CONTROLLER_ID);
ASSERT_TRUE(controller->ControlledMediaNum() == 0);
controller->NotifyMediaActiveChanged(true);
ASSERT_TRUE(controller->ControlledMediaNum() == 1);
controller->NotifyMediaActiveChanged(true);
ASSERT_TRUE(controller->ControlledMediaNum() == 2);
controller->NotifyMediaActiveChanged(false);
ASSERT_TRUE(controller->ControlledMediaNum() == 1);
controller->NotifyMediaActiveChanged(false);
ASSERT_TRUE(controller->ControlledMediaNum() == 0);
}
TEST(MediaController, ActiveAndDeactiveController)
{
RefPtr<MediaControlService> service = MediaControlService::GetService();
ASSERT_TRUE(service->GetControllersNum() == 0);
RefPtr<MediaController> controller1 =
new TabMediaController(FIRST_CONTROLLER_ID);
controller1->NotifyMediaActiveChanged(true);
ASSERT_TRUE(service->GetControllersNum() == 1);
controller1->NotifyMediaActiveChanged(false);
ASSERT_TRUE(service->GetControllersNum() == 0);
}
TEST(MediaController, AudibleChanged)
{
RefPtr<MediaController> controller = new TabMediaController(CONTROLLER_ID);
controller->Play();
ASSERT_TRUE(!controller->IsAudible());
controller->NotifyMediaAudibleChanged(true);
ASSERT_TRUE(controller->IsAudible());
controller->NotifyMediaAudibleChanged(false);
ASSERT_TRUE(!controller->IsAudible());
}
TEST(MediaController, AlwaysInaudibleIfControllerIsNotPlaying)
{
RefPtr<MediaController> controller = new TabMediaController(CONTROLLER_ID);
ASSERT_TRUE(!controller->IsAudible());
controller->NotifyMediaAudibleChanged(true);
ASSERT_TRUE(!controller->IsAudible());
controller->Play();
ASSERT_TRUE(controller->IsAudible());
controller->Pause();
ASSERT_TRUE(!controller->IsAudible());
controller->Play();
ASSERT_TRUE(controller->IsAudible());
controller->Stop();
ASSERT_TRUE(!controller->IsAudible());
}
TEST(MediaController, playingStateChanged)
{
RefPtr<MediaController> controller = new TabMediaController(CONTROLLER_ID);
ASSERT_TRUE(!controller->IsPlaying());
controller->Play();
ASSERT_TRUE(controller->IsPlaying());
controller->Play();
controller->Pause();
ASSERT_TRUE(!controller->IsPlaying());
controller->Play();
controller->Stop();
ASSERT_TRUE(!controller->IsPlaying());
}

View File

@ -1,22 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
UNIFIED_SOURCES += [
'TestAudioFocusManager.cpp',
'TestMediaController.cpp',
'TestMediaControlService.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')
LOCAL_INCLUDES += [
'/dom/media/mediacontrol',
]
FINAL_LIBRARY = 'xul-gtest'
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
CXXFLAGS += ['-Wno-error=shadow']

View File

@ -42,7 +42,6 @@ DIRS += [
'imagecapture',
'ipc',
'mediacapabilities',
'mediacontrol',
'mediasink',
'mediasource',
'mp3',
@ -83,8 +82,6 @@ MOCHITEST_MANIFESTS += [
'tests/mochitest/identity/mochitest.ini',
]
BROWSER_CHROME_MANIFESTS += ['mediacontrol/tests/browser.ini']
if CONFIG['MOZ_WEBRTC']:
MOCHITEST_MANIFESTS += ['tests/mochitest/mochitest.ini']
WEBRTC_SIGNALLING_TEST_MANIFESTS += ['tests/mochitest/steeplechase.ini']

View File

@ -5353,11 +5353,6 @@
value: false
mirror: always
- name: media.audioFocus.management
type: bool
value: false
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "mousewheel."
#---------------------------------------------------------------------------