From 6755c6fcbc2debf5395ae85f53788f87238b2837 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 14 Feb 2013 10:59:21 -0500 Subject: [PATCH] Bug 840559 - Convert MediaError to WebIDL. r=smaug --- content/html/content/src/MediaError.cpp | 26 ++++++++++++++----- content/html/content/src/MediaError.h | 26 ++++++++++++++++--- .../html/content/src/nsHTMLMediaElement.cpp | 6 +++-- dom/bindings/Bindings.conf | 4 +++ dom/webidl/MediaError.webidl | 22 ++++++++++++++++ dom/webidl/WebIDL.mk | 1 + 6 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 dom/webidl/MediaError.webidl diff --git a/content/html/content/src/MediaError.cpp b/content/html/content/src/MediaError.cpp index 4a1df0637083..60dad73d51f1 100644 --- a/content/html/content/src/MediaError.cpp +++ b/content/html/content/src/MediaError.cpp @@ -6,33 +6,45 @@ #include "mozilla/dom/MediaError.h" #include "nsDOMClassInfoID.h" +#include "mozilla/dom/MediaErrorBinding.h" DOMCI_DATA(MediaError, mozilla::dom::MediaError) namespace mozilla { namespace dom { -NS_IMPL_ADDREF(MediaError) -NS_IMPL_RELEASE(MediaError) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(MediaError, mParent) +NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaError) +NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaError) -NS_INTERFACE_MAP_BEGIN(MediaError) - NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaError) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsIDOMMediaError) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaError) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaError) NS_INTERFACE_MAP_END -MediaError::MediaError(uint16_t aCode) -: mCode(aCode) +MediaError::MediaError(nsHTMLMediaElement* aParent, uint16_t aCode) + : mParent(aParent) + , mCode(aCode) { + SetIsDOMBinding(); } NS_IMETHODIMP MediaError::GetCode(uint16_t* aCode) { if (aCode) - *aCode = mCode; + *aCode = Code(); return NS_OK; } +JSObject* +MediaError::WrapObject(JSContext* aCx, JSObject* aScope, + bool* aTriedToWrap) +{ + return MediaErrorBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + } // namespace dom } // namespace mozilla diff --git a/content/html/content/src/MediaError.h b/content/html/content/src/MediaError.h index ca1931f6b29d..6dd29e308e2c 100644 --- a/content/html/content/src/MediaError.h +++ b/content/html/content/src/MediaError.h @@ -8,26 +8,44 @@ #define mozilla_dom_MediaError_h #include "nsIDOMMediaError.h" +#include "nsHTMLMediaElement.h" +#include "nsWrapperCache.h" #include "nsISupports.h" #include "mozilla/Attributes.h" namespace mozilla { namespace dom { -class MediaError MOZ_FINAL : public nsIDOMMediaError +class MediaError MOZ_FINAL : public nsIDOMMediaError, + public nsWrapperCache { public: - MediaError(uint16_t aCode); + MediaError(nsHTMLMediaElement* aParent, uint16_t aCode); // nsISupports - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaError) // nsIDOMMediaError NS_DECL_NSIDOMMEDIAERROR + nsHTMLMediaElement* GetParentObject() const + { + return mParent; + } + + virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap); + + uint16_t Code() const + { + return mCode; + } + private: + nsRefPtr mParent; + // Error code - uint16_t mCode; + const uint16_t mCode; }; } // namespace dom diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 05f9916eadb5..5374e6a8cd63 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -436,6 +436,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLMediaElement, nsGenericH NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourcePointer) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoadBlockedDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceLoadCandidate) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mError) for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) { NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputStreams[i].mStream); } @@ -451,6 +452,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLMediaElement, nsGenericHTM NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourcePointer) NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoadBlockedDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceLoadCandidate) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mError) for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) { NS_IMPL_CYCLE_COLLECTION_UNLINK(mOutputStreams[i].mStream); } @@ -660,7 +662,7 @@ void nsHTMLMediaElement::NoSupportedMediaSourceError() { NS_ASSERTION(mDelayingLoadEvent, "Load event not delayed during source selection?"); - mError = new MediaError(nsIDOMMediaError::MEDIA_ERR_SRC_NOT_SUPPORTED); + mError = new MediaError(this, nsIDOMMediaError::MEDIA_ERR_SRC_NOT_SUPPORTED); mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE; DispatchAsyncEvent(NS_LITERAL_STRING("error")); // This clears mDelayingLoadEvent, so AddRemoveSelfReference will be called @@ -2740,7 +2742,7 @@ void nsHTMLMediaElement::Error(uint16_t aErrorCode) aErrorCode == nsIDOMMediaError::MEDIA_ERR_NETWORK || aErrorCode == nsIDOMMediaError::MEDIA_ERR_ABORTED, "Only use nsIDOMMediaError codes!"); - mError = new MediaError(aErrorCode); + mError = new MediaError(this, aErrorCode); mBegun = false; DispatchAsyncEvent(NS_LITERAL_STRING("error")); if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) { diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 5a55ca8ad3db..2f511ee171f0 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -601,6 +601,10 @@ DOMInterfaces = { 'register': False }, +'MediaError': { + 'hasInstanceInterface': 'nsIDOMMediaError', +}, + 'MediaStream': [{ 'nativeType': 'nsIDOMMediaStream', }, diff --git a/dom/webidl/MediaError.webidl b/dom/webidl/MediaError.webidl new file mode 100644 index 000000000000..79b66d4ed8fb --- /dev/null +++ b/dom/webidl/MediaError.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/. + * + * The origin of this IDL file is + * http://www.whatwg.org/html/#mediaerror + * + * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and + * Opera Software ASA. You are granted a license to use, reproduce + * and create derivative works of this document. + */ + +interface MediaError { + const unsigned short MEDIA_ERR_ABORTED = 1; + const unsigned short MEDIA_ERR_NETWORK = 2; + const unsigned short MEDIA_ERR_DECODE = 3; + const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4; + + [Constant] + readonly attribute unsigned short code; +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 59fb22a67b41..89aa7fda1623 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -223,6 +223,7 @@ endif ifdef MOZ_MEDIA webidl_files += \ HTMLSourceElement.webidl \ + MediaError.webidl \ $(NULL) endif