PersistentCoders should use modern decoding syntax
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Apr 2020 06:39:36 +0000 (06:39 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Apr 2020 06:39:36 +0000 (06:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207497

Patch by Alex Christensen <achristensen@webkit.org> on 2020-04-10
Reviewed by Darin Adler.

Source/WebCore:

* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::showCertificate):
* loader/FetchOptions.h:
(WebCore::FetchOptions::decodePersistent):
* page/csp/ContentSecurityPolicyResponseHeaders.h:
(WebCore::ContentSecurityPolicyResponseHeaders::encode const):
(WebCore::ContentSecurityPolicyResponseHeaders::decode):
* platform/PasteboardCustomData.cpp:
(WebCore::PasteboardCustomData::fromSharedBuffer):
* platform/network/ResourceLoadPriority.h:
* platform/network/ResourceRequestBase.h:
(WebCore::ResourceRequestBase::encodeBase const):
(WebCore::ResourceRequestBase::decodeBase):
* platform/network/cf/CertificateInfo.h:
(WTF::Persistence::decodeCFData):
(WTF::Persistence::decodeSecTrustRef):
(WTF::Persistence::decodeCertificateChain):
(WTF::Persistence::Coder<WebCore::CertificateInfo>::encode):
(WTF::Persistence::Coder<WebCore::CertificateInfo>::decode):
* workers/service/server/RegistrationDatabase.cpp:
(WebCore::RegistrationDatabase::doPushChanges):
(WebCore::RegistrationDatabase::importRecords):

Source/WebKit:

* NetworkProcess/cache/CacheStorageEngineCache.cpp:
(WebKit::CacheStorage::decodeDOMCacheRecord):
(WebKit::CacheStorage::Cache::decodeRecordHeader):
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::readOrigin):
(WebKit::CacheStorage::decodeCachesNames):
* NetworkProcess/cache/NetworkCacheCoders.cpp:
(WTF::Persistence::Coder<WebCore::HTTPHeaderMap>::decode):
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::decodeStorageRecord):
* NetworkProcess/cache/NetworkCacheKey.cpp:
(WebKit::NetworkCache::Key::decode):
* NetworkProcess/cache/NetworkCacheKey.h:
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::decodeRecordMetaData):
* NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
(WebKit::NetworkCache::SubresourceInfo::encode const):
(WebKit::NetworkCache::SubresourceInfo::decode):
(WebKit::NetworkCache::SubresourcesEntry::decodeStorageRecord):
* NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
* Shared/UserData.cpp:
(WebKit::UserData::decode):
* UIProcess/API/APIContentRuleListStore.cpp:
(API::decodeContentRuleListMetaData):

Source/WTF:

This paves the way for more serialized types that do not have a default constructor.

* wtf/persistence/PersistentCoder.h:
(WTF::Persistence::Coder::encode):
(WTF::Persistence::Coder::decode):
* wtf/persistence/PersistentCoders.cpp:
(WTF::Persistence::Coder<AtomString>::decode):
(WTF::Persistence::Coder<CString>::decode):
(WTF::Persistence::decodeStringText):
(WTF::Persistence::Coder<String>::decode):
(WTF::Persistence::Coder<SHA1::Digest>::decode):
* wtf/persistence/PersistentCoders.h:
(WTF::Persistence::Coder<Optional<T>>::decode):
(WTF::Persistence::Coder<Seconds>::decode):
(WTF::Persistence::Coder<WallTime>::decode):
* wtf/persistence/PersistentDecoder.cpp:
(WTF::Persistence::Decoder::decodeNumber):
(WTF::Persistence::Decoder::operator>>):
(WTF::Persistence::Decoder::decode): Deleted.
* wtf/persistence/PersistentDecoder.h:
(WTF::Persistence::Decoder::operator>>):
(WTF::Persistence::Decoder::decode): Deleted.
(WTF::Persistence::Decoder::decodeEnum): Deleted.
* wtf/persistence/PersistentEncoder.h:
(WTF::Persistence::Encoder::operator<<):
(WTF::Persistence::Encoder::encode): Deleted.
(WTF::Persistence::Encoder::encodeEnum): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259922 268f45cc-cd09-0410-ab3c-d52691b4dbfc

41 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/URL.h
Source/WTF/wtf/persistence/PersistentCoder.h
Source/WTF/wtf/persistence/PersistentCoders.cpp
Source/WTF/wtf/persistence/PersistentCoders.h
Source/WTF/wtf/persistence/PersistentDecoder.cpp
Source/WTF/wtf/persistence/PersistentDecoder.h
Source/WTF/wtf/persistence/PersistentEncoder.cpp
Source/WTF/wtf/persistence/PersistentEncoder.h
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorFrontendHost.cpp
Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Source/WebCore/loader/FetchOptions.h
Source/WebCore/page/SecurityOriginData.h
Source/WebCore/page/csp/ContentSecurityPolicyResponseHeaders.h
Source/WebCore/platform/PasteboardCustomData.cpp
Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp
Source/WebCore/platform/network/NetworkLoadMetrics.h
Source/WebCore/platform/network/ResourceLoadPriority.h
Source/WebCore/platform/network/ResourceRequestBase.h
Source/WebCore/platform/network/ResourceResponseBase.h
Source/WebCore/platform/network/cf/CertificateInfo.h
Source/WebCore/platform/network/cf/CertificateInfoCFNet.cpp
Source/WebCore/platform/network/curl/CertificateInfo.h
Source/WebCore/platform/network/soup/CertificateInfo.h
Source/WebCore/platform/network/soup/ResourceResponse.h
Source/WebCore/workers/service/ServiceWorkerContextData.h
Source/WebCore/workers/service/server/RegistrationDatabase.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheCoders.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheCoders.h
Source/WebKit/NetworkProcess/cache/NetworkCacheEntry.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheKey.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheKey.h
Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h
Source/WebKit/Shared/UserData.cpp
Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp

index 8c9641f..2a39c71 100644 (file)
@@ -1,3 +1,38 @@
+2020-04-10  Alex Christensen  <achristensen@webkit.org>
+
+        PersistentCoders should use modern decoding syntax
+        https://bugs.webkit.org/show_bug.cgi?id=207497
+
+        Reviewed by Darin Adler.
+
+        This paves the way for more serialized types that do not have a default constructor.
+
+        * wtf/persistence/PersistentCoder.h:
+        (WTF::Persistence::Coder::encode):
+        (WTF::Persistence::Coder::decode):
+        * wtf/persistence/PersistentCoders.cpp:
+        (WTF::Persistence::Coder<AtomString>::decode):
+        (WTF::Persistence::Coder<CString>::decode):
+        (WTF::Persistence::decodeStringText):
+        (WTF::Persistence::Coder<String>::decode):
+        (WTF::Persistence::Coder<SHA1::Digest>::decode):
+        * wtf/persistence/PersistentCoders.h:
+        (WTF::Persistence::Coder<Optional<T>>::decode):
+        (WTF::Persistence::Coder<Seconds>::decode):
+        (WTF::Persistence::Coder<WallTime>::decode):
+        * wtf/persistence/PersistentDecoder.cpp:
+        (WTF::Persistence::Decoder::decodeNumber):
+        (WTF::Persistence::Decoder::operator>>):
+        (WTF::Persistence::Decoder::decode): Deleted.
+        * wtf/persistence/PersistentDecoder.h:
+        (WTF::Persistence::Decoder::operator>>):
+        (WTF::Persistence::Decoder::decode): Deleted.
+        (WTF::Persistence::Decoder::decodeEnum): Deleted.
+        * wtf/persistence/PersistentEncoder.h:
+        (WTF::Persistence::Encoder::operator<<):
+        (WTF::Persistence::Encoder::encode): Deleted.
+        (WTF::Persistence::Encoder::encodeEnum): Deleted.
+
 2020-04-10  David Kilzer  <ddkilzer@apple.com>
 
         Follow-up: Add WARN_UNUSED_RETURN to decode methods in Source/WTF
index dde22cf..95af4a3 100644 (file)
@@ -248,10 +248,11 @@ bool URL::decode(Decoder& decoder, URL& url)
 template <class Decoder>
 Optional<URL> URL::decode(Decoder& decoder)
 {
-    String string;
-    if (!decoder.decode(string))
+    Optional<String> string;
+    decoder >> string;
+    if (!string)
         return WTF::nullopt;
-    return URL(URL(), string);
+    return URL(URL(), WTFMove(*string));
 }
 
 WTF_EXPORT_PRIVATE bool equalIgnoringFragmentIdentifier(const URL&, const URL&);
index 875de66..4f04f55 100644 (file)
@@ -30,16 +30,16 @@ namespace Persistence {
 
 class Decoder;
 class Encoder;
-    
+
 template<typename T> struct Coder {
     static void encode(Encoder& encoder, const T& t)
     {
         t.encode(encoder);
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, T& t)
+    static Optional<T> decode(Decoder& decoder)
     {
-        return T::decode(decoder, t);
+        return T::decode(decoder);
     }
 };
 
index 078511f..70c821a 100644 (file)
@@ -37,14 +37,14 @@ void Coder<AtomString>::encode(Encoder& encoder, const AtomString& atomString)
     encoder << atomString.string();
 }
 
-bool Coder<AtomString>::decode(Decoder& decoder, AtomString& atomString)
+Optional<AtomString> Coder<AtomString>::decode(Decoder& decoder)
 {
-    String string;
-    if (!decoder.decode(string))
-        return false;
+    Optional<String> string;
+    decoder >> string;
+    if (!string)
+        return WTF::nullopt;
 
-    atomString = string;
-    return true;
+    return {{ WTFMove(*string) }};
 }
 
 void Coder<CString>::encode(Encoder& encoder, const CString& string)
@@ -60,32 +60,30 @@ void Coder<CString>::encode(Encoder& encoder, const CString& string)
     encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length);
 }
 
-bool Coder<CString>::decode(Decoder& decoder, CString& result)
+Optional<CString> Coder<CString>::decode(Decoder& decoder)
 {
-    uint32_t length;
-    if (!decoder.decode(length))
-        return false;
+    Optional<uint32_t> length;
+    decoder >> length;
+    if (!length)
+        return WTF::nullopt;
 
     if (length == std::numeric_limits<uint32_t>::max()) {
         // This is the null string.
-        result = CString();
-        return true;
+        return CString();
     }
 
     // Before allocating the string, make sure that the decoder buffer is big enough.
-    if (!decoder.bufferIsLargeEnoughToContain<char>(length))
-        return false;
+    if (!decoder.bufferIsLargeEnoughToContain<char>(*length))
+        return WTF::nullopt;
 
     char* buffer;
-    CString string = CString::newUninitialized(length, buffer);
-    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length))
-        return false;
+    CString string = CString::newUninitialized(*length, buffer);
+    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), *length))
+        return WTF::nullopt;
 
-    result = string;
-    return true;
+    return WTFMove(string);
 }
 
-
 void Coder<String>::encode(Encoder& encoder, const String& string)
 {
     // Special case the null string.
@@ -106,40 +104,40 @@ void Coder<String>::encode(Encoder& encoder, const String& string)
 }
 
 template <typename CharacterType>
-static inline WARN_UNUSED_RETURN bool decodeStringText(Decoder& decoder, uint32_t length, String& result)
+static inline Optional<String> decodeStringText(Decoder& decoder, uint32_t length)
 {
     // Before allocating the string, make sure that the decoder buffer is big enough.
     if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length))
-        return false;
+        return WTF::nullopt;
 
     CharacterType* buffer;
     String string = String::createUninitialized(length, buffer);
     if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType)))
-        return false;
+        return WTF::nullopt;
     
-    result = string;
-    return true;    
+    return WTFMove(string);
 }
 
-bool Coder<String>::decode(Decoder& decoder, String& result)
+Optional<String> Coder<String>::decode(Decoder& decoder)
 {
-    uint32_t length;
-    if (!decoder.decode(length))
-        return false;
+    Optional<uint32_t> length;
+    decoder >> length;
+    if (!length)
+        return WTF::nullopt;
 
-    if (length == std::numeric_limits<uint32_t>::max()) {
+    if (*length == std::numeric_limits<uint32_t>::max()) {
         // This is the null string.
-        result = String();
-        return true;
+        return String();
     }
 
-    bool is8Bit;
-    if (!decoder.decode(is8Bit))
-        return false;
+    Optional<bool> is8Bit;
+    decoder >> is8Bit;
+    if (!is8Bit)
+        return WTF::nullopt;
 
-    if (is8Bit)
-        return decodeStringText<LChar>(decoder, length, result);
-    return decodeStringText<UChar>(decoder, length, result);
+    if (*is8Bit)
+        return decodeStringText<LChar>(decoder, *length);
+    return decodeStringText<UChar>(decoder, *length);
 }
 
 void Coder<SHA1::Digest>::encode(Encoder& encoder, const SHA1::Digest& digest)
@@ -147,9 +145,12 @@ void Coder<SHA1::Digest>::encode(Encoder& encoder, const SHA1::Digest& digest)
     encoder.encodeFixedLengthData(digest.data(), sizeof(digest));
 }
 
-bool Coder<SHA1::Digest>::decode(Decoder& decoder, SHA1::Digest& digest)
+Optional<SHA1::Digest> Coder<SHA1::Digest>::decode(Decoder& decoder)
 {
-    return decoder.decodeFixedLengthData(digest.data(), sizeof(digest));
+    SHA1::Digest tmp;
+    if (!decoder.decodeFixedLengthData(tmp.data(), sizeof(tmp)))
+        return WTF::nullopt;
+    return WTFMove(tmp);
 }
 
 }
index d9b7769..debc84e 100644 (file)
@@ -46,19 +46,19 @@ template<typename T, typename U> struct Coder<std::pair<T, U>> {
         encoder << pair.first << pair.second;
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, std::pair<T, U>& pair)
+    static Optional<std::pair<T, U>> decode(Decoder& decoder)
     {
-        T first;
-        if (!decoder.decode(first))
-            return false;
+        Optional<T> first;
+        decoder >> first;
+        if (!first)
+            return WTF::nullopt;
 
-        U second;
-        if (!decoder.decode(second))
-            return false;
+        Optional<U> second;
+        decoder >> second;
+        if (!second)
+            return WTF::nullopt;
 
-        pair.first = first;
-        pair.second = second;
-        return true;
+        return {{ WTFMove(*first), WTFMove(*second) }};
     }
 };
 
@@ -74,23 +74,21 @@ template<typename T> struct Coder<Optional<T>> {
         encoder << optional.value();
     }
     
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Optional<T>& optional)
+    static Optional<Optional<T>> decode(Decoder& decoder)
     {
-        bool isEngaged;
-        if (!decoder.decode(isEngaged))
-            return false;
+        Optional<bool> isEngaged;
+        decoder >> isEngaged;
+        if (!isEngaged)
+            return WTF::nullopt;
+        if (!*isEngaged)
+            return Optional<Optional<T>> { Optional<T> { WTF::nullopt } };
         
-        if (!isEngaged) {
-            optional = WTF::nullopt;
-            return true;
-        }
-        
-        T value;
-        if (!decoder.decode(value))
-            return false;
+        Optional<T> value;
+        decoder >> value;
+        if (!value)
+            return WTF::nullopt;
         
-        optional = WTFMove(value);
-        return true;
+        return Optional<Optional<T>> { Optional<T> { WTFMove(*value) } };
     }
 };
 
@@ -100,19 +98,19 @@ template<typename KeyType, typename ValueType> struct Coder<WTF::KeyValuePair<Ke
         encoder << pair.key << pair.value;
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
+    static Optional<WTF::KeyValuePair<KeyType, ValueType>> decode(Decoder& decoder)
     {
-        KeyType key;
-        if (!decoder.decode(key))
-            return false;
+        Optional<KeyType> key;
+        decoder >> key;
+        if (!key)
+            return WTF::nullopt;
 
-        ValueType value;
-        if (!decoder.decode(value))
-            return false;
+        Optional<ValueType> value;
+        decoder >>value;
+        if (!value)
+            return WTF::nullopt;
 
-        pair.key = key;
-        pair.value = value;
-        return true;
+        return {{ WTFMove(*key), WTFMove(*value) }};
     }
 };
 
@@ -126,24 +124,24 @@ template<typename T, size_t inlineCapacity> struct VectorCoder<false, T, inlineC
             encoder << vector[i];
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
+    static Optional<Vector<T, inlineCapacity>> decode(Decoder& decoder)
     {
-        uint64_t size;
-        if (!decoder.decode(size))
-            return false;
+        Optional<uint64_t> size;
+        decoder >> size;
+        if (!size)
+            return WTF::nullopt;
 
         Vector<T, inlineCapacity> tmp;
-        for (size_t i = 0; i < size; ++i) {
-            T element;
-            if (!decoder.decode(element))
-                return false;
-            
-            tmp.append(WTFMove(element));
+        for (size_t i = 0; i < *size; ++i) {
+            Optional<T> element;
+            decoder >> element;
+            if (!element)
+                return WTF::nullopt;
+            tmp.append(WTFMove(*element));
         }
 
         tmp.shrinkToFit();
-        vector.swap(tmp);
-        return true;
+        return WTFMove(tmp);
     }
 };
 
@@ -154,31 +152,31 @@ template<typename T, size_t inlineCapacity> struct VectorCoder<true, T, inlineCa
         encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T));
     }
     
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
+    static Optional<Vector<T, inlineCapacity>> decode(Decoder& decoder)
     {
-        uint64_t decodedSize;
-        if (!decoder.decode(decodedSize))
-            return false;
+        Optional<uint64_t> decodedSize;
+        decoder >> decodedSize;
+        if (!decodedSize)
+            return WTF::nullopt;
 
-        if (!isInBounds<size_t>(decodedSize))
-            return false;
+        if (!isInBounds<size_t>(*decodedSize))
+            return WTF::nullopt;
 
-        auto size = static_cast<size_t>(decodedSize);
+        auto size = static_cast<size_t>(*decodedSize);
 
         // Since we know the total size of the elements, we can allocate the vector in
         // one fell swoop. Before allocating we must however make sure that the decoder buffer
         // is big enough.
         if (!decoder.bufferIsLargeEnoughToContain<T>(size))
-            return false;
+            return WTF::nullopt;
 
         Vector<T, inlineCapacity> temp;
         temp.grow(size);
 
         if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T)))
-            return false;
+            return WTF::nullopt;
 
-        vector.swap(temp);
-        return true;
+        return WTFMove(temp);
     }
 };
 
@@ -194,30 +192,32 @@ template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTrai
             encoder << *it;
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, HashMapType& hashMap)
+    static Optional<HashMapType> decode(Decoder& decoder)
     {
-        uint64_t hashMapSize;
-        if (!decoder.decode(hashMapSize))
-            return false;
+        Optional<uint64_t> hashMapSize;
+        decoder >> hashMapSize;
+        if (!hashMapSize)
+            return WTF::nullopt;
 
         HashMapType tempHashMap;
-        tempHashMap.reserveInitialCapacity(static_cast<unsigned>(hashMapSize));
-        for (uint64_t i = 0; i < hashMapSize; ++i) {
-            KeyArg key;
-            MappedArg value;
-            if (!decoder.decode(key))
-                return false;
-            if (!decoder.decode(value))
-                return false;
-
-            if (!tempHashMap.add(key, value).isNewEntry) {
+        tempHashMap.reserveInitialCapacity(static_cast<unsigned>(*hashMapSize));
+        for (uint64_t i = 0; i < *hashMapSize; ++i) {
+            Optional<KeyArg> key;
+            decoder >> key;
+            if (!key)
+                return WTF::nullopt;
+            Optional<MappedArg> value;
+            decoder >> value;
+            if (!value)
+                return WTF::nullopt;
+
+            if (!tempHashMap.add(WTFMove(*key), WTFMove(*value)).isNewEntry) {
                 // The hash map already has the specified key, bail.
-                return false;
+                return WTF::nullopt;
             }
         }
 
-        hashMap.swap(tempHashMap);
-        return true;
+        return WTFMove(tempHashMap);
     }
 };
 
@@ -231,26 +231,27 @@ template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct Coder<
             encoder << *it;
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, HashSetType& hashSet)
+    static Optional<HashSetType> decode(Decoder& decoder)
     {
-        uint64_t hashSetSize;
-        if (!decoder.decode(hashSetSize))
-            return false;
+        Optional<uint64_t> hashSetSize;
+        decoder >> hashSetSize;
+        if (!hashSetSize)
+            return WTF::nullopt;
 
         HashSetType tempHashSet;
-        for (uint64_t i = 0; i < hashSetSize; ++i) {
-            KeyArg key;
-            if (!decoder.decode(key))
-                return false;
+        for (uint64_t i = 0; i < *hashSetSize; ++i) {
+            Optional<KeyArg> key;
+            decoder >> key;
+            if (!key)
+                return WTF::nullopt;
 
-            if (!tempHashSet.add(key).isNewEntry) {
+            if (!tempHashSet.add(WTFMove(*key)).isNewEntry) {
                 // The hash map already has the specified key, bail.
-                return false;
+                return WTF::nullopt;
             }
         }
 
-        hashSet.swap(tempHashSet);
-        return true;
+        return WTFMove(tempHashSet);
     }
 };
 
@@ -260,14 +261,13 @@ template<> struct Coder<Seconds> {
         encoder << seconds.value();
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Seconds& result)
+    static Optional<Seconds> decode(Decoder& decoder)
     {
-        double value;
-        if (!decoder.decode(value))
-            return false;
-
-        result = Seconds(value);
-        return true;
+        Optional<double> value;
+        decoder >> value;
+        if (!value)
+            return WTF::nullopt;
+        return Seconds(*value);
     }
 };
 
@@ -277,35 +277,35 @@ template<> struct Coder<WallTime> {
         encoder << time.secondsSinceEpoch().value();
     }
 
-    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, WallTime& result)
+    static Optional<WallTime> decode(Decoder& decoder)
     {
-        double value;
-        if (!decoder.decode(value))
-            return false;
+        Optional<double> value;
+        decoder >> value;
+        if (!value)
+            return WTF::nullopt;
 
-        result = WallTime::fromRawSeconds(value);
-        return true;
+        return WallTime::fromRawSeconds(*value);
     }
 };
 
 template<> struct Coder<AtomString> {
     WTF_EXPORT_PRIVATE static void encode(Encoder&, const AtomString&);
-    WTF_EXPORT_PRIVATE static bool decode(Decoder&, AtomString&) WARN_UNUSED_RETURN;
+    WTF_EXPORT_PRIVATE static Optional<AtomString> decode(Decoder&);
 };
 
 template<> struct Coder<CString> {
     WTF_EXPORT_PRIVATE static void encode(Encoder&, const CString&);
-    WTF_EXPORT_PRIVATE static bool decode(Decoder&, CString&) WARN_UNUSED_RETURN;
+    WTF_EXPORT_PRIVATE static Optional<CString> decode(Decoder&);
 };
 
 template<> struct Coder<String> {
     WTF_EXPORT_PRIVATE static void encode(Encoder&, const String&);
-    WTF_EXPORT_PRIVATE static bool decode(Decoder&, String&) WARN_UNUSED_RETURN;
+    WTF_EXPORT_PRIVATE static Optional<String> decode(Decoder&);
 };
 
 template<> struct Coder<SHA1::Digest> {
     WTF_EXPORT_PRIVATE static void encode(Encoder&, const SHA1::Digest&);
-    WTF_EXPORT_PRIVATE static bool decode(Decoder&, SHA1::Digest&) WARN_UNUSED_RETURN;
+    WTF_EXPORT_PRIVATE static Optional<SHA1::Digest> decode(Decoder&);
 };
 
 }
index f2300a5..8595fca 100644 (file)
@@ -59,65 +59,67 @@ bool Decoder::decodeFixedLengthData(uint8_t* data, size_t size)
     return true;
 }
 
-template<typename Type>
-bool Decoder::decodeNumber(Type& value)
+template<typename T>
+Decoder& Decoder::decodeNumber(Optional<T>& optional)
 {
-    if (!bufferIsLargeEnoughToContain(sizeof(value)))
-        return false;
+    if (!bufferIsLargeEnoughToContain(sizeof(T)))
+        return *this;
 
-    memcpy(&value, m_bufferPosition, sizeof(value));
-    m_bufferPosition += sizeof(Type);
+    T value;
+    memcpy(&value, m_bufferPosition, sizeof(T));
+    m_bufferPosition += sizeof(T);
 
     Encoder::updateChecksumForNumber(m_sha1, value);
-    return true;
+    optional = value;
+    return *this;
 }
 
-bool Decoder::decode(bool& result)
+Decoder& Decoder::operator>>(Optional<bool>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(uint8_t& result)
+Decoder& Decoder::operator>>(Optional<uint8_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(uint16_t& result)
+Decoder& Decoder::operator>>(Optional<uint16_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(int16_t& result)
+Decoder& Decoder::operator>>(Optional<int16_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(uint32_t& result)
+Decoder& Decoder::operator>>(Optional<uint32_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(uint64_t& result)
+Decoder& Decoder::operator>>(Optional<uint64_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(int32_t& result)
+Decoder& Decoder::operator>>(Optional<int32_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(int64_t& result)
+Decoder& Decoder::operator>>(Optional<int64_t>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(float& result)
+Decoder& Decoder::operator>>(Optional<float>& result)
 {
     return decodeNumber(result);
 }
 
-bool Decoder::decode(double& result)
+Decoder& Decoder::operator>>(Optional<double>& result)
 {
     return decodeNumber(result);
 }
index 9da9ebe..76ca015 100644 (file)
@@ -45,47 +45,36 @@ public:
 
     WTF_EXPORT_PRIVATE bool decodeFixedLengthData(uint8_t*, size_t) WARN_UNUSED_RETURN;
 
-    WTF_EXPORT_PRIVATE bool decode(bool&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(uint8_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(uint16_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(uint32_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(uint64_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(int16_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(int32_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(int64_t&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(float&) WARN_UNUSED_RETURN;
-    WTF_EXPORT_PRIVATE bool decode(double&) WARN_UNUSED_RETURN;
-
-    template<typename E> WARN_UNUSED_RETURN
-    auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool>
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<bool>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<uint8_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<uint16_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<uint32_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<uint64_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<int16_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<int32_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<int64_t>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<float>&);
+    WTF_EXPORT_PRIVATE Decoder& operator>>(Optional<double>&);
+
+    template<typename T, std::enable_if_t<!std::is_arithmetic<typename std::remove_const<T>>::value && !std::is_enum<T>::value>* = nullptr>
+    Decoder& operator>>(Optional<T>& result)
     {
-        uint64_t value;
-        if (!decode(value))
-            return false;
-        if (!isValidEnum<E>(value))
-            return false;
-
-        e = static_cast<E>(value);
-        return true;
-    }
-
-    template<typename T> WARN_UNUSED_RETURN
-    bool decodeEnum(T& result)
-    {
-        static_assert(sizeof(T) <= 8, "Enum type T must not be larger than 64 bits!");
-
-        uint64_t value;
-        if (!decode(value))
-            return false;
-        
-        result = static_cast<T>(value);
-        return true;
+        result = Coder<T>::decode(*this);
+        return *this;
     }
 
-    template<typename T> WARN_UNUSED_RETURN
-    auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>
+    template<typename E, std::enable_if_t<std::is_enum<E>::value>* = nullptr>
+    Decoder& operator>>(Optional<E>& result)
     {
-        return Coder<T>::decode(*this, t);
+        static_assert(sizeof(E) <= 8, "Enum type T must not be larger than 64 bits!");
+        Optional<uint64_t> value;
+        *this >> value;
+        if (!value)
+            return *this;
+        if (!isValidEnum<E>(*value))
+            return *this;
+        result = static_cast<E>(*value);
+        return *this;
     }
 
     template<typename T> WARN_UNUSED_RETURN
@@ -103,7 +92,7 @@ public:
 
 private:
     WTF_EXPORT_PRIVATE bool bufferIsLargeEnoughToContain(size_t) const WARN_UNUSED_RETURN;
-    template<typename Type> bool decodeNumber(Type&) WARN_UNUSED_RETURN;
+    template<typename Type> Decoder& decodeNumber(Optional<Type>&) WARN_UNUSED_RETURN;
 
     const uint8_t* m_buffer;
     const uint8_t* m_bufferPosition;
index 1e1057f..14dd3f6 100644 (file)
@@ -62,62 +62,63 @@ void Encoder::encodeFixedLengthData(const uint8_t* data, size_t size)
 }
 
 template<typename Type>
-void Encoder::encodeNumber(Type value)
+Encoder& Encoder::encodeNumber(Type value)
 {
     Encoder::updateChecksumForNumber(m_sha1, value);
 
     uint8_t* buffer = grow(sizeof(Type));
     memcpy(buffer, &value, sizeof(Type));
+    return *this;
 }
 
-void Encoder::encode(bool value)
+Encoder& Encoder::operator<<(bool value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(uint8_t value)
+Encoder& Encoder::operator<<(uint8_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(uint16_t value)
+Encoder& Encoder::operator<<(uint16_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(int16_t value)
+Encoder& Encoder::operator<<(int16_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(uint32_t value)
+Encoder& Encoder::operator<<(uint32_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(uint64_t value)
+Encoder& Encoder::operator<<(uint64_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(int32_t value)
+Encoder& Encoder::operator<<(int32_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(int64_t value)
+Encoder& Encoder::operator<<(int64_t value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(float value)
+Encoder& Encoder::operator<<(float value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
-void Encoder::encode(double value)
+Encoder& Encoder::operator<<(double value)
 {
-    encodeNumber(value);
+    return encodeNumber(value);
 }
 
 void Encoder::encodeChecksum()
index 32c973f..27ad0d0 100644 (file)
@@ -45,32 +45,31 @@ public:
     WTF_EXPORT_PRIVATE void encodeChecksum();
     WTF_EXPORT_PRIVATE void encodeFixedLengthData(const uint8_t*, size_t);
 
-    template<typename E> auto encode(E value) -> std::enable_if_t<std::is_enum<E>::value>
+    template<typename T, std::enable_if_t<std::is_enum<T>::value>* = nullptr>
+    Encoder& operator<<(const T& t)
     {
-        static_assert(sizeof(E) <= sizeof(uint64_t), "Enum type must not be larger than 64 bits.");
-
-        ASSERT(isValidEnum<E>(static_cast<uint64_t>(value)));
-        encode(static_cast<uint64_t>(value));
-    }
-
-    template<typename T> void encodeEnum(T t)
-    {
-        COMPILE_ASSERT(sizeof(T) <= sizeof(uint64_t), enum_type_must_not_be_larger_than_64_bits);
-
-        encode(static_cast<uint64_t>(t));
+        static_assert(sizeof(T) <= sizeof(uint64_t), "Enum type must not be larger than 64 bits.");
+        return *this << static_cast<uint64_t>(t);
     }
 
-    template<typename T> auto encode(const T& t) -> std::enable_if_t<!std::is_enum<T>::value>
+    template<typename T, std::enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<typename std::remove_const<T>>::value>* = nullptr>
+    Encoder& operator<<(const T& t)
     {
         Coder<T>::encode(*this, t);
-    }
-
-    template<typename T> Encoder& operator<<(const T& t)
-    {
-        encode(t);
         return *this;
     }
 
+    WTF_EXPORT_PRIVATE Encoder& operator<<(bool);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(uint8_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(uint16_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(uint32_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(uint64_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(int16_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(int32_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(int64_t);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(float);
+    WTF_EXPORT_PRIVATE Encoder& operator<<(double);
+
     const uint8_t* buffer() const { return m_buffer.data(); }
     size_t bufferSize() const { return m_buffer.size(); }
 
@@ -80,18 +79,8 @@ public:
     static constexpr bool isIPCEncoder = false;
 
 private:
-    WTF_EXPORT_PRIVATE void encode(bool);
-    WTF_EXPORT_PRIVATE void encode(uint8_t);
-    WTF_EXPORT_PRIVATE void encode(uint16_t);
-    WTF_EXPORT_PRIVATE void encode(uint32_t);
-    WTF_EXPORT_PRIVATE void encode(uint64_t);
-    WTF_EXPORT_PRIVATE void encode(int16_t);
-    WTF_EXPORT_PRIVATE void encode(int32_t);
-    WTF_EXPORT_PRIVATE void encode(int64_t);
-    WTF_EXPORT_PRIVATE void encode(float);
-    WTF_EXPORT_PRIVATE void encode(double);
-
-    template<typename Type> void encodeNumber(Type);
+
+    template<typename Type> Encoder& encodeNumber(Type);
 
     uint8_t* grow(size_t);
 
index 63e6328..5eebe46 100644 (file)
@@ -1,3 +1,33 @@
+2020-04-10  Alex Christensen  <achristensen@webkit.org>
+
+        PersistentCoders should use modern decoding syntax
+        https://bugs.webkit.org/show_bug.cgi?id=207497
+
+        Reviewed by Darin Adler.
+
+        * inspector/InspectorFrontendHost.cpp:
+        (WebCore::InspectorFrontendHost::showCertificate):
+        * loader/FetchOptions.h:
+        (WebCore::FetchOptions::decodePersistent):
+        * page/csp/ContentSecurityPolicyResponseHeaders.h:
+        (WebCore::ContentSecurityPolicyResponseHeaders::encode const):
+        (WebCore::ContentSecurityPolicyResponseHeaders::decode):
+        * platform/PasteboardCustomData.cpp:
+        (WebCore::PasteboardCustomData::fromSharedBuffer):
+        * platform/network/ResourceLoadPriority.h:
+        * platform/network/ResourceRequestBase.h:
+        (WebCore::ResourceRequestBase::encodeBase const):
+        (WebCore::ResourceRequestBase::decodeBase):
+        * platform/network/cf/CertificateInfo.h:
+        (WTF::Persistence::decodeCFData):
+        (WTF::Persistence::decodeSecTrustRef):
+        (WTF::Persistence::decodeCertificateChain):
+        (WTF::Persistence::Coder<WebCore::CertificateInfo>::encode):
+        (WTF::Persistence::Coder<WebCore::CertificateInfo>::decode):
+        * workers/service/server/RegistrationDatabase.cpp:
+        (WebCore::RegistrationDatabase::doPushChanges):
+        (WebCore::RegistrationDatabase::importRecords):
+
 2020-04-10  Simon Fraser  <simon.fraser@apple.com>
 
         [macOS] Fix scrollbar display for async-scrolling overflow
index 84705e2..248f492 100644 (file)
@@ -60,6 +60,7 @@
 #include <pal/system/Sound.h>
 #include <wtf/JSONValues.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/persistence/PersistentDecoder.h>
 #include <wtf/text/Base64.h>
 
 namespace WebCore {
@@ -574,15 +575,16 @@ bool InspectorFrontendHost::showCertificate(const String& serializedCertificate)
     if (!base64Decode(serializedCertificate, data))
         return false;
 
-    CertificateInfo certificateInfo;
     WTF::Persistence::Decoder decoder(data.data(), data.size());
-    if (!decoder.decode(certificateInfo))
+    Optional<CertificateInfo> certificateInfo;
+    decoder >> certificateInfo;
+    if (!certificateInfo)
         return false;
 
-    if (certificateInfo.isEmpty())
+    if (certificateInfo->isEmpty())
         return false;
 
-    m_client->showCertificate(certificateInfo);
+    m_client->showCertificate(*certificateInfo);
     return true;
 }
 
index ee9edb3..0a0bad0 100644 (file)
@@ -969,7 +969,7 @@ void InspectorNetworkAgent::getSerializedCertificate(ErrorString& errorString, c
     }
 
     WTF::Persistence::Encoder encoder;
-    encoder << certificate.value();
+    WTF::Persistence::Coder<WebCore::CertificateInfo>::encode(encoder, certificate.value());
     *serializedCertificate = base64Encode(encoder.buffer(), encoder.bufferSize());
 }
 
index d6ab46b..15fced0 100644 (file)
@@ -167,7 +167,8 @@ template<> struct EnumTraits<WebCore::FetchOptions::Redirect> {
 
 namespace WebCore {
 
-template<class Encoder> inline void FetchOptions::encodePersistent(Encoder& encoder) const
+template<class Encoder>
+inline void FetchOptions::encodePersistent(Encoder& encoder) const
 {
     // Changes to encoding here should bump NetworkCache Storage format version.
     encoder << destination;
@@ -180,59 +181,70 @@ template<class Encoder> inline void FetchOptions::encodePersistent(Encoder& enco
     encoder << keepAlive;
 }
 
-template<class Decoder> inline bool FetchOptions::decodePersistent(Decoder& decoder, FetchOptions& options)
+template<class Decoder>
+inline WARN_UNUSED_RETURN bool FetchOptions::decodePersistent(Decoder& decoder, FetchOptions& options)
 {
-    FetchOptions::Destination destination;
-    if (!decoder.decode(destination))
+    Optional<FetchOptions::Destination> destination;
+    decoder >> destination;
+    if (!destination)
         return false;
 
-    FetchOptions::Mode mode;
-    if (!decoder.decode(mode))
+    Optional<FetchOptions::Mode> mode;
+    decoder >> mode;
+    if (!mode)
         return false;
 
-    FetchOptions::Credentials credentials;
-    if (!decoder.decode(credentials))
+    Optional<FetchOptions::Credentials> credentials;
+    decoder >> credentials;
+    if (!credentials)
         return false;
 
-    FetchOptions::Cache cache;
-    if (!decoder.decode(cache))
+    Optional<FetchOptions::Cache> cache;
+    decoder >> cache;
+    if (!cache)
         return false;
 
-    FetchOptions::Redirect redirect;
-    if (!decoder.decode(redirect))
+    Optional<FetchOptions::Redirect> redirect;
+    decoder >> redirect;
+    if (!redirect)
         return false;
 
-    ReferrerPolicy referrerPolicy;
-    if (!decoder.decode(referrerPolicy))
+    Optional<ReferrerPolicy> referrerPolicy;
+    decoder >> referrerPolicy;
+    if (!referrerPolicy)
         return false;
 
-    String integrity;
-    if (!decoder.decode(integrity))
+    Optional<String> integrity;
+    decoder >> integrity;
+    if (!integrity)
         return false;
 
-    bool keepAlive;
-    if (!decoder.decode(keepAlive))
+    Optional<bool> keepAlive;
+    decoder >> keepAlive;
+    if (!keepAlive)
         return false;
 
-    options.destination = destination;
-    options.mode = mode;
-    options.credentials = credentials;
-    options.cache = cache;
-    options.redirect = redirect;
-    options.referrerPolicy = referrerPolicy;
-    options.integrity = WTFMove(integrity);
-    options.keepAlive = keepAlive;
+    options.destination = *destination;
+    options.mode = *mode;
+    options.credentials = *credentials;
+    options.cache = *cache;
+    options.redirect = *redirect;
+    options.referrerPolicy = *referrerPolicy;
+    options.integrity = WTFMove(*integrity);
+    options.keepAlive = *keepAlive;
 
     return true;
 }
 
-template<class Encoder> inline void FetchOptions::encode(Encoder& encoder) const
+template<class Encoder>
+inline void FetchOptions::encode(Encoder& encoder) const
 {
     encodePersistent(encoder);
     encoder << clientIdentifier.asOptional();
 }
 
-template<class Decoder> inline Optional<FetchOptions> FetchOptions::decode(Decoder& decoder)
+template<class Decoder>
+inline Optional<FetchOptions> FetchOptions::decode(Decoder& decoder)
 {
     FetchOptions options;
     if (!decodePersistent(decoder, options))
index 1645b71..6865a4f 100644 (file)
@@ -115,11 +115,12 @@ Optional<SecurityOriginData> SecurityOriginData::decode(Decoder& decoder)
     if (!host)
         return WTF::nullopt;
     
-    Optional<uint16_t> port;
-    if (!decoder.decode(port))
+    Optional<Optional<uint16_t>> port;
+    decoder >> port;
+    if (!port)
         return WTF::nullopt;
     
-    SecurityOriginData data { WTFMove(*protocol), WTFMove(*host), WTFMove(port) };
+    SecurityOriginData data { WTFMove(*protocol), WTFMove(*host), WTFMove(*port) };
     if (data.isHashTableDeletedValue())
         return WTF::nullopt;
 
index 792252f..4b6f542 100644 (file)
@@ -33,7 +33,7 @@ namespace WebCore {
 class ContentSecurityPolicy;
 class ResourceResponse;
 
-enum class ContentSecurityPolicyHeaderType {
+enum class ContentSecurityPolicyHeaderType : bool {
     Report,
     Enforce,
 };
@@ -46,7 +46,7 @@ public:
     ContentSecurityPolicyResponseHeaders isolatedCopy() const;
 
     template <class Encoder> void encode(Encoder&) const;
-    template <class Decoder> static bool decode(Decoder&, ContentSecurityPolicyResponseHeaders&);
+    template <class Decoder> static Optional<ContentSecurityPolicyResponseHeaders> decode(Decoder&);
 
     enum EmptyTag { Empty };
     struct MarkableTraits {
@@ -78,32 +78,40 @@ void ContentSecurityPolicyResponseHeaders::encode(Encoder& encoder) const
     encoder << static_cast<uint64_t>(m_headers.size());
     for (auto& pair : m_headers) {
         encoder << pair.first;
-        encoder.encodeEnum(pair.second);
+        encoder << pair.second;
     }
     encoder << m_httpStatusCode;
 }
 
 template <class Decoder>
-bool ContentSecurityPolicyResponseHeaders::decode(Decoder& decoder, ContentSecurityPolicyResponseHeaders& headers)
+Optional<ContentSecurityPolicyResponseHeaders> ContentSecurityPolicyResponseHeaders::decode(Decoder& decoder)
 {
-    uint64_t headersSize;
-    if (!decoder.decode(headersSize))
-        return false;
-    for (size_t i = 0; i < headersSize; ++i) {
-        String header;
-        if (!decoder.decode(header))
-            return false;
-        ContentSecurityPolicyHeaderType headerType;
-        if (!decoder.decodeEnum(headerType))
-            return false;
-        headers.m_headers.append(std::make_pair(header, headerType));
+    ContentSecurityPolicyResponseHeaders headers;
+
+    Optional<uint64_t> headersSize;
+    decoder >> headersSize;
+    if (!headersSize)
+        return WTF::nullopt;
+    for (size_t i = 0; i < *headersSize; ++i) {
+        Optional<String> header;
+        decoder >> header;
+        if (!header)
+            return WTF::nullopt;
+        Optional<ContentSecurityPolicyHeaderType> headerType;
+        decoder >> headerType;
+        if (!headerType)
+            return WTF::nullopt;
+        headers.m_headers.append(std::make_pair(WTFMove(*header), WTFMove(*headerType)));
     }
     headers.m_headers.shrinkToFit();
 
-    if (!decoder.decode(headers.m_httpStatusCode))
-        return false;
+    Optional<int> httpStatusCode;
+    decoder >> httpStatusCode;
+    if (!httpStatusCode)
+        return WTF::nullopt;
+    headers.m_httpStatusCode = *httpStatusCode;
 
-    return true;
+    return WTFMove(headers);
 }
 
 } // namespace WebCore
index d254665..dc695fd 100644 (file)
@@ -98,23 +98,29 @@ PasteboardCustomData PasteboardCustomData::fromSharedBuffer(const SharedBuffer&
 
     PasteboardCustomData result;
     auto decoder = buffer.decoder();
-    unsigned version;
-    if (!decoder.decode(version) || version > maxSupportedDataSerializationVersionNumber)
+    Optional<unsigned> version;
+    decoder >> version;
+    if (!version || *version > maxSupportedDataSerializationVersionNumber)
         return { };
 
-    if (!decoder.decode(result.m_origin))
+    Optional<String> origin;
+    decoder >> origin;
+    if (!origin)
         return { };
+    result.m_origin = WTFMove(*origin);
 
-    HashMap<String, String> sameOriginCustomStringData;
-    if (!decoder.decode(sameOriginCustomStringData))
+    Optional<HashMap<String, String>> sameOriginCustomStringData;
+    decoder >> sameOriginCustomStringData;
+    if (!sameOriginCustomStringData)
         return { };
 
-    Vector<String> orderedTypes;
-    if (!decoder.decode(orderedTypes))
+    Optional<Vector<String>> orderedTypes;
+    decoder >> orderedTypes;
+    if (!orderedTypes)
         return { };
 
-    for (auto& type : orderedTypes)
-        result.writeStringInCustomData(type, sameOriginCustomStringData.get(type));
+    for (auto& type : *orderedTypes)
+        result.writeStringInCustomData(type, sameOriginCustomStringData->get(type));
 
     return result;
 }
index a5a89e4..1b83a91 100644 (file)
@@ -48,40 +48,36 @@ private:
     HashMap<String, std::unique_ptr<Node>> m_map;
 };
 
-static bool readString(WTF::Persistence::Decoder& decoder, String& result)
+static Optional<String> readString(WTF::Persistence::Decoder& decoder)
 {
-    size_t size;
-    if (!decoder.decode(size))
-        return false;
-    if (!size) {
-        result = emptyString();
-        return true;
-    }
-
-    if (!decoder.bufferIsLargeEnoughToContain<uint8_t>(size))
-        return false;
-    Vector<uint8_t> buffer(size);
-    if (!decoder.decodeFixedLengthData(buffer.data(), size))
-        return false;
-    result = String::fromUTF8(buffer.data(), size);
+    Optional<size_t> size;
+    decoder >> size;
+    if (!size)
+        return WTF::nullopt;
+    if (!size.value())
+        return emptyString();
+
+    Vector<uint8_t> buffer(size.value());
+    if (!decoder.decodeFixedLengthData(buffer.data(), size.value()))
+        return WTF::nullopt;
+    auto result = String::fromUTF8(buffer.data(), size.value());
     if (result.isNull())
-        return false;
+        return WTF::nullopt;
 
-    return true;
+    return result;
 }
 
 template<typename T>
 static bool readSimpleValue(WTF::Persistence::Decoder& decoder, KeyedDecoderGeneric::Dictionary& dictionary)
 {
-    String key;
-    bool ok = readString(decoder, key);
-    if (!ok)
+    auto key = readString(decoder);
+    if (!key)
         return false;
-    T value;
-    ok = decoder.decode(value);
-    if (!ok)
+    Optional<T> value;
+    decoder >> value;
+    if (!value)
         return false;
-    dictionary.add(key, WTFMove(value));
+    dictionary.add(key.value(), WTFMove(value.value()));
     return true;
 }
 
@@ -93,31 +89,38 @@ std::unique_ptr<KeyedDecoder> KeyedDecoder::decoder(const uint8_t* data, size_t
 KeyedDecoderGeneric::KeyedDecoderGeneric(const uint8_t* data, size_t size)
 {
     WTF::Persistence::Decoder decoder(data, size);
-    KeyedEncoderGeneric::Type type;
-    String key;
 
     m_rootDictionary = makeUnique<Dictionary>();
     m_dictionaryStack.append(m_rootDictionary.get());
 
     bool ok = true;
-    while (ok && decoder.decodeEnum(type)) {
-        switch (type) {
+    while (ok) {
+        Optional<KeyedEncoderGeneric::Type> type;
+        decoder >> type;
+        if (!type)
+            break;
+
+        switch (*type) {
         case KeyedEncoderGeneric::Type::Bytes: {
-            ok = readString(decoder, key);
+            auto key = readString(decoder);
+            if (!key)
+                ok = false;
             if (!ok)
                 break;
-            size_t size;
-            ok = decoder.decode(size);
+            Optional<size_t> size;
+            decoder >> size;
+            if (!size)
+                ok = false;
             if (!ok)
                 break;
-            ok = decoder.bufferIsLargeEnoughToContain<uint8_t>(size);
+            ok = decoder.bufferIsLargeEnoughToContain<uint8_t>(*size);
             if (!ok)
                 break;
-            Vector<uint8_t> buffer(size);
-            ok = decoder.decodeFixedLengthData(buffer.data(), size);
+            Vector<uint8_t> buffer(*size);
+            ok = decoder.decodeFixedLengthData(buffer.data(), *size);
             if (!ok)
                 break;
-            m_dictionaryStack.last()->add(key, WTFMove(buffer));
+            m_dictionaryStack.last()->add(*key, WTFMove(buffer));
             break;
         }
         case KeyedEncoderGeneric::Type::Bool:
@@ -142,24 +145,29 @@ KeyedDecoderGeneric::KeyedDecoderGeneric(const uint8_t* data, size_t size)
             ok = readSimpleValue<double>(decoder, *m_dictionaryStack.last());
             break;
         case KeyedEncoderGeneric::Type::String: {
-            ok = readString(decoder, key);
+            auto key = readString(decoder);
+            if (!key)
+                ok = false;
             if (!ok)
                 break;
-            String value;
-            ok = readString(decoder, value);
+            auto value = readString(decoder);
+            if (!value)
+                ok = false;
             if (!ok)
                 break;
-            m_dictionaryStack.last()->add(key, WTFMove(value));
+            m_dictionaryStack.last()->add(*key, WTFMove(*value));
             break;
         }
         case KeyedEncoderGeneric::Type::BeginObject: {
-            ok = readString(decoder, key);
+            auto key = readString(decoder);
+            if (!key)
+                ok = false;
             if (!ok)
                 break;
             auto* currentDictinary = m_dictionaryStack.last();
             auto newDictionary = makeUnique<Dictionary>();
             m_dictionaryStack.append(newDictionary.get());
-            currentDictinary->add(key, WTFMove(newDictionary));
+            currentDictinary->add(*key, WTFMove(newDictionary));
             break;
         }
         case KeyedEncoderGeneric::Type::EndObject:
@@ -168,12 +176,14 @@ KeyedDecoderGeneric::KeyedDecoderGeneric(const uint8_t* data, size_t size)
                 ok = false;
             break;
         case KeyedEncoderGeneric::Type::BeginArray: {
-            ok = readString(decoder, key);
+            auto key = readString(decoder);
+            if (!key)
+                ok = false;
             if (!ok)
                 break;
             auto newArray = makeUnique<Array>();
             m_arrayStack.append(newArray.get());
-            m_dictionaryStack.last()->add(key, WTFMove(newArray));
+            m_dictionaryStack.last()->add(*key, WTFMove(newArray));
             break;
         }
         case KeyedEncoderGeneric::Type::BeginArrayElement: {
index 456896f..3d68833 100644 (file)
@@ -30,8 +30,7 @@
 #include <wtf/Box.h>
 #include <wtf/Optional.h>
 #include <wtf/Seconds.h>
-#include <wtf/persistence/PersistentDecoder.h>
-#include <wtf/persistence/PersistentEncoder.h>
+#include <wtf/persistence/PersistentCoder.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(COCOA)
index 00404d4..a01fcd9 100644 (file)
@@ -23,8 +23,9 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ResourceLoadPriority_h
-#define ResourceLoadPriority_h
+#pragma once
+
+#include <wtf/EnumTraits.h>
 
 namespace WebCore {
 
@@ -54,7 +55,19 @@ inline ResourceLoadPriority& operator--(ResourceLoadPriority& priority)
     return priority = static_cast<ResourceLoadPriority>(static_cast<int>(priority) - 1);
 }
 
-}
+} // namespace WebCore
 
-#endif
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::ResourceLoadPriority> {
+    using values = EnumValues<
+        WebCore::ResourceLoadPriority,
+        WebCore::ResourceLoadPriority::VeryLow,
+        WebCore::ResourceLoadPriority::Low,
+        WebCore::ResourceLoadPriority::Medium,
+        WebCore::ResourceLoadPriority::High,
+        WebCore::ResourceLoadPriority::VeryHigh
+    >;
+};
 
+} // namespace WTF
index 361b7e9..d1a8350 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ResourceRequestBase_h
-#define ResourceRequestBase_h
+#pragma once
 
 #include "FormData.h"
 #include "FrameLoaderTypes.h"
 #include "HTTPHeaderMap.h"
 #include "IntRect.h"
 #include "ResourceLoadPriority.h"
+#include <wtf/EnumTraits.h>
 #include <wtf/URL.h>
 
 namespace WebCore {
@@ -283,64 +283,88 @@ ALWAYS_INLINE void ResourceRequestBase::encodeBase(Encoder& encoder) const
     encoder << m_httpMethod;
     encoder << m_httpHeaderFields;
     encoder << m_responseContentDispositionEncodingFallbackArray;
-    encoder.encodeEnum(m_cachePolicy);
+    encoder << m_cachePolicy;
     encoder << m_allowCookies;
-    encoder.encodeEnum(m_sameSiteDisposition);
+    encoder << m_sameSiteDisposition;
     encoder << m_isTopSite;
-    encoder.encodeEnum(m_priority);
-    encoder.encodeEnum(m_requester);
+    encoder << m_priority;
+    encoder << m_requester;
 }
 
 template<class Decoder>
 ALWAYS_INLINE bool ResourceRequestBase::decodeBase(Decoder& decoder)
 {
-    if (!decoder.decode(m_url))
+    Optional<URL> url;
+    decoder >> url;
+    if (!url)
         return false;
+    m_url = WTFMove(*url);
 
-    if (!decoder.decode(m_timeoutInterval))
+    Optional<double> timeoutInterval;
+    decoder >> timeoutInterval;
+    if (!timeoutInterval)
         return false;
+    m_timeoutInterval = WTFMove(*timeoutInterval);
 
-    String firstPartyForCookies;
-    if (!decoder.decode(firstPartyForCookies))
+    Optional<String> firstPartyForCookies;
+    decoder >> firstPartyForCookies;
+    if (!firstPartyForCookies)
         return false;
-    m_firstPartyForCookies = URL({ }, firstPartyForCookies);
+    m_firstPartyForCookies = URL({ }, *firstPartyForCookies);
 
-    if (!decoder.decode(m_httpMethod))
+    Optional<String> httpMethod;
+    decoder >> httpMethod;
+    if (!httpMethod)
         return false;
+    m_httpMethod = WTFMove(*httpMethod);
 
-    if (!decoder.decode(m_httpHeaderFields))
+    Optional<HTTPHeaderMap> fields;
+    decoder >> fields;
+    if (!fields)
         return false;
+    m_httpHeaderFields = WTFMove(*fields);
 
-    if (!decoder.decode(m_responseContentDispositionEncodingFallbackArray))
+    Optional<Vector<String>> array;
+    decoder >> array;
+    if (!array)
         return false;
+    m_responseContentDispositionEncodingFallbackArray = WTFMove(*array);
 
-    ResourceRequestCachePolicy cachePolicy;
-    if (!decoder.decodeEnum(cachePolicy))
+    Optional<ResourceRequestCachePolicy> cachePolicy;
+    decoder >> cachePolicy;
+    if (!cachePolicy)
         return false;
-    m_cachePolicy = cachePolicy;
+    m_cachePolicy = *cachePolicy;
 
-    bool allowCookies;
-    if (!decoder.decode(allowCookies))
+    Optional<bool> allowCookies;
+    decoder >> allowCookies;
+    if (!allowCookies)
         return false;
-    m_allowCookies = allowCookies;
+    m_allowCookies = *allowCookies;
 
-    SameSiteDisposition sameSiteDisposition;
-    if (!decoder.decodeEnum(sameSiteDisposition))
+    Optional<SameSiteDisposition> sameSiteDisposition;
+    decoder >> sameSiteDisposition;
+    if (!sameSiteDisposition)
         return false;
-    m_sameSiteDisposition = sameSiteDisposition;
+    m_sameSiteDisposition = *sameSiteDisposition;
 
-    bool isTopSite;
-    if (!decoder.decode(isTopSite))
+    Optional<bool> isTopSite;
+    decoder >> isTopSite;
+    if (!isTopSite)
         return false;
-    m_isTopSite = isTopSite;
+    m_isTopSite = *isTopSite;
 
-    ResourceLoadPriority priority;
-    if (!decoder.decodeEnum(priority))
+    Optional<ResourceLoadPriority> priority;
+    decoder >> priority;
+    if (!priority)
         return false;
-    m_priority = priority;
+    m_priority = *priority;
 
-    if (!decoder.decodeEnum(m_requester))
+    Optional<Requester> requester;
+    decoder >> requester;
+    if (!requester)
         return false;
+    m_requester = *requester;
 
     return true;
 }
@@ -361,4 +385,41 @@ bool ResourceRequestBase::decodeWithoutPlatformData(Decoder& decoder)
 
 } // namespace WebCore
 
-#endif // ResourceRequestBase_h
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::ResourceRequestCachePolicy> {
+    using values = EnumValues<
+        WebCore::ResourceRequestCachePolicy,
+        WebCore::ResourceRequestCachePolicy::UseProtocolCachePolicy,
+        WebCore::ResourceRequestCachePolicy::ReloadIgnoringCacheData,
+        WebCore::ResourceRequestCachePolicy::ReturnCacheDataElseLoad,
+        WebCore::ResourceRequestCachePolicy::ReturnCacheDataDontLoad,
+        WebCore::ResourceRequestCachePolicy::DoNotUseAnyCache,
+        WebCore::ResourceRequestCachePolicy::RefreshAnyCacheData
+    >;
+};
+
+template<> struct EnumTraits<WebCore::ResourceRequestBase::SameSiteDisposition> {
+    using values = EnumValues<
+        WebCore::ResourceRequestBase::SameSiteDisposition,
+        WebCore::ResourceRequestBase::SameSiteDisposition::Unspecified,
+        WebCore::ResourceRequestBase::SameSiteDisposition::SameSite,
+        WebCore::ResourceRequestBase::SameSiteDisposition::CrossSite
+    >;
+};
+
+template<> struct EnumTraits<WebCore::ResourceRequestBase::Requester> {
+    using values = EnumValues<
+        WebCore::ResourceRequestBase::Requester,
+        WebCore::ResourceRequestBase::Requester::Unspecified,
+        WebCore::ResourceRequestBase::Requester::Main,
+        WebCore::ResourceRequestBase::Requester::XHR,
+        WebCore::ResourceRequestBase::Requester::Fetch,
+        WebCore::ResourceRequestBase::Requester::Media,
+        WebCore::ResourceRequestBase::Requester::ImportScripts,
+        WebCore::ResourceRequestBase::Requester::Ping,
+        WebCore::ResourceRequestBase::Requester::Beacon
+    >;
+};
+
+} // namespace WTF
index aeda269..d6efa2c 100644 (file)
@@ -32,6 +32,7 @@
 #include "NetworkLoadMetrics.h"
 #include "ParsedContentRange.h"
 #include <wtf/Box.h>
+#include <wtf/EnumTraits.h>
 #include <wtf/Markable.h>
 #include <wtf/URL.h>
 #include <wtf/WallTime.h>
@@ -297,9 +298,9 @@ void ResourceResponseBase::encode(Encoder& encoder) const
 
     encoder << m_httpStatusCode;
     encoder << m_certificateInfo;
-    encoder.encodeEnum(m_source);
-    encoder.encodeEnum(m_type);
-    encoder.encodeEnum(m_tainting);
+    encoder << m_source;
+    encoder << m_type;
+    encoder << m_tainting;
     encoder << m_isRedirected;
     UsedLegacyTLS usedLegacyTLS = m_usedLegacyTLS;
     encoder << usedLegacyTLS;
@@ -307,68 +308,161 @@ void ResourceResponseBase::encode(Encoder& encoder) const
 }
 
 template<class Decoder>
-bool ResourceResponseBase::decode(Decoder& decoder, ResourceResponseBase& response)
+bool WARN_UNUSED_RETURN ResourceResponseBase::decode(Decoder& decoder, ResourceResponseBase& response)
 {
     ASSERT(response.m_isNull);
-    bool responseIsNull;
-    if (!decoder.decode(responseIsNull))
+    Optional<bool> responseIsNull;
+    decoder >> responseIsNull;
+    if (!responseIsNull)
         return false;
-    if (responseIsNull)
+    if (*responseIsNull)
         return true;
 
     response.m_isNull = false;
 
-    if (!decoder.decode(response.m_url))
+    Optional<URL> url;
+    decoder >> url;
+    if (!url)
         return false;
-    if (!decoder.decode(response.m_mimeType))
+    response.m_url = WTFMove(*url);
+
+    Optional<String> mimeType;
+    decoder >> mimeType;
+    if (!mimeType)
         return false;
-    int64_t expectedContentLength;
-    if (!decoder.decode(expectedContentLength))
+    response.m_mimeType = WTFMove(*mimeType);
+
+    Optional<int64_t> expectedContentLength;
+    decoder >> expectedContentLength;
+    if (!expectedContentLength)
         return false;
-    response.m_expectedContentLength = expectedContentLength;
-    if (!decoder.decode(response.m_textEncodingName))
+    response.m_expectedContentLength = *expectedContentLength;
+
+    Optional<AtomString> textEncodingName;
+    decoder >> textEncodingName;
+    if (!textEncodingName)
         return false;
-    if (!decoder.decode(response.m_httpStatusText))
+    response.m_textEncodingName = WTFMove(*textEncodingName);
+
+    Optional<AtomString> httpStatusText;
+    decoder >> httpStatusText;
+    if (!httpStatusText)
         return false;
-    if (!decoder.decode(response.m_httpVersion))
+    response.m_httpStatusText = WTFMove(*httpStatusText);
+
+    Optional<AtomString> httpVersion;
+    decoder >> httpVersion;
+    if (!httpVersion)
         return false;
-    if (!decoder.decode(response.m_httpHeaderFields))
+    response.m_httpVersion = WTFMove(*httpVersion);
+
+    Optional<HTTPHeaderMap> httpHeaderFields;
+    decoder >> httpHeaderFields;
+    if (!httpHeaderFields)
         return false;
+    response.m_httpHeaderFields = WTFMove(*httpHeaderFields);
+
     // The networkLoadMetrics info is only send over IPC and not stored in disk cache.
     if constexpr (Decoder::isIPCDecoder) {
-        if (!decoder.decode(response.m_networkLoadMetrics))
+        Optional<Box<NetworkLoadMetrics>> networkLoadMetrics;
+        decoder >> networkLoadMetrics;
+        if (!networkLoadMetrics)
             return false;
+        response.m_networkLoadMetrics = WTFMove(*networkLoadMetrics);
     }
-    if (!decoder.decode(response.m_httpStatusCode))
+
+    Optional<short> httpStatusCode;
+    decoder >> httpStatusCode;
+    if (!httpStatusCode)
         return false;
-    if (!decoder.decode(response.m_certificateInfo))
+    response.m_httpStatusCode = WTFMove(*httpStatusCode);
+
+    Optional<Optional<CertificateInfo>> certificateInfo;
+    decoder >> certificateInfo;
+    if (!certificateInfo)
         return false;
-    Source source = Source::Unknown;
-    if (!decoder.decodeEnum(source))
+    response.m_certificateInfo = WTFMove(*certificateInfo);
+
+    Optional<Source> source;
+    decoder >> source;
+    if (!source)
         return false;
-    response.m_source = source;
-    Type type = Type::Default;
-    if (!decoder.decodeEnum(type))
+    response.m_source = WTFMove(*source);
+
+    Optional<Type> type;
+    decoder >> type;
+    if (!type)
         return false;
-    response.m_type = type;
-    Tainting tainting = Tainting::Basic;
-    if (!decoder.decodeEnum(tainting))
+    response.m_type = WTFMove(*type);
+
+    Optional<Tainting> tainting;
+    decoder >> tainting;
+    if (!tainting)
         return false;
-    response.m_tainting = tainting;
-    bool isRedirected = false;
-    if (!decoder.decode(isRedirected))
+    response.m_tainting = WTFMove(*tainting);
+
+    Optional<bool> isRedirected;
+    decoder >> isRedirected;
+    if (!isRedirected)
         return false;
-    response.m_isRedirected = isRedirected;
-    UsedLegacyTLS usedLegacyTLS = UsedLegacyTLS::No;
-    if (!decoder.decode(usedLegacyTLS))
+    response.m_isRedirected = WTFMove(*isRedirected);
+
+    Optional<UsedLegacyTLS> usedLegacyTLS;
+    decoder >> usedLegacyTLS;
+    if (!usedLegacyTLS)
         return false;
-    response.m_usedLegacyTLS = usedLegacyTLS;
-    bool isRangeRequested = false;
-    if (!decoder.decode(isRangeRequested))
+    response.m_usedLegacyTLS = WTFMove(*usedLegacyTLS);
+
+    Optional<bool> isRangeRequested;
+    decoder >> isRangeRequested;
+    if (!isRangeRequested)
         return false;
-    response.m_isRangeRequested = isRangeRequested;
+    response.m_isRangeRequested = WTFMove(*isRangeRequested);
 
     return true;
 }
 
 } // namespace WebCore
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::ResourceResponseBase::Type> {
+    using values = EnumValues<
+        WebCore::ResourceResponseBase::Type,
+        WebCore::ResourceResponseBase::Type::Basic,
+        WebCore::ResourceResponseBase::Type::Cors,
+        WebCore::ResourceResponseBase::Type::Default,
+        WebCore::ResourceResponseBase::Type::Error,
+        WebCore::ResourceResponseBase::Type::Opaque,
+        WebCore::ResourceResponseBase::Type::Opaqueredirect
+    >;
+};
+
+template<> struct EnumTraits<WebCore::ResourceResponseBase::Tainting> {
+    using values = EnumValues<
+        WebCore::ResourceResponseBase::Tainting,
+        WebCore::ResourceResponseBase::Tainting::Basic,
+        WebCore::ResourceResponseBase::Tainting::Cors,
+        WebCore::ResourceResponseBase::Tainting::Opaque,
+        WebCore::ResourceResponseBase::Tainting::Opaqueredirect
+    >;
+};
+
+
+template<> struct EnumTraits<WebCore::ResourceResponseBase::Source> {
+    using values = EnumValues<
+        WebCore::ResourceResponseBase::Source,
+        WebCore::ResourceResponseBase::Source::Unknown,
+        WebCore::ResourceResponseBase::Source::Network,
+        WebCore::ResourceResponseBase::Source::DiskCache,
+        WebCore::ResourceResponseBase::Source::DiskCacheAfterValidation,
+        WebCore::ResourceResponseBase::Source::MemoryCache,
+        WebCore::ResourceResponseBase::Source::MemoryCacheAfterValidation,
+        WebCore::ResourceResponseBase::Source::ServiceWorker,
+        WebCore::ResourceResponseBase::Source::ApplicationCache,
+        WebCore::ResourceResponseBase::Source::DOMCache,
+        WebCore::ResourceResponseBase::Source::InspectorOverride
+    >;
+};
+
+} // namespace WTF
index f931113..adca68b 100644 (file)
 #pragma once
 
 #include "CertificateInfoBase.h"
+#include <wtf/EnumTraits.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/Vector.h>
 #include <wtf/cf/TypeCastsCF.h>
-#include <wtf/persistence/PersistentCoders.h>
-#include <wtf/persistence/PersistentDecoder.h>
-#include <wtf/persistence/PersistentEncoder.h>
+#include <wtf/persistence/PersistentCoder.h>
 
 #if PLATFORM(COCOA)
 #include <Security/SecCertificate.h>
@@ -98,163 +97,25 @@ private:
 } // namespace WebCore
 
 namespace WTF {
-namespace Persistence {
-
-static void encodeCFData(Encoder& encoder, CFDataRef data)
-{
-    uint64_t length = CFDataGetLength(data);
-    const uint8_t* bytePtr = CFDataGetBytePtr(data);
-
-    encoder << length;
-    encoder.encodeFixedLengthData(bytePtr, static_cast<size_t>(length));
-}
-
-static bool decodeCFData(Decoder& decoder, RetainPtr<CFDataRef>& data)
-{
-    uint64_t size = 0;
-    if (!decoder.decode(size))
-        return false;
-
-    Vector<uint8_t> vector(static_cast<size_t>(size));
-    if (!decoder.decodeFixedLengthData(vector.data(), vector.size()))
-        return false;
-
-    data = adoptCF(CFDataCreate(nullptr, vector.data(), vector.size()));
-    return true;
-}
 
+template<> struct EnumTraits<WebCore::CertificateInfo::Type> {
+    using values = EnumValues<
+        WebCore::CertificateInfo::Type,
+        WebCore::CertificateInfo::Type::None,
+        WebCore::CertificateInfo::Type::CertificateChain
 #if HAVE(SEC_TRUST_SERIALIZATION)
-static void encodeSecTrustRef(Encoder& encoder, SecTrustRef trust)
-{
-    auto data = adoptCF(SecTrustSerialize(trust, nullptr));
-    if (!data) {
-        encoder << false;
-        return;
-    }
-
-    encoder << true;
-    encodeCFData(encoder, data.get());
-}
-
-static bool decodeSecTrustRef(Decoder& decoder, RetainPtr<SecTrustRef>& result)
-{
-    bool hasTrust;
-    if (!decoder.decode(hasTrust))
-        return false;
-
-    if (!hasTrust)
-        return true;
-
-    RetainPtr<CFDataRef> trustData;
-    if (!decodeCFData(decoder, trustData))
-        return false;
-
-    auto trust = adoptCF(SecTrustDeserialize(trustData.get(), nullptr));
-    if (!trust)
-        return false;
-
-    result = WTFMove(trust);
-    return true;
-}
+        , WebCore::CertificateInfo::Type::Trust
 #endif
+    >;
+};
 
-#if PLATFORM(COCOA)
-static void encodeCertificateChain(Encoder& encoder, CFArrayRef certificateChain)
-{
-    CFIndex size = CFArrayGetCount(certificateChain);
-    Vector<CFTypeRef, 32> values(size);
-
-    CFArrayGetValues(certificateChain, CFRangeMake(0, size), values.data());
-
-    encoder << static_cast<uint64_t>(size);
-
-    for (CFIndex i = 0; i < size; ++i) {
-        ASSERT(values[i]);
-        auto data = adoptCF(SecCertificateCopyData(checked_cf_cast<SecCertificateRef>(values[i])));
-        encodeCFData(encoder, data.get());
-    }
-}
-
-static bool decodeCertificateChain(Decoder& decoder, RetainPtr<CFArrayRef>& certificateChain)
-{
-    uint64_t size;
-    if (!decoder.decode(size))
-        return false;
-
-    auto array = adoptCF(CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks));
-
-    for (size_t i = 0; i < size; ++i) {
-        RetainPtr<CFDataRef> data;
-        if (!decodeCFData(decoder, data))
-            return false;
-
-        auto certificate = adoptCF(SecCertificateCreateWithData(0, data.get()));
-        CFArrayAppendValue(array.get(), certificate.get());
-    }
-
-    certificateChain = WTFMove(array);
-    return true;
-}
-#endif
+namespace Persistence {
 
 template<> struct Coder<WebCore::CertificateInfo> {
-    static void encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo)
-    {
-        encoder.encodeEnum(certificateInfo.type());
-
-        switch (certificateInfo.type()) {
-#if HAVE(SEC_TRUST_SERIALIZATION)
-        case WebCore::CertificateInfo::Type::Trust:
-            encodeSecTrustRef(encoder, certificateInfo.trust());
-            break;
-#endif
-#if PLATFORM(COCOA)
-        case WebCore::CertificateInfo::Type::CertificateChain: {
-            encodeCertificateChain(encoder, certificateInfo.certificateChain());
-            break;
-        }
-#endif
-        case WebCore::CertificateInfo::Type::None:
-            // Do nothing.
-            break;
-        }
-    }
-
-    static bool decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
-    {
-        WebCore::CertificateInfo::Type certificateInfoType;
-        if (!decoder.decodeEnum(certificateInfoType))
-            return false;
-
-        switch (certificateInfoType) {
-#if HAVE(SEC_TRUST_SERIALIZATION)
-        case WebCore::CertificateInfo::Type::Trust: {
-            RetainPtr<SecTrustRef> trust;
-            if (!decodeSecTrustRef(decoder, trust))
-                return false;
-
-            certificateInfo = WebCore::CertificateInfo(WTFMove(trust));
-            return true;
-        }
-#endif
-#if PLATFORM(COCOA)
-        case WebCore::CertificateInfo::Type::CertificateChain: {
-            RetainPtr<CFArrayRef> certificateChain;
-            if (!decodeCertificateChain(decoder, certificateChain))
-                return false;
-
-            certificateInfo = WebCore::CertificateInfo(WTFMove(certificateChain));
-            return true;
-        }
-#endif
-        case WebCore::CertificateInfo::Type::None:
-            // Do nothing.
-            break;
-        }
-
-        return true;
-    }
+    static WEBCORE_EXPORT void encode(Encoder&, const WebCore::CertificateInfo&);
+    static WEBCORE_EXPORT Optional<WebCore::CertificateInfo> decode(Decoder&);
 };
 
 } // namespace WTF::Persistence
+
 } // namespace WTF
index c377611..ee402ca 100644 (file)
@@ -26,6 +26,9 @@
 #include "config.h"
 #include "CertificateInfo.h"
 
+#include <wtf/persistence/PersistentDecoder.h>
+#include <wtf/persistence/PersistentEncoder.h>
+
 namespace WebCore {
 
 #if PLATFORM(COCOA)
@@ -153,3 +156,165 @@ Optional<CertificateInfo::SummaryInfo> CertificateInfo::summaryInfo() const
 }
 
 } // namespace WebCore
+
+namespace WTF {
+namespace Persistence {
+
+static void encodeCFData(Encoder& encoder, CFDataRef data)
+{
+    uint64_t length = CFDataGetLength(data);
+    const uint8_t* bytePtr = CFDataGetBytePtr(data);
+
+    encoder << length;
+    encoder.encodeFixedLengthData(bytePtr, static_cast<size_t>(length));
+}
+
+static Optional<RetainPtr<CFDataRef>> decodeCFData(Decoder& decoder)
+{
+    Optional<uint64_t> size;
+    decoder >> size;
+    if (!size)
+        return WTF::nullopt;
+
+    if (UNLIKELY(!isInBounds<size_t>(*size)))
+        return WTF::nullopt;
+    
+    Vector<uint8_t> vector(static_cast<size_t>(*size));
+    if (!decoder.decodeFixedLengthData(vector.data(), vector.size()))
+        return WTF::nullopt;
+
+    return adoptCF(CFDataCreate(nullptr, vector.data(), vector.size()));
+}
+
+#if HAVE(SEC_TRUST_SERIALIZATION)
+static void encodeSecTrustRef(Encoder& encoder, SecTrustRef trust)
+{
+    auto data = adoptCF(SecTrustSerialize(trust, nullptr));
+    if (!data) {
+        encoder << false;
+        return;
+    }
+
+    encoder << true;
+    encodeCFData(encoder, data.get());
+}
+
+static Optional<RetainPtr<SecTrustRef>> decodeSecTrustRef(Decoder& decoder)
+{
+    Optional<bool> hasTrust;
+    decoder >> hasTrust;
+    if (!hasTrust)
+        return WTF::nullopt;
+
+    if (!*hasTrust)
+        return { nullptr };
+
+    auto trustData = decodeCFData(decoder);
+    if (!trustData)
+        return WTF::nullopt;
+
+    auto trust = adoptCF(SecTrustDeserialize(trustData->get(), nullptr));
+    if (!trust)
+        return WTF::nullopt;
+
+    return WTFMove(trust);
+}
+#endif
+
+#if PLATFORM(COCOA)
+static void encodeCertificateChain(Encoder& encoder, CFArrayRef certificateChain)
+{
+    CFIndex size = CFArrayGetCount(certificateChain);
+    Vector<CFTypeRef, 32> values(size);
+
+    CFArrayGetValues(certificateChain, CFRangeMake(0, size), values.data());
+
+    encoder << static_cast<uint64_t>(size);
+
+    for (CFIndex i = 0; i < size; ++i) {
+        ASSERT(values[i]);
+        auto data = adoptCF(SecCertificateCopyData(checked_cf_cast<SecCertificateRef>(values[i])));
+        encodeCFData(encoder, data.get());
+    }
+}
+
+static Optional<RetainPtr<CFArrayRef>> decodeCertificateChain(Decoder& decoder)
+{
+    Optional<uint64_t> size;
+    decoder >> size;
+    if (!size)
+        return WTF::nullopt;
+
+    auto array = adoptCF(CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks));
+
+    for (size_t i = 0; i < *size; ++i) {
+        auto data = decodeCFData(decoder);
+        if (!data)
+            return WTF::nullopt;
+
+        auto certificate = adoptCF(SecCertificateCreateWithData(0, data->get()));
+        CFArrayAppendValue(array.get(), certificate.get());
+    }
+
+    return { WTFMove(array) };
+}
+#endif
+
+void Coder<WebCore::CertificateInfo>::encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo)
+{
+    encoder << certificateInfo.type();
+
+    switch (certificateInfo.type()) {
+#if HAVE(SEC_TRUST_SERIALIZATION)
+    case WebCore::CertificateInfo::Type::Trust:
+        encodeSecTrustRef(encoder, certificateInfo.trust());
+        break;
+#endif
+#if PLATFORM(COCOA)
+    case WebCore::CertificateInfo::Type::CertificateChain: {
+        encodeCertificateChain(encoder, certificateInfo.certificateChain());
+        break;
+    }
+#endif
+    case WebCore::CertificateInfo::Type::None:
+        // Do nothing.
+        break;
+    }
+}
+
+Optional<WebCore::CertificateInfo> Coder<WebCore::CertificateInfo>::decode(Decoder& decoder)
+{
+    Optional<WebCore::CertificateInfo::Type> certificateInfoType;
+    decoder >> certificateInfoType;
+    if (!certificateInfoType)
+        return WTF::nullopt;
+
+    switch (*certificateInfoType) {
+#if HAVE(SEC_TRUST_SERIALIZATION)
+    case WebCore::CertificateInfo::Type::Trust: {
+        auto trust = decodeSecTrustRef(decoder);
+        if (!trust)
+            return WTF::nullopt;
+
+        return WebCore::CertificateInfo(WTFMove(*trust));
+    }
+#endif
+#if PLATFORM(COCOA)
+    case WebCore::CertificateInfo::Type::CertificateChain: {
+        auto certificateChain = decodeCertificateChain(decoder);
+        if (!certificateChain)
+            return WTF::nullopt;
+
+        return WebCore::CertificateInfo(WTFMove(*certificateChain));
+    }
+#endif
+    case WebCore::CertificateInfo::Type::None:
+        // Do nothing.
+        return WebCore::CertificateInfo();
+    }
+
+    return WTF::nullopt;
+}
+
+} // namespace Persistence
+} // namespace WTF
index 93dd373..e51698b 100644 (file)
@@ -82,27 +82,29 @@ template<> struct Coder<WebCore::CertificateInfo> {
             encoder << certificate;
     }
 
-    static bool decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
+    static Optional<WebCore::CertificateInfo> decode(Decoder& decoder)
     {
-        int verificationError;
-        if (!decoder.decode(verificationError))
-            return false;
+        Optional<int> verificationError;
+        decoder >> verificationError;
+        if (!verificationError)
+            return WTF::nullopt;
 
-        size_t numOfCert = 0;
-        if (!decoder.decode(numOfCert))
-            return false;
+        Optional<size_t> numOfCerts;
+        decoder >> numOfCerts;
+        if (!numOfCerts)
+            return WTF::nullopt;
 
         WebCore::CertificateInfo::CertificateChain certificateChain;
-        for (size_t i = 0; i < numOfCert; i++) {
-            WebCore::CertificateInfo::Certificate certificate;
-            if (!decoder.decode(certificate))
-                return false;
+        for (size_t i = 0; i < numOfCerts.value(); i++) {
+            Optional<WebCore::CertificateInfo::Certificate> certificate;
+            decoder >> certificate;
+            if (!certificate)
+                return WTF::nullopt;
 
-            certificateChain.append(WTFMove(certificate));
+            certificateChain.append(WTFMove(certificate.value()));
         }
 
-        certificateInfo = WebCore::CertificateInfo(verificationError, WTFMove(certificateChain));
-        return true;
+        return WebCore::CertificateInfo(verificationError.value(), WTFMove(certificateChain));
     }
 };
 
index 939bae5..4eac4c7 100644 (file)
@@ -76,15 +76,18 @@ template<> struct Coder<GRefPtr<GByteArray>> {
         encoder.encodeFixedLengthData(byteArray->data, byteArray->len);
     }
 
-    static bool decode(Decoder &decoder, GRefPtr<GByteArray>& byteArray)
+    static Optional<GRefPtr<GByteArray>> decode(Decoder& decoder)
     {
-        uint32_t size;
-        if (!decoder.decode(size))
-            return false;
-
-        byteArray = adoptGRef(g_byte_array_sized_new(size));
-        g_byte_array_set_size(byteArray.get(), size);
-        return decoder.decodeFixedLengthData(byteArray->data, size);
+        Optional<uint32_t> size;
+        decoder >> size;
+        if (!size)
+            return WTF::nullopt;
+
+        GRefPtr<GByteArray> byteArray = adoptGRef(g_byte_array_sized_new(*size));
+        g_byte_array_set_size(byteArray.get(), *size);
+        if (!decoder.decodeFixedLengthData(byteArray->data, *size))
+            return WTF::nullopt;
+        return byteArray;
     }
 };
 
@@ -139,25 +142,29 @@ template<> struct Coder<WebCore::CertificateInfo> {
         encoder << static_cast<uint32_t>(certificateInfo.tlsErrors());
     }
 
-    static bool decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
+    static Optional<WebCore::CertificateInfo> decode(Decoder& decoder)
     {
-        Vector<GRefPtr<GByteArray>> certificatesDataList;
-        if (!decoder.decode(certificatesDataList))
-            return false;
+        Optional<Vector<GRefPtr<GByteArray>>> certificatesDataList;
+        decoder >> certificatesDataList;
+        if (!certificatesDataList)
+            return WTF::nullopt;
 
-        if (certificatesDataList.isEmpty())
-            return true;
-        auto certificate = certificateFromCertificatesDataList(certificatesDataList);
+        WebCore::CertificateInfo certificateInfo;
+        if (certificatesDataList->isEmpty())
+            return certificateInfo;
+
+        auto certificate = certificateFromCertificatesDataList(certificatesDataList.value());
         if (!certificate)
-            return false;
+            return WTF::nullopt;
         certificateInfo.setCertificate(certificate.get());
 
-        uint32_t tlsErrors;
-        if (!decoder.decode(tlsErrors))
-            return false;
-        certificateInfo.setTLSErrors(static_cast<GTlsCertificateFlags>(tlsErrors));
+        Optional<uint32_t> tlsErrors;
+        decoder >> tlsErrors;
+        if (!tlsErrors)
+            return WTF::nullopt;
+        certificateInfo.setTLSErrors(static_cast<GTlsCertificateFlags>(*tlsErrors));
 
-        return true;
+        return certificateInfo;
     }
 };
 
index 9e206bb..30e5b44 100644 (file)
@@ -92,7 +92,7 @@ template<class Encoder>
 void ResourceResponse::encode(Encoder& encoder) const
 {
     ResourceResponseBase::encode(encoder);
-    encoder.encodeEnum(m_soupFlags);
+    encoder << static_cast<uint64_t>(m_soupFlags);
 }
 
 template<class Decoder>
@@ -100,8 +100,12 @@ bool ResourceResponse::decode(Decoder& decoder, ResourceResponse& response)
 {
     if (!ResourceResponseBase::decode(decoder, response))
         return false;
-    if (!decoder.decodeEnum(response.m_soupFlags))
+    Optional<uint64_t> soupFlags;
+    decoder >> soupFlags;
+    if (!soupFlags)
         return false;
+    // FIXME: Verify that this is a valid value for SoupMessageFlags.
+    response.m_soupFlags = static_cast<SoupMessageFlags>(*soupFlags);
     return true;
 }
 
index ca0a78c..7faf131 100644 (file)
@@ -51,20 +51,28 @@ struct ServiceWorkerContextData {
             encoder << script << responseURL << mimeType;
         }
 
-        template<class Decoder> static bool decode(Decoder& decoder, ImportedScript& script)
+        template<class Decoder> static Optional<ImportedScript> decode(Decoder& decoder)
         {
-            ImportedScript importedScript;
-            if (!decoder.decode(importedScript.script))
-                return false;
-
-            if (!decoder.decode(importedScript.responseURL))
-                return false;
-
-            if (!decoder.decode(importedScript.mimeType))
-                return false;
-
-            script = WTFMove(importedScript);
-            return true;
+            Optional<String> script;
+            decoder >> script;
+            if (!script)
+                return WTF::nullopt;
+            
+            Optional<URL> responseURL;
+            decoder >> responseURL;
+            if (!responseURL)
+                return WTF::nullopt;
+            
+            Optional<String> mimeType;
+            decoder >> mimeType;
+            if (!mimeType)
+                return WTF::nullopt;
+            
+            return {{
+                WTFMove(*script),
+                WTFMove(*responseURL),
+                WTFMove(*mimeType)
+            }};
         }
     };
 
index 2cf5a48..dcbb28a 100644 (file)
@@ -342,7 +342,7 @@ void RegistrationDatabase::doPushChanges(const Vector<ServiceWorkerContextData>&
         data.contentSecurityPolicy.encode(cspEncoder);
 
         WTF::Persistence::Encoder scriptResourceMapEncoder;
-        scriptResourceMapEncoder.encode(data.scriptResourceMap);
+        scriptResourceMapEncoder << data.scriptResourceMap;
 
         if (sql.bindText(1, data.registration.key.toDatabaseKey()) != SQLITE_OK
             || sql.bindText(2, data.registration.scopeURL.protocolHostAndPort()) != SQLITE_OK
@@ -392,19 +392,23 @@ String RegistrationDatabase::importRecords()
         Vector<uint8_t> contentSecurityPolicyData;
         sql.getColumnBlobAsVector(9, contentSecurityPolicyData);
         WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyData.data(), contentSecurityPolicyData.size());
-        ContentSecurityPolicyResponseHeaders contentSecurityPolicy;
-        if (contentSecurityPolicyData.size() && !ContentSecurityPolicyResponseHeaders::decode(cspDecoder, contentSecurityPolicy))
-            continue;
+        Optional<ContentSecurityPolicyResponseHeaders> contentSecurityPolicy;
+        if (contentSecurityPolicyData.size()) {
+            cspDecoder >> contentSecurityPolicy;
+            if (!contentSecurityPolicy)
+                continue;
+        }
 
         auto referrerPolicy = sql.getColumnText(10);
 
         Vector<uint8_t> scriptResourceMapData;
         sql.getColumnBlobAsVector(11, scriptResourceMapData);
-        HashMap<URL, ServiceWorkerContextData::ImportedScript> scriptResourceMap;
+        Optional<HashMap<URL, ServiceWorkerContextData::ImportedScript>> scriptResourceMap;
 
         WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapData.data(), scriptResourceMapData.size());
         if (scriptResourceMapData.size()) {
-            if (!scriptResourceMapDecoder.decode(scriptResourceMap))
+            scriptResourceMapDecoder >> scriptResourceMap;
+            if (!scriptResourceMap)
                 continue;
         }
 
@@ -418,7 +422,7 @@ String RegistrationDatabase::importRecords()
         auto registrationIdentifier = ServiceWorkerRegistrationIdentifier::generate();
         auto serviceWorkerData = ServiceWorkerData { workerIdentifier, scriptURL, ServiceWorkerState::Activated, *workerType, registrationIdentifier };
         auto registration = ServiceWorkerRegistrationData { WTFMove(*key), registrationIdentifier, WTFMove(scopeURL), *updateViaCache, lastUpdateCheckTime, WTF::nullopt, WTF::nullopt, WTFMove(serviceWorkerData) };
-        auto contextData = ServiceWorkerContextData { WTF::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(referrerPolicy), WTFMove(scriptURL), *workerType, true, WTFMove(scriptResourceMap) };
+        auto contextData = ServiceWorkerContextData { WTF::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(*contentSecurityPolicy), WTFMove(referrerPolicy), WTFMove(scriptURL), *workerType, true, WTFMove(*scriptResourceMap) };
 
         callOnMainThread([protectedThis = makeRef(*this), contextData = contextData.isolatedCopy()]() mutable {
             protectedThis->addRegistrationToStore(WTFMove(contextData));
index 6f8516b..2f93f9f 100644 (file)
@@ -1,3 +1,35 @@
+2020-04-10  Alex Christensen  <achristensen@webkit.org>
+
+        PersistentCoders should use modern decoding syntax
+        https://bugs.webkit.org/show_bug.cgi?id=207497
+
+        Reviewed by Darin Adler.
+
+        * NetworkProcess/cache/CacheStorageEngineCache.cpp:
+        (WebKit::CacheStorage::decodeDOMCacheRecord):
+        (WebKit::CacheStorage::Cache::decodeRecordHeader):
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::Caches::readOrigin):
+        (WebKit::CacheStorage::decodeCachesNames):
+        * NetworkProcess/cache/NetworkCacheCoders.cpp:
+        (WTF::Persistence::Coder<WebCore::HTTPHeaderMap>::decode):
+        * NetworkProcess/cache/NetworkCacheEntry.cpp:
+        (WebKit::NetworkCache::Entry::decodeStorageRecord):
+        * NetworkProcess/cache/NetworkCacheKey.cpp:
+        (WebKit::NetworkCache::Key::decode):
+        * NetworkProcess/cache/NetworkCacheKey.h:
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::decodeRecordMetaData):
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
+        (WebKit::NetworkCache::SubresourceInfo::encode const):
+        (WebKit::NetworkCache::SubresourceInfo::decode):
+        (WebKit::NetworkCache::SubresourcesEntry::decodeStorageRecord):
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
+        * Shared/UserData.cpp:
+        (WebKit::UserData::decode):
+        * UIProcess/API/APIContentRuleListStore.cpp:
+        (API::decodeContentRuleListMetaData):
+
 2020-04-10  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: add `broadcastConsoleMessage` calls for new ITPDebug logs after r259275
index 5d43505..6a53d9f 100644 (file)
@@ -572,45 +572,80 @@ Storage::Record Cache::encode(const RecordInformation& recordInformation, const
     return { recordInformation.key, { }, header, body, { } };
 }
 
-Optional<Cache::DecodedRecord> Cache::decodeRecordHeader(const Storage::Record& storage)
+static Optional<WebCore::DOMCacheEngine::Record> decodeDOMCacheRecord(WTF::Persistence::Decoder& decoder)
 {
-    WTF::Persistence::Decoder decoder(storage.header.data(), storage.header.size());
-
-    Record record;
-
-    double insertionTime;
-    if (!decoder.decode(insertionTime))
+    Optional<FetchHeaders::Guard> requestHeadersGuard;
+    decoder >> requestHeadersGuard;
+    if (!requestHeadersGuard)
         return WTF::nullopt;
-
-    uint64_t size;
-    if (!decoder.decode(size))
+    
+    ResourceRequest request;
+    if (!request.decodeWithoutPlatformData(decoder))
         return WTF::nullopt;
-
-    if (!decoder.decode(record.requestHeadersGuard))
+    
+    FetchOptions options;
+    if (!FetchOptions::decodePersistent(decoder, options))
         return WTF::nullopt;
-
-    if (!record.request.decodeWithoutPlatformData(decoder))
+    
+    Optional<String> referrer;
+    decoder >> referrer;
+    if (!referrer)
         return WTF::nullopt;
-
-    if (!FetchOptions::decodePersistent(decoder, record.options))
+    
+    Optional<FetchHeaders::Guard> responseHeadersGuard;
+    decoder >> responseHeadersGuard;
+    if (!responseHeadersGuard)
         return WTF::nullopt;
 
-    if (!decoder.decode(record.referrer))
+    ResourceResponse response;
+    if (!ResourceResponse::decode(decoder, response))
+        return WTF::nullopt;
+    
+    Optional<uint64_t> responseBodySize;
+    decoder >> responseBodySize;
+    if (!responseBodySize)
         return WTF::nullopt;
 
-    if (!decoder.decode(record.responseHeadersGuard))
+    if (!decoder.verifyChecksum())
         return WTF::nullopt;
 
-    if (!decoder.decode(record.response))
+    return {{
+        0,
+        0,
+        WTFMove(*requestHeadersGuard),
+        WTFMove(request),
+        WTFMove(options),
+        WTFMove(*referrer),
+        WTFMove(*responseHeadersGuard),
+        WTFMove(response),
+        { },
+        WTFMove(*responseBodySize)
+    }};
+}
+
+Optional<Cache::DecodedRecord> Cache::decodeRecordHeader(const Storage::Record& storage)
+{
+    WTF::Persistence::Decoder decoder(storage.header.data(), storage.header.size());
+
+    Optional<double> insertionTime;
+    decoder >> insertionTime;
+    if (!insertionTime)
         return WTF::nullopt;
 
-    if (!decoder.decode(record.responseBodySize))
+    Optional<uint64_t> size;
+    decoder >> size;
+    if (!size)
         return WTF::nullopt;
 
-    if (!decoder.verifyChecksum())
+    Optional<WebCore::DOMCacheEngine::Record> record = decodeDOMCacheRecord(decoder);
+    if (!record)
         return WTF::nullopt;
 
-    return DecodedRecord { insertionTime, size, WTFMove(record) };
+    return {{
+        WTFMove(*insertionTime),
+        WTFMove(*size),
+        WTFMove(*record)
+    }};
 }
 
 Optional<Record> Cache::decode(const Storage::Record& storage)
index aadfa35..0b09b80 100644 (file)
@@ -112,23 +112,22 @@ void Caches::storeOrigin(CompletionCallback&& completionHandler)
 
 Optional<WebCore::ClientOrigin> Caches::readOrigin(const Data& data)
 {
-    // FIXME: We should be able to use modern decoders for persistent data.
-    WebCore::SecurityOriginData topOrigin, clientOrigin;
     WTF::Persistence::Decoder decoder(data.data(), data.size());
 
-    if (!decoder.decode(topOrigin.protocol))
+    Optional<WebCore::SecurityOriginData> topOrigin;
+    decoder >> topOrigin;
+    if (!topOrigin)
         return WTF::nullopt;
-    if (!decoder.decode(topOrigin.host))
-        return WTF::nullopt;
-    if (!decoder.decode(topOrigin.port))
-        return WTF::nullopt;
-    if (!decoder.decode(clientOrigin.protocol))
-        return WTF::nullopt;
-    if (!decoder.decode(clientOrigin.host))
-        return WTF::nullopt;
-    if (!decoder.decode(clientOrigin.port))
+
+    Optional<WebCore::SecurityOriginData> clientOrigin;
+    decoder >> clientOrigin;
+    if (!clientOrigin)
         return WTF::nullopt;
-    return WebCore::ClientOrigin { WTFMove(topOrigin), WTFMove(clientOrigin) };
+
+    return {{
+        WTFMove(*topOrigin),
+        WTFMove(*clientOrigin)
+    }};
 }
 
 void Caches::initialize(WebCore::DOMCacheEngine::CompletionCallback&& callback)
@@ -411,23 +410,26 @@ static inline Data encodeCacheNames(const Vector<Cache>& caches)
 static inline Expected<Vector<std::pair<String, String>>, Error> decodeCachesNames(const Data& data)
 {
     WTF::Persistence::Decoder decoder(data.data(), data.size());
-    uint64_t count;
-    if (!decoder.decode(count))
+    Optional<uint64_t> count;
+    decoder >> count;
+    if (!count)
         return makeUnexpected(Error::ReadDisk);
 
     Vector<std::pair<String, String>> names;
-    if (!names.tryReserveCapacity(count))
+    if (!names.tryReserveCapacity(*count))
         return makeUnexpected(Error::ReadDisk);
 
-    for (size_t index = 0; index < count; ++index) {
-        String name;
-        if (!decoder.decode(name))
+    for (size_t index = 0; index < *count; ++index) {
+        Optional<String> name;
+        decoder >> name;
+        if (!name)
             return makeUnexpected(Error::ReadDisk);
-        String uniqueName;
-        if (!decoder.decode(uniqueName))
+        Optional<String> uniqueName;
+        decoder >> uniqueName;
+        if (!uniqueName)
             return makeUnexpected(Error::ReadDisk);
 
-        names.uncheckedAppend(std::pair<String, String> { WTFMove(name), WTFMove(uniqueName) });
+        names.uncheckedAppend({ WTFMove(*name), WTFMove(*uniqueName) });
     }
     return names;
 }
index f35deb4..c962722 100644 (file)
@@ -40,21 +40,26 @@ void Coder<WebCore::HTTPHeaderMap>::encode(Encoder& encoder, const WebCore::HTTP
     }
 }
 
-bool Coder<WebCore::HTTPHeaderMap>::decode(Decoder& decoder, WebCore::HTTPHeaderMap& headers)
+Optional<WebCore::HTTPHeaderMap> Coder<WebCore::HTTPHeaderMap>::decode(Decoder& decoder)
 {
-    uint64_t headersSize;
-    if (!decoder.decode(headersSize))
-        return false;
-    for (uint64_t i = 0; i < headersSize; ++i) {
-        String name;
-        if (!decoder.decode(name))
-            return false;
-        String value;
-        if (!decoder.decode(value))
-            return false;
-        headers.append(name, value);
+    Optional<uint64_t> headersSize;
+    decoder >> headersSize;
+    if (!headersSize)
+        return WTF::nullopt;
+
+    WebCore::HTTPHeaderMap headers;
+    for (uint64_t i = 0; i < *headersSize; ++i) {
+        Optional<String> name;
+        decoder >> name;
+        if (!name)
+            return WTF::nullopt;
+        Optional<String> value;
+        decoder >> value;
+        if (!value)
+            return WTF::nullopt;
+        headers.append(WTFMove(*name), WTFMove(*value));
     }
-    return true;
+    return WTFMove(headers);
 }
 
 }
index 1298ab6..005b153 100644 (file)
@@ -36,7 +36,7 @@ namespace Persistence {
 
 template<> struct Coder<WebCore::HTTPHeaderMap> {
     static void encode(Encoder&, const WebCore::HTTPHeaderMap&);
-    static bool decode(Decoder&, WebCore::HTTPHeaderMap&);
+    static Optional<WebCore::HTTPHeaderMap> decode(Decoder&);
 };
 
 }
index 0b8ae24..28566a5 100644 (file)
@@ -112,31 +112,41 @@ std::unique_ptr<Entry> Entry::decodeStorageRecord(const Storage::Record& storage
     auto entry = makeUnique<Entry>(storageEntry);
 
     WTF::Persistence::Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
-    if (!decoder.decode(entry->m_response))
+    WebCore::ResourceResponse response;
+    if (!WebCore::ResourceResponse::decode(decoder, response))
         return nullptr;
+    entry->m_response = WTFMove(response);
     entry->m_response.setSource(WebCore::ResourceResponse::Source::DiskCache);
 
-    bool hasVaryingRequestHeaders;
-    if (!decoder.decode(hasVaryingRequestHeaders))
+    Optional<bool> hasVaryingRequestHeaders;
+    decoder >> hasVaryingRequestHeaders;
+    if (!hasVaryingRequestHeaders)
         return nullptr;
 
-    if (hasVaryingRequestHeaders) {
-        if (!decoder.decode(entry->m_varyingRequestHeaders))
+    if (*hasVaryingRequestHeaders) {
+        Optional<Vector<std::pair<String, String>>> varyingRequestHeaders;
+        decoder >> varyingRequestHeaders;
+        if (!varyingRequestHeaders)
             return nullptr;
+        entry->m_varyingRequestHeaders = WTFMove(*varyingRequestHeaders);
     }
 
-    bool isRedirect;
-    if (!decoder.decode(isRedirect))
+    Optional<bool> isRedirect;
+    decoder >> isRedirect;
+    if (!isRedirect)
         return nullptr;
 
-    if (isRedirect) {
+    if (*isRedirect) {
         entry->m_redirectRequest.emplace();
         if (!entry->m_redirectRequest->decodeWithoutPlatformData(decoder))
             return nullptr;
     }
 
-    if (!decoder.decode(entry->m_maxAgeCap))
+    Optional<Optional<Seconds>> maxAgeCap;
+    decoder >> maxAgeCap;
+    if (!maxAgeCap)
         return nullptr;
+    entry->m_maxAgeCap = WTFMove(*maxAgeCap);
 
     if (!decoder.verifyChecksum()) {
         LOG(NetworkCache, "(NetworkProcess) checksum verification failure\n");
index 8fa81d1..2265ae1 100644 (file)
@@ -173,9 +173,47 @@ void Key::encode(WTF::Persistence::Encoder& encoder) const
     encoder << m_partitionHash;
 }
 
-bool Key::decode(WTF::Persistence::Decoder& decoder, Key& key)
+Optional<Key> Key::decode(WTF::Persistence::Decoder& decoder)
 {
-    return decoder.decode(key.m_partition) && decoder.decode(key.m_type) && decoder.decode(key.m_identifier) && decoder.decode(key.m_range) && decoder.decode(key.m_hash) && decoder.decode(key.m_partitionHash);
+    Key key;
+    
+    Optional<String> partition;
+    decoder >> partition;
+    if (!partition)
+        return WTF::nullopt;
+    key.m_partition = WTFMove(*partition);
+
+    Optional<String> type;
+    decoder >> type;
+    if (!type)
+        return WTF::nullopt;
+    key.m_type = WTFMove(*type);
+
+    Optional<String> identifier;
+    decoder >> identifier;
+    if (!identifier)
+        return WTF::nullopt;
+    key.m_identifier = WTFMove(*identifier);
+
+    Optional<String> range;
+    decoder >> range;
+    if (!range)
+        return WTF::nullopt;
+    key.m_range = WTFMove(*range);
+
+    Optional<HashType> hash;
+    decoder >> hash;
+    if (!hash)
+        return WTF::nullopt;
+    key.m_hash = WTFMove(*hash);
+
+    Optional<HashType> partitionHash;
+    decoder >> partitionHash;
+    if (!partitionHash)
+        return WTF::nullopt;
+    key.m_partitionHash = WTFMove(*partitionHash);
+
+    return { WTFMove(key) };
 }
 
 }
index 2915b21..e64fd30 100644 (file)
@@ -83,7 +83,7 @@ public:
     String partitionHashAsString() const { return hashAsString(m_partitionHash); }
 
     void encode(WTF::Persistence::Encoder&) const;
-    static bool decode(WTF::Persistence::Decoder&, Key&);
+    static Optional<Key> decode(WTF::Persistence::Decoder&);
 
     bool operator==(const Key&) const;
     bool operator!=(const Key& other) const { return !(*this == other); }
index cb977f8..9a8feec 100644 (file)
@@ -438,24 +438,58 @@ static bool decodeRecordMetaData(RecordMetaData& metaData, const Data& fileData)
     bool success = false;
     fileData.apply([&metaData, &success](const uint8_t* data, size_t size) {
         WTF::Persistence::Decoder decoder(data, size);
-        if (!decoder.decode(metaData.cacheStorageVersion))
+        
+        Optional<unsigned> cacheStorageVersion;
+        decoder >> cacheStorageVersion;
+        if (!cacheStorageVersion)
             return false;
-        if (!decoder.decode(metaData.key))
+        metaData.cacheStorageVersion = WTFMove(*cacheStorageVersion);
+
+        Optional<Key> key;
+        decoder >> key;
+        if (!key)
             return false;
-        if (!decoder.decode(metaData.timeStamp))
+        metaData.key = WTFMove(*key);
+
+        Optional<WallTime> timeStamp;
+        decoder >> timeStamp;
+        if (!timeStamp)
             return false;
-        if (!decoder.decode(metaData.headerHash))
+        metaData.timeStamp = WTFMove(*timeStamp);
+
+        Optional<SHA1::Digest> headerHash;
+        decoder >> headerHash;
+        if (!headerHash)
             return false;
-        if (!decoder.decode(metaData.headerSize))
+        metaData.headerHash = WTFMove(*headerHash);
+
+        Optional<uint64_t> headerSize;
+        decoder >> headerSize;
+        if (!headerSize)
             return false;
-        if (!decoder.decode(metaData.bodyHash))
+        metaData.headerSize = WTFMove(*headerSize);
+
+        Optional<SHA1::Digest> bodyHash;
+        decoder >> bodyHash;
+        if (!bodyHash)
             return false;
-        if (!decoder.decode(metaData.bodySize))
+        metaData.bodyHash = WTFMove(*bodyHash);
+
+        Optional<uint64_t> bodySize;
+        decoder >> bodySize;
+        if (!bodySize)
             return false;
-        if (!decoder.decode(metaData.isBodyInline))
+        metaData.bodySize = WTFMove(*bodySize);
+
+        Optional<bool> isBodyInline;
+        decoder >> isBodyInline;
+        if (!isBodyInline)
             return false;
+        metaData.isBodyInline = WTFMove(*isBodyInline);
+
         if (!decoder.verifyChecksum())
             return false;
+
         metaData.headerOffset = decoder.currentOffset();
         success = true;
         return false;
index 3a02de5..fbc5d02 100644 (file)
@@ -49,37 +49,65 @@ void SubresourceInfo::encode(WTF::Persistence::Encoder& encoder) const
     encoder << m_isSameSite;
     encoder << m_firstPartyForCookies;
     encoder << m_requestHeaders;
-    encoder.encodeEnum(m_priority);
+    encoder << m_priority;
 }
 
-bool SubresourceInfo::decode(WTF::Persistence::Decoder& decoder, SubresourceInfo& info)
+Optional<SubresourceInfo> SubresourceInfo::decode(WTF::Persistence::Decoder& decoder)
 {
-    if (!decoder.decode(info.m_key))
-        return false;
-    if (!decoder.decode(info.m_lastSeen))
-        return false;
-    if (!decoder.decode(info.m_firstSeen))
-        return false;
-    
-    if (!decoder.decode(info.m_isTransient))
-        return false;
-    
-    if (info.m_isTransient)
-        return true;
-
-    if (!decoder.decode(info.m_isSameSite))
-        return false;
+    SubresourceInfo info;
+
+    Optional<Key> key;
+    decoder >> key;
+    if (!key)
+        return WTF::nullopt;
+    info.m_key = WTFMove(*key);
+
+    Optional<WallTime> lastSeen;
+    decoder >> lastSeen;
+    if (!lastSeen)
+        return WTF::nullopt;
+    info.m_lastSeen = WTFMove(*lastSeen);
+
+    Optional<WallTime> firstSeen;
+    decoder >> firstSeen;
+    if (!firstSeen)
+        return WTF::nullopt;
+    info.m_firstSeen = WTFMove(*firstSeen);
+
+    Optional<bool> isTransient;
+    decoder >> isTransient;
+    if (!isTransient)
+        return WTF::nullopt;
+    info.m_isTransient = WTFMove(*isTransient);
 
-    if (!decoder.decode(info.m_firstPartyForCookies))
-        return false;
-
-    if (!decoder.decode(info.m_requestHeaders))
-        return false;
-
-    if (!decoder.decodeEnum(info.m_priority))
-        return false;
+    if (info.m_isTransient)
+        return { WTFMove(info) };
+
+    Optional<bool> isSameSite;
+    decoder >> isSameSite;
+    if (!isSameSite)
+        return WTF::nullopt;
+    info.m_isSameSite = WTFMove(*isSameSite);
+
+    Optional<URL> firstPartyForCookies;
+    decoder >> firstPartyForCookies;
+    if (!firstPartyForCookies)
+        return WTF::nullopt;
+    info.m_firstPartyForCookies = WTFMove(*firstPartyForCookies);
+
+    Optional<WebCore::HTTPHeaderMap> requestHeaders;
+    decoder >> requestHeaders;
+    if (!requestHeaders)
+        return WTF::nullopt;
+    info.m_requestHeaders = WTFMove(*requestHeaders);
+
+    Optional<WebCore::ResourceLoadPriority> priority;
+    decoder >> priority;
+    if (!priority)
+        return WTF::nullopt;
+    info.m_priority = WTFMove(*priority);
     
-    return true;
+    return { WTFMove(info) };
 }
 
 bool SubresourceInfo::isFirstParty() const
@@ -103,8 +131,11 @@ std::unique_ptr<SubresourcesEntry> SubresourcesEntry::decodeStorageRecord(const
     auto entry = makeUnique<SubresourcesEntry>(storageEntry);
 
     WTF::Persistence::Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
-    if (!decoder.decode(entry->m_subresources))
+    Optional<Vector<SubresourceInfo>> subresources;
+    decoder >> subresources;
+    if (!subresources)
         return nullptr;
+    entry->m_subresources = WTFMove(*subresources);
 
     if (!decoder.verifyChecksum()) {
         LOG(NetworkCache, "(NetworkProcess) checksum verification failure\n");
index 6fe9530..d449504 100644 (file)
@@ -39,7 +39,7 @@ class SubresourceInfo {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     void encode(WTF::Persistence::Encoder&) const;
-    static bool decode(WTF::Persistence::Decoder&, SubresourceInfo&);
+    static Optional<SubresourceInfo> decode(WTF::Persistence::Decoder&);
 
     SubresourceInfo() = default;
     SubresourceInfo(const Key&, const WebCore::ResourceRequest&, const SubresourceInfo* previousInfo);
index e7a3731..bdc7f0c 100644 (file)
@@ -369,10 +369,11 @@ bool UserData::decode(IPC::Decoder& decoder, RefPtr<API::Object>& result)
         break;
 
     case API::Object::Type::CertificateInfo: {
-        WebCore::CertificateInfo certificateInfo;
-        if (!decoder.decode(certificateInfo))
+        Optional<WebCore::CertificateInfo> certificateInfo;
+        decoder >> certificateInfo;
+        if (!certificateInfo)
             return false;
-        result = WebCertificateInfo::create(certificateInfo);
+        result = WebCertificateInfo::create(*certificateInfo);
         break;
     }
 
index d409da9..f444b34 100644 (file)
@@ -179,20 +179,49 @@ static Optional<ContentRuleListMetaData> decodeContentRuleListMetaData(const T&
             return false;
 
         WTF::Persistence::Decoder decoder(data, size);
-        if (!decoder.decode(metaData.version))
+        
+        Optional<uint32_t> version;
+        decoder >> version;
+        if (!version)
             return false;
-        if (!decoder.decode(metaData.sourceSize))
+        metaData.version = WTFMove(*version);
+
+        Optional<uint64_t> sourceSize;
+        decoder >> sourceSize;
+        if (!sourceSize)
             return false;
-        if (!decoder.decode(metaData.actionsSize))
+        metaData.sourceSize = WTFMove(*sourceSize);
+
+        Optional<uint64_t> actionsSize;
+        decoder >> actionsSize;
+        if (!actionsSize)
             return false;
-        if (!decoder.decode(metaData.filtersWithoutConditionsBytecodeSize))
+        metaData.actionsSize = WTFMove(*actionsSize);
+
+        Optional<uint64_t> filtersWithoutConditionsBytecodeSize;
+        decoder >> filtersWithoutConditionsBytecodeSize;
+        if (!filtersWithoutConditionsBytecodeSize)
             return false;
-        if (!decoder.decode(metaData.filtersWithConditionsBytecodeSize))
+        metaData.filtersWithoutConditionsBytecodeSize = WTFMove(*filtersWithoutConditionsBytecodeSize);
+
+        Optional<uint64_t> filtersWithConditionsBytecodeSize;
+        decoder >> filtersWithConditionsBytecodeSize;
+        if (!filtersWithConditionsBytecodeSize)
             return false;
-        if (!decoder.decode(metaData.conditionedFiltersBytecodeSize))
+        metaData.filtersWithConditionsBytecodeSize = WTFMove(*filtersWithConditionsBytecodeSize);
+
+        Optional<uint64_t> conditionedFiltersBytecodeSize;
+        decoder >> conditionedFiltersBytecodeSize;
+        if (!conditionedFiltersBytecodeSize)
             return false;
-        if (!decoder.decode(metaData.conditionsApplyOnlyToDomain))
+        metaData.conditionedFiltersBytecodeSize = WTFMove(*conditionedFiltersBytecodeSize);
+
+        Optional<uint32_t> conditionsApplyOnlyToDomain;
+        decoder >> conditionsApplyOnlyToDomain;
+        if (!conditionsApplyOnlyToDomain)
             return false;
+        metaData.conditionsApplyOnlyToDomain = WTFMove(*conditionsApplyOnlyToDomain);
+
         success = true;
         return false;
     });