Bug 1447890 part 1. Remove nsISelection::AddRange. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 27 Mar 2018 00:35:22 -0400
changeset 410144 36a8a32f31ba779a1c834339a452f77b5e058d93
parent 410143 d463dcaf44db461ece627c4ac5fffe50c615108b
child 410145 c66a82ff97da825e6c8423f8e526dd2523633e17
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
bugs1447890
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 1447890 part 1. Remove nsISelection::AddRange. r=mystor MozReview-Commit-ID: 1JNLZp7tbII
accessible/base/nsCoreUtils.cpp
accessible/generic/HyperTextAccessible.cpp
dom/base/Selection.cpp
dom/base/nsFocusManager.cpp
dom/base/nsISelection.idl
dom/webidl/Selection.webidl
editor/libeditor/CompositionTransaction.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/SelectionState.cpp
extensions/spellcheck/src/mozInlineSpellChecker.cpp
extensions/spellcheck/src/mozInlineSpellChecker.h
layout/base/PresShell.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/nsFrameSelection.cpp
layout/printing/nsPrintJob.cpp
toolkit/components/find/nsWebBrowserFind.cpp
toolkit/components/find/nsWebBrowserFind.h
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
--- a/accessible/base/nsCoreUtils.cpp
+++ b/accessible/base/nsCoreUtils.cpp
@@ -33,16 +33,17 @@
 
 #include "nsComponentManagerUtils.h"
 
 #include "nsITreeBoxObject.h"
 #include "nsITreeColumns.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLLabelElement.h"
 #include "mozilla/dom/MouseEventBinding.h"
+#include "mozilla/dom/Selection.h"
 
 using namespace mozilla;
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsCoreUtils
 ////////////////////////////////////////////////////////////////////////////////
 
 bool
@@ -253,32 +254,32 @@ nsCoreUtils::ScrollSubstringTo(nsIFrame*
   return ScrollSubstringTo(aFrame, aRange, vertical, horizontal);
 }
 
 nsresult
 nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
                                nsIPresShell::ScrollAxis aVertical,
                                nsIPresShell::ScrollAxis aHorizontal)
 {
-  if (!aFrame)
+  if (!aFrame || !aRange) {
     return NS_ERROR_FAILURE;
+  }
 
   nsPresContext *presContext = aFrame->PresContext();
 
   nsCOMPtr<nsISelectionController> selCon;
   aFrame->GetSelectionController(presContext, getter_AddRefs(selCon));
   NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsISelection> selection;
-  selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY,
-                       getter_AddRefs(selection));
+  RefPtr<dom::Selection> selection =
+    selCon->GetDOMSelection(nsISelectionController::SELECTION_ACCESSIBILITY);
 
-  nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(selection));
+  nsCOMPtr<nsISelectionPrivate> privSel(do_QueryObject(selection));
   selection->RemoveAllRanges();
-  selection->AddRange(aRange);
+  selection->AddRange(*aRange, IgnoreErrors());
 
   privSel->ScrollIntoViewInternal(
     nsISelectionController::SELECTION_ANCHOR_REGION,
     true, aVertical, aHorizontal);
 
   selection->CollapseToStart();
 
   return NS_OK;
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -1656,21 +1656,26 @@ HyperTextAccessible::SetSelectionBoundsA
   if (!range)
     return false;
 
   if (!OffsetsToDOMRange(startOffset, endOffset, range))
     return false;
 
   // If new range was created then add it, otherwise notify selection listeners
   // that existing selection range was changed.
-  if (aSelectionNum == static_cast<int32_t>(rangeCount))
-    return NS_SUCCEEDED(domSel->AddRange(range));
+  if (aSelectionNum == static_cast<int32_t>(rangeCount)) {
+    IgnoredErrorResult err;
+    domSel->AddRange(*range, err);
+    return !err.Failed();
+  }
 
   domSel->RemoveRange(range);
-  return NS_SUCCEEDED(domSel->AddRange(range));
+  IgnoredErrorResult err;
+  domSel->AddRange(*range, err);
+  return !err.Failed();
 }
 
 bool
 HyperTextAccessible::RemoveFromSelection(int32_t aSelectionNum)
 {
   dom::Selection* domSel = DOMSelection();
   if (!domSel)
     return false;
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -2283,31 +2283,16 @@ Selection::RemoveAllRangesTemporarily()
   ErrorResult result;
   RemoveAllRanges(result);
   if (result.Failed()) {
     mCachedRange = nullptr;
   }
   return result.StealNSResult();
 }
 
-/** AddRange adds the specified range to the selection
- *  @param aRange is the range to be added
- */
-NS_IMETHODIMP
-Selection::AddRange(nsIDOMRange* aDOMRange)
-{
-  if (!aDOMRange) {
-    return NS_ERROR_NULL_POINTER;
-  }
-  nsRange* range = static_cast<nsRange*>(aDOMRange);
-  ErrorResult result;
-  AddRange(*range, result);
-  return result.StealNSResult();
-}
-
 void
 Selection::AddRangeJS(nsRange& aRange, ErrorResult& aRv)
 {
   AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
   mCalledByJS = true;
   AddRange(aRange, aRv);
 }
 
@@ -4073,19 +4058,18 @@ Selection::SetBaseAndExtent(nsINode& aAn
   }
 
   // Use non-virtual method instead of nsISelection::RemoveAllRanges().
   RemoveAllRanges(aRv);
   if (aRv.Failed()) {
     return;
   }
 
-  rv = AddRange(newRange);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
+  AddRange(*newRange, aRv);
+  if (aRv.Failed()) {
     return;
   }
 
   SetDirection(relativePosition > 0 ? eDirPrevious : eDirNext);
 }
 
 /** SelectionLanguageChange modifies the cursor Bidi level after a change in keyboard direction
  *  @param aLangRTL is true if the new language is right-to-left or false if the new language is left-to-right
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -2429,17 +2429,17 @@ nsFocusManager::UpdateCaret(bool aMoveCa
 }
 
 void
 nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell, nsIContent* aContent)
 {
   nsCOMPtr<nsIDocument> doc = aPresShell->GetDocument();
   if (doc) {
     RefPtr<nsFrameSelection> frameSelection = aPresShell->FrameSelection();
-    nsCOMPtr<nsISelection> domSelection =
+    RefPtr<Selection> domSelection =
       frameSelection->GetSelection(SelectionType::eNormal);
     if (domSelection) {
       // First clear the selection. This way, if there is no currently focused
       // content, the selection will just be cleared.
       domSelection->RemoveAllRanges();
       if (aContent) {
         ErrorResult rv;
         RefPtr<nsRange> newRange = doc->CreateRange(rv);
@@ -2455,17 +2455,17 @@ nsFocusManager::MoveCaretToFocus(nsIPres
         if (!aContent->GetFirstChild() ||
             aContent->IsNodeOfType(nsINode::eHTML_FORM_CONTROL)) {
           // If current focus node is a leaf, set range to before the
           // node by using the parent as a container.
           // This prevents it from appearing as selected.
           newRange->SetStartBefore(*aContent, IgnoreErrors());
           newRange->SetEndBefore(*aContent, IgnoreErrors());
         }
-        domSelection->AddRange(newRange);
+        domSelection->AddRange(*newRange, IgnoreErrors());
         domSelection->CollapseToStart();
       }
     }
   }
 }
 
 nsresult
 nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
--- a/dom/base/nsISelection.idl
+++ b/dom/base/nsISelection.idl
@@ -109,21 +109,16 @@ interface nsISelection : nsISupports
 
     /**
      * Adds all children of the specified node to the selection.
      * @param parentNode  the parent of the children to be added to the selection.
      */
     void selectAllChildren(in nsIDOMNode parentNode); 
 
     /**
-     * Adds a range to the current selection.
-     */
-    void addRange(in nsIDOMRange range);
- 
-    /**
      * Removes a range from the current selection.
      */
     void removeRange(in nsIDOMRange range);
 
     /**
      * Removes all ranges from the current selection.
      */
     void removeAllRanges();
--- a/dom/webidl/Selection.webidl
+++ b/dom/webidl/Selection.webidl
@@ -15,16 +15,19 @@ interface Selection {
   readonly attribute unsigned long anchorOffset;
   readonly attribute Node?         focusNode;
   readonly attribute unsigned long focusOffset;
   readonly attribute boolean       isCollapsed;
   readonly attribute unsigned long rangeCount;
   readonly attribute DOMString     type;
   [Throws]
   Range     getRangeAt(unsigned long index);
+  /**
+   * Adds a range to the current selection.
+   */
   [Throws, BinaryName="addRangeJS"]
   void      addRange(Range range);
   [Throws]
   void      removeRange(Range range);
   [Throws]
   void      removeAllRanges();
   [Throws, BinaryName="RemoveAllRanges"]
   void      empty();
--- a/editor/libeditor/CompositionTransaction.cpp
+++ b/editor/libeditor/CompositionTransaction.cpp
@@ -320,18 +320,19 @@ CompositionTransaction::SetIMESelection(
     // Set the range of the clause to selection.
     RefPtr<Selection> selectionOfIME =
       selCon->GetDOMSelection(ToRawSelectionType(textRange.mRangeType));
     if (!selectionOfIME) {
       NS_WARNING("Failed to get IME selection");
       break;
     }
 
-    rv = selectionOfIME->AddRange(clauseRange);
-    if (NS_FAILED(rv)) {
+    IgnoredErrorResult err;
+    selectionOfIME->AddRange(*clauseRange, err);
+    if (err.Failed()) {
       NS_WARNING("Failed to add selection range for a clause of composition");
       break;
     }
 
     // Set the style of the clause.
     rv = selectionOfIME->SetTextRangeStyle(clauseRange,
                                            textRange.mRangeStyle);
     if (NS_FAILED(rv)) {
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -3472,18 +3472,21 @@ EditorBase::JoinNodesImpl(nsINode* aNode
 
     RefPtr<nsRange> newRange;
     nsresult rv = nsRange::CreateRange(range.mStartContainer,
                                        range.mStartOffset,
                                        range.mEndContainer,
                                        range.mEndOffset,
                                        getter_AddRefs(newRange));
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = range.mSelection->AddRange(newRange);
-    NS_ENSURE_SUCCESS(rv, rv);
+    ErrorResult err;
+    range.mSelection->AddRange(*newRange, err);
+    if (NS_WARN_IF(err.Failed())) {
+      return err.StealNSResult();
+    }
   }
 
   if (shouldSetSelection) {
     // Editor wants us to set selection at join point.
     RefPtr<Selection> selection = GetSelection();
     NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     selection->Collapse(aNodeToKeep, AssertedCast<int32_t>(firstNodeLength));
   }
@@ -4879,17 +4882,19 @@ EditorBase::AppendNodeToSelectionAsRange
   int32_t offset = GetChildOffset(aNode, parentNode);
 
   RefPtr<nsRange> range;
   nsresult rv = CreateRange(parentNode, offset, parentNode, offset + 1,
                             getter_AddRefs(range));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
 
-  return selection->AddRange(range);
+  ErrorResult err;
+  selection->AddRange(*range, err);
+  return err.StealNSResult();
 }
 
 nsresult
 EditorBase::ClearSelection()
 {
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   return selection->RemoveAllRanges();
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -83,19 +83,20 @@ SelectionState::RestoreSelection(Selecti
   aSel->RemoveAllRanges();
 
   // set the selection ranges anew
   size_t arrayCount = mArray.Length();
   for (size_t i = 0; i < arrayCount; i++) {
     RefPtr<nsRange> range = mArray[i]->GetRange();
     NS_ENSURE_TRUE(range, NS_ERROR_UNEXPECTED);
 
-    nsresult rv = aSel->AddRange(range);
-    if (NS_FAILED(rv)) {
-      return rv;
+    ErrorResult rv;
+    aSel->AddRange(*range, rv);
+    if (rv.Failed()) {
+      return rv.StealNSResult();
     }
   }
   return NS_OK;
 }
 
 bool
 SelectionState::IsCollapsed()
 {
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -957,21 +957,20 @@ mozInlineSpellChecker::ReplaceWord(nsIDO
   {
     // This range was retrieved from the spellchecker selection. As
     // ranges cannot be shared between selections, we must clone it
     // before adding it to the editor's selection.
     RefPtr<nsRange> editorRange = static_cast<nsRange*>(range.get())->CloneRange();
 
     AutoPlaceholderBatch phb(mTextEditor, nullptr);
 
-    nsCOMPtr<nsISelection> selection;
-    res = mTextEditor->GetSelection(getter_AddRefs(selection));
-    NS_ENSURE_SUCCESS(res, res);
+    RefPtr<Selection> selection = mTextEditor->GetSelection();
+    NS_ENSURE_TRUE(selection, NS_ERROR_UNEXPECTED);
     selection->RemoveAllRanges();
-    selection->AddRange(editorRange);
+    selection->AddRange(*editorRange, IgnoreErrors());
 
     MOZ_ASSERT(mTextEditor);
     mTextEditor->InsertText(newword);
   }
 
   return NS_OK;
 }
 
@@ -1706,29 +1705,33 @@ mozInlineSpellChecker::RemoveRange(Selec
 
 // mozInlineSpellChecker::AddRange
 //
 //    For performance reasons, we have an upper bound on the number of word
 //    ranges we'll add to the spell check selection. Once we reach that upper
 //    bound, stop adding the ranges
 
 nsresult
-mozInlineSpellChecker::AddRange(nsISelection* aSpellCheckSelection,
-                                nsIDOMRange* aRange)
+mozInlineSpellChecker::AddRange(Selection* aSpellCheckSelection,
+                                nsRange* aRange)
 {
   NS_ENSURE_ARG_POINTER(aSpellCheckSelection);
   NS_ENSURE_ARG_POINTER(aRange);
 
   nsresult rv = NS_OK;
 
   if (!SpellCheckSelectionIsFull())
   {
-    rv = aSpellCheckSelection->AddRange(aRange);
-    if (NS_SUCCEEDED(rv))
+    IgnoredErrorResult err;
+    aSpellCheckSelection->AddRange(*aRange, err);
+    if (err.Failed()) {
+      rv = err.StealNSResult();
+    } else {
       mNumWordsInSpellSelection++;
+    }
   }
 
   return rv;
 }
 
 already_AddRefed<Selection>
 mozInlineSpellChecker::GetSpellCheckSelection()
 {
--- a/extensions/spellcheck/src/mozInlineSpellChecker.h
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.h
@@ -227,17 +227,18 @@ public:
                               nsIDOMNode *aNode,
                               int32_t aOffset,
                               nsIDOMRange **aRange);
 
   nsresult CleanupRangesInSelection(mozilla::dom::Selection *aSelection);
 
   nsresult RemoveRange(mozilla::dom::Selection *aSpellCheckSelection,
                        nsRange *aRange);
-  nsresult AddRange(nsISelection *aSpellCheckSelection, nsIDOMRange * aRange);
+  nsresult AddRange(mozilla::dom::Selection *aSpellCheckSelection,
+                    nsRange* aRange);
   bool     SpellCheckSelectionIsFull() { return mNumWordsInSpellSelection >= mMaxNumWordsInSpellSelection; }
 
   nsresult MakeSpellCheckRange(nsIDOMNode* aStartNode, int32_t aStartOffset,
                                nsIDOMNode* aEndNode, int32_t aEndOffset,
                                nsRange** aRange);
 
   // DOM and editor event registration helper routines
   nsresult RegisterEventListeners();
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -3183,17 +3183,17 @@ PresShell::GoToAnchor(const nsAString& a
     while (content && content->GetFirstChild()) {
       content = content->GetFirstChild();
     }
     jumpToRange->SelectNodeContents(*content, IgnoreErrors());
     // Select the anchor
     RefPtr<Selection> sel = mSelection->GetSelection(SelectionType::eNormal);
     if (sel) {
       sel->RemoveAllRanges();
-      sel->AddRange(jumpToRange);
+      sel->AddRange(*jumpToRange, IgnoreErrors());
       if (!selectAnchor) {
         // Use a caret (collapsed selection) at the start of the anchor
         sel->CollapseToStart();
       }
     }
     // Selection is at anchor.
     // Now focus the document itself if focus is on an element within it.
     nsPIDOMWindowOuter *win = mDocument->GetWindow();
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -26,16 +26,17 @@
 #include "nsIDOMElement.h"
 #include "nsIPresShell.h"
 
 #include <algorithm>
 #include "nsIDOMNodeList.h" //for selection setting helper func
 #include "nsRange.h" //for selection setting helper func
 #include "nsINode.h"
 #include "nsPIDOMWindow.h" //needed for notify selection changed to update the menus ect.
+#include "nsQueryObject.h"
 
 #include "nsFocusManager.h"
 #include "nsPresState.h"
 #include "nsAttrValueInlines.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/TextEditRules.h"
 #include "nsContentUtils.h"
 #include "nsTextNode.h"
@@ -870,36 +871,39 @@ nsTextControlFrame::SetSelectionInternal
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the selection, clear it and add the new range to it!
   nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
   NS_ASSERTION(txtCtrl, "Content not a text control element");
   nsISelectionController* selCon = txtCtrl->GetSelectionController();
   NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsISelection> selection;
-  selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
+  RefPtr<Selection> selection =
+    selCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection, &rv);
+  nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryObject(selection, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsDirection direction;
   if (aDirection == eNone) {
     // Preserve the direction
     direction = selPriv->GetSelectionDirection();
   } else {
     direction = (aDirection == eBackward) ? eDirPrevious : eDirNext;
   }
 
   rv = selection->RemoveAllRanges();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = selection->AddRange(range);  // NOTE: can destroy the world
-  NS_ENSURE_SUCCESS(rv, rv);
+  ErrorResult err;
+  selection->AddRange(*range, err);  // NOTE: can destroy the world
+  if (NS_WARN_IF(err.Failed())) {
+    return err.StealNSResult();
+  }
 
   selPriv->SetSelectionDirection(direction);
   return rv;
 }
 
 nsresult
 nsTextControlFrame::ScrollSelectionIntoView()
 {
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -1376,17 +1376,17 @@ nsFrameSelection::TakeFocus(nsIContent* 
     if (aMultipleSelection) {
       // Remove existing collapsed ranges as there's no point in having
       // non-anchor/focus collapsed ranges.
       mDomSelections[index]->RemoveCollapsedRanges();
 
       RefPtr<nsRange> newRange = new nsRange(aNewFocus);
 
       newRange->CollapseTo(aNewFocus, aContentOffset);
-      mDomSelections[index]->AddRange(newRange);
+      mDomSelections[index]->AddRange(*newRange, IgnoreErrors());
       mBatching = batching;
       mChangesDuringBatching = changes;
     } else {
       bool oldDesiredPosSet = mDesiredPosSet; //need to keep old desired position if it was set.
       mDomSelections[index]->Collapse(aNewFocus, aContentOffset);
       mDesiredPosSet = oldDesiredPosSet; //now reset desired pos back.
       mBatching = batching;
       mChangesDuringBatching = changes;
@@ -2807,17 +2807,19 @@ nsFrameSelection::CreateAndAddRange(nsIN
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
   if (!mDomSelections[index])
     return NS_ERROR_NULL_POINTER;
 
-  return mDomSelections[index]->AddRange(range);
+  ErrorResult err;
+  mDomSelections[index]->AddRange(*range, err);
+  return err.StealNSResult();
 }
 
 // End of Table Selection
 
 void
 nsFrameSelection::SetAncestorLimiter(nsIContent *aLimiter)
 {
   if (mAncestorLimiter != aLimiter) {
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -2166,17 +2166,17 @@ nsPrintJob::UpdateSelectionAndShrinkPrin
   // this function before.
   if (selectionPS) {
     selectionPS->RemoveAllRanges();
   }
   if (selection && selectionPS) {
     int32_t cnt = selection->RangeCount();
     int32_t inx;
     for (inx = 0; inx < cnt; ++inx) {
-        selectionPS->AddRange(selection->GetRangeAt(inx));
+      selectionPS->AddRange(*selection->GetRangeAt(inx), IgnoreErrors());
     }
   }
 
   // If we are trying to shrink the contents to fit on the page
   // we must first locate the "pageContent" frame
   // Then we walk the frame tree and look for the "xmost" frame
   // this is the frame where the right-hand side of the frame extends
   // the furthest
@@ -2587,17 +2587,17 @@ DeleteUnselectedNodes(nsIDocument* aOrig
 
     // Create the range that we want to remove. Note that if startNode or
     // endNode are null CreateRange will fail and we won't remove that section.
     RefPtr<nsRange> range;
     nsresult rv = nsRange::CreateRange(startNode, startOffset, endNode,
                                        endOffset, getter_AddRefs(range));
 
     if (NS_SUCCEEDED(rv) && !range->Collapsed()) {
-      selection->AddRange(range);
+      selection->AddRange(*range, IgnoreErrors());
 
       // Unless we've already added an ellipsis at the start, if we ended mid
       // text node then add ellipsis.
       Text* text = endNode->GetAsText();
       if (!ellipsisOffset && text && endOffset && endOffset < text->Length()) {
         text->InsertData(endOffset, kEllipsis, IgnoreErrors());
         ellipsisOffset += kEllipsis.Length();
       }
@@ -2623,17 +2623,17 @@ DeleteUnselectedNodes(nsIDocument* aOrig
   }
 
   // Add in the last range to the end of the body.
   RefPtr<nsRange> lastRange;
   nsresult rv = nsRange::CreateRange(startNode, startOffset, bodyNode,
                                      bodyNode->GetChildCount(),
                                      getter_AddRefs(lastRange));
   if (NS_SUCCEEDED(rv) && !lastRange->Collapsed()) {
-    selection->AddRange(lastRange);
+    selection->AddRange(*lastRange, IgnoreErrors());
   }
 
   selection->DeleteFromDocument();
   return NS_OK;
 }
 
 //-------------------------------------------------------
 nsresult
--- a/toolkit/components/find/nsWebBrowserFind.cpp
+++ b/toolkit/components/find/nsWebBrowserFind.cpp
@@ -348,31 +348,29 @@ IsInNativeAnonymousSubtree(nsIContent* a
     aContent = bindingParent;
   }
 
   return false;
 }
 
 void
 nsWebBrowserFind::SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow,
-                                        nsIDOMRange* aRange)
+                                        nsRange* aRange)
 {
   nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
   if (!doc) {
     return;
   }
 
   nsIPresShell* presShell = doc->GetShell();
   if (!presShell) {
     return;
   }
 
-  nsRange* range = static_cast<nsRange*>(aRange);
-
-  nsCOMPtr<nsINode> node = range->GetStartContainer();
+  nsCOMPtr<nsINode> node = aRange->GetStartContainer();
   nsCOMPtr<nsIContent> content(do_QueryInterface(node));
   nsIFrame* frame = content->GetPrimaryFrame();
   if (!frame) {
     return;
   }
   nsCOMPtr<nsISelectionController> selCon;
   frame->GetSelectionController(presShell->GetPresContext(),
                                 getter_AddRefs(selCon));
@@ -386,24 +384,22 @@ nsWebBrowserFind::SetSelectionAndScroll(
       if (!f) {
         return;
       }
       tcFrame = do_QueryFrame(f);
       break;
     }
   }
 
-  nsCOMPtr<nsISelection> selection;
-
   selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
-  selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                       getter_AddRefs(selection));
+  RefPtr<Selection> selection =
+    selCon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
   if (selection) {
     selection->RemoveAllRanges();
-    selection->AddRange(aRange);
+    selection->AddRange(*aRange, IgnoreErrors());
 
     nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
     if (fm) {
       if (tcFrame) {
         nsCOMPtr<nsIDOMElement> newFocusedElement(do_QueryInterface(content));
         fm->SetFocus(newFocusedElement, nsIFocusManager::FLAG_NOSCROLL);
       } else {
         nsCOMPtr<nsIDOMElement> result;
@@ -749,17 +745,17 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMW
   rv = find->Find(mSearchString.get(), searchRange, startPt, endPt,
                   getter_AddRefs(foundRange));
 
   if (NS_SUCCEEDED(rv) && foundRange) {
     *aDidFind = true;
     sel->RemoveAllRanges();
     // Beware! This may flush notifications via synchronous
     // ScrollSelectionIntoView.
-    SetSelectionAndScroll(aWindow, foundRange);
+    SetSelectionAndScroll(aWindow, static_cast<nsRange*>(foundRange.get()));
   }
 
   return rv;
 }
 
 // called when we start searching a frame that is not the initial focussed
 // frame. Prepare the frame to be searched. we clear the selection, so that the
 // search starts from the top of the frame.
--- a/toolkit/components/find/nsWebBrowserFind.h
+++ b/toolkit/components/find/nsWebBrowserFind.h
@@ -58,17 +58,17 @@ protected:
   nsresult OnStartSearchFrame(nsPIDOMWindowOuter* aWindow);
   nsresult OnEndSearchFrame(nsPIDOMWindowOuter* aWindow);
 
   already_AddRefed<nsISelection> GetFrameSelection(nsPIDOMWindowOuter* aWindow);
   nsresult ClearFrameSelection(nsPIDOMWindowOuter* aWindow);
 
   nsresult OnFind(nsPIDOMWindowOuter* aFoundWindow);
 
-  void SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow, nsIDOMRange* aRange);
+  void SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow, nsRange* aRange);
 
   nsresult GetRootNode(nsIDOMDocument* aDomDoc, nsIDOMNode** aNode);
   nsresult GetSearchLimits(nsRange* aRange,
                            nsRange* aStartPt, nsRange* aEndPt,
                            nsIDOMDocument* aDoc, nsISelection* aSel,
                            bool aWrap);
   nsresult SetRangeAroundDocument(nsRange* aSearchRange,
                                   nsRange* aStartPoint,
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -626,17 +626,17 @@ nsTypeAheadFind::FindItNow(nsIPresShell 
         GetSelection(presShell, getter_AddRefs(selectionController),
                      getter_AddRefs(selection));
       }
       mSelectionController = do_GetWeakReference(selectionController);
 
       // Select the found text
       if (selection) {
         selection->RemoveAllRanges();
-        selection->AddRange(returnRange);
+        selection->AddRange(*returnRange, IgnoreErrors());
       }
 
       if (!mFoundEditable && fm) {
         fm->MoveFocus(window->GetOuterWindow(),
                       nullptr, nsIFocusManager::MOVEFOCUS_CARET,
                       nsIFocusManager::FLAG_NOSCROLL | nsIFocusManager::FLAG_NOSWITCHFRAME,
                       getter_AddRefs(mFoundLink));
       }