Changeset 221620 in webkit
- Timestamp:
- Sep 5, 2017 10:33:06 AM (7 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r221615 r221620 1 2017-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 1 18 2017-09-05 Frederic Wang <fwang@igalia.com> 2 19 -
trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h
r221333 r221620 28 28 #include <wtf/Optional.h> 29 29 30 namespace WebCore { 31 class IntConstraint; 32 class DoubleConstraint; 33 class ResourceResponse; 34 } 35 30 36 namespace IPC { 31 37 32 38 class Decoder; 33 39 class Encoder; 40 41 template<typename> struct ArgumentCoder; 34 42 35 43 template<typename U> … … 39 47 template<typename T> static uint8_t check(Helper<std::optional<U> (*)(Decoder&), &T::decode>*); 40 48 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(...); 41 51 public: 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); 43 54 }; 55 56 template<typename U> 57 class UsesLegacyDecoder { 58 private: 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(...); 64 public: 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 69 template<typename BoolType> 70 class DefaultDecoderValues { 71 public: 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. 77 template<> class UsesModernDecoder<WebCore::ResourceResponse> : public DefaultDecoderValues<std::false_type> { }; 78 template<> class UsesLegacyDecoder<WebCore::ResourceResponse> : public DefaultDecoderValues<std::true_type> { }; 79 80 // IntConstraint and DoubleConstraint have their legacy decoder templates in NumericConstraint. 81 template<> class UsesModernDecoder<WebCore::IntConstraint> : public DefaultDecoderValues<std::false_type> { }; 82 template<> class UsesLegacyDecoder<WebCore::IntConstraint> : public DefaultDecoderValues<std::true_type> { }; 83 template<> class UsesModernDecoder<WebCore::DoubleConstraint> : public DefaultDecoderValues<std::false_type> { }; 84 template<> class UsesLegacyDecoder<WebCore::DoubleConstraint> : public DefaultDecoderValues<std::true_type> { }; 44 85 45 86 template<typename T> struct ArgumentCoder { … … 49 90 } 50 91 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> 52 93 static bool decode(Decoder& decoder, U& u) 53 94 { … … 55 96 } 56 97 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> 58 99 static std::optional<U> decode(Decoder& decoder) 59 100 { -
trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp
r210835 r221620 154 154 155 155 bool is8Bit; 156 157 156 if (!decoder.decode(is8Bit)) 158 157 return false; … … 163 162 } 164 163 164 std::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 } 165 189 166 190 void ArgumentCoder<SHA1::Digest>::encode(Encoder& encoder, const SHA1::Digest& digest) -
trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h
r221319 r221620 447 447 static void encode(Encoder&, const String&); 448 448 static bool decode(Decoder&, String&); 449 static std::optional<String> decode(Decoder&); 449 450 }; 450 451 -
trunk/Source/WebKit/Platform/IPC/Decoder.h
r221319 r221620 124 124 } 125 125 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> 127 127 bool decode(T& t) 128 128 { -
trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp
r221319 r221620 145 145 if (!decoder.decode(parameters.paginationLineGridEnabled)) 146 146 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); 149 152 if (!decoder.decode(parameters.itemStates)) 150 153 return std::nullopt;
Note: See TracChangeset
for help on using the changeset viewer.