Title: [221319] trunk/Source/WebKit
Revision
221319
Author
achristen...@apple.com
Date
2017-08-29 15:49:50 -0700 (Tue, 29 Aug 2017)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (221318 => 221319)


--- trunk/Source/WebKit/ChangeLog	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/ChangeLog	2017-08-29 22:49:50 UTC (rev 221319)
@@ -1,3 +1,31 @@
+2017-08-29  Alex Christensen  <achristen...@webkit.org>
+
+        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):
+
 2017-08-29  Youenn Fablet  <you...@apple.com>
 
         Setting the cache storage engine root path according the session WebsiteDataStore

Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h (221318 => 221319)


--- trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h	2017-08-29 22:49:50 UTC (rev 221319)
@@ -23,14 +23,19 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ArgumentCoder_h
-#define ArgumentCoder_h
+#pragma once
 
+#include <wtf/Optional.h>
+
 namespace IPC {
 
 class Decoder;
 class Encoder;
     
+template <typename... T> using IsUsingModernDecoder = void;
+template <typename T, typename = void> struct UsesModernDecoder : std::false_type { };
+template <typename T> struct UsesModernDecoder<T, IsUsingModernDecoder<typename T::ModernDecoder>> : std::true_type { };
+
 template<typename T> struct ArgumentCoder {
     static void encode(Encoder& encoder, const T& t)
     {
@@ -37,12 +42,17 @@
         t.encode(encoder);
     }
 
-    static bool decode(Decoder& decoder, T& t)
+    template<typename U = T, std::enable_if_t<!UsesModernDecoder<U>::value>* = nullptr>
+    static bool decode(Decoder& decoder, U& u)
     {
-        return T::decode(decoder, t);
+        return U::decode(decoder, u);
     }
+
+    template<typename U = T, std::enable_if_t<UsesModernDecoder<U>::value>* = nullptr>
+    static std::optional<U> decode(Decoder& decoder)
+    {
+        return U::decode(decoder);
+    }
 };
 
 }
-
-#endif // ArgumentCoder_h

Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h (221318 => 221319)


--- trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h	2017-08-29 22:49:50 UTC (rev 221319)
@@ -133,6 +133,7 @@
         TupleCoder<index - 1, Elements...>::encode(encoder, tuple);
     }
 
+    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>
     static bool decode(Decoder& decoder, std::tuple<Elements...>& tuple)
     {
         if (!decoder.decode(std::get<sizeof...(Elements) - index>(tuple)))
@@ -139,6 +140,17 @@
             return false;
         return TupleCoder<index - 1, Elements...>::decode(decoder, tuple);
     }
+    
+    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>
+    static bool decode(Decoder& decoder, std::tuple<Elements...>& tuple)
+    {
+        std::optional<U> optional;
+        decoder >> optional;
+        if (!optional)
+            return false;
+        std::get<sizeof...(Elements) - index>(tuple) = WTFMove(*optional);
+        return TupleCoder<index - 1, Elements...>::decode(decoder, tuple);
+    }
 };
 
 template<typename... Elements>

Modified: trunk/Source/WebKit/Platform/IPC/Decoder.h (221318 => 221319)


--- trunk/Source/WebKit/Platform/IPC/Decoder.h	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.h	2017-08-29 22:49:50 UTC (rev 221319)
@@ -123,12 +123,19 @@
         return bufferIsLargeEnoughToContain(alignof(T), numElements * sizeof(T));
     }
 
-    template<typename T>
-    auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>
+    template<typename T, std::enable_if_t<!std::is_enum<T>::value && !UsesModernDecoder<T>::value>* = nullptr>
+    bool decode(T& t)
     {
         return ArgumentCoder<T>::decode(*this, t);
     }
 
+    template<typename T, std::enable_if_t<UsesModernDecoder<T>::value>* = nullptr>
+    Decoder& operator>>(std::optional<T>& t)
+    {
+        t = ArgumentCoder<T>::decode(*this);
+        return *this;
+    }
+
     bool removeAttachment(Attachment&);
 
     static const bool isIPCDecoder = true;

Modified: trunk/Source/WebKit/Shared/API/APIPageGroupHandle.cpp (221318 => 221319)


--- trunk/Source/WebKit/Shared/API/APIPageGroupHandle.cpp	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Shared/API/APIPageGroupHandle.cpp	2017-08-29 22:49:50 UTC (rev 221319)
@@ -52,11 +52,12 @@
 
 bool PageGroupHandle::decode(IPC::Decoder& decoder, RefPtr<Object>& result)
 {
-    WebKit::WebPageGroupData webPageGroupData;
-    if (!decoder.decode(webPageGroupData))
+    std::optional<WebKit::WebPageGroupData> webPageGroupData;
+    decoder >> webPageGroupData;
+    if (!webPageGroupData)
         return false;
 
-    result = create(WTFMove(webPageGroupData));
+    result = create(WTFMove(*webPageGroupData));
     return true;
 }
 

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp (221318 => 221319)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2017-08-29 22:49:50 UTC (rev 221319)
@@ -108,156 +108,160 @@
 #endif
 }
 
-bool WebPageCreationParameters::decode(IPC::Decoder& decoder, WebPageCreationParameters& parameters)
+std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
 {
+    WebPageCreationParameters parameters;
     if (!decoder.decode(parameters.viewSize))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.activityState))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.store))
-        return false;
+        return std::nullopt;
     if (!decoder.decodeEnum(parameters.drawingAreaType))
-        return false;
-    if (!decoder.decode(parameters.pageGroupData))
-        return false;
+        return std::nullopt;
+    std::optional<WebPageGroupData> pageGroupData;
+    decoder >> pageGroupData;
+    if (!pageGroupData)
+        return std::nullopt;
+    parameters.pageGroupData = WTFMove(*pageGroupData);
     if (!decoder.decode(parameters.drawsBackground))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.isEditable))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.underlayColor))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.useFixedLayout))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.fixedLayoutSize))
-        return false;
+        return std::nullopt;
     if (!decoder.decodeEnum(parameters.paginationMode))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.paginationBehavesLikeColumns))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.pageLength))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.gapBetweenPages))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.paginationLineGridEnabled))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.userAgent))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.itemStates))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.sessionID))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.highestUsedBackForwardItemID))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.userContentControllerID))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.visitedLinkTableID))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.websiteDataStoreID))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.canRunBeforeUnloadConfirmPanel))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.canRunModal))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.deviceScaleFactor))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.viewScaleFactor))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.topContentInset))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.mediaVolume))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.muted))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.mayStartMediaWhenInWindow))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.minimumLayoutSize))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.autoSizingShouldExpandToViewHeight))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.viewportSizeForCSSViewportUnits))
-        return false;
+        return std::nullopt;
     if (!decoder.decodeEnum(parameters.scrollPinningBehavior))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.scrollbarOverlayStyle))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.backgroundExtendsBeyondPage))
-        return false;
+        return std::nullopt;
     if (!decoder.decodeEnum(parameters.layerHostingMode))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.mimeTypesWithCustomContentProviders))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.controlledByAutomation))
-        return false;
+        return std::nullopt;
 
 #if ENABLE(REMOTE_INSPECTOR)
     if (!decoder.decode(parameters.allowsRemoteInspection))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.remoteInspectionNameOverride))
-        return false;
+        return std::nullopt;
 #endif
 
 #if PLATFORM(MAC)
     if (!decoder.decode(parameters.colorSpace))
-        return false;
+        return std::nullopt;
 #endif
 
 #if PLATFORM(IOS)
     if (!decoder.decode(parameters.screenSize))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.availableScreenSize))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.textAutosizingWidth))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.ignoresViewportScaleLimits))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.allowsBlockSelection))
-        return false;
+        return std::nullopt;
 #endif
 
 #if PLATFORM(COCOA)
     if (!decoder.decode(parameters.smartInsertDeleteEnabled))
-        return false;
+        return std::nullopt;
 #endif
 
     if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.shouldScaleViewToFitDocument))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decodeEnum(parameters.userInterfaceLayoutDirection))
-        return false;
+        return std::nullopt;
     if (!decoder.decodeEnum(parameters.observedLayoutMilestones))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.overrideContentSecurityPolicy))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.cpuLimit))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.urlSchemeHandlers))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.iceCandidateFilteringEnabled))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.enumeratingAllNetworkInterfacesEnabled))
-        return false;
+        return std::nullopt;
 
     if (!decoder.decode(parameters.userContentWorlds))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.userScripts))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.userStyleSheets))
-        return false;
+        return std::nullopt;
     if (!decoder.decode(parameters.messageHandlers))
-        return false;
+        return std::nullopt;
 #if ENABLE(CONTENT_EXTENSIONS)
     if (!decoder.decode(parameters.contentRuleLists))
-        return false;
+        return std::nullopt;
 #endif
-    return true;
+    return WTFMove(parameters);
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.h (221318 => 221319)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2017-08-29 22:49:50 UTC (rev 221319)
@@ -59,7 +59,8 @@
 
 struct WebPageCreationParameters {
     void encode(IPC::Encoder&) const;
-    static bool decode(IPC::Decoder&, WebPageCreationParameters&);
+    static std::optional<WebPageCreationParameters> decode(IPC::Decoder&);
+    using ModernDecoder = std::true_type;
 
     WebCore::IntSize viewSize;
 

Modified: trunk/Source/WebKit/Shared/WebPageGroupData.cpp (221318 => 221319)


--- trunk/Source/WebKit/Shared/WebPageGroupData.cpp	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Shared/WebPageGroupData.cpp	2017-08-29 22:49:50 UTC (rev 221319)
@@ -39,19 +39,24 @@
     encoder << userContentControllerIdentifier;
 }
 
-bool WebPageGroupData::decode(IPC::Decoder& decoder, WebPageGroupData& data)
+std::optional<WebPageGroupData> WebPageGroupData::decode(IPC::Decoder& decoder)
 {
-    if (!decoder.decode(data.identifier))
-        return false;
-    if (!decoder.decode(data.pageGroupID))
-        return false;
-    if (!decoder.decode(data.visibleToInjectedBundle))
-        return false;
-    if (!decoder.decode(data.visibleToHistoryClient))
-        return false;
-    if (!decoder.decode(data.userContentControllerIdentifier))
-        return false;
-    return true;
+    String id;
+    if (!decoder.decode(id))
+        return std::nullopt;
+    uint64_t pageGroupID;
+    if (!decoder.decode(pageGroupID))
+        return std::nullopt;
+    bool visibleToInjectedBundle;
+    if (!decoder.decode(visibleToInjectedBundle))
+        return std::nullopt;
+    bool visibleToHistoryClient;
+    if (!decoder.decode(visibleToHistoryClient))
+        return std::nullopt;
+    uint64_t userContentControllerIdentifier;
+    if (!decoder.decode(userContentControllerIdentifier))
+        return std::nullopt;
+    return { { id, pageGroupID, visibleToInjectedBundle, visibleToHistoryClient, userContentControllerIdentifier } };
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/WebPageGroupData.h (221318 => 221319)


--- trunk/Source/WebKit/Shared/WebPageGroupData.h	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Shared/WebPageGroupData.h	2017-08-29 22:49:50 UTC (rev 221319)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebPageGroupData_h
-#define WebPageGroupData_h
+#pragma once
 
 #include <wtf/text/WTFString.h>
 
@@ -37,7 +36,8 @@
 
 struct WebPageGroupData {
     void encode(IPC::Encoder&) const;
-    static bool decode(IPC::Decoder&, WebPageGroupData&);
+    static std::optional<WebPageGroupData> decode(IPC::Decoder&);
+    using ModernDecoder = std::true_type;
 
     String identifier;
     uint64_t pageGroupID;
@@ -48,6 +48,3 @@
 };
 
 } // namespace WebKit
-
-
-#endif // WebPageGroupData_h

Modified: trunk/Source/WebKit/Shared/WebsitePolicies.h (221318 => 221319)


--- trunk/Source/WebKit/Shared/WebsitePolicies.h	2017-08-29 22:34:17 UTC (rev 221318)
+++ trunk/Source/WebKit/Shared/WebsitePolicies.h	2017-08-29 22:49:50 UTC (rev 221319)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <wtf/OptionSet.h>
+#include <wtf/Optional.h>
 
 namespace WebKit {
 
@@ -48,7 +49,8 @@
     WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default };
 
     template<class Encoder> void encode(Encoder&) const;
-    template<class Decoder> static bool decode(Decoder&, WebsitePolicies&);
+    template<class Decoder> static std::optional<WebsitePolicies> decode(Decoder&);
+    using ModernDecoder = std::true_type;
 };
 
 template<class Encoder> void WebsitePolicies::encode(Encoder& encoder) const
@@ -58,15 +60,21 @@
     encoder << allowedAutoplayQuirks;
 }
 
-template<class Decoder> bool WebsitePolicies::decode(Decoder& decoder, WebsitePolicies& result)
+template<class Decoder> std::optional<WebsitePolicies> WebsitePolicies::decode(Decoder& decoder)
 {
-    if (!decoder.decode(result.contentBlockersEnabled))
-        return false;
-    if (!decoder.decodeEnum(result.autoplayPolicy))
-        return false;
-    if (!decoder.decode(result.allowedAutoplayQuirks))
-        return false;
-    return true;
+    bool contentBlockersEnabled;
+    if (!decoder.decode(contentBlockersEnabled))
+        return std::nullopt;
+    
+    WebsiteAutoplayPolicy autoplayPolicy;
+    if (!decoder.decodeEnum(autoplayPolicy))
+        return std::nullopt;
+
+    OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
+    if (!decoder.decode(allowedAutoplayQuirks))
+        return std::nullopt;
+
+    return { { contentBlockersEnabled, allowedAutoplayQuirks, autoplayPolicy } };
 }
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to