Bug 938772. Don't give the anonymous poster <img> an empty 'src' attribute if we don't have a 'poster' attribute. r=cpearce

This commit is contained in:
Robert O'Callahan
2013-12-04 14:06:16 +13:00
parent 4dd81bafa9
commit cf73985817
4 changed files with 38 additions and 14 deletions

View File

@@ -85,8 +85,7 @@ nsVideoFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
// And now have it update its internal state
element->UpdateState(false);
nsresult res = UpdatePosterSource(false);
NS_ENSURE_SUCCESS(res,res);
UpdatePosterSource(false);
if (!aElements.AppendElement(mPosterImage))
return NS_ERROR_OUT_OF_MEMORY;
@@ -585,20 +584,22 @@ nsVideoFrame::GetVideoIntrinsicSize(nsRenderingContext *aRenderingContext)
nsPresContext::CSSPixelsToAppUnits(size.height));
}
nsresult
void
nsVideoFrame::UpdatePosterSource(bool aNotify)
{
NS_ASSERTION(HasVideoElement(), "Only call this on <video> elements.");
HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
nsAutoString posterStr;
element->GetPoster(posterStr);
nsresult res = mPosterImage->SetAttr(kNameSpaceID_None,
nsGkAtoms::src,
posterStr,
aNotify);
NS_ENSURE_SUCCESS(res,res);
return NS_OK;
if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::poster)) {
nsAutoString posterStr;
element->GetPoster(posterStr);
mPosterImage->SetAttr(kNameSpaceID_None,
nsGkAtoms::src,
posterStr,
aNotify);
} else {
mPosterImage->UnsetAttr(kNameSpaceID_None, nsGkAtoms::poster, aNotify);
}
}
NS_IMETHODIMP
@@ -607,8 +608,7 @@ nsVideoFrame::AttributeChanged(int32_t aNameSpaceID,
int32_t aModType)
{
if (aAttribute == nsGkAtoms::poster && HasVideoElement()) {
nsresult res = UpdatePosterSource(true);
NS_ENSURE_SUCCESS(res,res);
UpdatePosterSource(true);
}
return nsContainerFrame::AttributeChanged(aNameSpaceID,
aAttribute,

View File

@@ -112,7 +112,7 @@ protected:
// Sets the mPosterImage's src attribute to be the video's poster attribute,
// if we're the frame for a video element. Only call on frames for video
// elements, not for frames for audio elements.
nsresult UpdatePosterSource(bool aNotify);
void UpdatePosterSource(bool aNotify);
virtual ~nsVideoFrame();

View File

@@ -79,6 +79,7 @@ support-files = bug633762_iframe.html
[test_bug831780.html]
[test_bug841361.html]
[test_bug904810.html]
[test_bug938772.html]
[test_contained_plugin_transplant.html]
[test_image_selection.html]
[test_image_selection_2.html]

View File

@@ -0,0 +1,23 @@
<!doctype html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=938772
-->
<title>Test for Bug 938772</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=938772">Mozilla Bug 938772</a>
<p id="display"></p>
<iframe id="i"></iframe>
<pre id="test">
<script>
SimpleTest.waitForExplicitFinish();
i.onload = function() {
ok(!i.contentDocument.getElementById("v").failed,
"Check whether an error was reported");
SimpleTest.finish();
};
i.src = "data:text/html,<base href='http://basetag/basetag'><video id='v' onerror='v.failed=true'></video>";
</script>