Bug 1209739 - Make nsImageRenderer::PrepareImage() fail unless an image has STATUS_LOAD_COMPLETE. r=tn

This commit is contained in:
Seth Fowler 2015-10-14 00:02:37 -07:00
Родитель 93c62cd986
Коммит d06321a00c
1 изменённых файлов: 43 добавлений и 14 удалений

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

@ -4619,6 +4619,40 @@ nsImageRenderer::~nsImageRenderer()
{ {
} }
static bool
ShouldTreatAsCompleteDueToSyncDecode(const nsStyleImage* aImage,
uint32_t aFlags)
{
if (!(aFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES)) {
return false;
}
if (aImage->GetType() != eStyleImageType_Image) {
return false;
}
uint32_t status = 0;
if (NS_FAILED(aImage->GetImageData()->GetImageStatus(&status))) {
return false;
}
if (status & imgIRequest::STATUS_ERROR) {
// The image is "complete" since it's a corrupt image. If we created an
// imgIContainer at all, return true.
nsCOMPtr<imgIContainer> image;
aImage->GetImageData()->GetImage(getter_AddRefs(image));
return bool(image);
}
if (!(status & imgIRequest::STATUS_LOAD_COMPLETE)) {
// We must have loaded all of the image's data and the size must be
// available, or else sync decoding won't be able to decode the image.
return false;
}
return true;
}
bool bool
nsImageRenderer::PrepareImage() nsImageRenderer::PrepareImage()
{ {
@ -4628,22 +4662,17 @@ nsImageRenderer::PrepareImage()
} }
if (!mImage->IsComplete()) { if (!mImage->IsComplete()) {
// Make sure the image is actually decoding // Make sure the image is actually decoding.
mImage->StartDecoding(); mImage->StartDecoding();
// check again to see if we finished // Check again to see if we finished.
if (!mImage->IsComplete()) { // We cannot prepare the image for rendering if it is not fully loaded.
// We can not prepare the image for rendering if it is not fully loaded. // Special case: If we requested a sync decode and the image has loaded, push
// // on through because the Draw() will do a sync decode then.
// Special case: If we requested a sync decode and we have an image, push if (!mImage->IsComplete() &&
// on through because the Draw() will do a sync decode then !ShouldTreatAsCompleteDueToSyncDecode(mImage, mFlags)) {
nsCOMPtr<imgIContainer> img; mPrepareResult = DrawResult::NOT_READY;
if (!((mFlags & FLAG_SYNC_DECODE_IMAGES) && return false;
(mType == eStyleImageType_Image) &&
(NS_SUCCEEDED(mImage->GetImageData()->GetImage(getter_AddRefs(img)))))) {
mPrepareResult = DrawResult::NOT_READY;
return false;
}
} }
} }