Bug 605294 - Leak nsGlobalWindow hiding a focused iframe, r=peterv, a=blocking
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 17 Dec 2010 13:48:00 -0800
changeset 59509 dd9e50b46d311f1a9bf80112ef273501a43ee0d3
parent 59508 37290bda896db60060cc90dfd394110927364ed7
child 59510 c6669ebbabf7b3227954d45c5acf74d692360a75
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerspeterv, blocking
bugs605294
milestone2.0b9pre
Bug 605294 - Leak nsGlobalWindow hiding a focused iframe, r=peterv, a=blocking
dom/base/nsFocusManager.cpp
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -166,16 +166,21 @@ nsFocusManager::~nsFocusManager()
 {
   nsIPrefBranch2* prefBranch = nsContentUtils::GetPrefBranch();
 
   if (prefBranch) {
     prefBranch->RemoveObserver("accessibility.browsewithcaret", this);
     prefBranch->RemoveObserver("accessibility.tabfocus_applies_to_xul", this);
     prefBranch->RemoveObserver("accessibility.mouse_focuses_formcontrol", this);
   }
+  
+  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+  if (obs) {
+    obs->RemoveObserver(this, "xpcom-shutdown");
+  }
 }
 
 // static
 nsresult
 nsFocusManager::Init()
 {
   nsFocusManager* fm = new nsFocusManager();
   NS_ENSURE_TRUE(fm, NS_ERROR_OUT_OF_MEMORY);
@@ -189,45 +194,58 @@ nsFocusManager::Init()
   sMouseFocusesFormControl =
     nsContentUtils::GetBoolPref("accessibility.mouse_focuses_formcontrol", PR_FALSE);
 
   nsIPrefBranch2* prefBranch = nsContentUtils::GetPrefBranch();
   prefBranch->AddObserver("accessibility.browsewithcaret", fm, PR_TRUE);
   prefBranch->AddObserver("accessibility.tabfocus_applies_to_xul", fm, PR_TRUE);
   prefBranch->AddObserver("accessibility.mouse_focuses_formcontrol", fm, PR_TRUE);
 
+  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+  if (obs) {
+    obs->AddObserver(fm, "xpcom-shutdown", PR_TRUE);
+  }
+
   return NS_OK;
 }
 
 // static
 void
 nsFocusManager::Shutdown()
 {
   NS_IF_RELEASE(sInstance);
 }
 
 NS_IMETHODIMP
 nsFocusManager::Observe(nsISupports *aSubject,
                         const char *aTopic,
                         const PRUnichar *aData)
 {
-  nsDependentString data(aData);
   if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
+    nsDependentString data(aData);
     if (data.EqualsLiteral("accessibility.browsewithcaret")) {
       UpdateCaret(PR_FALSE, PR_TRUE, mFocusedContent);
     }
     else if (data.EqualsLiteral("accessibility.tabfocus_applies_to_xul")) {
       nsIContent::sTabFocusModelAppliesToXUL =
         nsContentUtils::GetBoolPref("accessibility.tabfocus_applies_to_xul",
                                     nsIContent::sTabFocusModelAppliesToXUL);
     }
     else if (data.EqualsLiteral("accessibility.mouse_focuses_formcontrol")) {
       sMouseFocusesFormControl =
         nsContentUtils::GetBoolPref("accessibility.mouse_focuses_formcontrol", PR_FALSE);
     }
+  } else if (!nsCRT::strcmp(aTopic, "xpcom-shutdown")) {
+    mActiveWindow = nsnull;
+    mFocusedWindow = nsnull;
+    mFocusedContent = nsnull;
+    mFirstBlurEvent = nsnull;
+    mFirstFocusEvent = nsnull;
+    mWindowBeingLowered = nsnull;
+    mMouseDownEventHandlingDocument = nsnull;
   }
 
   return NS_OK;
 }
 
 // given a frame content node, retrieve the nsIDOMWindow displayed in it 
 static nsPIDOMWindow*
 GetContentWindow(nsIContent* aContent)