<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[280769] trunk/Source/WebKit</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/280769">280769</a></dd>
<dt>Author</dt> <dd>ifernandez@igalia.com</dd>
<dt>Date</dt> <dd>2021-08-09 02:58:22 -0700 (Mon, 09 Aug 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow custom IPC::Attachment messaging in ConnectionUnix.cpp
https://bugs.webkit.org/show_bug.cgi?id=227740

Reviewed by Žan Doberšek.

In order to share AHardwareBuffer handles via IPC we need to use the AHardwareBuffer_sendHandleToUnixSocket()
and AHardwareBuffer_recvHandleFromUnixSocket() functions. This is not currently compatible with the Attachment
API used in UnixConnection, as those functions use custom messaging into the socked fd.

This patch adds a CustomWriterType Attachment that allows custom messaging going into the socket fd.

* Platform/IPC/unix/ConnectionUnix.cpp:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCAttachmenth">trunk/Source/WebKit/Platform/IPC/Attachment.h</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCunixAttachmentUnixcpp">trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCunixConnectionUnixcpp">trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (280768 => 280769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-08-09 02:09:10 UTC (rev 280768)
+++ trunk/Source/WebKit/ChangeLog       2021-08-09 09:58:22 UTC (rev 280769)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2021-08-09  Imanol Fernandez  <ifernandez@igalia.com>
+
+        Allow custom IPC::Attachment messaging in ConnectionUnix.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=227740
+
+        Reviewed by Žan Doberšek.
+
+        In order to share AHardwareBuffer handles via IPC we need to use the AHardwareBuffer_sendHandleToUnixSocket()
+        and AHardwareBuffer_recvHandleFromUnixSocket() functions. This is not currently compatible with the Attachment
+        API used in UnixConnection, as those functions use custom messaging into the socked fd.
+
+        This patch adds a CustomWriterType Attachment that allows custom messaging going into the socket fd.
+
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+
</ins><span class="cx"> 2021-08-08  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         caret-color does not work on first click in ios
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCAttachmenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/Attachment.h (280768 => 280769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/Attachment.h    2021-08-09 02:09:10 UTC (rev 280768)
+++ trunk/Source/WebKit/Platform/IPC/Attachment.h       2021-08-09 09:58:22 UTC (rev 280769)
</span><span class="lines">@@ -35,6 +35,11 @@
</span><span class="cx"> #include <windows.h>
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(UNIX_DOMAIN_SOCKETS)
+#include <wtf/Function.h>
+#include <wtf/Variant.h>
+#endif
+
</ins><span class="cx"> namespace IPC {
</span><span class="cx"> 
</span><span class="cx"> class Decoder;
</span><span class="lines">@@ -49,6 +54,7 @@
</span><span class="cx"> #if USE(UNIX_DOMAIN_SOCKETS)
</span><span class="cx">         SocketType,
</span><span class="cx">         MappedMemoryType,
</span><ins>+        CustomWriterType,
</ins><span class="cx"> #elif OS(DARWIN)
</span><span class="cx">         MachPortType
</span><span class="cx"> #endif
</span><span class="lines">@@ -60,6 +66,11 @@
</span><span class="cx">     Attachment(int fileDescriptor, size_t);
</span><span class="cx">     Attachment(int fileDescriptor);
</span><span class="cx">     ~Attachment();
</span><ins>+
+    using SocketDescriptor = int;
+    using CustomWriterFunc = WTF::Function<void(SocketDescriptor)>;
+    using CustomWriter = Variant<CustomWriterFunc, SocketDescriptor>;
+    Attachment(CustomWriter&&);
</ins><span class="cx"> #elif OS(DARWIN)
</span><span class="cx">     Attachment(mach_port_name_t, mach_msg_type_name_t disposition);
</span><span class="cx"> #elif OS(WINDOWS)
</span><span class="lines">@@ -75,6 +86,7 @@
</span><span class="cx"> 
</span><span class="cx">     int releaseFileDescriptor() { int temp = m_fileDescriptor; m_fileDescriptor = -1; return temp; }
</span><span class="cx">     int fileDescriptor() const { return m_fileDescriptor; }
</span><ins>+    const CustomWriter& customWriter() const { return m_customWriter; }
</ins><span class="cx"> #elif OS(DARWIN)
</span><span class="cx">     void release();
</span><span class="cx"> 
</span><span class="lines">@@ -94,6 +106,7 @@
</span><span class="cx"> #if USE(UNIX_DOMAIN_SOCKETS)
</span><span class="cx">     int m_fileDescriptor { -1 };
</span><span class="cx">     size_t m_size;
</span><ins>+    CustomWriter m_customWriter;
</ins><span class="cx"> #elif OS(DARWIN)
</span><span class="cx">     mach_port_name_t m_port { 0 };
</span><span class="cx">     mach_msg_type_name_t m_disposition { 0 };
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCunixAttachmentUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp (280768 => 280769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp 2021-08-09 02:09:10 UTC (rev 280768)
+++ trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp    2021-08-09 09:58:22 UTC (rev 280769)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx">     : m_type(attachment.m_type)
</span><span class="cx">     , m_fileDescriptor(attachment.m_fileDescriptor)
</span><span class="cx">     , m_size(attachment.m_size)
</span><ins>+    , m_customWriter(WTFMove(attachment.m_customWriter))
</ins><span class="cx"> {
</span><span class="cx">     attachment.m_type = Uninitialized;
</span><span class="cx">     attachment.m_fileDescriptor = -1;
</span><span class="lines">@@ -55,6 +56,14 @@
</span><span class="cx">     attachment.m_size = 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Attachment::Attachment(CustomWriter&& writer)
+    : m_type(CustomWriterType)
+    , m_fileDescriptor(-1)
+    , m_size(0)
+    , m_customWriter(WTFMove(writer))
+{
+}
+
</ins><span class="cx"> Attachment& Attachment::operator=(Attachment&& attachment)
</span><span class="cx"> {
</span><span class="cx">     m_type = attachment.m_type;
</span><span class="lines">@@ -63,6 +72,7 @@
</span><span class="cx">     attachment.m_fileDescriptor = -1;
</span><span class="cx">     m_size = attachment.m_size;
</span><span class="cx">     attachment.m_size = 0;
</span><ins>+    m_customWriter = WTFMove(attachment.m_customWriter);
</ins><span class="cx"> 
</span><span class="cx">     return *this;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCunixConnectionUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp (280768 => 280769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp 2021-08-09 02:09:10 UTC (rev 280768)
+++ trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp    2021-08-09 09:58:22 UTC (rev 280769)
</span><span class="lines">@@ -206,6 +206,9 @@
</span><span class="cx">                 fd = m_fileDescriptors[fdIndex++];
</span><span class="cx">             attachments[attachmentCount - i - 1] = Attachment(fd);
</span><span class="cx">             break;
</span><ins>+        case Attachment::CustomWriterType:
+            attachments[attachmentCount - i - 1] = Attachment(Attachment::CustomWriter(m_socketDescriptor));
+            break;
</ins><span class="cx">         case Attachment::Uninitialized:
</span><span class="cx">             attachments[attachmentCount - i - 1] = Attachment();
</span><span class="cx">         default:
</span><span class="lines">@@ -473,6 +476,7 @@
</span><span class="cx"> 
</span><span class="cx">     Vector<AttachmentInfo> attachmentInfo;
</span><span class="cx">     MallocPtr<char> attachmentFDBuffer;
</span><ins>+    bool hasCustomWriterAttachments { false };
</ins><span class="cx"> 
</span><span class="cx">     auto& attachments = outputMessage.attachments();
</span><span class="cx">     if (!attachments.isEmpty()) {
</span><span class="lines">@@ -514,6 +518,9 @@
</span><span class="cx">                 } else
</span><span class="cx">                     attachmentInfo[i].setNull();
</span><span class="cx">                 break;
</span><ins>+            case Attachment::CustomWriterType:
+                hasCustomWriterAttachments = true;
+                break;
</ins><span class="cx">             case Attachment::Uninitialized:
</span><span class="cx">             default:
</span><span class="cx">                 break;
</span><span class="lines">@@ -581,6 +588,16 @@
</span><span class="cx">             WTFLogAlways("Error sending IPC message: %s", strerror(errno));
</span><span class="cx">         return false;
</span><span class="cx">     }
</span><ins>+
+    if (hasCustomWriterAttachments) {
+        for (auto& attachment : attachments) {
+            if (attachment.type() == Attachment::CustomWriterType) {
+                ASSERT(WTF::holds_alternative<Attachment::CustomWriterFunc>(attachment.customWriter()));
+                WTF::get<Attachment::CustomWriterFunc>(attachment.customWriter())(m_socketDescriptor);
+            }
+        }
+    }
+
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>