Bug 814789 - Tie the life-time of the AudioContext to the life-time of the document owning it; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2012-11-23 18:33:41 -05:00
parent ed0385c3e4
commit 993cf8162c
4 changed files with 31 additions and 3 deletions

View File

@ -60,7 +60,7 @@ AudioContext::WrapObject(JSContext* aCx, JSObject* aScope,
/* static */ already_AddRefed<AudioContext>
AudioContext::Constructor(nsISupports* aGlobal, ErrorResult& aRv)
{
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(aGlobal);
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal);
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
@ -68,6 +68,7 @@ AudioContext::Constructor(nsISupports* aGlobal, ErrorResult& aRv)
AudioContext* object = new AudioContext(window);
NS_ADDREF(object);
window->AddAudioContext(object);
return object;
}

View File

@ -49,6 +49,8 @@ public:
return mWindow;
}
void Shutdown() {}
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap);

View File

@ -224,6 +224,7 @@
#include "nsSandboxFlags.h"
#include "TimeChangeObserver.h"
#include "nsPISocketTransportService.h"
#include "mozilla/dom/AudioContext.h"
#ifdef ANDROID
#include <android/log.h>
@ -1121,6 +1122,11 @@ nsGlobalWindow::FreeInnerObjects()
CleanupCachedXBLHandlers(this);
for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) {
mAudioContexts[i]->Shutdown();
}
mAudioContexts.Clear();
#ifdef DEBUG
nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
#endif
@ -2800,6 +2806,12 @@ nsPIDOMWindow::MaybeCreateDoc()
}
}
void
nsPIDOMWindow::AddAudioContext(AudioContext* aAudioContext)
{
mAudioContexts.AppendElement(aAudioContext);
}
NS_IMETHODIMP
nsGlobalWindow::GetDocument(nsIDOMDocument** aDocument)
{

View File

@ -16,6 +16,8 @@
#include "nsIDOMEventTarget.h"
#include "nsIDOMDocument.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
#include "nsIURI.h"
#define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
@ -47,9 +49,15 @@ class nsXBLPrototypeHandler;
class nsIArray;
class nsPIWindowRoot;
namespace mozilla {
namespace dom {
class AudioContext;
}
}
#define NS_PIDOMWINDOW_IID \
{ 0x7b18e421, 0x2179, 0x4e24, \
{ 0x96, 0x58, 0x26, 0x75, 0xa4, 0x37, 0xf3, 0x8f } }
{ 0xf5af1c3c, 0xebad, 0x4d00, \
{ 0xa2, 0xa4, 0x12, 0x2e, 0x27, 0x16, 0x59, 0x01 } }
class nsPIDOMWindow : public nsIDOMWindowInternal
{
@ -628,6 +636,8 @@ public:
OpenNoNavigate(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions, nsIDOMWindow **_retval) = 0;
void AddAudioContext(mozilla::dom::AudioContext* aAudioContext);
protected:
// The nsPIDOMWindow constructor. The aOuterWindow argument should
// be null if and only if the created window itself is an outer
@ -693,6 +703,9 @@ protected:
// window is active
nsCOMPtr<nsIContent> mFocusedNode;
// The AudioContexts created for the current document, if any.
nsTArray<nsRefPtr<mozilla::dom::AudioContext> > mAudioContexts;
// A unique (as long as our 64-bit counter doesn't roll over) id for
// this window.
uint64_t mWindowID;