Bug 1470856 - Add AudioWorklet definition. r=baku,karlt

MozReview-Commit-ID: 39eqjisGNTE

--HG--
extra : rebase_source : 97c18e1125c490f3e9aa3b9d5c864f99da6fd265
This commit is contained in:
Arnaud Bienner 2018-06-27 11:31:02 +02:00
Родитель bd000427cf
Коммит e89bd4b6e5
10 изменённых файлов: 94 добавлений и 3 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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,8 +509,12 @@ JSObject*
Worklet::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
MOZ_ASSERT(NS_IsMainThread());
if (mWorkletType == eAudioWorklet) {
return AudioWorklet_Binding::Wrap(aCx, this, aGivenProto);
} else {
return Worklet_Binding::Wrap(aCx, this, aGivenProto);
}
}
already_AddRefed<Promise>
Worklet::Import(const nsAString& aModuleURL, CallerType aCallerType,

Просмотреть файл

@ -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>

Просмотреть файл

@ -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>