Changeset 284763 in webkit
- Timestamp:
- Oct 24, 2021, 11:13:21 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 10 edited
-
WTF/ChangeLog (modified) (1 diff)
-
WTF/wtf/cocoa/URLCocoa.mm (modified) (5 diffs)
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/platform/cocoa/SharedBufferCocoa.mm (modified) (4 diffs)
-
WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm (modified) (2 diffs)
-
WebCore/platform/mac/PasteboardWriter.mm (modified) (5 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm (modified) (13 diffs)
-
WebKit/UIProcess/API/Cocoa/WKConnection.mm (modified) (2 diffs)
-
WebKit/UIProcess/Plugins/mac/PluginInfoStoreMac.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r284753 r284763 1 2021-10-24 Darin Adler <darin@apple.com> 2 3 [Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly 4 https://bugs.webkit.org/show_bug.cgi?id=232200 5 6 Reviewed by Anders Carlsson. 7 8 * wtf/cocoa/URLCocoa.mm: 9 (WTF::URL::URL): Use bridge_cast. 10 (WTF::URL::createCFURL const): Ditto, using the RetainPtr version to avoid 11 retain count churn. 12 1 13 2021-10-23 Alan Bujtas <zalan@apple.com> 2 14 -
trunk/Source/WTF/wtf/cocoa/URLCocoa.mm
r278619 r284763 1 1 /* 2 * Copyright (C) 2004 , 2008Apple Inc. All rights reserved.2 * Copyright (C) 2004-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 #import <wtf/cf/CFURLExtras.h> 31 31 #import <wtf/cocoa/NSURLExtras.h> 32 #import <wtf/cocoa/TypeCastsCocoa.h> 32 33 #import <wtf/text/CString.h> 33 34 … … 38 39 namespace WTF { 39 40 40 URL::URL(NSURL * url)41 URL::URL(NSURL *cocoaURL) 41 42 { 42 if (! url) {43 if (!cocoaURL) { 43 44 invalidate(); 44 45 return; … … 46 47 47 48 // FIXME: Why is it OK to ignore base URL here? 48 CString urlBytes;49 WTF::getURLBytes( (__bridge CFURLRef)url, urlBytes);50 URLParser parser( urlBytes.data());49 CString bytes; 50 WTF::getURLBytes(bridge_cast(cocoaURL), bytes); 51 URLParser parser(bytes.data()); 51 52 *this = parser.result(); 52 53 } … … 66 67 if (isEmpty()) { 67 68 // We use the toll-free bridge between NSURL and CFURL to create a CFURLRef supporting both empty and null values. 68 return (__bridge CFURLRef)adoptNS([[NSURL alloc] initWithString:@""]).get();69 return bridge_cast(adoptNS([[NSURL alloc] initWithString:@""])); 69 70 } 70 71 -
trunk/Source/WebCore/ChangeLog
r284761 r284763 1 2021-10-24 Darin Adler <darin@apple.com> 2 3 [Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly 4 https://bugs.webkit.org/show_bug.cgi?id=232200 5 6 Reviewed by Anders Carlsson. 7 8 * platform/cocoa/SharedBufferCocoa.mm: 9 (WebCore::SharedBuffer::create): Use bridge_cast. 10 (WebCore::SharedBuffer::append): Ditto. 11 (WebCore::SharedBuffer::createNSData const): Ditto. Here we are replacing 12 a leakRef/adoptNS pair, so this fixes an ARC incompatibility. 13 (WebCore::SharedBuffer::createCFData const): Ditto. Here we are replacing 14 a leakRef/adoptCF pair, so this fixes an ARC incompatibility. 15 (WebCore::SharedBuffer::createFromReadingFile): Tweaked coding style. 16 17 * platform/graphics/cocoa/HEVCUtilitiesCocoa.mm: 18 (WebCore::parseStringArrayFromDictionaryToUInt16Vector): Use dynamic_cf_cast, 19 dynamic_objc_cast, and makeVector to reduce code without behavior changes. 20 21 * platform/mac/PasteboardWriter.mm: 22 (WebCore::toUTI): Use bridge_cast. 23 (WebCore::toUTIUnlessAlreadyUTI): Use bridge_cast after doing adoptCF 24 rather than first casting and then doing an adoptNS, relying on it doing the 25 correct thing for a CF object. This fixes an ARC incompatibility. 26 (WebCore::createPasteboardWriter): Ditto. 27 1 28 2021-10-24 Alexey Shvayka <shvaikalesh@gmail.com> 2 29 -
trunk/Source/WebCore/platform/cocoa/SharedBufferCocoa.mm
r267938 r284763 1 1 /* 2 * Copyright (C) 2006-20 19Apple Inc. All rights reserved.2 * Copyright (C) 2006-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 32 32 #import <string.h> 33 33 #import <wtf/MainThread.h> 34 #import <wtf/cocoa/TypeCastsCocoa.h> 34 35 #import <wtf/cocoa/VectorCocoa.h> 35 36 … … 85 86 namespace WebCore { 86 87 87 Ref<SharedBuffer> SharedBuffer::create(NSData * nsData)88 Ref<SharedBuffer> SharedBuffer::create(NSData *data) 88 89 { 89 return adoptRef(*new SharedBuffer( (__bridge CFDataRef)nsData));90 return adoptRef(*new SharedBuffer(bridge_cast(data))); 90 91 } 91 92 92 void SharedBuffer::append(NSData * nsData)93 void SharedBuffer::append(NSData *data) 93 94 { 94 return append( (__bridge CFDataRef)nsData);95 return append(bridge_cast(data)); 95 96 } 96 97 97 98 RetainPtr<NSData> SharedBuffer::createNSData() const 98 99 { 99 return adoptNS((NSData *)createCFData().leakRef());100 return bridge_cast(createCFData()); 100 101 } 101 102 … … 106 107 return adoptCF(CFDataCreate(nullptr, nullptr, 0)); 107 108 ASSERT(m_segments.size() == 1); 108 return adoptCF((__bridge CFDataRef)m_segments[0].segment->createNSData().leakRef());109 return bridge_cast(m_segments[0].segment->createNSData()); 109 110 } 110 111 111 112 RefPtr<SharedBuffer> SharedBuffer::createFromReadingFile(const String& filePath) 112 113 { 113 NSData *resourceData = [NSData dataWithContentsOfFile:filePath]; 114 if (resourceData) 114 if (auto resourceData = [NSData dataWithContentsOfFile:filePath]) 115 115 return SharedBuffer::create(resourceData); 116 116 return nullptr; -
trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm
r281791 r284763 33 33 #import "MediaCapabilitiesInfo.h" 34 34 #import <wtf/cf/TypeCastsCF.h> 35 #import <wtf/cocoa/TypeCastsCocoa.h> 36 #import <wtf/cocoa/VectorCocoa.h> 35 37 #import <wtf/text/StringToIntegerConversion.h> 36 38 … … 137 139 static std::optional<Vector<uint16_t>> parseStringArrayFromDictionaryToUInt16Vector(CFDictionaryRef dictionary, const void* key) 138 140 { 139 auto value = CFDictionaryGetValue(dictionary, key);140 if (! value || CFGetTypeID(value) != CFArrayGetTypeID())141 auto array = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(dictionary, key)); 142 if (!array) 141 143 return std::nullopt; 142 NSArray *array = (__bridge NSArray *)value; 143 Vector<uint16_t> vector; 144 vector.reserveInitialCapacity(array.count); 145 for (id value in array) { 146 if (![value isKindOfClass:NSString.class]) 147 return std::nullopt; 148 auto numericValue = parseInteger<uint16_t>(String((NSString *)value)); 149 if (!numericValue) 150 return std::nullopt; 151 vector.uncheckedAppend(*numericValue); 152 } 153 return vector; 144 return makeVector(bridge_cast(array), [] (id value) { 145 return parseInteger<uint16_t>(String(dynamic_objc_cast<NSString>(value))); 146 }); 154 147 } 155 148 -
trunk/Source/WebCore/platform/mac/PasteboardWriter.mm
r269869 r284763 34 34 #import "SharedBuffer.h" 35 35 #import <pal/spi/mac/NSPasteboardSPI.h> 36 #import <wtf/cocoa/TypeCastsCocoa.h> 36 37 37 38 namespace WebCore { … … 40 41 { 41 42 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 42 return adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)pasteboardType, nullptr));43 return bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, bridge_cast(pasteboardType), nullptr))); 43 44 ALLOW_DEPRECATED_DECLARATIONS_END 44 45 } … … 47 48 { 48 49 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 49 if (UTTypeIsDeclared( (__bridge CFStringRef)type) || UTTypeIsDynamic((__bridge CFStringRef)type)) {50 if (UTTypeIsDeclared(bridge_cast(type)) || UTTypeIsDynamic(bridge_cast(type))) { 50 51 // This is already a UTI. 51 52 return type; … … 63 64 [pasteboardItem setString:plainText->text forType:NSPasteboardTypeString]; 64 65 if (plainText->canSmartCopyOrDelete) { 65 ALLOW_DEPRECATED_DECLARATIONS_BEGIN66 auto smartPasteType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)_NXSmartPaste, nullptr));67 ALLOW_DEPRECATED_DECLARATIONS_END66 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 67 auto smartPasteType = bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, bridge_cast(_NXSmartPaste), nullptr))); 68 ALLOW_DEPRECATED_DECLARATIONS_END 68 69 [pasteboardItem setData:[NSData data] forType:smartPasteType.get()]; 69 70 } … … 107 108 if (auto& webContent = data.webContent()) { 108 109 if (webContent->canSmartCopyOrDelete) { 109 ALLOW_DEPRECATED_DECLARATIONS_BEGIN110 auto smartPasteType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)_NXSmartPaste, nullptr));111 ALLOW_DEPRECATED_DECLARATIONS_END110 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 111 auto smartPasteType = bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, bridge_cast(_NXSmartPaste), nullptr))); 112 ALLOW_DEPRECATED_DECLARATIONS_END 112 113 [pasteboardItem setData:[NSData data] forType:smartPasteType.get()]; 113 114 } 114 115 if (webContent->dataInWebArchiveFormat) { 115 ALLOW_DEPRECATED_DECLARATIONS_BEGIN116 auto webArchiveType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)@"Apple Web Archive pasteboard type", nullptr));117 ALLOW_DEPRECATED_DECLARATIONS_END116 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 117 auto webArchiveType = bridge_cast(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, CFSTR("Apple Web Archive pasteboard type"), nullptr))); 118 ALLOW_DEPRECATED_DECLARATIONS_END 118 119 [pasteboardItem setData:webContent->dataInWebArchiveFormat->createNSData().get() forType:webArchiveType.get()]; 119 120 } -
trunk/Source/WebKit/ChangeLog
r284750 r284763 1 2021-10-24 Darin Adler <darin@apple.com> 2 3 [Cocoa] Adopt bridge_cast and makeVector in a few more places, including cases where adoptCF/NS was used incorrectly 4 https://bugs.webkit.org/show_bug.cgi?id=232200 5 6 Reviewed by Anders Carlsson. 7 8 * Shared/Cocoa/ArgumentCodersCocoa.mm: 9 (-[WKSecureCodingURLWrapper encodeWithCoder:]): Use bridge_cast. 10 (-[WKSecureCodingURLWrapper initWithCoder:]): Use bridge_cast 11 after calling adoptCF rather than first doing a bridging cast and 12 then doing adoptNS and relying on it correctly adopting a CF object. 13 This fixes an ARC incompatibility. 14 (IPC::encodeDataInternal): Use bridge_cast. 15 (IPC::decodeDataInternal): Use bridge_cast/WTFMove instead of 16 adoptNS/cast/leakRef. This fixes an ARC incompatibility 17 (IPC::encodeDateInternal): Use bridge_cast. 18 (IPC::decodeDateInternal): Use bridge_cast/WTFMove as above. 19 (IPC::encodeNumberInternal): Use bridge_cast. 20 (IPC::decodeNumberInternal): Use bridge_cast/WTFMove as above. 21 (IPC::decodeSecureCodingInternal): Use bridge_cast. 22 (IPC::encodeStringInternal): Use bridge_cast. 23 (IPC::decodeStringInternal): Use bridge_cast/WTFMove as above. 24 (IPC::encodeURLInternal): Use bridge_cast. 25 (IPC::decodeURLInternal): Use bridge_cast/WTFMove as above. 26 27 * UIProcess/API/Cocoa/WKConnection.mm: 28 (didReceiveMessage): Use bridge_cast and remove unneeded use of 29 RetainPtr/get on the body. 30 31 * UIProcess/Plugins/mac/PluginInfoStoreMac.mm: 32 (WebKit::PluginInfoStore::pluginPathsInDirectory): Use bridge_cast 33 and makeVectort. 34 1 35 2021-10-23 Dean Jackson <dino@apple.com> 2 36 -
trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm
r284630 r284763 106 106 107 107 WTF::URLCharBuffer urlBytes; 108 WTF::getURLBytes( (__bridge CFURLRef)m_wrappedURL.get(), urlBytes);108 WTF::getURLBytes(bridge_cast(m_wrappedURL.get()), urlBytes); 109 109 [coder encodeBytes:urlBytes.data() length:urlBytes.size()]; 110 110 } … … 125 125 NSUInteger length; 126 126 if (auto bytes = (UInt8 *)[coder decodeBytesWithReturnedLength:&length]) { 127 m_wrappedURL = adoptNS((__bridge NSURL*)CFURLCreateAbsoluteURLWithBytes(nullptr, bytes, length, kCFStringEncodingUTF8, (__bridge CFURLRef)baseURL.get(), true));127 m_wrappedURL = bridge_cast(adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, bytes, length, kCFStringEncodingUTF8, bridge_cast(baseURL.get()), true))); 128 128 if (!m_wrappedURL) 129 129 LOG_ERROR("Failed to decode NSURL due to invalid encoding of length %d. Substituting a blank URL", length); … … 280 280 static inline void encodeDataInternal(Encoder& encoder, NSData *data) 281 281 { 282 encoder << (__bridge CFDataRef)data;282 encoder << bridge_cast(data); 283 283 } 284 284 … … 288 288 if (!decoder.decode(data)) 289 289 return std::nullopt; 290 return { adoptNS((NSData *)data.leakRef()) };290 return { bridge_cast(WTFMove(data)) }; 291 291 } 292 292 … … 295 295 static inline void encodeDateInternal(Encoder& encoder, NSDate *date) 296 296 { 297 encoder << (__bridge CFDateRef)date;297 encoder << bridge_cast(date); 298 298 } 299 299 … … 303 303 if (!decoder.decode(date)) 304 304 return std::nullopt; 305 return { adoptNS((NSDate *)date.leakRef()) };305 return { bridge_cast(WTFMove(date)) }; 306 306 } 307 307 … … 388 388 static inline void encodeNumberInternal(Encoder& encoder, NSNumber *number) 389 389 { 390 encoder << (__bridge CFNumberRef)number;390 encoder << bridge_cast(number); 391 391 } 392 392 … … 396 396 if (!decoder.decode(number)) 397 397 return std::nullopt; 398 return { adoptNS((NSNumber *)number.leakRef()) };398 return { bridge_cast(WTFMove(number)) }; 399 399 } 400 400 … … 425 425 return std::nullopt; 426 426 427 auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData: (__bridge NSData *)data.get() error:nullptr]);427 auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:bridge_cast(data.get()) error:nullptr]); 428 428 unarchiver.get().decodingFailurePolicy = NSDecodingFailurePolicyRaiseException; 429 429 … … 451 451 static inline void encodeStringInternal(Encoder& encoder, NSString *string) 452 452 { 453 encoder << (__bridge CFStringRef)string;453 encoder << bridge_cast(string); 454 454 } 455 455 … … 459 459 if (!decoder.decode(string)) 460 460 return std::nullopt; 461 return { adoptNS((NSString *)string.leakRef()) };461 return { bridge_cast(WTFMove(string)) }; 462 462 } 463 463 … … 466 466 static inline void encodeURLInternal(Encoder& encoder, NSURL *URL) 467 467 { 468 encoder << (__bridge CFURLRef)URL;468 encoder << bridge_cast(URL); 469 469 } 470 470 … … 474 474 if (!decoder.decode(URL)) 475 475 return std::nullopt; 476 return { adoptNS((NSURL *)URL.leakRef()) };476 return { bridge_cast(WTFMove(URL)) }; 477 477 } 478 478 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKConnection.mm
r278780 r284763 34 34 #import <wtf/RetainPtr.h> 35 35 #import <wtf/WeakObjCPtr.h> 36 #import <wtf/cocoa/TypeCastsCocoa.h> 36 37 #import <wtf/text/WTFString.h> 37 38 … … 60 61 61 62 if ([delegate respondsToSelector:@selector(connection:didReceiveMessageWithName:body:)]) { 62 RetainPtr<CFStringRef> nsMessageName = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName));63 RetainPtr<id> nsMessageBody = static_cast<WebKit::ObjCObjectGraph*>(WebKit::toImpl(messageBody))->rootObject();64 [delegate connection:connection didReceiveMessageWithName: (__bridge NSString *)nsMessageName.get() body:nsMessageBody.get()];63 auto name = bridge_cast(adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName))); 64 id body = static_cast<WebKit::ObjCObjectGraph*>(WebKit::toImpl(messageBody))->rootObject(); 65 [delegate connection:connection didReceiveMessageWithName:name.get() body:body]; 65 66 } 66 67 } -
trunk/Source/WebKit/UIProcess/Plugins/mac/PluginInfoStoreMac.mm
r276880 r284763 35 35 #import <pwd.h> 36 36 #import <wtf/RetainPtr.h> 37 #import <wtf/cocoa/TypeCastsCocoa.h> 38 #import <wtf/cocoa/VectorCocoa.h> 37 39 #import <wtf/text/CString.h> 38 40 … … 56 58 Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory) 57 59 { 58 Vector<String> pluginPaths; 59 60 RetainPtr<CFStringRef> directoryCFString = directory.createCFString(); 61 NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:(__bridge NSString *)directoryCFString.get() error:nil]; 62 for (NSString *filename in filenames) 63 pluginPaths.append([(__bridge NSString *)directoryCFString.get() stringByAppendingPathComponent:filename]); 64 65 return pluginPaths; 60 auto directoryNSString = bridge_cast(directory.createCFString()); 61 return makeVector([[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryNSString.get() error:nil], [&] (id filename) -> std::optional<String> { 62 return [directoryNSString stringByAppendingPathComponent:filename]; 63 }); 66 64 } 67 65
Note:
See TracChangeset
for help on using the changeset viewer.