Changeset 221760 in webkit
- Timestamp:
- Sep 7, 2017 2:57:18 PM (7 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r221753 r221760 1 2017-09-07 Alex Christensen <achristensen@webkit.org> 2 3 Allow modern decoding of enums and OptionSets 4 https://bugs.webkit.org/show_bug.cgi?id=176480 5 6 Reviewed by Andy Estes. 7 8 * Platform/IPC/ArgumentCoders.h: 9 (IPC::ArgumentCoder<OptionSet<T>>::decode): 10 * Platform/IPC/Decoder.h: 11 (IPC::Decoder::operator>>): 12 * Platform/IPC/Encoder.h: 13 * Shared/WebsitePolicies.h: 14 (WebKit::WebsitePolicies::encode const): 15 (WebKit::WebsitePolicies::decode): 16 1 17 2017-09-07 Frederic Wang <fwang@igalia.com> 2 18 -
trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h
r221620 r221760 70 70 return true; 71 71 } 72 73 static std::optional<OptionSet<T>> decode(Decoder& decoder) 74 { 75 std::optional<uint64_t> value; 76 decoder >> value; 77 if (!value) 78 return std::nullopt; 79 return OptionSet<T>::fromRaw(*value); 80 } 72 81 }; 73 82 -
trunk/Source/WebKit/Platform/IPC/Decoder.h
r221698 r221760 110 110 } 111 111 112 template<typename E, std::enable_if_t<std::is_enum<E>::value>* = nullptr> 113 Decoder& operator>>(std::optional<E>& optional) 114 { 115 std::optional<uint64_t> value; 116 *this >> value; 117 if (value && isValidEnum<E>(*value)) 118 optional = static_cast<E>(*value); 119 return *this; 120 } 121 112 122 template<typename T> bool decodeEnum(T& result) 113 123 { -
trunk/Source/WebKit/Platform/IPC/Encoder.h
r204977 r221760 66 66 } 67 67 68 template<typename T >69 auto encode(T&& t) -> std::enable_if_t<!std::is_enum<typename std::remove_const_t<std::remove_reference_t<T>>>::value>68 template<typename T, std::enable_if_t<!std::is_enum<typename std::remove_const_t<std::remove_reference_t<T>>>::value>* = nullptr> 69 void encode(T&& t) 70 70 { 71 71 ArgumentCoder<typename std::remove_const<typename std::remove_reference<T>::type>::type>::encode(*this, std::forward<T>(t)); 72 72 } 73 73 74 template<typename T> Encoder& operator<<(T&& t) 74 template<typename T, std::enable_if_t<std::is_enum<T>::value>* = nullptr> 75 Encoder& operator<<(T&& t) 76 { 77 encode(static_cast<uint64_t>(t)); 78 return *this; 79 } 80 81 template<typename T, std::enable_if_t<!std::is_enum<T>::value>* = nullptr> 82 Encoder& operator<<(T&& t) 75 83 { 76 84 encode(std::forward<T>(t)); -
trunk/Source/WebKit/Shared/WebsitePolicies.h
r221333 r221760 26 26 #pragma once 27 27 28 #include <wtf/EnumTraits.h> 28 29 #include <wtf/OptionSet.h> 29 30 #include <wtf/Optional.h> … … 53 54 }; 54 55 56 } // namespace WebKit 57 58 namespace WTF { 59 60 template<> struct EnumTraits<WebKit::WebsiteAutoplayPolicy> { 61 using values = EnumValues< 62 WebKit::WebsiteAutoplayPolicy, 63 WebKit::WebsiteAutoplayPolicy::Default, 64 WebKit::WebsiteAutoplayPolicy::Allow, 65 WebKit::WebsiteAutoplayPolicy::AllowWithoutSound, 66 WebKit::WebsiteAutoplayPolicy::Deny 67 >; 68 }; 69 70 } // namespace WTF 71 72 namespace WebKit { 73 55 74 template<class Encoder> void WebsitePolicies::encode(Encoder& encoder) const 56 75 { 57 76 encoder << contentBlockersEnabled; 58 encoder .encodeEnum(autoplayPolicy);77 encoder << autoplayPolicy; 59 78 encoder << allowedAutoplayQuirks; 60 79 } … … 62 81 template<class Decoder> std::optional<WebsitePolicies> WebsitePolicies::decode(Decoder& decoder) 63 82 { 64 bool contentBlockersEnabled; 65 if (!decoder.decode(contentBlockersEnabled)) 83 std::optional<bool> contentBlockersEnabled; 84 decoder >> contentBlockersEnabled; 85 if (!contentBlockersEnabled) 66 86 return std::nullopt; 67 87 68 WebsiteAutoplayPolicy autoplayPolicy; 69 if (!decoder.decodeEnum(autoplayPolicy)) 88 std::optional<WebsiteAutoplayPolicy> autoplayPolicy; 89 decoder >> autoplayPolicy; 90 if (!autoplayPolicy) 70 91 return std::nullopt; 71 92 72 OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks; 73 if (!decoder.decode(allowedAutoplayQuirks)) 93 std::optional<OptionSet<WebsiteAutoplayQuirk>> allowedAutoplayQuirks; 94 decoder >> allowedAutoplayQuirks; 95 if (!allowedAutoplayQuirks) 74 96 return std::nullopt; 75 97 76 return { { contentBlockersEnabled, allowedAutoplayQuirks, autoplayPolicy } }; 98 return { { 99 WTFMove(*contentBlockersEnabled), 100 WTFMove(*allowedAutoplayQuirks), 101 WTFMove(*autoplayPolicy), 102 } }; 77 103 } 78 104
Note: See TracChangeset
for help on using the changeset viewer.