Bug 1466182 - Add AudioWorkletProcessor definitions. r=baku,karlt
authorArnaud Bienner <arnaud.bienner@gmail.com>
Sun, 24 Jun 2018 20:02:47 +0200
changeset 424465 fb53c31538e73ebf5003eb6461cdbfdd5f2dcba0
parent 424464 23b5f0e1a106a7bb9cbafe3391540ae1373edc65
child 424466 74e0bf980eae79f08d96fabd018d0fb0a0b149bd
push id34210
push userapavel@mozilla.com
push dateSat, 30 Jun 2018 09:48:57 +0000
treeherdermozilla-central@c0cd065ee5c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, karlt
bugs1466182
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466182 - Add AudioWorkletProcessor definitions. r=baku,karlt MozReview-Commit-ID: 1KKrUqRY2qf
dom/bindings/BindingUtils.cpp
dom/bindings/DOMJSClass.h
dom/media/webaudio/AudioWorkletProcessor.cpp
dom/media/webaudio/AudioWorkletProcessor.h
dom/media/webaudio/moz.build
dom/webidl/AudioWorkletProcessor.webidl
dom/webidl/EventTarget.webidl
dom/webidl/MessagePort.webidl
dom/webidl/moz.build
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -2943,17 +2943,18 @@ IsNonExposedGlobal(JSContext* aCx, JSObj
   MOZ_ASSERT(aNonExposedGlobals, "Why did we get called?");
   MOZ_ASSERT((aNonExposedGlobals &
               ~(GlobalNames::Window |
                 GlobalNames::BackstagePass |
                 GlobalNames::DedicatedWorkerGlobalScope |
                 GlobalNames::SharedWorkerGlobalScope |
                 GlobalNames::ServiceWorkerGlobalScope |
                 GlobalNames::WorkerDebuggerGlobalScope |
-                GlobalNames::WorkletGlobalScope)) == 0,
+                GlobalNames::WorkletGlobalScope |
+                GlobalNames::AudioWorkletGlobalScope)) == 0,
              "Unknown non-exposed global type");
 
   const char* name = js::GetObjectClass(aGlobal)->name;
 
   if ((aNonExposedGlobals & GlobalNames::Window) &&
       !strcmp(name, "Window")) {
     return true;
   }
@@ -2983,16 +2984,21 @@ IsNonExposedGlobal(JSContext* aCx, JSObj
     return true;
   }
 
   if ((aNonExposedGlobals & GlobalNames::WorkletGlobalScope) &&
       !strcmp(name, "WorkletGlobalScope")) {
     return true;
   }
 
+  if ((aNonExposedGlobals & GlobalNames::AudioWorkletGlobalScope) &&
+      !strcmp(name, "AudioWorkletGlobalScope")) {
+    return true;
+  }
+
   return false;
 }
 
 namespace binding_detail {
 
 /**
  * A ThisPolicy struct needs to provide the following methods:
  *
--- a/dom/bindings/DOMJSClass.h
+++ b/dom/bindings/DOMJSClass.h
@@ -101,16 +101,17 @@ namespace GlobalNames {
 // annotations.
 static const uint32_t Window = 1u << 0;
 static const uint32_t BackstagePass = 1u << 1;
 static const uint32_t DedicatedWorkerGlobalScope = 1u << 2;
 static const uint32_t SharedWorkerGlobalScope = 1u << 3;
 static const uint32_t ServiceWorkerGlobalScope = 1u << 4;
 static const uint32_t WorkerDebuggerGlobalScope = 1u << 5;
 static const uint32_t WorkletGlobalScope = 1u << 6;
+static const uint32_t AudioWorkletGlobalScope = 1u << 7;
 } // namespace GlobalNames
 
 struct PrefableDisablers {
   inline bool isEnabled(JSContext* cx, JS::Handle<JSObject*> obj) const {
     // Reading "enabled" on a worker thread is technically undefined behavior,
     // because it's written only on main threads, with no barriers of any sort.
     // So we want to avoid doing that.  But we don't particularly want to make
     // expensive NS_IsMainThread calls here.
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/AudioWorkletProcessor.cpp
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+#include "AudioWorkletProcessor.h"
+
+#include "mozilla/dom/AudioWorkletNodeBinding.h"
+#include "mozilla/dom/AudioWorkletProcessorBinding.h"
+#include "mozilla/dom/MessagePort.h"
+#include "nsIGlobalObject.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AudioWorkletProcessor, mParent)
+
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioWorkletProcessor, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioWorkletProcessor, Release)
+
+AudioWorkletProcessor::AudioWorkletProcessor(nsIGlobalObject* aParent)
+  : mParent(aParent)
+{
+}
+
+/* static */ already_AddRefed<AudioWorkletProcessor>
+AudioWorkletProcessor::Constructor(const GlobalObject& aGlobal,
+                                   const AudioWorkletNodeOptions& aOptions,
+                                   ErrorResult& aRv)
+{
+  nsCOMPtr<nsIGlobalObject> global =
+      do_QueryInterface(aGlobal.GetAsSupports());
+  MOZ_ASSERT(global);
+
+  RefPtr<AudioWorkletProcessor> audioWorkletProcessor =
+      new AudioWorkletProcessor(global);
+
+  return audioWorkletProcessor.forget();
+}
+
+JSObject*
+AudioWorkletProcessor::WrapObject(JSContext* aCx,
+                                  JS::Handle<JSObject*> aGivenProto)
+{
+  return AudioWorkletProcessor_Binding::Wrap(aCx, this, aGivenProto);
+}
+
+MessagePort*
+AudioWorkletProcessor::GetPort(ErrorResult& aRv) const
+{
+  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+  return nullptr;
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/AudioWorkletProcessor.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+#ifndef AudioWorkletProcessor_h_
+#define AudioWorkletProcessor_h_
+
+#include "nsCOMPtr.h"
+#include "nsWrapperCache.h"
+
+struct AudioWorkletNodeOptions;
+class ErrorResult;
+class GlobalObject;
+class MessagePort;
+class nsIGlobalObject;
+
+namespace mozilla {
+namespace dom {
+
+class AudioWorkletProcessor final : public nsWrapperCache
+{
+public:
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioWorkletProcessor)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioWorkletProcessor)
+
+  static already_AddRefed<AudioWorkletProcessor>
+  Constructor(const GlobalObject& aGlobal,
+              const AudioWorkletNodeOptions& aOptions,
+              ErrorResult& aRv);
+
+  nsIGlobalObject* GetParentObject() const { return mParent; }
+
+  JSObject* WrapObject(JSContext* aCx,
+                       JS::Handle<JSObject*> aGivenProto) override;
+
+  MessagePort* GetPort(ErrorResult& aRv) const;
+
+private:
+  explicit AudioWorkletProcessor(nsIGlobalObject* aParent);
+  ~AudioWorkletProcessor() = default;
+  nsCOMPtr<nsIGlobalObject> mParent;
+};
+
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // AudioWorkletProcessor_h_
--- a/dom/media/webaudio/moz.build
+++ b/dom/media/webaudio/moz.build
@@ -48,16 +48,17 @@ EXPORTS.mozilla.dom += [
     'AudioDestinationNode.h',
     'AudioListener.h',
     'AudioNode.h',
     'AudioParam.h',
     'AudioParamMap.h',
     'AudioProcessingEvent.h',
     'AudioScheduledSourceNode.h',
     'AudioWorkletNode.h',
+    'AudioWorkletProcessor.h',
     'BiquadFilterNode.h',
     'ChannelMergerNode.h',
     'ChannelSplitterNode.h',
     'ConstantSourceNode.h',
     'ConvolverNode.h',
     'DelayNode.h',
     'DynamicsCompressorNode.h',
     'GainNode.h',
@@ -86,16 +87,17 @@ UNIFIED_SOURCES += [
     'AudioNodeEngine.cpp',
     'AudioNodeExternalInputStream.cpp',
     'AudioNodeStream.cpp',
     'AudioParam.cpp',
     'AudioParamMap.cpp',
     'AudioProcessingEvent.cpp',
     'AudioScheduledSourceNode.cpp',
     'AudioWorkletNode.cpp',
+    'AudioWorkletProcessor.cpp',
     'BiquadFilterNode.cpp',
     'ChannelMergerNode.cpp',
     'ChannelSplitterNode.cpp',
     'ConstantSourceNode.cpp',
     'ConvolverNode.cpp',
     'DelayBuffer.cpp',
     'DelayNode.cpp',
     'DynamicsCompressorNode.cpp',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/AudioWorkletProcessor.webidl
@@ -0,0 +1,18 @@
+/* -*- 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/#audioworkletprocessor
+ *
+ * Copyright © 2018 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+[Exposed=AudioWorklet,
+ Constructor (optional AudioWorkletNodeOptions options)]
+interface AudioWorkletProcessor {
+    [Throws]
+    readonly attribute MessagePort port;
+};
--- a/dom/webidl/EventTarget.webidl
+++ b/dom/webidl/EventTarget.webidl
@@ -19,17 +19,17 @@ dictionary EventListenerOptions {
 };
 
 dictionary AddEventListenerOptions : EventListenerOptions {
   boolean passive;
   boolean once = false;
 };
 
 [Constructor,
- Exposed=(Window,Worker,WorkerDebugger,System)]
+ Exposed=(Window,Worker,WorkerDebugger,AudioWorklet,System)]
 interface EventTarget {
   /* Passing null for wantsUntrusted means "default behavior", which
      differs in content and chrome.  In content that default boolean
      value is true, while in chrome the default boolean value is
      false. */
   [Throws]
   void addEventListener(DOMString type,
                         EventListener? listener,
--- a/dom/webidl/MessagePort.webidl
+++ b/dom/webidl/MessagePort.webidl
@@ -2,17 +2,17 @@
 /* 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/.
  *
  * For more information on this interface, please see
  * http://www.whatwg.org/specs/web-apps/current-work/#channel-messaging
  */
 
-[Exposed=(Window,Worker,System)]
+[Exposed=(Window,Worker,AudioWorklet,System)]
 interface MessagePort : EventTarget {
   [Throws]
   void postMessage(any message, optional sequence<object> transferable = []);
 
   void start();
   void close();
 
   // event handlers
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -381,16 +381,17 @@ WEBIDL_FILES = [
     'AudioParamMap.webidl',
     'AudioProcessingEvent.webidl',
     'AudioScheduledSourceNode.webidl',
     'AudioStreamTrack.webidl',
     'AudioTrack.webidl',
     'AudioTrackList.webidl',
     'AudioWorkletGlobalScope.webidl',
     'AudioWorkletNode.webidl',
+    'AudioWorkletProcessor.webidl',
     'AutocompleteInfo.webidl',
     'BarProp.webidl',
     'BaseAudioContext.webidl',
     'BaseKeyframeTypes.webidl',
     'BasicCardPayment.webidl',
     'BatteryManager.webidl',
     'BeforeUnloadEvent.webidl',
     'BiquadFilterNode.webidl',