Bug 1028588 - Fix dangerous public destructors in gfx - r=jrmuizel
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 23 Jun 2014 14:49:07 -0400
changeset 200125 2c62d4b7b0554e09efe43a7e543fc6e976d6aac0
parent 200124 0f07aa386616c6d01064d0eb003c365bed7348d4
child 200126 4976dc6ee72a17fe1641de59fbd66c52716f8fd9
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel
bugs1028588
milestone33.0a1
Bug 1028588 - Fix dangerous public destructors in gfx - r=jrmuizel
gfx/gl/GfxTexturesReporter.h
gfx/layers/LayerScope.cpp
gfx/layers/ipc/ISurfaceAllocator.h
gfx/src/gfxCrashReporterUtils.cpp
gfx/src/nsDeviceContext.cpp
gfx/src/nsScriptableRegion.h
gfx/src/nsThebesFontEnumerator.h
gfx/thebes/gfxASurface.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxFontInfoLoader.cpp
gfx/thebes/gfxFontInfoLoader.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatformFontList.cpp
gfx/thebes/gfxPlatformFontList.h
gfx/thebes/gfxUserFontSet.h
--- a/gfx/gl/GfxTexturesReporter.h
+++ b/gfx/gl/GfxTexturesReporter.h
@@ -10,16 +10,18 @@
 #include "nsIMemoryReporter.h"
 #include "GLTypes.h"
 
 namespace mozilla {
 namespace gl {
 
 class GfxTexturesReporter MOZ_FINAL : public nsIMemoryReporter
 {
+    ~GfxTexturesReporter() {}
+
 public:
     NS_DECL_ISUPPORTS
 
     GfxTexturesReporter()
     {
 #ifdef DEBUG
         // There must be only one instance of this class, due to |sAmount|
         // being static.  Assert this.
--- a/gfx/layers/LayerScope.cpp
+++ b/gfx/layers/LayerScope.cpp
@@ -75,23 +75,25 @@ public:
         HandshakeSuccess,
         HandshakeFailed
     };
 
     LayerScopeWebSocketHandler()
         : mState(NoHandshake)
     { }
 
+private:
     virtual ~LayerScopeWebSocketHandler()
     {
         if (mTransport) {
             mTransport->Close(NS_OK);
         }
     }
 
+public:
     void OpenStream(nsISocketTransport* aTransport) {
         MOZ_ASSERT(aTransport);
 
         mTransport = aTransport;
         mTransport->OpenOutputStream(nsITransport::OPEN_BLOCKING,
                                      0,
                                      0,
                                      getter_AddRefs(mOutputStream));
@@ -545,22 +547,23 @@ CheckSender()
     if (!gLayerScopeWebSocketManager->IsConnected())
         return false;
 
     return true;
 }
 
 class DebugListener : public nsIServerSocketListener
 {
+    virtual ~DebugListener() { }
+
 public:
 
     NS_DECL_THREADSAFE_ISUPPORTS
 
     DebugListener() { }
-    virtual ~DebugListener() { }
 
     /* nsIServerSocketListener */
 
     NS_IMETHODIMP OnSocketAccepted(nsIServerSocket *aServ,
                                    nsISocketTransport *aTransport)
     {
         if (!gLayerScopeWebSocketManager)
             return NS_OK;
@@ -577,28 +580,28 @@ public:
     }
 };
 
 NS_IMPL_ISUPPORTS(DebugListener, nsIServerSocketListener);
 
 
 class DebugDataSender : public nsIRunnable
 {
+    virtual ~DebugDataSender() {
+        Cleanup();
+    }
+
 public:
 
     NS_DECL_THREADSAFE_ISUPPORTS
 
     DebugDataSender() {
         mList = new LinkedList<DebugGLData>();
     }
 
-    virtual ~DebugDataSender() {
-        Cleanup();
-    }
-
     void Append(DebugGLData *d) {
         mList->insertBack(d);
     }
 
     void Cleanup() {
         if (!mList)
             return;
 
--- a/gfx/layers/ipc/ISurfaceAllocator.h
+++ b/gfx/layers/ipc/ISurfaceAllocator.h
@@ -177,16 +177,18 @@ protected:
   // This is used to implement an extremely simple & naive heap allocator.
   std::vector<mozilla::ipc::Shmem> mUsedShmems;
 
   friend class AtomicRefCountedWithFinalize<ISurfaceAllocator>;
 };
 
 class GfxMemoryImageReporter MOZ_FINAL : public nsIMemoryReporter
 {
+  ~GfxMemoryImageReporter() {}
+
 public:
   NS_DECL_ISUPPORTS
 
   GfxMemoryImageReporter()
   {
 #ifdef DEBUG
     // There must be only one instance of this class, due to |sAmount|
     // being static.
--- a/gfx/src/gfxCrashReporterUtils.cpp
+++ b/gfx/src/gfxCrashReporterUtils.cpp
@@ -37,16 +37,17 @@ static nsTArray<nsCString> *gFeaturesAlr
 class ObserverToDestroyFeaturesAlreadyReported : public nsIObserver
 {
 
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   ObserverToDestroyFeaturesAlreadyReported() {}
+private:
   virtual ~ObserverToDestroyFeaturesAlreadyReported() {}
 };
 
 NS_IMPL_ISUPPORTS(ObserverToDestroyFeaturesAlreadyReported,
                   nsIObserver)
 
 NS_IMETHODIMP
 ObserverToDestroyFeaturesAlreadyReported::Observe(nsISupports* aSubject,
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -49,17 +49,16 @@
 
 using namespace mozilla;
 using mozilla::services::GetObserverService;
 
 class nsFontCache MOZ_FINAL : public nsIObserver
 {
 public:
     nsFontCache()   { MOZ_COUNT_CTOR(nsFontCache); }
-    ~nsFontCache()  { MOZ_COUNT_DTOR(nsFontCache); }
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 
     void Init(nsDeviceContext* aContext);
     void Destroy();
 
     nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage,
@@ -67,16 +66,18 @@ public:
                            gfxTextPerfMetrics* aTextPerf,
                            nsFontMetrics*& aMetrics);
 
     void FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
     void Compact();
     void Flush();
 
 protected:
+    ~nsFontCache()  { MOZ_COUNT_DTOR(nsFontCache); }
+
     nsDeviceContext*          mContext; // owner
     nsCOMPtr<nsIAtom>         mLocaleLanguage;
     nsTArray<nsFontMetrics*>  mFontMetrics;
 };
 
 NS_IMPL_ISUPPORTS(nsFontCache, nsIObserver)
 
 // The Init and Destroy methods are necessary because it's not
--- a/gfx/src/nsScriptableRegion.h
+++ b/gfx/src/nsScriptableRegion.h
@@ -17,12 +17,13 @@ class NS_GFX nsScriptableRegion MOZ_FINA
 public:
 	nsScriptableRegion();
 
 	NS_DECL_ISUPPORTS
 
 	NS_DECL_NSISCRIPTABLEREGION
 
 private:
+        ~nsScriptableRegion() {}
 	nsIntRegion mRegion;
 };
 
 #endif
--- a/gfx/src/nsThebesFontEnumerator.h
+++ b/gfx/src/nsThebesFontEnumerator.h
@@ -7,16 +7,17 @@
 #define _NSTHEBESFONTENUMERATOR_H_
 
 #include "mozilla/Attributes.h"         // for MOZ_FINAL
 #include "nsIFontEnumerator.h"          // for NS_DECL_NSIFONTENUMERATOR, etc
 #include "nsISupports.h"                // for NS_DECL_ISUPPORTS
 
 class nsThebesFontEnumerator MOZ_FINAL : public nsIFontEnumerator
 {
+    ~nsThebesFontEnumerator() {}
 public:
     nsThebesFontEnumerator();
 
     NS_DECL_ISUPPORTS
 
     NS_DECL_NSIFONTENUMERATOR
 };
 
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -577,16 +577,18 @@ PR_STATIC_ASSERT(uint32_t(CAIRO_SURFACE_
                  uint32_t(gfxSurfaceType::Skia));
 
 /* Surface size memory reporting */
 
 static int64_t gSurfaceMemoryUsed[size_t(gfxSurfaceType::Max)] = { 0 };
 
 class SurfaceMemoryReporter MOZ_FINAL : public nsIMemoryReporter
 {
+    ~SurfaceMemoryReporter() {}
+
 public:
     NS_DECL_ISUPPORTS
 
     NS_IMETHOD CollectReports(nsIMemoryReporterCallback *aCb,
                               nsISupports *aClosure, bool aAnonymize)
     {
         const size_t len = ArrayLength(sSurfaceMemoryReporterAttrs);
         for (size_t i = 0; i < len; i++) {
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -1086,25 +1086,27 @@ public:
     void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                 FontCacheSizes* aSizes) const;
     void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                 FontCacheSizes* aSizes) const;
 
 protected:
     class MemoryReporter MOZ_FINAL : public nsIMemoryReporter
     {
+        ~MemoryReporter() {}
     public:
         NS_DECL_ISUPPORTS
         NS_DECL_NSIMEMORYREPORTER
     };
 
     // Observer for notifications that the font cache cares about
     class Observer MOZ_FINAL
         : public nsIObserver
     {
+        ~Observer() {}
     public:
         NS_DECL_ISUPPORTS
         NS_DECL_NSIOBSERVER
     };
 
     void DestroyFont(gfxFont *aFont);
 
     static gfxFontCache *gGlobalCache;
--- a/gfx/thebes/gfxFontInfoLoader.cpp
+++ b/gfx/thebes/gfxFontInfoLoader.cpp
@@ -22,37 +22,39 @@ FontInfoData::Load()
     for (i = 0; i < n; i++) {
         LoadFontFamilyData(mFontFamiliesToLoad[i]);
     }
 
     mLoadTime = TimeStamp::Now() - start;
 }
 
 class FontInfoLoadCompleteEvent : public nsRunnable {
+    virtual ~FontInfoLoadCompleteEvent() {}
+
     NS_DECL_THREADSAFE_ISUPPORTS
 
     FontInfoLoadCompleteEvent(FontInfoData *aFontInfo) :
         mFontInfo(aFontInfo)
     {}
-    virtual ~FontInfoLoadCompleteEvent() {}
 
     NS_IMETHOD Run();
 
     nsRefPtr<FontInfoData> mFontInfo;
 };
 
 class AsyncFontInfoLoader : public nsRunnable {
+    virtual ~AsyncFontInfoLoader() {}
+
     NS_DECL_THREADSAFE_ISUPPORTS
 
     AsyncFontInfoLoader(FontInfoData *aFontInfo) :
         mFontInfo(aFontInfo)
     {
         mCompleteEvent = new FontInfoLoadCompleteEvent(aFontInfo);
     }
-    virtual ~AsyncFontInfoLoader() {}
 
     NS_IMETHOD Run();
 
     nsRefPtr<FontInfoData> mFontInfo;
     nsRefPtr<FontInfoLoadCompleteEvent> mCompleteEvent;
 };
 
 // runs on main thread after async font info loading is done
--- a/gfx/thebes/gfxFontInfoLoader.h
+++ b/gfx/thebes/gfxFontInfoLoader.h
@@ -190,20 +190,20 @@ protected:
     public:
         NS_DECL_ISUPPORTS
         NS_DECL_NSIOBSERVER
 
         ShutdownObserver(gfxFontInfoLoader *aLoader)
             : mLoader(aLoader)
         { }
 
+    protected:
         virtual ~ShutdownObserver()
         { }
 
-    protected:
         gfxFontInfoLoader *mLoader;
     };
 
     // CreateFontInfo - create platform-specific object used
     //                  to load system-wide font info
     virtual already_AddRefed<FontInfoData> CreateFontInfoData() {
         return nullptr;
     }
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -130,16 +130,17 @@ static void ShutdownCMS();
 #include "mozilla/gfx/SourceSurfaceCairo.h"
 using namespace mozilla::gfx;
 
 /* Class to listen for pref changes so that chrome code can dynamically
    force sRGB as an output profile. See Bug #452125. */
 class SRGBOverrideObserver MOZ_FINAL : public nsIObserver,
                                        public nsSupportsWeakReference
 {
+    ~SRGBOverrideObserver() {}
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
 NS_IMPL_ISUPPORTS(SRGBOverrideObserver, nsIObserver, nsISupportsWeakReference)
 
 #define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
@@ -175,16 +176,17 @@ static const char* kObservedPrefs[] = {
     "gfx.downloadable_fonts.",
     "gfx.font_rendering.",
     BIDI_NUMERAL_PREF,
     nullptr
 };
 
 class FontPrefsObserver MOZ_FINAL : public nsIObserver
 {
+    ~FontPrefsObserver() {}
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
 NS_IMPL_ISUPPORTS(FontPrefsObserver, nsIObserver)
 
 NS_IMETHODIMP
@@ -199,16 +201,17 @@ FontPrefsObserver::Observe(nsISupports *
     NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
     gfxPlatform::GetPlatform()->FontsPrefsChanged(NS_ConvertUTF16toUTF8(someData).get());
 
     return NS_OK;
 }
 
 class MemoryPressureObserver MOZ_FINAL : public nsIObserver
 {
+    ~MemoryPressureObserver() {}
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
 NS_IMPL_ISUPPORTS(MemoryPressureObserver, nsIObserver)
 
 NS_IMETHODIMP
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -96,16 +96,17 @@ const gfxFontEntry::ScriptRange gfxPlatf
 static const char* kObservedPrefs[] = {
     "font.",
     "font.name-list.",
     "intl.accept_languages",  // hmmmm...
     nullptr
 };
 
 class gfxFontListPrefObserver MOZ_FINAL : public nsIObserver {
+    ~gfxFontListPrefObserver() {}
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
 static gfxFontListPrefObserver* gFontListPrefObserver = nullptr;
 
 NS_IMPL_ISUPPORTS(gfxFontListPrefObserver, nsIObserver)
--- a/gfx/thebes/gfxPlatformFontList.h
+++ b/gfx/thebes/gfxPlatformFontList.h
@@ -186,16 +186,17 @@ public:
         mUserFontSetList.RemoveEntry(aUserFontSet);
     }
 
     static const gfxFontEntry::ScriptRange sComplexScriptRanges[];
 
 protected:
     class MemoryReporter MOZ_FINAL : public nsIMemoryReporter
     {
+        ~MemoryReporter() {}
     public:
         NS_DECL_ISUPPORTS
         NS_DECL_NSIMEMORYREPORTER
     };
 
     gfxPlatformFontList(bool aNeedFullnamePostscriptNames = true);
 
     static gfxPlatformFontList *sPlatformFontList;
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -274,21 +274,21 @@ public:
         static void Dump();
 #endif
 
     private:
         // Helper that we use to observe the empty-cache notification
         // from nsICacheService.
         class Flusher : public nsIObserver
         {
+            virtual ~Flusher() {}
         public:
             NS_DECL_ISUPPORTS
             NS_DECL_NSIOBSERVER
             Flusher() {}
-            virtual ~Flusher() {}
         };
 
         // Key used to look up entries in the user-font cache.
         // Note that key comparison does *not* use the mFontEntry field
         // as a whole; it only compares specific fields within the entry
         // (weight/width/style/features) that could affect font selection
         // or rendering, and that must match between a font-set's proxy
         // entry and the corresponding "real" font entry.