Implement checked cast for DDResultRef once DDResultGetTypeID() is available
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2018 16:28:33 +0000 (16:28 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2018 16:28:33 +0000 (16:28 +0000)
<https://webkit.org/b/184554>
<rdar://problem/36241894>

Reviewed by Brent Fulgham.

* editing/cocoa/DataDetection.mm:
(WebCore::detectItemAtPositionWithRange): Implement checked cast
for DDResultRef.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230713 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/DataDetection.mm

index 3be85e7..4191e1a 100644 (file)
@@ -1,3 +1,15 @@
+2018-04-17  David Kilzer  <ddkilzer@apple.com>
+
+        Implement checked cast for DDResultRef once DDResultGetTypeID() is available
+        <https://webkit.org/b/184554>
+        <rdar://problem/36241894>
+
+        Reviewed by Brent Fulgham.
+
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::detectItemAtPositionWithRange): Implement checked cast
+        for DDResultRef.
+
 2018-04-17  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Animated GIF imagery with finite looping are falling one loop short
index f445616..d319a11 100644 (file)
 #import "VisibleUnits.h"
 #import <pal/spi/ios/DataDetectorsUISPI.h>
 #import <pal/spi/mac/DataDetectorsSPI.h>
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/text/StringBuilder.h>
 
 #import "DataDetectorsCoreSoftLink.h"
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+WTF_DECLARE_CF_TYPE_TRAIT(DDResult);
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -78,8 +83,11 @@ static RetainPtr<DDActionContext> detectItemAtPositionWithRange(VisiblePosition
     RefPtr<Range> mainResultRange;
     CFIndex resultCount = CFArrayGetCount(results.get());
     for (CFIndex i = 0; i < resultCount; i++) {
-        // FIXME: <rdar://problem/36241894> Implement checked cast for DDResultRef once DDResultGetTypeID() is available
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+        DDResultRef result = checked_cf_cast<DDResultRef>(CFArrayGetValueAtIndex(results.get(), i));
+#else
         DDResultRef result = static_cast<DDResultRef>(const_cast<CF_BRIDGED_TYPE(id) void*>(CFArrayGetValueAtIndex(results.get(), i)));
+#endif
         CFRange resultRangeInContext = DDResultGetRange(result);
         if (hitLocation >= resultRangeInContext.location && (hitLocation - resultRangeInContext.location) < resultRangeInContext.length) {
             mainResult = result;