Bug 664430 - Make sure PopupManager doesn't keep objects alive after xpcom-shutdown, r=enndeakin

--HG--
extra : rebase_source : 137f6507926c47686d9542f97b6d518599e5ed0f
This commit is contained in:
Olli Pettay 2011-06-18 12:11:36 +03:00
Родитель 5e7764d4ab
Коммит 91010d2a7b
2 изменённых файлов: 35 добавлений и 3 удалений

Просмотреть файл

@ -299,7 +299,8 @@ private:
class nsXULPopupManager : public nsIDOMKeyListener,
public nsIMenuRollup,
public nsIRollupListener,
public nsITimerCallback
public nsITimerCallback,
public nsIObserver
{
public:
@ -308,6 +309,7 @@ public:
friend class nsXULMenuCommandEvent;
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSITIMERCALLBACK
// nsIRollupListener

Просмотреть файл

@ -70,6 +70,8 @@
#include "nsPIDOMWindow.h"
#include "nsPIWindowRoot.h"
#include "nsFrameManager.h"
#include "nsIObserverService.h"
#include "mozilla/Services.h"
const nsNavigationDirection DirectionFromKeyCodeTable[2][6] = {
{
@ -129,11 +131,12 @@ void nsMenuChainItem::Detach(nsMenuChainItem** aRoot)
}
}
NS_IMPL_ISUPPORTS4(nsXULPopupManager,
NS_IMPL_ISUPPORTS5(nsXULPopupManager,
nsIDOMKeyListener,
nsIDOMEventListener,
nsIMenuRollup,
nsITimerCallback)
nsITimerCallback,
nsIObserver)
nsXULPopupManager::nsXULPopupManager() :
mRangeOffset(0),
@ -143,6 +146,10 @@ nsXULPopupManager::nsXULPopupManager() :
mNoHidePanels(nsnull),
mTimerMenu(nsnull)
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this, "xpcom-shutdown", PR_FALSE);
}
}
nsXULPopupManager::~nsXULPopupManager()
@ -165,6 +172,29 @@ nsXULPopupManager::Shutdown()
NS_IF_RELEASE(sInstance);
}
NS_IMETHODIMP
nsXULPopupManager::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (!nsCRT::strcmp(aTopic, "xpcom-shutdown")) {
if (mKeyListener) {
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, PR_TRUE);
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keydown"), this, PR_TRUE);
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keyup"), this, PR_TRUE);
mKeyListener = nsnull;
}
mRangeParent = nsnull;
// mOpeningPopup is cleared explicitly soon after using it.
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, "xpcom-shutdown");
}
}
return NS_OK;
}
nsXULPopupManager*
nsXULPopupManager::GetInstance()
{