Bug 840559 - Convert MediaError to WebIDL. r=smaug

This commit is contained in:
Andrea Marchesini 2013-02-14 10:59:21 -05:00
Родитель d45ba3cb90
Коммит 6755c6fcbc
6 изменённых файлов: 72 добавлений и 13 удалений

Просмотреть файл

@ -6,33 +6,45 @@
#include "mozilla/dom/MediaError.h" #include "mozilla/dom/MediaError.h"
#include "nsDOMClassInfoID.h" #include "nsDOMClassInfoID.h"
#include "mozilla/dom/MediaErrorBinding.h"
DOMCI_DATA(MediaError, mozilla::dom::MediaError) DOMCI_DATA(MediaError, mozilla::dom::MediaError)
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
NS_IMPL_ADDREF(MediaError) NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(MediaError, mParent)
NS_IMPL_RELEASE(MediaError) NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaError)
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaError)
NS_INTERFACE_MAP_BEGIN(MediaError) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaError)
NS_INTERFACE_MAP_ENTRY(nsISupports) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaError) NS_INTERFACE_MAP_ENTRY(nsIDOMMediaError)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaError)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaError) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaError)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
MediaError::MediaError(uint16_t aCode) MediaError::MediaError(nsHTMLMediaElement* aParent, uint16_t aCode)
: mCode(aCode) : mParent(aParent)
, mCode(aCode)
{ {
SetIsDOMBinding();
} }
NS_IMETHODIMP MediaError::GetCode(uint16_t* aCode) NS_IMETHODIMP MediaError::GetCode(uint16_t* aCode)
{ {
if (aCode) if (aCode)
*aCode = mCode; *aCode = Code();
return NS_OK; return NS_OK;
} }
JSObject*
MediaError::WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap)
{
return MediaErrorBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla

Просмотреть файл

@ -8,26 +8,44 @@
#define mozilla_dom_MediaError_h #define mozilla_dom_MediaError_h
#include "nsIDOMMediaError.h" #include "nsIDOMMediaError.h"
#include "nsHTMLMediaElement.h"
#include "nsWrapperCache.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class MediaError MOZ_FINAL : public nsIDOMMediaError class MediaError MOZ_FINAL : public nsIDOMMediaError,
public nsWrapperCache
{ {
public: public:
MediaError(uint16_t aCode); MediaError(nsHTMLMediaElement* aParent, uint16_t aCode);
// nsISupports // nsISupports
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaError)
// nsIDOMMediaError // nsIDOMMediaError
NS_DECL_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: private:
nsRefPtr<nsHTMLMediaElement> mParent;
// Error code // Error code
uint16_t mCode; const uint16_t mCode;
}; };
} // namespace dom } // namespace dom

Просмотреть файл

@ -436,6 +436,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLMediaElement, nsGenericH
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourcePointer) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourcePointer)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoadBlockedDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoadBlockedDoc)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceLoadCandidate) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceLoadCandidate)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mError)
for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) { for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputStreams[i].mStream); 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(mSourcePointer)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoadBlockedDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoadBlockedDoc)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceLoadCandidate) NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceLoadCandidate)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mError)
for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) { for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) {
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOutputStreams[i].mStream); 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?"); 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; mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
DispatchAsyncEvent(NS_LITERAL_STRING("error")); DispatchAsyncEvent(NS_LITERAL_STRING("error"));
// This clears mDelayingLoadEvent, so AddRemoveSelfReference will be called // 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_NETWORK ||
aErrorCode == nsIDOMMediaError::MEDIA_ERR_ABORTED, aErrorCode == nsIDOMMediaError::MEDIA_ERR_ABORTED,
"Only use nsIDOMMediaError codes!"); "Only use nsIDOMMediaError codes!");
mError = new MediaError(aErrorCode); mError = new MediaError(this, aErrorCode);
mBegun = false; mBegun = false;
DispatchAsyncEvent(NS_LITERAL_STRING("error")); DispatchAsyncEvent(NS_LITERAL_STRING("error"));
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) { if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) {

Просмотреть файл

@ -601,6 +601,10 @@ DOMInterfaces = {
'register': False 'register': False
}, },
'MediaError': {
'hasInstanceInterface': 'nsIDOMMediaError',
},
'MediaStream': [{ 'MediaStream': [{
'nativeType': 'nsIDOMMediaStream', 'nativeType': 'nsIDOMMediaStream',
}, },

Просмотреть файл

@ -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;
};

Просмотреть файл

@ -223,6 +223,7 @@ endif
ifdef MOZ_MEDIA ifdef MOZ_MEDIA
webidl_files += \ webidl_files += \
HTMLSourceElement.webidl \ HTMLSourceElement.webidl \
MediaError.webidl \
$(NULL) $(NULL)
endif endif