Bug 516237, r=enndeakin, sr=neil
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 24 Nov 2009 17:19:11 +0200
changeset 33123 70b578cc2cf78bc0c5fcfd491944efe95b906975
parent 33122 d3dd5d4a97ccfecfa4a266dfac66f448ccd1d4e1
child 33124 cc03e11b9e7231681d3cff8ea42d5a8fad88480f
child 33176 9af54456e723ab465e79c2248b76e56e1a95a393
push id794
push useropettay@mozilla.com
push dateTue, 24 Nov 2009 15:51:11 +0000
reviewersenndeakin, neil
bugs516237
milestone1.9.2b4pre
Bug 516237, r=enndeakin, sr=neil
layout/xul/base/src/tree/src/nsTreeSelection.cpp
layout/xul/base/src/tree/src/nsTreeSelection.h
--- a/layout/xul/base/src/tree/src/nsTreeSelection.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeSelection.cpp
@@ -279,37 +279,40 @@ NS_INTERFACE_MAP_BEGIN(nsTreeSelection)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TreeSelection)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF(nsTreeSelection)
 NS_IMPL_RELEASE(nsTreeSelection)
 
 NS_IMETHODIMP nsTreeSelection::GetTree(nsITreeBoxObject * *aTree)
 {
-  NS_IF_ADDREF(mTree);
-  *aTree = mTree;
+  NS_IF_ADDREF(*aTree = mTree);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsTreeSelection::SetTree(nsITreeBoxObject * aTree)
 {
   if (mSelectTimer) {
     mSelectTimer->Cancel();
     mSelectTimer = nsnull;
   }
-  mTree = aTree; // WEAK
+
+  // Make sure aTree really implements nsITreeBoxObject!
+  mTree = do_QueryInterface(aTree);
+  NS_ENSURE_STATE(mTree || !aTree);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsTreeSelection::GetSingle(PRBool* aSingle)
 {
   if (!mTree)
     return NS_ERROR_NULL_POINTER;
 
   nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mTree);
+  NS_ENSURE_STATE(boxObject);
 
   nsCOMPtr<nsIDOMElement> element;
   boxObject->GetElement(getter_AddRefs(element));
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(element);
 
   static nsIContent::AttrValuesArray strings[] =
     {&nsGkAtoms::single, &nsGkAtoms::cell, &nsGkAtoms::text, nsnull};
--- a/layout/xul/base/src/tree/src/nsTreeSelection.h
+++ b/layout/xul/base/src/tree/src/nsTreeSelection.h
@@ -61,17 +61,17 @@ public:
   friend struct nsTreeRange;
 
 protected:
   nsresult FireOnSelectHandler();
   static void SelectCallback(nsITimer *aTimer, void *aClosure);
 
 protected:
   // Members
-  nsITreeBoxObject* mTree; // [Weak]. The tree will hold on to us through the view and let go when it dies.
+  nsCOMPtr<nsITreeBoxObject> mTree; // The tree will hold on to us through the view and let go when it dies.
 
   PRBool mSuppressed; // Whether or not we should be firing onselect events.
   PRInt32 mCurrentIndex; // The item to draw the rect around. The last one clicked, etc.
   nsCOMPtr<nsITreeColumn> mCurrentColumn;
   PRInt32 mShiftSelectPivot; // Used when multiple SHIFT+selects are performed to pivot on.
 
   nsTreeRange* mFirstRange; // Our list of ranges.