From de83a13903dc3969f062ad4214b0313734a95da9 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Thu, 19 May 2016 13:31:15 +0100 Subject: [PATCH] Bug 1275266 - Rename imgLoader::Singleton and imgLoader::PBSingleton to something less misleading, and document them. r=tnikkel --- dom/base/nsContentUtils.cpp | 14 ++++++---- embedding/browser/nsContextMenuInfo.cpp | 2 +- gfx/thebes/gfxWindowsPlatform.cpp | 6 ++-- image/imgLoader.cpp | 28 ++++++++++--------- image/imgLoader.h | 19 +++++++++++-- toolkit/system/gnome/nsAlertsIconListener.cpp | 4 +-- widget/cocoa/OSXNotificationCenter.mm | 4 +-- 7 files changed, 49 insertions(+), 28 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 097b8bac61a2..913e30445489 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3056,10 +3056,11 @@ nsContentUtils::GetImgLoaderForDocument(nsIDocument* aDoc) NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aDoc), nullptr); if (!aDoc) { - return imgLoader::Singleton(); + return imgLoader::NormalLoader(); } bool isPrivate = IsInPrivateBrowsing(aDoc); - return isPrivate ? imgLoader::PBSingleton() : imgLoader::Singleton(); + return isPrivate ? imgLoader::PrivateBrowsingLoader() + : imgLoader::NormalLoader(); } // static @@ -3069,11 +3070,14 @@ nsContentUtils::GetImgLoaderForChannel(nsIChannel* aChannel, { NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aContext), nullptr); - if (!aChannel) - return imgLoader::Singleton(); + if (!aChannel) { + return imgLoader::NormalLoader(); + } nsCOMPtr context; NS_QueryNotificationCallbacks(aChannel, context); - return context && context->UsePrivateBrowsing() ? imgLoader::PBSingleton() : imgLoader::Singleton(); + return context && context->UsePrivateBrowsing() ? + imgLoader::PrivateBrowsingLoader() : + imgLoader::NormalLoader(); } // static diff --git a/embedding/browser/nsContextMenuInfo.cpp b/embedding/browser/nsContextMenuInfo.cpp index 5b26a508032f..525f2de22e16 100644 --- a/embedding/browser/nsContextMenuInfo.cpp +++ b/embedding/browser/nsContextMenuInfo.cpp @@ -296,7 +296,7 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, NS_NewURI(getter_AddRefs(bgUri), bgStringValue); NS_ENSURE_TRUE(bgUri, NS_ERROR_FAILURE); - imgLoader* il = imgLoader::Singleton(); + imgLoader* il = imgLoader::NormalLoader(); NS_ENSURE_TRUE(il, NS_ERROR_FAILURE); return il->LoadImage(bgUri, nullptr, nullptr, diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp index 9375058b3c4a..d78a7ec9bcd5 100755 --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -464,8 +464,10 @@ gfxWindowsPlatform::HandleDeviceReset() mCompositorD3D11TextureSharingWorks = false; mDeviceResetReason = DeviceResetReason::OK; - imgLoader::Singleton()->ClearCache(true); - imgLoader::Singleton()->ClearCache(false); + imgLoader::Singleton()->NormalLoader(true); + imgLoader::Singleton()->NormalLoader(false); + imgLoader::Singleton()->PrivateBrowsingLoader(true); + imgLoader::Singleton()->PrivateBrowsingLoader(false); gfxAlphaBoxBlur::ShutdownBlurCache(); InitializeDevices(); diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 6aedadd8eb31..70cc40df759c 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -1134,8 +1134,8 @@ imgMemoryReporter* imgLoader::sMemReporter; NS_IMPL_ISUPPORTS(imgLoader, imgILoader, nsIContentSniffer, imgICache, nsISupportsWeakReference, nsIObserver) -static imgLoader* gSingleton = nullptr; -static imgLoader* gPBSingleton = nullptr; +static imgLoader* gNormalLoader = nullptr; +static imgLoader* gPrivateBrowsingLoader = nullptr; /* static */ already_AddRefed imgLoader::CreateImageLoader() @@ -1152,22 +1152,22 @@ imgLoader::CreateImageLoader() } imgLoader* -imgLoader::Singleton() +imgLoader::NormalLoader() { - if (!gSingleton) { - gSingleton = CreateImageLoader().take(); + if (!gNormalLoader) { + gNormalLoader = CreateImageLoader().take(); } - return gSingleton; + return gNormalLoader; } imgLoader* -imgLoader::PBSingleton() +imgLoader::PrivateBrowsingLoader() { - if (!gPBSingleton) { - gPBSingleton = CreateImageLoader().take(); - gPBSingleton->RespectPrivacyNotifications(); + if (!gPrivateBrowsingLoader) { + gPrivateBrowsingLoader = CreateImageLoader().take(); + gPrivateBrowsingLoader->RespectPrivacyNotifications(); } - return gPBSingleton; + return gPrivateBrowsingLoader; } imgLoader::imgLoader() @@ -1400,8 +1400,10 @@ imgLoader::ClearCacheForControlledDocument(nsIDocument* aDoc) void imgLoader::Shutdown() { - NS_IF_RELEASE(gSingleton); - NS_IF_RELEASE(gPBSingleton); + NS_IF_RELEASE(gNormalLoader); + gNormalLoader = nullptr; + NS_IF_RELEASE(gPrivateBrowsingLoader); + gPrivateBrowsingLoader = nullptr; } nsresult diff --git a/image/imgLoader.h b/image/imgLoader.h index 8816e23125eb..ffd438657f61 100644 --- a/image/imgLoader.h +++ b/image/imgLoader.h @@ -246,11 +246,24 @@ public: NS_DECL_IMGICACHE NS_DECL_NSIOBSERVER - static imgLoader* Singleton(); - static imgLoader* PBSingleton(); + /** + * Get the normal image loader instance that is used by gecko code, creating + * it if necessary. + */ + static imgLoader* NormalLoader(); /** - * Gecko code should use Singleton() or PBSingleton() to get an image loader. + * Get the Private Browsing image loader instance that is used by gecko code, + * creating it if necessary. + * + * The nsIChannel objects that this instance creates are created with the + * nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING flag. + */ + static imgLoader* PrivateBrowsingLoader(); + + /** + * Gecko code should use NormalLoader() or PrivateBrowsingLoader() to get the + * appropriate image loader. * * This constructor is public because the XPCOM module code that creates * instances of "@mozilla.org/image/loader;1" / "@mozilla.org/image/cache;1" diff --git a/toolkit/system/gnome/nsAlertsIconListener.cpp b/toolkit/system/gnome/nsAlertsIconListener.cpp index 824f3c5c95d1..51d29e0b1159 100644 --- a/toolkit/system/gnome/nsAlertsIconListener.cpp +++ b/toolkit/system/gnome/nsAlertsIconListener.cpp @@ -248,8 +248,8 @@ nsAlertsIconListener::StartRequest(const nsAString & aImageUrl, bool aInPrivateB if (!imageUri) return ShowAlert(nullptr); - imgLoader* il = - aInPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton(); + imgLoader* il = aInPrivateBrowsing ? imgLoader::PrivateBrowsingLoader() + : imgLoader::NormalLoader(); if (!il) return ShowAlert(nullptr); diff --git a/widget/cocoa/OSXNotificationCenter.mm b/widget/cocoa/OSXNotificationCenter.mm index 5f3822639b44..eeddf6c216f6 100644 --- a/widget/cocoa/OSXNotificationCenter.mm +++ b/widget/cocoa/OSXNotificationCenter.mm @@ -391,8 +391,8 @@ OSXNotificationCenter::ShowAlertWithIconData(nsIAlertNotification* aAlert, } else { mPendingAlerts.AppendElement(osxni); osxni->mPendingNotifiction = notification; - imgLoader* il = - inPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton(); + imgLoader* il = inPrivateBrowsing ? imgLoader::PrivateBrowsingLoader() + : imgLoader::NormalLoader(); if (il) { nsCOMPtr imageUri; NS_NewURI(getter_AddRefs(imageUri), imageUrl);