Changeset 221086 in webkit
- Timestamp:
- Aug 23, 2017 10:54:03 AM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r221076 r221086 1 2017-08-23 Youenn Fablet <youenn@apple.com> 2 3 [Cache API] Enable persistent coder to encode FetchOptions 4 https://bugs.webkit.org/show_bug.cgi?id=175883 5 6 Reviewed by Alex Christensen. 7 8 Enabling encoding/decoding of enums with EnumTraits. 9 This code is similar to the one of IPC encoder/decoder. 10 11 * wtf/persistence/PersistentDecoder.h: 12 (WTF::Persistence::Decoder::decode): 13 * wtf/persistence/PersistentEncoder.h: 14 (WTF::Persistence::Encoder::encode): 15 1 16 2017-08-23 Per Arne Vollan <pvollan@apple.com> 2 17 -
trunk/Source/WTF/wtf/persistence/PersistentDecoder.h
r220574 r221086 26 26 #pragma once 27 27 28 #include <wtf/EnumTraits.h> 28 29 #include <wtf/SHA1.h> 29 30 #include <wtf/persistence/PersistentCoder.h> … … 55 56 WTF_EXPORT_PRIVATE bool decode(double&); 56 57 58 template<typename E> auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool> 59 { 60 uint64_t value; 61 if (!decode(value)) 62 return false; 63 if (!isValidEnum<E>(value)) 64 return false; 65 66 e = static_cast<E>(value); 67 return true; 68 } 69 57 70 template<typename T> bool decodeEnum(T& result) 58 71 { … … 67 80 } 68 81 69 template<typename T> bool decode(T& t)82 template<typename T> auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool> 70 83 { 71 84 return Coder<T>::decode(*this, t); -
trunk/Source/WTF/wtf/persistence/PersistentEncoder.h
r220574 r221086 26 26 #pragma once 27 27 28 #include <wtf/EnumTraits.h> 28 29 #include <wtf/SHA1.h> 29 30 #include <wtf/Vector.h> … … 45 46 WTF_EXPORT_PRIVATE void encodeFixedLengthData(const uint8_t*, size_t); 46 47 48 template<typename E> auto encode(E value) -> std::enable_if_t<std::is_enum<E>::value> 49 { 50 static_assert(sizeof(E) <= sizeof(uint64_t), "Enum type must not be larger than 64 bits."); 51 52 ASSERT(isValidEnum<E>(static_cast<uint64_t>(value))); 53 encode(static_cast<uint64_t>(value)); 54 } 55 47 56 template<typename T> void encodeEnum(T t) 48 57 { … … 52 61 } 53 62 54 template<typename T> void encode(const T& t)63 template<typename T> auto encode(const T& t) -> std::enable_if_t<!std::is_enum<T>::value> 55 64 { 56 65 Coder<T>::encode(*this, t); -
trunk/Source/WebCore/ChangeLog
r221083 r221086 1 2017-08-23 Youenn Fablet <youenn@apple.com> 2 3 [Cache API] Enable persistent coder to encode FetchOptions 4 https://bugs.webkit.org/show_bug.cgi?id=175883 5 6 Reviewed by Alex Christensen. 7 8 No change of behavior. 9 Adding encode/decode routines for FetchOptions. 10 11 * loader/FetchOptions.h: 12 (WebCore::FetchOptions::encode const): 13 (WebCore::FetchOptions::decode): 14 * platform/ReferrerPolicy.h: 15 1 16 2017-08-23 Yusuke Suzuki <utatane.tea@gmail.com> 2 17 -
trunk/Source/WebCore/loader/FetchOptions.h
r220810 r221086 46 46 FetchOptions isolatedCopy() const { return { type, destination, mode, credentials, cache, redirect, referrerPolicy, integrity.isolatedCopy(), keepAlive }; } 47 47 48 template<class Encoder> void encode(Encoder&) const; 49 template<class Decoder> static bool decode(Decoder&, FetchOptions&); 50 48 51 Type type { Type::EmptyString }; 49 52 Destination destination { Destination::EmptyString }; … … 70 73 } 71 74 75 } 76 77 namespace WTF { 78 79 template<> struct EnumTraits<WebCore::FetchOptions::Type> { 80 using values = EnumValues< 81 WebCore::FetchOptions::Type, 82 WebCore::FetchOptions::Type::EmptyString, 83 WebCore::FetchOptions::Type::Audio, 84 WebCore::FetchOptions::Type::Font, 85 WebCore::FetchOptions::Type::Image, 86 WebCore::FetchOptions::Type::Script, 87 WebCore::FetchOptions::Type::Style, 88 WebCore::FetchOptions::Type::Track, 89 WebCore::FetchOptions::Type::Video 90 >; 91 }; 92 93 template<> struct EnumTraits<WebCore::FetchOptions::Destination> { 94 using values = EnumValues< 95 WebCore::FetchOptions::Destination, 96 WebCore::FetchOptions::Destination::EmptyString, 97 WebCore::FetchOptions::Destination::Document, 98 WebCore::FetchOptions::Destination::Sharedworker, 99 WebCore::FetchOptions::Destination::Subresource, 100 WebCore::FetchOptions::Destination::Unknown, 101 WebCore::FetchOptions::Destination::Worker 102 >; 103 }; 104 105 template<> struct EnumTraits<WebCore::FetchOptions::Mode> { 106 using values = EnumValues< 107 WebCore::FetchOptions::Mode, 108 WebCore::FetchOptions::Mode::Navigate, 109 WebCore::FetchOptions::Mode::SameOrigin, 110 WebCore::FetchOptions::Mode::NoCors, 111 WebCore::FetchOptions::Mode::Cors 112 >; 113 }; 114 115 template<> struct EnumTraits<WebCore::FetchOptions::Credentials> { 116 using values = EnumValues< 117 WebCore::FetchOptions::Credentials, 118 WebCore::FetchOptions::Credentials::Omit, 119 WebCore::FetchOptions::Credentials::SameOrigin, 120 WebCore::FetchOptions::Credentials::Include 121 >; 122 }; 123 124 template<> struct EnumTraits<WebCore::FetchOptions::Cache> { 125 using values = EnumValues< 126 WebCore::FetchOptions::Cache, 127 WebCore::FetchOptions::Cache::Default, 128 WebCore::FetchOptions::Cache::NoStore, 129 WebCore::FetchOptions::Cache::Reload, 130 WebCore::FetchOptions::Cache::NoCache, 131 WebCore::FetchOptions::Cache::ForceCache, 132 WebCore::FetchOptions::Cache::OnlyIfCached 133 >; 134 }; 135 136 template<> struct EnumTraits<WebCore::FetchOptions::Redirect> { 137 using values = EnumValues< 138 WebCore::FetchOptions::Redirect, 139 WebCore::FetchOptions::Redirect::Follow, 140 WebCore::FetchOptions::Redirect::Error, 141 WebCore::FetchOptions::Redirect::Manual 142 >; 143 }; 144 145 } 146 147 namespace WebCore { 148 149 template<class Encoder> inline void FetchOptions::encode(Encoder& encoder) const 150 { 151 encoder << type; 152 encoder << destination; 153 encoder << mode; 154 encoder << credentials; 155 encoder << cache; 156 encoder << redirect; 157 encoder << referrerPolicy; 158 encoder << integrity; 159 encoder << keepAlive; 160 } 161 162 template<class Decoder> inline bool FetchOptions::decode(Decoder& decoder, FetchOptions& options) 163 { 164 FetchOptions::Type type; 165 if (!decoder.decode(type)) 166 return false; 167 168 FetchOptions::Destination destination; 169 if (!decoder.decode(destination)) 170 return false; 171 172 FetchOptions::Mode mode; 173 if (!decoder.decode(mode)) 174 return false; 175 176 FetchOptions::Credentials credentials; 177 if (!decoder.decode(credentials)) 178 return false; 179 180 FetchOptions::Cache cache; 181 if (!decoder.decode(cache)) 182 return false; 183 184 FetchOptions::Redirect redirect; 185 if (!decoder.decode(redirect)) 186 return false; 187 188 ReferrerPolicy referrerPolicy; 189 if (!decoder.decode(referrerPolicy)) 190 return false; 191 192 String integrity; 193 if (!decoder.decode(integrity)) 194 return false; 195 196 bool keepAlive; 197 if (!decoder.decode(keepAlive)) 198 return false; 199 200 options.type = type; 201 options.destination = destination; 202 options.mode = mode; 203 options.credentials = credentials; 204 options.cache = cache; 205 options.redirect = redirect; 206 options.referrerPolicy = referrerPolicy; 207 options.integrity = WTFMove(integrity); 208 options.keepAlive = keepAlive; 209 210 return true; 211 } 212 72 213 } // namespace WebCore -
trunk/Source/WebCore/platform/ReferrerPolicy.h
r220208 r221086 33 33 #pragma once 34 34 35 #include <wtf/EnumTraits.h> 36 35 37 namespace WebCore { 36 38 … … 48 50 49 51 } 52 53 namespace WTF { 54 55 template<> struct EnumTraits<WebCore::ReferrerPolicy> { 56 using values = EnumValues< 57 WebCore::ReferrerPolicy, 58 WebCore::ReferrerPolicy::EmptyString, 59 WebCore::ReferrerPolicy::NoReferrer, 60 WebCore::ReferrerPolicy::NoReferrerWhenDowngrade, 61 WebCore::ReferrerPolicy::SameOrigin, 62 WebCore::ReferrerPolicy::Origin, 63 WebCore::ReferrerPolicy::StrictOrigin, 64 WebCore::ReferrerPolicy::OriginWhenCrossOrigin, 65 WebCore::ReferrerPolicy::StrictOriginWhenCrossOrigin, 66 WebCore::ReferrerPolicy::UnsafeUrl 67 >; 68 }; 69 70 } -
trunk/Source/WebKit/ChangeLog
r221085 r221086 1 2017-08-23 Youenn Fablet <youenn@apple.com> 2 3 [Cache API] Enable persistent coder to encode FetchOptions 4 https://bugs.webkit.org/show_bug.cgi?id=175883 5 6 Reviewed by Alex Christensen. 7 8 Removing FetchOptions related ArgumentCoders specific code. 9 10 * Shared/WebCoreArgumentCoders.cpp: 11 * Shared/WebCoreArgumentCoders.h: 12 1 13 2017-08-23 Youenn Fablet <youenn@apple.com> 2 14 -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp
r221068 r221086 215 215 } 216 216 217 void ArgumentCoder<FetchOptions>::encode(Encoder& encoder, const FetchOptions& options)218 {219 encoder << options.type;220 encoder << options.destination;221 encoder << options.mode;222 encoder << options.credentials;223 encoder << options.cache;224 encoder << options.redirect;225 encoder << options.referrerPolicy;226 encoder << options.integrity;227 encoder << options.keepAlive;228 }229 230 bool ArgumentCoder<FetchOptions>::decode(Decoder& decoder, FetchOptions& options)231 {232 FetchOptions::Type type;233 if (!decoder.decode(type))234 return false;235 236 FetchOptions::Destination destination;237 if (!decoder.decode(destination))238 return false;239 240 FetchOptions::Mode mode;241 if (!decoder.decode(mode))242 return false;243 244 FetchOptions::Credentials credentials;245 if (!decoder.decode(credentials))246 return false;247 248 FetchOptions::Cache cache;249 if (!decoder.decode(cache))250 return false;251 252 FetchOptions::Redirect redirect;253 if (!decoder.decode(redirect))254 return false;255 256 ReferrerPolicy referrerPolicy;257 if (!decoder.decode(referrerPolicy))258 return false;259 260 String integrity;261 if (!decoder.decode(integrity))262 return false;263 264 bool keepAlive;265 if (!decoder.decode(keepAlive))266 return false;267 268 options.type = type;269 options.destination = destination;270 options.mode = mode;271 options.credentials = credentials;272 options.cache = cache;273 options.redirect = redirect;274 options.referrerPolicy = referrerPolicy;275 options.integrity = WTFMove(integrity);276 options.keepAlive = keepAlive;277 278 return true;279 }280 281 217 void ArgumentCoder<CacheStorageConnection::CacheInfo>::encode(Encoder& encoder, const CacheStorageConnection::CacheInfo& info) 282 218 { -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h
r220917 r221086 98 98 struct EventTrackingRegions; 99 99 struct ExceptionDetails; 100 struct FetchOptions;101 100 struct FileChooserSettings; 102 101 struct Length; … … 197 196 }; 198 197 199 template<> struct ArgumentCoder<WebCore::FetchOptions> {200 static void encode(Encoder&, const WebCore::FetchOptions&);201 static bool decode(Decoder&, WebCore::FetchOptions&);202 };203 204 198 template<> struct ArgumentCoder<WebCore::CacheQueryOptions> { 205 199 static void encode(Encoder&, const WebCore::CacheQueryOptions&); … … 801 795 }; 802 796 803 template<> struct EnumTraits<WebCore::FetchOptions::Type> {804 using values = EnumValues<805 WebCore::FetchOptions::Type,806 WebCore::FetchOptions::Type::EmptyString,807 WebCore::FetchOptions::Type::Audio,808 WebCore::FetchOptions::Type::Font,809 WebCore::FetchOptions::Type::Image,810 WebCore::FetchOptions::Type::Script,811 WebCore::FetchOptions::Type::Style,812 WebCore::FetchOptions::Type::Track,813 WebCore::FetchOptions::Type::Video814 >;815 };816 817 template<> struct EnumTraits<WebCore::FetchOptions::Destination> {818 using values = EnumValues<819 WebCore::FetchOptions::Destination,820 WebCore::FetchOptions::Destination::EmptyString,821 WebCore::FetchOptions::Destination::Document,822 WebCore::FetchOptions::Destination::Sharedworker,823 WebCore::FetchOptions::Destination::Subresource,824 WebCore::FetchOptions::Destination::Unknown,825 WebCore::FetchOptions::Destination::Worker826 >;827 };828 829 template<> struct EnumTraits<WebCore::FetchOptions::Mode> {830 using values = EnumValues<831 WebCore::FetchOptions::Mode,832 WebCore::FetchOptions::Mode::Navigate,833 WebCore::FetchOptions::Mode::SameOrigin,834 WebCore::FetchOptions::Mode::NoCors,835 WebCore::FetchOptions::Mode::Cors836 >;837 };838 839 template<> struct EnumTraits<WebCore::FetchOptions::Credentials> {840 using values = EnumValues<841 WebCore::FetchOptions::Credentials,842 WebCore::FetchOptions::Credentials::Omit,843 WebCore::FetchOptions::Credentials::SameOrigin,844 WebCore::FetchOptions::Credentials::Include845 >;846 };847 848 template<> struct EnumTraits<WebCore::FetchOptions::Cache> {849 using values = EnumValues<850 WebCore::FetchOptions::Cache,851 WebCore::FetchOptions::Cache::Default,852 WebCore::FetchOptions::Cache::NoStore,853 WebCore::FetchOptions::Cache::Reload,854 WebCore::FetchOptions::Cache::NoCache,855 WebCore::FetchOptions::Cache::ForceCache,856 WebCore::FetchOptions::Cache::OnlyIfCached857 >;858 };859 860 template<> struct EnumTraits<WebCore::FetchOptions::Redirect> {861 using values = EnumValues<862 WebCore::FetchOptions::Redirect,863 WebCore::FetchOptions::Redirect::Follow,864 WebCore::FetchOptions::Redirect::Error,865 WebCore::FetchOptions::Redirect::Manual866 >;867 };868 869 template<> struct EnumTraits<WebCore::ReferrerPolicy> {870 using values = EnumValues<871 WebCore::ReferrerPolicy,872 WebCore::ReferrerPolicy::EmptyString,873 WebCore::ReferrerPolicy::NoReferrer,874 WebCore::ReferrerPolicy::NoReferrerWhenDowngrade,875 WebCore::ReferrerPolicy::SameOrigin,876 WebCore::ReferrerPolicy::Origin,877 WebCore::ReferrerPolicy::StrictOrigin,878 WebCore::ReferrerPolicy::OriginWhenCrossOrigin,879 WebCore::ReferrerPolicy::StrictOriginWhenCrossOrigin,880 WebCore::ReferrerPolicy::UnsafeUrl881 >;882 };883 884 797 } // namespace WTF
Note: See TracChangeset
for help on using the changeset viewer.