mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1562990 - Remove 'audioMuted' and 'audioVolume' properties from nsIDOMWindowUtils. r=NeilDeakin,alwu,farre
While working on porting the (audio-playback indicators) bug 1562990 to fission, we saw the potential to delete some methods in nsIDOMWindowUtils because they were not used anymore in our codebase except in a couple of tests files. So now, we should only mute/unmute or change the volume in the parent process. As such, interfaces are added in SpecialPowers to change media muted or volume state from content processes. Differential Revision: https://phabricator.services.mozilla.com/D41782 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
5ce82c5c12
commit
55e51c578b
@ -3684,41 +3684,6 @@ nsDOMWindowUtils::SetMediaSuspend(uint32_t aSuspend) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetAudioMuted(bool* aMuted) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(window);
|
||||
|
||||
*aMuted = window->GetAudioMuted();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SetAudioMuted(bool aMuted) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(window);
|
||||
|
||||
window->SetAudioMuted(aMuted);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetAudioVolume(float* aVolume) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(window);
|
||||
|
||||
*aVolume = window->GetAudioVolume();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SetAudioVolume(float aVolume) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(window);
|
||||
|
||||
return window->SetAudioVolume(aVolume);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SetChromeMargin(int32_t aTop, int32_t aRight, int32_t aBottom,
|
||||
int32_t aLeft) {
|
||||
|
@ -12,8 +12,6 @@ function pluginMuted() {
|
||||
return plugin.audioMuted();
|
||||
}
|
||||
function toggleMuteState(muted) {
|
||||
var Ci = SpecialPowers.Ci;
|
||||
var utils = SpecialPowers.getDOMWindowUtils(window.top);
|
||||
utils.audioMuted = muted;
|
||||
return SpecialPowers.toggleMuteState(muted, window.top);
|
||||
}
|
||||
</script>
|
||||
|
@ -16,8 +16,6 @@ function pluginMuted() {
|
||||
}
|
||||
|
||||
function toggleMuteState(muted) {
|
||||
var Ci = SpecialPowers.Ci;
|
||||
var utils = SpecialPowers.getDOMWindowUtils(window.top);
|
||||
utils.audioMuted = muted;
|
||||
return SpecialPowers.toggleMuteState(muted, window.top);
|
||||
}
|
||||
</script>
|
||||
|
@ -260,7 +260,6 @@ skip-if = headless # Bug 1405867
|
||||
[test_appname_override.html]
|
||||
[test_async_setTimeout_stack.html]
|
||||
[test_async_setTimeout_stack_across_globals.html]
|
||||
[test_audioWindowUtils.html]
|
||||
[test_audioNotification.html]
|
||||
tags = audiochannel
|
||||
skip-if = (os == "win" && processor == "aarch64") # bug 1535775
|
||||
|
@ -1,101 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for audio controller in windows</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="about:blank" id="iframe"></iframe>
|
||||
<script type="application/javascript">
|
||||
|
||||
function runTest() {
|
||||
var utils = SpecialPowers.getDOMWindowUtils(window);
|
||||
ok(utils, "nsIDOMWindowUtils");
|
||||
|
||||
is(utils.audioMuted, false, "By default utils.audioMuted is false");
|
||||
utils.audioMuted = true;
|
||||
is(utils.audioMuted, true, "utils.audioMuted is true");
|
||||
utils.audioMuted = false;
|
||||
is(utils.audioMuted, false, "utils.audioMuted is true");
|
||||
|
||||
is(utils.audioVolume, 1.0, "By default utils.audioVolume is 1.0");
|
||||
utils.audioVolume = 0.4;
|
||||
is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
|
||||
utils.audioMuted = true;
|
||||
is(utils.audioMuted, true, "utils.audioMuted is true");
|
||||
is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
|
||||
utils.audioMuted = false;
|
||||
|
||||
utils.audioVolume = 2.0;
|
||||
is(utils.audioVolume, 2.0, "utils.audioVolume is ok");
|
||||
|
||||
try {
|
||||
utils.audioVolume = -42;
|
||||
ok(false, "This should throw");
|
||||
} catch(e) {
|
||||
ok(true, "This should throw");
|
||||
}
|
||||
|
||||
utils.audioVolume = 0;
|
||||
is(utils.audioVolume, 0.0, "utils.audioVolume is ok");
|
||||
utils.audioVolume = 1.0;
|
||||
is(utils.audioVolume, 1.0, "utils.audioVolume is ok");
|
||||
|
||||
var iframe = document.getElementById("iframe");
|
||||
ok(iframe, "IFrame exists");
|
||||
|
||||
utils = SpecialPowers.getDOMWindowUtils(iframe.contentWindow);
|
||||
ok(utils, "nsIDOMWindowUtils");
|
||||
|
||||
is(utils.audioMuted, false, "By default utils.audioMuted is false");
|
||||
utils.audioMuted = true;
|
||||
is(utils.audioMuted, true, "utils.audioMuted is true");
|
||||
utils.audioMuted = false;
|
||||
is(utils.audioMuted, false, "utils.audioMuted is true");
|
||||
|
||||
is(utils.audioVolume, 1.0, "By default utils.audioVolume is 1.0");
|
||||
utils.audioVolume = 0.4;
|
||||
is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
|
||||
utils.audioMuted = true;
|
||||
is(utils.audioMuted, true, "utils.audioMuted is true");
|
||||
is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
|
||||
utils.audioMuted = false;
|
||||
|
||||
utils.audioVolume = 2.0;
|
||||
is(utils.audioVolume, 2.0, "utils.audioVolume is ok");
|
||||
|
||||
try {
|
||||
utils.audioVolume = -42;
|
||||
ok(false, "This should throw");
|
||||
} catch(e) {
|
||||
ok(true, "This should throw");
|
||||
}
|
||||
|
||||
utils.audioVolume = 0;
|
||||
is(utils.audioVolume, 0.0, "utils.audioVolume is ok");
|
||||
utils.audioVolume = 0.6;
|
||||
is(utils.audioVolume.toFixed(2), "0.60", "utils.audioVolume is ok");
|
||||
utils.audioMuted = true;
|
||||
|
||||
// Navigate the iframe to another URL, and verify that the volume and muted
|
||||
// information is preserved.
|
||||
iframe.onload = function() {
|
||||
utils = SpecialPowers.getDOMWindowUtils(iframe.contentWindow);
|
||||
ok(utils, "nsIDOMWindowUtils");
|
||||
|
||||
ok(utils.audioMuted, "Audio should still be muted");
|
||||
utils.audioMuted = false;
|
||||
is(utils.audioVolume.toFixed(2), "0.60", "Volume should be preserved");
|
||||
|
||||
SimpleTest.finish();
|
||||
};
|
||||
iframe.src = "data:text/html,page";
|
||||
}
|
||||
|
||||
onload = runTest;
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -15,70 +15,60 @@
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var expectedNotification = null;
|
||||
var iframe = null;
|
||||
|
||||
var observer = {
|
||||
observe: function(subject, topic, data) {
|
||||
is(topic, "audio-playback", "audio-playback received");
|
||||
is(data, expectedNotification, "This is the right notification");
|
||||
SimpleTest.executeSoon(runTest);
|
||||
}
|
||||
};
|
||||
function waitForObserver(expectedNotification) {
|
||||
return new Promise(resolve => {
|
||||
let observe = function(subject, topic, data) {
|
||||
is(topic, "audio-playback", "audio-playback received");
|
||||
is(data, expectedNotification, `${expectedNotification} is the right notification`);
|
||||
SpecialPowers.removeObserver(observe, "audio-playback");
|
||||
resolve();
|
||||
}
|
||||
|
||||
var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIObserverService);
|
||||
SpecialPowers.addObserver(observe, "audio-playback");
|
||||
});
|
||||
}
|
||||
|
||||
var tests = [
|
||||
function() {
|
||||
async function() {
|
||||
iframe = document.querySelector("iframe");
|
||||
observerService.addObserver(observer, "audio-playback");
|
||||
ok(true, "Observer set");
|
||||
runTest();
|
||||
},
|
||||
|
||||
function() {
|
||||
expectedNotification = 'active';
|
||||
let observerPromise = waitForObserver('active');
|
||||
iframe.src = "file_pluginAudio.html";
|
||||
await observerPromise;
|
||||
},
|
||||
|
||||
function() {
|
||||
async function() {
|
||||
info("=== Mute plugin ===");
|
||||
ok(!iframe.contentWindow.pluginMuted(), "Plugin should not be muted");
|
||||
let observerPromise = waitForObserver('inactive-nonaudible');
|
||||
iframe.contentWindow.toggleMuteState(true);
|
||||
await observerPromise;
|
||||
ok(iframe.contentWindow.pluginMuted(), "Plugin should be muted");
|
||||
expectedNotification = 'inactive-nonaudible';
|
||||
},
|
||||
|
||||
function() {
|
||||
async function() {
|
||||
info("=== unmute plugin ==");
|
||||
ok(iframe.contentWindow.pluginMuted(), "Plugin should be muted");
|
||||
let observerPromise = waitForObserver('active');
|
||||
iframe.contentWindow.toggleMuteState(false);
|
||||
await observerPromise;
|
||||
ok(!iframe.contentWindow.pluginMuted(), "Plugin should not be muted");
|
||||
expectedNotification = 'active';
|
||||
},
|
||||
|
||||
function() {
|
||||
async function() {
|
||||
info("=== stop audio ==");
|
||||
expectedNotification = 'inactive-pause';
|
||||
let observerPromise = waitForObserver('inactive-pause');
|
||||
iframe.contentWindow.stopAudio();
|
||||
await observerPromise;
|
||||
},
|
||||
|
||||
function() {
|
||||
observerService.removeObserver(observer, "audio-playback");
|
||||
ok(true, "Observer removed");
|
||||
runTest();
|
||||
}
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
if (!tests.length) {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
async function runTest() {
|
||||
for (let test of tests) {
|
||||
await test();
|
||||
}
|
||||
|
||||
var test = tests.shift();
|
||||
test();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
onload = runTest;
|
||||
@ -86,4 +76,3 @@ onload = runTest;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -19,9 +19,9 @@ function runTest() {
|
||||
var iframe = document.querySelector("iframe");
|
||||
iframe.src = "file_pluginAudioNonAutoStart.html";
|
||||
|
||||
function muteBeforePlay() {
|
||||
async function muteBeforePlay() {
|
||||
ok(!iframe.contentWindow.pluginMuted(), "Plugin should not be muted");
|
||||
iframe.contentWindow.toggleMuteState(true);
|
||||
await iframe.contentWindow.toggleMuteState(true);
|
||||
|
||||
iframe.contentWindow.startAudio();
|
||||
ok(iframe.contentWindow.pluginMuted(), "Plugin should still be muted after playing");
|
||||
@ -29,13 +29,13 @@ function runTest() {
|
||||
iframe.contentWindow.stopAudio();
|
||||
|
||||
// Reset the window's mute state, avoid to interrupt other tests.
|
||||
iframe.contentWindow.toggleMuteState(false);
|
||||
await iframe.contentWindow.toggleMuteState(false);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
iframe.onload = function() {
|
||||
iframe.onload = async function() {
|
||||
ok(true, "Already load iframe.");
|
||||
muteBeforePlay();
|
||||
await muteBeforePlay();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1752,19 +1752,6 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
*/
|
||||
attribute uint32_t mediaSuspend;
|
||||
|
||||
/**
|
||||
* With this it's possible to mute all the MediaElements in this window.
|
||||
* We have audioMuted and audioVolume to preserve the volume across
|
||||
* mute/umute.
|
||||
*/
|
||||
attribute boolean audioMuted;
|
||||
|
||||
/**
|
||||
* range: greater or equal to 0. The real volume level is affected by the
|
||||
* volume of all ancestor windows.
|
||||
*/
|
||||
attribute float audioVolume;
|
||||
|
||||
/**
|
||||
* This method doesn't do anything useful. It was solely added for the
|
||||
* purpose of the test for bug 503926.
|
||||
|
@ -489,6 +489,13 @@ class SpecialPowersAPI extends JSWindowActorChild {
|
||||
return bindDOMWindowUtils(aWindow);
|
||||
}
|
||||
|
||||
async toggleMuteState(aMuted, aWindow) {
|
||||
let actor = aWindow
|
||||
? aWindow.getWindowGlobalChild().getActor("SpecialPowers")
|
||||
: this;
|
||||
return actor.sendQuery("SPToggleMuteAudio", { mute: aMuted });
|
||||
}
|
||||
|
||||
/*
|
||||
* A method to get a DOMParser that can't parse XUL.
|
||||
*/
|
||||
|
@ -449,6 +449,15 @@ class SpecialPowersAPIParent extends JSWindowActorParent {
|
||||
throw new Error(`Unexpected preference type: ${type}`);
|
||||
}
|
||||
|
||||
_toggleMuteAudio(aMuted) {
|
||||
let browser = this.browsingContext.top.embedderElement;
|
||||
if (aMuted) {
|
||||
browser.mute();
|
||||
} else {
|
||||
browser.unmute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* messageManager callback function
|
||||
* This will get requests from our API in the window and process them in chrome for it
|
||||
@ -459,6 +468,8 @@ class SpecialPowersAPIParent extends JSWindowActorParent {
|
||||
// doesn't trigger a flurry of warnings about "does not always return
|
||||
// a value".
|
||||
switch (aMessage.name) {
|
||||
case "SPToggleMuteAudio":
|
||||
return this._toggleMuteAudio(aMessage.data.mute);
|
||||
case "PushPrefEnv":
|
||||
return this.pushPrefEnv(aMessage.data);
|
||||
|
||||
|
@ -23,12 +23,6 @@ class AudioPlaybackChild extends JSWindowActorChild {
|
||||
|
||||
let suspendTypes = Ci.nsISuspendedTypes;
|
||||
switch (msg) {
|
||||
case "mute":
|
||||
utils.audioMuted = true;
|
||||
break;
|
||||
case "unmute":
|
||||
utils.audioMuted = false;
|
||||
break;
|
||||
case "lostAudioFocus":
|
||||
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user