Changeset 222584 in webkit


Ignore:
Timestamp:
Sep 27, 2017 4:50:21 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Allow modern decoding of std::optional<T>
https://bugs.webkit.org/show_bug.cgi?id=177519

Reviewed by Tim Horton.

Source/WebCore:

  • platform/DragItem.h:

(WebCore::DragItem::decode):

Source/WebKit:

  • Platform/IPC/ArgumentCoders.h:

(IPC::ArgumentCoder<std::optional<T>>::decode):

  • Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:

(IPC::ArgumentCoder<WebCore::PaymentAuthorizationResult>::decode):
(IPC::ArgumentCoder<WebCore::PaymentError>::decode):
(IPC::ArgumentCoder<WebCore::PaymentMethodUpdate>::decode):
(IPC::ArgumentCoder<WebCore::ShippingContactUpdate>::decode):
(IPC::ArgumentCoder<WebCore::ShippingMethodUpdate>::decode):

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<IntPoint>::decode):
(IPC::ArgumentCoder<IntSize>::decode):

  • Shared/WebCoreArgumentCoders.h:
  • Shared/WebPageCreationParameters.cpp:

(WebKit::WebPageCreationParameters::decode):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r222576 r222584  
     12017-09-27  Alex Christensen  <achristensen@webkit.org>
     2
     3        Allow modern decoding of std::optional<T>
     4        https://bugs.webkit.org/show_bug.cgi?id=177519
     5
     6        Reviewed by Tim Horton.
     7
     8        * platform/DragItem.h:
     9        (WebCore::DragItem::decode):
     10
    1112017-09-27  Myles C. Maxfield  <mmaxfield@apple.com>
    212
  • trunk/Source/WebCore/platform/DragItem.h

    r221907 r222584  
    9393        return false;
    9494    if (hasIndicatorData) {
    95         TextIndicatorData indicatorData;
    96         if (!decoder.decode(indicatorData))
     95        std::optional<TextIndicatorData> indicatorData;
     96        decoder >> indicatorData;
     97        if (!indicatorData)
    9798            return false;
    98         result.image.setIndicatorData(indicatorData);
     99        result.image.setIndicatorData(*indicatorData);
    99100    }
    100101    return true;
  • trunk/Source/WebKit/ChangeLog

    r222583 r222584  
     12017-09-27  Alex Christensen  <achristensen@webkit.org>
     2
     3        Allow modern decoding of std::optional<T>
     4        https://bugs.webkit.org/show_bug.cgi?id=177519
     5
     6        Reviewed by Tim Horton.
     7
     8        * Platform/IPC/ArgumentCoders.h:
     9        (IPC::ArgumentCoder<std::optional<T>>::decode):
     10        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
     11        (IPC::ArgumentCoder<WebCore::PaymentAuthorizationResult>::decode):
     12        (IPC::ArgumentCoder<WebCore::PaymentError>::decode):
     13        (IPC::ArgumentCoder<WebCore::PaymentMethodUpdate>::decode):
     14        (IPC::ArgumentCoder<WebCore::ShippingContactUpdate>::decode):
     15        (IPC::ArgumentCoder<WebCore::ShippingMethodUpdate>::decode):
     16        * Shared/WebCoreArgumentCoders.cpp:
     17        (IPC::ArgumentCoder<IntPoint>::decode):
     18        (IPC::ArgumentCoder<IntSize>::decode):
     19        * Shared/WebCoreArgumentCoders.h:
     20        * Shared/WebPageCreationParameters.cpp:
     21        (WebKit::WebPageCreationParameters::decode):
     22
    1232017-09-27  Commit Queue  <commit-queue@webkit.org>
    224
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h

    r222233 r222584  
    111111        return true;
    112112    }
     113   
     114    static std::optional<std::optional<T>> decode(Decoder& decoder)
     115    {
     116        std::optional<bool> isEngaged;
     117        decoder >> isEngaged;
     118        if (!isEngaged)
     119            return std::nullopt;
     120        if (*isEngaged) {
     121            std::optional<T> value;
     122            decoder >> value;
     123            if (!value)
     124                return std::nullopt;
     125            return std::optional<std::optional<T>>(WTFMove(*value));
     126        }
     127        return std::optional<std::optional<T>>(std::optional<T>(std::nullopt));
     128    }
    113129};
    114130
  • trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm

    r222233 r222584  
    8989}
    9090
    91 bool ArgumentCoder<WebCore::PaymentAuthorizationResult>::decode(Decoder& decoder, WebCore::PaymentAuthorizationResult& result)
    92 {
    93     if (!decoder.decode(result.status))
    94         return false;
    95     if (!decoder.decode(result.errors))
    96         return false;
    97 
    98     return true;
     91std::optional<WebCore::PaymentAuthorizationResult> ArgumentCoder<WebCore::PaymentAuthorizationResult>::decode(Decoder& decoder)
     92{
     93    std::optional<PaymentAuthorizationStatus> status;
     94    decoder >> status;
     95    if (!status)
     96        return std::nullopt;
     97
     98    std::optional<Vector<PaymentError>> errors;
     99    decoder >> errors;
     100    if (!errors)
     101        return std::nullopt;
     102   
     103    return {{ WTFMove(*status), WTFMove(*errors) }};
    99104}
    100105
     
    142147std::optional<WebCore::PaymentError> ArgumentCoder<WebCore::PaymentError>::decode(Decoder& decoder)
    143148{
    144     WebCore::PaymentError error;
    145     if (!decoder.decode(error.code))
    146         return std::nullopt;
    147     if (!decoder.decode(error.message))
    148         return std::nullopt;
    149     if (!decoder.decode(error.contactField))
    150         return std::nullopt;
    151 
    152     return WTFMove(error);
     149    std::optional<WebCore::PaymentError::Code> code;
     150    decoder >> code;
     151    if (!code)
     152        return std::nullopt;
     153   
     154    std::optional<String> message;
     155    decoder >> message;
     156    if (!message)
     157        return std::nullopt;
     158   
     159    std::optional<std::optional<WebCore::PaymentError::ContactField>> contactField;
     160    decoder >> contactField;
     161    if (!contactField)
     162        return std::nullopt;
     163
     164    return {{ WTFMove(*code), WTFMove(*message), WTFMove(*contactField) }};
    153165}
    154166
     
    227239}
    228240
    229 bool ArgumentCoder<WebCore::PaymentMethodUpdate>::decode(Decoder& decoder, WebCore::PaymentMethodUpdate& update)
     241std::optional<WebCore::PaymentMethodUpdate> ArgumentCoder<WebCore::PaymentMethodUpdate>::decode(Decoder& decoder)
    230242{
    231243    std::optional<ApplePaySessionPaymentRequest::TotalAndLineItems> newTotalAndLineItems;
    232244    decoder >> newTotalAndLineItems;
    233245    if (!newTotalAndLineItems)
    234         return false;
    235     update = { WTFMove(*newTotalAndLineItems) };
    236     return true;
     246        return std::nullopt;
     247    return {{ WTFMove(*newTotalAndLineItems) }};
    237248}
    238249
     
    448459}
    449460
    450 bool ArgumentCoder<WebCore::ShippingContactUpdate>::decode(Decoder& decoder, WebCore::ShippingContactUpdate& update)
    451 {
    452     if (!decoder.decode(update.errors))
    453         return false;
    454     if (!decoder.decode(update.newShippingMethods))
    455         return false;
     461std::optional<WebCore::ShippingContactUpdate> ArgumentCoder<WebCore::ShippingContactUpdate>::decode(Decoder& decoder)
     462{
     463    std::optional<Vector<PaymentError>> errors;
     464    decoder >> errors;
     465    if (!errors)
     466        return std::nullopt;
     467   
     468    std::optional<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> newShippingMethods;
     469    decoder >> newShippingMethods;
     470    if (!newShippingMethods)
     471        return std::nullopt;
    456472   
    457473    std::optional<ApplePaySessionPaymentRequest::TotalAndLineItems> newTotalAndLineItems;
    458474    decoder >> newTotalAndLineItems;
    459475    if (!newTotalAndLineItems)
    460         return false;
    461     update.newTotalAndLineItems = WTFMove(*newTotalAndLineItems);
    462 
    463     return true;
     476        return std::nullopt;
     477   
     478    return {{ WTFMove(*errors), WTFMove(*newShippingMethods), WTFMove(*newTotalAndLineItems) }};
    464479}
    465480
     
    469484}
    470485
    471 bool ArgumentCoder<WebCore::ShippingMethodUpdate>::decode(Decoder& decoder, WebCore::ShippingMethodUpdate& update)
     486std::optional<WebCore::ShippingMethodUpdate> ArgumentCoder<WebCore::ShippingMethodUpdate>::decode(Decoder& decoder)
    472487{
    473488    std::optional<ApplePaySessionPaymentRequest::TotalAndLineItems> newTotalAndLineItems;
    474489    decoder >> newTotalAndLineItems;
    475490    if (!newTotalAndLineItems)
    476         return false;
    477     update = { WTFMove(*newTotalAndLineItems) };
    478     return true;
     491        return std::nullopt;
     492    return {{ WTFMove(*newTotalAndLineItems) }};
    479493}
    480494
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r222392 r222584  
    560560}
    561561
     562std::optional<FloatPoint> ArgumentCoder<FloatPoint>::decode(Decoder& decoder)
     563{
     564    FloatPoint floatPoint;
     565    if (!SimpleArgumentCoder<FloatPoint>::decode(decoder, floatPoint))
     566        return std::nullopt;
     567    return WTFMove(floatPoint);
     568}
    562569
    563570void ArgumentCoder<FloatPoint3D>::encode(Encoder& encoder, const FloatPoint3D& floatPoint)
     
    659666}
    660667
     668std::optional<WebCore::IntPoint> ArgumentCoder<IntPoint>::decode(Decoder& decoder)
     669{
     670    IntPoint intPoint;
     671    if (!SimpleArgumentCoder<IntPoint>::decode(decoder, intPoint))
     672        return std::nullopt;
     673    return WTFMove(intPoint);
     674}
    661675
    662676void ArgumentCoder<IntRect>::encode(Encoder& encoder, const IntRect& intRect)
     
    678692}
    679693
    680 
    681694void ArgumentCoder<IntSize>::encode(Encoder& encoder, const IntSize& intSize)
    682695{
     
    689702}
    690703
     704std::optional<IntSize> ArgumentCoder<IntSize>::decode(Decoder& decoder)
     705{
     706    IntSize intSize;
     707    if (!SimpleArgumentCoder<IntSize>::decode(decoder, intSize))
     708        return std::nullopt;
     709    return WTFMove(intSize);
     710}
    691711
    692712void ArgumentCoder<LayoutSize>::encode(Encoder& encoder, const LayoutSize& layoutSize)
     
    22992319}
    23002320
    2301 bool ArgumentCoder<TextIndicatorData>::decode(Decoder& decoder, TextIndicatorData& textIndicatorData)
    2302 {
     2321std::optional<TextIndicatorData> ArgumentCoder<TextIndicatorData>::decode(Decoder& decoder)
     2322{
     2323    TextIndicatorData textIndicatorData;
    23032324    if (!decoder.decode(textIndicatorData.selectionRectInRootViewCoordinates))
    2304         return false;
     2325        return std::nullopt;
    23052326
    23062327    if (!decoder.decode(textIndicatorData.textBoundingRectInRootViewCoordinates))
    2307         return false;
     2328        return std::nullopt;
    23082329
    23092330    if (!decoder.decode(textIndicatorData.textRectsInBoundingRectCoordinates))
    2310         return false;
     2331        return std::nullopt;
    23112332
    23122333    if (!decoder.decode(textIndicatorData.contentImageWithoutSelectionRectInRootViewCoordinates))
    2313         return false;
     2334        return std::nullopt;
    23142335
    23152336    if (!decoder.decode(textIndicatorData.contentImageScaleFactor))
    2316         return false;
     2337        return std::nullopt;
    23172338
    23182339    if (!decoder.decode(textIndicatorData.estimatedBackgroundColor))
    2319         return false;
     2340        return std::nullopt;
    23202341
    23212342    if (!decoder.decodeEnum(textIndicatorData.presentationTransition))
    2322         return false;
     2343        return std::nullopt;
    23232344
    23242345    uint64_t options;
    23252346    if (!decoder.decode(options))
    2326         return false;
     2347        return std::nullopt;
    23272348    textIndicatorData.options = static_cast<TextIndicatorOptions>(options);
    23282349
    23292350    if (!decodeOptionalImage(decoder, textIndicatorData.contentImage))
    2330         return false;
     2351        return std::nullopt;
    23312352
    23322353    if (!decodeOptionalImage(decoder, textIndicatorData.contentImageWithHighlight))
    2333         return false;
     2354        return std::nullopt;
    23342355
    23352356    if (!decodeOptionalImage(decoder, textIndicatorData.contentImageWithoutSelection))
    2336         return false;
    2337 
    2338     return true;
     2357        return std::nullopt;
     2358
     2359    return WTFMove(textIndicatorData);
    23392360}
    23402361
     
    24092430        return false;
    24102431
    2411     if (!decoder.decode(result.textIndicator))
    2412         return false;
     2432    std::optional<TextIndicatorData> textIndicator;
     2433    decoder >> textIndicator;
     2434    if (!textIndicator)
     2435        return false;
     2436    result.textIndicator = WTFMove(*textIndicator);
    24132437
    24142438#if PLATFORM(COCOA)
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h

    r222392 r222584  
    232232    static void encode(Encoder&, const WebCore::FloatPoint&);
    233233    static bool decode(Decoder&, WebCore::FloatPoint&);
     234    static std::optional<WebCore::FloatPoint> decode(Decoder&);
    234235};
    235236
     
    275276    static void encode(Encoder&, const WebCore::IntPoint&);
    276277    static bool decode(Decoder&, WebCore::IntPoint&);
     278    static std::optional<WebCore::IntPoint> decode(Decoder&);
    277279};
    278280
     
    286288    static void encode(Encoder&, const WebCore::IntSize&);
    287289    static bool decode(Decoder&, WebCore::IntSize&);
     290    static std::optional<WebCore::IntSize> decode(Decoder&);
    288291};
    289292
     
    525528template<> struct ArgumentCoder<WebCore::TextIndicatorData> {
    526529    static void encode(Encoder&, const WebCore::TextIndicatorData&);
    527     static bool decode(Decoder&, WebCore::TextIndicatorData&);
     530    static std::optional<WebCore::TextIndicatorData> decode(Decoder&);
    528531};
    529532
     
    566569template<> struct ArgumentCoder<WebCore::PaymentAuthorizationResult> {
    567570    static void encode(Encoder&, const WebCore::PaymentAuthorizationResult&);
    568     static bool decode(Decoder&, WebCore::PaymentAuthorizationResult&);
     571    static std::optional<WebCore::PaymentAuthorizationResult> decode(Decoder&);
    569572};
    570573
     
    591594template<> struct ArgumentCoder<WebCore::PaymentMethodUpdate> {
    592595    static void encode(Encoder&, const WebCore::PaymentMethodUpdate&);
    593     static bool decode(Decoder&, WebCore::PaymentMethodUpdate&);
     596    static std::optional<WebCore::PaymentMethodUpdate> decode(Decoder&);
    594597};
    595598
     
    626629template<> struct ArgumentCoder<WebCore::ShippingContactUpdate> {
    627630    static void encode(Encoder&, const WebCore::ShippingContactUpdate&);
    628     static bool decode(Decoder&, WebCore::ShippingContactUpdate&);
     631    static std::optional<WebCore::ShippingContactUpdate> decode(Decoder&);
    629632};
    630633
    631634template<> struct ArgumentCoder<WebCore::ShippingMethodUpdate> {
    632635    static void encode(Encoder&, const WebCore::ShippingMethodUpdate&);
    633     static bool decode(Decoder&, WebCore::ShippingMethodUpdate&);
     636    static std::optional<WebCore::ShippingMethodUpdate> decode(Decoder&);
    634637};
    635638
  • trunk/Source/WebKit/Shared/WebHitTestResultData.cpp

    r213010 r222584  
    165165
    166166    if (hasLinkTextIndicator) {
    167         WebCore::TextIndicatorData indicatorData;
    168         if (!decoder.decode(indicatorData))
     167        std::optional<WebCore::TextIndicatorData> indicatorData;
     168        decoder >> indicatorData;
     169        if (!indicatorData)
    169170            return false;
    170171
    171         hitTestResultData.linkTextIndicator = WebCore::TextIndicator::create(indicatorData);
     172        hitTestResultData.linkTextIndicator = WebCore::TextIndicator::create(*indicatorData);
    172173    }
    173174
  • trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp

    r222233 r222584  
    192192    if (!decoder.decodeEnum(parameters.scrollPinningBehavior))
    193193        return std::nullopt;
    194     if (!decoder.decode(parameters.scrollbarOverlayStyle))
    195         return std::nullopt;
     194
     195    std::optional<std::optional<uint32_t>> scrollbarOverlayStyle;
     196    decoder >> scrollbarOverlayStyle;
     197    if (!scrollbarOverlayStyle)
     198        return std::nullopt;
     199    parameters.scrollbarOverlayStyle = WTFMove(*scrollbarOverlayStyle);
     200
    196201    if (!decoder.decode(parameters.backgroundExtendsBeyondPage))
    197202        return std::nullopt;
     
    247252        return std::nullopt;
    248253
    249     if (!decoder.decode(parameters.cpuLimit))
    250         return std::nullopt;
     254    std::optional<std::optional<double>> cpuLimit;
     255    decoder >> cpuLimit;
     256    if (!cpuLimit)
     257        return std::nullopt;
     258    parameters.cpuLimit = WTFMove(*cpuLimit);
    251259
    252260    if (!decoder.decode(parameters.urlSchemeHandlers))
  • trunk/Source/WebKit/Shared/ios/InteractionInformationAtPosition.mm

    r220506 r222584  
    145145        return false;
    146146   
    147     if (!decoder.decode(result.linkIndicator))
    148         return false;
     147    std::optional<WebCore::TextIndicatorData> linkIndicator;
     148    decoder >> linkIndicator;
     149    if (!linkIndicator)
     150        return false;
     151    result.linkIndicator = WTFMove(*linkIndicator);
    149152
    150153    ShareableBitmap::Handle handle;
  • trunk/Source/WebKit/Shared/mac/WebHitTestResultData.mm

    r220979 r222584  
    9898
    9999    if (hasDetectedDataTextIndicator) {
    100         WebCore::TextIndicatorData indicatorData;
    101         if (!decoder.decode(indicatorData))
     100        std::optional<WebCore::TextIndicatorData> indicatorData;
     101        decoder >> indicatorData;
     102        if (!indicatorData)
    102103            return false;
    103104
    104         hitTestResultData.detectedDataTextIndicator = WebCore::TextIndicator::create(indicatorData);
     105        hitTestResultData.detectedDataTextIndicator = WebCore::TextIndicator::create(*indicatorData);
    105106    }
    106107
Note: See TracChangeset for help on using the changeset viewer.