Index: Source/core/editing/FrameSelection.cpp |
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp |
index 7301e5ff67b7d9e8111f4aac4ccdbd0775a7b577..449637f07faa4e0477c284d393e24ca172fff521 100644 |
--- a/Source/core/editing/FrameSelection.cpp |
+++ b/Source/core/editing/FrameSelection.cpp |
@@ -223,7 +223,7 @@ void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec |
bool shouldClearTypingStyle = options & ClearTypingStyle; |
EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
- VisibleSelection s = newSelection; |
+ VisibleSelection s = validateSelection(newSelection); |
if (shouldAlwaysUseDirectionalSelection(m_frame)) |
s.setIsDirectional(true); |
@@ -1848,6 +1848,28 @@ void FrameSelection::didChangeVisibleSelection() |
m_observingVisibleSelection = false; |
} |
+VisibleSelection FrameSelection::validateSelection(const VisibleSelection& selection) |
+{ |
+ if (!m_frame || selection.isNone()) |
+ return selection; |
+ |
+ Position base = selection.base(); |
+ Position extent = selection.extent(); |
+ bool isBaseValid = base.document() == m_frame->document(); |
+ bool isExtentValid = extent.document() == m_frame->document(); |
+ |
+ if (isBaseValid && isExtentValid) |
+ return selection; |
+ |
+ VisibleSelection newSelection; |
+ if (isBaseValid) { |
+ newSelection.setWithoutValidation(base, base); |
+ } else if (isExtentValid) { |
+ newSelection.setWithoutValidation(extent, extent); |
+ } |
+ return newSelection; |
+} |
+ |
void FrameSelection::startObservingVisibleSelectionChange() |
{ |
ASSERT(!m_observingVisibleSelection); |