Title: [235256] trunk/Source/WebCore
Revision
235256
Author
[email protected]
Date
2018-08-23 16:19:59 -0700 (Thu, 23 Aug 2018)

Log Message

[iOS] Test editing/undo/replace-text-in-node-preserving-markers-crash.html crashes
https://bugs.webkit.org/show_bug.cgi?id=188898

Reviewed by Simon Fraser.

Not all document markers may have a dictation metadata on iOS.

Currently we assume that every marker has dictation alternatives (i.e. DocumentMarker::alternatives()
can be called) when deleting a selection preserving document markers on iOS. However, only markers
for dictation may have dictation alternatives. For example, document markers for misspelled words do
not have dictation metadata by definition. Instead of assuming every marker has dictation alternatives
on iOS we need to check the marker type to determine whether it has associated dictation metadata and
invoke the appropriate DocumentMarkerController::addMarker() overload.

* dom/DocumentMarker.h:
(WebCore::DocumentMarker::isDictation const): Added.
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers): Only access DocumentMarker::alternatives()
and add a dictation marker on iOS if the marker is a dictation marker.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (235255 => 235256)


--- trunk/Source/WebCore/ChangeLog	2018-08-23 23:11:10 UTC (rev 235255)
+++ trunk/Source/WebCore/ChangeLog	2018-08-23 23:19:59 UTC (rev 235256)
@@ -1,3 +1,25 @@
+2018-08-23  Daniel Bates  <[email protected]>
+
+        [iOS] Test editing/undo/replace-text-in-node-preserving-markers-crash.html crashes
+        https://bugs.webkit.org/show_bug.cgi?id=188898
+
+        Reviewed by Simon Fraser.
+
+        Not all document markers may have a dictation metadata on iOS.
+
+        Currently we assume that every marker has dictation alternatives (i.e. DocumentMarker::alternatives()
+        can be called) when deleting a selection preserving document markers on iOS. However, only markers
+        for dictation may have dictation alternatives. For example, document markers for misspelled words do
+        not have dictation metadata by definition. Instead of assuming every marker has dictation alternatives
+        on iOS we need to check the marker type to determine whether it has associated dictation metadata and
+        invoke the appropriate DocumentMarkerController::addMarker() overload.
+
+        * dom/DocumentMarker.h:
+        (WebCore::DocumentMarker::isDictation const): Added.
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers): Only access DocumentMarker::alternatives()
+        and add a dictation marker on iOS if the marker is a dictation marker.
+
 2018-08-23  Mark Lam  <[email protected]>
 
         Move vmEntryGlobalObject() to VM from CallFrame.

Modified: trunk/Source/WebCore/dom/DocumentMarker.h (235255 => 235256)


--- trunk/Source/WebCore/dom/DocumentMarker.h	2018-08-23 23:11:10 UTC (rev 235255)
+++ trunk/Source/WebCore/dom/DocumentMarker.h	2018-08-23 23:19:59 UTC (rev 235256)
@@ -127,6 +127,7 @@
     void shiftOffsets(int delta);
 
 #if PLATFORM(IOS)
+    bool isDictation() const;
     const Vector<String>& alternatives() const;
     void setAlternative(const String&, size_t index);
     id metadata() const;
@@ -222,9 +223,14 @@
     , m_endOffset(endOffset)
     , m_data(DictationAlternativesData { alternatives, metadata })
 {
-    ASSERT(type == DictationPhraseWithAlternatives || type == DictationResult);
+    ASSERT(isDictation());
 }
 
+inline bool DocumentMarker::isDictation() const
+{
+    return m_type == DictationPhraseWithAlternatives || m_type == DictationResult;
+}
+
 inline const Vector<String>& DocumentMarker::alternatives() const
 {
     return WTF::get<DictationAlternativesData>(m_data).alternatives;

Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (235255 => 235256)


--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2018-08-23 23:11:10 UTC (rev 235255)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2018-08-23 23:19:59 UTC (rev 235256)
@@ -769,12 +769,15 @@
     auto markers = copyMarkers(markerController.markersInRange(Range::create(document(), &node, offset, &node, offset + count), DocumentMarker::allMarkers()));
     replaceTextInNode(node, offset, count, replacementText);
     RefPtr<Range> newRange = Range::create(document(), &node, offset, &node, offset + replacementText.length());
-    for (const auto& marker : markers)
+    for (const auto& marker : markers) {
 #if PLATFORM(IOS)
-        markerController.addMarker(newRange.get(), marker.type(), marker.description(), marker.alternatives(), marker.metadata());
-#else
+        if (marker.isDictation()) {
+            markerController.addMarker(newRange.get(), marker.type(), marker.description(), marker.alternatives(), marker.metadata());
+            continue;
+        }
+#endif
         markerController.addMarker(newRange.get(), marker.type(), marker.description());
-#endif // PLATFORM(IOS)
+    }
 }
 
 Position CompositeEditCommand::positionOutsideTabSpan(const Position& position)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to