Bug 449363 - Support media attribute of <source> elements. r=cpearce,bz

This commit is contained in:
Paul Adenot 2012-05-15 08:56:51 -04:00
Родитель 53b5000601
Коммит 9462877e3c
6 изменённых файлов: 91 добавлений и 5 удалений

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

@ -98,6 +98,9 @@
#include "nsDOMMediaStream.h"
#include "nsIScriptError.h"
#include "nsCSSParser.h"
#include "nsIMediaList.h"
#ifdef MOZ_OGG
#include "nsOggDecoder.h"
#endif
@ -850,6 +853,12 @@ void nsHTMLMediaElement::LoadFromSourceChildren()
"Should delay load event (if in document) during load");
NS_ASSERTION(mIsLoadingFromSourceChildren,
"Must remember we're loading from source children");
nsIDocument* parentDoc = OwnerDoc()->GetParentDocument();
if (parentDoc) {
parentDoc->FlushPendingNotifications(Flush_Layout);
}
while (true) {
nsIContent* child = GetNextSource();
if (!child) {
@ -876,11 +885,25 @@ void nsHTMLMediaElement::LoadFromSourceChildren()
GetCanPlay(type) == CANPLAY_NO) {
DispatchAsyncSourceError(child);
const PRUnichar* params[] = { type.get(), src.get() };
ReportLoadError("MediaLoadUnsupportedType", params, ArrayLength(params));
ReportLoadError("MediaLoadUnsupportedTypeAttribute", params, ArrayLength(params));
continue;
}
LOG(PR_LOG_DEBUG, ("%p Trying load from <source>=%s type=%s", this,
NS_ConvertUTF16toUTF8(src).get(), NS_ConvertUTF16toUTF8(type).get()));
nsAutoString media;
if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::media, media) && !media.IsEmpty()) {
nsCSSParser cssParser;
nsRefPtr<nsMediaList> mediaList(new nsMediaList());
cssParser.ParseMediaList(media, NULL, 0, mediaList, false);
nsIPresShell* presShell = OwnerDoc()->GetShell();
if (presShell && !mediaList->Matches(presShell->GetPresContext(), NULL)) {
DispatchAsyncSourceError(child);
const PRUnichar* params[] = { media.get(), src.get() };
ReportLoadError("MediaLoadSourceMediaNotMatched", params, ArrayLength(params));
continue;
}
}
LOG(PR_LOG_DEBUG, ("%p Trying load from <source>=%s type=%s media=%s", this,
NS_ConvertUTF16toUTF8(src).get(), NS_ConvertUTF16toUTF8(type).get(),
NS_ConvertUTF16toUTF8(media).get()));
nsCOMPtr<nsIURI> uri;
NewURIFromString(src, getter_AddRefs(uri));

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

@ -114,6 +114,7 @@ NS_IMPL_ELEMENT_CLONE(nsHTMLSourceElement)
NS_IMPL_URI_ATTR(nsHTMLSourceElement, Src, src)
NS_IMPL_STRING_ATTR(nsHTMLSourceElement, Type, type)
NS_IMPL_STRING_ATTR(nsHTMLSourceElement, Media, media)
nsresult
nsHTMLSourceElement::BindToTree(nsIDocument *aDocument,

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

@ -161,6 +161,7 @@ _TEST_FILES = \
use_large_cache.js \
test_audiowrite.html \
test_mozHasAudio.html \
test_source_media.html \
$(NULL)
# Don't run in suite

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

@ -0,0 +1,58 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Media test: media attribute for the source element.</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
<script type="text/javascript" src="../../html/content/test/reflect.js"></script>
</head>
<body>
<pre id="test">
<script type="text/javascript">
var testCount = 0;
function notifyFinished() {
testCount++;
if (testCount == 2) {
SimpleTest.finish();
}
}
SimpleTest.waitForExplicitFinish();
reflectString({
element: document.createElement("source"),
attribute: "media",
});
var media = getPlayableVideo(gSmallTests);
if (media == null) {
todo(false, "No media supported.");
SimpleTest.finish();
} else {
var v = document.createElement('video');
v.innerHTML = "<source src=\"" + media.name + "?fail\" media=\"not all\">" +
"<source src=\""+ media.name + "?pass\" media=\"all\">";
var v2 = document.createElement("video");
v2.innerHTML = "<source src=\""+ media.name +"?pass\">" +
"<source src=\""+ media.name + "?fail\" media=\"all\">";
document.body.appendChild(v);
document.body.appendChild(v2);
v.addEventListener("loadedmetadata", function(e) {
ok(/pass/.test(e.target.currentSrc),
"The source has been chosen according to the media attribute.");
notifyFinished();
});
v2.addEventListener("loadedmetadata", function(e) {
ok(/pass/.test(e.target.currentSrc),
"If no media attribute is specified, it defaults to \'all\'.")
notifyFinished();
});
}
</script>
</pre>
</body>
</html>

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

@ -48,9 +48,10 @@
* @status UNDER_DEVELOPMENT
*/
[scriptable, uuid(4BF58085-9986-47B5-BB03-62BAA0451497)]
[scriptable, uuid(af4b7ca2-2694-4672-a182-8a63be79c826)]
interface nsIDOMHTMLSourceElement : nsIDOMHTMLElement
{
attribute DOMString src;
attribute DOMString type;
attribute DOMString media;
};

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

@ -144,7 +144,9 @@ MediaLoadHttpError=HTTP load failed with status %1$S. Load of media resource %2$
# LOCALIZATION NOTE: %S is the URL of the media resource which failed to load.
MediaLoadInvalidURI=Invalid URI. Load of media resource %S failed.
# LOCALIZATION NOTE: %1$S is the media resource's format/codec type (basically equivalent to the file type, e.g. MP4,AVI,WMV,MOV etc), %2$S is the URL of the media resource which failed to load.
MediaLoadUnsupportedType=Specified "type" of "%1$S" is not supported. Load of media resource %2$S failed.
MediaLoadUnsupportedTypeAttribute=Specified "type" attribute of "%1$S" is not supported. Load of media resource %2$S failed.
# LOCALIZATION NOTE: %1$S is the "media" attribute value of the <source> element. It is a media query. %2$S is the URL of the media resource which failed to load.
MediaLoadSourceMediaNotMatched=Specified "media" attribute of "%1$S" does not match the environment. Load of media resource %2$S failed.
# LOCALIZATION NOTE: %1$S is the MIME type HTTP header being sent by the web server, %2$S is the URL of the media resource which failed to load.
MediaLoadUnsupportedMimeType=HTTP "Content-Type" of "%1$S" is not supported. Load of media resource %2$S failed.
# LOCALIZATION NOTE: %S is the URL of the media resource which failed to load because of error in decoding.