mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1470856 - Add AudioWorklet definition. r=baku,karlt
MozReview-Commit-ID: 39eqjisGNTE --HG-- extra : rebase_source : 97c18e1125c490f3e9aa3b9d5c864f99da6fd265
This commit is contained in:
parent
bd000427cf
commit
e89bd4b6e5
@ -94,6 +94,10 @@ DOMInterfaces = {
|
||||
},
|
||||
},
|
||||
|
||||
'AudioWorklet': {
|
||||
'nativeType': 'mozilla::dom::Worklet',
|
||||
},
|
||||
|
||||
'BarProp': {
|
||||
'headerFile': 'mozilla/dom/BarProps.h',
|
||||
},
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/StereoPannerNodeBinding.h"
|
||||
#include "mozilla/dom/WaveShaperNodeBinding.h"
|
||||
#include "mozilla/dom/Worklet.h"
|
||||
|
||||
#include "AudioBuffer.h"
|
||||
#include "AudioBufferSourceNode.h"
|
||||
@ -60,6 +61,7 @@
|
||||
#include "MediaStreamAudioSourceNode.h"
|
||||
#include "MediaStreamGraph.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGlobalWindowInner.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
@ -537,6 +539,28 @@ AudioContext::Listener()
|
||||
return mListener;
|
||||
}
|
||||
|
||||
Worklet*
|
||||
AudioContext::GetAudioWorklet(ErrorResult& aRv)
|
||||
{
|
||||
if (!mWorklet) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (NS_WARN_IF(!window)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
nsGlobalWindowInner::Cast(window)->GetPrincipal();
|
||||
if (NS_WARN_IF(!principal)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mWorklet = new Worklet(window, principal, Worklet::eAudioWorklet);
|
||||
}
|
||||
|
||||
return mWorklet;
|
||||
}
|
||||
|
||||
bool
|
||||
AudioContext::IsRunning() const
|
||||
{
|
||||
|
@ -70,6 +70,7 @@ class PannerNode;
|
||||
class ScriptProcessorNode;
|
||||
class StereoPannerNode;
|
||||
class WaveShaperNode;
|
||||
class Worklet;
|
||||
class PeriodicWave;
|
||||
struct PeriodicWaveConstraints;
|
||||
class Promise;
|
||||
@ -192,6 +193,9 @@ public:
|
||||
AudioListener* Listener();
|
||||
|
||||
AudioContextState State() const { return mAudioContextState; }
|
||||
|
||||
Worklet* GetAudioWorklet(ErrorResult& aRv);
|
||||
|
||||
bool IsRunning() const;
|
||||
|
||||
// Those three methods return a promise to content, that is resolved when an
|
||||
@ -352,6 +356,7 @@ private:
|
||||
AudioContextState mAudioContextState;
|
||||
RefPtr<AudioDestinationNode> mDestination;
|
||||
RefPtr<AudioListener> mListener;
|
||||
RefPtr<Worklet> mWorklet;
|
||||
nsTArray<UniquePtr<WebAudioDecodeJob> > mDecodeJobs;
|
||||
// This array is used to keep the suspend/close promises alive until
|
||||
// they are resolved, so we can safely pass them accross threads.
|
||||
|
15
dom/webidl/AudioWorklet.webidl
Normal file
15
dom/webidl/AudioWorklet.webidl
Normal file
@ -0,0 +1,15 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/
|
||||
*
|
||||
* Copyright © 2018 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
[Exposed=Window, SecureContext, Pref="dom.audioworklet.enabled"]
|
||||
interface AudioWorklet : Worklet {
|
||||
};
|
@ -25,6 +25,8 @@ interface BaseAudioContext : EventTarget {
|
||||
readonly attribute double currentTime;
|
||||
readonly attribute AudioListener listener;
|
||||
readonly attribute AudioContextState state;
|
||||
[Throws, SameObject, SecureContext, Pref="dom.audioworklet.enabled"]
|
||||
readonly attribute AudioWorklet audioWorklet;
|
||||
// Bug 1324552: readonly attribute double baseLatency;
|
||||
|
||||
[Throws]
|
||||
|
@ -384,6 +384,7 @@ WEBIDL_FILES = [
|
||||
'AudioStreamTrack.webidl',
|
||||
'AudioTrack.webidl',
|
||||
'AudioTrackList.webidl',
|
||||
'AudioWorklet.webidl',
|
||||
'AudioWorkletGlobalScope.webidl',
|
||||
'AudioWorkletNode.webidl',
|
||||
'AudioWorkletProcessor.webidl',
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "PaintWorkletGlobalScope.h"
|
||||
|
||||
#include "mozilla/dom/WorkletBinding.h"
|
||||
#include "mozilla/dom/AudioWorkletBinding.h"
|
||||
#include "mozilla/dom/BlobBinding.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/Fetch.h"
|
||||
@ -508,7 +509,11 @@ JSObject*
|
||||
Worklet::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return Worklet_Binding::Wrap(aCx, this, aGivenProto);
|
||||
if (mWorkletType == eAudioWorklet) {
|
||||
return AudioWorklet_Binding::Wrap(aCx, this, aGivenProto);
|
||||
} else {
|
||||
return Worklet_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
|
@ -11,8 +11,10 @@ skip-if = verify
|
||||
support-files=server_import_with_cache.sjs
|
||||
[test_dump.html]
|
||||
support-files=worklet_dump.js
|
||||
[test_audioWorklet_insecureContext.html]
|
||||
[test_audioWorklet.html]
|
||||
support-files=worklet_audioWorklet.js
|
||||
scheme = https
|
||||
[test_exception.html]
|
||||
support-files=worklet_exception.js
|
||||
[test_paintWorklet.html]
|
||||
|
@ -33,13 +33,17 @@ function configureTest() {
|
||||
var cl = new consoleListener();
|
||||
|
||||
return SpecialPowers.pushPrefEnv(
|
||||
{"set": [["dom.audioWorklet.enabled", true],
|
||||
{"set": [["dom.audioworklet.enabled", true],
|
||||
["dom.worklet.enabled", true]]});
|
||||
}
|
||||
|
||||
// This function is called into an iframe.
|
||||
function runTestInIframe() {
|
||||
audioWorklet.import("worklet_audioWorklet.js")
|
||||
ok(window.isSecureContext, "Test should run in secure context");
|
||||
var audioContext = new AudioContext();
|
||||
ok(audioContext.audioWorklet instanceof AudioWorklet,
|
||||
"AudioContext.audioWorklet should be an instance of AudioWorklet");
|
||||
audioContext.audioWorklet.import("worklet_audioWorklet.js")
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
29
dom/worklet/tests/test_audioWorklet_insecureContext.html
Normal file
29
dom/worklet/tests/test_audioWorklet_insecureContext.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for No AudioWorklet in insecure context</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript" src="common.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript">
|
||||
|
||||
function configureTest() {
|
||||
return SpecialPowers.pushPrefEnv(
|
||||
{"set": [["dom.audioworklet.enabled", true],
|
||||
["dom.worklet.enabled", true]]});
|
||||
}
|
||||
|
||||
// This function is called into an iframe.
|
||||
function runTestInIframe() {
|
||||
ok(!window.isSecureContext, "Test should run in an insecure context");
|
||||
var audioContext = new AudioContext();
|
||||
ok(!("audioWorklet" in audioContext),
|
||||
"AudioWorklet shouldn't be defined in AudioContext in a insecure context");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user