Title: [221086] trunk/Source
Revision
221086
Author
[email protected]
Date
2017-08-23 10:54:03 -0700 (Wed, 23 Aug 2017)

Log Message

[Cache API] Enable persistent coder to encode FetchOptions
https://bugs.webkit.org/show_bug.cgi?id=175883

Patch by Youenn Fablet <[email protected]> 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):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (221085 => 221086)


--- trunk/Source/WTF/ChangeLog	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WTF/ChangeLog	2017-08-23 17:54:03 UTC (rev 221086)
@@ -1,3 +1,18 @@
+2017-08-23  Youenn Fablet  <[email protected]>
+
+        [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  <[email protected]>
 
         [Win] Compile error, include file <wtf/AVFoundationHeaderDetection.h> is not found.

Modified: trunk/Source/WTF/wtf/persistence/PersistentDecoder.h (221085 => 221086)


--- trunk/Source/WTF/wtf/persistence/PersistentDecoder.h	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WTF/wtf/persistence/PersistentDecoder.h	2017-08-23 17:54:03 UTC (rev 221086)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <wtf/EnumTraits.h>
 #include <wtf/SHA1.h>
 #include <wtf/persistence/PersistentCoder.h>
 
@@ -54,6 +55,18 @@
     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 @@
         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);
     }

Modified: trunk/Source/WTF/wtf/persistence/PersistentEncoder.h (221085 => 221086)


--- trunk/Source/WTF/wtf/persistence/PersistentEncoder.h	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WTF/wtf/persistence/PersistentEncoder.h	2017-08-23 17:54:03 UTC (rev 221086)
@@ -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 @@
     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 @@
         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);
     }

Modified: trunk/Source/WebCore/ChangeLog (221085 => 221086)


--- trunk/Source/WebCore/ChangeLog	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WebCore/ChangeLog	2017-08-23 17:54:03 UTC (rev 221086)
@@ -1,3 +1,18 @@
+2017-08-23  Youenn Fablet  <[email protected]>
+
+        [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  <[email protected]>
 
         Race condition in StartWebThread causing crash

Modified: trunk/Source/WebCore/loader/FetchOptions.h (221085 => 221086)


--- trunk/Source/WebCore/loader/FetchOptions.h	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WebCore/loader/FetchOptions.h	2017-08-23 17:54:03 UTC (rev 221086)
@@ -45,6 +45,9 @@
     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 @@
 {
 }
 
+}
+
+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

Modified: trunk/Source/WebCore/platform/ReferrerPolicy.h (221085 => 221086)


--- trunk/Source/WebCore/platform/ReferrerPolicy.h	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WebCore/platform/ReferrerPolicy.h	2017-08-23 17:54:03 UTC (rev 221086)
@@ -32,6 +32,8 @@
 
 #pragma once
 
+#include <wtf/EnumTraits.h>
+
 namespace WebCore {
 
 enum class ReferrerPolicy {
@@ -47,3 +49,22 @@
 };
 
 }
+
+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
+    >;
+};
+
+}

Modified: trunk/Source/WebKit/ChangeLog (221085 => 221086)


--- trunk/Source/WebKit/ChangeLog	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WebKit/ChangeLog	2017-08-23 17:54:03 UTC (rev 221086)
@@ -1,5 +1,17 @@
 2017-08-23  Youenn Fablet  <[email protected]>
 
+        [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  <[email protected]>
+
         CacheStorageEngine readCachesFromDisk callback should return the read Caches
         https://bugs.webkit.org/show_bug.cgi?id=175882
 

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (221085 => 221086)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2017-08-23 17:54:03 UTC (rev 221086)
@@ -214,70 +214,6 @@
     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;

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (221085 => 221086)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2017-08-23 17:52:56 UTC (rev 221085)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2017-08-23 17:54:03 UTC (rev 221086)
@@ -97,7 +97,6 @@
 struct DictionaryPopupInfo;
 struct EventTrackingRegions;
 struct ExceptionDetails;
-struct FetchOptions;
 struct FileChooserSettings;
 struct Length;
 struct GrammarDetail;
@@ -196,11 +195,6 @@
     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::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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to