Bug 1447889 part 6. Remove nsIDOMRange::SetStart/End. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 27 Mar 2018 00:35:21 -0400
changeset 410135 a55c7ad25f9a81d0451d7c9f191f976c617ab1d3
parent 410134 063c747e3f312941362a5f29ec2feed00c24f8f0
child 410136 37568a081a19a8bd293d2c7a5554c094a40d9564
push id33718
push userbtara@mozilla.com
push dateTue, 27 Mar 2018 09:16:52 +0000
treeherdermozilla-central@97cdd8febc40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1447889
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1447889 part 6. Remove nsIDOMRange::SetStart/End. r=mystor MozReview-Commit-ID: 8yOZMWBexsN
dom/base/nsDocumentEncoder.cpp
dom/base/nsRange.cpp
dom/interfaces/range/nsIDOMRange.idl
toolkit/components/find/nsFind.cpp
toolkit/components/find/nsFind.h
toolkit/components/find/nsWebBrowserFind.cpp
toolkit/components/find/nsWebBrowserFind.h
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.h
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -1161,28 +1161,28 @@ protected:
 
   enum Endpoint
   {
     kStart,
     kEnd
   };
 
   nsresult PromoteRange(nsRange* inRange);
-  nsresult PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
-                                int32_t *ioStartOffset,
-                                int32_t *ioEndOffset);
-  nsresult GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t aOffset,
-                            nsCOMPtr<nsIDOMNode> *outNode, int32_t *outOffset, nsIDOMNode *aCommon);
-  nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, int32_t aOffset);
+  nsresult PromoteAncestorChain(nsCOMPtr<nsINode>* ioNode,
+                                int32_t* ioStartOffset,
+                                int32_t* ioEndOffset);
+  nsresult GetPromotedPoint(Endpoint aWhere, nsINode* aNode, int32_t aOffset,
+                            nsCOMPtr<nsINode>* outNode, int32_t* outOffset, nsINode* aCommon);
+  nsCOMPtr<nsINode> GetChildAt(nsINode *aParent, int32_t aOffset);
   bool IsMozBR(nsIDOMNode* aNode);
   bool IsMozBR(Element* aNode);
-  nsresult GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr<nsIDOMNode> *outParent, int32_t *outOffset);
-  bool IsRoot(nsIDOMNode* aNode);
-  bool IsFirstNode(nsIDOMNode *aNode);
-  bool IsLastNode(nsIDOMNode *aNode);
+  nsresult GetNodeLocation(nsINode *inChild, nsCOMPtr<nsINode> *outParent, int32_t *outOffset);
+  bool IsRoot(nsINode* aNode);
+  bool IsFirstNode(nsINode *aNode);
+  bool IsLastNode(nsINode *aNode);
   bool IsEmptyTextContent(nsIDOMNode* aNode);
   virtual bool IncludeInContext(nsINode *aNode) override;
   virtual int32_t
   GetImmediateContextCount(const nsTArray<nsINode*>& aAncestorArray) override;
 
   bool mIsTextWidget;
 };
 
@@ -1470,121 +1470,127 @@ nsHTMLCopyEncoder::PromoteRange(nsRange*
     return NS_ERROR_UNEXPECTED;
   }
   nsCOMPtr<nsINode> startNode = inRange->GetStartContainer();
   uint32_t startOffset = inRange->StartOffset();
   nsCOMPtr<nsINode> endNode = inRange->GetEndContainer();
   uint32_t endOffset = inRange->EndOffset();
   nsCOMPtr<nsINode> common = inRange->GetCommonAncestor();
 
-  nsCOMPtr<nsIDOMNode> opStartNode;
-  nsCOMPtr<nsIDOMNode> opEndNode;
+  nsCOMPtr<nsINode> opStartNode;
+  nsCOMPtr<nsINode> opEndNode;
   int32_t opStartOffset, opEndOffset;
 
   // examine range endpoints.
   nsresult rv =
-    GetPromotedPoint(kStart, startNode->AsDOMNode(),
+    GetPromotedPoint(kStart, startNode,
                      static_cast<int32_t>(startOffset),
                      address_of(opStartNode), &opStartOffset,
-                     common->AsDOMNode());
+                     common);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = GetPromotedPoint(kEnd, endNode->AsDOMNode(),
+  rv = GetPromotedPoint(kEnd, endNode,
                         static_cast<int32_t>(endOffset),
                         address_of(opEndNode), &opEndOffset,
-                        common->AsDOMNode());
+                        common);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // if both range endpoints are at the common ancestor, check for possible inclusion of ancestors
-  if (opStartNode == common->AsDOMNode() && opEndNode == common->AsDOMNode()) {
+  if (opStartNode == common && opEndNode == common) {
     rv = PromoteAncestorChain(address_of(opStartNode), &opStartOffset, &opEndOffset);
     NS_ENSURE_SUCCESS(rv, rv);
     opEndNode = opStartNode;
   }
 
   // set the range to the new values
-  rv = inRange->SetStart(opStartNode, static_cast<uint32_t>(opStartOffset));
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = inRange->SetEnd(opEndNode, static_cast<uint32_t>(opEndOffset));
-  return rv;
+  ErrorResult err;
+  inRange->SetStart(*opStartNode, static_cast<uint32_t>(opStartOffset), err);
+  if (NS_WARN_IF(err.Failed())) {
+    return err.StealNSResult();
+  }
+  inRange->SetEnd(*opEndNode, static_cast<uint32_t>(opEndOffset), err);
+  if (NS_WARN_IF(err.Failed())) {
+    return err.StealNSResult();
+  }
+  return NS_OK;
 }
 
 
 // PromoteAncestorChain will promote a range represented by [{*ioNode,*ioStartOffset} , {*ioNode,*ioEndOffset}]
 // The promotion is different from that found in getPromotedPoint: it will only promote one endpoint if it can
 // promote the other.  Thus, instead of having a startnode/endNode, there is just the one ioNode.
 nsresult
-nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
-                                        int32_t *ioStartOffset,
-                                        int32_t *ioEndOffset)
+nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsINode>* ioNode,
+                                        int32_t* ioStartOffset,
+                                        int32_t* ioEndOffset)
 {
   if (!ioNode || !ioStartOffset || !ioEndOffset) return NS_ERROR_NULL_POINTER;
 
   nsresult rv = NS_OK;
   bool done = false;
 
-  nsCOMPtr<nsIDOMNode> frontNode, endNode, parent;
+  nsCOMPtr<nsINode> frontNode, endNode, parent;
   int32_t frontOffset, endOffset;
 
   //save the editable state of the ioNode, so we don't promote an ancestor if it has different editable state
-  nsCOMPtr<nsINode> node = do_QueryInterface(*ioNode);
+  nsCOMPtr<nsINode> node = *ioNode;
   bool isEditable = node->IsEditable();
 
   // loop for as long as we can promote both endpoints
   while (!done)
   {
-    node = do_QueryInterface(*ioNode);
-    parent = do_QueryInterface(node->GetParentNode());
+    node = *ioNode;
+    parent = node->GetParentNode();
     if (!parent) {
       done = true;
     } else {
       // passing parent as last param to GetPromotedPoint() allows it to promote only one level
       // up the hierarchy.
       rv = GetPromotedPoint( kStart, *ioNode, *ioStartOffset, address_of(frontNode), &frontOffset, parent);
       NS_ENSURE_SUCCESS(rv, rv);
       // then we make the same attempt with the endpoint
       rv = GetPromotedPoint( kEnd, *ioNode, *ioEndOffset, address_of(endNode), &endOffset, parent);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      nsCOMPtr<nsINode> frontINode = do_QueryInterface(frontNode);
       // if both endpoints were promoted one level and isEditable is the same as the original node,
       // keep looping - otherwise we are done.
-      if ( (frontNode != parent) || (endNode != parent) || (frontINode->IsEditable() != isEditable) )
+      if ( (frontNode != parent) || (endNode != parent) || (frontNode->IsEditable() != isEditable) )
         done = true;
       else
       {
         *ioNode = frontNode;
         *ioStartOffset = frontOffset;
         *ioEndOffset = endOffset;
       }
     }
   }
   return rv;
 }
 
 nsresult
-nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t aOffset,
-                                  nsCOMPtr<nsIDOMNode> *outNode, int32_t *outOffset, nsIDOMNode *common)
+nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsINode* aNode,
+                                    int32_t aOffset, nsCOMPtr<nsINode>* outNode,
+                                    int32_t* outOffset, nsINode* common)
 {
   nsresult rv = NS_OK;
-  nsCOMPtr<nsIDOMNode> node = aNode;
-  nsCOMPtr<nsIDOMNode> parent = aNode;
+  nsCOMPtr<nsINode> node = aNode;
+  nsCOMPtr<nsINode> parent = aNode;
   int32_t offset = aOffset;
   bool    bResetPromotion = false;
 
   // default values
   *outNode = node;
   *outOffset = offset;
 
   if (common == node)
     return NS_OK;
 
   if (aWhere == kStart)
   {
     // some special casing for text nodes
-    nsCOMPtr<nsINode> t = do_QueryInterface(aNode);
+    nsCOMPtr<nsINode> t = aNode;
     if (auto nodeAsText = t->GetAsText())
     {
       // if not at beginning of text node, we are done
       if (offset >  0)
       {
         // unless everything before us in just whitespace.  NOTE: we need a more
         // general solution that truly detects all cases of non-significant
         // whitesace with no false alarms.
@@ -1726,28 +1732,28 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endp
       }
       return rv;
     }
   }
 
   return rv;
 }
 
-nsCOMPtr<nsIDOMNode>
-nsHTMLCopyEncoder::GetChildAt(nsIDOMNode *aParent, int32_t aOffset)
+nsCOMPtr<nsINode>
+nsHTMLCopyEncoder::GetChildAt(nsINode *aParent, int32_t aOffset)
 {
-  nsCOMPtr<nsIDOMNode> resultNode;
+  nsCOMPtr<nsINode> resultNode;
 
   if (!aParent)
     return resultNode;
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
   NS_PRECONDITION(content, "null content in nsHTMLCopyEncoder::GetChildAt");
 
-  resultNode = do_QueryInterface(content->GetChildAt_Deprecated(aOffset));
+  resultNode = content->GetChildAt_Deprecated(aOffset);
 
   return resultNode;
 }
 
 bool
 nsHTMLCopyEncoder::IsMozBR(nsIDOMNode* aNode)
 {
   MOZ_ASSERT(aNode);
@@ -1759,87 +1765,85 @@ bool
 nsHTMLCopyEncoder::IsMozBR(Element* aElement)
 {
   return aElement->IsHTMLElement(nsGkAtoms::br) &&
          aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
                                NS_LITERAL_STRING("_moz"), eIgnoreCase);
 }
 
 nsresult
-nsHTMLCopyEncoder::GetNodeLocation(nsIDOMNode *inChild,
-                                   nsCOMPtr<nsIDOMNode> *outParent,
+nsHTMLCopyEncoder::GetNodeLocation(nsINode *inChild,
+                                   nsCOMPtr<nsINode> *outParent,
                                    int32_t *outOffset)
 {
   NS_ASSERTION((inChild && outParent && outOffset), "bad args");
   if (inChild && outParent && outOffset)
   {
     nsCOMPtr<nsIContent> child = do_QueryInterface(inChild);
     if (!child) {
       return NS_ERROR_NULL_POINTER;
     }
 
     nsIContent* parent = child->GetParent();
     if (!parent) {
       return NS_ERROR_NULL_POINTER;
     }
 
-    *outParent = do_QueryInterface(parent);
+    *outParent = parent;
     *outOffset = parent->ComputeIndexOf(child);
     return NS_OK;
   }
   return NS_ERROR_NULL_POINTER;
 }
 
 bool
-nsHTMLCopyEncoder::IsRoot(nsIDOMNode* aNode)
+nsHTMLCopyEncoder::IsRoot(nsINode* aNode)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   if (!content) {
     return false;
   }
 
   if (mIsTextWidget) {
     return content->IsHTMLElement(nsGkAtoms::div);
   }
 
   return content->IsAnyOfHTMLElements(nsGkAtoms::body,
                                       nsGkAtoms::td,
                                       nsGkAtoms::th);
 }
 
 bool
-nsHTMLCopyEncoder::IsFirstNode(nsIDOMNode *aNode)
+nsHTMLCopyEncoder::IsFirstNode(nsINode *aNode)
 {
-  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   // need to check if any nodes before us are really visible.
   // Mike wrote something for me along these lines in nsSelectionController,
   // but I don't think it's ready for use yet - revisit.
   // HACK: for now, simply consider all whitespace text nodes to be
   // invisible formatting nodes.
-  for (nsIContent* sibling = node->GetPreviousSibling();
+  for (nsIContent* sibling = aNode->GetPreviousSibling();
        sibling;
        sibling = sibling->GetPreviousSibling()) {
     if (!sibling->TextIsOnlyWhitespace()) {
       return false;
     }
   }
 
   return true;
 }
 
 bool
-nsHTMLCopyEncoder::IsLastNode(nsIDOMNode *aNode)
+nsHTMLCopyEncoder::IsLastNode(nsINode *aNode)
 {
-  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   // need to check if any nodes after us are really visible.
   // Mike wrote something for me along these lines in nsSelectionController,
   // but I don't think it's ready for use yet - revisit.
   // HACK: for now, simply consider all whitespace text nodes to be
   // invisible formatting nodes.
-  for (nsIContent* sibling = node->GetNextSibling();
+  for (nsIContent* sibling = aNode->GetNextSibling();
        sibling;
        sibling = sibling->GetNextSibling()) {
     if (sibling->IsElement() && IsMozBR(sibling->AsElement())) {
       // we ignore trailing moz BRs.
       continue;
     }
     if (!sibling->TextIsOnlyWhitespace()) {
       return false;
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -1325,29 +1325,16 @@ nsRange::SetStart(nsINode& aNode, uint32
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
   AutoInvalidateSelection atEndOfBlock(this);
   SetStart(RawRangeBoundary(&aNode, aOffset), aRv);
 }
 
-NS_IMETHODIMP
-nsRange::SetStart(nsIDOMNode* aContainer, uint32_t aOffset)
-{
-  nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
-  if (!container) {
-    return NS_ERROR_DOM_NOT_OBJECT_ERR;
-  }
-
-  ErrorResult rv;
-  SetStart(*container, aOffset, rv);
-  return rv.StealNSResult();
-}
-
 void
 nsRange::SetStart(const RawRangeBoundary& aPoint, ErrorResult& aRv)
 {
   nsINode* newRoot = IsValidBoundary(aPoint.Container());
   if (!newRoot) {
     aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
     return;
   }
@@ -1461,29 +1448,16 @@ nsRange::SetEnd(nsINode& aNode, uint32_t
      !nsContentUtils::CanCallerAccess(&aNode)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
   AutoInvalidateSelection atEndOfBlock(this);
   SetEnd(RawRangeBoundary(&aNode, aOffset), aRv);
 }
 
-NS_IMETHODIMP
-nsRange::SetEnd(nsIDOMNode* aContainer, uint32_t aOffset)
-{
-  nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
-  if (!container) {
-    return NS_ERROR_DOM_NOT_OBJECT_ERR;
-  }
-
-  ErrorResult rv;
-  SetEnd(*container, aOffset, rv);
-  return rv.StealNSResult();
-}
-
 void
 nsRange::SetEnd(const RawRangeBoundary& aPoint, ErrorResult& aRv)
 {
   nsINode* newRoot = IsValidBoundary(aPoint.Container());
   if (!newRoot) {
     aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
     return;
   }
--- a/dom/interfaces/range/nsIDOMRange.idl
+++ b/dom/interfaces/range/nsIDOMRange.idl
@@ -12,18 +12,16 @@
  * http://www.w3.org/TR/DOM-Level-2-Traversal-Range/
  */
 
 [builtinclass, uuid(1f94055c-42e7-4a30-96a1-6a804f1c2d1e)]
 interface nsIDOMRange : nsISupports
 {
   readonly attribute boolean          collapsed;
 
-  void               setStart(in nsIDOMNode refNode, in unsigned long offset);
-  void               setEnd(in nsIDOMNode refNode, in unsigned long offset);
   void               setStartBefore(in nsIDOMNode refNode);
   void               setStartAfter(in nsIDOMNode refNode);
   void               setEndBefore(in nsIDOMNode refNode);
   void               setEndAfter(in nsIDOMNode refNode);
   void               collapse(in boolean toStart);
   void               selectNode(in nsIDOMNode refNode);
   void               selectNodeContents(in nsIDOMNode refNode);
 
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -122,30 +122,30 @@ public:
   virtual nsINode* GetCurrentNode() override;
   virtual bool IsDone() override;
   virtual nsresult PositionAt(nsINode* aCurNode) override;
 
 protected:
   virtual ~nsFindContentIterator() {}
 
 private:
-  static already_AddRefed<nsIDOMRange> CreateRange(nsINode* aNode)
+  static already_AddRefed<nsRange> CreateRange(nsINode* aNode)
   {
     RefPtr<nsRange> range = new nsRange(aNode);
     range->SetMaySpanAnonymousSubtrees(true);
     return range.forget();
   }
 
   nsCOMPtr<nsIContentIterator> mOuterIterator;
   nsCOMPtr<nsIContentIterator> mInnerIterator;
   // Can't use a range here, since we want to represent part of the flattened
   // tree, including native anonymous content.
-  nsCOMPtr<nsIDOMNode> mStartNode;
+  nsCOMPtr<nsINode> mStartNode;
   int32_t mStartOffset;
-  nsCOMPtr<nsIDOMNode> mEndNode;
+  nsCOMPtr<nsINode> mEndNode;
   int32_t mEndOffset;
 
   nsCOMPtr<nsIContent> mStartOuterContent;
   nsCOMPtr<nsIContent> mEndOuterContent;
   bool mFindBackward;
 
   void Reset();
   void MaybeSetupInnerIterator();
@@ -179,19 +179,19 @@ nsFindContentIterator::Init(nsIDOMNode* 
       // Use pre-order in the forward case, so we get parents before children in
       // case we want to prevent descending into a node.
       mOuterIterator = do_CreateInstance(kCPreContentIteratorCID);
     }
     NS_ENSURE_ARG_POINTER(mOuterIterator);
   }
 
   // Set up the search "range" that we will examine
-  mStartNode = aStartNode;
+  mStartNode = do_QueryInterface(aStartNode);
   mStartOffset = aStartOffset;
-  mEndNode = aEndNode;
+  mEndNode = do_QueryInterface(aEndNode);
   mEndOffset = aEndOffset;
 
   return NS_OK;
 }
 
 void
 nsFindContentIterator::First()
 {
@@ -290,22 +290,22 @@ nsFindContentIterator::Reset()
   nsCOMPtr<nsIContent> endContent(do_QueryInterface(mEndNode));
   if (endContent) {
     mEndOuterContent = endContent->FindFirstNonChromeOnlyAccessContent();
   }
 
   // Note: OK to just set up the outer iterator here; if our range has a native
   // anonymous endpoint we'll end up setting up an inner iterator, and reset the
   // outer one in the process.
-  nsCOMPtr<nsINode> node = do_QueryInterface(mStartNode);
+  nsCOMPtr<nsINode> node = mStartNode;
   NS_ENSURE_TRUE_VOID(node);
 
-  nsCOMPtr<nsIDOMRange> range = CreateRange(node);
-  range->SetStart(mStartNode, mStartOffset);
-  range->SetEnd(mEndNode, mEndOffset);
+  RefPtr<nsRange> range = CreateRange(node);
+  range->SetStart(*mStartNode, mStartOffset, IgnoreErrors());
+  range->SetEnd(*mEndNode, mEndOffset, IgnoreErrors());
   mOuterIterator->Init(range);
 
   if (!mFindBackward) {
     if (mStartOuterContent != startContent) {
       // the start node was an anonymous text node
       SetupInnerIterator(mStartOuterContent);
       if (mInnerIterator) {
         mInnerIterator->First();
@@ -387,53 +387,52 @@ nsFindContentIterator::SetupInnerIterato
   RefPtr<TextEditor> textEditor = tcFrame->GetTextEditor();
   if (!textEditor || textEditor->IsDisabled()) {
     return;
   }
 
   nsCOMPtr<nsIDOMElement> rootElement;
   textEditor->GetRootElement(getter_AddRefs(rootElement));
 
-  nsCOMPtr<nsIDOMRange> innerRange = CreateRange(aContent);
-  nsCOMPtr<nsIDOMRange> outerRange = CreateRange(aContent);
+  RefPtr<nsRange> innerRange = CreateRange(aContent);
+  RefPtr<nsRange> outerRange = CreateRange(aContent);
   if (!innerRange || !outerRange) {
     return;
   }
 
   // now create the inner-iterator
   mInnerIterator = do_CreateInstance(kCPreContentIteratorCID);
 
   if (mInnerIterator) {
     innerRange->SelectNodeContents(rootElement);
 
     // fix up the inner bounds, we may have to only lookup a portion
     // of the text control if the current node is a boundary point
     if (aContent == mStartOuterContent) {
-      innerRange->SetStart(mStartNode, mStartOffset);
+      innerRange->SetStart(*mStartNode, mStartOffset, IgnoreErrors());
     }
     if (aContent == mEndOuterContent) {
-      innerRange->SetEnd(mEndNode, mEndOffset);
+      innerRange->SetEnd(*mEndNode, mEndOffset, IgnoreErrors());
     }
     // Note: we just init here. We do First() or Last() later.
     mInnerIterator->Init(innerRange);
 
     // make sure to place the outer-iterator outside the text control so that we
     // don't go there again.
-    nsresult res1, res2;
-    nsCOMPtr<nsIDOMNode> outerNode(do_QueryInterface(aContent));
+    IgnoredErrorResult res1, res2;
     if (!mFindBackward) { // find forward
       // cut the outer-iterator after the current node
-      res1 = outerRange->SetEnd(mEndNode, mEndOffset);
-      res2 = outerRange->SetStartAfter(outerNode);
+      outerRange->SetEnd(*mEndNode, mEndOffset, res1);
+      outerRange->SetStartAfter(*aContent, res2);
     } else { // find backward
       // cut the outer-iterator before the current node
-      res1 = outerRange->SetStart(mStartNode, mStartOffset);
-      res2 = outerRange->SetEndBefore(outerNode);
+      outerRange->SetStart(*mStartNode, mStartOffset, res1);
+      outerRange->SetEndBefore(*aContent, res2);
     }
-    if (NS_FAILED(res1) || NS_FAILED(res2)) {
+    if (res1.Failed() || res2.Failed()) {
       // we are done with the outer-iterator, the inner-iterator will traverse
       // what we want
       outerRange->Collapse(true);
     }
 
     // Note: we just re-init here, using the segment of our search range that
     // is yet to be visited. Thus when we later do mOuterIterator->First() [or
     // mOuterIterator->Last()], we will effectively be on the next node [or
@@ -828,17 +827,17 @@ nsFind::IsBlockNode(nsIContent* aContent
                                     nsGkAtoms::td)) {
     return true;
   }
 
   return nsContentUtils::IsHTMLBlock(aContent);
 }
 
 bool
-nsFind::IsVisibleNode(nsIDOMNode* aDOMNode)
+nsFind::IsVisibleNode(nsINode* aDOMNode)
 {
   nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
   if (!content) {
     return false;
   }
 
   nsIFrame* frame = content->GetPrimaryFrame();
   if (!frame) {
@@ -1244,18 +1243,18 @@ nsFind::Find(const char16_t* aPatText, n
       // Are we done?
       if (DONE_WITH_PINDEX) {
         // Matched the whole string!
 #ifdef DEBUG_FIND
         printf("Found a match!\n");
 #endif
 
         // Make the range:
-        nsCOMPtr<nsIDOMNode> startParent;
-        nsCOMPtr<nsIDOMNode> endParent;
+        nsCOMPtr<nsINode> startParent;
+        nsCOMPtr<nsINode> endParent;
 
         // Check for word break (if necessary)
         if (mWordBreaker) {
           int32_t nextfindex = findex + incr;
 
           char16_t nextChar;
           // If still in array boundaries, get nextChar.
           if (mFindBackward ? (nextfindex >= 0) : (nextfindex < fragLen))
@@ -1269,36 +1268,36 @@ nsFind::Find(const char16_t* aPatText, n
 
           // If a word break isn't there when it needs to be, reset search.
           if (!mWordBreaker->BreakInBetween(&c, 1, &nextChar, 1)) {
             matchAnchorNode = nullptr;
             continue;
           }
         }
 
-        nsCOMPtr<nsIDOMRange> range = new nsRange(tc);
+        RefPtr<nsRange> range = new nsRange(tc);
         if (range) {
           int32_t matchStartOffset, matchEndOffset;
           // convert char index to range point:
           int32_t mao = matchAnchorOffset + (mFindBackward ? 1 : 0);
           if (mFindBackward) {
-            startParent = do_QueryInterface(tc);
-            endParent = matchAnchorNode->AsDOMNode();
+            startParent = tc;
+            endParent = matchAnchorNode;
             matchStartOffset = findex;
             matchEndOffset = mao;
           } else {
-            startParent = matchAnchorNode->AsDOMNode();
-            endParent = do_QueryInterface(tc);
+            startParent = matchAnchorNode;
+            endParent = tc;
             matchStartOffset = mao;
             matchEndOffset = findex + 1;
           }
           if (startParent && endParent &&
               IsVisibleNode(startParent) && IsVisibleNode(endParent)) {
-            range->SetStart(startParent, matchStartOffset);
-            range->SetEnd(endParent, matchEndOffset);
+            range->SetStart(*startParent, matchStartOffset, IgnoreErrors());
+            range->SetEnd(*endParent, matchEndOffset, IgnoreErrors());
             *aRangeRet = range.get();
             NS_ADDREF(*aRangeRet);
           } else {
             // This match is no good -- invisible or bad range
             startParent = nullptr;
           }
         }
 
--- a/toolkit/components/find/nsFind.h
+++ b/toolkit/components/find/nsFind.h
@@ -51,17 +51,17 @@ protected:
 
   // Last block parent, so that we will notice crossing block boundaries:
   nsCOMPtr<nsIDOMNode> mLastBlockParent;
   nsresult GetBlockParent(nsIDOMNode* aNode, nsIDOMNode** aParent);
 
   // Utility routines:
   bool IsBlockNode(nsIContent* aNode);
   bool SkipNode(nsIContent* aNode);
-  bool IsVisibleNode(nsIDOMNode* aNode);
+  bool IsVisibleNode(nsINode* aNode);
 
   // Move in the right direction for our search:
   nsresult NextNode(nsRange* aSearchRange,
                     nsRange* aStartPoint, nsRange* aEndPoint,
                     bool aContinueOk);
 
   // Get the first character from the next node (last if mFindBackward).
   char16_t PeekNextChar(nsRange* aSearchRange,
--- a/toolkit/components/find/nsWebBrowserFind.cpp
+++ b/toolkit/components/find/nsWebBrowserFind.cpp
@@ -445,53 +445,53 @@ nsWebBrowserFind::GetRootNode(nsIDOMDocu
   // For non-HTML documents, the content root node will be the doc element.
   Element* root = doc->GetDocumentElement();
   NS_ENSURE_ARG_POINTER(root);
   NS_ADDREF(*aNode = root->AsDOMNode());
   return NS_OK;
 }
 
 nsresult
-nsWebBrowserFind::SetRangeAroundDocument(nsIDOMRange* aSearchRange,
-                                         nsIDOMRange* aStartPt,
-                                         nsIDOMRange* aEndPt,
+nsWebBrowserFind::SetRangeAroundDocument(nsRange* aSearchRange,
+                                         nsRange* aStartPt,
+                                         nsRange* aEndPt,
                                          nsIDOMDocument* aDoc)
 {
   nsCOMPtr<nsIDOMNode> bodyNode;
   nsresult rv = GetRootNode(aDoc, getter_AddRefs(bodyNode));
   nsCOMPtr<nsIContent> bodyContent(do_QueryInterface(bodyNode));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_ARG_POINTER(bodyContent);
 
   uint32_t childCount = bodyContent->GetChildCount();
 
-  aSearchRange->SetStart(bodyNode, 0);
-  aSearchRange->SetEnd(bodyNode, childCount);
+  aSearchRange->SetStart(*bodyContent, 0, IgnoreErrors());
+  aSearchRange->SetEnd(*bodyContent, childCount, IgnoreErrors());
 
   if (mFindBackwards) {
-    aStartPt->SetStart(bodyNode, childCount);
-    aStartPt->SetEnd(bodyNode, childCount);
-    aEndPt->SetStart(bodyNode, 0);
-    aEndPt->SetEnd(bodyNode, 0);
+    aStartPt->SetStart(*bodyContent, childCount, IgnoreErrors());
+    aStartPt->SetEnd(*bodyContent, childCount, IgnoreErrors());
+    aEndPt->SetStart(*bodyContent, 0, IgnoreErrors());
+    aEndPt->SetEnd(*bodyContent, 0, IgnoreErrors());
   } else {
-    aStartPt->SetStart(bodyNode, 0);
-    aStartPt->SetEnd(bodyNode, 0);
-    aEndPt->SetStart(bodyNode, childCount);
-    aEndPt->SetEnd(bodyNode, childCount);
+    aStartPt->SetStart(*bodyContent, 0, IgnoreErrors());
+    aStartPt->SetEnd(*bodyContent, 0, IgnoreErrors());
+    aEndPt->SetStart(*bodyContent, childCount, IgnoreErrors());
+    aEndPt->SetEnd(*bodyContent, childCount, IgnoreErrors());
   }
 
   return NS_OK;
 }
 
 // Set the range to go from the end of the current selection to the end of the
 // document (forward), or beginning to beginning (reverse). or around the whole
 // document if there's no selection.
 nsresult
-nsWebBrowserFind::GetSearchLimits(nsIDOMRange* aSearchRange,
-                                  nsIDOMRange* aStartPt, nsIDOMRange* aEndPt,
+nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange,
+                                  nsRange* aStartPt, nsRange* aEndPt,
                                   nsIDOMDocument* aDoc, nsISelection* aSel,
                                   bool aWrap)
 {
   NS_ENSURE_ARG_POINTER(aSel);
 
   Selection* sel = aSel->AsSelection();
 
   // There is a selection.
@@ -526,79 +526,79 @@ nsWebBrowserFind::GetSearchLimits(nsIDOM
       return NS_ERROR_UNEXPECTED;
     }
     node = range->GetEndContainer();
     if (!node) {
       return NS_ERROR_UNEXPECTED;
     }
     offset = range->EndOffset();
 
-    aSearchRange->SetStart(node->AsDOMNode(), offset);
-    aSearchRange->SetEnd(bodyNode, childCount);
-    aStartPt->SetStart(node->AsDOMNode(), offset);
-    aStartPt->SetEnd(node->AsDOMNode(), offset);
-    aEndPt->SetStart(bodyNode, childCount);
-    aEndPt->SetEnd(bodyNode, childCount);
+    aSearchRange->SetStart(*node, offset, IgnoreErrors());
+    aSearchRange->SetEnd(*bodyContent, childCount, IgnoreErrors());
+    aStartPt->SetStart(*node, offset, IgnoreErrors());
+    aStartPt->SetEnd(*node, offset, IgnoreErrors());
+    aEndPt->SetStart(*bodyContent, childCount, IgnoreErrors());
+    aEndPt->SetEnd(*bodyContent, childCount, IgnoreErrors());
   }
   // Backward, not wrapping: DocStart to SelStart
   else if (mFindBackwards && !aWrap) {
     range = sel->GetRangeAt(0);
     if (!range) {
       return NS_ERROR_UNEXPECTED;
     }
     node = range->GetStartContainer();
     if (!node) {
       return NS_ERROR_UNEXPECTED;
     }
     offset = range->StartOffset();
 
-    aSearchRange->SetStart(bodyNode, 0);
-    aSearchRange->SetEnd(bodyNode, childCount);
-    aStartPt->SetStart(node->AsDOMNode(), offset);
-    aStartPt->SetEnd(node->AsDOMNode(), offset);
-    aEndPt->SetStart(bodyNode, 0);
-    aEndPt->SetEnd(bodyNode, 0);
+    aSearchRange->SetStart(*bodyContent, 0, IgnoreErrors());
+    aSearchRange->SetEnd(*bodyContent, childCount, IgnoreErrors());
+    aStartPt->SetStart(*node, offset, IgnoreErrors());
+    aStartPt->SetEnd(*node, offset, IgnoreErrors());
+    aEndPt->SetStart(*bodyContent, 0, IgnoreErrors());
+    aEndPt->SetEnd(*bodyContent, 0, IgnoreErrors());
   }
   // Forward, wrapping: DocStart to SelEnd
   else if (!mFindBackwards && aWrap) {
     range = sel->GetRangeAt(count - 1);
     if (!range) {
       return NS_ERROR_UNEXPECTED;
     }
     node = range->GetEndContainer();
     if (!node) {
       return NS_ERROR_UNEXPECTED;
     }
     offset = range->EndOffset();
 
-    aSearchRange->SetStart(bodyNode, 0);
-    aSearchRange->SetEnd(bodyNode, childCount);
-    aStartPt->SetStart(bodyNode, 0);
-    aStartPt->SetEnd(bodyNode, 0);
-    aEndPt->SetStart(node->AsDOMNode(), offset);
-    aEndPt->SetEnd(node->AsDOMNode(), offset);
+    aSearchRange->SetStart(*bodyContent, 0, IgnoreErrors());
+    aSearchRange->SetEnd(*bodyContent, childCount, IgnoreErrors());
+    aStartPt->SetStart(*bodyContent, 0, IgnoreErrors());
+    aStartPt->SetEnd(*bodyContent, 0, IgnoreErrors());
+    aEndPt->SetStart(*node, offset, IgnoreErrors());
+    aEndPt->SetEnd(*node, offset, IgnoreErrors());
   }
   // Backward, wrapping: SelStart to DocEnd
   else if (mFindBackwards && aWrap) {
     range = sel->GetRangeAt(0);
     if (!range) {
       return NS_ERROR_UNEXPECTED;
     }
     node = range->GetStartContainer();
     if (!node) {
       return NS_ERROR_UNEXPECTED;
     }
     offset = range->StartOffset();
 
-    aSearchRange->SetStart(bodyNode, 0);
-    aSearchRange->SetEnd(bodyNode, childCount);
-    aStartPt->SetStart(bodyNode, childCount);
-    aStartPt->SetEnd(bodyNode, childCount);
-    aEndPt->SetStart(node->AsDOMNode(), offset);
-    aEndPt->SetEnd(node->AsDOMNode(), offset);
+    aSearchRange->SetStart(*bodyContent, 0, IgnoreErrors());
+    aSearchRange->SetEnd(*bodyContent, childCount, IgnoreErrors());
+    aStartPt->SetStart(*bodyContent, childCount, IgnoreErrors());
+    aStartPt->SetEnd(*bodyContent, childCount, IgnoreErrors());
+    aEndPt->SetStart(*node, offset, IgnoreErrors());
+    aEndPt->SetEnd(*node, offset, IgnoreErrors());
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWebBrowserFind::GetSearchFrames(bool* aSearchFrames)
 {
   NS_ENSURE_ARG_POINTER(aSearchFrames);
@@ -720,21 +720,19 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMW
 
   // Now make sure the content (for actual finding) and frame (for
   // selection) models are up to date.
   theDoc->FlushPendingNotifications(FlushType::Frames);
 
   nsCOMPtr<nsISelection> sel = GetFrameSelection(aWindow);
   NS_ENSURE_ARG_POINTER(sel);
 
-  nsCOMPtr<nsIDOMRange> searchRange = new nsRange(theDoc);
-  NS_ENSURE_ARG_POINTER(searchRange);
-  nsCOMPtr<nsIDOMRange> startPt = new nsRange(theDoc);
-  NS_ENSURE_ARG_POINTER(startPt);
-  nsCOMPtr<nsIDOMRange> endPt = new nsRange(theDoc);
+  RefPtr<nsRange> searchRange = new nsRange(theDoc);
+  RefPtr<nsRange> startPt = new nsRange(theDoc);
+  RefPtr<nsRange> endPt = new nsRange(theDoc);
   NS_ENSURE_ARG_POINTER(endPt);
 
   nsCOMPtr<nsIDOMRange> foundRange;
 
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(theDoc);
   MOZ_ASSERT(domDoc);
 
   // If !aWrapping, search from selection to end
--- a/toolkit/components/find/nsWebBrowserFind.h
+++ b/toolkit/components/find/nsWebBrowserFind.h
@@ -20,16 +20,17 @@
 
 #define NS_WEB_BROWSER_FIND_CID \
   {0x57cf9383, 0x3405, 0x11d5, {0xbe, 0x5b, 0xaa, 0x20, 0xfa, 0x2c, 0xf3, 0x7c}}
 
 class nsISelection;
 class nsIDOMWindow;
 
 class nsIDocShell;
+class nsRange;
 
 //*****************************************************************************
 // class nsWebBrowserFind
 //*****************************************************************************
 
 class nsWebBrowserFind
   : public nsIWebBrowserFind
   , public nsIWebBrowserFindInFrames
@@ -60,23 +61,23 @@ protected:
   already_AddRefed<nsISelection> GetFrameSelection(nsPIDOMWindowOuter* aWindow);
   nsresult ClearFrameSelection(nsPIDOMWindowOuter* aWindow);
 
   nsresult OnFind(nsPIDOMWindowOuter* aFoundWindow);
 
   void SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow, nsIDOMRange* aRange);
 
   nsresult GetRootNode(nsIDOMDocument* aDomDoc, nsIDOMNode** aNode);
-  nsresult GetSearchLimits(nsIDOMRange* aRange,
-                           nsIDOMRange* aStartPt, nsIDOMRange* aEndPt,
+  nsresult GetSearchLimits(nsRange* aRange,
+                           nsRange* aStartPt, nsRange* aEndPt,
                            nsIDOMDocument* aDoc, nsISelection* aSel,
                            bool aWrap);
-  nsresult SetRangeAroundDocument(nsIDOMRange* aSearchRange,
-                                  nsIDOMRange* aStartPoint,
-                                  nsIDOMRange* aEndPoint,
+  nsresult SetRangeAroundDocument(nsRange* aSearchRange,
+                                  nsRange* aStartPoint,
+                                  nsRange* aEndPoint,
                                   nsIDOMDocument* aDoc);
 
 protected:
   nsString mSearchString;
 
   bool mFindBackwards;
   bool mWrapFind;
   bool mEntireWord;
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsCOMPtr.h"
 #include "nsMemory.h"
 #include "nsIServiceManager.h"
+#include "mozilla/ErrorResult.h"
 #include "mozilla/ModuleUtils.h"
 #include "mozilla/Services.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsCURILoader.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsNetUtil.h"
 #include "nsIURL.h"
 #include "nsIURI.h"
@@ -25,16 +26,17 @@
 #include "nsGenericHTMLElement.h"
 
 #include "nsIDOMNode.h"
 #include "nsIFrame.h"
 #include "nsFrameTraversal.h"
 #include "nsIImageDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDocument.h"
+#include "nsIContent.h"
 #include "nsISelection.h"
 #include "nsTextFragment.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIEditor.h"
 
 #include "nsIDocShellTreeItem.h"
 #include "nsIWebNavigation.h"
 #include "nsIInterfaceRequestor.h"
@@ -51,16 +53,17 @@
 #include "mozilla/dom/Link.h"
 #include "mozilla/dom/Selection.h"
 #include "nsRange.h"
 #include "nsXBLBinding.h"
 
 #include "nsTypeAheadFind.h"
 
 using mozilla::dom::Selection;
+using mozilla::IgnoreErrors;
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTypeAheadFind)
   NS_INTERFACE_MAP_ENTRY(nsITypeAheadFind)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITypeAheadFind)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
 NS_INTERFACE_MAP_END
 
@@ -494,33 +497,33 @@ nsTypeAheadFind::FindItNow(nsIPresShell 
           nsresult rv =
             mStartPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_END,
                                                     returnRange, &compareResult);
           if (NS_SUCCEEDED(rv) && compareResult <= 0) {
             // OK to start at the end of mStartPointRange
             mStartPointRange->Collapse(false);
           } else {
             // Start at the beginning of returnRange
-            returnRange->CloneRange(getter_AddRefs(mStartPointRange));
+            mStartPointRange = returnRange->CloneRange();
             mStartPointRange->Collapse(true);
           }
         } else {
           // We can continue at the start of mStartPointRange if its start is
           // after the end of returnRange or coincides with it.  Otherwise, we
           // need to continue at the end of returnRange.
           int16_t compareResult;
           nsresult rv =
             mStartPointRange->CompareBoundaryPoints(nsIDOMRange::END_TO_START,
                                                     returnRange, &compareResult);
           if (NS_SUCCEEDED(rv) && compareResult >= 0) {
             // OK to start at the start of mStartPointRange
             mStartPointRange->Collapse(true);
           } else {
             // Start at the end of returnRange
-            returnRange->CloneRange(getter_AddRefs(mStartPointRange));
+            mStartPointRange = returnRange->CloneRange();
             mStartPointRange->Collapse(false);
           }
         }
         continue;
       }
 
       mFoundRange = returnRange;
 
@@ -700,18 +703,17 @@ nsTypeAheadFind::FindItNow(nsIPresShell 
                                         getter_AddRefs(presShell),
                                         getter_AddRefs(presContext)))) {
         continue;
       }
 
       if (aFindPrev) {
         // Reverse mode: swap start and end points, so that we start
         // at end of document and go to beginning
-        nsCOMPtr<nsIDOMRange> tempRange;
-        mStartPointRange->CloneRange(getter_AddRefs(tempRange));
+        RefPtr<nsRange> tempRange = mStartPointRange->CloneRange();
         if (!mEndPointRange) {
           mEndPointRange = new nsRange(presShell->GetDocument());
         }
 
         mStartPointRange = mEndPointRange;
         mEndPointRange = tempRange;
       }
 
@@ -791,54 +793,52 @@ nsTypeAheadFind::GetSearchContainers(nsI
   if (!doc)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIContent> rootContent;
   if (doc->IsHTMLOrXHTML()) {
     rootContent = doc->GetBody();
   }
 
-  if (!rootContent)
+  if (!rootContent) {
     rootContent = doc->GetRootElement();
-
-  nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootContent));
-
-  if (!rootNode)
-    return NS_ERROR_FAILURE;
+    if (!rootContent) {
+      return NS_ERROR_FAILURE;
+    }
+  }
 
   if (!mSearchRange) {
     mSearchRange = new nsRange(doc);
   }
-  nsCOMPtr<nsIDOMNode> searchRootNode = rootNode;
+  nsCOMPtr<nsINode> searchRootNode(rootContent);
 
   // Hack for XMLPrettyPrinter. nsFind can't handle complex anonymous content.
   // If the root node has an XBL binding then there's not much we can do in
   // in general, but we can try searching the binding's first child, which
   // in the case of XMLPrettyPrinter contains the visible pretty-printed
   // content.
   nsXBLBinding* binding = rootContent->GetXBLBinding();
   if (binding) {
     nsIContent* anonContent = binding->GetAnonymousContent();
     if (anonContent) {
-      searchRootNode = do_QueryInterface(anonContent->GetFirstChild());
+      searchRootNode = anonContent->GetFirstChild();
     }
   }
-  mSearchRange->SelectNodeContents(searchRootNode);
+  mSearchRange->SelectNodeContents(*searchRootNode, IgnoreErrors());
 
   if (!mStartPointRange) {
     mStartPointRange = new nsRange(doc);
   }
-  mStartPointRange->SetStart(searchRootNode, 0);
+  mStartPointRange->SetStart(*searchRootNode, 0, IgnoreErrors());
   mStartPointRange->Collapse(true); // collapse to start
 
   if (!mEndPointRange) {
     mEndPointRange = new nsRange(doc);
   }
-  nsCOMPtr<nsINode> searchRootTmp = do_QueryInterface(searchRootNode);
-  mEndPointRange->SetEnd(searchRootNode, searchRootTmp->Length());
+  mEndPointRange->SetEnd(*searchRootNode, searchRootNode->Length(), IgnoreErrors());
   mEndPointRange->Collapse(false); // collapse to end
 
   // Consider current selection as null if
   // it's not in the currently focused document
   RefPtr<nsRange> currentSelectionRange;
   nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell();
   if (aSelectionController && selectionPresShell && selectionPresShell == presShell) {
     RefPtr<Selection> selection = aSelectionController->GetDOMSelection(
@@ -861,26 +861,24 @@ nsTypeAheadFind::GetSearchContainers(nsI
     nsCOMPtr<nsINode> startNode;
     if (aFindPrev) {
       startNode = currentSelectionRange->GetStartContainer();
       startOffset = currentSelectionRange->StartOffset();
     } else {
       startNode = currentSelectionRange->GetEndContainer();
       startOffset = currentSelectionRange->EndOffset();
     }
-    nsCOMPtr<nsIDOMNode> newStart;
-    if (startNode) {
-      newStart = startNode->AsDOMNode();
-    } else {
-      newStart = rootNode;
+
+    if (!startNode) {
+      startNode = rootContent;
     }
 
     // We need to set the start point this way, other methods haven't worked
-    mStartPointRange->SelectNode(newStart);
-    mStartPointRange->SetStart(newStart, startOffset);
+    mStartPointRange->SelectNode(*startNode, IgnoreErrors());
+    mStartPointRange->SetStart(*startNode, startOffset, IgnoreErrors());
   }
 
   mStartPointRange->Collapse(true); // collapse to start
 
   presShell.forget(aPresShell);
   presContext.forget(aPresContext);
 
   return NS_OK;
@@ -1185,40 +1183,40 @@ nsTypeAheadFind::IsRangeVisible(nsIDOMRa
   nsCOMPtr<nsINode> node = range->GetStartContainer();
 
   nsIDocument* doc = node->OwnerDoc();
   nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
   if (!presShell) {
     return NS_ERROR_UNEXPECTED;
   }
   RefPtr<nsPresContext> presContext = presShell->GetPresContext();
-  nsCOMPtr<nsIDOMRange> ignored;
+  RefPtr<nsRange> ignored;
   *aResult = IsRangeVisible(presShell, presContext, range,
                             aMustBeInViewPort, false,
                             getter_AddRefs(ignored),
                             nullptr);
   return NS_OK;
 }
 
 bool
 nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
                                 nsPresContext *aPresContext,
                                 nsRange *aRange, bool aMustBeInViewPort,
                                 bool aGetTopVisibleLeaf,
-                                nsIDOMRange **aFirstVisibleRange,
+                                nsRange **aFirstVisibleRange,
                                 bool *aUsesIndependentSelection)
 {
   NS_ASSERTION(aPresShell && aPresContext && aRange && aFirstVisibleRange,
                "params are invalid");
 
   // We need to know if the range start is visible.
   // Otherwise, return the first visible range start
   // in aFirstVisibleRange
 
-  aRange->CloneRange(aFirstVisibleRange);
+  *aFirstVisibleRange = aRange->CloneRange().take();
 
   nsCOMPtr<nsIContent> content =
     do_QueryInterface(aRange->GetStartContainer());
   if (!content) {
     return false;
   }
 
   nsIFrame *frame = content->GetPrimaryFrame();
@@ -1315,22 +1313,24 @@ nsTypeAheadFind::IsRangeVisible(nsIPresS
       rectVisibility =
         aPresShell->GetRectVisibility(frame,
                                       nsRect(nsPoint(0,0), frame->GetSize()),
                                       minDistance);
     }
   }
 
   if (frame) {
-    nsCOMPtr<nsIDOMNode> firstVisibleNode = do_QueryInterface(frame->GetContent());
+    nsINode* firstVisibleNode = frame->GetContent();
 
     if (firstVisibleNode) {
       frame->GetOffsets(startFrameOffset, endFrameOffset);
-      (*aFirstVisibleRange)->SetStart(firstVisibleNode, startFrameOffset);
-      (*aFirstVisibleRange)->SetEnd(firstVisibleNode, endFrameOffset);
+      (*aFirstVisibleRange)->SetStart(*firstVisibleNode, startFrameOffset,
+                                      IgnoreErrors());
+      (*aFirstVisibleRange)->SetEnd(*firstVisibleNode, endFrameOffset,
+                                    IgnoreErrors());
     }
   }
 
   return false;
 }
 
 NS_IMETHODIMP
 nsTypeAheadFind::IsRangeRendered(nsIDOMRange *aRange,
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.h
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.h
@@ -54,17 +54,17 @@ protected:
                              bool *aIsInsideLink, bool *aIsStartingLink);
 
   void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon,
                     nsISelection **aDomSel);
   // *aNewRange may not be collapsed.  If you want to collapse it in a
   // particular way, you need to do it yourself.
   bool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext,
                       nsRange *aRange, bool aMustBeVisible,
-                      bool aGetTopVisibleLeaf, nsIDOMRange **aNewRange,
+                      bool aGetTopVisibleLeaf, nsRange **aNewRange,
                       bool *aUsesIndependentSelection);
   bool IsRangeRendered(nsIPresShell *aPresShell, nsPresContext *aPresContext,
                        nsRange *aRange);
   nsresult FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
                      bool aIsFirstVisiblePreferred, bool aFindPrev,
                      uint16_t* aResult);
   nsresult GetSearchContainers(nsISupports *aContainer,
                                nsISelectionController *aSelectionController,
@@ -98,18 +98,18 @@ protected:
   // Sound is played asynchronously on some platforms.
   // If we destroy mSoundInterface before sound has played, it won't play
   nsCOMPtr<nsISound> mSoundInterface;
   bool mIsSoundInitialized;
 
   // where selection was when user started the find
   nsCOMPtr<nsIDOMRange> mStartFindRange;
   RefPtr<nsRange> mSearchRange;
-  nsCOMPtr<nsIDOMRange> mStartPointRange;
-  nsCOMPtr<nsIDOMRange> mEndPointRange;
+  RefPtr<nsRange> mStartPointRange;
+  RefPtr<nsRange> mEndPointRange;
 
   // Cached useful interfaces
   nsCOMPtr<nsIFind> mFind;
 
   bool mCaseSensitive;
   bool mEntireWord;
 
   bool EnsureFind() {