bug 787704, better to remember addref/release sContent in IMEStateManager, r=masayuki
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 20 Sep 2012 19:13:18 +0300
changeset 107696 f8d30ea0974c940e915b2b8bc5539a182374c7b1
parent 107695 7748dba7f579a800e4420dfbe29ce33311bd9412
child 107697 f627a702d90d0030d850562700ff22a260fd2718
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersmasayuki
bugs787704
milestone18.0a1
bug 787704, better to remember addref/release sContent in IMEStateManager, r=masayuki
content/events/src/nsIMEStateManager.cpp
--- a/content/events/src/nsIMEStateManager.cpp
+++ b/content/events/src/nsIMEStateManager.cpp
@@ -56,17 +56,17 @@ nsIMEStateManager::OnDestroyPresContext(
     return NS_OK;
   nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
   if (widget) {
     IMEState newState = GetNewIMEState(sPresContext, nullptr);
     InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
                               InputContextAction::LOST_FOCUS);
     SetIMEState(newState, nullptr, widget, action);
   }
-  sContent = nullptr;
+  NS_IF_RELEASE(sContent);
   sPresContext = nullptr;
   OnTextStateBlur(nullptr, nullptr);
   return NS_OK;
 }
 
 nsresult
 nsIMEStateManager::OnRemoveContent(nsPresContext* aPresContext,
                                    nsIContent* aContent)
@@ -84,17 +84,17 @@ nsIMEStateManager::OnRemoveContent(nsPre
     if (NS_FAILED(rv))
       widget->ResetInputState();
     IMEState newState = GetNewIMEState(sPresContext, nullptr);
     InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
                               InputContextAction::LOST_FOCUS);
     SetIMEState(newState, nullptr, widget, action);
   }
 
-  sContent = nullptr;
+  NS_IF_RELEASE(sContent);
   sPresContext = nullptr;
 
   return NS_OK;
 }
 
 nsresult
 nsIMEStateManager::OnChangeFocus(nsPresContext* aPresContext,
                                  nsIContent* aContent,
@@ -167,17 +167,20 @@ nsIMEStateManager::OnChangeFocusInternal
     if (oldWidget)
       oldWidget->ResetInputState();
   }
 
   // Update IME state for new focus widget
   SetIMEState(newState, aContent, widget, aAction);
 
   sPresContext = aPresContext;
-  sContent = aContent;
+  if (sContent != aContent) {
+    NS_IF_RELEASE(sContent);
+    NS_IF_ADDREF(sContent = aContent);
+  }
 
   return NS_OK;
 }
 
 void
 nsIMEStateManager::OnInstalledMenuKeyboardListener(bool aInstalling)
 {
   sInstalledMenuKeyboardListener = aInstalling;