Changeset 221620 in webkit


Ignore:
Timestamp:
Sep 5, 2017 10:33:06 AM (7 years ago)
Author:
achristensen@apple.com
Message:

Allow classes to have modern and legacy decoders to aid transition
https://bugs.webkit.org/show_bug.cgi?id=176186

Reviewed by Zan Dobersek.

To illustrate this, I made legacy and modern decoders to WTF::String and transitioned one String decoder.

  • Platform/IPC/ArgumentCoder.h:
  • Platform/IPC/ArgumentCoders.cpp:

(IPC::ArgumentCoder<String>::decode):

  • Platform/IPC/ArgumentCoders.h:
  • Platform/IPC/Decoder.h:
  • Shared/WebPageCreationParameters.cpp:

(WebKit::WebPageCreationParameters::decode):

Location:
trunk/Source/WebKit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221615 r221620  
     12017-09-04  Alex Christensen  <achristensen@webkit.org>
     2
     3        Allow classes to have modern and legacy decoders to aid transition
     4        https://bugs.webkit.org/show_bug.cgi?id=176186
     5
     6        Reviewed by Zan Dobersek.
     7
     8        To illustrate this, I made legacy and modern decoders to WTF::String and transitioned one String decoder.
     9
     10        * Platform/IPC/ArgumentCoder.h:
     11        * Platform/IPC/ArgumentCoders.cpp:
     12        (IPC::ArgumentCoder<String>::decode):
     13        * Platform/IPC/ArgumentCoders.h:
     14        * Platform/IPC/Decoder.h:
     15        * Shared/WebPageCreationParameters.cpp:
     16        (WebKit::WebPageCreationParameters::decode):
     17
    1182017-09-05  Frederic Wang  <fwang@igalia.com>
    219
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h

    r221333 r221620  
    2828#include <wtf/Optional.h>
    2929
     30namespace WebCore {
     31class IntConstraint;
     32class DoubleConstraint;
     33class ResourceResponse;
     34}
     35
    3036namespace IPC {
    3137
    3238class Decoder;
    3339class Encoder;
     40
     41template<typename> struct ArgumentCoder;
    3442
    3543template<typename U>
     
    3947    template<typename T> static uint8_t check(Helper<std::optional<U> (*)(Decoder&), &T::decode>*);
    4048    template<typename T> static uint16_t check(...);
     49    template<typename T> static uint8_t checkArgumentCoder(Helper<std::optional<U> (*)(Decoder&), &ArgumentCoder<T>::decode>*);
     50    template<typename T> static uint16_t checkArgumentCoder(...);
    4151public:
    42     static constexpr bool value = sizeof(check<U>(0)) == sizeof(uint8_t);
     52    static constexpr bool argumentCoderValue = sizeof(check<U>(nullptr)) == sizeof(uint8_t);
     53    static constexpr bool value = argumentCoderValue || sizeof(checkArgumentCoder<U>(nullptr)) == sizeof(uint8_t);
    4354};
     55
     56template<typename U>
     57class UsesLegacyDecoder {
     58private:
     59    template<typename T, T> struct Helper;
     60    template<typename T> static uint8_t check(Helper<bool (*)(Decoder&, U&), &T::decode>*);
     61    template<typename T> static uint16_t check(...);
     62    template<typename T> static uint8_t checkArgumentCoder(Helper<bool (*)(Decoder&, U&), &ArgumentCoder<T>::decode>*);
     63    template<typename T> static uint16_t checkArgumentCoder(...);
     64public:
     65    static constexpr bool argumentCoderValue = sizeof(check<U>(nullptr)) == sizeof(uint8_t);
     66    static constexpr bool value = argumentCoderValue || sizeof(checkArgumentCoder<U>(nullptr)) == sizeof(uint8_t);
     67};
     68
     69template<typename BoolType>
     70class DefaultDecoderValues {
     71public:
     72    static constexpr bool argumentCoderValue = BoolType::value;
     73    static constexpr bool value = BoolType::value;
     74};
     75
     76// ResourceResponseBase has the legacy decode template, not ResourceResponse.
     77template<> class UsesModernDecoder<WebCore::ResourceResponse> : public DefaultDecoderValues<std::false_type> { };
     78template<> class UsesLegacyDecoder<WebCore::ResourceResponse> : public DefaultDecoderValues<std::true_type> { };
     79
     80// IntConstraint and DoubleConstraint have their legacy decoder templates in NumericConstraint.
     81template<> class UsesModernDecoder<WebCore::IntConstraint> : public DefaultDecoderValues<std::false_type> { };
     82template<> class UsesLegacyDecoder<WebCore::IntConstraint> : public DefaultDecoderValues<std::true_type> { };
     83template<> class UsesModernDecoder<WebCore::DoubleConstraint> : public DefaultDecoderValues<std::false_type> { };
     84template<> class UsesLegacyDecoder<WebCore::DoubleConstraint> : public DefaultDecoderValues<std::true_type> { };
    4485
    4586template<typename T> struct ArgumentCoder {
     
    4990    }
    5091
    51     template<typename U = T, std::enable_if_t<!UsesModernDecoder<U>::value>* = nullptr>
     92    template<typename U = T, std::enable_if_t<UsesLegacyDecoder<U>::argumentCoderValue>* = nullptr>
    5293    static bool decode(Decoder& decoder, U& u)
    5394    {
     
    5596    }
    5697
    57     template<typename U = T, std::enable_if_t<UsesModernDecoder<U>::value>* = nullptr>
     98    template<typename U = T, std::enable_if_t<UsesModernDecoder<U>::argumentCoderValue>* = nullptr>
    5899    static std::optional<U> decode(Decoder& decoder)
    59100    {
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp

    r210835 r221620  
    154154
    155155    bool is8Bit;
    156 
    157156    if (!decoder.decode(is8Bit))
    158157        return false;
     
    163162}
    164163
     164std::optional<String> ArgumentCoder<String>::decode(Decoder& decoder)
     165{
     166    uint32_t length;
     167    if (!decoder.decode(length))
     168        return std::nullopt;
     169   
     170    if (length == std::numeric_limits<uint32_t>::max()) {
     171        // This is the null string.
     172        return String();
     173    }
     174   
     175    bool is8Bit;
     176    if (!decoder.decode(is8Bit))
     177        return std::nullopt;
     178   
     179    String result;
     180    if (is8Bit) {
     181        if (!decodeStringText<LChar>(decoder, length, result))
     182            return std::nullopt;
     183        return result;
     184    }
     185    if (!decodeStringText<UChar>(decoder, length, result))
     186        return std::nullopt;
     187    return result;
     188}
    165189
    166190void ArgumentCoder<SHA1::Digest>::encode(Encoder& encoder, const SHA1::Digest& digest)
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h

    r221319 r221620  
    447447    static void encode(Encoder&, const String&);
    448448    static bool decode(Decoder&, String&);
     449    static std::optional<String> decode(Decoder&);
    449450};
    450451
  • trunk/Source/WebKit/Platform/IPC/Decoder.h

    r221319 r221620  
    124124    }
    125125
    126     template<typename T, std::enable_if_t<!std::is_enum<T>::value && !UsesModernDecoder<T>::value>* = nullptr>
     126    template<typename T, std::enable_if_t<!std::is_enum<T>::value && UsesLegacyDecoder<T>::value>* = nullptr>
    127127    bool decode(T& t)
    128128    {
  • trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp

    r221319 r221620  
    145145    if (!decoder.decode(parameters.paginationLineGridEnabled))
    146146        return std::nullopt;
    147     if (!decoder.decode(parameters.userAgent))
    148         return std::nullopt;
     147    std::optional<String> userAgent;
     148    decoder >> userAgent;
     149    if (!userAgent)
     150        return std::nullopt;
     151    parameters.userAgent = WTFMove(*userAgent);
    149152    if (!decoder.decode(parameters.itemStates))
    150153        return std::nullopt;
Note: See TracChangeset for help on using the changeset viewer.