Bug 821383 - Don't bother with JSAPI magic in nsHTMLMediaElement::{G,S}etMozSrcObject; r=bz+roc

This commit is contained in:
Ms2ger 2013-03-10 08:58:18 +01:00
parent d805e77871
commit 4465cc3a75
5 changed files with 18 additions and 30 deletions

View File

@ -442,38 +442,21 @@ NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLMediaElement, Preload, preload, NULL)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLMediaElement, MozAudioChannelType, mozaudiochannel, "normal") NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLMediaElement, MozAudioChannelType, mozaudiochannel, "normal")
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLMediaElement::GetMozSrcObject(JSContext* aCtx, jsval *aParams) nsHTMLMediaElement::GetMozSrcObject(nsIDOMMediaStream** aStream)
{ {
if (mSrcAttrStream) { NS_ASSERTION(!mSrcAttrStream || mSrcAttrStream->GetStream(),
NS_ASSERTION(mSrcAttrStream->GetStream(), "MediaStream should have been set up properly"); "MediaStream should have been set up properly");
return nsContentUtils::WrapNative(aCtx, JS_GetGlobalForScopeChain(aCtx), nsRefPtr<DOMMediaStream> stream = mSrcAttrStream;
mSrcAttrStream, aParams); stream.forget(aStream);
}
*aParams = JSVAL_NULL;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLMediaElement::SetMozSrcObject(JSContext* aCtx, const jsval & aParams) nsHTMLMediaElement::SetMozSrcObject(nsIDOMMediaStream* aStream)
{ {
if (aParams.isNull()) { mSrcAttrStream = static_cast<DOMMediaStream*>(aStream);
mSrcAttrStream = nullptr;
Load(); Load();
return NS_OK; return NS_OK;
}
if (aParams.isObject()) {
nsCOMPtr<nsIDOMMediaStream> stream;
stream = do_QueryInterface(nsContentUtils::XPConnect()->
GetNativeOfWrapper(aCtx, JSVAL_TO_OBJECT(aParams)));
if (stream) {
mSrcAttrStream = static_cast<DOMMediaStream*>(stream.get());
Load();
return NS_OK;
}
}
// Should we store unsupported values on the element's attribute anyway?
// Let's not.
return NS_OK;
} }
/* readonly attribute nsIDOMHTMLMediaElement mozAutoplayEnabled; */ /* readonly attribute nsIDOMHTMLMediaElement mozAutoplayEnabled; */

View File

@ -24,7 +24,12 @@ function doTest() {
var stream = a.mozCaptureStream(); var stream = a.mozCaptureStream();
b.mozSrcObject = stream; b.mozSrcObject = stream;
is(b.mozSrcObject, stream, "Stream set correctly"); is(b.mozSrcObject, stream, "Stream set correctly");
try {
b.mozSrcObject = "invalid"; b.mozSrcObject = "invalid";
ok(false, "Setting mozSrcObject to an invalid value should throw.");
} catch (e) {
todo(e instanceof TypeError, "Exception should be a TypeError");
}
is(b.mozSrcObject, stream, "Stream not set to invalid value"); is(b.mozSrcObject, stream, "Stream not set to invalid value");
is(b.src, newSrc, "src attribute not affected by setting srcObject"); is(b.src, newSrc, "src attribute not affected by setting srcObject");
var step = 0; var step = 0;

View File

@ -20,7 +20,7 @@
* @status UNDER_DEVELOPMENT * @status UNDER_DEVELOPMENT
*/ */
[scriptable, uuid(ee5df17c-3928-11e2-8808-10bf48d64bd4)] [scriptable, uuid(e960385a-25e6-4695-a5e6-95908f88c5ec)]
interface nsIDOMHTMLAudioElement : nsIDOMHTMLMediaElement interface nsIDOMHTMLAudioElement : nsIDOMHTMLMediaElement
{ {
// Setup the audio stream for writing // Setup the audio stream for writing

View File

@ -27,7 +27,7 @@ interface nsIDOMMediaStream;
#endif #endif
%} %}
[scriptable, uuid(d9331886-3928-11e2-b0e1-10bf48d64bd4)] [scriptable, uuid(e1a30308-9e84-4c8d-bc81-06fb03385406)]
interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
{ {
// error state // error state
@ -35,7 +35,7 @@ interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
// network state // network state
attribute DOMString src; attribute DOMString src;
[implicit_jscontext] attribute jsval mozSrcObject; attribute nsIDOMMediaStream mozSrcObject;
readonly attribute DOMString currentSrc; readonly attribute DOMString currentSrc;
attribute DOMString crossorigin; attribute DOMString crossorigin;
const unsigned short NETWORK_EMPTY = 0; const unsigned short NETWORK_EMPTY = 0;

View File

@ -16,7 +16,7 @@
* @status UNDER_DEVELOPMENT * @status UNDER_DEVELOPMENT
*/ */
[scriptable, uuid(fe914e4a-3928-11e2-bea2-10bf48d64bd4)] [scriptable, uuid(4fb3129d-0c3e-4a5c-bf75-c3973f7463c3)]
interface nsIDOMHTMLVideoElement : nsIDOMHTMLMediaElement interface nsIDOMHTMLVideoElement : nsIDOMHTMLMediaElement
{ {
attribute long width; attribute long width;