Bug 1266782 - Use RefPtr to hold document and selection in ExtendPhoneNumberSelection.
MozReview-Commit-ID: 3zAgKt7r8TO
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -856,20 +856,24 @@ AccessibleCaretManager::SelectMoreIfPhon
ExtendPhoneNumberSelection(NS_LITERAL_STRING("backward"));
SetSelectionDirection(eDirNext);
}
void
AccessibleCaretManager::ExtendPhoneNumberSelection(const nsAString& aDirection) const
{
- nsIDocument* doc = mPresShell->GetDocument();
+ if (!mPresShell) {
+ return;
+ }
+
+ RefPtr<nsIDocument> doc = mPresShell->GetDocument();
// Extend the phone number selection until we find a boundary.
- Selection* selection = GetSelection();
+ RefPtr<Selection> selection = GetSelection();
while (selection) {
const nsRange* anchorFocusRange = selection->GetAnchorFocusRange();
if (!anchorFocusRange) {
return;
}
// Backup the anchor focus range since both anchor node and focus node might
@@ -877,16 +881,19 @@ AccessibleCaretManager::ExtendPhoneNumbe
RefPtr<nsRange> oldAnchorFocusRange = anchorFocusRange->CloneRange();
// Save current Focus position, and extend the selection one char.
nsINode* focusNode = selection->GetFocusNode();
uint32_t focusOffset = selection->FocusOffset();
selection->Modify(NS_LITERAL_STRING("extend"),
aDirection,
NS_LITERAL_STRING("character"));
+ if (IsTerminated()) {
+ return;
+ }
// If the selection didn't change, (can't extend further), we're done.
if (selection->GetFocusNode() == focusNode &&
selection->FocusOffset() == focusOffset) {
return;
}
// If the changed selection isn't a valid phone number, we're done.