Title: [226483] trunk/Source
Revision
226483
Author
ddkil...@apple.com
Date
2018-01-05 19:19:57 -0800 (Fri, 05 Jan 2018)

Log Message

Re-enable -Wcast-qual in WebCore for Apple ports
<https://webkit.org/b/177895>
<rdar://problem/34960830>

Reviewed by Joseph Pecoraro.

Source/WebCore:

* Configurations/Base.xcconfig:
(WARNING_CFLAGS): Remove FIXME and add -Wcast-qual back to
arguments.

* crypto/mac/SerializedCryptoKeyWrapMac.mm:
(WebCore::createAndStoreMasterKey):
- Use checked_cf_cast<SecACLRef>().

* editing/cocoa/DataDetection.mm:
(WebCore::detectItemAtPositionWithRange):
- Manually cast CFTypeRef to DDResultRef until
  DDResultGetTypeID() is available as SPI.

* platform/gamepad/mac/HIDGamepad.cpp:
(WebCore::HIDGamepad::initElementsFromArray):
- Use checked_cf_cast<IOHIDElementRef>().

* platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
(WebCore::MediaSampleAVFObjC::createImageSample):
(WebCore::CMSampleBufferIsRandomAccess):
(WebCore::CMSampleBufferIsNonDisplaying):
(WebCore::MediaSampleAVFObjC::createNonDisplayingCopy const):
- Use checked_cf_cast<CFMutableDictionaryRef>() and
  checked_cf_cast<CFDictionaryRef>().

* platform/graphics/cocoa/IOSurface.h:
(WebCore::IOSurface::asLayerContents):
- Use reinterpret_cast<id>() to cast from IOSurfaceRef to id.

* platform/graphics/cocoa/WebCoreDecompressionSession.mm:
(WebCore::WebCoreDecompressionSession::getFirstVideoFrame):
(WebCore::WebCoreDecompressionSession::automaticDequeue):
(WebCore::WebCoreDecompressionSession::imageForTime):
(WebCore::WebCoreDecompressionSession::getDecodeTime):
(WebCore::WebCoreDecompressionSession::getPresentationTime):
(WebCore::WebCoreDecompressionSession::getDuration):
- Use checked_cf_cast<CMSampleBufferRef>().

* platform/graphics/Font.h:
(WebCore::Font::m_kernedCFStringAttributes):
(WebCore::Font::m_nonKernedCFStringAttributes):
- Change type from RetainPtr<CFDictionaryRef> to
  RetainPtr<CFMutableDictionaryRef> since that's what they are.
* platform/graphics/mac/SimpleFontDataCoreText.cpp:
(WebCore::Font::getCFStringAttributes const):
- Replace local `mutableAttributes` variable with
  `attributesDictionary.get()` since it returns the correct type
  now.

* platform/ios/wak/WAKView.mm:
(-[WAKView _initWithViewRef:]):
(_WAKCopyWrapper):
* platform/ios/wak/WKView.mm:
(_WKViewClearSuperview):
(WKViewFirstChild):
(WKViewNextSibling):
- Use static_cast<WKViewRef>(const_cast<void*>()) to convert
  const void* variable to WKViewRef.

* platform/mac/PasteboardMac.mm:
(WebCore::flipImageSpec):
(WebCore::setDragImageImpl):
- Use const_cast<> to remove 'const' modifier from
  unsigned char pointers.  This regressed while -Wcast-qual was
  disabled for WebCore.

* platform/mac/SSLKeyGeneratorMac.mm:
(WebCore::signedPublicKeyAndChallengeString):
- Use checked_cf_cast<SecACLRef>().

* platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp:
(WebCore::RealtimeIncomingVideoSourceCocoa::OnFrame):
- Use checked_cf_cast<CFMutableDictionaryRef>().

* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::copyCONNECTProxyResponse):
- Use checked_cf_cast<CFHTTPMessageRef>().

* platform/network/cocoa/ResourceResponseCocoa.mm:
(WebCore::ResourceResponse::platformCertificateInfo const):
- Use checked_cf_cast<SecTrustRef>().

* platform/network/mac/CertificateInfoMac.mm:
(WebCore::CertificateInfo::containsNonRootSHA1SignedCertificate const):
(WebCore::CertificateInfo::dump const):
- Use checked_cf_cast<SecCertificateRef>().

* testing/cocoa/WebArchiveDumpSupport.mm:
(WebCoreTestSupport::createCFURLResponseFromResponseData):
- Use checked_cf_cast<>() for CFMutable* types.

Source/WTF:

* wtf/RetainPtr.h:
(WTF::RetainPtr::fromStorageTypeHelper const): Add const_cast<>
operator here since some CFTypes are not defined as const
pointers, which triggers a warning in C++ source with
-Wcast-qual when casting from CFTypeRef back to the original
type.  Note that we use const_cast<CF_BRIDGED_TYPE(id) void*>()
here (and in TypeCastsCF.h below) since this is what CFTypeRef
is defined as in CFBase.h, but without the 'const' modifier.
(WTF::RetainPtr::fromStorageType const): Ditto.

* wtf/cf/TypeCastsCF.h: Use #pragma once.
(WTF_DECLARE_CF_TYPE_TRAIT): Rename from DECLARE_CF_TYPE_TRAIT.
Don't #undef it so that it can be used in other source files.
(WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT): Add new macro that is used
for declaring CFMutable types.  The CFTypeID for CF_Foo_ and
CFMutable_Foo_ are the same, so we have to use a different macro
to declare type traits for those types.
(WTF::dynamic_cf_cast): Add assertion to catch issues in Debug
builds.
(WTF::checked_cf_cast): Inline code from WTF::dynamic_cf_cast
and change behavior to be more consistent between Debug and
Release builds, as well as other "checked" functions.
Previously this function would return nullptr in Release builds
if nullptr or the wrong type of object was passed in, but crash
in both cases on Debug builds.  The new behavior always returns
nullptr if nullptr was passed in (but never crashes), and always
crashes if the wrong type of object is passed in.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (226482 => 226483)


--- trunk/Source/WTF/ChangeLog	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WTF/ChangeLog	2018-01-06 03:19:57 UTC (rev 226483)
@@ -1,3 +1,39 @@
+2018-01-05  David Kilzer  <ddkil...@apple.com>
+
+        Re-enable -Wcast-qual in WebCore for Apple ports
+        <https://webkit.org/b/177895>
+        <rdar://problem/34960830>
+
+        Reviewed by Joseph Pecoraro.
+
+        * wtf/RetainPtr.h:
+        (WTF::RetainPtr::fromStorageTypeHelper const): Add const_cast<>
+        operator here since some CFTypes are not defined as const
+        pointers, which triggers a warning in C++ source with
+        -Wcast-qual when casting from CFTypeRef back to the original
+        type.  Note that we use const_cast<CF_BRIDGED_TYPE(id) void*>()
+        here (and in TypeCastsCF.h below) since this is what CFTypeRef
+        is defined as in CFBase.h, but without the 'const' modifier.
+        (WTF::RetainPtr::fromStorageType const): Ditto.
+
+        * wtf/cf/TypeCastsCF.h: Use #pragma once.
+        (WTF_DECLARE_CF_TYPE_TRAIT): Rename from DECLARE_CF_TYPE_TRAIT.
+        Don't #undef it so that it can be used in other source files.
+        (WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT): Add new macro that is used
+        for declaring CFMutable types.  The CFTypeID for CF_Foo_ and
+        CFMutable_Foo_ are the same, so we have to use a different macro
+        to declare type traits for those types.
+        (WTF::dynamic_cf_cast): Add assertion to catch issues in Debug
+        builds.
+        (WTF::checked_cf_cast): Inline code from WTF::dynamic_cf_cast
+        and change behavior to be more consistent between Debug and
+        Release builds, as well as other "checked" functions.
+        Previously this function would return nullptr in Release builds
+        if nullptr or the wrong type of object was passed in, but crash
+        in both cases on Debug builds.  The new behavior always returns
+        nullptr if nullptr was passed in (but never crashes), and always
+        crashes if the wrong type of object is passed in.
+
 2018-01-04  Keith Miller  <keith_mil...@apple.com>
 
         TypedArrays and Wasm should use index masking.

Modified: trunk/Source/WTF/wtf/RetainPtr.h (226482 => 226483)


--- trunk/Source/WTF/wtf/RetainPtr.h	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WTF/wtf/RetainPtr.h	2018-01-06 03:19:57 UTC (rev 226483)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2005, 2006, 2007, 2008, 2010, 2013, 2014 Apple Inc. All rights reserved.
+ *  Copyright (C) 2005-2018 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -37,6 +37,10 @@
 #import <Foundation/Foundation.h>
 #endif
 
+#ifndef CF_BRIDGED_TYPE
+#define CF_BRIDGED_TYPE(T)
+#endif
+
 #ifndef CF_RELEASES_ARGUMENT
 #define CF_RELEASES_ARGUMENT
 #endif
@@ -116,7 +120,7 @@
     typename std::enable_if<std::is_convertible<U, id>::value, PtrType>::type
     fromStorageTypeHelper(StorageType ptr) const
     {
-        return (__bridge PtrType)ptr;
+        return (__bridge PtrType)const_cast<CF_BRIDGED_TYPE(id) void*>(ptr);
     }
 
     template<typename U>
@@ -123,7 +127,7 @@
     typename std::enable_if<!std::is_convertible<U, id>::value, PtrType>::type
     fromStorageTypeHelper(StorageType ptr) const
     {
-        return (PtrType)ptr;
+        return (PtrType)const_cast<CF_BRIDGED_TYPE(id) void*>(ptr);
     }
 
     PtrType fromStorageType(StorageType ptr) const { return fromStorageTypeHelper<PtrType>(ptr); }
@@ -132,11 +136,7 @@
 #else
     PtrType fromStorageType(StorageType ptr) const
     {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
-        // FIXME: Bug 177895: Re-enable -Wcast-qual for Apple ports.
-        return (PtrType)ptr;
-#pragma clang diagnostic pop
+        return (PtrType)const_cast<CF_BRIDGED_TYPE(id) void*>(ptr);
     }
     StorageType toStorageType(PtrType ptr) const { return (StorageType)ptr; }
 #endif

Modified: trunk/Source/WTF/wtf/cf/TypeCastsCF.h (226482 => 226483)


--- trunk/Source/WTF/wtf/cf/TypeCastsCF.h	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WTF/wtf/cf/TypeCastsCF.h	2018-01-06 03:19:57 UTC (rev 226483)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,48 +23,65 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef TypeCastsCF_h
-#define TypeCastsCF_h
+#pragma once
 
 #include <CoreFoundation/CoreFoundation.h>
 #include <wtf/Assertions.h>
 
+#ifndef CF_BRIDGED_TYPE
+#define CF_BRIDGED_TYPE(T)
+#endif
+
 namespace WTF {
 
 template <typename> struct CFTypeTrait;
 
-#define DECLARE_CF_TYPE_TRAIT(ClassName) \
+#define WTF_DECLARE_CF_TYPE_TRAIT(ClassName) \
 template <> \
-struct CFTypeTrait<ClassName##Ref> { \
-    static inline CFTypeID typeID() { return ClassName##GetTypeID(); } \
+struct WTF::CFTypeTrait<ClassName##Ref> { \
+    static inline CFTypeID typeID(void) { return ClassName##GetTypeID(); } \
 };
 
-DECLARE_CF_TYPE_TRAIT(CFArray);
-DECLARE_CF_TYPE_TRAIT(CFBoolean);
-DECLARE_CF_TYPE_TRAIT(CFData);
-DECLARE_CF_TYPE_TRAIT(CFDictionary);
-DECLARE_CF_TYPE_TRAIT(CFNumber);
-DECLARE_CF_TYPE_TRAIT(CFString);
+WTF_DECLARE_CF_TYPE_TRAIT(CFArray);
+WTF_DECLARE_CF_TYPE_TRAIT(CFBoolean);
+WTF_DECLARE_CF_TYPE_TRAIT(CFData);
+WTF_DECLARE_CF_TYPE_TRAIT(CFDictionary);
+WTF_DECLARE_CF_TYPE_TRAIT(CFNumber);
+WTF_DECLARE_CF_TYPE_TRAIT(CFString);
 
-#undef DECLARE_CF_TYPE_TRAIT
+#define WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(ClassName, MutableClassName) \
+template <> \
+struct WTF::CFTypeTrait<MutableClassName##Ref> { \
+    static inline CFTypeID typeID(void) { return ClassName##GetTypeID(); } \
+};
 
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFArray, CFMutableArray);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFData, CFMutableData);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFDictionary, CFMutableDictionary);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFString, CFMutableString);
+
+#undef WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT
+
 template<typename T> T dynamic_cf_cast(CFTypeRef object)
 {
     if (!object)
         return nullptr;
 
+    ASSERT_WITH_SECURITY_IMPLICATION(CFGetTypeID(object) == CFTypeTrait<T>::typeID());
     if (CFGetTypeID(object) != CFTypeTrait<T>::typeID())
         return nullptr;
 
-    return static_cast<T>(object);
+    return static_cast<T>(const_cast<CF_BRIDGED_TYPE(id) void*>(object));
 }
 
 template<typename T> T checked_cf_cast(CFTypeRef object)
 {
-    auto result = dynamic_cf_cast<T>(object);
-    ASSERT_WITH_SECURITY_IMPLICATION(result);
+    if (!object)
+        return nullptr;
 
-    return result;
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(CFGetTypeID(object) == CFTypeTrait<T>::typeID());
+
+    return static_cast<T>(const_cast<CF_BRIDGED_TYPE(id) void*>(object));
 }
 
 } // namespace WTF
@@ -71,5 +88,3 @@
 
 using WTF::checked_cf_cast;
 using WTF::dynamic_cf_cast;
-
-#endif // TypeCastsCF_h

Modified: trunk/Source/WebCore/ChangeLog (226482 => 226483)


--- trunk/Source/WebCore/ChangeLog	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/ChangeLog	2018-01-06 03:19:57 UTC (rev 226483)
@@ -1,3 +1,102 @@
+2018-01-05  David Kilzer  <ddkil...@apple.com>
+
+        Re-enable -Wcast-qual in WebCore for Apple ports
+        <https://webkit.org/b/177895>
+        <rdar://problem/34960830>
+
+        Reviewed by Joseph Pecoraro.
+
+        * Configurations/Base.xcconfig:
+        (WARNING_CFLAGS): Remove FIXME and add -Wcast-qual back to
+        arguments.
+
+        * crypto/mac/SerializedCryptoKeyWrapMac.mm:
+        (WebCore::createAndStoreMasterKey):
+        - Use checked_cf_cast<SecACLRef>().
+
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::detectItemAtPositionWithRange):
+        - Manually cast CFTypeRef to DDResultRef until
+          DDResultGetTypeID() is available as SPI.
+
+        * platform/gamepad/mac/HIDGamepad.cpp:
+        (WebCore::HIDGamepad::initElementsFromArray):
+        - Use checked_cf_cast<IOHIDElementRef>().
+
+        * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
+        (WebCore::MediaSampleAVFObjC::createImageSample):
+        (WebCore::CMSampleBufferIsRandomAccess):
+        (WebCore::CMSampleBufferIsNonDisplaying):
+        (WebCore::MediaSampleAVFObjC::createNonDisplayingCopy const):
+        - Use checked_cf_cast<CFMutableDictionaryRef>() and
+          checked_cf_cast<CFDictionaryRef>().
+
+        * platform/graphics/cocoa/IOSurface.h:
+        (WebCore::IOSurface::asLayerContents):
+        - Use reinterpret_cast<id>() to cast from IOSurfaceRef to id.
+
+        * platform/graphics/cocoa/WebCoreDecompressionSession.mm:
+        (WebCore::WebCoreDecompressionSession::getFirstVideoFrame):
+        (WebCore::WebCoreDecompressionSession::automaticDequeue):
+        (WebCore::WebCoreDecompressionSession::imageForTime):
+        (WebCore::WebCoreDecompressionSession::getDecodeTime):
+        (WebCore::WebCoreDecompressionSession::getPresentationTime):
+        (WebCore::WebCoreDecompressionSession::getDuration):
+        - Use checked_cf_cast<CMSampleBufferRef>().
+
+        * platform/graphics/Font.h:
+        (WebCore::Font::m_kernedCFStringAttributes):
+        (WebCore::Font::m_nonKernedCFStringAttributes):
+        - Change type from RetainPtr<CFDictionaryRef> to
+          RetainPtr<CFMutableDictionaryRef> since that's what they are.
+        * platform/graphics/mac/SimpleFontDataCoreText.cpp:
+        (WebCore::Font::getCFStringAttributes const):
+        - Replace local `mutableAttributes` variable with
+          `attributesDictionary.get()` since it returns the correct type
+          now.
+
+        * platform/ios/wak/WAKView.mm:
+        (-[WAKView _initWithViewRef:]):
+        (_WAKCopyWrapper):
+        * platform/ios/wak/WKView.mm:
+        (_WKViewClearSuperview):
+        (WKViewFirstChild):
+        (WKViewNextSibling):
+        - Use static_cast<WKViewRef>(const_cast<void*>()) to convert
+          const void* variable to WKViewRef.
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::flipImageSpec):
+        (WebCore::setDragImageImpl):
+        - Use const_cast<> to remove 'const' modifier from
+          unsigned char pointers.  This regressed while -Wcast-qual was
+          disabled for WebCore.
+
+        * platform/mac/SSLKeyGeneratorMac.mm:
+        (WebCore::signedPublicKeyAndChallengeString):
+        - Use checked_cf_cast<SecACLRef>().
+
+        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp:
+        (WebCore::RealtimeIncomingVideoSourceCocoa::OnFrame):
+        - Use checked_cf_cast<CFMutableDictionaryRef>().
+
+        * platform/network/cf/SocketStreamHandleImplCFNet.cpp:
+        (WebCore::copyCONNECTProxyResponse):
+        - Use checked_cf_cast<CFHTTPMessageRef>().
+
+        * platform/network/cocoa/ResourceResponseCocoa.mm:
+        (WebCore::ResourceResponse::platformCertificateInfo const):
+        - Use checked_cf_cast<SecTrustRef>().
+
+        * platform/network/mac/CertificateInfoMac.mm:
+        (WebCore::CertificateInfo::containsNonRootSHA1SignedCertificate const):
+        (WebCore::CertificateInfo::dump const):
+        - Use checked_cf_cast<SecCertificateRef>().
+
+        * testing/cocoa/WebArchiveDumpSupport.mm:
+        (WebCoreTestSupport::createCFURLResponseFromResponseData):
+        - Use checked_cf_cast<>() for CFMutable* types.
+
 2018-01-05  John Wilander  <wilan...@apple.com>
 
         Storage Access API: Refactor to make naming accurate and explicit, simplify access table, and prepare for access removal for page

Modified: trunk/Source/WebCore/Configurations/Base.xcconfig (226482 => 226483)


--- trunk/Source/WebCore/Configurations/Base.xcconfig	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/Configurations/Base.xcconfig	2018-01-06 03:19:57 UTC (rev 226483)
@@ -80,8 +80,7 @@
 GCC_WARN_UNINITIALIZED_AUTOS = YES;
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
-// FIXME: Bug 177895: Re-enable -Wcast-qual for Apple ports.
-WARNING_CFLAGS = -Wall -Wextra -Wchar-subscripts -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wno-unknown-warning-option;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wno-unknown-warning-option;
 
 TARGET_MAC_OS_X_VERSION_MAJOR = $(TARGET_MAC_OS_X_VERSION_MAJOR$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier));
 TARGET_MAC_OS_X_VERSION_MAJOR_11 = 101100;

Modified: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm (226482 => 226483)


--- trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -43,6 +43,11 @@
 #define USE_KEYCHAIN_ACCESS_CONTROL_LISTS 1
 #endif
 
+#if USE(KEYCHAIN_ACCESS_CONTROL_LISTS)
+#include <wtf/cf/TypeCastsCF.h>
+WTF_DECLARE_CF_TYPE_TRAIT(SecACL);
+#endif
+
 namespace WebCore {
 
 const NSUInteger currentSerializationVersion = 1;
@@ -103,7 +108,7 @@
     RetainPtr<SecAccessRef> access = adoptCF(accessRef);
 
     RetainPtr<CFArrayRef> acls = adoptCF(SecAccessCopyMatchingACLList(accessRef, kSecACLAuthorizationExportClear));
-    SecACLRef acl = (SecACLRef)CFArrayGetValueAtIndex(acls.get(), 0);
+    SecACLRef acl = checked_cf_cast<SecACLRef>(CFArrayGetValueAtIndex(acls.get(), 0));
 
     SecTrustedApplicationRef trustedAppRef;
     status = SecTrustedApplicationCreateFromPath(0, &trustedAppRef);

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (226482 => 226483)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -78,7 +78,8 @@
     RefPtr<Range> mainResultRange;
     CFIndex resultCount = CFArrayGetCount(results.get());
     for (CFIndex i = 0; i < resultCount; i++) {
-        DDResultRef result = (DDResultRef)CFArrayGetValueAtIndex(results.get(), i);
+        // FIXME: <rdar://problem/36241894> Implement checked cast for DDResultRef once DDResultGetTypeID() is available
+        DDResultRef result = static_cast<DDResultRef>(const_cast<CF_BRIDGED_TYPE(id) void*>(CFArrayGetValueAtIndex(results.get(), i)));
         CFRange resultRangeInContext = DDResultGetRange(result);
         if (hitLocation >= resultRangeInContext.location && (hitLocation - resultRangeInContext.location) < resultRangeInContext.length) {
             mainResult = result;

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp (226482 => 226483)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2018-01-06 03:19:57 UTC (rev 226483)
@@ -32,9 +32,12 @@
 #include <IOKit/hid/IOHIDUsageTables.h>
 #include <IOKit/hid/IOHIDValue.h>
 #include <wtf/CurrentTime.h>
+#include <wtf/cf/TypeCastsCF.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(IOHIDElement);
+
 namespace WebCore {
 
 HIDGamepad::HIDGamepad(IOHIDDeviceRef hidDevice, unsigned index)
@@ -94,7 +97,7 @@
 void HIDGamepad::initElementsFromArray(CFArrayRef elements)
 {
     for (CFIndex i = 0, count = CFArrayGetCount(elements); i < count; ++i) {
-        IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
+        IOHIDElementRef element = checked_cf_cast<IOHIDElementRef>(CFArrayGetValueAtIndex(elements, i));
         if (CFGetTypeID(element) != IOHIDElementGetTypeID())
             continue;
 

Modified: trunk/Source/WebCore/platform/graphics/Font.h (226482 => 226483)


--- trunk/Source/WebCore/platform/graphics/Font.h	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2018-01-06 03:19:57 UTC (rev 226483)
@@ -289,8 +289,8 @@
 #endif
 
 #if PLATFORM(COCOA)
-    mutable RetainPtr<CFDictionaryRef> m_nonKernedCFStringAttributes;
-    mutable RetainPtr<CFDictionaryRef> m_kernedCFStringAttributes;
+    mutable RetainPtr<CFMutableDictionaryRef> m_nonKernedCFStringAttributes;
+    mutable RetainPtr<CFMutableDictionaryRef> m_kernedCFStringAttributes;
     mutable std::optional<BitVector> m_glyphsSupportedBySmallCaps;
     mutable std::optional<BitVector> m_glyphsSupportedByAllSmallCaps;
     mutable std::optional<BitVector> m_glyphsSupportedByPetiteCaps;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -30,13 +30,17 @@
 #import <runtime/JSCInlines.h>
 #import <runtime/TypedArrayInlines.h>
 #import <wtf/PrintStream.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 #import <pal/cf/CoreMediaSoftLink.h>
 #import "CoreVideoSoftLink.h"
 
-namespace WebCore {
 using namespace PAL;
 
+WTF_DECLARE_CF_TYPE_TRAIT(CMSampleBuffer);
+
+namespace WebCore {
+
 static inline void releaseUint8Vector(void *array, const void*)
 {
     adoptMallocPtr(static_cast<uint8_t*>(array));
@@ -67,7 +71,7 @@
 
     CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sample.get(), true);
     for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
     }
     return create(sample.get());
@@ -116,7 +120,7 @@
         return true;
     
     for (CFIndex i = 0, count = CFArrayGetCount(attachments); i < count; ++i) {
-        CFDictionaryRef attachmentDict = (CFDictionaryRef)CFArrayGetValueAtIndex(attachments, i);
+        CFDictionaryRef attachmentDict = checked_cf_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(attachments, i));
         if (CFDictionaryContainsKey(attachmentDict, kCMSampleAttachmentKey_NotSync))
             return false;
     }
@@ -130,7 +134,7 @@
         return false;
     
     for (CFIndex i = 0; i < CFArrayGetCount(attachments); ++i) {
-        CFDictionaryRef attachmentDict = (CFDictionaryRef)CFArrayGetValueAtIndex(attachments, i);
+        CFDictionaryRef attachmentDict = checked_cf_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(attachments, i));
         if (CFDictionaryContainsKey(attachmentDict, kCMSampleAttachmentKey_DoNotDisplay))
             return true;
     }
@@ -266,7 +270,7 @@
 
     CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(newSampleBuffer, true);
     for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DoNotDisplay, kCFBooleanTrue);
     }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (226482 => 226483)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2018-01-06 03:19:57 UTC (rev 226483)
@@ -101,7 +101,7 @@
     WEBCORE_EXPORT RetainPtr<CGImageRef> createImage();
     WEBCORE_EXPORT static RetainPtr<CGImageRef> sinkIntoImage(std::unique_ptr<IOSurface>);
 
-    id asLayerContents() const { return (id)(CFTypeRef)m_surface.get(); }
+    id asLayerContents() const { return reinterpret_cast<id>(m_surface.get()); }
     IOSurfaceRef surface() const { return m_surface.get(); }
     WEBCORE_EXPORT GraphicsContext& ensureGraphicsContext();
     WEBCORE_EXPORT CGContextRef ensurePlatformContext();

Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -38,14 +38,18 @@
 #import <wtf/MediaTime.h>
 #import <wtf/StringPrintStream.h>
 #import <wtf/Vector.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 #import <pal/cf/CoreMediaSoftLink.h>
 #import "CoreVideoSoftLink.h"
 #import "VideoToolboxSoftLink.h"
 
-namespace WebCore {
 using namespace PAL;
 
+WTF_DECLARE_CF_TYPE_TRAIT(CMSampleBuffer);
+
+namespace WebCore {
+
 WebCoreDecompressionSession::WebCoreDecompressionSession(Mode mode)
     : m_mode(mode)
     , m_decompressionQueue(adoptOSObject(dispatch_queue_create("WebCoreDecompressionSession Decompression Queue", DISPATCH_QUEUE_SERIAL)))
@@ -322,7 +326,7 @@
     if (!m_producerQueue || CMBufferQueueIsEmpty(m_producerQueue.get()))
         return nullptr;
 
-    RetainPtr<CMSampleBufferRef> currentSample = adoptCF((CMSampleBufferRef)CMBufferQueueDequeueAndRetain(m_producerQueue.get()));
+    RetainPtr<CMSampleBufferRef> currentSample = adoptCF(checked_cf_cast<CMSampleBufferRef>(CMBufferQueueDequeueAndRetain(m_producerQueue.get())));
     RetainPtr<CVPixelBufferRef> imageBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(currentSample.get());
     ASSERT(CFGetTypeID(imageBuffer.get()) == CVPixelBufferGetTypeID());
 
@@ -342,7 +346,7 @@
     MediaTime nextFireTime = MediaTime::positiveInfiniteTime();
     bool releasedImageBuffers = false;
 
-    while (CMSampleBufferRef firstSample = (CMSampleBufferRef)CMBufferQueueGetHead(m_producerQueue.get())) {
+    while (CMSampleBufferRef firstSample = checked_cf_cast<CMSampleBufferRef>(CMBufferQueueGetHead(m_producerQueue.get()))) {
         MediaTime presentationTimestamp = PAL::toMediaTime(CMSampleBufferGetPresentationTimeStamp(firstSample));
         MediaTime duration = PAL::toMediaTime(CMSampleBufferGetDuration(firstSample));
         MediaTime presentationEndTimestamp = presentationTimestamp + duration;
@@ -481,7 +485,7 @@
 
     bool releasedImageBuffers = false;
 
-    while (CMSampleBufferRef firstSample = (CMSampleBufferRef)CMBufferQueueGetHead(m_producerQueue.get())) {
+    while (CMSampleBufferRef firstSample = checked_cf_cast<CMSampleBufferRef>(CMBufferQueueGetHead(m_producerQueue.get()))) {
         MediaTime presentationTimestamp = PAL::toMediaTime(CMSampleBufferGetPresentationTimeStamp(firstSample));
         MediaTime duration = PAL::toMediaTime(CMSampleBufferGetDuration(firstSample));
         MediaTime presentationEndTimestamp = presentationTimestamp + duration;
@@ -493,7 +497,7 @@
             continue;
         }
 
-        RetainPtr<CMSampleBufferRef> currentSample = adoptCF((CMSampleBufferRef)CMBufferQueueDequeueAndRetain(m_producerQueue.get()));
+        RetainPtr<CMSampleBufferRef> currentSample = adoptCF(checked_cf_cast<CMSampleBufferRef>(CMBufferQueueDequeueAndRetain(m_producerQueue.get())));
         RetainPtr<CVPixelBufferRef> imageBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(currentSample.get());
         ASSERT(CFGetTypeID(imageBuffer.get()) == CVPixelBufferGetTypeID());
 
@@ -531,22 +535,19 @@
 
 CMTime WebCoreDecompressionSession::getDecodeTime(CMBufferRef buf, void*)
 {
-    ASSERT(CFGetTypeID(buf) == CMSampleBufferGetTypeID());
-    CMSampleBufferRef sample = (CMSampleBufferRef)(buf);
+    CMSampleBufferRef sample = checked_cf_cast<CMSampleBufferRef>(buf);
     return CMSampleBufferGetDecodeTimeStamp(sample);
 }
 
 CMTime WebCoreDecompressionSession::getPresentationTime(CMBufferRef buf, void*)
 {
-    ASSERT(CFGetTypeID(buf) == CMSampleBufferGetTypeID());
-    CMSampleBufferRef sample = (CMSampleBufferRef)(buf);
+    CMSampleBufferRef sample = checked_cf_cast<CMSampleBufferRef>(buf);
     return CMSampleBufferGetPresentationTimeStamp(sample);
 }
 
 CMTime WebCoreDecompressionSession::getDuration(CMBufferRef buf, void*)
 {
-    ASSERT(CFGetTypeID(buf) == CMSampleBufferGetTypeID());
-    CMSampleBufferRef sample = (CMSampleBufferRef)(buf);
+    CMSampleBufferRef sample = checked_cf_cast<CMSampleBufferRef>(buf);
     return CMSampleBufferGetDuration(sample);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp (226482 => 226483)


--- trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp	2018-01-06 03:19:57 UTC (rev 226483)
@@ -42,18 +42,17 @@
         return attributesDictionary.get();
 
     attributesDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    CFMutableDictionaryRef mutableAttributes = (CFMutableDictionaryRef)attributesDictionary.get();
 
-    CFDictionarySetValue(mutableAttributes, kCTFontAttributeName, platformData().ctFont());
+    CFDictionarySetValue(attributesDictionary.get(), kCTFontAttributeName, platformData().ctFont());
 
     if (!enableKerning) {
         const float zero = 0;
         static CFNumberRef zeroKerningValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero);
-        CFDictionarySetValue(mutableAttributes, kCTKernAttributeName, zeroKerningValue);
+        CFDictionarySetValue(attributesDictionary.get(), kCTKernAttributeName, zeroKerningValue);
     }
 
     if (orientation == Vertical)
-        CFDictionarySetValue(mutableAttributes, kCTVerticalFormsAttributeName, kCFBooleanTrue);
+        CFDictionarySetValue(attributesDictionary.get(), kCTVerticalFormsAttributeName, kCFBooleanTrue);
 
     return attributesDictionary.get();
 }

Modified: trunk/Source/WebCore/platform/ios/wak/WAKView.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/ios/wak/WAKView.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/ios/wak/WAKView.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -221,7 +221,7 @@
     if (!self)
         return nil;
 
-    viewRef = (WKViewRef)WKRetain (viewR);
+    viewRef = static_cast<WKViewRef>(const_cast<void*>(WKRetain(viewR)));
     viewRef->wrapper = (void *)self;
 
     return self;
@@ -288,7 +288,7 @@
         return;
     
     NSMutableArray *array = (NSMutableArray *)context;
-    WAKView *view = WAKViewForWKViewRef((WKViewRef)value);
+    WAKView *view = WAKViewForWKViewRef(static_cast<WKViewRef>(const_cast<void*>(value)));
     if (view)
         [array addObject:view];
 }

Modified: trunk/Source/WebCore/platform/ios/wak/WKView.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/ios/wak/WKView.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/ios/wak/WKView.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -73,7 +73,7 @@
 static void _WKViewClearSuperview(const void *value, void *context)
 {
     UNUSED_PARAM(context);
-    _WKViewSetSuperview((WKViewRef)value, 0);
+    _WKViewSetSuperview(static_cast<WKViewRef>(const_cast<void*>(value)), 0);
 }
 
 static void _WKViewDealloc (WKObjectRef v)
@@ -105,7 +105,7 @@
 
 WKViewRef WKViewCreateWithFrame (CGRect frame, WKViewContext *context)
 {
-    WKViewRef view = (WKViewRef)WKCreateObjectWithSize (sizeof(struct _WKView), &WKViewClassInfo);
+    WKViewRef view = static_cast<WKViewRef>(const_cast<void*>(WKCreateObjectWithSize(sizeof(struct _WKView), &WKViewClassInfo)));
     if (!view)
         return 0;
     
@@ -468,7 +468,7 @@
     if (!count)
         return 0;
         
-    return (const WKViewRef)CFArrayGetValueAtIndex (sv, 0);
+    return static_cast<WKViewRef>(const_cast<void*>(CFArrayGetValueAtIndex(sv, 0)));
 }
 
 WKViewRef WKViewNextSibling (WKViewRef view)
@@ -495,7 +495,7 @@
     if (thisIndex+1 >= count)
         return 0;
         
-    return (const WKViewRef)CFArrayGetValueAtIndex (svs, thisIndex+1);
+    return static_cast<WKViewRef>(const_cast<void*>(CFArrayGetValueAtIndex(svs, thisIndex + 1)));
 }
 
 // To remove, see: <rdar://problem/10360425> Remove WKViewTraverseNext from Skankphone

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -575,7 +575,7 @@
     int planes = imageSpec->isPlanar ? imageSpec->samplesPerPixel : 1;
 
     for (int p = 0; p < planes; ++p) {
-        unsigned char* topRow = (unsigned char*)imageSpec->data[p];
+        unsigned char* topRow = const_cast<unsigned char*>(imageSpec->data[p]);
         unsigned char* botRow = topRow + (imageSpec->pixelsHigh - 1) * imageSpec->bytesPerRow;
         for (int i = 0; i < imageSpec->pixelsHigh / 2; ++i, topRow += imageSpec->bytesPerRow, botRow -= imageSpec->bytesPerRow) {
             bcopy(topRow, tempRow, imageSpec->bytesPerRow);
@@ -624,7 +624,7 @@
     imageSpec.bytesPerRow = [bitmapImage bytesPerRow];
     imageSpec.isPlanar = [bitmapImage isPlanar];
     imageSpec.hasAlpha = [bitmapImage hasAlpha];
-    [bitmapImage getBitmapDataPlanes:(unsigned char**)imageSpec.data];
+    [bitmapImage getBitmapDataPlanes:const_cast<unsigned char**>(imageSpec.data)];
 
     // if image was flipped, we have an upside down bitmap since the cache is rendered flipped
     if (flipImage)

Modified: trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -33,9 +33,12 @@
 #import <Security/SecEncodeTransform.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Scope.h>
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/spi/cocoa/SecuritySPI.h>
 #import <wtf/text/Base64.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(SecACL);
+
 namespace WebCore {
 
 #pragma clang diagnostic push
@@ -138,7 +141,7 @@
         return String();
     RetainPtr<CFArrayRef> acls = adoptCF(aclsRef);
 
-    SecACLRef acl = (SecACLRef)(CFArrayGetValueAtIndex(acls.get(), 0));
+    SecACLRef acl = checked_cf_cast<SecACLRef>(CFArrayGetValueAtIndex(acls.get(), 0));
 
     // Passing nullptr to SecTrustedApplicationCreateFromPath tells that function to assume the application bundle.
     SecTrustedApplicationRef trustedAppRef { nullptr };

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp (226482 => 226483)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp	2018-01-06 03:19:57 UTC (rev 226483)
@@ -33,6 +33,7 @@
 #include "Logging.h"
 #include "MediaSampleAVFObjC.h"
 #include <webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h>
+#include <wtf/cf/TypeCastsCF.h>
 
 #include <pal/cf/CoreMediaSoftLink.h>
 #include "CoreVideoSoftLink.h"
@@ -124,7 +125,7 @@
 
     CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
     for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
     }
 

Modified: trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp (226482 => 226483)


--- trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp	2018-01-06 03:19:57 UTC (rev 226483)
@@ -45,6 +45,7 @@
 #include <wtf/Lock.h>
 #include <wtf/MainThread.h>
 #include <wtf/SoftLinking.h>
+#include <wtf/cf/TypeCastsCF.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(WIN)
@@ -66,6 +67,8 @@
 SOFT_LINK_OPTIONAL(CFNetwork, _CFHTTPMessageSetResponseProxyURL, void, __cdecl, (CFHTTPMessageRef, CFURLRef));
 #endif
 
+WTF_DECLARE_CF_TYPE_TRAIT(CFHTTPMessage);
+
 namespace WebCore {
 
 SocketStreamHandleImpl::SocketStreamHandleImpl(const URL& url, SocketStreamHandleClient& client, PAL::SessionID sessionID, const String& credentialPartition, SourceApplicationAuditToken&& auditData)
@@ -505,7 +508,7 @@
 
 static RetainPtr<CFHTTPMessageRef> copyCONNECTProxyResponse(CFReadStreamRef stream, CFURLRef responseURL, CFStringRef proxyHost, CFNumberRef proxyPort)
 {
-    auto message = adoptCF((CFHTTPMessageRef)CFReadStreamCopyProperty(stream, kCFStreamPropertyCONNECTResponse));
+    auto message = adoptCF(checked_cf_cast<CFHTTPMessageRef>(CFReadStreamCopyProperty(stream, kCFStreamPropertyCONNECTResponse)));
     // CFNetwork needs URL to be set on response in order to handle authentication - even though it doesn't seem to make sense to provide ultimate target URL when authenticating to a proxy.
     // This is set by CFNetwork internally for normal HTTP responses, but not for proxies.
     _CFHTTPMessageSetResponseURL(message.get(), responseURL);

Modified: trunk/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -36,8 +36,11 @@
 #import <wtf/AutodrainedPool.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/StdLibExtras.h>
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/text/StringView.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(SecTrust);
+
 namespace WebCore {
 
 void ResourceResponse::initNSURLResponse() const
@@ -88,8 +91,7 @@
     auto trustValue = CFDictionaryGetValue(context, kCFStreamPropertySSLPeerTrust);
     if (!trustValue)
         return { };
-    ASSERT(CFGetTypeID(trustValue) == SecTrustGetTypeID());
-    auto trust = (SecTrustRef)trustValue;
+    auto trust = checked_cf_cast<SecTrustRef>(trustValue);
 
     SecTrustResultType trustResultType;
     OSStatus result = SecTrustGetTrustResult(trust, &trustResultType);

Modified: trunk/Source/WebCore/platform/network/mac/CertificateInfoMac.mm (226482 => 226483)


--- trunk/Source/WebCore/platform/network/mac/CertificateInfoMac.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/platform/network/mac/CertificateInfoMac.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -27,8 +27,11 @@
 #import "CertificateInfo.h"
 
 #import "NotImplemented.h"
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/spi/cocoa/SecuritySPI.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(SecCertificate);
+
 namespace WebCore {
 
 #if PLATFORM(COCOA)
@@ -84,7 +87,7 @@
     if (m_certificateChain) {
         // Allow only the root certificate (the last in the chain) to be SHA1.
         for (CFIndex i = 0, size = CFArrayGetCount(m_certificateChain.get()) - 1; i < size; ++i) {
-            auto certificate = (SecCertificateRef)CFArrayGetValueAtIndex(m_certificateChain.get(), i);
+            auto certificate = checked_cf_cast<SecCertificateRef>(CFArrayGetValueAtIndex(m_certificateChain.get(), i));
             if (SecCertificateGetSignatureHashAlgorithm(certificate) == kSecSignatureHashAlgorithmSHA1)
                 return true;
         }
@@ -117,7 +120,7 @@
         NSLog(@"CertificateInfo (Certificate Chain)\n");
         NSLog(@"  Entries: %ld\n", entries);
         for (CFIndex i = 0; i < entries; ++i) {
-            RetainPtr<CFStringRef> summary = adoptCF(SecCertificateCopySubjectSummary((SecCertificateRef)CFArrayGetValueAtIndex(m_certificateChain.get(), i)));
+            RetainPtr<CFStringRef> summary = adoptCF(SecCertificateCopySubjectSummary(checked_cf_cast<SecCertificateRef>(CFArrayGetValueAtIndex(m_certificateChain.get(), i))));
             NSLog(@"  %@", (NSString *)summary.get());
         }
 

Modified: trunk/Source/WebCore/testing/cocoa/WebArchiveDumpSupport.mm (226482 => 226483)


--- trunk/Source/WebCore/testing/cocoa/WebArchiveDumpSupport.mm	2018-01-06 02:16:51 UTC (rev 226482)
+++ trunk/Source/WebCore/testing/cocoa/WebArchiveDumpSupport.mm	2018-01-06 03:19:57 UTC (rev 226483)
@@ -34,6 +34,7 @@
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 using namespace WebCore;
 
@@ -90,7 +91,7 @@
 
 static void convertWebResourceDataToString(CFMutableDictionaryRef resource)
 {
-    CFMutableStringRef mimeType = (CFMutableStringRef)CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType"));
+    CFMutableStringRef mimeType = checked_cf_cast<CFMutableStringRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType")));
     CFStringLowercase(mimeType, CFLocaleGetSystem());
     convertMIMEType(mimeType);
 
@@ -219,7 +220,7 @@
 {
     CFErrorRef error = 0;
     CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
-    RetainPtr<CFMutableDictionaryRef> propertyList = adoptCF((CFMutableDictionaryRef)CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &format, &error));
+    RetainPtr<CFMutableDictionaryRef> propertyList = adoptCF(checked_cf_cast<CFMutableDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &format, &error)));
 
     if (!propertyList) {
         if (error)
@@ -231,26 +232,26 @@
     CFArrayAppendValue(resources.get(), propertyList.get());
 
     while (CFArrayGetCount(resources.get())) {
-        RetainPtr<CFMutableDictionaryRef> resourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(resources.get(), 0);
+        RetainPtr<CFMutableDictionaryRef> resourcePropertyList = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(resources.get(), 0));
         CFArrayRemoveValueAtIndex(resources.get(), 0);
 
-        CFMutableDictionaryRef mainResource = (CFMutableDictionaryRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebMainResource"));
-        normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(mainResource, CFSTR("WebResourceURL")));
+        CFMutableDictionaryRef mainResource = checked_cf_cast<CFMutableDictionaryRef>(CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebMainResource")));
+        normalizeWebResourceURL(checked_cf_cast<CFMutableStringRef>(CFDictionaryGetValue(mainResource, CFSTR("WebResourceURL"))));
         convertWebResourceDataToString(mainResource);
 
         // Add subframeArchives to list for processing
-        CFMutableArrayRef subframeArchives = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubframeArchives")); // WebSubframeArchivesKey in WebArchive.m
+        CFMutableArrayRef subframeArchives = checked_cf_cast<CFMutableArrayRef>(CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubframeArchives"))); // WebSubframeArchivesKey in WebArchive.m
         if (subframeArchives)
             CFArrayAppendArray(resources.get(), subframeArchives, CFRangeMake(0, CFArrayGetCount(subframeArchives)));
 
-        CFMutableArrayRef subresources = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubresources")); // WebSubresourcesKey in WebArchive.m
+        CFMutableArrayRef subresources = checked_cf_cast<CFMutableArrayRef>(CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubresources"))); // WebSubresourcesKey in WebArchive.m
         if (!subresources)
             continue;
 
         CFIndex subresourcesCount = CFArrayGetCount(subresources);
         for (CFIndex i = 0; i < subresourcesCount; ++i) {
-            CFMutableDictionaryRef subresourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(subresources, i);
-            normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(subresourcePropertyList, CFSTR("WebResourceURL")));
+            CFMutableDictionaryRef subresourcePropertyList = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(subresources, i));
+            normalizeWebResourceURL(checked_cf_cast<CFMutableStringRef>(CFDictionaryGetValue(subresourcePropertyList, CFSTR("WebResourceURL"))));
             convertWebResourceResponseToDictionary(subresourcePropertyList);
             convertWebResourceDataToString(subresourcePropertyList);
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to