- Revision
- 262075
- Author
- [email protected]
- Date
- 2020-05-22 14:45:47 -0700 (Fri, 22 May 2020)
Log Message
[IPC] Add support for specifying `Async WantsConnection` in message files
https://bugs.webkit.org/show_bug.cgi?id=212276
Reviewed by Alex Christensen.
Augments the IPC message receiver generation script to allow for "Async WantsConnection" in `.message.in` files.
Currently, specifying this in a message causes the `connection` argument to be passed twice when handling the
IPC message. This is because normal async IPC messages without replies normally don't have the `IPC::Connection`
argument, and use the overloaded `handleMessage(Connection& connection, ...)` version of `handleMessage` when
`WantsConnection` is specified.
However, in the `Async` reply case, we already pass in the `IPC::Connection`. Instead of overloading the method
signature, we introduce a different method instead, named `handleMessageAsyncWantsConnection`, which forwards
the given `IPC::Connection` along to the member function.
Test: TestAsyncMessageWithConnection
* Platform/IPC/HandleMessage.h:
(IPC::handleMessageAsyncWantsConnection):
Add another variant of the message receiver template, for the case where the message receiver wants a connection.
This is similar to handleMessageSynchronousWantsConnection, above.
* Scripts/test-superclassMessageReceiver.cpp:
(Messages::WebPage::TestAsyncMessageWithConnection::callReply):
(Messages::WebPage::TestAsyncMessageWithConnection::cancelReply):
(Messages::WebPage::TestAsyncMessageWithConnection::send):
(WebKit::WebPage::didReceiveMessage):
* Scripts/test-superclassMessages.h:
(Messages::WebPage::TestAsyncMessageWithConnection::name):
(Messages::WebPage::TestAsyncMessageWithConnection::asyncMessageReplyName):
(Messages::WebPage::TestAsyncMessageWithConnection::TestAsyncMessageWithConnection):
(Messages::WebPage::TestAsyncMessageWithConnection::arguments const):
* Scripts/webkit/messages.py:
* Scripts/webkit/messages_unittest.py:
* Scripts/webkit/test-superclass.messages.in:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (262074 => 262075)
--- trunk/Source/WebKit/ChangeLog 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/ChangeLog 2020-05-22 21:45:47 UTC (rev 262075)
@@ -1,3 +1,42 @@
+2020-05-22 Wenson Hsieh <[email protected]>
+
+ [IPC] Add support for specifying `Async WantsConnection` in message files
+ https://bugs.webkit.org/show_bug.cgi?id=212276
+
+ Reviewed by Alex Christensen.
+
+ Augments the IPC message receiver generation script to allow for "Async WantsConnection" in `.message.in` files.
+ Currently, specifying this in a message causes the `connection` argument to be passed twice when handling the
+ IPC message. This is because normal async IPC messages without replies normally don't have the `IPC::Connection`
+ argument, and use the overloaded `handleMessage(Connection& connection, ...)` version of `handleMessage` when
+ `WantsConnection` is specified.
+
+ However, in the `Async` reply case, we already pass in the `IPC::Connection`. Instead of overloading the method
+ signature, we introduce a different method instead, named `handleMessageAsyncWantsConnection`, which forwards
+ the given `IPC::Connection` along to the member function.
+
+ Test: TestAsyncMessageWithConnection
+
+ * Platform/IPC/HandleMessage.h:
+ (IPC::handleMessageAsyncWantsConnection):
+
+ Add another variant of the message receiver template, for the case where the message receiver wants a connection.
+ This is similar to handleMessageSynchronousWantsConnection, above.
+
+ * Scripts/test-superclassMessageReceiver.cpp:
+ (Messages::WebPage::TestAsyncMessageWithConnection::callReply):
+ (Messages::WebPage::TestAsyncMessageWithConnection::cancelReply):
+ (Messages::WebPage::TestAsyncMessageWithConnection::send):
+ (WebKit::WebPage::didReceiveMessage):
+ * Scripts/test-superclassMessages.h:
+ (Messages::WebPage::TestAsyncMessageWithConnection::name):
+ (Messages::WebPage::TestAsyncMessageWithConnection::asyncMessageReplyName):
+ (Messages::WebPage::TestAsyncMessageWithConnection::TestAsyncMessageWithConnection):
+ (Messages::WebPage::TestAsyncMessageWithConnection::arguments const):
+ * Scripts/webkit/messages.py:
+ * Scripts/webkit/messages_unittest.py:
+ * Scripts/webkit/test-superclass.messages.in:
+
2020-05-22 Tim Horton <[email protected]>
Excessive hang time in iOS Safari under waitForDidUpdateActivityState
Modified: trunk/Source/WebKit/Platform/IPC/HandleMessage.h (262074 => 262075)
--- trunk/Source/WebKit/Platform/IPC/HandleMessage.h 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/Platform/IPC/HandleMessage.h 2020-05-22 21:45:47 UTC (rev 262075)
@@ -183,4 +183,29 @@
callMemberFunction(WTFMove(*arguments), WTFMove(completionHandler), object, function);
}
+template<typename T, typename C, typename MF>
+void handleMessageAsyncWantsConnection(Connection& connection, Decoder& decoder, C* object, MF function)
+{
+ Optional<uint64_t> listenerID;
+ decoder >> listenerID;
+ if (!listenerID) {
+ decoder.markInvalid();
+ return;
+ }
+
+ Optional<typename CodingType<typename T::Arguments>::Type> arguments;
+ decoder >> arguments;
+ if (!arguments) {
+ decoder.markInvalid();
+ return;
+ }
+
+ typename T::AsyncReply completionHandler = [listenerID = *listenerID, connection = makeRef(connection)] (auto&&... args) mutable {
+ auto encoder = makeUnique<Encoder>(T::asyncMessageReplyName(), 0);
+ *encoder << listenerID;
+ T::send(WTFMove(encoder), WTFMove(connection), args...);
+ };
+ callMemberFunction(connection, WTFMove(*arguments), WTFMove(completionHandler), object, function);
+}
+
} // namespace IPC
Modified: trunk/Source/WebKit/Scripts/test-superclassMessageReceiver.cpp (262074 => 262075)
--- trunk/Source/WebKit/Scripts/test-superclassMessageReceiver.cpp 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/Scripts/test-superclassMessageReceiver.cpp 2020-05-22 21:45:47 UTC (rev 262075)
@@ -122,6 +122,33 @@
#endif
+#if ENABLE(TEST_FEATURE)
+
+void TestAsyncMessageWithConnection::callReply(IPC::Decoder& decoder, CompletionHandler<void(bool&&)>&& completionHandler)
+{
+ Optional<bool> flag;
+ decoder >> flag;
+ if (!flag) {
+ ASSERT_NOT_REACHED();
+ cancelReply(WTFMove(completionHandler));
+ return;
+ }
+ completionHandler(WTFMove(*flag));
+}
+
+void TestAsyncMessageWithConnection::cancelReply(CompletionHandler<void(bool&&)>&& completionHandler)
+{
+ completionHandler(IPC::AsyncReplyError<bool>::create());
+}
+
+void TestAsyncMessageWithConnection::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, bool flag)
+{
+ *encoder << flag;
+ connection.sendSyncReply(WTFMove(encoder));
+}
+
+#endif
+
void TestSyncMessage::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, uint8_t reply)
{
*encoder << reply;
@@ -165,6 +192,12 @@
return;
}
#endif
+#if ENABLE(TEST_FEATURE)
+ if (decoder.messageName() == Messages::WebPage::TestAsyncMessageWithConnection::name()) {
+ IPC::handleMessageAsyncWantsConnection<Messages::WebPage::TestAsyncMessageWithConnection>(connection, decoder, this, &WebPage::testAsyncMessageWithConnection);
+ return;
+ }
+#endif
WebPageBase::didReceiveMessage(connection, decoder);
}
Modified: trunk/Source/WebKit/Scripts/test-superclassMessages.h (262074 => 262075)
--- trunk/Source/WebKit/Scripts/test-superclassMessages.h 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/Scripts/test-superclassMessages.h 2020-05-22 21:45:47 UTC (rev 262075)
@@ -147,6 +147,36 @@
};
#endif
+#if ENABLE(TEST_FEATURE)
+class TestAsyncMessageWithConnection {
+public:
+ typedef std::tuple<const int&> Arguments;
+
+ static IPC::MessageName name() { return IPC::MessageName::WebPage_TestAsyncMessageWithConnection; }
+ static const bool isSync = false;
+
+ static void callReply(IPC::Decoder&, CompletionHandler<void(bool&&)>&&);
+ static void cancelReply(CompletionHandler<void(bool&&)>&&);
+ static IPC::MessageName asyncMessageReplyName() { return IPC::MessageName::WebPage_TestAsyncMessageWithConnectionReply; }
+ using AsyncReply = TestAsyncMessageWithConnectionAsyncReply;
+ static void send(std::unique_ptr<IPC::Encoder>&&, IPC::Connection&, bool flag);
+ using Reply = std::tuple<bool&>;
+ using ReplyArguments = std::tuple<bool>;
+ explicit TestAsyncMessageWithConnection(const int& value)
+ : m_arguments(value)
+ {
+ }
+
+ const Arguments& arguments() const
+ {
+ return m_arguments;
+ }
+
+private:
+ Arguments m_arguments;
+};
+#endif
+
class TestSyncMessage {
public:
typedef std::tuple<uint32_t> Arguments;
Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (262074 => 262075)
--- trunk/Source/WebKit/Scripts/webkit/messages.py 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py 2020-05-22 21:45:47 UTC (rev 262075)
@@ -474,7 +474,10 @@
dispatch_function_args.insert(0, 'connection')
if message.has_attribute(WANTS_CONNECTION_ATTRIBUTE):
- dispatch_function_args.insert(0, 'connection')
+ if message.has_attribute(ASYNC_ATTRIBUTE):
+ dispatch_function += 'WantsConnection'
+ else:
+ dispatch_function_args.insert(0, 'connection')
result = []
result.append(' if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
Modified: trunk/Source/WebKit/Scripts/webkit/messages_unittest.py (262074 => 262075)
--- trunk/Source/WebKit/Scripts/webkit/messages_unittest.py 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/Scripts/webkit/messages_unittest.py 2020-05-22 21:45:47 UTC (rev 262075)
@@ -275,6 +275,16 @@
'conditions': ('ENABLE(TEST_FEATURE)'),
},
{
+ 'name': 'TestAsyncMessageWithConnection',
+ 'parameters': (
+ ('int', 'value'),
+ ),
+ 'reply_parameters': (
+ ('bool', 'flag'),
+ ),
+ 'conditions': ('ENABLE(TEST_FEATURE)'),
+ },
+ {
'name': 'TestSyncMessage',
'parameters': (
('uint32_t', 'param'),
Modified: trunk/Source/WebKit/Scripts/webkit/test-superclass.messages.in (262074 => 262075)
--- trunk/Source/WebKit/Scripts/webkit/test-superclass.messages.in 2020-05-22 21:30:30 UTC (rev 262074)
+++ trunk/Source/WebKit/Scripts/webkit/test-superclass.messages.in 2020-05-22 21:45:47 UTC (rev 262075)
@@ -26,6 +26,7 @@
TestAsyncMessage(enum:bool WebKit::TestTwoStateEnum twoStateEnum) -> (uint64_t result) Async
TestAsyncMessageWithNoArguments() -> () Async
TestAsyncMessageWithMultipleArguments() -> (bool flag, uint64_t value) Async
+ TestAsyncMessageWithConnection(int value) -> (bool flag) Async WantsConnection
#endif
TestSyncMessage(uint32_t param) -> (uint8_t reply) Synchronous
TestSynchronousMessage(bool value) -> (Optional<WebKit::TestClassName> optionalReply) Synchronous