<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[192185] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/192185">192185</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2015-11-09 16:05:30 -0800 (Mon, 09 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add reply blocks to _WKRemoteObjectInterface similar to NSXPCConnection
https://bugs.webkit.org/show_bug.cgi?id=151056
rdar://problem/23222609

Reviewed by Tim Horton.

Source/WebKit2:

* Platform/spi/Cocoa/NSInvocationSPI.h:
Add NSBlockInvocation declaration.

* Shared/API/Cocoa/RemoteObjectInvocation.mm:
(WebKit::RemoteObjectInvocation::encode):
Encode true if we have a reply ID.

* Shared/API/Cocoa/RemoteObjectRegistry.h:
Add new members.

* Shared/API/Cocoa/RemoteObjectRegistry.messages.in:
Add new CallReplyBlock message.

* Shared/API/Cocoa/RemoteObjectRegistry.mm:
(WebKit::RemoteObjectRegistry::sendReplyBlock):
Just send the CallReplyBlock message.

(WebKit::RemoteObjectRegistry::callReplyBlock):
Call through to _WKRemoteObjectRegistry.

* Shared/API/Cocoa/WKRemoteObjectCoder.h:
Pass an optional reply selector.

* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(encodeInvocationArguments):
Don't hard-code the first argument index.

(encodeInvocation):
Encode block invocations.

(-[WKRemoteObjectDecoder initWithInterface:rootObjectDictionary:replyToSelector:]):
Initialize _replyToSelector.

(validateClass):
NSBlockInvocation doesn't need to conform to NSSecureCoding.

(decodeInvocationArguments):
Don't hard-code the first argument, take it as a parameter instead.

(decodeInvocation):
Decode NSBlockInvocations (reply block invocations).

(decodeObject):
Check for NSBlockInvocation.

* Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
(-[_WKRemoteObjectInterface _methodSignatureForSelector:]):
Return null if we can't find the method.

(-[_WKRemoteObjectInterface _methodSignatureForReplyBlockOfSelector:]):
Look up the reply block signature and return it.

(-[_WKRemoteObjectInterface _allowedArgumentClassesForReplyBlockOfSelector:]):
Look up the allowed reply argument classes and return them.

* Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h:
Add new methods.

* Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
(PendingReply::PendingReply):
Add new object that represents a pending reply.

(-[_WKRemoteObjectRegistry _sendInvocation:interface:]):
If the invocation has a reply block, add a pending reply to our map.

(-[_WKRemoteObjectRegistry _invokeMethod:]):
If the method we're about to invoke has a reply block, construct a special reply block that calls us back with an invocation.
Encode this invocation and send it back across the wire.

(-[_WKRemoteObjectRegistry _callReplyWithID:blockInvocation:]):
Find the pending reply, decode the reply block invocation and call it.

* Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h:
Add new methods.

Tools:

Update test.

* TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm:
(TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm:
(-[RemoteObjectRegistryPlugIn sayHello:completionHandler:]):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformspiCocoaNSInvocationSPIh">trunk/Source/WebKit2/Platform/spi/Cocoa/NSInvocationSPI.h</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaRemoteObjectInvocationmm">trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaRemoteObjectRegistryh">trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaRemoteObjectRegistrymessagesin">trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.messages.in</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaRemoteObjectRegistrymm">trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaWKRemoteObjectCoderh">trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.h</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaWKRemoteObjectCodermm">trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfacemm">trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfaceInternalh">trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectRegistrymm">trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectRegistryInternalh">trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaRemoteObjectRegistrymm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaRemoteObjectRegistryPlugInmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/ChangeLog        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -1,3 +1,86 @@
</span><ins>+2015-11-09  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Add reply blocks to _WKRemoteObjectInterface similar to NSXPCConnection
+        https://bugs.webkit.org/show_bug.cgi?id=151056
+        rdar://problem/23222609
+
+        Reviewed by Tim Horton.
+
+        * Platform/spi/Cocoa/NSInvocationSPI.h:
+        Add NSBlockInvocation declaration.
+
+        * Shared/API/Cocoa/RemoteObjectInvocation.mm:
+        (WebKit::RemoteObjectInvocation::encode):
+        Encode true if we have a reply ID.
+
+        * Shared/API/Cocoa/RemoteObjectRegistry.h:
+        Add new members.
+
+        * Shared/API/Cocoa/RemoteObjectRegistry.messages.in:
+        Add new CallReplyBlock message.
+
+        * Shared/API/Cocoa/RemoteObjectRegistry.mm:
+        (WebKit::RemoteObjectRegistry::sendReplyBlock):
+        Just send the CallReplyBlock message.
+
+        (WebKit::RemoteObjectRegistry::callReplyBlock):
+        Call through to _WKRemoteObjectRegistry.
+
+        * Shared/API/Cocoa/WKRemoteObjectCoder.h:
+        Pass an optional reply selector.
+
+        * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+        (encodeInvocationArguments):
+        Don't hard-code the first argument index.
+
+        (encodeInvocation):
+        Encode block invocations.
+
+        (-[WKRemoteObjectDecoder initWithInterface:rootObjectDictionary:replyToSelector:]):
+        Initialize _replyToSelector.
+
+        (validateClass):
+        NSBlockInvocation doesn't need to conform to NSSecureCoding.
+
+        (decodeInvocationArguments):
+        Don't hard-code the first argument, take it as a parameter instead.
+
+        (decodeInvocation):
+        Decode NSBlockInvocations (reply block invocations).
+
+        (decodeObject):
+        Check for NSBlockInvocation.
+
+        * Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
+        (-[_WKRemoteObjectInterface _methodSignatureForSelector:]):
+        Return null if we can't find the method.
+
+        (-[_WKRemoteObjectInterface _methodSignatureForReplyBlockOfSelector:]):
+        Look up the reply block signature and return it.
+
+        (-[_WKRemoteObjectInterface _allowedArgumentClassesForReplyBlockOfSelector:]):
+        Look up the allowed reply argument classes and return them.
+
+        * Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h:
+        Add new methods.
+
+        * Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
+        (PendingReply::PendingReply):
+        Add new object that represents a pending reply.
+
+        (-[_WKRemoteObjectRegistry _sendInvocation:interface:]):
+        If the invocation has a reply block, add a pending reply to our map.
+
+        (-[_WKRemoteObjectRegistry _invokeMethod:]):
+        If the method we're about to invoke has a reply block, construct a special reply block that calls us back with an invocation.
+        Encode this invocation and send it back across the wire.
+
+        (-[_WKRemoteObjectRegistry _callReplyWithID:blockInvocation:]):
+        Find the pending reply, decode the reply block invocation and call it.
+
+        * Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h:
+        Add new methods.
+
</ins><span class="cx"> 2015-11-09  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add drawsBackground SPI to WKWebView, and get rid of drawsTransparentBackground from WebKit2
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformspiCocoaNSInvocationSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/spi/Cocoa/NSInvocationSPI.h (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/spi/Cocoa/NSInvocationSPI.h        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Platform/spi/Cocoa/NSInvocationSPI.h        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -34,3 +34,6 @@
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> #endif // USE(APPLE_INTERNAL_SDK)
</span><ins>+
+@interface NSBlockInvocation : NSInvocation
+@end
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaRemoteObjectInvocationmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    encoder &lt;&lt; true;
</ins><span class="cx">     encoder &lt;&lt; m_replyInfo-&gt;replyID;
</span><span class="cx">     encoder &lt;&lt; m_replyInfo-&gt;blockSignature;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaRemoteObjectRegistryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> class RemoteObjectInvocation;
</span><ins>+class UserData;
</ins><span class="cx"> 
</span><span class="cx"> class RemoteObjectRegistry final : public IPC::MessageReceiver {
</span><span class="cx"> public:
</span><span class="lines">@@ -44,6 +45,7 @@
</span><span class="cx">     ~RemoteObjectRegistry();
</span><span class="cx"> 
</span><span class="cx">     void sendInvocation(const RemoteObjectInvocation&amp;);
</span><ins>+    void sendReplyBlock(uint64_t replyID, const UserData&amp; blockInvocation);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     // IPC::MessageReceiver
</span><span class="lines">@@ -51,6 +53,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Message handlers
</span><span class="cx">     void invokeMethod(const RemoteObjectInvocation&amp;);
</span><ins>+    void callReplyBlock(uint64_t replyID, const UserData&amp; blockInvocation);
</ins><span class="cx"> 
</span><span class="cx">     _WKRemoteObjectRegistry *m_remoteObjectRegistry;
</span><span class="cx">     IPC::MessageSender&amp; m_messageSender;
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaRemoteObjectRegistrymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.messages.in (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.messages.in        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.messages.in        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -22,4 +22,5 @@
</span><span class="cx"> 
</span><span class="cx"> messages -&gt; RemoteObjectRegistry {
</span><span class="cx">     InvokeMethod(WebKit::RemoteObjectInvocation invocation)
</span><ins>+    CallReplyBlock(uint64_t replyID, WebKit::UserData blockInvocation);
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaRemoteObjectRegistrymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #import &quot;MessageSender.h&quot;
</span><span class="cx"> #import &quot;RemoteObjectInvocation.h&quot;
</span><span class="cx"> #import &quot;RemoteObjectRegistryMessages.h&quot;
</span><ins>+#import &quot;UserData.h&quot;
</ins><span class="cx"> #import &quot;_WKRemoteObjectRegistryInternal.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -48,6 +49,11 @@
</span><span class="cx">     m_messageSender.send(Messages::RemoteObjectRegistry::InvokeMethod(invocation));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RemoteObjectRegistry::sendReplyBlock(uint64_t replyID, const UserData&amp; blockInvocation)
+{
+    m_messageSender.send(Messages::RemoteObjectRegistry::CallReplyBlock(replyID, blockInvocation));
+}
+
</ins><span class="cx"> void RemoteObjectRegistry::invokeMethod(const RemoteObjectInvocation&amp; invocation)
</span><span class="cx"> {
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="lines">@@ -55,4 +61,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RemoteObjectRegistry::callReplyBlock(uint64_t replyID, const UserData&amp; blockInvocation)
+{
+    [m_remoteObjectRegistry _callReplyWithID:replyID blockInvocation:blockInvocation];
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaWKRemoteObjectCoderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.h (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.h        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.h        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx"> 
</span><span class="cx"> @interface WKRemoteObjectDecoder : NSCoder
</span><span class="cx"> 
</span><del>-- (id)initWithInterface:(_WKRemoteObjectInterface *)interface rootObjectDictionary:(const API::Dictionary*)rootObjectDictionary;
</del><ins>+- (id)initWithInterface:(_WKRemoteObjectInterface *)interface rootObjectDictionary:(const API::Dictionary*)rootObjectDictionary replyToSelector:(SEL)replyToSelector;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaWKRemoteObjectCodermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import &quot;APIDictionary.h&quot;
</span><span class="cx"> #import &quot;APINumber.h&quot;
</span><span class="cx"> #import &quot;APIString.h&quot;
</span><ins>+#import &quot;NSInvocationSPI.h&quot;
</ins><span class="cx"> #import &quot;_WKRemoteObjectInterfaceInternal.h&quot;
</span><span class="cx"> #import &lt;objc/runtime.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="lines">@@ -45,6 +46,7 @@
</span><span class="cx"> 
</span><span class="cx"> static NSString * const selectorKey = @&quot;selector&quot;;
</span><span class="cx"> static NSString * const typeStringKey = @&quot;typeString&quot;;
</span><ins>+static NSString * const isReplyBlockKey = @&quot;isReplyBlock&quot;;
</ins><span class="cx"> 
</span><span class="cx"> static RefPtr&lt;API::Dictionary&gt; createEncodedObject(WKRemoteObjectEncoder *, id);
</span><span class="cx"> 
</span><span class="lines">@@ -118,7 +120,7 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(firstArgument &lt;= argumentCount);
</span><span class="cx"> 
</span><del>-    for (NSUInteger i = 2; i &lt; argumentCount; ++i) {
</del><ins>+    for (NSUInteger i = firstArgument; i &lt; argumentCount; ++i) {
</ins><span class="cx">         const char* type = [methodSignature getArgumentTypeAtIndex:i];
</span><span class="cx"> 
</span><span class="cx">         switch (*type) {
</span><span class="lines">@@ -213,9 +215,14 @@
</span><span class="cx"> {
</span><span class="cx">     NSMethodSignature *methodSignature = invocation.methodSignature;
</span><span class="cx">     [encoder encodeObject:methodSignature._typeString forKey:typeStringKey];
</span><del>-    [encoder encodeObject:NSStringFromSelector(invocation.selector) forKey:selectorKey];
</del><span class="cx"> 
</span><del>-    encodeInvocationArguments(encoder, invocation, 2);
</del><ins>+    if ([invocation isKindOfClass:[NSBlockInvocation class]]) {
+        [encoder encodeBool:YES forKey:isReplyBlockKey];
+        encodeInvocationArguments(encoder, invocation, 1);
+    } else {
+        [encoder encodeObject:NSStringFromSelector(invocation.selector) forKey:selectorKey];
+        encodeInvocationArguments(encoder, invocation, 2);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void encodeString(WKRemoteObjectEncoder *encoder, NSString *string)
</span><span class="lines">@@ -355,13 +362,15 @@
</span><span class="cx">     const API::Dictionary* _rootDictionary;
</span><span class="cx">     const API::Dictionary* _currentDictionary;
</span><span class="cx"> 
</span><ins>+    SEL _replyToSelector;
+
</ins><span class="cx">     const API::Array* _objectStream;
</span><span class="cx">     size_t _objectStreamPosition;
</span><span class="cx"> 
</span><span class="cx">     const HashSet&lt;Class&gt;* _allowedClasses;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (id)initWithInterface:(_WKRemoteObjectInterface *)interface rootObjectDictionary:(const API::Dictionary*)rootObjectDictionary
</del><ins>+- (id)initWithInterface:(_WKRemoteObjectInterface *)interface rootObjectDictionary:(const API::Dictionary*)rootObjectDictionary replyToSelector:(SEL)replyToSelector
</ins><span class="cx"> {
</span><span class="cx">     if (!(self = [super init]))
</span><span class="cx">         return nil;
</span><span class="lines">@@ -371,6 +380,8 @@
</span><span class="cx">     _rootDictionary = rootObjectDictionary;
</span><span class="cx">     _currentDictionary = _rootDictionary;
</span><span class="cx"> 
</span><ins>+    _replyToSelector = replyToSelector;
+
</ins><span class="cx">     _objectStream = _rootDictionary-&gt;get&lt;API::Array&gt;(objectStreamKey);
</span><span class="cx"> 
</span><span class="cx">     return self;
</span><span class="lines">@@ -442,23 +453,21 @@
</span><span class="cx"> 
</span><span class="cx">     checkIfClassIsAllowed(decoder, objectClass);
</span><span class="cx"> 
</span><del>-    // NSInvocation doesn't support NSSecureCoding, but we allow it anyway.
-    if (objectClass == [NSInvocation class])
</del><ins>+    // NSInvocation and NSBlockInvocation don't support NSSecureCoding, but we allow them anyway.
+    if (objectClass == [NSInvocation class] || objectClass == [NSBlockInvocation class])
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     [decoder validateClassSupportsSecureCoding:objectClass];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocation *invocation, const Vector&lt;HashSet&lt;Class&gt;&gt;&amp; allowedArgumentClasses)
</del><ins>+static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocation *invocation, const Vector&lt;HashSet&lt;Class&gt;&gt;&amp; allowedArgumentClasses, NSUInteger firstArgument)
</ins><span class="cx"> {
</span><span class="cx">     NSMethodSignature *methodSignature = invocation.methodSignature;
</span><span class="cx">     NSUInteger argumentCount = methodSignature.numberOfArguments;
</span><span class="cx"> 
</span><del>-    // The invocation should always have have self and _cmd arguments.
-    ASSERT(argumentCount &gt;= 2);
</del><ins>+    ASSERT(firstArgument &lt;= argumentCount);
</ins><span class="cx"> 
</span><del>-    // We ignore self and _cmd.
-    for (NSUInteger i = 2; i &lt; argumentCount; ++i) {
</del><ins>+    for (NSUInteger i = firstArgument; i &lt; argumentCount; ++i) {
</ins><span class="cx">         const char* type = [methodSignature getArgumentTypeAtIndex:i];
</span><span class="cx"> 
</span><span class="cx">         switch (*type) {
</span><span class="lines">@@ -520,7 +529,7 @@
</span><span class="cx">             
</span><span class="cx">         // Objective-C object
</span><span class="cx">         case '@': {
</span><del>-            auto&amp; allowedClasses = allowedArgumentClasses[i - 2];
</del><ins>+            auto&amp; allowedClasses = allowedArgumentClasses[i - firstArgument];
</ins><span class="cx"> 
</span><span class="cx">             id value = decodeObjectFromObjectStream(decoder, allowedClasses);
</span><span class="cx">             [invocation setArgument:&amp;value atIndex:i];
</span><span class="lines">@@ -537,31 +546,52 @@
</span><span class="cx"> 
</span><span class="cx"> static NSInvocation *decodeInvocation(WKRemoteObjectDecoder *decoder)
</span><span class="cx"> {
</span><del>-    NSString *selectorString = [decoder decodeObjectOfClass:[NSString class] forKey:selectorKey];
-    if (!selectorString)
-        [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Invocation had no selector&quot;];
</del><ins>+    SEL selector = nullptr;
+    NSMethodSignature *localMethodSignature = nil;
</ins><span class="cx"> 
</span><del>-    SEL selector = NSSelectorFromString(selectorString);
-    ASSERT(selector);
</del><ins>+    BOOL isReplyBlock = [decoder decodeBoolForKey:isReplyBlockKey];
</ins><span class="cx"> 
</span><del>-    NSMethodSignature *localMethodSignature = [decoder-&gt;_interface _methodSignatureForSelector:selector];
-    if (!localMethodSignature)
-        [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Selector \&quot;%@\&quot; is not defined in the local interface&quot;, selectorString];
</del><ins>+    if (isReplyBlock) {
+        if (!decoder-&gt;_replyToSelector)
+            [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;%@: Received unknown reply block&quot;, decoder];
</ins><span class="cx"> 
</span><ins>+        localMethodSignature = [decoder-&gt;_interface _methodSignatureForReplyBlockOfSelector:decoder-&gt;_replyToSelector];
+        if (!localMethodSignature)
+            [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Reply block for selector \&quot;%s\&quot; is not defined in the local interface&quot;, sel_getName(decoder-&gt;_replyToSelector)];
+    } else {
+        NSString *selectorString = [decoder decodeObjectOfClass:[NSString class] forKey:selectorKey];
+        if (!selectorString)
+            [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Invocation had no selector&quot;];
+
+        selector = NSSelectorFromString(selectorString);
+        ASSERT(selector);
+
+        localMethodSignature = [decoder-&gt;_interface _methodSignatureForSelector:selector];
+        if (!localMethodSignature)
+            [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Selector \&quot;%@\&quot; is not defined in the local interface&quot;, selectorString];
+    }
+
</ins><span class="cx">     NSString *typeSignature = [decoder decodeObjectOfClass:[NSString class] forKey:typeStringKey];
</span><span class="cx">     if (!typeSignature)
</span><span class="cx">         [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Invocation had no type signature&quot;];
</span><span class="cx"> 
</span><span class="cx">     NSMethodSignature *remoteMethodSignature = [NSMethodSignature signatureWithObjCTypes:typeSignature.UTF8String];
</span><ins>+    localMethodSignature = remoteMethodSignature;
</ins><span class="cx">     if (![localMethodSignature isEqual:remoteMethodSignature])
</span><del>-        [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Local and remote method signatures are not equal for method \&quot;%@\&quot;&quot;, selectorString];
</del><ins>+        [NSException raise:NSInvalidUnarchiveOperationException format:@&quot;Local and remote method signatures are not equal for method \&quot;%s\&quot;&quot;, selector ? sel_getName(selector) : &quot;(no selector)&quot;];
</ins><span class="cx"> 
</span><span class="cx">     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:localMethodSignature];
</span><span class="cx"> 
</span><del>-    const auto&amp; allowedClasses = [decoder-&gt;_interface _allowedArgumentClassesForSelector:selector];
-    decodeInvocationArguments(decoder, invocation, allowedClasses);
</del><ins>+    if (isReplyBlock) {
+        const auto&amp; allowedClasses = [decoder-&gt;_interface _allowedArgumentClassesForReplyBlockOfSelector:decoder-&gt;_replyToSelector];
+        decodeInvocationArguments(decoder, invocation, allowedClasses, 1);
+    } else {
+        const auto&amp; allowedClasses = [decoder-&gt;_interface _allowedArgumentClassesForSelector:selector];
+        decodeInvocationArguments(decoder, invocation, allowedClasses, 2);
</ins><span class="cx"> 
</span><del>-    [invocation setArgument:&amp;selector atIndex:1];
</del><ins>+        [invocation setArgument:&amp;selector atIndex:1];
+    }
+
</ins><span class="cx">     return invocation;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -588,7 +618,7 @@
</span><span class="cx"> 
</span><span class="cx">     validateClass(decoder, objectClass);
</span><span class="cx"> 
</span><del>-    if (objectClass == [NSInvocation class])
</del><ins>+    if (objectClass == [NSInvocation class] || objectClass == [NSBlockInvocation class])
</ins><span class="cx">         return decodeInvocation(decoder);
</span><span class="cx"> 
</span><span class="cx">     if (objectClass == [NSString class])
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfacemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -311,6 +311,9 @@
</span><span class="cx"> 
</span><span class="cx"> - (NSMethodSignature *)_methodSignatureForSelector:(SEL)selector
</span><span class="cx"> {
</span><ins>+    if (!_methods.contains(selector))
+        return nil;
+
</ins><span class="cx">     const char* types = methodArgumentTypeEncodingForSelector(_protocol, selector);
</span><span class="cx">     if (!types)
</span><span class="cx">         return nil;
</span><span class="lines">@@ -318,6 +321,19 @@
</span><span class="cx">     return [NSMethodSignature signatureWithObjCTypes:types];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (NSMethodSignature *)_methodSignatureForReplyBlockOfSelector:(SEL)selector
+{
+    auto it = _methods.find(selector);
+    if (it  == _methods.end())
+        return nil;
+
+    auto&amp; methodInfo = it-&gt;value;
+    if (!methodInfo.replyInfo)
+        return nil;
+
+    return [NSMethodSignature signatureWithObjCTypes:methodInfo.replyInfo-&gt;replySignature.data()];
+}
+
</ins><span class="cx"> - (const Vector&lt;HashSet&lt;Class&gt;&gt;&amp;)_allowedArgumentClassesForSelector:(SEL)selector
</span><span class="cx"> {
</span><span class="cx">     ASSERT(_methods.contains(selector));
</span><span class="lines">@@ -325,6 +341,13 @@
</span><span class="cx">     return _methods.find(selector)-&gt;value.allowedArgumentClasses;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (const Vector&lt;HashSet&lt;Class&gt;&gt;&amp;)_allowedArgumentClassesForReplyBlockOfSelector:(SEL)selector
+{
+    ASSERT(_methods.contains(selector));
+
+    return _methods.find(selector)-&gt;value.replyInfo-&gt;allowedReplyClasses;
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfaceInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -35,7 +35,9 @@
</span><span class="cx"> @interface _WKRemoteObjectInterface ()
</span><span class="cx"> 
</span><span class="cx"> - (NSMethodSignature *)_methodSignatureForSelector:(SEL)selector;
</span><ins>+- (NSMethodSignature *)_methodSignatureForReplyBlockOfSelector:(SEL)selector;
</ins><span class="cx"> - (const Vector&lt;HashSet&lt;Class&gt;&gt;&amp;)_allowedArgumentClassesForSelector:(SEL)selector;
</span><ins>+- (const Vector&lt;HashSet&lt;Class&gt;&gt;&amp;)_allowedArgumentClassesForReplyBlockOfSelector:(SEL)selector;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectRegistrymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -33,22 +33,48 @@
</span><span class="cx"> #import &quot;Connection.h&quot;
</span><span class="cx"> #import &quot;RemoteObjectInvocation.h&quot;
</span><span class="cx"> #import &quot;RemoteObjectRegistry.h&quot;
</span><ins>+#import &quot;UserData.h&quot;
</ins><span class="cx"> #import &quot;WKConnectionRef.h&quot;
</span><span class="cx"> #import &quot;WKRemoteObject.h&quot;
</span><span class="cx"> #import &quot;WKRemoteObjectCoder.h&quot;
</span><span class="cx"> #import &quot;WKSharedAPICast.h&quot;
</span><del>-#import &quot;WebConnection.h&quot;
</del><span class="cx"> #import &quot;_WKRemoteObjectInterface.h&quot;
</span><ins>+#import &lt;objc/runtime.h&gt;
</ins><span class="cx"> 
</span><ins>+extern &quot;C&quot; id __NSMakeSpecialForwardingCaptureBlock(const char *signature, void (^handler)(NSInvocation *inv));
+
+static const void* replyBlockKey = &amp;replyBlockKey;
+
+@interface NSMethodSignature ()
+- (NSString *)_typeString;
+@end
+
</ins><span class="cx"> NSString * const invocationKey = @&quot;invocation&quot;;
</span><span class="cx"> 
</span><span class="cx"> using namespace WebKit;
</span><span class="cx"> 
</span><ins>+struct PendingReply {
+    PendingReply() = default;
+
+    PendingReply(_WKRemoteObjectInterface* interface, SEL selector, id block)
+        : interface(interface)
+        , selector(selector)
+        , block(adoptNS([block copy]))
+    {
+    }
+
+    RetainPtr&lt;_WKRemoteObjectInterface&gt; interface;
+    SEL selector { nullptr };
+    RetainPtr&lt;id&gt; block;
+};
+
</ins><span class="cx"> @implementation _WKRemoteObjectRegistry {
</span><span class="cx">     std::unique_ptr&lt;RemoteObjectRegistry&gt; _remoteObjectRegistry;
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;NSMapTable&gt; _remoteObjectProxies;
</span><span class="cx">     HashMap&lt;String, std::pair&lt;RetainPtr&lt;id&gt;, RetainPtr&lt;_WKRemoteObjectInterface&gt;&gt;&gt; _exportedObjects;
</span><ins>+
+    HashMap&lt;uint64_t, PendingReply&gt; _pendingReplies;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)registerExportedObject:(id)object interface:(_WKRemoteObjectInterface *)interface
</span><span class="lines">@@ -116,12 +142,12 @@
</span><span class="cx">         if (replyInfo)
</span><span class="cx">             [NSException raise:NSInvalidArgumentException format:@&quot;Only one reply block is allowed per message send. (%s)&quot;, sel_getName(invocation.selector)];
</span><span class="cx"> 
</span><del>-        id block = nullptr;
-        [invocation getArgument:&amp;block atIndex:i];
-        if (!block)
</del><ins>+        id replyBlock = nullptr;
+        [invocation getArgument:&amp;replyBlock atIndex:i];
+        if (!replyBlock)
</ins><span class="cx">             [NSException raise:NSInvalidArgumentException format:@&quot;A NULL reply block was passed into a message. (%s)&quot;, sel_getName(invocation.selector)];
</span><span class="cx"> 
</span><del>-        const char* replyBlockSignature = _Block_signature(block);
</del><ins>+        const char* replyBlockSignature = _Block_signature(replyBlock);
</ins><span class="cx"> 
</span><span class="cx">         if (strcmp([NSMethodSignature signatureWithObjCTypes:replyBlockSignature].methodReturnType, &quot;v&quot;))
</span><span class="cx">             [NSException raise:NSInvalidArgumentException format:@&quot;Return value of block argument must be 'void'. (%s)&quot;, sel_getName(invocation.selector)];
</span><span class="lines">@@ -131,6 +157,9 @@
</span><span class="cx">         // Replace the block object so we won't try to encode it.
</span><span class="cx">         id null = nullptr;
</span><span class="cx">         [invocation setArgument:&amp;null atIndex:i];
</span><ins>+
+        ASSERT(!_pendingReplies.contains(replyInfo-&gt;replyID));
+        _pendingReplies.add(replyInfo-&gt;replyID, PendingReply(interface, invocation.selector, replyBlock));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;WKRemoteObjectEncoder&gt; encoder = adoptNS([[WKRemoteObjectEncoder alloc] init]);
</span><span class="lines">@@ -159,8 +188,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    RetainPtr&lt;WKRemoteObjectDecoder&gt; decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:interfaceAndObject.second.get() rootObjectDictionary:encodedInvocation]);
</del><ins>+    RetainPtr&lt;_WKRemoteObjectInterface&gt; interface = interfaceAndObject.second;
</ins><span class="cx"> 
</span><ins>+    auto decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:interface.get() rootObjectDictionary:encodedInvocation replyToSelector:nullptr]);
+
</ins><span class="cx">     NSInvocation *invocation = nil;
</span><span class="cx"> 
</span><span class="cx">     @try {
</span><span class="lines">@@ -169,6 +200,38 @@
</span><span class="cx">         NSLog(@&quot;Exception caught during decoding of message: %@&quot;, exception);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (auto* replyInfo = remoteObjectInvocation.replyInfo()) {
+        NSMethodSignature *methodSignature = invocation.methodSignature;
+
+        // Look for the block argument.
+        for (NSUInteger i = 0, count = methodSignature.numberOfArguments; i &lt; count; ++i) {
+            const char *type = [methodSignature getArgumentTypeAtIndex:i];
+
+            if (strcmp(type, &quot;@?&quot;))
+                continue;
+
+            // We found the block.
+            // FIXME: Validate the signature.
+            NSMethodSignature *wireBlockSignature = [NSMethodSignature signatureWithObjCTypes:replyInfo-&gt;blockSignature.utf8().data()];
+
+            RetainPtr&lt;_WKRemoteObjectRegistry&gt; remoteObjectRegistry = self;
+            uint64_t replyID = replyInfo-&gt;replyID;
+            id replyBlock = __NSMakeSpecialForwardingCaptureBlock(wireBlockSignature._typeString.UTF8String, [interface, remoteObjectRegistry, replyID](NSInvocation *invocation) {
+
+                auto encoder = adoptNS([[WKRemoteObjectEncoder alloc] init]);
+                [encoder encodeObject:invocation forKey:invocationKey];
+
+                remoteObjectRegistry-&gt;_remoteObjectRegistry-&gt;sendReplyBlock(replyID, UserData([encoder rootObjectDictionary]));
+            });
+
+            [invocation setArgument:&amp;replyBlock atIndex:i];
+
+            // Make sure that the block won't be destroyed before the invocation.
+            objc_setAssociatedObject(invocation, replyBlockKey, replyBlock, OBJC_ASSOCIATION_RETAIN);
+            break;
+        }
+    }
+
</ins><span class="cx">     invocation.target = interfaceAndObject.first.get();
</span><span class="cx"> 
</span><span class="cx">     @try {
</span><span class="lines">@@ -178,6 +241,34 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_callReplyWithID:(uint64_t)replyID blockInvocation:(const WebKit::UserData&amp;)blockInvocation
+{
+    auto encodedInvocation = blockInvocation.object();
+    if (!encodedInvocation || encodedInvocation-&gt;type() != API::Object::Type::Dictionary)
+        return;
+
+    auto it = _pendingReplies.find(replyID);
+    if (it == _pendingReplies.end())
+        return;
+
+    auto pendingReply = it-&gt;value;
+    _pendingReplies.remove(it);
+
+    auto decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:pendingReply.interface.get() rootObjectDictionary:static_cast&lt;API::Dictionary*&gt;(encodedInvocation) replyToSelector:pendingReply.selector]);
+
+    NSInvocation *replyInvocation = nil;
+
+    @try {
+        replyInvocation = [decoder decodeObjectOfClass:[NSInvocation class] forKey:invocationKey];
+    } @catch (NSException *exception) {
+        NSLog(@&quot;Exception caught during decoding of reply: %@&quot;, exception);
+        return;
+    }
+
+    [replyInvocation setTarget:pendingReply.block.get()];
+    [replyInvocation invoke];
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectRegistryInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> class RemoteObjectInvocation;
</span><span class="cx"> class RemoteObjectRegistry;
</span><ins>+class UserData;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @interface _WKRemoteObjectRegistry ()
</span><span class="lines">@@ -46,6 +47,8 @@
</span><span class="cx"> - (void)_sendInvocation:(NSInvocation *)invocation interface:(_WKRemoteObjectInterface *)interface;
</span><span class="cx"> - (void)_invokeMethod:(const WebKit::RemoteObjectInvocation&amp;)invocation;
</span><span class="cx"> 
</span><ins>+- (void)_callReplyWithID:(uint64_t)replyID blockInvocation:(const WebKit::UserData&amp;)blockInvocation;
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Tools/ChangeLog        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-11-09  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Add reply blocks to _WKRemoteObjectInterface similar to NSXPCConnection
+        https://bugs.webkit.org/show_bug.cgi?id=151056
+        rdar://problem/23222609
+
+        Reviewed by Tim Horton.
+
+        Update test.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm:
+        (-[RemoteObjectRegistryPlugIn sayHello:completionHandler:]):
+
</ins><span class="cx"> 2015-11-09  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add drawsBackground SPI to WKWebView, and get rid of drawsTransparentBackground from WebKit2
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaRemoteObjectRegistrymm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -60,9 +60,14 @@
</span><span class="cx">         }];
</span><span class="cx">         TestWebKitAPI::Util::run(&amp;isDone);
</span><span class="cx"> 
</span><del>-        [object sayHello:@&quot;Hello Again!&quot; completionHandler:^(NSString *) {
-            // FIXME: Check the string here.
</del><ins>+        isDone = false;
+        [object sayHello:@&quot;Hello Again!&quot; completionHandler:^(NSString *result) {
+            EXPECT_TRUE([result isKindOfClass:[NSString class]]);
+            EXPECT_WK_STREQ(result, @&quot;Your string was 'Hello Again!'&quot;);
+            isDone = true;
</ins><span class="cx">         }];
</span><ins>+
+        TestWebKitAPI::Util::run(&amp;isDone);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaRemoteObjectRegistryPlugInmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm (192184 => 192185)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm        2015-11-10 00:03:28 UTC (rev 192184)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm        2015-11-10 00:05:30 UTC (rev 192185)
</span><span class="lines">@@ -64,8 +64,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)sayHello:(NSString *)hello completionHandler:(void (^)(NSString *))completionHandler
</span><span class="cx"> {
</span><del>-    // FIXME: Actually call this.
-    // completionHandler([NSString stringWithFormat:@&quot;Your string was '%@'&quot;, hello]);
</del><ins>+    completionHandler([NSString stringWithFormat:@&quot;Your string was '%@'&quot;, hello]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre>
</div>
</div>

</body>
</html>