Changeset 221319 in webkit


Ignore:
Timestamp:
Aug 29, 2017 3:49:50 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Begin transition to modern IPC decoding
https://bugs.webkit.org/show_bug.cgi?id=176043

Reviewed by JF Bastien.

Right now, if a class is decoded from IPC we must have a default constructor.
This prevents us from having Ref or C++ references in such types, which is cluttering up our code.
This is because IPC::decode makes a default-constructed object, fills it, and returns a bool indicating success.
Making IPC::decode instead return a std::optional makes it so we do not need to call an empty constructor.
This could also enable us to add IPC::Decoder::operator>> and other fun things!
I also modernized two arbitrary classes, WebsitePolicies and WebPageGroupData with more to come.
There's no good way to update the actual generated IPC code until each class has been transitioned.

  • Platform/IPC/ArgumentCoder.h:

(IPC::ArgumentCoder::decode):

  • Platform/IPC/Decoder.h:

(IPC::Decoder::decode):

  • Shared/WebPageCreationParameters.cpp:

(WebKit::WebPageCreationParameters::decode):

  • Shared/WebPageCreationParameters.h:
  • Shared/WebPageGroupData.cpp:

(WebKit::WebPageGroupData::decode):

  • Shared/WebPageGroupData.h:
  • Shared/WebsitePolicies.h:

(WebKit::WebsitePolicies::decode):

Location:
trunk/Source/WebKit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221315 r221319  
     12017-08-29  Alex Christensen  <achristensen@webkit.org>
     2
     3        Begin transition to modern IPC decoding
     4        https://bugs.webkit.org/show_bug.cgi?id=176043
     5
     6        Reviewed by JF Bastien.
     7
     8        Right now, if a class is decoded from IPC we must have a default constructor.
     9        This prevents us from having Ref or C++ references in such types, which is cluttering up our code.
     10        This is because IPC::decode makes a default-constructed object, fills it, and returns a bool indicating success.
     11        Making IPC::decode instead return a std::optional makes it so we do not need to call an empty constructor.
     12        This could also enable us to add IPC::Decoder::operator>> and other fun things!
     13        I also modernized two arbitrary classes, WebsitePolicies and WebPageGroupData with more to come.
     14        There's no good way to update the actual generated IPC code until each class has been transitioned.
     15
     16        * Platform/IPC/ArgumentCoder.h:
     17        (IPC::ArgumentCoder::decode):
     18        * Platform/IPC/Decoder.h:
     19        (IPC::Decoder::decode):
     20        * Shared/WebPageCreationParameters.cpp:
     21        (WebKit::WebPageCreationParameters::decode):
     22        * Shared/WebPageCreationParameters.h:
     23        * Shared/WebPageGroupData.cpp:
     24        (WebKit::WebPageGroupData::decode):
     25        * Shared/WebPageGroupData.h:
     26        * Shared/WebsitePolicies.h:
     27        (WebKit::WebsitePolicies::decode):
     28
    1292017-08-29  Youenn Fablet  <youenn@apple.com>
    230
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h

    r204668 r221319  
    2424 */
    2525
    26 #ifndef ArgumentCoder_h
    27 #define ArgumentCoder_h
     26#pragma once
     27
     28#include <wtf/Optional.h>
    2829
    2930namespace IPC {
     
    3233class Encoder;
    3334   
     35template <typename... T> using IsUsingModernDecoder = void;
     36template <typename T, typename = void> struct UsesModernDecoder : std::false_type { };
     37template <typename T> struct UsesModernDecoder<T, IsUsingModernDecoder<typename T::ModernDecoder>> : std::true_type { };
     38
    3439template<typename T> struct ArgumentCoder {
    3540    static void encode(Encoder& encoder, const T& t)
     
    3843    }
    3944
    40     static bool decode(Decoder& decoder, T& t)
     45    template<typename U = T, std::enable_if_t<!UsesModernDecoder<U>::value>* = nullptr>
     46    static bool decode(Decoder& decoder, U& u)
    4147    {
    42         return T::decode(decoder, t);
     48        return U::decode(decoder, u);
     49    }
     50
     51    template<typename U = T, std::enable_if_t<UsesModernDecoder<U>::value>* = nullptr>
     52    static std::optional<U> decode(Decoder& decoder)
     53    {
     54        return U::decode(decoder);
    4355    }
    4456};
    4557
    4658}
    47 
    48 #endif // ArgumentCoder_h
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h

    r220917 r221319  
    134134    }
    135135
     136    template<typename U = typename std::remove_reference<typename std::tuple_element<sizeof...(Elements) - index, std::tuple<Elements...>>::type>::type, std::enable_if_t<!UsesModernDecoder<U>::value>* = nullptr>
    136137    static bool decode(Decoder& decoder, std::tuple<Elements...>& tuple)
    137138    {
    138139        if (!decoder.decode(std::get<sizeof...(Elements) - index>(tuple)))
    139140            return false;
     141        return TupleCoder<index - 1, Elements...>::decode(decoder, tuple);
     142    }
     143   
     144    template<typename U = typename std::remove_reference<typename std::tuple_element<sizeof...(Elements) - index, std::tuple<Elements...>>::type>::type, std::enable_if_t<UsesModernDecoder<U>::value>* = nullptr>
     145    static bool decode(Decoder& decoder, std::tuple<Elements...>& tuple)
     146    {
     147        std::optional<U> optional;
     148        decoder >> optional;
     149        if (!optional)
     150            return false;
     151        std::get<sizeof...(Elements) - index>(tuple) = WTFMove(*optional);
    140152        return TupleCoder<index - 1, Elements...>::decode(decoder, tuple);
    141153    }
  • trunk/Source/WebKit/Platform/IPC/Decoder.h

    r209407 r221319  
    124124    }
    125125
    126     template<typename T>
    127     auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>
     126    template<typename T, std::enable_if_t<!std::is_enum<T>::value && !UsesModernDecoder<T>::value>* = nullptr>
     127    bool decode(T& t)
    128128    {
    129129        return ArgumentCoder<T>::decode(*this, t);
     130    }
     131
     132    template<typename T, std::enable_if_t<UsesModernDecoder<T>::value>* = nullptr>
     133    Decoder& operator>>(std::optional<T>& t)
     134    {
     135        t = ArgumentCoder<T>::decode(*this);
     136        return *this;
    130137    }
    131138
  • trunk/Source/WebKit/Shared/API/APIPageGroupHandle.cpp

    r204668 r221319  
    5353bool PageGroupHandle::decode(IPC::Decoder& decoder, RefPtr<Object>& result)
    5454{
    55     WebKit::WebPageGroupData webPageGroupData;
    56     if (!decoder.decode(webPageGroupData))
     55    std::optional<WebKit::WebPageGroupData> webPageGroupData;
     56    decoder >> webPageGroupData;
     57    if (!webPageGroupData)
    5758        return false;
    5859
    59     result = create(WTFMove(webPageGroupData));
     60    result = create(WTFMove(*webPageGroupData));
    6061    return true;
    6162}
  • trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp

    r218528 r221319  
    109109}
    110110
    111 bool WebPageCreationParameters::decode(IPC::Decoder& decoder, WebPageCreationParameters& parameters)
     111std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
    112112{
     113    WebPageCreationParameters parameters;
    113114    if (!decoder.decode(parameters.viewSize))
    114         return false;
     115        return std::nullopt;
    115116    if (!decoder.decode(parameters.activityState))
    116         return false;
     117        return std::nullopt;
    117118    if (!decoder.decode(parameters.store))
    118         return false;
     119        return std::nullopt;
    119120    if (!decoder.decodeEnum(parameters.drawingAreaType))
    120         return false;
    121     if (!decoder.decode(parameters.pageGroupData))
    122         return false;
     121        return std::nullopt;
     122    std::optional<WebPageGroupData> pageGroupData;
     123    decoder >> pageGroupData;
     124    if (!pageGroupData)
     125        return std::nullopt;
     126    parameters.pageGroupData = WTFMove(*pageGroupData);
    123127    if (!decoder.decode(parameters.drawsBackground))
    124         return false;
     128        return std::nullopt;
    125129    if (!decoder.decode(parameters.isEditable))
    126         return false;
     130        return std::nullopt;
    127131    if (!decoder.decode(parameters.underlayColor))
    128         return false;
     132        return std::nullopt;
    129133    if (!decoder.decode(parameters.useFixedLayout))
    130         return false;
     134        return std::nullopt;
    131135    if (!decoder.decode(parameters.fixedLayoutSize))
    132         return false;
     136        return std::nullopt;
    133137    if (!decoder.decodeEnum(parameters.paginationMode))
    134         return false;
     138        return std::nullopt;
    135139    if (!decoder.decode(parameters.paginationBehavesLikeColumns))
    136         return false;
     140        return std::nullopt;
    137141    if (!decoder.decode(parameters.pageLength))
    138         return false;
     142        return std::nullopt;
    139143    if (!decoder.decode(parameters.gapBetweenPages))
    140         return false;
     144        return std::nullopt;
    141145    if (!decoder.decode(parameters.paginationLineGridEnabled))
    142         return false;
     146        return std::nullopt;
    143147    if (!decoder.decode(parameters.userAgent))
    144         return false;
     148        return std::nullopt;
    145149    if (!decoder.decode(parameters.itemStates))
    146         return false;
     150        return std::nullopt;
    147151    if (!decoder.decode(parameters.sessionID))
    148         return false;
     152        return std::nullopt;
    149153    if (!decoder.decode(parameters.highestUsedBackForwardItemID))
    150         return false;
     154        return std::nullopt;
    151155    if (!decoder.decode(parameters.userContentControllerID))
    152         return false;
     156        return std::nullopt;
    153157    if (!decoder.decode(parameters.visitedLinkTableID))
    154         return false;
     158        return std::nullopt;
    155159    if (!decoder.decode(parameters.websiteDataStoreID))
    156         return false;
     160        return std::nullopt;
    157161    if (!decoder.decode(parameters.canRunBeforeUnloadConfirmPanel))
    158         return false;
     162        return std::nullopt;
    159163    if (!decoder.decode(parameters.canRunModal))
    160         return false;
     164        return std::nullopt;
    161165    if (!decoder.decode(parameters.deviceScaleFactor))
    162         return false;
     166        return std::nullopt;
    163167    if (!decoder.decode(parameters.viewScaleFactor))
    164         return false;
     168        return std::nullopt;
    165169    if (!decoder.decode(parameters.topContentInset))
    166         return false;
     170        return std::nullopt;
    167171    if (!decoder.decode(parameters.mediaVolume))
    168         return false;
     172        return std::nullopt;
    169173    if (!decoder.decode(parameters.muted))
    170         return false;
     174        return std::nullopt;
    171175    if (!decoder.decode(parameters.mayStartMediaWhenInWindow))
    172         return false;
     176        return std::nullopt;
    173177    if (!decoder.decode(parameters.minimumLayoutSize))
    174         return false;
     178        return std::nullopt;
    175179    if (!decoder.decode(parameters.autoSizingShouldExpandToViewHeight))
    176         return false;
     180        return std::nullopt;
    177181    if (!decoder.decode(parameters.viewportSizeForCSSViewportUnits))
    178         return false;
     182        return std::nullopt;
    179183    if (!decoder.decodeEnum(parameters.scrollPinningBehavior))
    180         return false;
     184        return std::nullopt;
    181185    if (!decoder.decode(parameters.scrollbarOverlayStyle))
    182         return false;
     186        return std::nullopt;
    183187    if (!decoder.decode(parameters.backgroundExtendsBeyondPage))
    184         return false;
     188        return std::nullopt;
    185189    if (!decoder.decodeEnum(parameters.layerHostingMode))
    186         return false;
     190        return std::nullopt;
    187191    if (!decoder.decode(parameters.mimeTypesWithCustomContentProviders))
    188         return false;
     192        return std::nullopt;
    189193    if (!decoder.decode(parameters.controlledByAutomation))
    190         return false;
     194        return std::nullopt;
    191195
    192196#if ENABLE(REMOTE_INSPECTOR)
    193197    if (!decoder.decode(parameters.allowsRemoteInspection))
    194         return false;
     198        return std::nullopt;
    195199    if (!decoder.decode(parameters.remoteInspectionNameOverride))
    196         return false;
     200        return std::nullopt;
    197201#endif
    198202
    199203#if PLATFORM(MAC)
    200204    if (!decoder.decode(parameters.colorSpace))
    201         return false;
     205        return std::nullopt;
    202206#endif
    203207
    204208#if PLATFORM(IOS)
    205209    if (!decoder.decode(parameters.screenSize))
    206         return false;
     210        return std::nullopt;
    207211    if (!decoder.decode(parameters.availableScreenSize))
    208         return false;
     212        return std::nullopt;
    209213    if (!decoder.decode(parameters.textAutosizingWidth))
    210         return false;
     214        return std::nullopt;
    211215    if (!decoder.decode(parameters.ignoresViewportScaleLimits))
    212         return false;
     216        return std::nullopt;
    213217    if (!decoder.decode(parameters.allowsBlockSelection))
    214         return false;
     218        return std::nullopt;
    215219#endif
    216220
    217221#if PLATFORM(COCOA)
    218222    if (!decoder.decode(parameters.smartInsertDeleteEnabled))
    219         return false;
     223        return std::nullopt;
    220224#endif
    221225
    222226    if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled))
    223         return false;
     227        return std::nullopt;
    224228
    225229    if (!decoder.decode(parameters.shouldScaleViewToFitDocument))
    226         return false;
     230        return std::nullopt;
    227231
    228232    if (!decoder.decodeEnum(parameters.userInterfaceLayoutDirection))
    229         return false;
     233        return std::nullopt;
    230234    if (!decoder.decodeEnum(parameters.observedLayoutMilestones))
    231         return false;
     235        return std::nullopt;
    232236
    233237    if (!decoder.decode(parameters.overrideContentSecurityPolicy))
    234         return false;
     238        return std::nullopt;
    235239
    236240    if (!decoder.decode(parameters.cpuLimit))
    237         return false;
     241        return std::nullopt;
    238242
    239243    if (!decoder.decode(parameters.urlSchemeHandlers))
    240         return false;
     244        return std::nullopt;
    241245
    242246    if (!decoder.decode(parameters.iceCandidateFilteringEnabled))
    243         return false;
     247        return std::nullopt;
    244248
    245249    if (!decoder.decode(parameters.enumeratingAllNetworkInterfacesEnabled))
    246         return false;
     250        return std::nullopt;
    247251
    248252    if (!decoder.decode(parameters.userContentWorlds))
    249         return false;
     253        return std::nullopt;
    250254    if (!decoder.decode(parameters.userScripts))
    251         return false;
     255        return std::nullopt;
    252256    if (!decoder.decode(parameters.userStyleSheets))
    253         return false;
     257        return std::nullopt;
    254258    if (!decoder.decode(parameters.messageHandlers))
    255         return false;
     259        return std::nullopt;
    256260#if ENABLE(CONTENT_EXTENSIONS)
    257261    if (!decoder.decode(parameters.contentRuleLists))
    258         return false;
    259 #endif
    260     return true;
     262        return std::nullopt;
     263#endif
     264    return WTFMove(parameters);
    261265}
    262266
  • trunk/Source/WebKit/Shared/WebPageCreationParameters.h

    r220887 r221319  
    6060struct WebPageCreationParameters {
    6161    void encode(IPC::Encoder&) const;
    62     static bool decode(IPC::Decoder&, WebPageCreationParameters&);
     62    static std::optional<WebPageCreationParameters> decode(IPC::Decoder&);
     63    using ModernDecoder = std::true_type;
    6364
    6465    WebCore::IntSize viewSize;
  • trunk/Source/WebKit/Shared/WebPageGroupData.cpp

    r204668 r221319  
    4040}
    4141
    42 bool WebPageGroupData::decode(IPC::Decoder& decoder, WebPageGroupData& data)
     42std::optional<WebPageGroupData> WebPageGroupData::decode(IPC::Decoder& decoder)
    4343{
    44     if (!decoder.decode(data.identifier))
    45         return false;
    46     if (!decoder.decode(data.pageGroupID))
    47         return false;
    48     if (!decoder.decode(data.visibleToInjectedBundle))
    49         return false;
    50     if (!decoder.decode(data.visibleToHistoryClient))
    51         return false;
    52     if (!decoder.decode(data.userContentControllerIdentifier))
    53         return false;
    54     return true;
     44    String id;
     45    if (!decoder.decode(id))
     46        return std::nullopt;
     47    uint64_t pageGroupID;
     48    if (!decoder.decode(pageGroupID))
     49        return std::nullopt;
     50    bool visibleToInjectedBundle;
     51    if (!decoder.decode(visibleToInjectedBundle))
     52        return std::nullopt;
     53    bool visibleToHistoryClient;
     54    if (!decoder.decode(visibleToHistoryClient))
     55        return std::nullopt;
     56    uint64_t userContentControllerIdentifier;
     57    if (!decoder.decode(userContentControllerIdentifier))
     58        return std::nullopt;
     59    return { { id, pageGroupID, visibleToInjectedBundle, visibleToHistoryClient, userContentControllerIdentifier } };
    5560}
    5661
  • trunk/Source/WebKit/Shared/WebPageGroupData.h

    r204668 r221319  
    2424 */
    2525
    26 #ifndef WebPageGroupData_h
    27 #define WebPageGroupData_h
     26#pragma once
    2827
    2928#include <wtf/text/WTFString.h>
     
    3837struct WebPageGroupData {
    3938    void encode(IPC::Encoder&) const;
    40     static bool decode(IPC::Decoder&, WebPageGroupData&);
     39    static std::optional<WebPageGroupData> decode(IPC::Decoder&);
     40    using ModernDecoder = std::true_type;
    4141
    4242    String identifier;
     
    4949
    5050} // namespace WebKit
    51 
    52 
    53 #endif // WebPageGroupData_h
  • trunk/Source/WebKit/Shared/WebsitePolicies.h

    r218229 r221319  
    2727
    2828#include <wtf/OptionSet.h>
     29#include <wtf/Optional.h>
    2930
    3031namespace WebKit {
     
    4950
    5051    template<class Encoder> void encode(Encoder&) const;
    51     template<class Decoder> static bool decode(Decoder&, WebsitePolicies&);
     52    template<class Decoder> static std::optional<WebsitePolicies> decode(Decoder&);
     53    using ModernDecoder = std::true_type;
    5254};
    5355
     
    5961}
    6062
    61 template<class Decoder> bool WebsitePolicies::decode(Decoder& decoder, WebsitePolicies& result)
     63template<class Decoder> std::optional<WebsitePolicies> WebsitePolicies::decode(Decoder& decoder)
    6264{
    63     if (!decoder.decode(result.contentBlockersEnabled))
    64         return false;
    65     if (!decoder.decodeEnum(result.autoplayPolicy))
    66         return false;
    67     if (!decoder.decode(result.allowedAutoplayQuirks))
    68         return false;
    69     return true;
     65    bool contentBlockersEnabled;
     66    if (!decoder.decode(contentBlockersEnabled))
     67        return std::nullopt;
     68   
     69    WebsiteAutoplayPolicy autoplayPolicy;
     70    if (!decoder.decodeEnum(autoplayPolicy))
     71        return std::nullopt;
     72
     73    OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
     74    if (!decoder.decode(allowedAutoplayQuirks))
     75        return std::nullopt;
     76
     77    return { { contentBlockersEnabled, allowedAutoplayQuirks, autoplayPolicy } };
    7078}
    7179
Note: See TracChangeset for help on using the changeset viewer.