diff --git a/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp b/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp index ac89205b5a5f..c7ecbc169208 100644 --- a/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp +++ b/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp @@ -10,7 +10,10 @@ #include "nsContentUtils.h" // NS_DROP_JS_OBJECTS #include "jsfriendapi.h" -nsDOMNotifyAudioAvailableEvent::nsDOMNotifyAudioAvailableEvent(mozilla::dom::EventTarget* aOwner, +using namespace mozilla; +using namespace mozilla::dom; + +nsDOMNotifyAudioAvailableEvent::nsDOMNotifyAudioAvailableEvent(EventTarget* aOwner, nsPresContext* aPresContext, nsEvent* aEvent, uint32_t aEventType, @@ -28,6 +31,7 @@ nsDOMNotifyAudioAvailableEvent::nsDOMNotifyAudioAvailableEvent(mozilla::dom::Eve if (mEvent) { mEvent->message = aEventType; } + SetIsDOMBinding(); } DOMCI_DATA(NotifyAudioAvailableEvent, nsDOMNotifyAudioAvailableEvent) @@ -93,7 +97,7 @@ nsDOMNotifyAudioAvailableEvent::GetFrameBuffer(JSContext* aCx, JS::Value* aResul NS_IMETHODIMP nsDOMNotifyAudioAvailableEvent::GetTime(float *aRetVal) { - *aRetVal = mTime; + *aRetVal = Time(); return NS_OK; } @@ -117,11 +121,42 @@ nsDOMNotifyAudioAvailableEvent::InitAudioAvailableEvent(const nsAString& aType, mFrameBufferLength = aFrameBufferLength; mTime = aTime; mAllowAudioData = aAllowAudioData; + mCachedArray = nullptr; return NS_OK; } +void +nsDOMNotifyAudioAvailableEvent::InitAudioAvailableEvent(const nsAString& aType, + bool aCanBubble, + bool aCancelable, + const Nullable >& aFrameBuffer, + uint32_t aFrameBufferLength, + float aTime, + bool aAllowAudioData, + ErrorResult& aRv) +{ + if ((aFrameBuffer.IsNull() && aFrameBufferLength > 0) || + (!aFrameBuffer.IsNull() && + aFrameBuffer.Value().Length() < aFrameBufferLength)) { + aRv = NS_ERROR_UNEXPECTED; + return; + } + + nsAutoArrayPtr buffer; + if (!aFrameBuffer.IsNull()) { + buffer = new float[aFrameBufferLength]; + memcpy(buffer.get(), aFrameBuffer.Value().Elements(), + aFrameBufferLength * sizeof(float)); + } + + aRv = InitAudioAvailableEvent(aType, aCanBubble, aCancelable, + buffer.forget(), + aFrameBufferLength, + aTime, aAllowAudioData); +} + nsresult NS_NewDOMAudioAvailableEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, + EventTarget* aOwner, nsPresContext* aPresContext, nsEvent *aEvent, uint32_t aEventType, diff --git a/content/events/src/nsDOMNotifyAudioAvailableEvent.h b/content/events/src/nsDOMNotifyAudioAvailableEvent.h index 0188498f1d80..763c002792ef 100644 --- a/content/events/src/nsDOMNotifyAudioAvailableEvent.h +++ b/content/events/src/nsDOMNotifyAudioAvailableEvent.h @@ -11,6 +11,7 @@ #include "nsDOMEvent.h" #include "nsPresContext.h" #include "nsCycleCollectionParticipant.h" +#include "mozilla/dom/NotifyAudioAvailableEventBinding.h" class nsDOMNotifyAudioAvailableEvent : public nsDOMEvent, public nsIDOMNotifyAudioAvailableEvent @@ -39,6 +40,32 @@ public: ~nsDOMNotifyAudioAvailableEvent(); + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aScope) MOZ_OVERRIDE + { + return mozilla::dom::NotifyAudioAvailableEventBinding::Wrap(aCx, aScope, this); + } + + JSObject* GetFrameBuffer(JSContext* aCx, mozilla::ErrorResult& aRv) + { + JS::Value dummy; + aRv = GetFrameBuffer(aCx, &dummy); + return mCachedArray; + } + + float Time() + { + return mTime; + } + + void InitAudioAvailableEvent(const nsAString& aType, + bool aCanBubble, + bool aCancelable, + const mozilla::dom::Nullable >& aFrameBuffer, + uint32_t aFrameBufferLength, + float aTime, + bool aAllowAudioData, + mozilla::ErrorResult& aRv); private: nsAutoArrayPtr mFrameBuffer; uint32_t mFrameBufferLength; diff --git a/content/events/test/Makefile.in b/content/events/test/Makefile.in index 67584a5f97fd..16996a2dd964 100644 --- a/content/events/test/Makefile.in +++ b/content/events/test/Makefile.in @@ -102,6 +102,7 @@ MOCHITEST_FILES = \ test_bug812744.html \ test_addEventListenerExtraArg.html \ test_focus_disabled.html \ + test_bug847597.html \ $(NULL) MOCHITEST_CHROME_FILES = \ diff --git a/content/events/test/test_bug847597.html b/content/events/test/test_bug847597.html new file mode 100644 index 000000000000..5d1251ee1779 --- /dev/null +++ b/content/events/test/test_bug847597.html @@ -0,0 +1,81 @@ + + + + + + Test for Bug 847597 + + + + + +Mozilla Bug 847597 +

+ +
+
+ + diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 1d86df7d280e..5c8df590bb9e 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -665,6 +665,10 @@ DOMInterfaces = { 'nativeType': 'nsDOMNotifyPaintEvent', }, +'NotifyAudioAvailableEvent': { + 'nativeType': 'nsDOMNotifyAudioAvailableEvent', +}, + 'PaintRequest': { 'nativeType': 'nsPaintRequest', }, diff --git a/dom/webidl/NotifyAudioAvailableEvent.webidl b/dom/webidl/NotifyAudioAvailableEvent.webidl new file mode 100644 index 000000000000..26672befecc6 --- /dev/null +++ b/dom/webidl/NotifyAudioAvailableEvent.webidl @@ -0,0 +1,22 @@ +/* -*- 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/. + */ + +interface NotifyAudioAvailableEvent : Event +{ + [Throws] + readonly attribute Float32Array frameBuffer; + + readonly attribute float time; + + [Throws] + void initAudioAvailableEvent(DOMString type, + boolean canBubble, + boolean cancelable, + sequence? frameBuffer, + unsigned long frameBufferLength, + float time, + boolean allowAudioData); +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 3d8357f40fc9..3656299212c5 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -172,6 +172,7 @@ webidl_files = \ NodeIterator.webidl \ NodeList.webidl \ Notification.webidl \ + NotifyAudioAvailableEvent.webidl \ NotifyPaintEvent.webidl \ PaintRequest.webidl \ PaintRequestList.webidl \ diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index 817040abcb5b..ff564b544775 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -100,10 +100,6 @@ members = [ 'nsIBoxObject.width', 'nsIBoxObject.height', - # Audio - 'nsIDOMNotifyAudioAvailableEvent.frameBuffer', - 'nsIDOMNotifyAudioAvailableEvent.time', - # dom/indexedDB 'nsIIDBCursor.*', 'nsIIDBCursorWithValue.*',