<!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>[242551] 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/242551">242551</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2019-03-06 09:38:37 -0800 (Wed, 06 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Frequent 1 second IPC deadlocks when showing a paste callout
https://bugs.webkit.org/show_bug.cgi?id=195354
<rdar://problem/48624675>

Reviewed by Tim Horton.

Source/WebKit:

When triggering programmatic paste, we frequently hit deadlocks due to sync IPC going from the UI process to the
web process and vice versa. What happens in this scenario is that prior to triggering programmatic paste, the
page may try to move focus to a different element (e.g. a hidden editable area) before calling `execCommand`.
This causes us to send an ElementDidFocus message to the UI process, followed by RequestDOMPasteAccess.

However, upon receiving ElementDidFocus, we reload input views and (in the process) UIKit requests the
autocorrection context, which we implement in WebKit using a sync message to the web process due to
<rdar://problem/16207002> and its blocking bug <rdar://problem/48383001>. This means we'll end up in a state
where both the UI process and web process are blocked on each other waiting for a sync IPC response, and the UI
process is hung for a second until the IPC message times out.

Ideally, we should fix this by addressing <rdar://problem/16207002>. However, this requires potentially large
changes in UIKit (<rdar://problem/48383001>); for the time being, work around this deadlock by refactoring
synchronous autocorrection context requests such that they can be resolved by an out-of-band IPC response
(HandleAutocorrectionContext). Then prior to requesting DOM paste access, preemptively send a
HandleAutocorrectionContext message to the UI process to unblock any pending synchronous autocorrection context
requests.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::handleAutocorrectionContext):
* UIProcess/ios/WKContentViewInteraction.h:

Make it possible for WKContentView to remember its current pending autocorrection context completion handler.
This is invoked and cleared out in `-_invokePendingAutocorrectionContextHandler:`.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _invokePendingAutocorrectionContextHandler:]):
(-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
(-[WKContentView _handleAutocorrectionContext:]):

Handle an autocorrection context response. This is invoked when the web process either handles an autocorrection
context message, or when it preemptively sends an autocorrection context before requesting DOM paste access.

(+[WKAutocorrectionContext emptyAutocorrectionContext]):

Add a helper to create an empty autocorrection context.

* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::requestAutocorrectionContext):
(WebKit::WebPageProxy::handleAutocorrectionContext):
(WebKit::WebPageProxy::autocorrectionContextSync): Deleted.

Removed this sync version, since we now only have requestAutocorrectionContext.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::requestDOMPasteAccess):

Send WebPageProxy::HandleAutocorrectionContext, and add a FIXME referencing <rdar://problem/16207002>.

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Split AutocorrectionContextSync into RequestAutocorrectionContext and HandleAutocorrectionContext; additionally,
remove the existing RequestAutocorrectionContext message.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestAutocorrectionContext):
(WebKit::WebPage::autocorrectionContextSync): Deleted.

LayoutTests:

Most of these tests currently encounter and rely on the 1 second IPC timeout to finish. To test this fix, force
`ignoreSynchronousMessagingTimeouts=true` to make them fail if the processes encounter a deadlock.

* editing/pasteboard/ios/dom-paste-confirmation.html:
* editing/pasteboard/ios/dom-paste-consecutive-confirmations.html:
* editing/pasteboard/ios/dom-paste-rejection.html:
* editing/pasteboard/ios/dom-paste-requires-user-gesture.html:
* editing/pasteboard/ios/dom-paste-same-origin.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardiosdompasteconfirmationhtml">trunk/LayoutTests/editing/pasteboard/ios/dom-paste-confirmation.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardiosdompasteconsecutiveconfirmationshtml">trunk/LayoutTests/editing/pasteboard/ios/dom-paste-consecutive-confirmations.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardiosdompasterejectionhtml">trunk/LayoutTests/editing/pasteboard/ios/dom-paste-rejection.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardiosdompasterequiresusergesturehtml">trunk/LayoutTests/editing/pasteboard/ios/dom-paste-requires-user-gesture.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardiosdompastesameoriginhtml">trunk/LayoutTests/editing/pasteboard/ios/dom-paste-same-origin.html</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessPageClienth">trunk/Source/WebKit/UIProcess/PageClient.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxymessagesin">trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosPageClientImplIOSh">trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosPageClientImplIOSmm">trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionh">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWebPageProxyIOSmm">trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagecpp">trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagemessagesin">trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/LayoutTests/ChangeLog 2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2019-03-06  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Frequent 1 second IPC deadlocks when showing a paste callout
+        https://bugs.webkit.org/show_bug.cgi?id=195354
+        <rdar://problem/48624675>
+
+        Reviewed by Tim Horton.
+
+        Most of these tests currently encounter and rely on the 1 second IPC timeout to finish. To test this fix, force
+        `ignoreSynchronousMessagingTimeouts=true` to make them fail if the processes encounter a deadlock.
+
+        * editing/pasteboard/ios/dom-paste-confirmation.html:
+        * editing/pasteboard/ios/dom-paste-consecutive-confirmations.html:
+        * editing/pasteboard/ios/dom-paste-rejection.html:
+        * editing/pasteboard/ios/dom-paste-requires-user-gesture.html:
+        * editing/pasteboard/ios/dom-paste-same-origin.html:
+
</ins><span class="cx"> 2019-03-06  Javier Fernandez  <jfernandez@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         Import new tests from the CSS Text 3 WPT test suite
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardiosdompasteconfirmationhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/ios/dom-paste-confirmation.html (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/ios/dom-paste-confirmation.html     2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/LayoutTests/editing/pasteboard/ios/dom-paste-confirmation.html        2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ] -->
</del><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ignoreSynchronousMessagingTimeouts=true ] -->
</ins><span class="cx"> <html>
</span><span class="cx"> <meta name="viewport" content="width=device-width, initial-scale=1">
</span><span class="cx"> <head>
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardiosdompasteconsecutiveconfirmationshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/ios/dom-paste-consecutive-confirmations.html (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/ios/dom-paste-consecutive-confirmations.html        2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/LayoutTests/editing/pasteboard/ios/dom-paste-consecutive-confirmations.html   2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ] -->
</del><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ignoreSynchronousMessagingTimeouts=true ] -->
</ins><span class="cx"> <html>
</span><span class="cx"> <meta name="viewport" content="width=device-width, initial-scale=1">
</span><span class="cx"> <head>
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardiosdompasterejectionhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/ios/dom-paste-rejection.html (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/ios/dom-paste-rejection.html        2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/LayoutTests/editing/pasteboard/ios/dom-paste-rejection.html   2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ] -->
</del><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ignoreSynchronousMessagingTimeouts=true ] -->
</ins><span class="cx"> <html>
</span><span class="cx"> <meta name="viewport" content="width=device-width, initial-scale=1">
</span><span class="cx"> <head>
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardiosdompasterequiresusergesturehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/ios/dom-paste-requires-user-gesture.html (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/ios/dom-paste-requires-user-gesture.html    2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/LayoutTests/editing/pasteboard/ios/dom-paste-requires-user-gesture.html       2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ] -->
</del><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ignoreSynchronousMessagingTimeouts=true ] -->
</ins><span class="cx"> <html>
</span><span class="cx"> <meta name="viewport" content="width=device-width, initial-scale=1">
</span><span class="cx"> <head>
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardiosdompastesameoriginhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/ios/dom-paste-same-origin.html (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/ios/dom-paste-same-origin.html      2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/LayoutTests/editing/pasteboard/ios/dom-paste-same-origin.html 2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ] -->
</del><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ignoreSynchronousMessagingTimeouts=true ] -->
</ins><span class="cx"> <html>
</span><span class="cx"> <meta name="viewport" content="width=device-width, initial-scale=1">
</span><span class="cx"> <head>
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/ChangeLog       2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -1,3 +1,74 @@
</span><ins>+2019-03-06  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Frequent 1 second IPC deadlocks when showing a paste callout
+        https://bugs.webkit.org/show_bug.cgi?id=195354
+        <rdar://problem/48624675>
+
+        Reviewed by Tim Horton.
+
+        When triggering programmatic paste, we frequently hit deadlocks due to sync IPC going from the UI process to the
+        web process and vice versa. What happens in this scenario is that prior to triggering programmatic paste, the
+        page may try to move focus to a different element (e.g. a hidden editable area) before calling `execCommand`.
+        This causes us to send an ElementDidFocus message to the UI process, followed by RequestDOMPasteAccess.
+
+        However, upon receiving ElementDidFocus, we reload input views and (in the process) UIKit requests the
+        autocorrection context, which we implement in WebKit using a sync message to the web process due to
+        <rdar://problem/16207002> and its blocking bug <rdar://problem/48383001>. This means we'll end up in a state
+        where both the UI process and web process are blocked on each other waiting for a sync IPC response, and the UI
+        process is hung for a second until the IPC message times out.
+
+        Ideally, we should fix this by addressing <rdar://problem/16207002>. However, this requires potentially large
+        changes in UIKit (<rdar://problem/48383001>); for the time being, work around this deadlock by refactoring
+        synchronous autocorrection context requests such that they can be resolved by an out-of-band IPC response
+        (HandleAutocorrectionContext). Then prior to requesting DOM paste access, preemptively send a
+        HandleAutocorrectionContext message to the UI process to unblock any pending synchronous autocorrection context
+        requests.
+
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::handleAutocorrectionContext):
+        * UIProcess/ios/WKContentViewInteraction.h:
+
+        Make it possible for WKContentView to remember its current pending autocorrection context completion handler.
+        This is invoked and cleared out in `-_invokePendingAutocorrectionContextHandler:`.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _invokePendingAutocorrectionContextHandler:]):
+        (-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
+        (-[WKContentView _handleAutocorrectionContext:]):
+
+        Handle an autocorrection context response. This is invoked when the web process either handles an autocorrection
+        context message, or when it preemptively sends an autocorrection context before requesting DOM paste access.
+
+        (+[WKAutocorrectionContext emptyAutocorrectionContext]):
+
+        Add a helper to create an empty autocorrection context.
+
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::requestAutocorrectionContext):
+        (WebKit::WebPageProxy::handleAutocorrectionContext):
+        (WebKit::WebPageProxy::autocorrectionContextSync): Deleted.
+
+        Removed this sync version, since we now only have requestAutocorrectionContext.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::requestDOMPasteAccess):
+
+        Send WebPageProxy::HandleAutocorrectionContext, and add a FIXME referencing <rdar://problem/16207002>.
+
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
+        Split AutocorrectionContextSync into RequestAutocorrectionContext and HandleAutocorrectionContext; additionally,
+        remove the existing RequestAutocorrectionContext message.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestAutocorrectionContext):
+        (WebKit::WebPage::autocorrectionContextSync): Deleted.
+
</ins><span class="cx"> 2019-03-06  Rob Buis  <rbuis@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         Consider supporting the `referrerpolicy` attribute.
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessPageClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/PageClient.h (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/PageClient.h       2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/PageClient.h  2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -130,6 +130,7 @@
</span><span class="cx"> 
</span><span class="cx"> struct FocusedElementInformation;
</span><span class="cx"> struct InteractionInformationAtPosition;
</span><ins>+struct WebAutocorrectionContext;
</ins><span class="cx"> struct WebHitTestResultData;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TOUCH_EVENTS)
</span><span class="lines">@@ -394,6 +395,8 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void enableInspectorNodeSearch() = 0;
</span><span class="cx">     virtual void disableInspectorNodeSearch() = 0;
</span><ins>+
+    virtual void handleAutocorrectionContext(const WebAutocorrectionContext&) = 0;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // Auxiliary Client Creation
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -650,8 +650,8 @@
</span><span class="cx">     void requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&&);
</span><span class="cx">     void applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&&);
</span><span class="cx">     bool applyAutocorrection(const String& correction, const String& originalText);
</span><del>-    void requestAutocorrectionContext(Function<void(const WebAutocorrectionContext&, CallbackBase::Error)>&&);
-    WebAutocorrectionContext autocorrectionContextSync();
</del><ins>+    void requestAutocorrectionContext();
+    void handleAutocorrectionContext(const WebAutocorrectionContext&);
</ins><span class="cx">     void requestDictationContext(WTF::Function<void (const String&, const String&, const String&, CallbackBase::Error)>&&);
</span><span class="cx">     void replaceDictatedText(const String& oldText, const String& newText);
</span><span class="cx">     void replaceSelectedText(const String& oldText, const String& newText);
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in   2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in      2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -417,6 +417,7 @@
</span><span class="cx">     DisableInspectorNodeSearch()
</span><span class="cx"> 
</span><span class="cx">     UpdateStringForFind(String findString)
</span><ins>+    HandleAutocorrectionContext(struct WebKit::WebAutocorrectionContext context)
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     DidChangeInspectorFrontendCount(uint64_t count)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosPageClientImplIOSh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h    2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h       2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -236,6 +236,8 @@
</span><span class="cx">     void didChangeDragCaretRect(const WebCore::IntRect& previousCaretRect, const WebCore::IntRect& caretRect) override;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    void handleAutocorrectionContext(const WebAutocorrectionContext&) final;
+
</ins><span class="cx">     void didFinishProcessingAllPendingMouseEvents() final { }
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(PENCILKIT)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosPageClientImplIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm   2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm      2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -857,6 +857,11 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+void PageClientImpl::handleAutocorrectionContext(const WebAutocorrectionContext& context)
+{
+    [m_contentView _handleAutocorrectionContext:context];
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(IOS_FAMILY)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h     2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h        2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -85,6 +85,7 @@
</span><span class="cx"> class SmartMagnificationController;
</span><span class="cx"> class WebOpenPanelResultListenerProxy;
</span><span class="cx"> class WebPageProxy;
</span><ins>+struct WebAutocorrectionContext;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @class _UILookupGestureRecognizer;
</span><span class="lines">@@ -318,6 +319,7 @@
</span><span class="cx"> 
</span><span class="cx">     BOOL _hasSetUpInteractions;
</span><span class="cx">     CompletionHandler<void(WebCore::DOMPasteAccessResponse)> _domPasteRequestHandler;
</span><ins>+    BlockPtr<void(UIWKAutocorrectionContext *)> _pendingAutocorrectionContextHandler;
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">     WebKit::DragDropInteractionState _dragDropInteractionState;
</span><span class="lines">@@ -465,6 +467,8 @@
</span><span class="cx"> - (WKDrawingCoordinator *)_drawingCoordinator;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+- (void)_handleAutocorrectionContext:(const WebKit::WebAutocorrectionContext&)context;
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @interface WKContentView (WKTesting)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm    2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm       2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -276,6 +276,7 @@
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @interface WKAutocorrectionContext : UIWKAutocorrectionContext
</span><ins>++ (WKAutocorrectionContext *)emptyAutocorrectionContext;
</ins><span class="cx"> + (WKAutocorrectionContext *)autocorrectionContextWithContext:(const WebKit::WebAutocorrectionContext&)context;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="lines">@@ -3579,6 +3580,12 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_invokePendingAutocorrectionContextHandler:(WKAutocorrectionContext *)context
+{
+    if (auto handler = WTFMove(_pendingAutocorrectionContextHandler))
+        handler(context);
+}
+
</ins><span class="cx"> - (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler
</span><span class="cx"> {
</span><span class="cx">     if (!completionHandler) {
</span><span class="lines">@@ -3588,7 +3595,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(UIKIT_KEYBOARD_ADDITIONS)
</span><span class="cx">     if ([self _disableAutomaticKeyboardUI]) {
</span><del>-        completionHandler([WKAutocorrectionContext autocorrectionContextWithContext:(WebKit::WebAutocorrectionContext { })]);
</del><ins>+        completionHandler(WKAutocorrectionContext.emptyAutocorrectionContext);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="lines">@@ -3596,14 +3603,21 @@
</span><span class="cx">     // FIXME: Remove the synchronous call when <rdar://problem/16207002> is fixed.
</span><span class="cx">     const bool useSyncRequest = true;
</span><span class="cx"> 
</span><ins>+    [self _invokePendingAutocorrectionContextHandler:WKAutocorrectionContext.emptyAutocorrectionContext];
+
+    _pendingAutocorrectionContextHandler = completionHandler;
+    _page->requestAutocorrectionContext();
+
</ins><span class="cx">     if (useSyncRequest) {
</span><del>-        completionHandler([WKAutocorrectionContext autocorrectionContextWithContext:_page->autocorrectionContextSync()]);
</del><ins>+        _page->process().connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::HandleAutocorrectionContext>(_page->pageID(), 1_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives);
+        [self _invokePendingAutocorrectionContextHandler:WKAutocorrectionContext.emptyAutocorrectionContext];
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><ins>+}
</ins><span class="cx"> 
</span><del>-    _page->requestAutocorrectionContext([protectedSelf = retainPtr(self), completion = makeBlockPtr(completionHandler)] (auto& context, auto) {
-        completion([WKAutocorrectionContext autocorrectionContextWithContext:context]);
-    });
</del><ins>+- (void)_handleAutocorrectionContext:(const WebKit::WebAutocorrectionContext&)context
+{
+    [self _invokePendingAutocorrectionContextHandler:[WKAutocorrectionContext autocorrectionContextWithContext:context]];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // UIWebFormAccessoryDelegate
</span><span class="lines">@@ -7410,6 +7424,11 @@
</span><span class="cx"> 
</span><span class="cx"> @implementation WKAutocorrectionContext
</span><span class="cx"> 
</span><ins>++ (WKAutocorrectionContext *)emptyAutocorrectionContext
+{
+    return [self autocorrectionContextWithContext:WebKit::WebAutocorrectionContext { }];
+}
+
</ins><span class="cx"> + (WKAutocorrectionContext *)autocorrectionContextWithContext:(const WebKit::WebAutocorrectionContext&)webContext
</span><span class="cx"> {
</span><span class="cx">     WKAutocorrectionContext *context = [[WKAutocorrectionContext alloc] init];
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWebPageProxyIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm     2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm        2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -563,22 +563,14 @@
</span><span class="cx">     m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPageProxy::requestAutocorrectionContext(Function<void(const WebAutocorrectionContext&, CallbackBase::Error)>&& callback)
</del><ins>+void WebPageProxy::requestAutocorrectionContext()
</ins><span class="cx"> {
</span><del>-    if (!isValid()) {
-        callback({ }, CallbackBase::Error::OwnerWasInvalidated);
-        return;
-    }
-
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
-    m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
</del><ins>+    m_process->send(Messages::WebPage::RequestAutocorrectionContext(), m_pageID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebAutocorrectionContext WebPageProxy::autocorrectionContextSync()
</del><ins>+void WebPageProxy::handleAutocorrectionContext(const WebAutocorrectionContext& context)
</ins><span class="cx"> {
</span><del>-    WebAutocorrectionContext context;
-    m_process->sendSync(Messages::WebPage::AutocorrectionContextSync(), Messages::WebPage::AutocorrectionContextSync::Reply(context), m_pageID);
-    return context;
</del><ins>+    pageClient().handleAutocorrectionContext(context);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::getSelectionContext(WTF::Function<void(const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp       2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp  2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -268,6 +268,7 @@
</span><span class="cx"> #include "InteractionInformationAtPosition.h"
</span><span class="cx"> #include "InteractionInformationRequest.h"
</span><span class="cx"> #include "RemoteLayerTreeDrawingArea.h"
</span><ins>+#include "WebAutocorrectionContext.h"
</ins><span class="cx"> #include <CoreGraphics/CoreGraphics.h>
</span><span class="cx"> #include <WebCore/Icon.h>
</span><span class="cx"> #include <pal/spi/cocoa/CoreTextSPI.h>
</span><span class="lines">@@ -6373,6 +6374,13 @@
</span><span class="cx"> WebCore::DOMPasteAccessResponse WebPage::requestDOMPasteAccess(const String& originIdentifier)
</span><span class="cx"> {
</span><span class="cx">     auto response = WebCore::DOMPasteAccessResponse::DeniedForGesture;
</span><ins>+#if PLATFORM(IOS_FAMILY)
+    // FIXME: Computing and sending an autocorrection context is a workaround for the fact that autocorrection context
+    // requests on iOS are currently synchronous in the web process. This allows us to immediately fulfill pending
+    // autocorrection context requests in the UI process on iOS before handling the DOM paste request. This workaround
+    // should be removed once <rdar://problem/16207002> is resolved.
+    send(Messages::WebPageProxy::HandleAutocorrectionContext(autocorrectionContext()));
+#endif
</ins><span class="cx">     sendSyncWithDelayedReply(Messages::WebPageProxy::RequestDOMPasteAccess(rectForElementAtInteractionLocation(), originIdentifier), Messages::WebPageProxy::RequestDOMPasteAccess::Reply(response));
</span><span class="cx">     return response;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -641,8 +641,7 @@
</span><span class="cx">     void requestAutocorrectionData(const String& textForAutocorrection, CallbackID);
</span><span class="cx">     void applyAutocorrection(const String& correction, const String& originalText, CallbackID);
</span><span class="cx">     void syncApplyAutocorrection(const String& correction, const String& originalText, CompletionHandler<void(bool)>&&);
</span><del>-    void requestAutocorrectionContext(CallbackID);
-    void autocorrectionContextSync(CompletionHandler<void(WebAutocorrectionContext&&)>&&);
</del><ins>+    void requestAutocorrectionContext();
</ins><span class="cx">     void getPositionInformation(const InteractionInformationRequest&, CompletionHandler<void(InteractionInformationAtPosition&&)>&&);
</span><span class="cx">     void requestPositionInformation(const InteractionInformationRequest&);
</span><span class="cx">     void startInteractionWithElementAtPosition(const WebCore::IntPoint&);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in       2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in  2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -78,8 +78,7 @@
</span><span class="cx">     RequestAutocorrectionData(String textForAutocorrection, WebKit::CallbackID callbackID)
</span><span class="cx">     ApplyAutocorrection(String correction, String originalText, WebKit::CallbackID callbackID)
</span><span class="cx">     SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) Delayed
</span><del>-    RequestAutocorrectionContext(WebKit::CallbackID callbackID)
-    AutocorrectionContextSync() -> (struct WebKit::WebAutocorrectionContext context) Delayed
</del><ins>+    RequestAutocorrectionContext()
</ins><span class="cx">     RequestEvasionRectsAboveSelection() -> (Vector<WebCore::FloatRect> rects) Async
</span><span class="cx">     GetPositionInformation(struct WebKit::InteractionInformationRequest request) -> (struct WebKit::InteractionInformationAtPosition information) Delayed
</span><span class="cx">     RequestPositionInformation(struct WebKit::InteractionInformationRequest request)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (242550 => 242551)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-03-06 15:57:06 UTC (rev 242550)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm    2019-03-06 17:38:37 UTC (rev 242551)
</span><span class="lines">@@ -2157,16 +2157,11 @@
</span><span class="cx">     return { WTFMove(contextBefore), WTFMove(markedText), WTFMove(selectedText), WTFMove(contextAfter), location, length };
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::requestAutocorrectionContext(CallbackID callbackID)
</del><ins>+void WebPage::requestAutocorrectionContext()
</ins><span class="cx"> {
</span><del>-    send(Messages::WebPageProxy::AutocorrectionContextCallback(autocorrectionContext(), callbackID));
</del><ins>+    send(Messages::WebPageProxy::HandleAutocorrectionContext(autocorrectionContext()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::autocorrectionContextSync(CompletionHandler<void(WebAutocorrectionContext&&)>&& completionHandler)
-{
-    completionHandler(autocorrectionContext());
-}
-
</del><span class="cx"> static HTMLAnchorElement* containingLinkElement(Element* element)
</span><span class="cx"> {
</span><span class="cx">     for (auto& currentElement : elementLineage(element)) {
</span></span></pre>
</div>
</div>

</body>
</html>