Bug 853298 - Part 2: Make AudioNode an EventTarget; r=smaug
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 12 Apr 2013 11:28:33 -0400
changeset 135524 5d549a8fc2eb70898a41216ec1de267cf1649f75
parent 135523 dedbbce5235fe4a54b762ee63f796e7767f115e1
child 135525 dbb82c0a48e56c5e204d6ab4cb8cfc7db5b81487
push id3752
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 17:21:10 +0000
treeherdermozilla-aurora@1580544aef0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs853298
milestone23.0a1
Bug 853298 - Part 2: Make AudioNode an EventTarget; r=smaug
content/media/webaudio/AudioContext.cpp
content/media/webaudio/AudioContext.h
content/media/webaudio/AudioNode.cpp
content/media/webaudio/AudioNode.h
content/media/webaudio/test/test_singleSourceDest.html
dom/webidl/AudioNode.webidl
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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/. */
 
 #include "AudioContext.h"
 #include "nsContentUtils.h"
-#include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "mozilla/ErrorResult.h"
 #include "MediaStreamGraph.h"
 #include "mozilla/dom/AnalyserNode.h"
 #include "AudioDestinationNode.h"
 #include "AudioBufferSourceNode.h"
 #include "AudioBuffer.h"
 #include "GainNode.h"
@@ -28,17 +27,17 @@ namespace dom {
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(AudioContext,
                                         mWindow, mDestination, mListener)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioContext, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioContext, Release)
 
 static uint8_t gWebAudioOutputKey;
 
-AudioContext::AudioContext(nsIDOMWindow* aWindow)
+AudioContext::AudioContext(nsPIDOMWindow* aWindow)
   : mWindow(aWindow)
   , mDestination(new AudioDestinationNode(this, MediaStreamGraph::GetInstance()))
 {
   // Actually play audio
   mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
   SetIsDOMBinding();
 }
 
--- a/content/media/webaudio/AudioContext.h
+++ b/content/media/webaudio/AudioContext.h
@@ -14,27 +14,26 @@
 #include "EnableWebAudioCheck.h"
 #include "nsAutoPtr.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/AudioContextBinding.h"
 #include "MediaBufferDecoder.h"
 #include "StreamBuffer.h"
 #include "MediaStreamGraph.h"
-#include "nsIDOMWindow.h"
 
 // X11 has a #define for CurrentTime. Unbelievable :-(.
 // See content/media/DOMMediaStream.h for more fun!
 #ifdef CurrentTime
 #undef CurrentTime
 #endif
 
 struct JSContext;
 class JSObject;
-class nsIDOMWindow;
+class nsPIDOMWindow;
 
 namespace mozilla {
 
 class ErrorResult;
 struct WebAudioDecodeJob;
 
 namespace dom {
 
@@ -48,24 +47,24 @@ class DelayNode;
 class DynamicsCompressorNode;
 class GainNode;
 class GlobalObject;
 class PannerNode;
 
 class AudioContext MOZ_FINAL : public nsWrapperCache,
                                public EnableWebAudioCheck
 {
-  explicit AudioContext(nsIDOMWindow* aParentWindow);
+  explicit AudioContext(nsPIDOMWindow* aParentWindow);
   ~AudioContext();
 
 public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioContext)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioContext)
 
-  nsIDOMWindow* GetParentObject() const
+  nsPIDOMWindow* GetParentObject() const
   {
     return mWindow;
   }
 
   void Shutdown()
   {
     Suspend();
     mDecoder.Shutdown();
@@ -143,17 +142,17 @@ public:
   void UpdatePannerSource();
 
 private:
   void RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob);
 
   friend struct ::mozilla::WebAudioDecodeJob;
 
 private:
-  nsCOMPtr<nsIDOMWindow> mWindow;
+  nsCOMPtr<nsPIDOMWindow> mWindow;
   nsRefPtr<AudioDestinationNode> mDestination;
   nsRefPtr<AudioListener> mListener;
   MediaBufferDecoder mDecoder;
   nsTArray<nsAutoPtr<WebAudioDecodeJob> > mDecodeJobs;
   // Two arrays containing all the PannerNodes and AudioBufferSourceNodes,
   // to compute the doppler shift. Those are weak pointers.
   nsTArray<PannerNode*> mPannerNodes;
   nsTArray<AudioBufferSourceNode*> mAudioBufferSourceNodes;
--- a/content/media/webaudio/AudioNode.cpp
+++ b/content/media/webaudio/AudioNode.cpp
@@ -8,40 +8,36 @@
 #include "AudioContext.h"
 #include "nsContentUtils.h"
 #include "mozilla/ErrorResult.h"
 #include "AudioNodeStream.h"
 
 namespace mozilla {
 namespace dom {
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AudioNode)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AudioNode, nsDOMEventTargetHelper)
   tmp->DisconnectFromGraph();
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mContext)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mOutputNodes)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AudioNode)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AudioNode, nsDOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContext)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputNodes)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(AudioNode)
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(AudioNode)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(AudioNode)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioNode)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
+NS_IMPL_ADDREF_INHERITED(AudioNode, nsDOMEventTargetHelper)
+NS_IMPL_RELEASE_INHERITED(AudioNode, nsDOMEventTargetHelper)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioNode)
+NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 AudioNode::AudioNode(AudioContext* aContext)
   : mContext(aContext)
 {
   MOZ_ASSERT(aContext);
+  nsDOMEventTargetHelper::BindToOwner(aContext->GetParentObject());
   SetIsDOMBinding();
 }
 
 AudioNode::~AudioNode()
 {
   DisconnectFromGraph();
   MOZ_ASSERT(mInputNodes.IsEmpty());
   MOZ_ASSERT(mOutputNodes.IsEmpty());
--- a/content/media/webaudio/AudioNode.h
+++ b/content/media/webaudio/AudioNode.h
@@ -2,17 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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/. */
 
 #ifndef AudioNode_h_
 #define AudioNode_h_
 
-#include "nsWrapperCache.h"
+#include "nsDOMEventTargetHelper.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 #include "EnableWebAudioCheck.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "AudioContext.h"
 #include "AudioParamTimeline.h"
 #include "MediaStreamGraph.h"
@@ -65,18 +65,17 @@ private:
  *
  * We track the incoming and outgoing connections to other AudioNodes.
  * All connections are strong and thus rely on cycle collection to break them.
  * However, we also track whether an AudioNode is capable of producing output
  * in the future. If it isn't, then we break its connections to its inputs
  * and outputs, allowing nodes to be immediately disconnected. This
  * disconnection is done internally, invisible to DOM users.
  */
-class AudioNode : public nsISupports,
-                  public nsWrapperCache,
+class AudioNode : public nsDOMEventTargetHelper,
                   public EnableWebAudioCheck
 {
 public:
   explicit AudioNode(AudioContext* aContext);
   virtual ~AudioNode();
 
   // This should be idempotent (safe to call multiple times).
   // This should be called in the destructor of every class that overrides
@@ -92,17 +91,18 @@ public:
   // This method should be overridden to return true in nodes
   // which support being hooked up to the Media Stream graph.
   virtual bool SupportsMediaStreams() const
   {
     return false;
   }
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AudioNode)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioNode,
+                                           nsDOMEventTargetHelper)
 
   virtual AudioBufferSourceNode* AsAudioBufferSourceNode() {
     return nullptr;
   }
 
   AudioContext* GetParentObject() const
   {
     return mContext;
--- a/content/media/webaudio/test/test_singleSourceDest.html
+++ b/content/media/webaudio/test/test_singleSourceDest.html
@@ -20,16 +20,17 @@ addLoadEvent(function() {
     buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
   }
 
   var destination = context.destination;
   is(destination.context, context, "Destination node has proper context");
   is(destination.context, context, "Destination node has proper context");
   is(destination.numberOfInputs, 1, "Destination node has 1 inputs");
   is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
+  ok(destination instanceof EventTarget, "AudioNodes must be EventTargets");
 
   testWith(context, buffer, destination, function(source) {
     source.start(0);
   }, function(source) {
     source.stop();
   }, function() {
     testWith(context, buffer, destination, function(source) {
       source.start(0, 1);
--- a/dom/webidl/AudioNode.webidl
+++ b/dom/webidl/AudioNode.webidl
@@ -6,17 +6,17 @@
  * The origin of this IDL file is
  * https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [PrefControlled]
-interface AudioNode {
+interface AudioNode : EventTarget {
 
     [Throws]
     void connect(AudioNode destination, optional unsigned long output = 0, optional unsigned long input = 0);
 
     // [Throws]
     // void connect(AudioParam destination, optional unsigned long output = 0);
 
     [Throws]