Changeset 221086 in webkit


Ignore:
Timestamp:
Aug 23, 2017 10:54:03 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[Cache API] Enable persistent coder to encode FetchOptions
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):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r221076 r221086  
     12017-08-23  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Enable persistent coder to encode FetchOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=175883
     5
     6        Reviewed by Alex Christensen.
     7
     8        Enabling encoding/decoding of enums with EnumTraits.
     9        This code is similar to the one of IPC encoder/decoder.
     10
     11        * wtf/persistence/PersistentDecoder.h:
     12        (WTF::Persistence::Decoder::decode):
     13        * wtf/persistence/PersistentEncoder.h:
     14        (WTF::Persistence::Encoder::encode):
     15
    1162017-08-23  Per Arne Vollan  <pvollan@apple.com>
    217
  • trunk/Source/WTF/wtf/persistence/PersistentDecoder.h

    r220574 r221086  
    2626#pragma once
    2727
     28#include <wtf/EnumTraits.h>
    2829#include <wtf/SHA1.h>
    2930#include <wtf/persistence/PersistentCoder.h>
     
    5556    WTF_EXPORT_PRIVATE bool decode(double&);
    5657
     58    template<typename E> auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool>
     59    {
     60        uint64_t value;
     61        if (!decode(value))
     62            return false;
     63        if (!isValidEnum<E>(value))
     64            return false;
     65
     66        e = static_cast<E>(value);
     67        return true;
     68    }
     69
    5770    template<typename T> bool decodeEnum(T& result)
    5871    {
     
    6780    }
    6881
    69     template<typename T> bool decode(T& t)
     82    template<typename T> auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>
    7083    {
    7184        return Coder<T>::decode(*this, t);
  • trunk/Source/WTF/wtf/persistence/PersistentEncoder.h

    r220574 r221086  
    2626#pragma once
    2727
     28#include <wtf/EnumTraits.h>
    2829#include <wtf/SHA1.h>
    2930#include <wtf/Vector.h>
     
    4546    WTF_EXPORT_PRIVATE void encodeFixedLengthData(const uint8_t*, size_t);
    4647
     48    template<typename E> auto encode(E value) -> std::enable_if_t<std::is_enum<E>::value>
     49    {
     50        static_assert(sizeof(E) <= sizeof(uint64_t), "Enum type must not be larger than 64 bits.");
     51
     52        ASSERT(isValidEnum<E>(static_cast<uint64_t>(value)));
     53        encode(static_cast<uint64_t>(value));
     54    }
     55
    4756    template<typename T> void encodeEnum(T t)
    4857    {
     
    5261    }
    5362
    54     template<typename T> void encode(const T& t)
     63    template<typename T> auto encode(const T& t) -> std::enable_if_t<!std::is_enum<T>::value>
    5564    {
    5665        Coder<T>::encode(*this, t);
  • trunk/Source/WebCore/ChangeLog

    r221083 r221086  
     12017-08-23  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Enable persistent coder to encode FetchOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=175883
     5
     6        Reviewed by Alex Christensen.
     7
     8        No change of behavior.
     9        Adding encode/decode routines for FetchOptions.
     10
     11        * loader/FetchOptions.h:
     12        (WebCore::FetchOptions::encode const):
     13        (WebCore::FetchOptions::decode):
     14        * platform/ReferrerPolicy.h:
     15
    1162017-08-23  Yusuke Suzuki  <utatane.tea@gmail.com>
    217
  • trunk/Source/WebCore/loader/FetchOptions.h

    r220810 r221086  
    4646    FetchOptions isolatedCopy() const { return { type, destination, mode, credentials, cache, redirect, referrerPolicy, integrity.isolatedCopy(), keepAlive }; }
    4747
     48    template<class Encoder> void encode(Encoder&) const;
     49    template<class Decoder> static bool decode(Decoder&, FetchOptions&);
     50
    4851    Type type { Type::EmptyString };
    4952    Destination destination { Destination::EmptyString };
     
    7073}
    7174
     75}
     76
     77namespace WTF {
     78
     79template<> struct EnumTraits<WebCore::FetchOptions::Type> {
     80    using values = EnumValues<
     81        WebCore::FetchOptions::Type,
     82        WebCore::FetchOptions::Type::EmptyString,
     83        WebCore::FetchOptions::Type::Audio,
     84        WebCore::FetchOptions::Type::Font,
     85        WebCore::FetchOptions::Type::Image,
     86        WebCore::FetchOptions::Type::Script,
     87        WebCore::FetchOptions::Type::Style,
     88        WebCore::FetchOptions::Type::Track,
     89        WebCore::FetchOptions::Type::Video
     90    >;
     91};
     92
     93template<> struct EnumTraits<WebCore::FetchOptions::Destination> {
     94    using values = EnumValues<
     95        WebCore::FetchOptions::Destination,
     96        WebCore::FetchOptions::Destination::EmptyString,
     97        WebCore::FetchOptions::Destination::Document,
     98        WebCore::FetchOptions::Destination::Sharedworker,
     99        WebCore::FetchOptions::Destination::Subresource,
     100        WebCore::FetchOptions::Destination::Unknown,
     101        WebCore::FetchOptions::Destination::Worker
     102    >;
     103};
     104
     105template<> struct EnumTraits<WebCore::FetchOptions::Mode> {
     106    using values = EnumValues<
     107        WebCore::FetchOptions::Mode,
     108        WebCore::FetchOptions::Mode::Navigate,
     109        WebCore::FetchOptions::Mode::SameOrigin,
     110        WebCore::FetchOptions::Mode::NoCors,
     111        WebCore::FetchOptions::Mode::Cors
     112    >;
     113};
     114
     115template<> struct EnumTraits<WebCore::FetchOptions::Credentials> {
     116    using values = EnumValues<
     117        WebCore::FetchOptions::Credentials,
     118        WebCore::FetchOptions::Credentials::Omit,
     119        WebCore::FetchOptions::Credentials::SameOrigin,
     120        WebCore::FetchOptions::Credentials::Include
     121    >;
     122};
     123
     124template<> struct EnumTraits<WebCore::FetchOptions::Cache> {
     125    using values = EnumValues<
     126        WebCore::FetchOptions::Cache,
     127        WebCore::FetchOptions::Cache::Default,
     128        WebCore::FetchOptions::Cache::NoStore,
     129        WebCore::FetchOptions::Cache::Reload,
     130        WebCore::FetchOptions::Cache::NoCache,
     131        WebCore::FetchOptions::Cache::ForceCache,
     132        WebCore::FetchOptions::Cache::OnlyIfCached
     133    >;
     134};
     135
     136template<> struct EnumTraits<WebCore::FetchOptions::Redirect> {
     137    using values = EnumValues<
     138        WebCore::FetchOptions::Redirect,
     139        WebCore::FetchOptions::Redirect::Follow,
     140        WebCore::FetchOptions::Redirect::Error,
     141        WebCore::FetchOptions::Redirect::Manual
     142    >;
     143};
     144
     145}
     146
     147namespace WebCore {
     148
     149template<class Encoder> inline void FetchOptions::encode(Encoder& encoder) const
     150{
     151    encoder << type;
     152    encoder << destination;
     153    encoder << mode;
     154    encoder << credentials;
     155    encoder << cache;
     156    encoder << redirect;
     157    encoder << referrerPolicy;
     158    encoder << integrity;
     159    encoder << keepAlive;
     160}
     161
     162template<class Decoder> inline bool FetchOptions::decode(Decoder& decoder, FetchOptions& options)
     163{
     164    FetchOptions::Type type;
     165    if (!decoder.decode(type))
     166        return false;
     167
     168    FetchOptions::Destination destination;
     169    if (!decoder.decode(destination))
     170        return false;
     171
     172    FetchOptions::Mode mode;
     173    if (!decoder.decode(mode))
     174        return false;
     175
     176    FetchOptions::Credentials credentials;
     177    if (!decoder.decode(credentials))
     178        return false;
     179
     180    FetchOptions::Cache cache;
     181    if (!decoder.decode(cache))
     182        return false;
     183
     184    FetchOptions::Redirect redirect;
     185    if (!decoder.decode(redirect))
     186        return false;
     187
     188    ReferrerPolicy referrerPolicy;
     189    if (!decoder.decode(referrerPolicy))
     190        return false;
     191
     192    String integrity;
     193    if (!decoder.decode(integrity))
     194        return false;
     195
     196    bool keepAlive;
     197    if (!decoder.decode(keepAlive))
     198        return false;
     199
     200    options.type = type;
     201    options.destination = destination;
     202    options.mode = mode;
     203    options.credentials = credentials;
     204    options.cache = cache;
     205    options.redirect = redirect;
     206    options.referrerPolicy = referrerPolicy;
     207    options.integrity = WTFMove(integrity);
     208    options.keepAlive = keepAlive;
     209
     210    return true;
     211}
     212
    72213} // namespace WebCore
  • trunk/Source/WebCore/platform/ReferrerPolicy.h

    r220208 r221086  
    3333#pragma once
    3434
     35#include <wtf/EnumTraits.h>
     36
    3537namespace WebCore {
    3638
     
    4850
    4951}
     52
     53namespace WTF {
     54
     55template<> struct EnumTraits<WebCore::ReferrerPolicy> {
     56    using values = EnumValues<
     57        WebCore::ReferrerPolicy,
     58        WebCore::ReferrerPolicy::EmptyString,
     59        WebCore::ReferrerPolicy::NoReferrer,
     60        WebCore::ReferrerPolicy::NoReferrerWhenDowngrade,
     61        WebCore::ReferrerPolicy::SameOrigin,
     62        WebCore::ReferrerPolicy::Origin,
     63        WebCore::ReferrerPolicy::StrictOrigin,
     64        WebCore::ReferrerPolicy::OriginWhenCrossOrigin,
     65        WebCore::ReferrerPolicy::StrictOriginWhenCrossOrigin,
     66        WebCore::ReferrerPolicy::UnsafeUrl
     67    >;
     68};
     69
     70}
  • trunk/Source/WebKit/ChangeLog

    r221085 r221086  
     12017-08-23  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Enable persistent coder to encode FetchOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=175883
     5
     6        Reviewed by Alex Christensen.
     7
     8        Removing FetchOptions related ArgumentCoders specific code.
     9
     10        * Shared/WebCoreArgumentCoders.cpp:
     11        * Shared/WebCoreArgumentCoders.h:
     12
    1132017-08-23  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r221068 r221086  
    215215}
    216216
    217 void ArgumentCoder<FetchOptions>::encode(Encoder& encoder, const FetchOptions& options)
    218 {
    219     encoder << options.type;
    220     encoder << options.destination;
    221     encoder << options.mode;
    222     encoder << options.credentials;
    223     encoder << options.cache;
    224     encoder << options.redirect;
    225     encoder << options.referrerPolicy;
    226     encoder << options.integrity;
    227     encoder << options.keepAlive;
    228 }
    229 
    230 bool ArgumentCoder<FetchOptions>::decode(Decoder& decoder, FetchOptions& options)
    231 {
    232     FetchOptions::Type type;
    233     if (!decoder.decode(type))
    234         return false;
    235 
    236     FetchOptions::Destination destination;
    237     if (!decoder.decode(destination))
    238         return false;
    239 
    240     FetchOptions::Mode mode;
    241     if (!decoder.decode(mode))
    242         return false;
    243 
    244     FetchOptions::Credentials credentials;
    245     if (!decoder.decode(credentials))
    246         return false;
    247 
    248     FetchOptions::Cache cache;
    249     if (!decoder.decode(cache))
    250         return false;
    251 
    252     FetchOptions::Redirect redirect;
    253     if (!decoder.decode(redirect))
    254         return false;
    255 
    256     ReferrerPolicy referrerPolicy;
    257     if (!decoder.decode(referrerPolicy))
    258         return false;
    259 
    260     String integrity;
    261     if (!decoder.decode(integrity))
    262         return false;
    263 
    264     bool keepAlive;
    265     if (!decoder.decode(keepAlive))
    266         return false;
    267 
    268     options.type = type;
    269     options.destination = destination;
    270     options.mode = mode;
    271     options.credentials = credentials;
    272     options.cache = cache;
    273     options.redirect = redirect;
    274     options.referrerPolicy = referrerPolicy;
    275     options.integrity = WTFMove(integrity);
    276     options.keepAlive = keepAlive;
    277 
    278     return true;
    279 }
    280 
    281217void ArgumentCoder<CacheStorageConnection::CacheInfo>::encode(Encoder& encoder, const CacheStorageConnection::CacheInfo& info)
    282218{
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h

    r220917 r221086  
    9898struct EventTrackingRegions;
    9999struct ExceptionDetails;
    100 struct FetchOptions;
    101100struct FileChooserSettings;
    102101struct Length;
     
    197196};
    198197
    199 template<> struct ArgumentCoder<WebCore::FetchOptions> {
    200     static void encode(Encoder&, const WebCore::FetchOptions&);
    201     static bool decode(Decoder&, WebCore::FetchOptions&);
    202 };
    203 
    204198template<> struct ArgumentCoder<WebCore::CacheQueryOptions> {
    205199    static void encode(Encoder&, const WebCore::CacheQueryOptions&);
     
    801795};
    802796
    803 template<> struct EnumTraits<WebCore::FetchOptions::Type> {
    804     using values = EnumValues<
    805         WebCore::FetchOptions::Type,
    806         WebCore::FetchOptions::Type::EmptyString,
    807         WebCore::FetchOptions::Type::Audio,
    808         WebCore::FetchOptions::Type::Font,
    809         WebCore::FetchOptions::Type::Image,
    810         WebCore::FetchOptions::Type::Script,
    811         WebCore::FetchOptions::Type::Style,
    812         WebCore::FetchOptions::Type::Track,
    813         WebCore::FetchOptions::Type::Video
    814     >;
    815 };
    816 
    817 template<> struct EnumTraits<WebCore::FetchOptions::Destination> {
    818     using values = EnumValues<
    819         WebCore::FetchOptions::Destination,
    820         WebCore::FetchOptions::Destination::EmptyString,
    821         WebCore::FetchOptions::Destination::Document,
    822         WebCore::FetchOptions::Destination::Sharedworker,
    823         WebCore::FetchOptions::Destination::Subresource,
    824         WebCore::FetchOptions::Destination::Unknown,
    825         WebCore::FetchOptions::Destination::Worker
    826     >;
    827 };
    828 
    829 template<> struct EnumTraits<WebCore::FetchOptions::Mode> {
    830     using values = EnumValues<
    831         WebCore::FetchOptions::Mode,
    832         WebCore::FetchOptions::Mode::Navigate,
    833         WebCore::FetchOptions::Mode::SameOrigin,
    834         WebCore::FetchOptions::Mode::NoCors,
    835         WebCore::FetchOptions::Mode::Cors
    836     >;
    837 };
    838 
    839 template<> struct EnumTraits<WebCore::FetchOptions::Credentials> {
    840     using values = EnumValues<
    841         WebCore::FetchOptions::Credentials,
    842         WebCore::FetchOptions::Credentials::Omit,
    843         WebCore::FetchOptions::Credentials::SameOrigin,
    844         WebCore::FetchOptions::Credentials::Include
    845     >;
    846 };
    847 
    848 template<> struct EnumTraits<WebCore::FetchOptions::Cache> {
    849     using values = EnumValues<
    850         WebCore::FetchOptions::Cache,
    851         WebCore::FetchOptions::Cache::Default,
    852         WebCore::FetchOptions::Cache::NoStore,
    853         WebCore::FetchOptions::Cache::Reload,
    854         WebCore::FetchOptions::Cache::NoCache,
    855         WebCore::FetchOptions::Cache::ForceCache,
    856         WebCore::FetchOptions::Cache::OnlyIfCached
    857     >;
    858 };
    859 
    860 template<> struct EnumTraits<WebCore::FetchOptions::Redirect> {
    861     using values = EnumValues<
    862         WebCore::FetchOptions::Redirect,
    863         WebCore::FetchOptions::Redirect::Follow,
    864         WebCore::FetchOptions::Redirect::Error,
    865         WebCore::FetchOptions::Redirect::Manual
    866     >;
    867 };
    868 
    869 template<> struct EnumTraits<WebCore::ReferrerPolicy> {
    870     using values = EnumValues<
    871         WebCore::ReferrerPolicy,
    872         WebCore::ReferrerPolicy::EmptyString,
    873         WebCore::ReferrerPolicy::NoReferrer,
    874         WebCore::ReferrerPolicy::NoReferrerWhenDowngrade,
    875         WebCore::ReferrerPolicy::SameOrigin,
    876         WebCore::ReferrerPolicy::Origin,
    877         WebCore::ReferrerPolicy::StrictOrigin,
    878         WebCore::ReferrerPolicy::OriginWhenCrossOrigin,
    879         WebCore::ReferrerPolicy::StrictOriginWhenCrossOrigin,
    880         WebCore::ReferrerPolicy::UnsafeUrl
    881     >;
    882 };
    883 
    884797} // namespace WTF
Note: See TracChangeset for help on using the changeset viewer.