Changeset 262075 in webkit


Ignore:
Timestamp:
May 22, 2020 2:45:47 PM (4 years ago)
Author:
Wenson Hsieh
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:
Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r262071 r262075  
     12020-05-22  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [IPC] Add support for specifying `Async WantsConnection` in message files
     4        https://bugs.webkit.org/show_bug.cgi?id=212276
     5
     6        Reviewed by Alex Christensen.
     7
     8        Augments the IPC message receiver generation script to allow for "Async WantsConnection" in `.message.in` files.
     9        Currently, specifying this in a message causes the `connection` argument to be passed twice when handling the
     10        IPC message. This is because normal async IPC messages without replies normally don't have the `IPC::Connection`
     11        argument, and use the overloaded `handleMessage(Connection& connection, ...)` version of `handleMessage` when
     12        `WantsConnection` is specified.
     13
     14        However, in the `Async` reply case, we already pass in the `IPC::Connection`. Instead of overloading the method
     15        signature, we introduce a different method instead, named `handleMessageAsyncWantsConnection`, which forwards
     16        the given `IPC::Connection` along to the member function.
     17
     18        Test: TestAsyncMessageWithConnection
     19
     20        * Platform/IPC/HandleMessage.h:
     21        (IPC::handleMessageAsyncWantsConnection):
     22
     23        Add another variant of the message receiver template, for the case where the message receiver wants a connection.
     24        This is similar to handleMessageSynchronousWantsConnection, above.
     25
     26        * Scripts/test-superclassMessageReceiver.cpp:
     27        (Messages::WebPage::TestAsyncMessageWithConnection::callReply):
     28        (Messages::WebPage::TestAsyncMessageWithConnection::cancelReply):
     29        (Messages::WebPage::TestAsyncMessageWithConnection::send):
     30        (WebKit::WebPage::didReceiveMessage):
     31        * Scripts/test-superclassMessages.h:
     32        (Messages::WebPage::TestAsyncMessageWithConnection::name):
     33        (Messages::WebPage::TestAsyncMessageWithConnection::asyncMessageReplyName):
     34        (Messages::WebPage::TestAsyncMessageWithConnection::TestAsyncMessageWithConnection):
     35        (Messages::WebPage::TestAsyncMessageWithConnection::arguments const):
     36        * Scripts/webkit/messages.py:
     37        * Scripts/webkit/messages_unittest.py:
     38        * Scripts/webkit/test-superclass.messages.in:
     39
    1402020-05-22  Tim Horton  <timothy_horton@apple.com>
    241
  • trunk/Source/WebKit/Platform/IPC/HandleMessage.h

    r261254 r262075  
    184184}
    185185
     186template<typename T, typename C, typename MF>
     187void handleMessageAsyncWantsConnection(Connection& connection, Decoder& decoder, C* object, MF function)
     188{
     189    Optional<uint64_t> listenerID;
     190    decoder >> listenerID;
     191    if (!listenerID) {
     192        decoder.markInvalid();
     193        return;
     194    }
     195
     196    Optional<typename CodingType<typename T::Arguments>::Type> arguments;
     197    decoder >> arguments;
     198    if (!arguments) {
     199        decoder.markInvalid();
     200        return;
     201    }
     202
     203    typename T::AsyncReply completionHandler = [listenerID = *listenerID, connection = makeRef(connection)] (auto&&... args) mutable {
     204        auto encoder = makeUnique<Encoder>(T::asyncMessageReplyName(), 0);
     205        *encoder << listenerID;
     206        T::send(WTFMove(encoder), WTFMove(connection), args...);
     207    };
     208    callMemberFunction(connection, WTFMove(*arguments), WTFMove(completionHandler), object, function);
     209}
     210
    186211} // namespace IPC
  • trunk/Source/WebKit/Scripts/test-superclassMessageReceiver.cpp

    r261254 r262075  
    123123#endif
    124124
     125#if ENABLE(TEST_FEATURE)
     126
     127void TestAsyncMessageWithConnection::callReply(IPC::Decoder& decoder, CompletionHandler<void(bool&&)>&& completionHandler)
     128{
     129    Optional<bool> flag;
     130    decoder >> flag;
     131    if (!flag) {
     132        ASSERT_NOT_REACHED();
     133        cancelReply(WTFMove(completionHandler));
     134        return;
     135    }
     136    completionHandler(WTFMove(*flag));
     137}
     138
     139void TestAsyncMessageWithConnection::cancelReply(CompletionHandler<void(bool&&)>&& completionHandler)
     140{
     141    completionHandler(IPC::AsyncReplyError<bool>::create());
     142}
     143
     144void TestAsyncMessageWithConnection::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, bool flag)
     145{
     146    *encoder << flag;
     147    connection.sendSyncReply(WTFMove(encoder));
     148}
     149
     150#endif
     151
    125152void TestSyncMessage::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, uint8_t reply)
    126153{
     
    163190    if (decoder.messageName() == Messages::WebPage::TestAsyncMessageWithMultipleArguments::name()) {
    164191        IPC::handleMessageAsync<Messages::WebPage::TestAsyncMessageWithMultipleArguments>(connection, decoder, this, &WebPage::testAsyncMessageWithMultipleArguments);
     192        return;
     193    }
     194#endif
     195#if ENABLE(TEST_FEATURE)
     196    if (decoder.messageName() == Messages::WebPage::TestAsyncMessageWithConnection::name()) {
     197        IPC::handleMessageAsyncWantsConnection<Messages::WebPage::TestAsyncMessageWithConnection>(connection, decoder, this, &WebPage::testAsyncMessageWithConnection);
    165198        return;
    166199    }
  • trunk/Source/WebKit/Scripts/test-superclassMessages.h

    r261254 r262075  
    148148#endif
    149149
     150#if ENABLE(TEST_FEATURE)
     151class TestAsyncMessageWithConnection {
     152public:
     153    typedef std::tuple<const int&> Arguments;
     154
     155    static IPC::MessageName name() { return IPC::MessageName::WebPage_TestAsyncMessageWithConnection; }
     156    static const bool isSync = false;
     157
     158    static void callReply(IPC::Decoder&, CompletionHandler<void(bool&&)>&&);
     159    static void cancelReply(CompletionHandler<void(bool&&)>&&);
     160    static IPC::MessageName asyncMessageReplyName() { return IPC::MessageName::WebPage_TestAsyncMessageWithConnectionReply; }
     161    using AsyncReply = TestAsyncMessageWithConnectionAsyncReply;
     162    static void send(std::unique_ptr<IPC::Encoder>&&, IPC::Connection&, bool flag);
     163    using Reply = std::tuple<bool&>;
     164    using ReplyArguments = std::tuple<bool>;
     165    explicit TestAsyncMessageWithConnection(const int& value)
     166        : m_arguments(value)
     167    {
     168    }
     169
     170    const Arguments& arguments() const
     171    {
     172        return m_arguments;
     173    }
     174
     175private:
     176    Arguments m_arguments;
     177};
     178#endif
     179
    150180class TestSyncMessage {
    151181public:
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r262024 r262075  
    475475
    476476    if message.has_attribute(WANTS_CONNECTION_ATTRIBUTE):
    477         dispatch_function_args.insert(0, 'connection')
     477        if message.has_attribute(ASYNC_ATTRIBUTE):
     478            dispatch_function += 'WantsConnection'
     479        else:
     480            dispatch_function_args.insert(0, 'connection')
    478481
    479482    result = []
  • trunk/Source/WebKit/Scripts/webkit/messages_unittest.py

    r261811 r262075  
    276276        },
    277277        {
     278            'name': 'TestAsyncMessageWithConnection',
     279            'parameters': (
     280                ('int', 'value'),
     281            ),
     282            'reply_parameters': (
     283                ('bool', 'flag'),
     284            ),
     285            'conditions': ('ENABLE(TEST_FEATURE)'),
     286        },
     287        {
    278288            'name': 'TestSyncMessage',
    279289            'parameters': (
  • trunk/Source/WebKit/Scripts/webkit/test-superclass.messages.in

    r261254 r262075  
    2727    TestAsyncMessageWithNoArguments() -> () Async
    2828    TestAsyncMessageWithMultipleArguments() -> (bool flag, uint64_t value) Async
     29    TestAsyncMessageWithConnection(int value) -> (bool flag) Async WantsConnection
    2930#endif
    3031    TestSyncMessage(uint32_t param) -> (uint8_t reply) Synchronous
Note: See TracChangeset for help on using the changeset viewer.