From e68d0fd3d281d2aca8623cb2efc137852ab18cf7 Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Wed, 7 Feb 2018 07:27:28 -0500 Subject: [PATCH] Bug 1383682 - Part 3. Prevent imgRequestProxy from leaking the current state when validating. r=tnikkel There are two other means from which a caller can get the current state which originally ignored validation -- GetImageStatus and StartDecodingWithResult. These methods are used by layout in some circumstances to decide whether or not the image is ready to display. As observed in some web platform tests, in particular css/css-backgrounds-3/background-size-031.html, we may actually validate and purge the cache for images under test. The state given by the aforementioned methods was misleading, because validation changed it. Now they take into account validation, and do not imply any particular state while validation is in progress. --- image/imgRequestProxy.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/image/imgRequestProxy.cpp b/image/imgRequestProxy.cpp index 90a7caeb5b46..e6db02a95d59 100644 --- a/image/imgRequestProxy.cpp +++ b/image/imgRequestProxy.cpp @@ -560,8 +560,11 @@ imgRequestProxy::CancelAndForgetObserver(nsresult aStatus) NS_IMETHODIMP imgRequestProxy::StartDecoding(uint32_t aFlags) { - // Flag this, so we know to transfer the request if our owner changes - mDecodeRequested = true; + // Flag this, so we know to request after validation if pending. + if (IsValidating()) { + mDecodeRequested = true; + return NS_OK; + } RefPtr image = GetImage(); if (image) { @@ -578,8 +581,11 @@ imgRequestProxy::StartDecoding(uint32_t aFlags) bool imgRequestProxy::StartDecodingWithResult(uint32_t aFlags) { - // Flag this, so we know to transfer the request if our owner changes - mDecodeRequested = true; + // Flag this, so we know to request after validation if pending. + if (IsValidating()) { + mDecodeRequested = true; + return false; + } RefPtr image = GetImage(); if (image) { @@ -736,8 +742,16 @@ imgRequestProxy::GetImage(imgIContainer** aImage) NS_IMETHODIMP imgRequestProxy::GetImageStatus(uint32_t* aStatus) { - RefPtr progressTracker = GetProgressTracker(); - *aStatus = progressTracker->GetImageStatus(); + if (IsValidating()) { + // We are currently validating the image, and so our status could revert if + // we discard the cache. We should also be deferring notifications, such + // that the caller will be notified when validation completes. Rather than + // risk misleading the caller, return nothing. + *aStatus = imgIRequest::STATUS_NONE; + } else { + RefPtr progressTracker = GetProgressTracker(); + *aStatus = progressTracker->GetImageStatus(); + } return NS_OK; }