Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / editing / FrameSelection.cpp
index e8802b2..a737752 100644 (file)
@@ -222,7 +222,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);
 
@@ -1838,6 +1838,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);