Title: [284763] trunk/Source
Revision
284763
Author
da...@apple.com
Date
2021-10-24 11:13:21 -0700 (Sun, 24 Oct 2021)

Log Message

[Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly
https://bugs.webkit.org/show_bug.cgi?id=232200

Reviewed by Anders Carlsson.

Source/WebCore:

* platform/cocoa/SharedBufferCocoa.mm:
(WebCore::SharedBuffer::create): Use bridge_cast.
(WebCore::SharedBuffer::append): Ditto.
(WebCore::SharedBuffer::createNSData const): Ditto. Here we are replacing
a leakRef/adoptNS pair, so this fixes an ARC incompatibility.
(WebCore::SharedBuffer::createCFData const): Ditto. Here we are replacing
a leakRef/adoptCF pair, so this fixes an ARC incompatibility.
(WebCore::SharedBuffer::createFromReadingFile): Tweaked coding style.

* platform/graphics/cocoa/HEVCUtilitiesCocoa.mm:
(WebCore::parseStringArrayFromDictionaryToUInt16Vector): Use dynamic_cf_cast,
dynamic_objc_cast, and makeVector to reduce code without behavior changes.

* platform/mac/PasteboardWriter.mm:
(WebCore::toUTI): Use bridge_cast.
(WebCore::toUTIUnlessAlreadyUTI): Use bridge_cast after doing adoptCF
rather than first casting and then doing an adoptNS, relying on it doing the
correct thing for a CF object. This fixes an ARC incompatibility.
(WebCore::createPasteboardWriter): Ditto.

Source/WebKit:

* Shared/Cocoa/ArgumentCodersCocoa.mm:
(-[WKSecureCodingURLWrapper encodeWithCoder:]): Use bridge_cast.
(-[WKSecureCodingURLWrapper initWithCoder:]): Use bridge_cast
after calling adoptCF rather than first doing a bridging cast and
then doing adoptNS and relying on it correctly adopting a CF object.
This fixes an ARC incompatibility.
(IPC::encodeDataInternal): Use bridge_cast.
(IPC::decodeDataInternal): Use bridge_cast/WTFMove instead of
adoptNS/cast/leakRef. This fixes an ARC incompatibility
(IPC::encodeDateInternal): Use bridge_cast.
(IPC::decodeDateInternal): Use bridge_cast/WTFMove as above.
(IPC::encodeNumberInternal): Use bridge_cast.
(IPC::decodeNumberInternal): Use bridge_cast/WTFMove as above.
(IPC::decodeSecureCodingInternal): Use bridge_cast.
(IPC::encodeStringInternal): Use bridge_cast.
(IPC::decodeStringInternal): Use bridge_cast/WTFMove as above.
(IPC::encodeURLInternal): Use bridge_cast.
(IPC::decodeURLInternal): Use bridge_cast/WTFMove as above.

* UIProcess/API/Cocoa/WKConnection.mm:
(didReceiveMessage): Use bridge_cast and remove unneeded use of
RetainPtr/get on the body.

* UIProcess/Plugins/mac/PluginInfoStoreMac.mm:
(WebKit::PluginInfoStore::pluginPathsInDirectory): Use bridge_cast
and makeVectort.

Source/WTF:

* wtf/cocoa/URLCocoa.mm:
(WTF::URL::URL): Use bridge_cast.
(WTF::URL::createCFURL const): Ditto, using the RetainPtr version to avoid
retain count churn.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (284762 => 284763)


--- trunk/Source/WTF/ChangeLog	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WTF/ChangeLog	2021-10-24 18:13:21 UTC (rev 284763)
@@ -1,3 +1,15 @@
+2021-10-24  Darin Adler  <da...@apple.com>
+
+        [Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=232200
+
+        Reviewed by Anders Carlsson.
+
+        * wtf/cocoa/URLCocoa.mm:
+        (WTF::URL::URL): Use bridge_cast.
+        (WTF::URL::createCFURL const): Ditto, using the RetainPtr version to avoid
+        retain count churn.
+
 2021-10-23  Alan Bujtas  <za...@apple.com>
 
         Addressing post-commit review (r284744).

Modified: trunk/Source/WTF/wtf/cocoa/URLCocoa.mm (284762 => 284763)


--- trunk/Source/WTF/wtf/cocoa/URLCocoa.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WTF/wtf/cocoa/URLCocoa.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,6 +29,7 @@
 #import <wtf/URLParser.h>
 #import <wtf/cf/CFURLExtras.h>
 #import <wtf/cocoa/NSURLExtras.h>
+#import <wtf/cocoa/TypeCastsCocoa.h>
 #import <wtf/text/CString.h>
 
 @interface NSString (WTFNSURLExtras)
@@ -37,17 +38,17 @@
 
 namespace WTF {
 
-URL::URL(NSURL *url)
+URL::URL(NSURL *cocoaURL)
 {
-    if (!url) {
+    if (!cocoaURL) {
         invalidate();
         return;
     }
 
     // FIXME: Why is it OK to ignore base URL here?
-    CString urlBytes;
-    WTF::getURLBytes((__bridge CFURLRef)url, urlBytes);
-    URLParser parser(urlBytes.data());
+    CString bytes;
+    WTF::getURLBytes(bridge_cast(cocoaURL), bytes);
+    URLParser parser(bytes.data());
     *this = parser.result();
 }
 
@@ -65,7 +66,7 @@
 
     if (isEmpty()) {
         // We use the toll-free bridge between NSURL and CFURL to create a CFURLRef supporting both empty and null values.
-        return (__bridge CFURLRef)adoptNS([[NSURL alloc] initWithString:@""]).get();
+        return bridge_cast(adoptNS([[NSURL alloc] initWithString:@""]));
     }
 
     RetainPtr<CFURLRef> cfURL;

Modified: trunk/Source/WebCore/ChangeLog (284762 => 284763)


--- trunk/Source/WebCore/ChangeLog	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebCore/ChangeLog	2021-10-24 18:13:21 UTC (rev 284763)
@@ -1,3 +1,30 @@
+2021-10-24  Darin Adler  <da...@apple.com>
+
+        [Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=232200
+
+        Reviewed by Anders Carlsson.
+
+        * platform/cocoa/SharedBufferCocoa.mm:
+        (WebCore::SharedBuffer::create): Use bridge_cast.
+        (WebCore::SharedBuffer::append): Ditto.
+        (WebCore::SharedBuffer::createNSData const): Ditto. Here we are replacing
+        a leakRef/adoptNS pair, so this fixes an ARC incompatibility.
+        (WebCore::SharedBuffer::createCFData const): Ditto. Here we are replacing
+        a leakRef/adoptCF pair, so this fixes an ARC incompatibility.
+        (WebCore::SharedBuffer::createFromReadingFile): Tweaked coding style.
+
+        * platform/graphics/cocoa/HEVCUtilitiesCocoa.mm:
+        (WebCore::parseStringArrayFromDictionaryToUInt16Vector): Use dynamic_cf_cast,
+        dynamic_objc_cast, and makeVector to reduce code without behavior changes.
+
+        * platform/mac/PasteboardWriter.mm:
+        (WebCore::toUTI): Use bridge_cast.
+        (WebCore::toUTIUnlessAlreadyUTI): Use bridge_cast after doing adoptCF
+        rather than first casting and then doing an adoptNS, relying on it doing the
+        correct thing for a CF object. This fixes an ARC incompatibility.
+        (WebCore::createPasteboardWriter): Ditto.
+
 2021-10-24  Alexey Shvayka  <shvaikal...@gmail.com>
 
         Assertions in IDBTransaction::request*() methods fail on cross-realm methods

Modified: trunk/Source/WebCore/platform/cocoa/SharedBufferCocoa.mm (284762 => 284763)


--- trunk/Source/WebCore/platform/cocoa/SharedBufferCocoa.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebCore/platform/cocoa/SharedBufferCocoa.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,6 +31,7 @@
 #import <_javascript_Core/InitializeThreading.h>
 #import <string.h>
 #import <wtf/MainThread.h>
+#import <wtf/cocoa/TypeCastsCocoa.h>
 #import <wtf/cocoa/VectorCocoa.h>
 
 @interface WebCoreSharedBufferData : NSData
@@ -84,19 +85,19 @@
 
 namespace WebCore {
 
-Ref<SharedBuffer> SharedBuffer::create(NSData *nsData)
+Ref<SharedBuffer> SharedBuffer::create(NSData *data)
 {
-    return adoptRef(*new SharedBuffer((__bridge CFDataRef)nsData));
+    return adoptRef(*new SharedBuffer(bridge_cast(data)));
 }
 
-void SharedBuffer::append(NSData *nsData)
+void SharedBuffer::append(NSData *data)
 {
-    return append((__bridge CFDataRef)nsData);
+    return append(bridge_cast(data));
 }
 
 RetainPtr<NSData> SharedBuffer::createNSData() const
 {
-    return adoptNS((NSData *)createCFData().leakRef());
+    return bridge_cast(createCFData());
 }
 
 RetainPtr<CFDataRef> SharedBuffer::createCFData() const
@@ -105,13 +106,12 @@
     if (!m_segments.size())
         return adoptCF(CFDataCreate(nullptr, nullptr, 0));
     ASSERT(m_segments.size() == 1);
-    return adoptCF((__bridge CFDataRef)m_segments[0].segment->createNSData().leakRef());
+    return bridge_cast(m_segments[0].segment->createNSData());
 }
 
 RefPtr<SharedBuffer> SharedBuffer::createFromReadingFile(const String& filePath)
 {
-    NSData *resourceData = [NSData dataWithContentsOfFile:filePath];
-    if (resourceData) 
+    if (auto resourceData = [NSData dataWithContentsOfFile:filePath])
         return SharedBuffer::create(resourceData);
     return nullptr;
 }

Modified: trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm (284762 => 284763)


--- trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -32,6 +32,8 @@
 #import "HEVCUtilities.h"
 #import "MediaCapabilitiesInfo.h"
 #import <wtf/cf/TypeCastsCF.h>
+#import <wtf/cocoa/TypeCastsCocoa.h>
+#import <wtf/cocoa/VectorCocoa.h>
 #import <wtf/text/StringToIntegerConversion.h>
 
 #import "VideoToolboxSoftLink.h"
@@ -136,21 +138,12 @@
 
 static std::optional<Vector<uint16_t>> parseStringArrayFromDictionaryToUInt16Vector(CFDictionaryRef dictionary, const void* key)
 {
-    auto value = CFDictionaryGetValue(dictionary, key);
-    if (!value || CFGetTypeID(value) != CFArrayGetTypeID())
+    auto array = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(dictionary, key));
+    if (!array)
         return std::nullopt;
-    NSArray *array = (__bridge NSArray *)value;
-    Vector<uint16_t> vector;
-    vector.reserveInitialCapacity(array.count);
-    for (id value in array) {
-        if (![value isKindOfClass:NSString.class])
-            return std::nullopt;
-        auto numericValue = parseInteger<uint16_t>(String((NSString *)value));
-        if (!numericValue)
-            return std::nullopt;
-        vector.uncheckedAppend(*numericValue);
-    }
-    return vector;
+    return makeVector(bridge_cast(array), [] (id value) {
+        return parseInteger<uint16_t>(String(dynamic_objc_cast<NSString>(value)));
+    });
 }
 
 std::optional<MediaCapabilitiesInfo> validateDoViParameters(const DoViParameters& parameters, bool hasAlphaChannel, bool hdrSupport)

Modified: trunk/Source/WebCore/platform/mac/PasteboardWriter.mm (284762 => 284763)


--- trunk/Source/WebCore/platform/mac/PasteboardWriter.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebCore/platform/mac/PasteboardWriter.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -33,6 +33,7 @@
 #import "PasteboardWriterData.h"
 #import "SharedBuffer.h"
 #import <pal/spi/mac/NSPasteboardSPI.h>
+#import <wtf/cocoa/TypeCastsCocoa.h>
 
 namespace WebCore {
 
@@ -39,7 +40,7 @@
 static RetainPtr<NSString> toUTI(NSString *pasteboardType)
 {
 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-    return adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)pasteboardType, nullptr));
+    return bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, bridge_cast(pasteboardType), nullptr)));
 ALLOW_DEPRECATED_DECLARATIONS_END
 }
 
@@ -46,7 +47,7 @@
 static RetainPtr<NSString> toUTIUnlessAlreadyUTI(NSString *type)
 {
 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-    if (UTTypeIsDeclared((__bridge CFStringRef)type) || UTTypeIsDynamic((__bridge CFStringRef)type)) {
+    if (UTTypeIsDeclared(bridge_cast(type)) || UTTypeIsDynamic(bridge_cast(type))) {
         // This is already a UTI.
         return type;
     }
@@ -62,9 +63,9 @@
     if (auto& plainText = data.plainText()) {
         [pasteboardItem setString:plainText->text forType:NSPasteboardTypeString];
         if (plainText->canSmartCopyOrDelete) {
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-            auto smartPasteType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)_NXSmartPaste, nullptr));
-ALLOW_DEPRECATED_DECLARATIONS_END
+            ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+            auto smartPasteType = bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, bridge_cast(_NXSmartPaste), nullptr)));
+            ALLOW_DEPRECATED_DECLARATIONS_END
             [pasteboardItem setData:[NSData data] forType:smartPasteType.get()];
         }
     }
@@ -106,15 +107,15 @@
 
     if (auto& webContent = data.webContent()) {
         if (webContent->canSmartCopyOrDelete) {
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-            auto smartPasteType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)_NXSmartPaste, nullptr));
-ALLOW_DEPRECATED_DECLARATIONS_END
+            ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+            auto smartPasteType = bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, bridge_cast(_NXSmartPaste), nullptr)));
+            ALLOW_DEPRECATED_DECLARATIONS_END
             [pasteboardItem setData:[NSData data] forType:smartPasteType.get()];
         }
         if (webContent->dataInWebArchiveFormat) {
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-            auto webArchiveType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)@"Apple Web Archive pasteboard type", nullptr));
-ALLOW_DEPRECATED_DECLARATIONS_END
+            ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+            auto webArchiveType = bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, CFSTR("Apple Web Archive pasteboard type"), nullptr)));
+            ALLOW_DEPRECATED_DECLARATIONS_END
             [pasteboardItem setData:webContent->dataInWebArchiveFormat->createNSData().get() forType:webArchiveType.get()];
         }
         if (webContent->dataInRTFDFormat)

Modified: trunk/Source/WebKit/ChangeLog (284762 => 284763)


--- trunk/Source/WebKit/ChangeLog	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebKit/ChangeLog	2021-10-24 18:13:21 UTC (rev 284763)
@@ -1,3 +1,37 @@
+2021-10-24  Darin Adler  <da...@apple.com>
+
+        [Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=232200
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/Cocoa/ArgumentCodersCocoa.mm:
+        (-[WKSecureCodingURLWrapper encodeWithCoder:]): Use bridge_cast.
+        (-[WKSecureCodingURLWrapper initWithCoder:]): Use bridge_cast
+        after calling adoptCF rather than first doing a bridging cast and
+        then doing adoptNS and relying on it correctly adopting a CF object.
+        This fixes an ARC incompatibility.
+        (IPC::encodeDataInternal): Use bridge_cast.
+        (IPC::decodeDataInternal): Use bridge_cast/WTFMove instead of
+        adoptNS/cast/leakRef. This fixes an ARC incompatibility
+        (IPC::encodeDateInternal): Use bridge_cast.
+        (IPC::decodeDateInternal): Use bridge_cast/WTFMove as above.
+        (IPC::encodeNumberInternal): Use bridge_cast.
+        (IPC::decodeNumberInternal): Use bridge_cast/WTFMove as above.
+        (IPC::decodeSecureCodingInternal): Use bridge_cast.
+        (IPC::encodeStringInternal): Use bridge_cast.
+        (IPC::decodeStringInternal): Use bridge_cast/WTFMove as above.
+        (IPC::encodeURLInternal): Use bridge_cast.
+        (IPC::decodeURLInternal): Use bridge_cast/WTFMove as above.
+
+        * UIProcess/API/Cocoa/WKConnection.mm:
+        (didReceiveMessage): Use bridge_cast and remove unneeded use of
+        RetainPtr/get on the body.
+
+        * UIProcess/Plugins/mac/PluginInfoStoreMac.mm:
+        (WebKit::PluginInfoStore::pluginPathsInDirectory): Use bridge_cast
+        and makeVectort.
+
 2021-10-23  Dean Jackson  <d...@apple.com>
 
         Disable PiP when HAVE(UIKIT_WEBKIT_INTERNALS)

Modified: trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm (284762 => 284763)


--- trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -105,7 +105,7 @@
         [coder encodeObject:baseURL forKey:baseURLKey];
 
     WTF::URLCharBuffer urlBytes;
-    WTF::getURLBytes((__bridge CFURLRef)m_wrappedURL.get(), urlBytes);
+    WTF::getURLBytes(bridge_cast(m_wrappedURL.get()), urlBytes);
     [coder encodeBytes:urlBytes.data() length:urlBytes.size()];
 }
 
@@ -124,7 +124,7 @@
 
     NSUInteger length;
     if (auto bytes = (UInt8 *)[coder decodeBytesWithReturnedLength:&length]) {
-        m_wrappedURL = adoptNS((__bridge NSURL*)CFURLCreateAbsoluteURLWithBytes(nullptr, bytes, length, kCFStringEncodingUTF8, (__bridge CFURLRef)baseURL.get(), true));
+        m_wrappedURL = bridge_cast(adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, bytes, length, kCFStringEncodingUTF8, bridge_cast(baseURL.get()), true)));
         if (!m_wrappedURL)
             LOG_ERROR("Failed to decode NSURL due to invalid encoding of length %d. Substituting a blank URL", length);
     }
@@ -279,7 +279,7 @@
 
 static inline void encodeDataInternal(Encoder& encoder, NSData *data)
 {
-    encoder << (__bridge CFDataRef)data;
+    encoder << bridge_cast(data);
 }
 
 static inline std::optional<RetainPtr<id>> decodeDataInternal(Decoder& decoder)
@@ -287,7 +287,7 @@
     RetainPtr<CFDataRef> data;
     if (!decoder.decode(data))
         return std::nullopt;
-    return { adoptNS((NSData *)data.leakRef()) };
+    return { bridge_cast(WTFMove(data)) };
 }
 
 #pragma mark - NSDate
@@ -294,7 +294,7 @@
 
 static inline void encodeDateInternal(Encoder& encoder, NSDate *date)
 {
-    encoder << (__bridge CFDateRef)date;
+    encoder << bridge_cast(date);
 }
 
 static inline std::optional<RetainPtr<id>> decodeDateInternal(Decoder& decoder)
@@ -302,7 +302,7 @@
     RetainPtr<CFDateRef> date;
     if (!decoder.decode(date))
         return std::nullopt;
-    return { adoptNS((NSDate *)date.leakRef()) };
+    return { bridge_cast(WTFMove(date)) };
 }
 
 #pragma mark - NSDictionary
@@ -387,7 +387,7 @@
 
 static inline void encodeNumberInternal(Encoder& encoder, NSNumber *number)
 {
-    encoder << (__bridge CFNumberRef)number;
+    encoder << bridge_cast(number);
 }
 
 static inline std::optional<RetainPtr<id>> decodeNumberInternal(Decoder& decoder)
@@ -395,7 +395,7 @@
     RetainPtr<CFNumberRef> number;
     if (!decoder.decode(number))
         return std::nullopt;
-    return { adoptNS((NSNumber *)number.leakRef()) };
+    return { bridge_cast(WTFMove(number)) };
 }
 
 #pragma mark - id <NSSecureCoding>
@@ -424,7 +424,7 @@
     if (!decoder.decode(data))
         return std::nullopt;
 
-    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:(__bridge NSData *)data.get() error:nullptr]);
+    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:bridge_cast(data.get()) error:nullptr]);
     unarchiver.get().decodingFailurePolicy = NSDecodingFailurePolicyRaiseException;
 
     auto delegate = adoptNS([[WKSecureCodingArchivingDelegate alloc] init]);
@@ -450,7 +450,7 @@
 
 static inline void encodeStringInternal(Encoder& encoder, NSString *string)
 {
-    encoder << (__bridge CFStringRef)string;
+    encoder << bridge_cast(string);
 }
 
 static inline std::optional<RetainPtr<id>> decodeStringInternal(Decoder& decoder)
@@ -458,7 +458,7 @@
     RetainPtr<CFStringRef> string;
     if (!decoder.decode(string))
         return std::nullopt;
-    return { adoptNS((NSString *)string.leakRef()) };
+    return { bridge_cast(WTFMove(string)) };
 }
 
 #pragma mark - NSURL
@@ -465,7 +465,7 @@
 
 static inline void encodeURLInternal(Encoder& encoder, NSURL *URL)
 {
-    encoder << (__bridge CFURLRef)URL;
+    encoder << bridge_cast(URL);
 }
 
 static inline std::optional<RetainPtr<id>> decodeURLInternal(Decoder& decoder)
@@ -473,7 +473,7 @@
     RetainPtr<CFURLRef> URL;
     if (!decoder.decode(URL))
         return std::nullopt;
-    return { adoptNS((NSURL *)URL.leakRef()) };
+    return { bridge_cast(WTFMove(URL)) };
 }
 
 #pragma mark - Entry Point Encoder / Decoder

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKConnection.mm (284762 => 284763)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKConnection.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKConnection.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -33,6 +33,7 @@
 #import <WebCore/WebCoreObjCExtras.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/WeakObjCPtr.h>
+#import <wtf/cocoa/TypeCastsCocoa.h>
 #import <wtf/text/WTFString.h>
 
 ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
@@ -59,9 +60,9 @@
     auto delegate = connection->_delegate.get();
 
     if ([delegate respondsToSelector:@selector(connection:didReceiveMessageWithName:body:)]) {
-        RetainPtr<CFStringRef> nsMessageName = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName));
-        RetainPtr<id> nsMessageBody = static_cast<WebKit::ObjCObjectGraph*>(WebKit::toImpl(messageBody))->rootObject();
-        [delegate connection:connection didReceiveMessageWithName:(__bridge NSString *)nsMessageName.get() body:nsMessageBody.get()];
+        auto name = bridge_cast(adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName)));
+        id body = static_cast<WebKit::ObjCObjectGraph*>(WebKit::toImpl(messageBody))->rootObject();
+        [delegate connection:connection didReceiveMessageWithName:name.get() body:body];
     }
 }
 

Modified: trunk/Source/WebKit/UIProcess/Plugins/mac/PluginInfoStoreMac.mm (284762 => 284763)


--- trunk/Source/WebKit/UIProcess/Plugins/mac/PluginInfoStoreMac.mm	2021-10-24 17:47:17 UTC (rev 284762)
+++ trunk/Source/WebKit/UIProcess/Plugins/mac/PluginInfoStoreMac.mm	2021-10-24 18:13:21 UTC (rev 284763)
@@ -34,6 +34,8 @@
 #import <WebCore/PluginBlocklist.h>
 #import <pwd.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/cocoa/TypeCastsCocoa.h>
+#import <wtf/cocoa/VectorCocoa.h>
 #import <wtf/text/CString.h>
 
 namespace WebKit {
@@ -55,14 +57,10 @@
     
 Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory)
 {
-    Vector<String> pluginPaths;
-
-    RetainPtr<CFStringRef> directoryCFString = directory.createCFString();
-    NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:(__bridge NSString *)directoryCFString.get() error:nil];
-    for (NSString *filename in filenames)
-        pluginPaths.append([(__bridge NSString *)directoryCFString.get() stringByAppendingPathComponent:filename]);
-    
-    return pluginPaths;
+    auto directoryNSString = bridge_cast(directory.createCFString());
+    return makeVector([[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryNSString.get() error:nil], [&] (id filename) -> std::optional<String> {
+        return [directoryNSString stringByAppendingPathComponent:filename];
+    });
 }
 
 Vector<String> PluginInfoStore::individualPluginPaths()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to