From 029e4c37060a4fd0c25e5d24b6d52e1b533b0589 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Mon, 24 Sep 2012 15:47:30 +1200 Subject: [PATCH] Bug 792665. Stop allowing HTMLMediaElement.src = mediaStream, and support HTMLMediaElement.mozSrcObject = mediaStream instead. r=cpearce,jesup --HG-- extra : rebase_source : 1986b88dc293939055b12ec7065c37dae394af8c --- .../html/content/src/nsHTMLAudioElement.cpp | 16 +++++-- .../html/content/src/nsHTMLMediaElement.cpp | 35 +++++--------- content/media/test/Makefile.in | 1 + .../test/test_streams_element_capture.html | 4 +- .../test_streams_element_capture_reset.html | 4 +- .../media/test/test_streams_srcObject.html | 47 +++++++++++++++++++ .../html/nsIDOMHTMLAudioElement.idl | 2 +- .../html/nsIDOMHTMLMediaElement.idl | 5 +- .../html/nsIDOMHTMLVideoElement.idl | 2 +- 9 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 content/media/test/test_streams_srcObject.html diff --git a/content/html/content/src/nsHTMLAudioElement.cpp b/content/html/content/src/nsHTMLAudioElement.cpp index 224866678a1..4bb9349c99a 100644 --- a/content/html/content/src/nsHTMLAudioElement.cpp +++ b/content/html/content/src/nsHTMLAudioElement.cpp @@ -11,6 +11,7 @@ #include "nsIDocument.h" #include "jsfriendapi.h" #include "nsContentUtils.h" +#include "nsJSUtils.h" using namespace mozilla::dom; @@ -93,9 +94,18 @@ nsHTMLAudioElement::Initialize(nsISupports* aOwner, JSContext* aContext, return NS_OK; } - // The only (optional) argument is the src of the audio (which can - // be a URL string or a MediaStream object) - return SetSrc(aContext, argv[0]); + // The only (optional) argument is the url of the audio + JSString* jsstr = JS_ValueToString(aContext, argv[0]); + if (!jsstr) + return NS_ERROR_FAILURE; + + nsDependentJSString str; + if (!str.init(aContext, jsstr)) + return NS_ERROR_FAILURE; + + // The only (optional) argument is the src of the audio (which must + // be a URL string), used to initialize the 'src' attribute. + return SetSrc(str); } NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 0d78f419117..3ac7dfcce7c 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -429,6 +429,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsHTMLMediaElement) NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement) // nsIDOMHTMLMediaElement +NS_IMPL_URI_ATTR(nsHTMLMediaElement, Src, src) +NS_IMPL_STRING_ATTR(nsHTMLMediaElement, Crossorigin, crossorigin) NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Controls, controls) NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Autoplay, autoplay) NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Loop, loop) @@ -436,47 +438,38 @@ NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, DefaultMuted, muted) NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLMediaElement, Preload, preload, NULL) NS_IMETHODIMP -nsHTMLMediaElement::GetSrc(JSContext* aCtx, jsval *aParams) +nsHTMLMediaElement::GetMozSrcObject(JSContext* aCtx, jsval *aParams) { if (mSrcAttrStream) { NS_ASSERTION(mSrcAttrStream->GetStream(), "MediaStream should have been set up properly"); return nsContentUtils::WrapNative(aCtx, JS_GetGlobalForScopeChain(aCtx), mSrcAttrStream, aParams); } - - nsAutoString str; - nsresult rv = GetURIAttr(nsGkAtoms::src, nullptr, str); - NS_ENSURE_SUCCESS(rv, rv); - if (!xpc::StringToJsval(aCtx, str, aParams)) { - return NS_ERROR_FAILURE; - } + *aParams = JSVAL_NULL; return NS_OK; } NS_IMETHODIMP -nsHTMLMediaElement::SetSrc(JSContext* aCtx, const jsval & aParams) +nsHTMLMediaElement::SetMozSrcObject(JSContext* aCtx, const jsval & aParams) { + if (aParams.isNull()) { + mSrcAttrStream = nullptr; + Load(); + return NS_OK; + } if (aParams.isObject()) { nsCOMPtr stream; stream = do_QueryInterface(nsContentUtils::XPConnect()-> GetNativeOfWrapper(aCtx, JSVAL_TO_OBJECT(aParams))); if (stream) { mSrcAttrStream = static_cast(stream.get()); - UnsetAttr(kNameSpaceID_None, nsGkAtoms::src, true); Load(); return NS_OK; } } - - mSrcAttrStream = nullptr; - JSString* jsStr = JS_ValueToString(aCtx, aParams); - if (!jsStr) - return NS_ERROR_DOM_TYPE_MISMATCH_ERR; - nsDependentJSString str; - if (!str.init(aCtx, jsStr)) - return NS_ERROR_DOM_TYPE_MISMATCH_ERR; - // Will trigger Load() - return SetAttrHelper(nsGkAtoms::src, str); + // Should we store unsupported values on the element's attribute anyway? + // Let's not. + return NS_OK; } /* readonly attribute nsIDOMHTMLMediaElement mozAutoplayEnabled; */ @@ -1851,8 +1844,6 @@ NS_IMETHODIMP nsHTMLMediaElement::Play() return NS_OK; } -NS_IMPL_STRING_ATTR(nsHTMLMediaElement, Crossorigin, crossorigin) - bool nsHTMLMediaElement::ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, const nsAString& aValue, diff --git a/content/media/test/Makefile.in b/content/media/test/Makefile.in index 721a1e63bd6..36c1219334e 100644 --- a/content/media/test/Makefile.in +++ b/content/media/test/Makefile.in @@ -129,6 +129,7 @@ MOCHITEST_FILES = \ test_seekLies.html \ test_media_sniffer.html \ contentType.sjs \ + test_streams_srcObject.html \ $(NULL) $(warning test_error_in_video_document.html is disabled for intermittent failures. Bug 608634) diff --git a/content/media/test/test_streams_element_capture.html b/content/media/test/test_streams_element_capture.html index c264897ed23..7c51cc285a0 100644 --- a/content/media/test/test_streams_element_capture.html +++ b/content/media/test/test_streams_element_capture.html @@ -31,8 +31,8 @@ function startTest(test, token) { v.src = test.name; var stream = v.mozCaptureStreamUntilEnded(); is(stream.currentTime, 0, test.name + " stream initial currentTime"); - vout.src = stream; - is(vout.src, stream, test.name + " set output element .src correctly"); + vout.mozSrcObject = stream; + is(vout.mozSrcObject, stream, test.name + " set output element .srcObject correctly"); var checkEnded = function(test, vout, stream) { return function() { is(stream.currentTime, vout.currentTime, test.name + " stream final currentTime"); diff --git a/content/media/test/test_streams_element_capture_reset.html b/content/media/test/test_streams_element_capture_reset.html index 49ab5f83418..1878c222f0a 100644 --- a/content/media/test/test_streams_element_capture_reset.html +++ b/content/media/test/test_streams_element_capture_reset.html @@ -17,8 +17,8 @@ SimpleTest.waitForExplicitFinish(); var v = document.getElementById('v'); var vout = document.getElementById('vout'); var vout_untilended = document.getElementById('vout_untilended'); -vout.src = v.mozCaptureStream(); -vout_untilended.src = v.mozCaptureStreamUntilEnded(); +vout.mozSrcObject = v.mozCaptureStream(); +vout_untilended.mozSrcObject = v.mozCaptureStreamUntilEnded(); function dumpEvent(event) { dump("GOT EVENT " + event.type + " currentTime=" + event.target.currentTime + diff --git a/content/media/test/test_streams_srcObject.html b/content/media/test/test_streams_srcObject.html new file mode 100644 index 00000000000..7d8b108de99 --- /dev/null +++ b/content/media/test/test_streams_srcObject.html @@ -0,0 +1,47 @@ + + + + Test interactions of src and srcObject + + + + + + +
+
+
+ + diff --git a/dom/interfaces/html/nsIDOMHTMLAudioElement.idl b/dom/interfaces/html/nsIDOMHTMLAudioElement.idl index f5c9fb20998..006cdea618e 100644 --- a/dom/interfaces/html/nsIDOMHTMLAudioElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLAudioElement.idl @@ -20,7 +20,7 @@ * @status UNDER_DEVELOPMENT */ -[scriptable, uuid(5fb3bed5-e9da-49ef-8488-ee3304db1a09)] +[scriptable, uuid(9e6cbf3e-4ae5-4a7b-a6ce-5af23572693f)] interface nsIDOMHTMLAudioElement : nsIDOMHTMLMediaElement { // Setup the audio stream for writing diff --git a/dom/interfaces/html/nsIDOMHTMLMediaElement.idl b/dom/interfaces/html/nsIDOMHTMLMediaElement.idl index 8764327c978..2d0f012bd3b 100644 --- a/dom/interfaces/html/nsIDOMHTMLMediaElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLMediaElement.idl @@ -27,14 +27,15 @@ interface nsIDOMMediaStream; #endif %} -[scriptable, uuid(e901c0cb-0698-4470-b057-246f64fc7e57)] +[scriptable, uuid(f49b0fea-dc13-47bd-b43e-606044280741)] interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement { // error state readonly attribute nsIDOMMediaError error; // network state - [implicit_jscontext] attribute jsval src; + attribute DOMString src; + [implicit_jscontext] attribute jsval mozSrcObject; readonly attribute DOMString currentSrc; attribute DOMString crossorigin; const unsigned short NETWORK_EMPTY = 0; diff --git a/dom/interfaces/html/nsIDOMHTMLVideoElement.idl b/dom/interfaces/html/nsIDOMHTMLVideoElement.idl index 11fe04c6761..7f4e623a18e 100644 --- a/dom/interfaces/html/nsIDOMHTMLVideoElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLVideoElement.idl @@ -16,7 +16,7 @@ * @status UNDER_DEVELOPMENT */ -[scriptable, uuid(e277b2e8-074e-4c8d-a401-f327b5d477e3)] +[scriptable, uuid(1fb777fd-952a-4666-bb26-0b32acaf674d)] interface nsIDOMHTMLVideoElement : nsIDOMHTMLMediaElement { attribute long width;