<!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>[194986] trunk/Source/WebKit2</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/194986">194986</a></dd>
<dt>Author</dt> <dd>ggaren@apple.com</dd>
<dt>Date</dt> <dd>2016-01-13 14:45:38 -0800 (Wed, 13 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebKit2 should have an API for eagerly querying whether the web process is responsive
https://bugs.webkit.org/show_bug.cgi?id=153037

Reviewed by Tim Horton.

WebKit2 provides a delegate notification when the web process doesn't
respond to a message after a while. But there's no way to send a message
eagerly and check for reply.

We want this new mechanism so that navigation can terminate the web
process eagerly if it is hung.

* UIProcess/API/C/WKPage.cpp:
(WKPageGetWebProcessIsResponsive):
* UIProcess/API/C/WKPagePrivate.h: This is the new API.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::sendWheelEvent): Updated for interface change.

(WebKit::WebPageProxy::getWebProcessIsResponsive): Calls through to the
web process proxy. We claim that we are responsive when there is no
web process because we assume that a fresh web process will not hang.

* UIProcess/WebPageProxy.h:

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::WebProcessProxy):
(WebKit::WebProcessProxy::didBecomeUnresponsive): Keep a flag indicating
whether the process is unresponsive so that we can fire unresponsiveness
callbacks immediately for a hung process instead of waiting another 3s.

(WebKit::WebProcessProxy::didBecomeResponsive): We don't fire responsiveness
callbacks inside didBecomeResponsive because we assume that a responsive
web process will invoke didReceiveMainThreadPing -- and we fire the
callbacks there.

(WebKit::WebProcessProxy::getIsResponsive): If the web process is already
known to be unresponsive, fire the callback right away. Otherwise, queue
it up to fire once we have an answer from a main thread ping.

(WebKit::WebProcessProxy::didReceiveMainThreadPing): Fire any pending
callbacks when we learn that the web process is responsive.

* UIProcess/WebProcessProxy.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagecpp">trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagePrivateh">trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebProcessProxycpp">trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebProcessProxyh">trunk/Source/WebKit2/UIProcess/WebProcessProxy.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/ChangeLog        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -1,3 +1,50 @@
</span><ins>+2016-01-12  Geoffrey Garen  &lt;ggaren@apple.com&gt;
+
+        WebKit2 should have an API for eagerly querying whether the web process is responsive
+        https://bugs.webkit.org/show_bug.cgi?id=153037
+
+        Reviewed by Tim Horton.
+
+        WebKit2 provides a delegate notification when the web process doesn't
+        respond to a message after a while. But there's no way to send a message
+        eagerly and check for reply.
+
+        We want this new mechanism so that navigation can terminate the web
+        process eagerly if it is hung.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageGetWebProcessIsResponsive):
+        * UIProcess/API/C/WKPagePrivate.h: This is the new API.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::sendWheelEvent): Updated for interface change.
+
+        (WebKit::WebPageProxy::getWebProcessIsResponsive): Calls through to the
+        web process proxy. We claim that we are responsive when there is no
+        web process because we assume that a fresh web process will not hang.
+
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy):
+        (WebKit::WebProcessProxy::didBecomeUnresponsive): Keep a flag indicating
+        whether the process is unresponsive so that we can fire unresponsiveness
+        callbacks immediately for a hung process instead of waiting another 3s.
+
+        (WebKit::WebProcessProxy::didBecomeResponsive): We don't fire responsiveness
+        callbacks inside didBecomeResponsive because we assume that a responsive
+        web process will invoke didReceiveMainThreadPing -- and we fire the
+        callbacks there.
+
+        (WebKit::WebProcessProxy::getIsResponsive): If the web process is already
+        known to be unresponsive, fire the callback right away. Otherwise, queue
+        it up to fire once we have an answer from a main thread ping.
+
+        (WebKit::WebProcessProxy::didReceiveMainThreadPing): Fire any pending
+        callbacks when we learn that the web process is responsive.
+
+        * UIProcess/WebProcessProxy.h:
+
</ins><span class="cx"> 2016-01-12  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.11.3 release.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -2363,6 +2363,13 @@
</span><span class="cx">     toImpl(pageRef)-&gt;getBytecodeProfile(toGenericCallbackFunction(context, callback));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WKPageIsWebProcessResponsive(WKPageRef pageRef, void* context, WKPageIsWebProcessResponsiveFunction callback)
+{
+    toImpl(pageRef)-&gt;isWebProcessResponsive([context, callback](bool isWebProcessResponsive) {
+        callback(isWebProcessResponsive, context);
+    });
+}
+
</ins><span class="cx"> void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
</span><span class="cx"> {
</span><span class="cx">     toImpl(pageRef)-&gt;getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagePrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -90,6 +90,9 @@
</span><span class="cx"> 
</span><span class="cx"> typedef void (*WKPageGetBytecodeProfileFunction)(WKStringRef, WKErrorRef, void*);
</span><span class="cx"> WK_EXPORT void WKPageGetBytecodeProfile(WKPageRef page, void* context, WKPageGetBytecodeProfileFunction function);
</span><ins>+
+typedef void (*WKPageIsWebProcessResponsiveFunction)(bool isWebProcessResponsive, void* context);
+WK_EXPORT void WKPageIsWebProcessResponsive(WKPageRef page, void* context, WKPageIsWebProcessResponsiveFunction function);
</ins><span class="cx">     
</span><span class="cx"> WK_EXPORT WKArrayRef WKPageCopyRelatedPages(WKPageRef page);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -1801,7 +1801,9 @@
</span><span class="cx">             rubberBandsAtBottom()
</span><span class="cx">         ), 0);
</span><span class="cx"> 
</span><del>-    m_process-&gt;sendMainThreadPing();
</del><ins>+    // Manually ping the web process to check for responsiveness since our wheel
+    // event will dispatch to a non-main thread, which always responds.
+    m_process-&gt;isResponsive(nullptr);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent&amp; event)
</span><span class="lines">@@ -2637,7 +2639,20 @@
</span><span class="cx">     m_loadDependentStringCallbackIDs.add(callbackID);
</span><span class="cx">     m_process-&gt;send(Messages::WebPage::GetBytecodeProfile(callbackID), m_pageID);
</span><span class="cx"> }
</span><del>-    
</del><ins>+
+void WebPageProxy::isWebProcessResponsive(std::function&lt;void (bool isWebProcessResponsive)&gt; callbackFunction)
+{
+    if (!isValid()) {
+        RunLoop::main().dispatch([callbackFunction] {
+            bool isWebProcessResponsive = true;
+            callbackFunction(isWebProcessResponsive);
+        });
+        return;
+    }
+
+    m_process-&gt;isResponsive(callbackFunction);
+}
+
</ins><span class="cx"> #if ENABLE(MHTML)
</span><span class="cx"> void WebPageProxy::getContentsAsMHTMLData(std::function&lt;void (API::Data*, CallbackBase::Error)&gt; callbackFunction)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -743,6 +743,7 @@
</span><span class="cx"> 
</span><span class="cx">     void getContentsAsString(std::function&lt;void (const String&amp;, CallbackBase::Error)&gt;);
</span><span class="cx">     void getBytecodeProfile(std::function&lt;void (const String&amp;, CallbackBase::Error)&gt;);
</span><ins>+    void isWebProcessResponsive(std::function&lt;void (bool isWebProcessResponsive)&gt;);
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MHTML)
</span><span class="cx">     void getContentsAsMHTMLData(std::function&lt;void (API::Data*, CallbackBase::Error)&gt;);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -106,6 +106,7 @@
</span><span class="cx">     , m_customProtocolManagerProxy(this, processPool)
</span><span class="cx">     , m_numberOfTimesSuddenTerminationWasDisabled(0)
</span><span class="cx">     , m_throttler(*this)
</span><ins>+    , m_isResponsive(NoOrMaybe::Maybe)
</ins><span class="cx"> {
</span><span class="cx">     WebPasteboardProxy::singleton().addWebProcessProxy(*this);
</span><span class="cx"> 
</span><span class="lines">@@ -549,14 +550,25 @@
</span><span class="cx"> 
</span><span class="cx"> void WebProcessProxy::didBecomeUnresponsive()
</span><span class="cx"> {
</span><ins>+    m_isResponsive = NoOrMaybe::No;
+
</ins><span class="cx">     Vector&lt;RefPtr&lt;WebPageProxy&gt;&gt; pages;
</span><span class="cx">     copyValuesToVector(m_pageMap, pages);
</span><ins>+
+    auto isResponsiveCallbacks = WTFMove(m_isResponsiveCallbacks);
+
</ins><span class="cx">     for (auto&amp; page : pages)
</span><span class="cx">         page-&gt;processDidBecomeUnresponsive();
</span><ins>+
+    bool isWebProcessResponsive = false;
+    for (auto&amp; callback : isResponsiveCallbacks)
+        callback(isWebProcessResponsive);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcessProxy::didBecomeResponsive()
</span><span class="cx"> {
</span><ins>+    m_isResponsive = NoOrMaybe::Maybe;
+
</ins><span class="cx">     Vector&lt;RefPtr&lt;WebPageProxy&gt;&gt; pages;
</span><span class="cx">     copyValuesToVector(m_pageMap, pages);
</span><span class="cx">     for (auto&amp; page : pages)
</span><span class="lines">@@ -984,8 +996,21 @@
</span><span class="cx">         m_tokenForHoldingLockedFiles = m_throttler.backgroundActivityToken();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebProcessProxy::sendMainThreadPing()
</del><ins>+void WebProcessProxy::isResponsive(std::function&lt;void(bool isWebProcessResponsive)&gt; callback)
</ins><span class="cx"> {
</span><ins>+    if (m_isResponsive == NoOrMaybe::No) {
+        if (callback) {
+            RunLoop::main().dispatch([callback] {
+                bool isWebProcessResponsive = false;
+                callback(isWebProcessResponsive);
+            });
+        }
+        return;
+    }
+
+    if (callback)
+        m_isResponsiveCallbacks.append(callback);
+
</ins><span class="cx">     responsivenessTimer().start();
</span><span class="cx">     send(Messages::WebProcess::MainThreadPing(), 0);
</span><span class="cx"> }
</span><span class="lines">@@ -993,6 +1018,11 @@
</span><span class="cx"> void WebProcessProxy::didReceiveMainThreadPing()
</span><span class="cx"> {
</span><span class="cx">     responsivenessTimer().stop();
</span><ins>+
+    auto isResponsiveCallbacks = WTFMove(m_isResponsiveCallbacks);
+    bool isWebProcessResponsive = true;
+    for (auto&amp; callback : isResponsiveCallbacks)
+        callback(isWebProcessResponsive);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (194985 => 194986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h        2016-01-13 22:32:55 UTC (rev 194985)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h        2016-01-13 22:45:38 UTC (rev 194986)
</span><span class="lines">@@ -151,7 +151,7 @@
</span><span class="cx"> 
</span><span class="cx">     void reinstateNetworkProcessAssertionState(NetworkProcessProxy&amp;);
</span><span class="cx"> 
</span><del>-    void sendMainThreadPing();
</del><ins>+    void isResponsive(std::function&lt;void(bool isWebProcessResponsive)&gt;);
</ins><span class="cx">     void didReceiveMainThreadPing();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -254,6 +254,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     HashMap&lt;String, uint64_t&gt; m_pageURLRetainCountMap;
</span><ins>+
+    enum class NoOrMaybe { No, Maybe } m_isResponsive;
+    Vector&lt;std::function&lt;void(bool webProcessIsResponsive)&gt;&gt; m_isResponsiveCallbacks;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>