Bug 1067541. Image preloads should not keep going once the actual image has started and gotten canceled. r=peterv

This commit is contained in:
Boris Zbarsky 2014-11-24 11:57:49 -05:00
parent 4832423e61
commit 505dd78d3d
4 changed files with 35 additions and 5 deletions

View File

@ -9593,7 +9593,22 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
// the "real" load occurs. Unpinned in DispatchContentLoadedEvents and
// unlink
if (NS_SUCCEEDED(rv)) {
mPreloadingImages.AppendObject(request);
mPreloadingImages.Put(uri, request.forget());
}
}
void
nsDocument::ForgetImagePreload(nsIURI* aURI)
{
// Checking count is faster than hashing the URI in the common
// case of empty table.
if (mPreloadingImages.Count() != 0) {
nsCOMPtr<imgIRequest> req;
mPreloadingImages.Remove(aURI, getter_AddRefs(req));
if (req) {
// Make sure to cancel the request so imagelib knows it's gone.
req->CancelAndForgetObserver(NS_BINDING_ABORTED);
}
}
}

View File

@ -1094,6 +1094,7 @@ public:
virtual void MaybePreLoadImage(nsIURI* uri,
const nsAString &aCrossOriginAttr,
ReferrerPolicy aReferrerPolicy) MOZ_OVERRIDE;
virtual void ForgetImagePreload(nsIURI* aURI) MOZ_OVERRIDE;
virtual void PreloadStyle(nsIURI* uri, const nsAString& charset,
const nsAString& aCrossOriginAttr,
@ -1742,8 +1743,11 @@ private:
nsExternalResourceMap mExternalResourceMap;
// All images in process of being preloaded
nsCOMArray<imgIRequest> mPreloadingImages;
// All images in process of being preloaded. This is a hashtable so
// we can remove them as the real image loads start; that way we
// make sure to not keep the image load going when no one cares
// about it anymore.
nsRefPtrHashtable<nsURIHashKey, imgIRequest> mPreloadingImages;
nsRefPtr<mozilla::dom::DOMImplementation> mDOMImplementation;

View File

@ -146,8 +146,8 @@ struct FullScreenOptions {
} // namespace mozilla
#define NS_IDOCUMENT_IID \
{ 0x1f343423, 0x957c, 0x4da3, \
{ 0xaa, 0xa3, 0x07, 0x37, 0x54, 0x3e, 0x79, 0x2a } }
{ 0xf63d2f6e, 0xd1c1, 0x49b9, \
{ 0x88, 0x26, 0xd5, 0x9e, 0x5d, 0x72, 0x2a, 0x42 } }
// Enum for requesting a particular type of document when creating a doc
enum DocumentFlavor {
@ -1922,6 +1922,12 @@ public:
const nsAString& aCrossOriginAttr,
ReferrerPolicy aReferrerPolicy) = 0;
/**
* Called by images to forget an image preload when they start doing
* the real load.
*/
virtual void ForgetImagePreload(nsIURI* aURI) = 0;
/**
* Called by nsParser to preload style sheets. Can also be merged into the
* parser if and when the parser is merged with libgklayout. aCrossOriginAttr

View File

@ -893,6 +893,11 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
getter_AddRefs(req),
policyType);
// Tell the document to forget about the image preload, if any, for
// this URI, now that we might have another imgRequestProxy for it.
// That way if we get canceled later the image load won't continue.
aDocument->ForgetImagePreload(aNewURI);
if (NS_SUCCEEDED(rv)) {
TrackImage(req);
ResetAnimationIfNeeded();