зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1375119 - Consider a page active if it has running AudioContexts. r=ehsan
MozReview-Commit-ID: IOQ2DY9LoTw --HG-- extra : rebase_source : f47568d3db129ff8d9a484d5b5554f1154d53133
This commit is contained in:
Родитель
dc60e7a8cf
Коммит
b9e645073e
|
@ -4425,6 +4425,11 @@ nsPIDOMWindowInner::SyncStateFromParentWindow()
|
||||||
bool
|
bool
|
||||||
nsPIDOMWindowInner::IsPlayingAudio()
|
nsPIDOMWindowInner::IsPlayingAudio()
|
||||||
{
|
{
|
||||||
|
for (uint32_t i = 0; i < mAudioContexts.Length(); i++) {
|
||||||
|
if (mAudioContexts[i]->IsRunning()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
RefPtr<AudioChannelService> acs = AudioChannelService::Get();
|
RefPtr<AudioChannelService> acs = AudioChannelService::Get();
|
||||||
if (!acs) {
|
if (!acs) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -22,6 +22,7 @@ support-files =
|
||||||
file_use_counter_svg_fill_pattern_internal.svg
|
file_use_counter_svg_fill_pattern_internal.svg
|
||||||
file_use_counter_svg_fill_pattern_data.svg
|
file_use_counter_svg_fill_pattern_data.svg
|
||||||
file_webaudioLoop.html
|
file_webaudioLoop.html
|
||||||
|
file_webaudio_startstop.html
|
||||||
plugin.js
|
plugin.js
|
||||||
!/image/test/mochitest/shaver.png
|
!/image/test/mochitest/shaver.png
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ var testURLs = [
|
||||||
"http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html",
|
"http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html",
|
||||||
"http://mochi.test:8888/browser/dom/base/test/file_audioLoopInIframe.html",
|
"http://mochi.test:8888/browser/dom/base/test/file_audioLoopInIframe.html",
|
||||||
"http://mochi.test:8888/browser/dom/base/test/file_pluginAudio.html",
|
"http://mochi.test:8888/browser/dom/base/test/file_pluginAudio.html",
|
||||||
"http://mochi.test:8888/browser/dom/base/test/file_webaudioLoop.html",
|
"http://mochi.test:8888/browser/dom/base/test/file_webaudio_startstop.html",
|
||||||
];
|
];
|
||||||
|
|
||||||
// We want to ensure that while audio is being played back, a background tab is
|
// We want to ensure that while audio is being played back, a background tab is
|
||||||
|
|
|
@ -8,19 +8,10 @@ var runningPromise = new Promise(resolve => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
fetch("audio.ogg").then(response => {
|
|
||||||
return response.arrayBuffer();
|
var osc = ac.createOscillator();
|
||||||
}).then(ab => {
|
osc.connect(ac.destination);
|
||||||
return ac.decodeAudioData(ab);
|
osc.start(0);
|
||||||
}).then(ab => {
|
|
||||||
var src = ac.createBufferSource();
|
|
||||||
src.buffer = ab;
|
|
||||||
src.loop = true;
|
|
||||||
src.loopStart = 0;
|
|
||||||
src.loopEnd = ab.duration;
|
|
||||||
src.start();
|
|
||||||
src.connect(ac.destination);
|
|
||||||
});
|
|
||||||
|
|
||||||
var suspendPromise;
|
var suspendPromise;
|
||||||
function suspendAC() {
|
function suspendAC() {
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script>
|
||||||
|
var ac = new AudioContext();
|
||||||
|
var runningPromise = new Promise(resolve => {
|
||||||
|
ac.onstatechange = event => {
|
||||||
|
if (ac.state == "running") {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
var osc = ac.createOscillator();
|
||||||
|
osc.connect(ac.destination);
|
||||||
|
osc.start(0);
|
||||||
|
osc.stop(osc.context.currentTime + 2.0);
|
||||||
|
|
||||||
|
var suspendPromise;
|
||||||
|
function suspendAC() {
|
||||||
|
runningPromise.then(() => {
|
||||||
|
suspendPromise = ac.suspend();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var resumePromise;
|
||||||
|
function resumeAC() {
|
||||||
|
suspendPromise.then(() => {
|
||||||
|
resumePromise = ac.resume();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeAC() {
|
||||||
|
resumePromise.then(() => {
|
||||||
|
ac.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -210,6 +210,7 @@ support-files =
|
||||||
file_audioLoop.html
|
file_audioLoop.html
|
||||||
file_webaudioLoop.html
|
file_webaudioLoop.html
|
||||||
file_webaudioLoop2.html
|
file_webaudioLoop2.html
|
||||||
|
file_webaudio_startstop.html
|
||||||
file_pluginAudio.html
|
file_pluginAudio.html
|
||||||
file_pluginAudioNonAutoStart.html
|
file_pluginAudioNonAutoStart.html
|
||||||
noaudio.webm
|
noaudio.webm
|
||||||
|
|
|
@ -492,6 +492,12 @@ AudioContext::Listener()
|
||||||
return mListener;
|
return mListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
AudioContext::IsRunning() const
|
||||||
|
{
|
||||||
|
return mAudioContextState == AudioContextState::Running;
|
||||||
|
}
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
AudioContext::DecodeAudioData(const ArrayBuffer& aBuffer,
|
AudioContext::DecodeAudioData(const ArrayBuffer& aBuffer,
|
||||||
const Optional<OwningNonNull<DecodeSuccessCallback> >& aSuccessCallback,
|
const Optional<OwningNonNull<DecodeSuccessCallback> >& aSuccessCallback,
|
||||||
|
|
|
@ -181,6 +181,7 @@ public:
|
||||||
AudioListener* Listener();
|
AudioListener* Listener();
|
||||||
|
|
||||||
AudioContextState State() const { return mAudioContextState; }
|
AudioContextState State() const { return mAudioContextState; }
|
||||||
|
bool IsRunning() const;
|
||||||
|
|
||||||
// Those three methods return a promise to content, that is resolved when an
|
// Those three methods return a promise to content, that is resolved when an
|
||||||
// (possibly long) operation is completed on the MSG (and possibly other)
|
// (possibly long) operation is completed on the MSG (and possibly other)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче