Bug 795804 - Use WeakPtr for nsTextEditorState where appropriate; r=ehsan a=akeybl
authorAryeh Gregor <ayg@aryeh.name>
Wed, 10 Oct 2012 15:22:27 -0400
changeset 116580 67d247b7a7ab904f0269d7919177c0e6f5c53119
parent 116579 b62f5e245b7f32a0b820857f3101a748704a50ce
child 116581 ef941370f8d2fe0d4dd2135c042f574354a2e6de
push id239
push userakeybl@mozilla.com
push dateThu, 03 Jan 2013 21:54:43 +0000
treeherdermozilla-release@3a7b66445659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, akeybl
bugs795804
milestone18.0a2
Bug 795804 - Use WeakPtr for nsTextEditorState where appropriate; r=ehsan a=akeybl
content/html/content/src/nsTextEditorState.cpp
content/html/content/src/nsTextEditorState.h
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -1005,39 +1005,41 @@ nsTextEditorState::GetSelectionControlle
 }
 
 // Helper class, used below in BindToFrame().
 class PrepareEditorEvent : public nsRunnable {
 public:
   PrepareEditorEvent(nsTextEditorState &aState,
                      nsIContent *aOwnerContent,
                      const nsAString &aCurrentValue)
-    : mState(aState)
+    : mState(aState.asWeakPtr())
     , mOwnerContent(aOwnerContent)
     , mCurrentValue(aCurrentValue)
   {
-    mState.mValueTransferInProgress = true;
+    aState.mValueTransferInProgress = true;
   }
 
   NS_IMETHOD Run() {
+    NS_ENSURE_TRUE(mState, NS_ERROR_NULL_POINTER);
+
     // Transfer the saved value to the editor if we have one
     const nsAString *value = nullptr;
     if (!mCurrentValue.IsEmpty()) {
       value = &mCurrentValue;
     }
 
-    mState.PrepareEditor(value);
+    mState->PrepareEditor(value);
 
-    mState.mValueTransferInProgress = false;
+    mState->mValueTransferInProgress = false;
 
     return NS_OK;
   }
 
 private:
-  nsTextEditorState &mState;
+  WeakPtr<nsTextEditorState> mState;
   nsCOMPtr<nsIContent> mOwnerContent; // strong reference
   nsAutoString mCurrentValue;
 };
 
 nsresult
 nsTextEditorState::BindToFrame(nsTextControlFrame* aFrame)
 {
   NS_ASSERTION(aFrame, "The frame to bind to should be valid");
--- a/content/html/content/src/nsTextEditorState.h
+++ b/content/html/content/src/nsTextEditorState.h
@@ -8,16 +8,17 @@
 #define nsTextEditorState_h__
 
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsITextControlElement.h"
 #include "nsITextControlFrame.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIContent.h"
+#include "mozilla/WeakPtr.h"
 
 class nsTextInputListener;
 class nsTextControlFrame;
 class nsTextInputSelectionImpl;
 class nsAnonDivObserver;
 class nsISelectionController;
 class nsFrameSelection;
 class nsIEditor;
@@ -112,17 +113,17 @@ class nsITextControlElement;
  *
  *   * If the text editor state object is unbound from the control's frame, the value is
  *     transferred to the mValue member variable, and will be managed there until a new
  *     frame is bound to the text editor state object.
  */
 
 class RestoreSelectionState;
 
-class nsTextEditorState {
+class nsTextEditorState : public mozilla::SupportsWeakPtr<nsTextEditorState> {
 public:
   explicit nsTextEditorState(nsITextControlElement* aOwningElement);
   ~nsTextEditorState();
 
   void Traverse(nsCycleCollectionTraversalCallback& cb);
   void Unlink();
 
   nsIEditor* GetEditor();