<!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>[244400] 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/244400">244400</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2019-04-17 13:20:40 -0700 (Wed, 17 Apr 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>UI↔Web deadlock when printing with a JavaScript alert visible
https://bugs.webkit.org/show_bug.cgi?id=196839
<rdar://problem/49157642>

Reviewed by Andy Estes.

Source/WebKit:

* Platform/IPC/Connection.cpp:
(IPC::Connection::dispatchWorkQueueMessageReceiverMessage):
(IPC::Connection::sendSyncReply):
(IPC::Connection::dispatchSyncMessage):
* Platform/IPC/Connection.h:
(IPC::Connection::hasOutstandingOutgoingSynchronousReplies const):
Keep track of whether we owe the other side of the connection any
delayed sync replies.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _webViewPrintFormatter]):
Most actions one can take with a _WKWebViewPrintFormatter involve
synchronously messaging the Web Content process with an infinite timeout.
Doing so while the Web Content process is awaiting a reply to a deferred-reply
synchronous message (like, say, an alert()) results in an app-destroying deadlock.
Instead of that, return a nil _WKWebViewPrintFormatter, indicating to the client
that we can't print right now.

* UIProcess/ios/WKContentView.mm:
(-[WKContentView _wk_pageCountForPrintFormatter:]):
(-[WKContentView _wk_printedDocument]):
The above isn't sufficient, though, because a sync message could arrive and
be handled between creation and use of the _WKWebViewPrintFormatter.
So, we also bail with a zero page count and null CGPDFDocument immediately
before we would send a sync message to the Web Content process. Clients
handle this less gracefully (e.g. showing a zero page PDF), but it is
very rare compared to the above case.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm: Added.
(-[PrintOnAlertUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCConnectioncpp">trunk/Source/WebKit/Platform/IPC/Connection.cpp</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCConnectionh">trunk/Source/WebKit/Platform/IPC/Connection.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewmm">trunk/Source/WebKit/UIProcess/ios/WKContentView.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaWKWebViewPrintFormattermm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Source/WebKit/ChangeLog       2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2019-04-17  Tim Horton  <timothy_horton@apple.com>
+
+        UI↔Web deadlock when printing with a JavaScript alert visible
+        https://bugs.webkit.org/show_bug.cgi?id=196839
+        <rdar://problem/49157642>
+
+        Reviewed by Andy Estes.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::dispatchWorkQueueMessageReceiverMessage):
+        (IPC::Connection::sendSyncReply):
+        (IPC::Connection::dispatchSyncMessage):
+        * Platform/IPC/Connection.h:
+        (IPC::Connection::hasOutstandingOutgoingSynchronousReplies const):
+        Keep track of whether we owe the other side of the connection any
+        delayed sync replies.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _webViewPrintFormatter]):
+        Most actions one can take with a _WKWebViewPrintFormatter involve
+        synchronously messaging the Web Content process with an infinite timeout.
+        Doing so while the Web Content process is awaiting a reply to a deferred-reply
+        synchronous message (like, say, an alert()) results in an app-destroying deadlock.
+        Instead of that, return a nil _WKWebViewPrintFormatter, indicating to the client
+        that we can't print right now.
+
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _wk_pageCountForPrintFormatter:]):
+        (-[WKContentView _wk_printedDocument]):
+        The above isn't sufficient, though, because a sync message could arrive and
+        be handled between creation and use of the _WKWebViewPrintFormatter.
+        So, we also bail with a zero page count and null CGPDFDocument immediately
+        before we would send a sync message to the Web Content process. Clients
+        handle this less gracefully (e.g. showing a zero page PDF), but it is
+        very rare compared to the above case.
+
</ins><span class="cx"> 2019-04-17  Zalan Bujtas  <zalan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [ContentChangeObserver] Use aria role as a hint whether a tap should result in a synthetic click
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/Connection.cpp  2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp     2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -341,6 +341,8 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    m_outstandingOutgoingSynchronousReplyCount++;
+
</ins><span class="cx">     auto replyEncoder = std::make_unique<Encoder>("IPC", "SyncMessageReply", syncRequestID);
</span><span class="cx"> 
</span><span class="cx">     // Hand off both the decoder and encoder to the work queue message receiver.
</span><span class="lines">@@ -458,6 +460,9 @@
</span><span class="cx"> 
</span><span class="cx"> bool Connection::sendSyncReply(std::unique_ptr<Encoder> encoder)
</span><span class="cx"> {
</span><ins>+    ASSERT(m_outstandingOutgoingSynchronousReplyCount);
+    m_outstandingOutgoingSynchronousReplyCount--;
+
</ins><span class="cx">     return sendMessage(WTFMove(encoder), { });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -888,6 +893,8 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    m_outstandingOutgoingSynchronousReplyCount++;
+
</ins><span class="cx">     auto replyEncoder = std::make_unique<Encoder>("IPC", "SyncMessageReply", syncRequestID);
</span><span class="cx"> 
</span><span class="cx">     if (decoder.messageReceiverName() == "IPC" && decoder.messageName() == "WrappedAsyncMessageForTesting") {
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/Connection.h    2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h       2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -196,6 +196,8 @@
</span><span class="cx"> 
</span><span class="cx">     bool inSendSync() const { return m_inSendSyncCount; }
</span><span class="cx"> 
</span><ins>+    bool hasOutstandingOutgoingSynchronousReplies() const { return m_outstandingOutgoingSynchronousReplyCount; }
+
</ins><span class="cx">     Identifier identifier() const;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="lines">@@ -297,6 +299,7 @@
</span><span class="cx">     unsigned m_inDispatchMessageCount;
</span><span class="cx">     unsigned m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount;
</span><span class="cx">     unsigned m_inDispatchMessageMarkedToUseFullySynchronousModeForTesting { 0 };
</span><ins>+    unsigned m_outstandingOutgoingSynchronousReplyCount { 0 };
</ins><span class="cx">     bool m_fullySynchronousModeIsAllowedForTesting { false };
</span><span class="cx">     bool m_ignoreTimeoutsForTesting { false };
</span><span class="cx">     bool m_didReceiveInvalidMessage;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm     2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm        2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -6323,6 +6323,9 @@
</span><span class="cx"> - (_WKWebViewPrintFormatter *)_webViewPrintFormatter
</span><span class="cx"> {
</span><span class="cx"> #if !PLATFORM(IOSMAC)
</span><ins>+    if (_page->process().connection()->hasOutstandingOutgoingSynchronousReplies())
+        return nil;
+
</ins><span class="cx">     UIViewPrintFormatter *viewPrintFormatter = self.viewPrintFormatter;
</span><span class="cx">     ASSERT([viewPrintFormatter isKindOfClass:[_WKWebViewPrintFormatter class]]);
</span><span class="cx">     return (_WKWebViewPrintFormatter *)viewPrintFormatter;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm       2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm  2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -726,6 +726,9 @@
</span><span class="cx">     if (_isPrintingToPDF)
</span><span class="cx">         return 0;
</span><span class="cx"> 
</span><ins>+    if (_page->process().connection()->hasOutstandingOutgoingSynchronousReplies())
+        return 0;
+
</ins><span class="cx">     uint64_t frameID;
</span><span class="cx">     if (_WKFrameHandle *handle = printFormatter.frameToPrint)
</span><span class="cx">         frameID = handle._frameID;
</span><span class="lines">@@ -769,6 +772,9 @@
</span><span class="cx"> 
</span><span class="cx"> - (CGPDFDocumentRef)_wk_printedDocument
</span><span class="cx"> {
</span><ins>+    if (_page->process().connection()->hasOutstandingOutgoingSynchronousReplies())
+        return nullptr;
+
</ins><span class="cx">     if (_isPrintingToPDF) {
</span><span class="cx">         if (!_page->process().connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DrawToPDFCallback>(_page->pageID(), Seconds::infinity())) {
</span><span class="cx">             ASSERT_NOT_REACHED();
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Tools/ChangeLog       2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2019-04-17  Tim Horton  <timothy_horton@apple.com>
+
+        UI↔Web deadlock when printing with a JavaScript alert visible
+        https://bugs.webkit.org/show_bug.cgi?id=196839
+        <rdar://problem/49157642>
+
+        Reviewed by Andy Estes.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm: Added.
+        (-[PrintOnAlertUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (TEST):
+
</ins><span class="cx"> 2019-04-17  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         WKRetainPtr's adoption constructor should be private
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (244399 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2019-04-17 20:01:47 UTC (rev 244399)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj   2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -94,6 +94,7 @@
</span><span class="cx">          2D21FE591F04642900B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D21FE581F04642800B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm */; };
</span><span class="cx">          2D2BEB2D22324E5F005544CA /* RequestTextInputContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D2BEB2C22324E5F005544CA /* RequestTextInputContext.mm */; };
</span><span class="cx">          2D3CA3A8221DF4B40088E803 /* PageOverlayPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D3CA3A4221DF2390088E803 /* PageOverlayPlugin.mm */; };
</span><ins>+               2D41CFB92260014F00FFF335 /* WKWebViewPrintFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D41CFB82260014E00FFF335 /* WKWebViewPrintFormatter.mm */; };
</ins><span class="cx">           2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */; };
</span><span class="cx">          2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; };
</span><span class="cx">          2D70059621EDA0C6003463CB /* TabOutOfWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D70059521EDA0C6003463CB /* TabOutOfWebView.mm */; };
</span><span class="lines">@@ -1450,6 +1451,7 @@
</span><span class="cx">          2D21FE581F04642800B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFViewStablePresentationUpdateCallback.mm; sourceTree = "<group>"; };
</span><span class="cx">          2D2BEB2C22324E5F005544CA /* RequestTextInputContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RequestTextInputContext.mm; sourceTree = "<group>"; };
</span><span class="cx">          2D3CA3A4221DF2390088E803 /* PageOverlayPlugin.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageOverlayPlugin.mm; sourceTree = "<group>"; };
</span><ins>+               2D41CFB82260014E00FFF335 /* WKWebViewPrintFormatter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewPrintFormatter.mm; sourceTree = "<group>"; };
</ins><span class="cx">           2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKThumbnailView.mm; path = WebKit/WKThumbnailView.mm; sourceTree = "<group>"; };
</span><span class="cx">          2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; };
</span><span class="cx">          2D61EC3021B0B75C00A7D1CB /* PencilKitTestSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PencilKitTestSPI.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -2714,6 +2716,7 @@
</span><span class="cx">                          CE449E1021AE0F7200E7ADA1 /* WKWebViewFindString.mm */,
</span><span class="cx">                          F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */,
</span><span class="cx">                          D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
</span><ins>+                               2D41CFB82260014E00FFF335 /* WKWebViewPrintFormatter.mm */,
</ins><span class="cx">                           37A9DBE7213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm */,
</span><span class="cx">                          93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */,
</span><span class="cx">                          9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */,
</span><span class="lines">@@ -4446,6 +4449,7 @@
</span><span class="cx">                          F4106C6921ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm in Sources */,
</span><span class="cx">                          D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */,
</span><span class="cx">                          F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */,
</span><ins>+                               2D41CFB92260014F00FFF335 /* WKWebViewPrintFormatter.mm in Sources */,
</ins><span class="cx">                           37A9DBE9213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm in Sources */,
</span><span class="cx">                          93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */,
</span><span class="cx">                          9984FACC1CFFAF60008D198C /* WKWebViewTextInput.mm in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaWKWebViewPrintFormattermm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm (0 => 244400)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm                           (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm      2019-04-17 20:20:40 UTC (rev 244400)
</span><span class="lines">@@ -0,0 +1,75 @@
</span><ins>+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKPreferencesRefPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WebKit.h>
+#import <WebKit/_WKTextInputContext.h>
+#import <wtf/RetainPtr.h>
+
+static bool done;
+
+@interface PrintOnAlertUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation PrintOnAlertUIDelegate
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+    EXPECT_NULL([webView _webViewPrintFormatter]);
+
+    dispatch_async(dispatch_get_main_queue(), ^{
+        EXPECT_NULL([webView _webViewPrintFormatter]);
+        completionHandler();
+        done = true;
+    });
+}
+
+@end
+
+TEST(WebKit, WKWebViewPrintFormatterJavaScriptAlertDeadlock)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    auto delegate = adoptNS([[PrintOnAlertUIDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+
+    [webView synchronouslyLoadHTMLString:@"The quick brown fox jumps over the lazy dog."];
+    EXPECT_NOT_NULL([webView _webViewPrintFormatter]);
+
+    [webView evaluateJavaScript:@"alert('hello')" completionHandler:nil];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_NOT_NULL([webView _webViewPrintFormatter]);
+}
+
+#endif // PLATFORM(IOS_FAMILY)
</ins></span></pre>
</div>
</div>

</body>
</html>