diff --git a/dom/html/TextTrackManager.cpp b/dom/html/TextTrackManager.cpp
index 7c785453025f..6678987e9212 100644
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -31,6 +31,13 @@ namespace dom {
NS_IMPL_ISUPPORTS(TextTrackManager::ShutdownObserverProxy, nsIObserver);
+void
+TextTrackManager::ShutdownObserverProxy::Unregister()
+{
+ nsContentUtils::UnregisterShutdownObserver(this);
+ mManager = nullptr;
+}
+
CompareTextTracks::CompareTextTracks(HTMLMediaElement* aMediaElement)
{
mMediaElement = aMediaElement;
@@ -140,7 +147,7 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
TextTrackManager::~TextTrackManager()
{
WEBVTT_LOG("%p ~TextTrackManager",this);
- nsContentUtils::UnregisterShutdownObserver(mShutdownProxy);
+ mShutdownProxy->Unregister();
}
TextTrackList*
diff --git a/dom/html/TextTrackManager.h b/dom/html/TextTrackManager.h
index 4e65eb012591..797abfc1269c 100644
--- a/dom/html/TextTrackManager.h
+++ b/dom/html/TextTrackManager.h
@@ -174,12 +174,16 @@ private:
{
MOZ_ASSERT(NS_IsMainThread());
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
- nsContentUtils::UnregisterShutdownObserver(this);
- mManager->NotifyShutdown();
+ if (mManager) {
+ mManager->NotifyShutdown();
+ }
+ Unregister();
}
return NS_OK;
}
+ void Unregister();
+
private:
~ShutdownObserverProxy() {};
TextTrackManager* mManager;
diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp
index 249b4dcbea21..c4cc5bfb8958 100644
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -945,6 +945,15 @@ public:
: mFontList(aFontList)
{ }
+ void Remove()
+ {
+ nsCOMPtr obs = services::GetObserverService();
+ if (obs) {
+ obs->RemoveObserver(this, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID);
+ }
+ mFontList = nullptr;
+ }
+
protected:
virtual ~WillShutdownObserver()
{ }
@@ -980,11 +989,7 @@ gfxFT2FontList::gfxFT2FontList()
gfxFT2FontList::~gfxFT2FontList()
{
if (mObserver) {
- nsCOMPtr obs = services::GetObserverService();
- if (obs) {
- obs->RemoveObserver(mObserver, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID);
- }
- mObserver = nullptr;
+ mObserver->Remove();
}
}
diff --git a/gfx/thebes/gfxFT2FontList.h b/gfx/thebes/gfxFT2FontList.h
index 93e6bd6db0a8..1efc40f585ec 100644
--- a/gfx/thebes/gfxFT2FontList.h
+++ b/gfx/thebes/gfxFT2FontList.h
@@ -20,6 +20,7 @@ using mozilla::dom::FontListEntry;
class FontNameCache;
typedef struct FT_FaceRec_* FT_Face;
class nsZipArchive;
+class WillShutdownObserver;
class FT2FontEntry : public gfxFontEntry
{
@@ -200,7 +201,8 @@ protected:
private:
mozilla::UniquePtr mFontNameCache;
int64_t mJarModifiedTime;
- nsCOMPtr mObserver;
+ RefPtr mObserver;
+
};
#endif /* GFX_FT2FONTLIST_H */