Changeset 260112 in webkit


Ignore:
Timestamp:
Apr 14, 2020, 6:24:30 PM (5 years ago)
Author:
ddkilzer@apple.com
Message:

dictionaryValueOfType() in WebCoreArgumentCodersMac.mm can be replaced with dynamic_cf_cast<>()
<https://webkit.org/b/210456>

Reviewed by Darin Adler.

  • Shared/mac/WebCoreArgumentCodersMac.mm:

(IPC::dictionaryValueOfType): Delete.
(IPC::extractDictionaryValue): Add.

  • Use dynamic_cf_cast<>() in place of manually checking the CFTypeID of each object.

(IPC::createArchiveList):

  • Call new extractDictionaryValue() template function to verify values are the correct types in the dictionary and to set the output variables.
Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260111 r260112  
     12020-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
    1182020-04-14  David Kilzer  <ddkilzer@apple.com>
    219
  • trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm

    r260111 r260112  
    11/*
    2  * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 * Copyright (C) 2013 Company 100 Inc. All rights reserved.
    44 *
     
    4141#import <pal/spi/cf/CFNetworkSPI.h>
    4242#import <wtf/MachSendRight.h>
     43#import <wtf/cf/TypeCastsCF.h>
    4344
    4445#if ENABLE(WIRELESS_PLAYBACK_TARGET)
     
    9293}
    9394
    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;
     95template<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;
    100104}
    101105
    102106static bool createArchiveList(CFDictionaryRef representation, CFTypeRef tokenNull, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties, CFNumberRef* expectedContentLength, CFStringRef* mimeType)
    103107{
    104     CFNumberRef versionNumber = (CFNumberRef)dictionaryValueOfType(representation, CFSTR("version"), CFNumberGetTypeID());
     108    auto versionNumber = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(representation, CFSTR("version")));
    105109    if (!versionNumber)
    106110        return false;
     
    109113        return false;
    110114
    111     CFArrayRef archiveListArray = (CFArrayRef)dictionaryValueOfType(representation, CFSTR("archiveList"), CFArrayGetTypeID());
     115    auto archiveListArray = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(representation, CFSTR("archiveList")));
    112116    if (!archiveListArray)
    113117        return false;
     
    130134    }
    131135
    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;
    140142
    141143    return true;
Note: See TracChangeset for help on using the changeset viewer.