Title: [221698] trunk/Source/WebKit
Revision
221698
Author
[email protected]
Date
2017-09-06 13:26:43 -0700 (Wed, 06 Sep 2017)

Log Message

Add modern decoders for POD types
https://bugs.webkit.org/show_bug.cgi?id=176456

Reviewed by Geoffrey Garen.

* Platform/IPC/Decoder.cpp:
(IPC::Decoder::getOptional):
(IPC::Decoder::operator>>):
* Platform/IPC/Decoder.h:
* Shared/NavigationActionData.cpp:
(WebKit::NavigationActionData::decode):
* Shared/NavigationActionData.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (221697 => 221698)


--- trunk/Source/WebKit/ChangeLog	2017-09-06 20:24:56 UTC (rev 221697)
+++ trunk/Source/WebKit/ChangeLog	2017-09-06 20:26:43 UTC (rev 221698)
@@ -1,5 +1,20 @@
 2017-09-06  Alex Christensen  <[email protected]>
 
+        Add modern decoders for POD types
+        https://bugs.webkit.org/show_bug.cgi?id=176456
+
+        Reviewed by Geoffrey Garen.
+
+        * Platform/IPC/Decoder.cpp:
+        (IPC::Decoder::getOptional):
+        (IPC::Decoder::operator>>):
+        * Platform/IPC/Decoder.h:
+        * Shared/NavigationActionData.cpp:
+        (WebKit::NavigationActionData::decode):
+        * Shared/NavigationActionData.h:
+
+2017-09-06  Alex Christensen  <[email protected]>
+
         Add WKUIDelegatePrivate equivalent of WKPageUIClient's pinnedStateDidChange
         https://bugs.webkit.org/show_bug.cgi?id=176474
         <rdar://problem/29270035>

Modified: trunk/Source/WebKit/Platform/IPC/Decoder.cpp (221697 => 221698)


--- trunk/Source/WebKit/Platform/IPC/Decoder.cpp	2017-09-06 20:24:56 UTC (rev 221697)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.cpp	2017-09-06 20:26:43 UTC (rev 221698)
@@ -188,6 +188,63 @@
     bufferPosition += sizeof(Type);
 }
 
+template<typename Type>
+Decoder& Decoder::getOptional(std::optional<Type>& optional)
+{
+    Type result;
+    if (!alignBufferPosition(sizeof(result), sizeof(result)))
+        return *this;
+    
+    decodeValueFromBuffer(result, m_bufferPos);
+    optional = result;
+    return *this;
+}
+
+Decoder& Decoder::operator>>(std::optional<bool>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<uint8_t>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<uint16_t>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<uint32_t>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<uint64_t>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<int32_t>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<int64_t>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<float>& optional)
+{
+    return getOptional(optional);
+}
+
+Decoder& Decoder::operator>>(std::optional<double>& optional)
+{
+    return getOptional(optional);
+}
+
 bool Decoder::decode(bool& result)
 {
     if (!alignBufferPosition(sizeof(result), sizeof(result)))

Modified: trunk/Source/WebKit/Platform/IPC/Decoder.h (221697 => 221698)


--- trunk/Source/WebKit/Platform/IPC/Decoder.h	2017-09-06 20:24:56 UTC (rev 221697)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.h	2017-09-06 20:26:43 UTC (rev 221698)
@@ -78,14 +78,23 @@
     bool decodeVariableLengthByteArray(DataReference&);
 
     bool decode(bool&);
+    Decoder& operator>>(std::optional<bool>&);
     bool decode(uint8_t&);
+    Decoder& operator>>(std::optional<uint8_t>&);
     bool decode(uint16_t&);
+    Decoder& operator>>(std::optional<uint16_t>&);
     bool decode(uint32_t&);
+    Decoder& operator>>(std::optional<uint32_t>&);
     bool decode(uint64_t&);
+    Decoder& operator>>(std::optional<uint64_t>&);
     bool decode(int32_t&);
+    Decoder& operator>>(std::optional<int32_t>&);
     bool decode(int64_t&);
+    Decoder& operator>>(std::optional<int64_t>&);
     bool decode(float&);
+    Decoder& operator>>(std::optional<float>&);
     bool decode(double&);
+    Decoder& operator>>(std::optional<double>&);
 
     template<typename E>
     auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool>
@@ -143,6 +152,7 @@
 private:
     bool alignBufferPosition(unsigned alignment, size_t);
     bool bufferIsLargeEnoughToContain(unsigned alignment, size_t) const;
+    template<typename Type> Decoder& getOptional(std::optional<Type>&);
 
     const uint8_t* m_buffer;
     const uint8_t* m_bufferPos;

Modified: trunk/Source/WebKit/Shared/NavigationActionData.cpp (221697 => 221698)


--- trunk/Source/WebKit/Shared/NavigationActionData.cpp	2017-09-06 20:24:56 UTC (rev 221697)
+++ trunk/Source/WebKit/Shared/NavigationActionData.cpp	2017-09-06 20:26:43 UTC (rev 221698)
@@ -49,30 +49,53 @@
     encoder << isRedirect;
 }
 
-bool NavigationActionData::decode(IPC::Decoder& decoder, NavigationActionData& result)
+std::optional<NavigationActionData> NavigationActionData::decode(IPC::Decoder& decoder)
 {
-    if (!decoder.decodeEnum(result.navigationType))
-        return false;
-    if (!decoder.decodeEnum(result.modifiers))
-        return false;
-    if (!decoder.decodeEnum(result.mouseButton))
-        return false;
-    if (!decoder.decodeEnum(result.syntheticClickType))
-        return false;
-    if (!decoder.decode(result.userGestureTokenIdentifier))
-        return false;
-    if (!decoder.decode(result.canHandleRequest))
-        return false;
-    if (!decoder.decodeEnum(result.shouldOpenExternalURLsPolicy))
-        return false;
-    if (!decoder.decode(result.downloadAttribute))
-        return false;
-    if (!decoder.decode(result.clickLocationInRootViewCoordinates))
-        return false;
-    if (!decoder.decode(result.isRedirect))
-        return false;
+    WebCore::NavigationType navigationType;
+    if (!decoder.decodeEnum(navigationType))
+        return std::nullopt;
+    
+    WebEvent::Modifiers modifiers;
+    if (!decoder.decodeEnum(modifiers))
+        return std::nullopt;
+    
+    WebMouseEvent::Button mouseButton;
+    if (!decoder.decodeEnum(mouseButton))
+        return std::nullopt;
+    
+    WebMouseEvent::SyntheticClickType syntheticClickType;
+    if (!decoder.decodeEnum(syntheticClickType))
+        return std::nullopt;
+    
+    std::optional<uint64_t> userGestureTokenIdentifier;
+    decoder >> userGestureTokenIdentifier;
+    if (!userGestureTokenIdentifier)
+        return std::nullopt;
+    
+    std::optional<bool> canHandleRequest;
+    decoder >> canHandleRequest;
+    if (!canHandleRequest)
+        return std::nullopt;
+    
+    WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy;
+    if (!decoder.decodeEnum(shouldOpenExternalURLsPolicy))
+        return std::nullopt;
+    
+    std::optional<String> downloadAttribute;
+    decoder >> downloadAttribute;
+    if (!downloadAttribute)
+        return std::nullopt;
+    
+    WebCore::FloatPoint clickLocationInRootViewCoordinates;
+    if (!decoder.decode(clickLocationInRootViewCoordinates))
+        return std::nullopt;
+    
+    std::optional<bool> isRedirect;
+    decoder >> isRedirect;
+    if (!isRedirect)
+        return std::nullopt;
 
-    return true;
+    return {{ WTFMove(navigationType), WTFMove(modifiers), WTFMove(mouseButton), WTFMove(syntheticClickType), WTFMove(*userGestureTokenIdentifier), WTFMove(*canHandleRequest), WTFMove(shouldOpenExternalURLsPolicy), WTFMove(*downloadAttribute), WTFMove(clickLocationInRootViewCoordinates), WTFMove(*isRedirect) }};
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/NavigationActionData.h (221697 => 221698)


--- trunk/Source/WebKit/Shared/NavigationActionData.h	2017-09-06 20:24:56 UTC (rev 221697)
+++ trunk/Source/WebKit/Shared/NavigationActionData.h	2017-09-06 20:26:43 UTC (rev 221698)
@@ -38,7 +38,7 @@
 
 struct NavigationActionData {
     void encode(IPC::Encoder&) const;
-    static bool decode(IPC::Decoder&, NavigationActionData&);
+    static std::optional<NavigationActionData> decode(IPC::Decoder&);
 
     WebCore::NavigationType navigationType { WebCore::NavigationType::Other };
     WebEvent::Modifiers modifiers { };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to