Bug 1275266 - Rename imgLoader::Singleton and imgLoader::PBSingleton to something less misleading, and document them. r=tnikkel
authorJonathan Watt <jwatt@jwatt.org>
Thu, 19 May 2016 13:31:15 +0100
changeset 327781 2f3fc8f9ec43faf0c41be3a55d51f9d604be0e0d
parent 327780 a03bd5fc36c0cd66762e0d41e5115900079d83fb
child 327782 ecd5857dc829b186767d2a3f33df3b577cb6c6e4
push idunknown
push userunknown
push dateunknown
reviewerstnikkel
bugs1275266
milestone49.0a1
Bug 1275266 - Rename imgLoader::Singleton and imgLoader::PBSingleton to something less misleading, and document them. r=tnikkel
dom/base/nsContentUtils.cpp
embedding/browser/nsContextMenuInfo.cpp
gfx/thebes/gfxWindowsPlatform.cpp
image/imgLoader.cpp
image/imgLoader.h
toolkit/system/gnome/nsAlertsIconListener.cpp
widget/cocoa/OSXNotificationCenter.mm
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3051,34 +3051,38 @@ nsContentUtils::DocumentInactiveForImage
 }
 
 imgLoader*
 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
 imgLoader*
 nsContentUtils::GetImgLoaderForChannel(nsIChannel* aChannel,
                                        nsIDocument* aContext)
 {
   NS_ENSURE_TRUE(!DocumentInactiveForImageLoads(aContext), nullptr);
 
-  if (!aChannel)
-    return imgLoader::Singleton();
+  if (!aChannel) {
+    return imgLoader::NormalLoader();
+  }
   nsCOMPtr<nsILoadContext> context;
   NS_QueryNotificationCallbacks(aChannel, context);
-  return context && context->UsePrivateBrowsing() ? imgLoader::PBSingleton() : imgLoader::Singleton();
+  return context && context->UsePrivateBrowsing() ?
+                      imgLoader::PrivateBrowsingLoader() :
+                      imgLoader::NormalLoader();
 }
 
 // static
 bool
 nsContentUtils::IsImageInCache(nsIURI* aURI, nsIDocument* aDocument)
 {
     imgILoader* loader = GetImgLoaderForDocument(aDocument);
     nsCOMPtr<imgICache> cache = do_QueryInterface(loader);
--- a/embedding/browser/nsContextMenuInfo.cpp
+++ b/embedding/browser/nsContextMenuInfo.cpp
@@ -291,17 +291,17 @@ nsContextMenuInfo::GetBackgroundImageReq
       primitiveValue = do_QueryInterface(cssValue);
       if (primitiveValue) {
         primitiveValue->GetStringValue(bgStringValue);
         if (!bgStringValue.EqualsLiteral("none")) {
           nsCOMPtr<nsIURI> bgUri;
           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,
                                doc->GetReferrerPolicy(), principal, nullptr,
                                nullptr, nullptr, nullptr, nsIRequest::LOAD_NORMAL,
                                nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE,
                                EmptyString(), aRequest);
         }
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -459,18 +459,20 @@ gfxWindowsPlatform::HandleDeviceReset()
   // Reset local state. Note: we leave feature status variables as-is. They
   // will be recomputed by InitializeDevices().
   mHasDeviceReset = false;
   mHasFakeDeviceReset = false;
   mHasD3D9DeviceReset = false;
   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();
   UpdateANGLEConfig();
   BumpDeviceCounter();
   return true;
 }
 
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1129,50 +1129,50 @@ imgCacheExpirationTracker::NotifyExpired
 
 double imgLoader::sCacheTimeWeight;
 uint32_t imgLoader::sCacheMaxSize;
 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>
 imgLoader::CreateImageLoader()
 {
   // In some cases, such as xpctests, XPCOM modules are not automatically
   // initialized.  We need to make sure that our module is initialized before
   // we hand out imgLoader instances and code starts using them.
   mozilla::image::EnsureModuleInitialized();
 
   RefPtr<imgLoader> loader = new imgLoader();
   loader->Init();
 
   return loader.forget();
 }
 
 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()
 : mUncachedImagesMutex("imgLoader::UncachedImages"), mRespectPrivacy(false)
 {
   sMemReporter->AddRef();
   sMemReporter->RegisterLoader(this);
 }
@@ -1395,18 +1395,20 @@ imgLoader::ClearCacheForControlledDocume
       NS_WARNING("Couldn't remove an entry from the cache in ClearCacheForControlledDocument()\n");
     }
   }
 }
 
 void
 imgLoader::Shutdown()
 {
-  NS_IF_RELEASE(gSingleton);
-  NS_IF_RELEASE(gPBSingleton);
+  NS_IF_RELEASE(gNormalLoader);
+  gNormalLoader = nullptr;
+  NS_IF_RELEASE(gPrivateBrowsingLoader);
+  gPrivateBrowsingLoader = nullptr;
 }
 
 nsresult
 imgLoader::ClearChromeImageCache()
 {
   return EvictEntries(mChromeCache);
 }
 
--- a/image/imgLoader.h
+++ b/image/imgLoader.h
@@ -241,21 +241,34 @@ public:
   typedef mozilla::Mutex Mutex;
 
   NS_DECL_ISUPPORTS
   NS_DECL_IMGILOADER
   NS_DECL_NSICONTENTSNIFFER
   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"
    * for nsIComponentManager.createInstance()/nsIServiceManager.getService()
    * calls (now only made by add-ons) needs access to it.
    *
    * XXX We would like to get rid of the nsIServiceManager.getService (and
    * nsIComponentManager.createInstance) method of creating imgLoader objects,
--- a/toolkit/system/gnome/nsAlertsIconListener.cpp
+++ b/toolkit/system/gnome/nsAlertsIconListener.cpp
@@ -243,18 +243,18 @@ nsAlertsIconListener::StartRequest(const
     mIconRequest = nullptr;
   }
 
   nsCOMPtr<nsIURI> imageUri;
   NS_NewURI(getter_AddRefs(imageUri), aImageUrl);
   if (!imageUri)
     return ShowAlert(nullptr);
 
-  imgLoader* il =
-    aInPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton();
+  imgLoader* il = aInPrivateBrowsing ? imgLoader::PrivateBrowsingLoader()
+                                     : imgLoader::NormalLoader();
   if (!il)
     return ShowAlert(nullptr);
 
   nsresult rv = il->LoadImageXPCOM(imageUri, nullptr, nullptr,
                                    NS_LITERAL_STRING("default"), nullptr, nullptr,
                                    this, nullptr,
                                    aInPrivateBrowsing ? nsIRequest::LOAD_ANONYMOUS :
                                                         nsIRequest::LOAD_NORMAL,
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -386,18 +386,18 @@ OSXNotificationCenter::ShowAlertWithIcon
     [GetNotificationCenter() deliverNotification:notification];
     [notification release];
     if (aAlertListener) {
       aAlertListener->Observe(nullptr, "alertshow", cookie.get());
     }
   } else {
     mPendingAlerts.AppendElement(osxni);
     osxni->mPendingNotifiction = notification;
-    imgLoader* il =
-      inPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton();
+    imgLoader* il = inPrivateBrowsing ? imgLoader::PrivateBrowsingLoader()
+                                      : imgLoader::NormalLoader();
     if (il) {
       nsCOMPtr<nsIURI> imageUri;
       NS_NewURI(getter_AddRefs(imageUri), imageUrl);
       if (imageUri) {
         nsCOMPtr<nsIPrincipal> principal;
         rv = aAlert->GetPrincipal(getter_AddRefs(principal));
         if (NS_SUCCEEDED(rv)) {
           rv = il->LoadImage(imageUri, nullptr, nullptr,