Changeset 262075 in webkit
- Timestamp:
- May 22, 2020 2:45:47 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r262071 r262075 1 2020-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 1 40 2020-05-22 Tim Horton <timothy_horton@apple.com> 2 41 -
trunk/Source/WebKit/Platform/IPC/HandleMessage.h
r261254 r262075 184 184 } 185 185 186 template<typename T, typename C, typename MF> 187 void 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 186 211 } // namespace IPC -
trunk/Source/WebKit/Scripts/test-superclassMessageReceiver.cpp
r261254 r262075 123 123 #endif 124 124 125 #if ENABLE(TEST_FEATURE) 126 127 void 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 139 void TestAsyncMessageWithConnection::cancelReply(CompletionHandler<void(bool&&)>&& completionHandler) 140 { 141 completionHandler(IPC::AsyncReplyError<bool>::create()); 142 } 143 144 void 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 125 152 void TestSyncMessage::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, uint8_t reply) 126 153 { … … 163 190 if (decoder.messageName() == Messages::WebPage::TestAsyncMessageWithMultipleArguments::name()) { 164 191 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); 165 198 return; 166 199 } -
trunk/Source/WebKit/Scripts/test-superclassMessages.h
r261254 r262075 148 148 #endif 149 149 150 #if ENABLE(TEST_FEATURE) 151 class TestAsyncMessageWithConnection { 152 public: 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 175 private: 176 Arguments m_arguments; 177 }; 178 #endif 179 150 180 class TestSyncMessage { 151 181 public: -
trunk/Source/WebKit/Scripts/webkit/messages.py
r262024 r262075 475 475 476 476 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') 478 481 479 482 result = [] -
trunk/Source/WebKit/Scripts/webkit/messages_unittest.py
r261811 r262075 276 276 }, 277 277 { 278 'name': 'TestAsyncMessageWithConnection', 279 'parameters': ( 280 ('int', 'value'), 281 ), 282 'reply_parameters': ( 283 ('bool', 'flag'), 284 ), 285 'conditions': ('ENABLE(TEST_FEATURE)'), 286 }, 287 { 278 288 'name': 'TestSyncMessage', 279 289 'parameters': ( -
trunk/Source/WebKit/Scripts/webkit/test-superclass.messages.in
r261254 r262075 27 27 TestAsyncMessageWithNoArguments() -> () Async 28 28 TestAsyncMessageWithMultipleArguments() -> (bool flag, uint64_t value) Async 29 TestAsyncMessageWithConnection(int value) -> (bool flag) Async WantsConnection 29 30 #endif 30 31 TestSyncMessage(uint32_t param) -> (uint8_t reply) Synchronous
Note: See TracChangeset
for help on using the changeset viewer.