Changeset 237294 in webkit


Ignore:
Timestamp:
Oct 19, 2018, 10:40:20 AM (7 years ago)
Author:
achristensen@apple.com
Message:

Introduce CompletionHandler-based Async IPC messages with replies
https://bugs.webkit.org/show_bug.cgi?id=190746

Reviewed by Tim Horton.

Before this patch, to make an asynchronous IPC message with a reply you had to find two objects that
can talk to each other, make two new message types, send a generated identifier, keep track of that
identifier, make a HashMap somewhere to store the object waiting for the response, and hook it all up.
What a mess. No wonder people take shortcuts and make strange design decisions.

Now, you can just use a CompletionHandler and mark the reply as Async in *.messages.in.
I've adopted this with a message whose behavior is covered by the storage/indexeddb/modern/blob-cursor.html
layout test and many others. I intent to refine and further adopt this incrementally.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::getSandboxExtensionsForBlobFiles):
(WebKit::NetworkProcess::didGetSandboxExtensionsForBlobFiles): Deleted.

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkProcess.messages.in:

This is representative of how code will be simplified with greater adoption.

  • NetworkProcess/NetworkResourceLoadParameters.cpp:

(WebKit::NetworkResourceLoadParameters::decode):
Modernize HandleArray decoding.

  • Platform/IPC/Connection.cpp:

(IPC::Connection::dispatchMessage):
(IPC::nextAsyncReplyHandlerID):
(IPC::asyncReplyHandlerMap):
Handle async replies when looking at incoming messages from the sending process.

  • Platform/IPC/Connection.h:

(IPC::Connection::sendWithAsyncReply):
Send a message with an async reply and prepare the reply receiver.

  • Platform/IPC/Encoder.h:

Make the uint64_t encoder public so we can use it when encoding the listenerID.

  • Platform/IPC/HandleMessage.h:

(IPC::handleMessageAsync):
Handle an asynchronous message with a reply from the receiving process.
This is similar to how DelayedReply messages are handled, but the listenerID is automatically captured and sent back.

  • Scripts/webkit/messages.py:

Generate code for async message replies.

  • Shared/Databases/IndexedDB/WebIDBResult.cpp:

(WebKit::WebIDBResult::decode):

  • Shared/SandboxExtension.h:

(WebKit::SandboxExtension::HandleArray::at):
(WebKit::SandboxExtension::HandleArray::decode):

  • Shared/WebProcessCreationParameters.cpp:

(WebKit::WebProcessCreationParameters::decode):

  • Shared/mac/SandboxExtensionMac.mm:

(WebKit::SandboxExtension::HandleArray::decode):
Modernize the decoding of HandleArray to work with generated decoding.

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::getSandboxExtensionsForBlobFiles):

  • UIProcess/Network/NetworkProcessProxy.h:
  • UIProcess/Network/NetworkProcessProxy.messages.in:

This is also representative of how code will be simplified with greater adoption.

  • WebProcess/MediaStream/MediaDeviceSandboxExtensions.cpp:

(WebKit::MediaDeviceSandboxExtensions::decode):
Modernize HandleArray decoding.

Location:
trunk/Source/WebKit
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r237283 r237294  
     12018-10-19  Alex Christensen  <achristensen@webkit.org>
     2
     3        Introduce CompletionHandler-based Async IPC messages with replies
     4        https://bugs.webkit.org/show_bug.cgi?id=190746
     5
     6        Reviewed by Tim Horton.
     7
     8        Before this patch, to make an asynchronous IPC message with a reply you had to find two objects that
     9        can talk to each other, make two new message types, send a generated identifier, keep track of that
     10        identifier, make a HashMap somewhere to store the object waiting for the response, and hook it all up.
     11        What a mess.  No wonder people take shortcuts and make strange design decisions.
     12
     13        Now, you can just use a CompletionHandler and mark the reply as Async in *.messages.in.
     14        I've adopted this with a message whose behavior is covered by the storage/indexeddb/modern/blob-cursor.html
     15        layout test and many others.  I intent to refine and further adopt this incrementally.
     16
     17        * NetworkProcess/NetworkProcess.cpp:
     18        (WebKit::NetworkProcess::getSandboxExtensionsForBlobFiles):
     19        (WebKit::NetworkProcess::didGetSandboxExtensionsForBlobFiles): Deleted.
     20        * NetworkProcess/NetworkProcess.h:
     21        * NetworkProcess/NetworkProcess.messages.in:
     22        This is representative of how code will be simplified with greater adoption.
     23        * NetworkProcess/NetworkResourceLoadParameters.cpp:
     24        (WebKit::NetworkResourceLoadParameters::decode):
     25        Modernize HandleArray decoding.
     26        * Platform/IPC/Connection.cpp:
     27        (IPC::Connection::dispatchMessage):
     28        (IPC::nextAsyncReplyHandlerID):
     29        (IPC::asyncReplyHandlerMap):
     30        Handle async replies when looking at incoming messages from the sending process.
     31        * Platform/IPC/Connection.h:
     32        (IPC::Connection::sendWithAsyncReply):
     33        Send a message with an async reply and prepare the reply receiver.
     34        * Platform/IPC/Encoder.h:
     35        Make the uint64_t encoder public so we can use it when encoding the listenerID.
     36        * Platform/IPC/HandleMessage.h:
     37        (IPC::handleMessageAsync):
     38        Handle an asynchronous message with a reply from the receiving process.
     39        This is similar to how DelayedReply messages are handled, but the listenerID is automatically captured and sent back.
     40        * Scripts/webkit/messages.py:
     41        Generate code for async message replies.
     42        * Shared/Databases/IndexedDB/WebIDBResult.cpp:
     43        (WebKit::WebIDBResult::decode):
     44        * Shared/SandboxExtension.h:
     45        (WebKit::SandboxExtension::HandleArray::at):
     46        (WebKit::SandboxExtension::HandleArray::decode):
     47        * Shared/WebProcessCreationParameters.cpp:
     48        (WebKit::WebProcessCreationParameters::decode):
     49        * Shared/mac/SandboxExtensionMac.mm:
     50        (WebKit::SandboxExtension::HandleArray::decode):
     51        Modernize the decoding of HandleArray to work with generated decoding.
     52        * UIProcess/Network/NetworkProcessProxy.cpp:
     53        (WebKit::NetworkProcessProxy::getSandboxExtensionsForBlobFiles):
     54        * UIProcess/Network/NetworkProcessProxy.h:
     55        * UIProcess/Network/NetworkProcessProxy.messages.in:
     56        This is also representative of how code will be simplified with greater adoption.
     57        * WebProcess/MediaStream/MediaDeviceSandboxExtensions.cpp:
     58        (WebKit::MediaDeviceSandboxExtensions::decode):
     59        Modernize HandleArray decoding.
     60
    1612018-10-19  Chris Dumez  <cdumez@apple.com>
    262
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r236988 r237294  
    11911191
    11921192#if ENABLE(SANDBOX_EXTENSIONS)
    1193 void NetworkProcess::getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, Function<void(SandboxExtension::HandleArray&&)>&& completionHandler)
    1194 {
    1195     static uint64_t lastRequestID;
    1196    
    1197     uint64_t requestID = ++lastRequestID;
    1198     m_sandboxExtensionForBlobsCompletionHandlersStorageForNetworkProcess.set(requestID, WTFMove(completionHandler));
    1199     parentProcessConnection()->send(Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles(requestID, filenames), 0);
    1200 }
    1201 
    1202 void NetworkProcess::didGetSandboxExtensionsForBlobFiles(uint64_t requestID, SandboxExtension::HandleArray&& handles)
    1203 {
    1204     if (auto handler = m_sandboxExtensionForBlobsCompletionHandlersStorageForNetworkProcess.take(requestID))
    1205         handler(WTFMove(handles));
    1206 }
    1207    
     1193void NetworkProcess::getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&& completionHandler)
     1194{
     1195    parentProcessConnection()->sendWithAsyncReply(Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles(filenames), WTFMove(completionHandler));
     1196}
     1197
    12081198void NetworkProcess::updateTemporaryFileSandboxExtensions(const Vector<String>& paths, SandboxExtension::HandleArray& handles)
    12091199{
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r237266 r237294  
    194194
    195195#if ENABLE(SANDBOX_EXTENSIONS)
    196     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, WTF::Function<void(SandboxExtension::HandleArray&&)>&& completionHandler);
     196    void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
    197197    void updateTemporaryFileSandboxExtensions(const Vector<String>& paths, SandboxExtension::HandleArray&);
    198198#endif
     
    314314    void registerURLSchemeAsCORSEnabled(const String&) const;
    315315    void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
    316 
    317 #if ENABLE(SANDBOX_EXTENSIONS)
    318     void didGetSandboxExtensionsForBlobFiles(uint64_t requestID, SandboxExtension::HandleArray&&);
    319 #endif
    320316
    321317#if ENABLE(INDEXED_DATABASE)
     
    399395
    400396    HashMap<String, RefPtr<SandboxExtension>> m_blobTemporaryFileSandboxExtensions;
    401     HashMap<uint64_t, WTF::Function<void(SandboxExtension::HandleArray&&)>> m_sandboxExtensionForBlobsCompletionHandlersStorageForNetworkProcess;
    402397   
    403398    Deque<CrossThreadTask> m_storageTasks;
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r237264 r237294  
    7474    ProcessDidResume()
    7575
    76 #if ENABLE(SANDBOX_EXTENSIONS)
    77     DidGetSandboxExtensionsForBlobFiles(uint64_t requestID, WebKit::SandboxExtension::HandleArray extensions)
    78 #endif
    79 
    8076    WriteBlobToFilePath(WebCore::URL blobURL, String path, WebKit::SandboxExtension::Handle handle, uint64_t callbackID)
    8177
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.cpp

    r236365 r237294  
    134134        result.request.setHTTPBody(WTFMove(formData));
    135135
    136         SandboxExtension::HandleArray requestBodySandboxExtensionHandles;
    137         if (!decoder.decode(requestBodySandboxExtensionHandles))
    138             return false;
    139         for (size_t i = 0; i < requestBodySandboxExtensionHandles.size(); ++i) {
    140             if (auto extension = SandboxExtension::create(WTFMove(requestBodySandboxExtensionHandles[i])))
     136        std::optional<SandboxExtension::HandleArray> requestBodySandboxExtensionHandles;
     137        decoder >> requestBodySandboxExtensionHandles;
     138        if (!requestBodySandboxExtensionHandles)
     139            return false;
     140        for (size_t i = 0; i < requestBodySandboxExtensionHandles->size(); ++i) {
     141            if (auto extension = SandboxExtension::create(WTFMove(requestBodySandboxExtensionHandles->at(i))))
    141142                result.requestBodySandboxExtensions.append(WTFMove(extension));
    142143        }
  • trunk/Source/WebKit/Platform/IPC/Connection.cpp

    r236680 r237294  
    238238}
    239239
     240static HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>& asyncReplyHandlerMap()
     241{
     242    static NeverDestroyed<HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>> map;
     243    return map.get();
     244}
     245   
    240246Connection::Connection(Identifier identifier, bool isServer, Client& client)
    241247    : m_client(client)
     
    272278
    273279    allConnections().remove(m_uniqueID);
     280   
     281    auto map = asyncReplyHandlerMap().take(reinterpret_cast<uintptr_t>(this));
     282    for (auto& handler : map.values()) {
     283        if (handler)
     284            handler(nullptr);
     285    }
    274286}
    275287
     
    949961{
    950962    RELEASE_ASSERT(isValid());
     963    if (decoder.messageReceiverName() == "AsyncReply") {
     964        std::optional<uint64_t> listenerID;
     965        decoder >> listenerID;
     966        if (!listenerID) {
     967            ASSERT_NOT_REACHED();
     968            return;
     969        }
     970        auto handler = takeAsyncReplyHandler(*this, *listenerID);
     971        if (!handler) {
     972            ASSERT_NOT_REACHED();
     973            return;
     974        }
     975        handler(&decoder);
     976        return;
     977    }
    951978    m_client.didReceiveMessage(*this, decoder);
    952979}
     
    10941121}
    10951122
     1123uint64_t nextAsyncReplyHandlerID()
     1124{
     1125    static uint64_t identifier { 0 };
     1126    return ++identifier;
     1127}
     1128
     1129void addAsyncReplyHandler(Connection& connection, uint64_t identifier, CompletionHandler<void(Decoder*)>&& completionHandler)
     1130{
     1131    auto result = asyncReplyHandlerMap().ensure(reinterpret_cast<uintptr_t>(&connection), [] {
     1132        return HashMap<uint64_t, CompletionHandler<void(Decoder*)>>();
     1133    }).iterator->value.add(identifier, WTFMove(completionHandler));
     1134    ASSERT_UNUSED(result, result.isNewEntry);
     1135}
     1136
     1137CompletionHandler<void(Decoder*)> takeAsyncReplyHandler(Connection& connection, uint64_t identifier)
     1138{
     1139    auto iterator = asyncReplyHandlerMap().find(reinterpret_cast<uintptr_t>(&connection));
     1140    if (iterator != asyncReplyHandlerMap().end()) {
     1141        if (!iterator->value.isValidKey(identifier)) {
     1142            ASSERT_NOT_REACHED();
     1143            connection.markCurrentlyDispatchedMessageAsInvalid();
     1144            return nullptr;
     1145        }
     1146        ASSERT(iterator->value.contains(identifier));
     1147        return iterator->value.take(identifier);
     1148    }
     1149    ASSERT_NOT_REACHED();
     1150    return nullptr;
     1151}
     1152
    10961153void Connection::wakeUpRunLoop()
    10971154{
  • trunk/Source/WebKit/Platform/IPC/Connection.h

    r236680 r237294  
    178178    void postConnectionDidCloseOnConnectionWorkQueue();
    179179
     180    template<typename T, typename... Args> void sendWithAsyncReply(T&& message, CompletionHandler<void(Args...)>&& args, uint64_t destinationID = 0);
    180181    template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<SendOption> sendOptions = { });
    181182    template<typename T> void sendWithReply(T&& message, uint64_t destinationID, FunctionDispatcher& replyDispatcher, Function<void(std::optional<typename CodingType<typename T::Reply>::Type>)>&& replyHandler);
     
    411412}
    412413
     414uint64_t nextAsyncReplyHandlerID();
     415void addAsyncReplyHandler(Connection&, uint64_t, CompletionHandler<void(Decoder*)>&&);
     416CompletionHandler<void(Decoder*)> takeAsyncReplyHandler(Connection&, uint64_t);
     417
     418template<typename T, typename... Args>
     419void Connection::sendWithAsyncReply(T&& message, CompletionHandler<void(Args...)>&& completionHandler, uint64_t destinationID)
     420{
     421    COMPILE_ASSERT(!T::isSync, AsyncMessageExpected);
     422
     423    auto encoder = std::make_unique<Encoder>(T::receiverName(), T::name(), destinationID);
     424    uint64_t listenerID = nextAsyncReplyHandlerID();
     425    encoder->encode(listenerID);
     426    encoder->encode(message.arguments());
     427    sendMessage(WTFMove(encoder), { });
     428    addAsyncReplyHandler(*this, listenerID, [completionHandler = WTFMove(completionHandler)] (Decoder* decoder) mutable {
     429        if (decoder && !decoder->isInvalid())
     430            T::callReply(*decoder, WTFMove(completionHandler));
     431        else
     432            T::cancelReply(WTFMove(completionHandler));
     433    });
     434}
     435
    413436template<typename T>
    414437void Connection::sendWithReply(T&& message, uint64_t destinationID, FunctionDispatcher& replyDispatcher, Function<void(std::optional<typename CodingType<typename T::Reply>::Type>)>&& replyHandler)
  • trunk/Source/WebKit/Platform/IPC/Encoder.h

    r222894 r237294  
    9595    static const bool isIPCEncoder = true;
    9696
     97    void encode(uint64_t);
     98
    9799private:
    98100    uint8_t* grow(unsigned alignment, size_t);
     
    102104    void encode(uint16_t);
    103105    void encode(uint32_t);
    104     void encode(uint64_t);
    105106    void encode(int16_t);
    106107    void encode(int32_t);
  • trunk/Source/WebKit/Platform/IPC/HandleMessage.h

    r235951 r237294  
    188188}
    189189
     190template<typename T, typename C, typename MF>
     191void handleMessageAsync(Connection& connection, Decoder& decoder, C* object, MF function)
     192{
     193    std::optional<uint64_t> listenerID;
     194    decoder >> listenerID;
     195    if (!listenerID) {
     196        ASSERT(decoder.isInvalid());
     197        return;
     198    }
     199   
     200    typename CodingType<typename T::Arguments>::Type arguments;
     201    if (!decoder.decode(arguments)) {
     202        ASSERT(decoder.isInvalid());
     203        return;
     204    }
     205
     206    typename T::AsyncReply completionHandler = [listenerID = *listenerID, connection = makeRef(connection)] (auto&&... args) mutable {
     207        auto encoder = std::make_unique<Encoder>("AsyncReply", T::asyncMessageReplyName(), 0);
     208        *encoder << listenerID;
     209        T::send(WTFMove(encoder), WTFMove(connection), args...);
     210    };
     211    callMemberFunction(WTFMove(arguments), WTFMove(completionHandler), object, function);
     212}
     213
    190214} // namespace IPC
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r237264 r237294  
    3030LEGACY_RECEIVER_ATTRIBUTE = 'LegacyReceiver'
    3131DELAYED_ATTRIBUTE = 'Delayed'
     32ASYNC_ATTRIBUTE = 'Async'
    3233
    3334_license_header = """/*
     
    9798
    9899
     100def move_type(type):
     101    return '%s&&' % type
     102
     103
    99104def arguments_type(message):
    100105    return 'std::tuple<%s>' % ', '.join(function_parameter_type(parameter.type, parameter.kind) for parameter in message.parameters)
     
    114119    result.append('    static IPC::StringReference receiverName() { return messageReceiverName(); }\n')
    115120    result.append('    static IPC::StringReference name() { return IPC::StringReference("%s"); }\n' % message.name)
    116     result.append('    static const bool isSync = %s;\n' % ('false', 'true')[message.reply_parameters != None])
     121    result.append('    static const bool isSync = %s;\n' % ('false', 'true')[message.reply_parameters != None and not message.has_attribute(ASYNC_ATTRIBUTE)])
    117122    result.append('\n')
    118123    if message.reply_parameters != None:
    119         if message.has_attribute(DELAYED_ATTRIBUTE):
    120             send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
    121             result.append('    using DelayedReply = CompletionHandler<void(')
    122             if len(send_parameters):
    123                 result.append('%s' % ', '.join([' '.join(x) for x in send_parameters]))
    124             result.append(')>;\n')
     124        send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
     125        if message.has_attribute(DELAYED_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE):
     126            completion_handler_parameters = '%s' % ', '.join([' '.join(x) for x in send_parameters])
     127            if message.has_attribute(ASYNC_ATTRIBUTE):
     128                move_parameters = ', '.join([move_type(x.type) for x in message.reply_parameters])
     129                result.append('    static void callReply(IPC::Decoder&, CompletionHandler<void(%s)>&&);\n' % move_parameters)
     130                result.append('    static void cancelReply(CompletionHandler<void(%s)>&&);\n' % move_parameters)
     131                result.append('    static IPC::StringReference asyncMessageReplyName() { return { "%sReply" }; }\n' % message.name)
     132                result.append('    using AsyncReply')
     133            else:
     134                result.append('    using DelayedReply')
     135            result.append(' = CompletionHandler<void(%s)>;\n' % completion_handler_parameters)
    125136            result.append('    static void send(std::unique_ptr<IPC::Encoder>&&, IPC::Connection&')
    126137            if len(send_parameters):
    127                 result.append(', %s' % ', '.join([' '.join(x) for x in send_parameters]))
     138                result.append(', %s' % completion_handler_parameters)
    128139            result.append(');\n')
    129 
    130140        result.append('    typedef %s Reply;\n' % reply_type(message))
    131141
     
    277287
    278288    dispatch_function = 'handleMessage'
     289    if message.has_attribute(ASYNC_ATTRIBUTE):
     290        dispatch_function += 'Async'
     291        dispatch_function_args.insert(0, 'connection')
    279292
    280293    if message.has_attribute(WANTS_CONNECTION_ATTRIBUTE):
     
    293306    if message.has_attribute(DELAYED_ATTRIBUTE):
    294307        dispatch_function += 'Delayed'
     308    if message.has_attribute(ASYNC_ATTRIBUTE):
     309        dispatch_function += 'Async'
    295310
    296311    wants_connection = message.has_attribute(DELAYED_ATTRIBUTE) or message.has_attribute(WANTS_CONNECTION_ATTRIBUTE)
     
    298313    result = []
    299314    result.append('    if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
    300     result.append('        IPC::%s<Messages::%s::%s>(%sdecoder, %sreplyEncoder, this, &%s);\n' % (dispatch_function, receiver.name, message.name, 'connection, ' if wants_connection else '', '' if message.has_attribute(DELAYED_ATTRIBUTE) else '*', handler_function(receiver, message)))
     315    result.append('        IPC::%s<Messages::%s::%s>(%sdecoder, %sreplyEncoder, this, &%s);\n' % (dispatch_function, receiver.name, message.name, 'connection, ' if wants_connection else '', '' if message.has_attribute(DELAYED_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE) else '*', handler_function(receiver, message)))
    301316    result.append('        return;\n')
    302317    result.append('    }\n')
     
    526541    result.append('\n')
    527542
    528     sync_delayed_messages = []
     543    delayed_or_async_messages = []
    529544    for message in receiver.messages:
    530         if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE):
    531             sync_delayed_messages.append(message)
    532 
    533     if sync_delayed_messages:
     545        if message.reply_parameters != None and (message.has_attribute(DELAYED_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE)):
     546            delayed_or_async_messages.append(message)
     547
     548    if delayed_or_async_messages:
    534549        result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name)
    535550
    536         for message in sync_delayed_messages:
     551        for message in delayed_or_async_messages:
    537552            send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
    538553
    539554            if message.condition:
    540555                result.append('#if %s\n\n' % message.condition)
     556
     557            if message.has_attribute(ASYNC_ATTRIBUTE):
     558                move_parameters = message.name, ', '.join([move_type(x.type) for x in message.reply_parameters])
     559                result.append('void %s::callReply(IPC::Decoder& decoder, CompletionHandler<void(%s)>&& completionHandler)\n{\n' % move_parameters)
     560                for x in message.reply_parameters:
     561                    result.append('    std::optional<%s> %s;\n' % (x.type, x.name))
     562                    result.append('    decoder >> %s;\n' % x.name)
     563                    result.append('    if (!%s) {\n        ASSERT_NOT_REACHED();\n        return;\n    }\n' % x.name)
     564                result.append('    completionHandler(WTFMove(*%s));\n}\n\n' % (', *'.join(x.name for x in message.reply_parameters)))
     565                result.append('void %s::cancelReply(CompletionHandler<void(%s)>&& completionHandler)\n{\n    completionHandler(' % move_parameters)
     566                result.append(', '.join(['{ }' for x in message.reply_parameters]))
     567                result.append(');\n}\n\n')
    541568
    542569            result.append('void %s::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection' % (message.name))
     
    559586    sync_messages = []
    560587    for message in receiver.messages:
    561         if message.reply_parameters is not None:
     588        if message.reply_parameters is not None and not message.has_attribute(ASYNC_ATTRIBUTE):
    562589            sync_messages.append(message)
    563590        else:
     
    587614        result.append('}\n')
    588615
    589     result.append('\n} // namespace WebKit\n')
     616    result.append('\n} // namespace WebKit\n\n')
    590617
    591618    if receiver.condition:
  • trunk/Source/WebKit/Shared/Databases/IndexedDB/WebIDBResult.cpp

    r222233 r237294  
    4747    result.m_resultData = WTFMove(*resultData);
    4848
    49     if (!SandboxExtension::HandleArray::decode(decoder, result.m_handles))
     49    std::optional<SandboxExtension::HandleArray> handles;
     50    decoder >> handles;
     51    if (!handles)
    5052        return false;
     53    result.m_handles = WTFMove(*handles);
    5154
    5255    return true;
  • trunk/Source/WebKit/Shared/SandboxExtension.h

    r231342 r237294  
    7878        HandleArray();
    7979        HandleArray(HandleArray&&) = default;
     80        HandleArray& operator=(HandleArray&&) = default;
    8081        ~HandleArray();
    8182        void allocate(size_t);
    8283        Handle& operator[](size_t i);
     84        Handle& at(size_t i) { return operator[](i); }
    8385        const Handle& operator[](size_t i) const;
    8486        size_t size() const;
    8587        void encode(IPC::Encoder&) const;
    86         static bool decode(IPC::Decoder&, HandleArray&);
    87        
     88        static std::optional<HandleArray> decode(IPC::Decoder&);
     89
    8890    private:
    8991#if ENABLE(SANDBOX_EXTENSIONS)
     
    129131inline SandboxExtension::Handle& SandboxExtension::HandleArray::operator[](size_t) { return m_emptyHandle; }
    130132inline void SandboxExtension::HandleArray::encode(IPC::Encoder&) const { }
    131 inline bool SandboxExtension::HandleArray::decode(IPC::Decoder&, HandleArray&) { return true; }
     133inline auto SandboxExtension::HandleArray::decode(IPC::Decoder&) -> std::optional<HandleArray> { return {{ }}; }
    132134inline RefPtr<SandboxExtension> SandboxExtension::create(Handle&&) { return nullptr; }
    133135inline bool SandboxExtension::createHandle(const String&, Type, Handle&) { return true; }
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r237281 r237294  
    176176    parameters.injectedBundlePathExtensionHandle = WTFMove(*injectedBundlePathExtensionHandle);
    177177
    178     if (!decoder.decode(parameters.additionalSandboxExtensionHandles))
    179         return false;
     178    std::optional<SandboxExtension::HandleArray> additionalSandboxExtensionHandles;
     179    decoder >> additionalSandboxExtensionHandles;
     180    if (!additionalSandboxExtensionHandles)
     181        return false;
     182    parameters.additionalSandboxExtensionHandles = WTFMove(*additionalSandboxExtensionHandles);
    180183    if (!decoder.decode(parameters.initializationUserData))
    181184        return false;
  • trunk/Source/WebKit/Shared/mac/SandboxExtensionMac.mm

    r237266 r237294  
    191191}
    192192
    193 bool SandboxExtension::HandleArray::decode(IPC::Decoder& decoder, SandboxExtension::HandleArray& handles)
    194 {
    195     uint64_t size;
    196     if (!decoder.decode(size))
    197         return false;
    198     handles.allocate(size);
    199     for (size_t i = 0; i < size; i++) {
     193std::optional<SandboxExtension::HandleArray> SandboxExtension::HandleArray::decode(IPC::Decoder& decoder)
     194{
     195    std::optional<uint64_t> size;
     196    decoder >> size;
     197    if (!size)
     198        return std::nullopt;
     199    SandboxExtension::HandleArray handles;
     200    handles.allocate(*size);
     201    for (size_t i = 0; i < *size; ++i) {
    200202        std::optional<SandboxExtension::Handle> handle;
    201203        decoder >> handle;
    202204        if (!handle)
    203             return false;
     205            return std::nullopt;
    204206        handles[i] = WTFMove(*handle);
    205207    }
    206     return true;
     208    return WTFMove(handles);
    207209}
    208210
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r237266 r237294  
    693693
    694694#if ENABLE(SANDBOX_EXTENSIONS)
    695 void NetworkProcessProxy::getSandboxExtensionsForBlobFiles(uint64_t requestID, const Vector<String>& paths)
     695void NetworkProcessProxy::getSandboxExtensionsForBlobFiles(const Vector<String>& paths, Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles::AsyncReply&& reply)
    696696{
    697697    SandboxExtension::HandleArray extensions;
     
    701701        SandboxExtension::createHandle(paths[i], SandboxExtension::Type::ReadWrite, extensions[i]);
    702702    }
    703    
    704     send(Messages::NetworkProcess::DidGetSandboxExtensionsForBlobFiles(requestID, extensions), 0);
     703    reply(WTFMove(extensions));
    705704}
    706705#endif
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r237110 r237294  
    3131#include "LegacyCustomProtocolManagerProxy.h"
    3232#endif
     33#include "NetworkProcessProxyMessages.h"
    3334#include "ProcessLauncher.h"
    3435#include "ProcessThrottler.h"
     
    157158
    158159#if ENABLE(SANDBOX_EXTENSIONS)
    159     void getSandboxExtensionsForBlobFiles(uint64_t requestID, const Vector<String>& paths);
     160    void getSandboxExtensionsForBlobFiles(const Vector<String>& paths, Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles::AsyncReply&&);
    160161#endif
    161162
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in

    r237110 r237294  
    5757
    5858#if ENABLE(SANDBOX_EXTENSIONS)
    59     GetSandboxExtensionsForBlobFiles(uint64_t requestID, Vector<String> paths)
     59    GetSandboxExtensionsForBlobFiles(Vector<String> paths) -> (WebKit::SandboxExtension::HandleArray extensions) Async
    6060#endif
    6161
  • trunk/Source/WebKit/WebProcess/MediaStream/MediaDeviceSandboxExtensions.cpp

    r225926 r237294  
    5151        return false;
    5252
    53     if (!SandboxExtension::HandleArray::decode(decoder, result.m_handles))
     53    std::optional<SandboxExtension::HandleArray> handles;
     54    decoder >> handles;
     55    if (!handles)
    5456        return false;
     57    result.m_handles = WTFMove(*handles);
    5558
    5659    return true;
Note: See TracChangeset for help on using the changeset viewer.