From 7982ac318d89e218399f52c3855b2f3a11f237ee Mon Sep 17 00:00:00 2001 From: Joe Drew Date: Thu, 30 Jun 2011 21:58:28 -0400 Subject: [PATCH] Bug 552605 - Change "must validate if expired" to "must always validate" in the image cache, to fit with the spirit of the HTTP spec. r=jrmuizel f=bz --- modules/libpr0n/src/imgLoader.cpp | 11 +++++++---- modules/libpr0n/src/imgLoader.h | 10 +++++----- modules/libpr0n/src/imgRequest.cpp | 9 ++------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/libpr0n/src/imgLoader.cpp b/modules/libpr0n/src/imgLoader.cpp index fb875c28544..cba7c5fe2a3 100644 --- a/modules/libpr0n/src/imgLoader.cpp +++ b/modules/libpr0n/src/imgLoader.cpp @@ -401,7 +401,7 @@ static PRBool NewRequestAndEntry(nsIURI *uri, imgRequest **request, imgCacheEntr if (!*request) return PR_FALSE; - *entry = new imgCacheEntry(*request, /* mustValidateIfExpired = */ isFile); + *entry = new imgCacheEntry(*request, /* mustValidate = */ isFile); if (!*entry) { delete *request; return PR_FALSE; @@ -425,6 +425,9 @@ static PRBool ShouldRevalidateEntry(imgCacheEntry *aEntry, if (aFlags & nsIRequest::VALIDATE_ALWAYS) { bValidateEntry = PR_TRUE; } + else if (aEntry->GetMustValidate()) { + bValidateEntry = PR_TRUE; + } // // The cache entry has expired... Determine whether the stale cache // entry can be used without validation... @@ -438,7 +441,7 @@ static PRBool ShouldRevalidateEntry(imgCacheEntry *aEntry, if (aFlags & (nsIRequest::VALIDATE_NEVER | nsIRequest::VALIDATE_ONCE_PER_SESSION)) { - bValidateEntry = aEntry->GetMustValidateIfExpired(); + bValidateEntry = PR_FALSE; } // // LOAD_FROM_CACHE allows a stale cache entry to be used... Otherwise, @@ -526,12 +529,12 @@ static PRUint32 SecondsFromPRTime(PRTime prTime) return PRUint32(PRInt64(prTime) / PRInt64(PR_USEC_PER_SEC)); } -imgCacheEntry::imgCacheEntry(imgRequest *request, PRBool mustValidateIfExpired /* = PR_FALSE */) +imgCacheEntry::imgCacheEntry(imgRequest *request, PRBool mustValidate /* = PR_FALSE */) : mRequest(request), mDataSize(0), mTouchedTime(SecondsFromPRTime(PR_Now())), mExpiryTime(0), - mMustValidateIfExpired(mustValidateIfExpired), + mMustValidate(mustValidate), mEvicted(PR_FALSE), mHasNoProxies(PR_TRUE) {} diff --git a/modules/libpr0n/src/imgLoader.h b/modules/libpr0n/src/imgLoader.h index 16d2bbcb982..bfa20b0e253 100644 --- a/modules/libpr0n/src/imgLoader.h +++ b/modules/libpr0n/src/imgLoader.h @@ -123,13 +123,13 @@ public: Touch(); } - PRBool GetMustValidateIfExpired() const + PRBool GetMustValidate() const { - return mMustValidateIfExpired; + return mMustValidate; } - void SetMustValidateIfExpired(PRBool aValidate) + void SetMustValidate(PRBool aValidate) { - mMustValidateIfExpired = aValidate; + mMustValidate = aValidate; Touch(); } @@ -178,7 +178,7 @@ private: // data PRInt32 mTouchedTime; PRInt32 mExpiryTime; nsExpirationState mExpirationState; - PRPackedBool mMustValidateIfExpired : 1; + PRPackedBool mMustValidate : 1; PRPackedBool mEvicted : 1; PRPackedBool mHasNoProxies : 1; }; diff --git a/modules/libpr0n/src/imgRequest.cpp b/modules/libpr0n/src/imgRequest.cpp index a8a63b3d15f..6453d2506b9 100644 --- a/modules/libpr0n/src/imgRequest.cpp +++ b/modules/libpr0n/src/imgRequest.cpp @@ -530,13 +530,8 @@ void imgRequest::SetCacheValidation(imgCacheEntry* aCacheEntry, nsIRequest* aReq } } - // - // Determine whether the cache entry must be revalidated when it expires. - // If so, then the cache entry must *not* be used during HISTORY loads if - // it has expired. - // + // Determine whether the cache entry must be revalidated when we try to use it. // Currently, only HTTP specifies this information... - // nsCOMPtr httpChannel(do_QueryInterface(aRequest)); if (httpChannel) { PRBool bMustRevalidate = PR_FALSE; @@ -561,7 +556,7 @@ void imgRequest::SetCacheValidation(imgCacheEntry* aCacheEntry, nsIRequest* aReq // multiple calls to this function don't override an earlier decision to // validate by making validation a one-way decision. if (bMustRevalidate) - aCacheEntry->SetMustValidateIfExpired(bMustRevalidate); + aCacheEntry->SetMustValidate(bMustRevalidate); } } }