Changeset 260112 in webkit
- Timestamp:
- Apr 14, 2020, 6:24:30 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r260111 r260112 1 2020-04-14 David Kilzer <ddkilzer@apple.com> 2 3 dictionaryValueOfType() in WebCoreArgumentCodersMac.mm can be replaced with dynamic_cf_cast<>() 4 <https://webkit.org/b/210456> 5 6 Reviewed by Darin Adler. 7 8 * Shared/mac/WebCoreArgumentCodersMac.mm: 9 (IPC::dictionaryValueOfType): Delete. 10 (IPC::extractDictionaryValue): Add. 11 - Use dynamic_cf_cast<>() in place of manually checking the 12 CFTypeID of each object. 13 (IPC::createArchiveList): 14 - Call new extractDictionaryValue() template function to verify 15 values are the correct types in the dictionary and to set the 16 output variables. 17 1 18 2020-04-14 David Kilzer <ddkilzer@apple.com> 2 19 -
trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm
r260111 r260112 1 1 /* 2 * Copyright (C) 2010-20 18Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2013 Company 100 Inc. All rights reserved. 4 4 * … … 41 41 #import <pal/spi/cf/CFNetworkSPI.h> 42 42 #import <wtf/MachSendRight.h> 43 #import <wtf/cf/TypeCastsCF.h> 43 44 44 45 #if ENABLE(WIRELESS_PLAYBACK_TARGET) … … 92 93 } 93 94 94 static CFTypeRef dictionaryValueOfType(CFDictionaryRef dictionary, CFStringRef key, CFTypeID type) 95 { 96 CFTypeRef value = CFDictionaryGetValue(dictionary, key); 97 if (value && CFGetTypeID(value) == type) 98 return value; 99 return nullptr; 95 template<typename ValueType> bool extractDictionaryValue(CFDictionaryRef dictionary, CFStringRef key, ValueType* result) 96 { 97 auto untypedValue = CFDictionaryGetValue(dictionary, key); 98 auto value = dynamic_cf_cast<ValueType>(untypedValue); 99 if (untypedValue && !value) 100 return false; 101 if (result) 102 *result = value; 103 return true; 100 104 } 101 105 102 106 static bool createArchiveList(CFDictionaryRef representation, CFTypeRef tokenNull, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties, CFNumberRef* expectedContentLength, CFStringRef* mimeType) 103 107 { 104 CFNumberRef versionNumber = (CFNumberRef)dictionaryValueOfType(representation, CFSTR("version"), CFNumberGetTypeID());108 auto versionNumber = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(representation, CFSTR("version"))); 105 109 if (!versionNumber) 106 110 return false; … … 109 113 return false; 110 114 111 CFArrayRef archiveListArray = (CFArrayRef)dictionaryValueOfType(representation, CFSTR("archiveList"), CFArrayGetTypeID());115 auto archiveListArray = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(representation, CFSTR("archiveList"))); 112 116 if (!archiveListArray) 113 117 return false; … … 130 134 } 131 135 132 if (protocolProperties) 133 *protocolProperties = (CFDictionaryRef)dictionaryValueOfType(representation, CFSTR("protocolProperties"), CFDictionaryGetTypeID()); 134 135 if (expectedContentLength) 136 *expectedContentLength = (CFNumberRef)dictionaryValueOfType(representation, CFSTR("expectedContentLength"), CFNumberGetTypeID()); 137 138 if (mimeType) 139 *mimeType = (CFStringRef)dictionaryValueOfType(representation, CFSTR("mimeType"), CFStringGetTypeID()); 136 if (!extractDictionaryValue(representation, CFSTR("protocolProperties"), protocolProperties)) 137 return false; 138 if (!extractDictionaryValue(representation, CFSTR("expectedContentLength"), expectedContentLength)) 139 return false; 140 if (!extractDictionaryValue(representation, CFSTR("mimeType"), mimeType)) 141 return false; 140 142 141 143 return true;
Note:
See TracChangeset
for help on using the changeset viewer.