From a7bf9ca8586e16b25860fd4d18faf5658f44906e Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 21 Dec 2010 13:28:45 -0800 Subject: [PATCH] Bug 612551 - Clear appshell observers on xpcom-shutdown. r=blassey a=blocking-fennec --- widget/src/android/nsAppShell.cpp | 20 ++++++++++++++++++++ widget/src/android/nsAppShell.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/widget/src/android/nsAppShell.cpp b/widget/src/android/nsAppShell.cpp index 02f2290f83c9..8aa1a1f7d014 100644 --- a/widget/src/android/nsAppShell.cpp +++ b/widget/src/android/nsAppShell.cpp @@ -75,6 +75,8 @@ nsIGeolocationUpdate *gLocationCallback = nsnull; nsAppShell *nsAppShell::gAppShell = nsnull; +NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver) + nsAppShell::nsAppShell() : mQueueLock(nsnull), mCondLock(nsnull), @@ -114,9 +116,27 @@ nsAppShell::Init() nsresult rv = nsBaseAppShell::Init(); if (AndroidBridge::Bridge()) AndroidBridge::Bridge()->NotifyAppShellReady(); + + nsCOMPtr obsServ = + mozilla::services::GetObserverService(); + if (obsServ) { + obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE); + } return rv; } +NS_IMETHODIMP +nsAppShell::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) +{ + if (!strcmp(aTopic, "xpcom-shutdown")) { + // We need to ensure no observers stick around after XPCOM shuts down + // or we'll see crashes, as the app shell outlives XPConnect. + mObserversHash.Clear(); + } + return nsBaseAppShell::Observe(aSubject, aTopic, aData); +} void nsAppShell::ScheduleNativeEventCallback() diff --git a/widget/src/android/nsAppShell.h b/widget/src/android/nsAppShell.h index 3a8f24cdb15a..5ddc08283ba1 100644 --- a/widget/src/android/nsAppShell.h +++ b/widget/src/android/nsAppShell.h @@ -61,6 +61,9 @@ public: nsAppShell(); + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_NSIOBSERVER + nsresult Init(); void NotifyNativeEvent();