[Cache API] Enable persistent coder to encode FetchOptions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Aug 2017 17:54:03 +0000 (17:54 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Aug 2017 17:54:03 +0000 (17:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175883

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-23
Reviewed by Alex Christensen.

Source/WebCore:

No change of behavior.
Adding encode/decode routines for FetchOptions.

* loader/FetchOptions.h:
(WebCore::FetchOptions::encode const):
(WebCore::FetchOptions::decode):
* platform/ReferrerPolicy.h:

Source/WebKit:

Removing FetchOptions related ArgumentCoders specific code.

* Shared/WebCoreArgumentCoders.cpp:
* Shared/WebCoreArgumentCoders.h:

Source/WTF:

Enabling encoding/decoding of enums with EnumTraits.
This code is similar to the one of IPC encoder/decoder.

* wtf/persistence/PersistentDecoder.h:
(WTF::Persistence::Decoder::decode):
* wtf/persistence/PersistentEncoder.h:
(WTF::Persistence::Encoder::encode):

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

Source/WTF/ChangeLog
Source/WTF/wtf/persistence/PersistentDecoder.h
Source/WTF/wtf/persistence/PersistentEncoder.h
Source/WebCore/ChangeLog
Source/WebCore/loader/FetchOptions.h
Source/WebCore/platform/ReferrerPolicy.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h

index 349615c..1987822 100644 (file)
@@ -1,3 +1,18 @@
+2017-08-23  Youenn Fablet  <youenn@apple.com>
+
+        [Cache API] Enable persistent coder to encode FetchOptions
+        https://bugs.webkit.org/show_bug.cgi?id=175883
+
+        Reviewed by Alex Christensen.
+
+        Enabling encoding/decoding of enums with EnumTraits.
+        This code is similar to the one of IPC encoder/decoder.
+
+        * wtf/persistence/PersistentDecoder.h:
+        (WTF::Persistence::Decoder::decode):
+        * wtf/persistence/PersistentEncoder.h:
+        (WTF::Persistence::Encoder::encode):
+
 2017-08-23  Per Arne Vollan  <pvollan@apple.com>
 
         [Win] Compile error, include file <wtf/AVFoundationHeaderDetection.h> is not found.
index 91073ef..a20907b 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <wtf/EnumTraits.h>
 #include <wtf/SHA1.h>
 #include <wtf/persistence/PersistentCoder.h>
 
@@ -54,6 +55,18 @@ public:
     WTF_EXPORT_PRIVATE bool decode(float&);
     WTF_EXPORT_PRIVATE bool decode(double&);
 
+    template<typename E> auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool>
+    {
+        uint64_t value;
+        if (!decode(value))
+            return false;
+        if (!isValidEnum<E>(value))
+            return false;
+
+        e = static_cast<E>(value);
+        return true;
+    }
+
     template<typename T> bool decodeEnum(T& result)
     {
         static_assert(sizeof(T) <= 8, "Enum type T must not be larger than 64 bits!");
@@ -66,7 +79,7 @@ public:
         return true;
     }
 
-    template<typename T> bool decode(T& t)
+    template<typename T> auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>
     {
         return Coder<T>::decode(*this, t);
     }
index d4fc0e1..bacfac8 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <wtf/EnumTraits.h>
 #include <wtf/SHA1.h>
 #include <wtf/Vector.h>
 #include <wtf/persistence/PersistentCoder.h>
@@ -44,6 +45,14 @@ 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>
+    {
+        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);
@@ -51,7 +60,7 @@ public:
         encode(static_cast<uint64_t>(t));
     }
 
-    template<typename T> void encode(const T& t)
+    template<typename T> auto encode(const T& t) -> std::enable_if_t<!std::is_enum<T>::value>
     {
         Coder<T>::encode(*this, t);
     }
index e1d851a..233a6ac 100644 (file)
@@ -1,3 +1,18 @@
+2017-08-23  Youenn Fablet  <youenn@apple.com>
+
+        [Cache API] Enable persistent coder to encode FetchOptions
+        https://bugs.webkit.org/show_bug.cgi?id=175883
+
+        Reviewed by Alex Christensen.
+
+        No change of behavior.
+        Adding encode/decode routines for FetchOptions.
+
+        * loader/FetchOptions.h:
+        (WebCore::FetchOptions::encode const):
+        (WebCore::FetchOptions::decode):
+        * platform/ReferrerPolicy.h:
+
 2017-08-23  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Race condition in StartWebThread causing crash
index b173723..463f098 100644 (file)
@@ -45,6 +45,9 @@ struct FetchOptions {
     FetchOptions(Type, Destination, Mode, Credentials, Cache, Redirect, ReferrerPolicy, String&&, bool);
     FetchOptions isolatedCopy() const { return { type, destination, mode, credentials, cache, redirect, referrerPolicy, integrity.isolatedCopy(), keepAlive }; }
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static bool decode(Decoder&, FetchOptions&);
+
     Type type { Type::EmptyString };
     Destination destination { Destination::EmptyString };
     Mode mode { Mode::NoCors };
@@ -69,4 +72,142 @@ inline FetchOptions::FetchOptions(Type type, Destination destination, Mode mode,
 {
 }
 
+}
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::FetchOptions::Type> {
+    using values = EnumValues<
+        WebCore::FetchOptions::Type,
+        WebCore::FetchOptions::Type::EmptyString,
+        WebCore::FetchOptions::Type::Audio,
+        WebCore::FetchOptions::Type::Font,
+        WebCore::FetchOptions::Type::Image,
+        WebCore::FetchOptions::Type::Script,
+        WebCore::FetchOptions::Type::Style,
+        WebCore::FetchOptions::Type::Track,
+        WebCore::FetchOptions::Type::Video
+    >;
+};
+
+template<> struct EnumTraits<WebCore::FetchOptions::Destination> {
+    using values = EnumValues<
+        WebCore::FetchOptions::Destination,
+        WebCore::FetchOptions::Destination::EmptyString,
+        WebCore::FetchOptions::Destination::Document,
+        WebCore::FetchOptions::Destination::Sharedworker,
+        WebCore::FetchOptions::Destination::Subresource,
+        WebCore::FetchOptions::Destination::Unknown,
+        WebCore::FetchOptions::Destination::Worker
+    >;
+};
+
+template<> struct EnumTraits<WebCore::FetchOptions::Mode> {
+    using values = EnumValues<
+        WebCore::FetchOptions::Mode,
+        WebCore::FetchOptions::Mode::Navigate,
+        WebCore::FetchOptions::Mode::SameOrigin,
+        WebCore::FetchOptions::Mode::NoCors,
+        WebCore::FetchOptions::Mode::Cors
+    >;
+};
+
+template<> struct EnumTraits<WebCore::FetchOptions::Credentials> {
+    using values = EnumValues<
+        WebCore::FetchOptions::Credentials,
+        WebCore::FetchOptions::Credentials::Omit,
+        WebCore::FetchOptions::Credentials::SameOrigin,
+        WebCore::FetchOptions::Credentials::Include
+    >;
+};
+
+template<> struct EnumTraits<WebCore::FetchOptions::Cache> {
+    using values = EnumValues<
+        WebCore::FetchOptions::Cache,
+        WebCore::FetchOptions::Cache::Default,
+        WebCore::FetchOptions::Cache::NoStore,
+        WebCore::FetchOptions::Cache::Reload,
+        WebCore::FetchOptions::Cache::NoCache,
+        WebCore::FetchOptions::Cache::ForceCache,
+        WebCore::FetchOptions::Cache::OnlyIfCached
+    >;
+};
+
+template<> struct EnumTraits<WebCore::FetchOptions::Redirect> {
+    using values = EnumValues<
+        WebCore::FetchOptions::Redirect,
+        WebCore::FetchOptions::Redirect::Follow,
+        WebCore::FetchOptions::Redirect::Error,
+        WebCore::FetchOptions::Redirect::Manual
+    >;
+};
+
+}
+
+namespace WebCore {
+
+template<class Encoder> inline void FetchOptions::encode(Encoder& encoder) const
+{
+    encoder << type;
+    encoder << destination;
+    encoder << mode;
+    encoder << credentials;
+    encoder << cache;
+    encoder << redirect;
+    encoder << referrerPolicy;
+    encoder << integrity;
+    encoder << keepAlive;
+}
+
+template<class Decoder> inline bool FetchOptions::decode(Decoder& decoder, FetchOptions& options)
+{
+    FetchOptions::Type type;
+    if (!decoder.decode(type))
+        return false;
+
+    FetchOptions::Destination destination;
+    if (!decoder.decode(destination))
+        return false;
+
+    FetchOptions::Mode mode;
+    if (!decoder.decode(mode))
+        return false;
+
+    FetchOptions::Credentials credentials;
+    if (!decoder.decode(credentials))
+        return false;
+
+    FetchOptions::Cache cache;
+    if (!decoder.decode(cache))
+        return false;
+
+    FetchOptions::Redirect redirect;
+    if (!decoder.decode(redirect))
+        return false;
+
+    ReferrerPolicy referrerPolicy;
+    if (!decoder.decode(referrerPolicy))
+        return false;
+
+    String integrity;
+    if (!decoder.decode(integrity))
+        return false;
+
+    bool keepAlive;
+    if (!decoder.decode(keepAlive))
+        return false;
+
+    options.type = type;
+    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;
+}
+
 } // namespace WebCore
index e543c97..8959299 100644 (file)
@@ -32,6 +32,8 @@
 
 #pragma once
 
+#include <wtf/EnumTraits.h>
+
 namespace WebCore {
 
 enum class ReferrerPolicy {
@@ -47,3 +49,22 @@ enum class ReferrerPolicy {
 };
 
 }
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::ReferrerPolicy> {
+    using values = EnumValues<
+        WebCore::ReferrerPolicy,
+        WebCore::ReferrerPolicy::EmptyString,
+        WebCore::ReferrerPolicy::NoReferrer,
+        WebCore::ReferrerPolicy::NoReferrerWhenDowngrade,
+        WebCore::ReferrerPolicy::SameOrigin,
+        WebCore::ReferrerPolicy::Origin,
+        WebCore::ReferrerPolicy::StrictOrigin,
+        WebCore::ReferrerPolicy::OriginWhenCrossOrigin,
+        WebCore::ReferrerPolicy::StrictOriginWhenCrossOrigin,
+        WebCore::ReferrerPolicy::UnsafeUrl
+    >;
+};
+
+}
index 92af2ab..5872452 100644 (file)
@@ -1,5 +1,17 @@
 2017-08-23  Youenn Fablet  <youenn@apple.com>
 
+        [Cache API] Enable persistent coder to encode FetchOptions
+        https://bugs.webkit.org/show_bug.cgi?id=175883
+
+        Reviewed by Alex Christensen.
+
+        Removing FetchOptions related ArgumentCoders specific code.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        * Shared/WebCoreArgumentCoders.h:
+
+2017-08-23  Youenn Fablet  <youenn@apple.com>
+
         CacheStorageEngine readCachesFromDisk callback should return the read Caches
         https://bugs.webkit.org/show_bug.cgi?id=175882
 
index 7c49ce8..a6f8a01 100644 (file)
@@ -214,70 +214,6 @@ bool ArgumentCoder<CacheQueryOptions>::decode(Decoder& decoder, CacheQueryOption
     return true;
 }
 
-void ArgumentCoder<FetchOptions>::encode(Encoder& encoder, const FetchOptions& options)
-{
-    encoder << options.type;
-    encoder << options.destination;
-    encoder << options.mode;
-    encoder << options.credentials;
-    encoder << options.cache;
-    encoder << options.redirect;
-    encoder << options.referrerPolicy;
-    encoder << options.integrity;
-    encoder << options.keepAlive;
-}
-
-bool ArgumentCoder<FetchOptions>::decode(Decoder& decoder, FetchOptions& options)
-{
-    FetchOptions::Type type;
-    if (!decoder.decode(type))
-        return false;
-
-    FetchOptions::Destination destination;
-    if (!decoder.decode(destination))
-        return false;
-
-    FetchOptions::Mode mode;
-    if (!decoder.decode(mode))
-        return false;
-
-    FetchOptions::Credentials credentials;
-    if (!decoder.decode(credentials))
-        return false;
-
-    FetchOptions::Cache cache;
-    if (!decoder.decode(cache))
-        return false;
-
-    FetchOptions::Redirect redirect;
-    if (!decoder.decode(redirect))
-        return false;
-
-    ReferrerPolicy referrerPolicy;
-    if (!decoder.decode(referrerPolicy))
-        return false;
-
-    String integrity;
-    if (!decoder.decode(integrity))
-        return false;
-
-    bool keepAlive;
-    if (!decoder.decode(keepAlive))
-        return false;
-
-    options.type = type;
-    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;
-}
-
 void ArgumentCoder<CacheStorageConnection::CacheInfo>::encode(Encoder& encoder, const CacheStorageConnection::CacheInfo& info)
 {
     encoder << info.identifier;
index 67edaf8..081fb01 100644 (file)
@@ -97,7 +97,6 @@ struct DictationAlternative;
 struct DictionaryPopupInfo;
 struct EventTrackingRegions;
 struct ExceptionDetails;
-struct FetchOptions;
 struct FileChooserSettings;
 struct Length;
 struct GrammarDetail;
@@ -196,11 +195,6 @@ template<> struct ArgumentCoder<WebCore::AffineTransform> {
     static bool decode(Decoder&, WebCore::AffineTransform&);
 };
 
-template<> struct ArgumentCoder<WebCore::FetchOptions> {
-    static void encode(Encoder&, const WebCore::FetchOptions&);
-    static bool decode(Decoder&, WebCore::FetchOptions&);
-};
-
 template<> struct ArgumentCoder<WebCore::CacheQueryOptions> {
     static void encode(Encoder&, const WebCore::CacheQueryOptions&);
     static bool decode(Decoder&, WebCore::CacheQueryOptions&);
@@ -800,85 +794,4 @@ template<> struct EnumTraits<WebCore::CacheStorageConnection::Error> {
     >;
 };
 
-template<> struct EnumTraits<WebCore::FetchOptions::Type> {
-    using values = EnumValues<
-        WebCore::FetchOptions::Type,
-        WebCore::FetchOptions::Type::EmptyString,
-        WebCore::FetchOptions::Type::Audio,
-        WebCore::FetchOptions::Type::Font,
-        WebCore::FetchOptions::Type::Image,
-        WebCore::FetchOptions::Type::Script,
-        WebCore::FetchOptions::Type::Style,
-        WebCore::FetchOptions::Type::Track,
-        WebCore::FetchOptions::Type::Video
-    >;
-};
-
-template<> struct EnumTraits<WebCore::FetchOptions::Destination> {
-    using values = EnumValues<
-        WebCore::FetchOptions::Destination,
-        WebCore::FetchOptions::Destination::EmptyString,
-        WebCore::FetchOptions::Destination::Document,
-        WebCore::FetchOptions::Destination::Sharedworker,
-        WebCore::FetchOptions::Destination::Subresource,
-        WebCore::FetchOptions::Destination::Unknown,
-        WebCore::FetchOptions::Destination::Worker
-    >;
-};
-
-template<> struct EnumTraits<WebCore::FetchOptions::Mode> {
-    using values = EnumValues<
-        WebCore::FetchOptions::Mode,
-        WebCore::FetchOptions::Mode::Navigate,
-        WebCore::FetchOptions::Mode::SameOrigin,
-        WebCore::FetchOptions::Mode::NoCors,
-        WebCore::FetchOptions::Mode::Cors
-    >;
-};
-
-template<> struct EnumTraits<WebCore::FetchOptions::Credentials> {
-    using values = EnumValues<
-        WebCore::FetchOptions::Credentials,
-        WebCore::FetchOptions::Credentials::Omit,
-        WebCore::FetchOptions::Credentials::SameOrigin,
-        WebCore::FetchOptions::Credentials::Include
-    >;
-};
-
-template<> struct EnumTraits<WebCore::FetchOptions::Cache> {
-    using values = EnumValues<
-        WebCore::FetchOptions::Cache,
-        WebCore::FetchOptions::Cache::Default,
-        WebCore::FetchOptions::Cache::NoStore,
-        WebCore::FetchOptions::Cache::Reload,
-        WebCore::FetchOptions::Cache::NoCache,
-        WebCore::FetchOptions::Cache::ForceCache,
-        WebCore::FetchOptions::Cache::OnlyIfCached
-    >;
-};
-
-template<> struct EnumTraits<WebCore::FetchOptions::Redirect> {
-    using values = EnumValues<
-        WebCore::FetchOptions::Redirect,
-        WebCore::FetchOptions::Redirect::Follow,
-        WebCore::FetchOptions::Redirect::Error,
-        WebCore::FetchOptions::Redirect::Manual
-    >;
-};
-
-template<> struct EnumTraits<WebCore::ReferrerPolicy> {
-    using values = EnumValues<
-        WebCore::ReferrerPolicy,
-        WebCore::ReferrerPolicy::EmptyString,
-        WebCore::ReferrerPolicy::NoReferrer,
-        WebCore::ReferrerPolicy::NoReferrerWhenDowngrade,
-        WebCore::ReferrerPolicy::SameOrigin,
-        WebCore::ReferrerPolicy::Origin,
-        WebCore::ReferrerPolicy::StrictOrigin,
-        WebCore::ReferrerPolicy::OriginWhenCrossOrigin,
-        WebCore::ReferrerPolicy::StrictOriginWhenCrossOrigin,
-        WebCore::ReferrerPolicy::UnsafeUrl
-    >;
-};
-
 } // namespace WTF