Bug 576621 - clearing cache does NOT clear cached images.r=joe,gavin

This commit is contained in:
Bobby Holley 2010-07-11 21:01:53 -04:00
Родитель 599142a072
Коммит 57fe00ab9a
3 изменённых файлов: 41 добавлений и 6 удалений

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

@ -122,6 +122,12 @@ Sanitizer.prototype = {
// facility for timespan-based eviction. Wipe it.
cacheService.evictEntries(Ci.nsICache.STORE_ANYWHERE);
} catch(er) {}
var imageCache = Cc["@mozilla.org/image/cache;1"].
getService(Ci.imgICache);
try {
imageCache.clearCache(false); // true=chrome, false=content
} catch(er) {}
},
get canClear()

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

@ -571,6 +571,17 @@ PrivateBrowsingService.prototype = {
}
}
// Image Cache
let (imageCache = Cc["@mozilla.org/image/cache;1"].
getService(Ci.imgICache)) {
try {
imageCache.clearCache(false); // true=chrome, false=content
} catch (ex) {
Cu.reportError("Exception thrown while clearing the image cache: " +
ex.toString());
}
}
// Cookies
let (cm = Cc["@mozilla.org/cookiemanager;1"].
getService(Ci.nsICookieManager2)) {

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

@ -78,6 +78,7 @@
#include "nsIApplicationCacheContainer.h"
#include "nsIMemoryReporter.h"
#include "nsIPrivateBrowsingService.h"
// we want to explore making the document own the load group
// so we can associate the document URI with the load group.
@ -874,19 +875,36 @@ nsresult imgLoader::Init()
prefs->AddObserver("image.http.accept", this, PR_TRUE);
// Listen for when we leave private browsing mode
nsCOMPtr<nsIObserverService> obService = mozilla::services::GetObserverService();
if (obService)
obService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
imgLoader::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData)
{
NS_ASSERTION(strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0,
"invalid topic received");
if (strcmp(NS_ConvertUTF16toUTF8(aData).get(), "image.http.accept") == 0) {
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
ReadAcceptHeaderPref(prefs);
// We listen for pref change notifications...
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
if (!strcmp(NS_ConvertUTF16toUTF8(aData).get(), "image.http.accept")) {
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
ReadAcceptHeaderPref(prefs);
}
}
// ...and exits from private browsing.
else if (!strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC)) {
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(aData))
ClearImageCache();
}
// (Nothing else should bring us here)
else {
NS_ABORT_IF_FALSE(0, "Invalid topic received");
}
return NS_OK;
}