Title: [267439] trunk
Revision
267439
Author
[email protected]
Date
2020-09-22 15:21:43 -0700 (Tue, 22 Sep 2020)

Log Message

REGRESSION(r266075): WebContent process crashes at TextManipulationController::getPath
https://bugs.webkit.org/show_bug.cgi?id=216846

Reviewed by Wenson Hsieh.

Source/WebCore:

TextIterator does not visit node that has no renderer, so if node has become hidden, TextManipulationController
will not find content node in paragraph range during replacement.

API Test: TextManipulation.CompleteTextManipulationParagraphBecomesHidden

* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::replace):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (267438 => 267439)


--- trunk/Source/WebCore/ChangeLog	2020-09-22 22:10:35 UTC (rev 267438)
+++ trunk/Source/WebCore/ChangeLog	2020-09-22 22:21:43 UTC (rev 267439)
@@ -1,3 +1,18 @@
+2020-09-22  Sihui Liu  <[email protected]>
+
+        REGRESSION(r266075): WebContent process crashes at TextManipulationController::getPath
+        https://bugs.webkit.org/show_bug.cgi?id=216846
+
+        Reviewed by Wenson Hsieh.
+
+        TextIterator does not visit node that has no renderer, so if node has become hidden, TextManipulationController 
+        will not find content node in paragraph range during replacement.
+
+        API Test: TextManipulation.CompleteTextManipulationParagraphBecomesHidden
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::TextManipulationController::replace):
+
 2020-09-22  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Atomic inline-level box with margin is mispositioned

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (267438 => 267439)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-09-22 22:10:35 UTC (rev 267438)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-09-22 22:21:43 UTC (rev 267439)
@@ -828,6 +828,9 @@
         }
     }
 
+    if (!firstContentNode)
+        return ManipulationFailureType::ContentChanged;
+
     while (lastChildOfCommonAncestorInRange && lastChildOfCommonAncestorInRange->parentNode() != commonAncestor)
         lastChildOfCommonAncestorInRange = lastChildOfCommonAncestorInRange->parentNode();
 

Modified: trunk/Tools/ChangeLog (267438 => 267439)


--- trunk/Tools/ChangeLog	2020-09-22 22:10:35 UTC (rev 267438)
+++ trunk/Tools/ChangeLog	2020-09-22 22:21:43 UTC (rev 267439)
@@ -1,3 +1,13 @@
+2020-09-22  Sihui Liu  <[email protected]>
+
+        REGRESSION(r266075): WebContent process crashes at TextManipulationController::getPath
+        https://bugs.webkit.org/show_bug.cgi?id=216846
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+        (TestWebKitAPI::TEST):
+
 2020-09-22  Keith Rollin  <[email protected]>
 
         Refactor build rules in Makefiles and Makefile.shared

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (267438 => 267439)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-09-22 22:10:35 UTC (rev 267438)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-09-22 22:21:43 UTC (rev 267439)
@@ -3195,6 +3195,46 @@
         [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"]);
 }
 
+TEST(TextManipulation, CompleteTextManipulationParagraphBecomesHidden)
+{
+    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView _setTextManipulationDelegate:delegate.get()];
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html>"
+        "<head><style> .hidden { display: none; } </style></head>"
+        "<body><span>hello</span></body>"];
+
+    done = false;
+    [webView _startTextManipulationsWithConfiguration:nil completion:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    auto items = [delegate items];
+    EXPECT_EQ(items.count, 1UL);
+    EXPECT_EQ(items[0].tokens.count, 1UL);
+    EXPECT_WK_STREQ("hello", items[0].tokens[0].content);
+
+    done = false;
+    [webView evaluateJavaScript:@"document.querySelector('span').classList.add('hidden');" completionHandler:^(id result, NSError *) {
+        EXPECT_NULL(result);
+        done = true;
+    }];
+
+    done = false;
+    __block auto item = createItem(items[0].identifier, {{ items[0].tokens[0].identifier, @"Hello" }});
+    [webView _completeTextManipulationForItems:@[item.get()] completion:^(NSArray<NSError *> *errors) {
+        EXPECT_EQ(errors.count, 1UL);
+        EXPECT_EQ(errors.firstObject.domain, _WKTextManipulationItemErrorDomain);
+        EXPECT_EQ(errors.firstObject.code, _WKTextManipulationItemErrorContentChanged);
+        EXPECT_EQ(errors.firstObject.userInfo[_WKTextManipulationItemErrorItemKey], item.get());
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_WK_STREQ("<span class=\"hidden\">hello</span>", [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"]);
+}
+
 TEST(TextManipulation, TextManipulationTokenDebugDescription)
 {
     auto token = adoptNS([[_WKTextManipulationToken alloc] init]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to