Bug 1553328 - use browsing context to notify tab mute/unmute media. r=baku,farre

This bug will use the browsing context to notify content tab to mute/unmute media, instead of using MessageManager. We would use the top level canonical browsing context to
set the media mute property for the top level window and propagate it to other top level windows in other processes.

If we don't do so, we're not able to mute/unmute media in the different process when we we enable Fission, because the current way we use can only notify one process and would cause the media on other process can't be muted/unmuted.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alastor Wu 2019-05-22 12:19:49 +00:00
parent 31f6daf51c
commit d6b68d2693
8 changed files with 39 additions and 2 deletions

View File

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

View File

@ -73,6 +73,11 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// autoplay media.
void NotifyStartDelayedAutoplayMedia();
// This function is used to mute or unmute all media within a tab. It would
// set the media mute property for the top level window and propagate it to
// other top level windows in other processes.
void NotifyMediaMutedChanged(bool aMuted);
// 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

@ -2886,6 +2886,9 @@ void nsPIDOMWindowOuter::SetAudioMuted(bool aMuted) {
return;
}
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("nsPIDOMWindowOuter %p, SetAudioMuted=%s", this,
aMuted ? "muted" : "unmuted"));
mAudioMuted = aMuted;
RefreshMediaElementsVolume();
}

View File

@ -46,6 +46,7 @@ interface CanonicalBrowsingContext : BrowsingContext {
readonly attribute WindowGlobalParent? embedderWindowGlobal;
void notifyStartDelayedAutoplayMedia();
void notifyMediaMutedChanged(boolean muted);
};
[Exposed=Window, ChromeOnly]

View File

@ -3627,6 +3627,16 @@ mozilla::ipc::IPCResult ContentChild::RecvStartDelayedAutoplayMediaComponents(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvSetMediaMuted(
BrowsingContext* aContext, bool aMuted) {
MOZ_ASSERT(aContext);
nsCOMPtr<nsPIDOMWindowOuter> window = aContext->GetDOMWindow();
if (window) {
window->SetAudioMuted(aMuted);
}
return IPC_OK();
}
already_AddRefed<nsIEventTarget> ContentChild::GetSpecificMessageEventTarget(
const Message& aMsg) {
switch (aMsg.type()) {

View File

@ -674,6 +674,9 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvStartDelayedAutoplayMediaComponents(
BrowsingContext* aContext);
mozilla::ipc::IPCResult RecvSetMediaMuted(BrowsingContext* aContext,
bool aMuted);
void HoldBrowsingContextGroup(BrowsingContextGroup* aBCG);
#ifdef NIGHTLY_BUILD

View File

@ -800,6 +800,11 @@ child:
*/
async StartDelayedAutoplayMediaComponents(BrowsingContext aContext);
/**
* This method is used to notifty content process to mute or unmute media.
*/
async SetMediaMuted(BrowsingContext aContext, bool aMuted);
// Begin subscribing to a new BrowsingContextGroup, sending down the current
// value for every individual BrowsingContext.
async RegisterBrowsingContextGroup(BrowsingContextInitializer[] aInits);

View File

@ -979,12 +979,12 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) {
if (!transientState) {
this._audioMuted = true;
}
this.messageManager.sendAsyncMessage("AudioPlayback", { type: "mute" });
this.frameLoader.browsingContext.notifyMediaMutedChanged(true);
}
unmute() {
this._audioMuted = false;
this.messageManager.sendAsyncMessage("AudioPlayback", { type: "unmute" });
this.frameLoader.browsingContext.notifyMediaMutedChanged(false);
}
pauseMedia(disposable) {