Title: [249115] trunk
Revision
249115
Author
[email protected]
Date
2019-08-26 13:26:50 -0700 (Mon, 26 Aug 2019)

Log Message

Don't compute upconverted characters twice in buildQuery() in DataDetection.mm
<https://webkit.org/b/201144>
<rdar://problem/54689399>

Reviewed by Brent Fulgham.

Source/WebCore:

* editing/cocoa/DataDetection.mm:
(WebCore::buildQuery): Extract common variables to prevent double
conversion for 8-bit strings.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add
DataDetectorsTestIOS.mm to the project.
* TestWebKitAPI/Tests/ios/DataDetectorsTestIOS.mm: Add a new
test for Data Detectors for phone numbers.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249114 => 249115)


--- trunk/Source/WebCore/ChangeLog	2019-08-26 20:22:05 UTC (rev 249114)
+++ trunk/Source/WebCore/ChangeLog	2019-08-26 20:26:50 UTC (rev 249115)
@@ -1,3 +1,15 @@
+2019-08-26  David Kilzer  <[email protected]>
+
+        Don't compute upconverted characters twice in buildQuery() in DataDetection.mm
+        <https://webkit.org/b/201144>
+        <rdar://problem/54689399>
+
+        Reviewed by Brent Fulgham.
+
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::buildQuery): Extract common variables to prevent double
+        conversion for 8-bit strings.
+
 2019-08-26  Brent Fulgham  <[email protected]>
 
         [FTW] Go back to ID2D1Bitmap as our NativeImage type

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (249114 => 249115)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2019-08-26 20:22:05 UTC (rev 249114)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2019-08-26 20:26:50 UTC (rev 249115)
@@ -363,7 +363,8 @@
     // Build the scan query adding separators.
     // For each fragment the iterator increment is stored as metadata.
     for (TextIterator iterator(contextRange); !iterator.atEnd(); iterator.advance(), iteratorCount++) {
-        size_t currentTextLength = iterator.text().length();
+        StringView currentText = iterator.text();
+        size_t currentTextLength = currentText.length();
         if (!currentTextLength) {
             softLink_DataDetectorsCore_DDScanQueryAddSeparator(scanQuery, DDTextCoalescingTypeHardBreak);
             if (iteratorCount > maxFragmentWithHardBreak)
@@ -371,7 +372,8 @@
             continue;
         }
         // Test for white space nodes, we're coalescing them.
-        const UniChar* currentCharPtr = iterator.text().upconvertedCharacters();
+        auto currentTextUpconvertedCharacters = currentText.upconvertedCharacters();
+        const UniChar* currentCharPtr = currentTextUpconvertedCharacters.get();
         
         bool containsOnlyWhiteSpace = true;
         bool hasTab = false;
@@ -410,8 +412,8 @@
             continue;
         }
         
-        RetainPtr<CFStringRef> currentText = adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, iterator.text().upconvertedCharacters(), iterator.text().length()));
-        softLink_DataDetectorsCore_DDScanQueryAddTextFragment(scanQuery, currentText.get(), CFRangeMake(0, currentTextLength), (void *)iteratorCount, (DDTextFragmentMode)0, DDTextCoalescingTypeNone);
+        auto currentTextCFString = adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, currentTextUpconvertedCharacters.get(), currentTextLength));
+        softLink_DataDetectorsCore_DDScanQueryAddTextFragment(scanQuery, currentTextCFString.get(), CFRangeMake(0, currentTextLength), (void *)iteratorCount, (DDTextFragmentMode)0, DDTextCoalescingTypeNone);
         fragmentCount++;
     }
 }

Modified: trunk/Tools/ChangeLog (249114 => 249115)


--- trunk/Tools/ChangeLog	2019-08-26 20:22:05 UTC (rev 249114)
+++ trunk/Tools/ChangeLog	2019-08-26 20:26:50 UTC (rev 249115)
@@ -1,3 +1,16 @@
+2019-08-26  David Kilzer  <[email protected]>
+
+        Don't compute upconverted characters twice in buildQuery() in DataDetection.mm
+        <https://webkit.org/b/201144>
+        <rdar://problem/54689399>
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add
+        DataDetectorsTestIOS.mm to the project.
+        * TestWebKitAPI/Tests/ios/DataDetectorsTestIOS.mm: Add a new
+        test for Data Detectors for phone numbers.
+
 2019-08-26  Wenson Hsieh  <[email protected]>
 
         REGRESSION (iOS 13): Tests that simulate multiple back-to-back single taps fail or time out

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (249114 => 249115)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-08-26 20:22:05 UTC (rev 249114)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-08-26 20:26:50 UTC (rev 249115)
@@ -211,6 +211,7 @@
 		4135FB852011FABF00332139 /* libWebCoreTestSupport.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4135FB862011FABF00332139 /* libWebCoreTestSupport.dylib */; };
 		414AD6862285D1C000777F2D /* StorageQuota.mm in Sources */ = {isa = PBXBuildFile; fileRef = 414AD6852285D1B000777F2D /* StorageQuota.mm */; };
 		41882F0321010C0D002FF288 /* ProcessPreWarming.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41882F0221010A70002FF288 /* ProcessPreWarming.mm */; };
+		44077BB123144B5000179E2D /* DataDetectorsTestIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */; };
 		4433A396208044140091ED57 /* SynchronousTimeoutTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */; };
 		44817A2F1F0486BF00003810 /* WKRequestActivatedElementInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */; };
 		448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; };
@@ -1684,6 +1685,7 @@
 		414AD6852285D1B000777F2D /* StorageQuota.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = StorageQuota.mm; sourceTree = "<group>"; };
 		41882F0221010A70002FF288 /* ProcessPreWarming.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProcessPreWarming.mm; sourceTree = "<group>"; };
 		41973B5C1AF22875006C7B36 /* SharedBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBuffer.cpp; sourceTree = "<group>"; };
+		44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorsTestIOS.mm; sourceTree = "<group>"; };
 		442BBF681C91CAD90017087F /* RefLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefLogger.cpp; sourceTree = "<group>"; };
 		4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SynchronousTimeoutTests.mm; sourceTree = "<group>"; };
 		44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKRequestActivatedElementInfo.mm; sourceTree = "<group>"; };
@@ -3047,6 +3049,7 @@
 				2E205BA31F527746005952DD /* AccessibilityTestsIOS.mm */,
 				F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */,
 				F42D634322A1729F00D2FB3A /* AutocorrectionTestsIOS.mm */,
+				44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */,
 				F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */,
 				F4BC0B132146C849002A0478 /* FocusPreservationTests.mm */,
 				CDA93DAC22F4EC2200490A69 /* FullscreenTouchSecheuristicTests.cpp */,
@@ -4422,6 +4425,7 @@
 				46A911592108E6780078D40D /* CustomUserAgent.mm in Sources */,
 				751B05D61F8EAC410028A09E /* DatabaseTrackerTest.mm in Sources */,
 				2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */,
+				44077BB123144B5000179E2D /* DataDetectorsTestIOS.mm in Sources */,
 				9BAD7F3E22690F2000F8DA66 /* DeallocWebViewInEventListener.mm in Sources */,
 				518EE51D20A78D3600E024F3 /* DecidePolicyForNavigationAction.mm in Sources */,
 				2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/DataDetectorsTestIOS.mm (0 => 249115)


--- trunk/Tools/TestWebKitAPI/Tests/ios/DataDetectorsTestIOS.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataDetectorsTestIOS.mm	2019-08-26 20:26:50 UTC (rev 249115)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(DATA_DETECTION) && PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewConfiguration.h>
+#import <wtf/text/WTFString.h>
+
+namespace TestWebKitAPI {
+
+TEST(DataDetectorTests, LoadWKWebViewWithDataDetectorTypePhoneNumber)
+{
+    NSString *const phoneNumber = @"(555) 867-5309";
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().dataDetectorTypes = WKDataDetectorTypePhoneNumber;
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
+    [webView synchronouslyLoadHTMLString:[NSString stringWithFormat:@"<!DOCTYPE><html><head></head><body><p>Call Jenny at %@</p></body></html>", phoneNumber]];
+
+    // Ensure that the phone number is linked by Data Detectors.
+    NSString *linkCount = [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('a').length"];
+    EXPECT_EQ(1, linkCount.intValue);
+    NSString *linkText = [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('a')[0].innerText"];
+    EXPECT_WK_STREQ(phoneNumber, linkText);
+    NSString *linkURL = [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('a')[0].href"];
+    NSString *expectedLinkURL = [NSString stringWithFormat:@"tel:%@", [phoneNumber stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet whitespaceCharacterSet].invertedSet]];
+    EXPECT_WK_STREQ(expectedLinkURL, linkURL);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // ENABLE(DATA_DETECTION) && PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to