Bug 1565689 - part5 : control media from chrome process. r=farre,baku

This patch implements how to use MediaController to control corresponding media in content processes.

Differential Revision: https://phabricator.services.mozilla.com/D38145

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-08-06 01:13:07 +00:00
parent 519f56c448
commit f8f21d9082
11 changed files with 117 additions and 0 deletions

View File

@ -209,6 +209,16 @@ 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,6 +8,7 @@
#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"
@ -78,6 +79,10 @@ 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

@ -30,6 +30,8 @@
#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"
@ -270,6 +272,12 @@ 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) { \
@ -2876,6 +2884,26 @@ 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,6 +70,7 @@ class TimeoutManager;
class WindowGlobalChild;
class CustomElementRegistry;
enum class CallerType : uint32_t;
enum class MediaControlActions : uint32_t;
} // namespace dom
} // namespace mozilla
@ -756,6 +757,8 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
void MaybeActiveMediaComponents();
void UpdateMediaAction(const mozilla::dom::MediaControlActions aAction);
void SetServiceWorkersTestingEnabled(bool aEnabled);
bool GetServiceWorkersTestingEnabled();

View File

@ -228,6 +228,7 @@
#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"
@ -3750,6 +3751,16 @@ 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

@ -74,6 +74,7 @@ class ClonedMessageData;
class BrowserChild;
class GetFilesHelperChild;
class TabContext;
enum class MediaControlActions : uint32_t;
class ContentChild final : public PContentChild,
public nsIWindowProvider,
@ -693,6 +694,9 @@ 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

@ -105,6 +105,7 @@ 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
{
@ -809,6 +810,12 @@ 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);

View File

@ -0,0 +1,24 @@
/* -*- 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

@ -8,6 +8,7 @@
#include "MediaControlService.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
extern mozilla::LazyLogModule gMediaControlLog;
@ -40,16 +41,28 @@ TabMediaController::~TabMediaController() {
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() {

View File

@ -15,6 +15,14 @@ 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

View File

@ -10,6 +10,10 @@ EXPORTS.mozilla.dom += [
'MediaControlUtils.h',
]
EXPORTS.ipc += [
'MediaControlIPC.h',
]
UNIFIED_SOURCES += [
'AudioFocusManager.cpp',
'MediaController.cpp',