IPC code should support messages with both Delayed and WantsConnection attributes
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Feb 2019 18:53:02 +0000 (18:53 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Feb 2019 18:53:02 +0000 (18:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194679

Reviewed by Geoffrey Garen.

* Platform/IPC/HandleMessage.h:
(IPC::callMemberFunctionImpl):
(IPC::callMemberFunction):
(IPC::handleMessageDelayedWantsConnection):
* Scripts/webkit/messages.py:
* UIProcess/WebStorage/StorageManager.cpp:
(WebKit::StorageManager::getValues):
* UIProcess/WebStorage/StorageManager.h:
* UIProcess/WebStorage/StorageManager.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241595 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/HandleMessage.h
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/UIProcess/WebStorage/StorageManager.cpp
Source/WebKit/UIProcess/WebStorage/StorageManager.h
Source/WebKit/UIProcess/WebStorage/StorageManager.messages.in

index 3e51a5b..31df18d 100644 (file)
@@ -1,3 +1,20 @@
+2019-02-15  Alex Christensen  <achristensen@webkit.org>
+
+        IPC code should support messages with both Delayed and WantsConnection attributes
+        https://bugs.webkit.org/show_bug.cgi?id=194679
+
+        Reviewed by Geoffrey Garen.
+
+        * Platform/IPC/HandleMessage.h:
+        (IPC::callMemberFunctionImpl):
+        (IPC::callMemberFunction):
+        (IPC::handleMessageDelayedWantsConnection):
+        * Scripts/webkit/messages.py:
+        * UIProcess/WebStorage/StorageManager.cpp:
+        (WebKit::StorageManager::getValues):
+        * UIProcess/WebStorage/StorageManager.h:
+        * UIProcess/WebStorage/StorageManager.messages.in:
+
 2019-02-15  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r241559 and r241566.
index 3939730..cc8abbd 100644 (file)
@@ -75,6 +75,20 @@ void callMemberFunction(ArgsTuple&& args, CompletionHandler<CH>&& completionHand
     callMemberFunctionImpl(object, function, WTFMove(completionHandler), std::forward<ArgsTuple>(args), ArgsIndicies());
 }
 
+// Dispatch functions with connection parameter with delayed reply arguments.
+
+template <typename C, typename MF, typename CH, typename ArgsTuple, size_t... ArgsIndex>
+void callMemberFunctionImpl(Connection& connection, C* object, MF function, CompletionHandler<CH>&& completionHandler, ArgsTuple&& args, std::index_sequence<ArgsIndex...>)
+{
+    (object->*function)(connection, std::get<ArgsIndex>(std::forward<ArgsTuple>(args))..., WTFMove(completionHandler));
+}
+
+template<typename C, typename MF, typename CH, typename ArgsTuple, typename ArgsIndicies = std::make_index_sequence<std::tuple_size<ArgsTuple>::value>>
+void callMemberFunction(Connection& connection, ArgsTuple&& args, CompletionHandler<CH>&& completionHandler, C* object, MF function)
+{
+    callMemberFunctionImpl(connection, object, function, WTFMove(completionHandler), std::forward<ArgsTuple>(args), ArgsIndicies());
+}
+
 // Dispatch functions with connection parameter with no reply arguments.
 
 template <typename C, typename MF, typename ArgsTuple, size_t... ArgsIndex>
@@ -188,6 +202,21 @@ void handleMessageDelayed(Connection& connection, Decoder& decoder, std::unique_
 }
 
 template<typename T, typename C, typename MF>
+void handleMessageDelayedWantsConnection(Connection& connection, Decoder& decoder, std::unique_ptr<Encoder>& replyEncoder, C* object, MF function)
+{
+    typename CodingType<typename T::Arguments>::Type arguments;
+    if (!decoder.decode(arguments)) {
+        ASSERT(decoder.isInvalid());
+        return;
+    }
+    
+    typename T::DelayedReply completionHandler = [replyEncoder = WTFMove(replyEncoder), connection = makeRef(connection)] (auto&&... args) mutable {
+        T::send(WTFMove(replyEncoder), WTFMove(connection), args...);
+    };
+    callMemberFunction(connection, WTFMove(arguments), WTFMove(completionHandler), object, function);
+}
+
+template<typename T, typename C, typename MF>
 void handleMessageAsync(Connection& connection, Decoder& decoder, C* object, MF function)
 {
     Optional<uint64_t> listenerID;
index 8a5eb60..9ae038a 100644 (file)
@@ -307,6 +307,8 @@ def sync_message_statement(receiver, message):
     dispatch_function = 'handleMessage'
     if message.has_attribute(DELAYED_ATTRIBUTE):
         dispatch_function += 'Delayed'
+        if message.has_attribute(WANTS_CONNECTION_ATTRIBUTE):
+            dispatch_function += 'WantsConnection'
     if message.has_attribute(ASYNC_ATTRIBUTE):
         dispatch_function += 'Async'
     if message.has_attribute(LEGACY_SYNC_ATTRIBUTE):
index 36b05f2..81973ca 100644 (file)
@@ -785,15 +785,15 @@ void StorageManager::destroyStorageMap(IPC::Connection& connection, uint64_t sto
     m_storageAreasByConnection.remove(connectionAndStorageMapIDPair);
 }
 
-void StorageManager::getValues(IPC::Connection& connection, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values)
+void StorageManager::getValues(IPC::Connection& connection, uint64_t storageMapID, uint64_t storageMapSeed, CompletionHandler<void(const HashMap<String, String>&)>&& completionHandler)
 {
     StorageArea* storageArea = findStorageArea(connection, storageMapID);
     if (!storageArea) {
         // This is a session storage area for a page that has already been closed. Ignore it.
-        return;
+        return completionHandler({ });
     }
 
-    values = storageArea->items();
+    completionHandler(storageArea->items());
     connection.send(Messages::StorageAreaMap::DidGetValues(storageMapSeed), storageMapID);
 }
 
index 69585c8..1c1c7f7 100644 (file)
@@ -81,7 +81,7 @@ private:
     void createSessionStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, WebCore::SecurityOriginData&&);
     void destroyStorageMap(IPC::Connection&, uint64_t storageMapID);
 
-    void getValues(IPC::Connection&, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values);
+    void getValues(IPC::Connection&, uint64_t storageMapID, uint64_t storageMapSeed, CompletionHandler<void(const HashMap<String, String>&)>&&);
     void setItem(IPC::Connection&, uint64_t storageAreaID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& value, const String& urlString);
     void removeItem(IPC::Connection&, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& urlString);
     void clear(IPC::Connection&, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& urlString);
index da7f1aa..58cbcfb 100644 (file)
@@ -26,7 +26,7 @@ messages -> StorageManager {
     CreateSessionStorageMap(uint64_t storageMapID, uint64_t storageNamespaceID, struct WebCore::SecurityOriginData securityOriginData) WantsConnection
     DestroyStorageMap(uint64_t storageMapID) WantsConnection
 
-    GetValues(uint64_t storageMapID, uint64_t storageMapSeed) -> (HashMap<String, String> values) LegacySync WantsConnection
+    GetValues(uint64_t storageMapID, uint64_t storageMapSeed) -> (HashMap<String, String> values) Delayed WantsConnection
 
     SetItem(uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, String key, String value, String urlString) WantsConnection
     RemoveItem(uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, String key, String urlString) WantsConnection