Bug 1451913 P3 Make AudioContext add itself to the new window when its rebound for a document.open(). r=smaug
authorBen Kelly <ben@wanderview.com>
Mon, 16 Apr 2018 06:08:52 -0700
changeset 413845 4952f8b12700e60c7e7aeaa9aeff06cbf7658456
parent 413844 1ff0b30a815e50f299185443e90580ec4ced0911
child 413846 7f45cea49e22faa07640c736808b0aebc5994fa7
push id33852
push usershindli@mozilla.com
push dateMon, 16 Apr 2018 21:59:17 +0000
treeherdermozilla-central@0ceabd10aac2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1451913
milestone61.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 1451913 P3 Make AudioContext add itself to the new window when its rebound for a document.open(). r=smaug
dom/media/webaudio/AudioContext.cpp
dom/media/webaudio/AudioContext.h
dom/media/webaudio/AudioNode.cpp
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -684,16 +684,33 @@ AudioContext::CurrentTime()
 void AudioContext::DisconnectFromOwner()
 {
   mIsDisconnecting = true;
   Shutdown();
   DOMEventTargetHelper::DisconnectFromOwner();
 }
 
 void
+AudioContext::BindToOwner(nsIGlobalObject* aNew)
+{
+  auto scopeExit = MakeScopeExit([&] {
+    DOMEventTargetHelper::BindToOwner(aNew);
+  });
+
+  if (GetOwner()) {
+    GetOwner()->RemoveAudioContext(this);
+  }
+
+  nsCOMPtr<nsPIDOMWindowInner> newWindow = do_QueryInterface(aNew);
+  if (newWindow) {
+    newWindow->AddAudioContext(this);
+  }
+}
+
+void
 AudioContext::Shutdown()
 {
   mIsShutDown = true;
 
   // We don't want to touch promises if the global is going away soon.
   if (!mIsDisconnecting) {
     if (!mIsOffline) {
       RefPtr<Promise> ignored = Close(IgnoreErrors());
--- a/dom/media/webaudio/AudioContext.h
+++ b/dom/media/webaudio/AudioContext.h
@@ -140,16 +140,17 @@ public:
   MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
 
   nsPIDOMWindowInner* GetParentObject() const
   {
     return GetOwner();
   }
 
   virtual void DisconnectFromOwner() override;
+  virtual void BindToOwner(nsIGlobalObject* aNew) override;
 
   void Shutdown(); // idempotent
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   using DOMEventTargetHelper::DispatchTrustedEvent;
 
   // Constructor for regular AudioContext
--- a/dom/media/webaudio/AudioNode.cpp
+++ b/dom/media/webaudio/AudioNode.cpp
@@ -52,17 +52,16 @@ AudioNode::AudioNode(AudioContext* aCont
   , mChannelCount(aChannelCount)
   , mChannelCountMode(aChannelCountMode)
   , mChannelInterpretation(aChannelInterpretation)
   , mId(gId++)
   , mPassThrough(false)
   , mAbstractMainThread(aContext->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other))
 {
   MOZ_ASSERT(aContext);
-  DOMEventTargetHelper::BindToOwner(aContext->GetParentObject());
   aContext->RegisterNode(this);
 }
 
 AudioNode::~AudioNode()
 {
   MOZ_ASSERT(mInputNodes.IsEmpty());
   MOZ_ASSERT(mOutputNodes.IsEmpty());
   MOZ_ASSERT(mOutputParams.IsEmpty());