From 1218c93b6041715823656b2a040db07a48b61b3e Mon Sep 17 00:00:00 2001 From: John Schoenick Date: Wed, 29 Oct 2014 13:24:02 -0700 Subject: [PATCH] Bug 1090530 - Ensure that we unregister preference observers in nsPresContext unlink. r=roc --- layout/base/nsPresContext.cpp | 49 ++++++++++++++++------------------- layout/base/nsPresContext.h | 3 +++ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index a03249ff13a6..c83c558cfe9b 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -252,24 +252,14 @@ nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType) PR_INIT_CLIST(&mDOMMediaQueryLists); } -nsPresContext::~nsPresContext() +void +nsPresContext::Destroy() { - NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer"); - SetShell(nullptr); - - NS_ABORT_IF_FALSE(PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists), - "must not have media query lists left"); - - // Disconnect the refresh driver *after* the transition manager, which - // needs it. - if (mRefreshDriver && mRefreshDriver->PresContext() == this) { - mRefreshDriver->Disconnect(); - } - if (mEventManager) { // unclear if these are needed, but can't hurt mEventManager->NotifyDestroyPresContext(this); mEventManager->SetPresContext(nullptr); + mEventManager = nullptr; } if (mPrefChangedTimer) @@ -321,6 +311,24 @@ nsPresContext::~nsPresContext() Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback, "nglayout.debug.paint_flashing_chrome", this); + + // Disconnect the refresh driver *after* the transition manager, which + // needs it. + if (mRefreshDriver && mRefreshDriver->PresContext() == this) { + mRefreshDriver->Disconnect(); + mRefreshDriver = nullptr; + } +} + +nsPresContext::~nsPresContext() +{ + NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer"); + SetShell(nullptr); + + NS_ABORT_IF_FALSE(PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists), + "must not have media query lists left"); + + Destroy(); } NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPresContext) @@ -368,13 +376,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument); NS_IMPL_CYCLE_COLLECTION_UNLINK(mDeviceContext); // worth bothering? - if (tmp->mEventManager) { - // unclear if these are needed, but can't hurt - tmp->mEventManager->NotifyDestroyPresContext(tmp); - tmp->mEventManager->SetPresContext(nullptr); - tmp->mEventManager = nullptr; - } - // We own only the items in mDOMMediaQueryLists that have listeners; // this reference is managed by their AddListener and RemoveListener // methods. @@ -387,15 +388,11 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext) } // NS_RELEASE(tmp->mLanguage); // an atom - // NS_IMPL_CYCLE_COLLECTION_UNLINK(mTheme); // a service // NS_IMPL_CYCLE_COLLECTION_UNLINK(mLangService); // a service NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrintSettings); - if (tmp->mPrefChangedTimer) - { - tmp->mPrefChangedTimer->Cancel(); - tmp->mPrefChangedTimer = nullptr; - } + + tmp->Destroy(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index efa40f549ac8..59c6c02eadc4 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -1172,6 +1172,9 @@ public: #endif protected: + // May be called multiple times (unlink, destructor) + void Destroy(); + void InvalidatePaintedLayers(); void AppUnitsPerDevPixelChanged();