Bug 1275266 - Rename imgLoader::Singleton and imgLoader::PBSingleton to something less misleading, and document them. r=tnikkel

This commit is contained in:
Jonathan Watt 2016-05-19 13:31:15 +01:00
parent 887122b9b7
commit de83a13903
7 changed files with 49 additions and 28 deletions

View File

@ -3056,10 +3056,11 @@ nsContentUtils::GetImgLoaderForDocument(nsIDocument* aDoc)
NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aDoc), nullptr); NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aDoc), nullptr);
if (!aDoc) { if (!aDoc) {
return imgLoader::Singleton(); return imgLoader::NormalLoader();
} }
bool isPrivate = IsInPrivateBrowsing(aDoc); bool isPrivate = IsInPrivateBrowsing(aDoc);
return isPrivate ? imgLoader::PBSingleton() : imgLoader::Singleton(); return isPrivate ? imgLoader::PrivateBrowsingLoader()
: imgLoader::NormalLoader();
} }
// static // static
@ -3069,11 +3070,14 @@ nsContentUtils::GetImgLoaderForChannel(nsIChannel* aChannel,
{ {
NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aContext), nullptr); NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aContext), nullptr);
if (!aChannel) if (!aChannel) {
return imgLoader::Singleton(); return imgLoader::NormalLoader();
}
nsCOMPtr<nsILoadContext> context; nsCOMPtr<nsILoadContext> context;
NS_QueryNotificationCallbacks(aChannel, context); NS_QueryNotificationCallbacks(aChannel, context);
return context && context->UsePrivateBrowsing() ? imgLoader::PBSingleton() : imgLoader::Singleton(); return context && context->UsePrivateBrowsing() ?
imgLoader::PrivateBrowsingLoader() :
imgLoader::NormalLoader();
} }
// static // static

View File

@ -296,7 +296,7 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode,
NS_NewURI(getter_AddRefs(bgUri), bgStringValue); NS_NewURI(getter_AddRefs(bgUri), bgStringValue);
NS_ENSURE_TRUE(bgUri, NS_ERROR_FAILURE); NS_ENSURE_TRUE(bgUri, NS_ERROR_FAILURE);
imgLoader* il = imgLoader::Singleton(); imgLoader* il = imgLoader::NormalLoader();
NS_ENSURE_TRUE(il, NS_ERROR_FAILURE); NS_ENSURE_TRUE(il, NS_ERROR_FAILURE);
return il->LoadImage(bgUri, nullptr, nullptr, return il->LoadImage(bgUri, nullptr, nullptr,

View File

@ -464,8 +464,10 @@ gfxWindowsPlatform::HandleDeviceReset()
mCompositorD3D11TextureSharingWorks = false; mCompositorD3D11TextureSharingWorks = false;
mDeviceResetReason = DeviceResetReason::OK; mDeviceResetReason = DeviceResetReason::OK;
imgLoader::Singleton()->ClearCache(true); imgLoader::Singleton()->NormalLoader(true);
imgLoader::Singleton()->ClearCache(false); imgLoader::Singleton()->NormalLoader(false);
imgLoader::Singleton()->PrivateBrowsingLoader(true);
imgLoader::Singleton()->PrivateBrowsingLoader(false);
gfxAlphaBoxBlur::ShutdownBlurCache(); gfxAlphaBoxBlur::ShutdownBlurCache();
InitializeDevices(); InitializeDevices();

View File

@ -1134,8 +1134,8 @@ imgMemoryReporter* imgLoader::sMemReporter;
NS_IMPL_ISUPPORTS(imgLoader, imgILoader, nsIContentSniffer, imgICache, NS_IMPL_ISUPPORTS(imgLoader, imgILoader, nsIContentSniffer, imgICache,
nsISupportsWeakReference, nsIObserver) nsISupportsWeakReference, nsIObserver)
static imgLoader* gSingleton = nullptr; static imgLoader* gNormalLoader = nullptr;
static imgLoader* gPBSingleton = nullptr; static imgLoader* gPrivateBrowsingLoader = nullptr;
/* static */ already_AddRefed<imgLoader> /* static */ already_AddRefed<imgLoader>
imgLoader::CreateImageLoader() imgLoader::CreateImageLoader()
@ -1152,22 +1152,22 @@ imgLoader::CreateImageLoader()
} }
imgLoader* imgLoader*
imgLoader::Singleton() imgLoader::NormalLoader()
{ {
if (!gSingleton) { if (!gNormalLoader) {
gSingleton = CreateImageLoader().take(); gNormalLoader = CreateImageLoader().take();
} }
return gSingleton; return gNormalLoader;
} }
imgLoader* imgLoader*
imgLoader::PBSingleton() imgLoader::PrivateBrowsingLoader()
{ {
if (!gPBSingleton) { if (!gPrivateBrowsingLoader) {
gPBSingleton = CreateImageLoader().take(); gPrivateBrowsingLoader = CreateImageLoader().take();
gPBSingleton->RespectPrivacyNotifications(); gPrivateBrowsingLoader->RespectPrivacyNotifications();
} }
return gPBSingleton; return gPrivateBrowsingLoader;
} }
imgLoader::imgLoader() imgLoader::imgLoader()
@ -1400,8 +1400,10 @@ imgLoader::ClearCacheForControlledDocument(nsIDocument* aDoc)
void void
imgLoader::Shutdown() imgLoader::Shutdown()
{ {
NS_IF_RELEASE(gSingleton); NS_IF_RELEASE(gNormalLoader);
NS_IF_RELEASE(gPBSingleton); gNormalLoader = nullptr;
NS_IF_RELEASE(gPrivateBrowsingLoader);
gPrivateBrowsingLoader = nullptr;
} }
nsresult nsresult

View File

@ -246,11 +246,24 @@ public:
NS_DECL_IMGICACHE NS_DECL_IMGICACHE
NS_DECL_NSIOBSERVER 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 * This constructor is public because the XPCOM module code that creates
* instances of "@mozilla.org/image/loader;1" / "@mozilla.org/image/cache;1" * instances of "@mozilla.org/image/loader;1" / "@mozilla.org/image/cache;1"

View File

@ -248,8 +248,8 @@ nsAlertsIconListener::StartRequest(const nsAString & aImageUrl, bool aInPrivateB
if (!imageUri) if (!imageUri)
return ShowAlert(nullptr); return ShowAlert(nullptr);
imgLoader* il = imgLoader* il = aInPrivateBrowsing ? imgLoader::PrivateBrowsingLoader()
aInPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton(); : imgLoader::NormalLoader();
if (!il) if (!il)
return ShowAlert(nullptr); return ShowAlert(nullptr);

View File

@ -391,8 +391,8 @@ OSXNotificationCenter::ShowAlertWithIconData(nsIAlertNotification* aAlert,
} else { } else {
mPendingAlerts.AppendElement(osxni); mPendingAlerts.AppendElement(osxni);
osxni->mPendingNotifiction = notification; osxni->mPendingNotifiction = notification;
imgLoader* il = imgLoader* il = inPrivateBrowsing ? imgLoader::PrivateBrowsingLoader()
inPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton(); : imgLoader::NormalLoader();
if (il) { if (il) {
nsCOMPtr<nsIURI> imageUri; nsCOMPtr<nsIURI> imageUri;
NS_NewURI(getter_AddRefs(imageUri), imageUrl); NS_NewURI(getter_AddRefs(imageUri), imageUrl);