<!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>[204426] branches/safari-602.1.50.1-branch/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/204426">204426</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2016-08-12 14:56:21 -0700 (Fri, 12 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/204414">r204414</a>. rdar://problem/27624095</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6021501branchSourceWebKit2ChangeLog">branches/safari-602.1.50.1-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2PlatformIPCmacConnectionMacmm">branches/safari-602.1.50.1-branch/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2UIProcessChildProcessProxycpp">branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/ChildProcessProxy.cpp</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2UIProcessLauncherProcessLaunchercpp">branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2UIProcessLauncherProcessLauncherh">branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2UIProcessLaunchermacProcessLauncherMacmm">branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2UIProcessNetworkNetworkProcessProxycpp">branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp</a></li>
<li><a href="#branchessafari6021501branchSourceWebKit2UIProcessWebProcessProxycpp">branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/WebProcessProxy.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6021501branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/ChangeLog (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/ChangeLog        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/ChangeLog        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2016-08-12  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r204414. rdar://problem/27624095
+
+    2016-08-12  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+            message loading never finishes in Mail
+            https://bugs.webkit.org/show_bug.cgi?id=160806
+            rdar://problem/27624095
+
+            Reviewed by Dan Bernstein.
+
+            Add more checks for when a process goes away before we've established a proper connection to it.
+
+            * Platform/IPC/mac/ConnectionMac.mm:
+            (IPC::Connection::receiveSourceEventHandler):
+            Handle the MACH_NOTIFY_NO_SENDERS and MACH_NOTIFY_SEND_ONCE messages here. Also, once we receive a send
+            right from the other side, stop listening for the MACH_NOTIFY_NO_SENDERS notification.
+
+            * UIProcess/ChildProcessProxy.cpp:
+            (WebKit::ChildProcessProxy::didFinishLaunching):
+            Null check the connection identifier.
+
+            * UIProcess/Launcher/ProcessLauncher.cpp:
+            (WebKit::ProcessLauncher::ProcessLauncher):
+            (WebKit::processLauncherWorkQueue): Deleted.
+            Get rid of the process launcher queue - we're not doing any blocking work here.
+
+            * UIProcess/Launcher/ProcessLauncher.h:
+            Add a weak factory.
+
+            * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+            (WebKit::systemDirectoryPath):
+            Move this before launchProcess().
+
+            (WebKit::ProcessLauncher::launchProcess):
+            Merge createService and connectToService into launchProcess. Also make the following changes:
+            - Use mach_port_request_notification to get a notification for when our receive right loses all its senders.
+            This lets us listen for the other process going away before we have a send right for it.
+            - Use xpc_connection_set_event_handler to listen for errors, so we can detect the process going away before
+            we've sent a message to it.
+
+            (WebKit::connectToService): Deleted.
+            (WebKit::createService): Deleted.
+
+            * UIProcess/Network/NetworkProcessProxy.cpp:
+            (WebKit::NetworkProcessProxy::didFinishLaunching):
+            If we failed to launch, call networkProcessCrashedOrFailedToLaunch so we'll unblock any waiting web processes.
+
+            * UIProcess/WebProcessProxy.cpp:
+            (WebKit::WebProcessProxy::didFinishLaunching):
+            Null check the connection and XPC connection before trying to get its pid.
+
</ins><span class="cx"> 2016-08-04  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r204135. rdar://problem/19814215
</span></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2PlatformIPCmacConnectionMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -479,6 +479,20 @@
</span><span class="cx">     if (!header)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    switch (header-&gt;msgh_id) {
+    case MACH_NOTIFY_NO_SENDERS:
+        ASSERT(m_isServer);
+        if (!m_sendPort)
+            connectionDidClose();
+        return;
+
+    case MACH_NOTIFY_SEND_ONCE:
+        return;
+
+    default:
+        break;
+    }
+
</ins><span class="cx">     std::unique_ptr&lt;MessageDecoder&gt; decoder = createMessageDecoder(header);
</span><span class="cx">     ASSERT(decoder);
</span><span class="cx"> 
</span><span class="lines">@@ -500,6 +514,12 @@
</span><span class="cx">         m_sendPort = port.port();
</span><span class="cx">         
</span><span class="cx">         if (m_sendPort) {
</span><ins>+            mach_port_t previousNotificationPort;
+            mach_port_request_notification(mach_task_self(), m_receivePort, MACH_NOTIFY_NO_SENDERS, 0, MACH_PORT_NULL, MACH_MSG_TYPE_MOVE_SEND_ONCE, &amp;previousNotificationPort);
+
+            if (previousNotificationPort != MACH_PORT_NULL)
+                mach_port_deallocate(mach_task_self(), previousNotificationPort);
+
</ins><span class="cx">             initializeDeadNameSource();
</span><span class="cx">             dispatch_resume(m_deadNameSource);
</span><span class="cx">         }
</span></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2UIProcessChildProcessProxycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/ChildProcessProxy.cpp (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/ChildProcessProxy.cpp        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/ChildProcessProxy.cpp        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -171,6 +171,9 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!m_connection);
</span><span class="cx"> 
</span><ins>+    if (IPC::Connection::identifierIsNull(connectionIdentifier))
+        return;
+
</ins><span class="cx">     m_connection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &lt;= 101000
</span><span class="cx">     m_connection-&gt;setShouldCloseConnectionOnMachExceptions();
</span></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2UIProcessLauncherProcessLaunchercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -31,23 +31,14 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-static WorkQueue&amp; processLauncherWorkQueue()
-{
-
-    static WorkQueue&amp; processLauncherWorkQueue = WorkQueue::create(&quot;com.apple.WebKit.ProcessLauncher&quot;).leakRef();
-    return processLauncherWorkQueue;
-}
-
</del><span class="cx"> ProcessLauncher::ProcessLauncher(Client* client, const LaunchOptions&amp; launchOptions)
</span><span class="cx">     : m_client(client)
</span><ins>+    , m_weakPtrFactory(this)
</ins><span class="cx">     , m_launchOptions(launchOptions)
</span><span class="cx">     , m_processIdentifier(0)
</span><span class="cx"> {
</span><span class="cx">     m_isLaunching = true;
</span><del>-
-    processLauncherWorkQueue().dispatch([processLauncher = makeRef(*this)]() mutable {
-        processLauncher-&gt;launchProcess();
-    });
</del><ins>+    launchProcess();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ProcessLauncher::didFinishLaunchingProcess(pid_t processIdentifier, IPC::Connection::Identifier identifier)
</span></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2UIProcessLauncherProcessLauncherh"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -23,13 +23,13 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef WebProcessLauncher_h
-#define WebProcessLauncher_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #include &quot;Connection.h&quot;
</span><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><ins>+#include &lt;wtf/WeakPtr.h&gt;
</ins><span class="cx"> #include &lt;wtf/text/StringHash.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -86,6 +86,7 @@
</span><span class="cx"> 
</span><span class="cx">     Client* m_client;
</span><span class="cx"> 
</span><ins>+    WeakPtrFactory&lt;ProcessLauncher&gt; m_weakPtrFactory;
</ins><span class="cx">     const LaunchOptions m_launchOptions;
</span><span class="cx">     bool m_isLaunching;
</span><span class="cx">     pid_t m_processIdentifier;
</span><span class="lines">@@ -92,5 +93,3 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span><del>-
-#endif // WebProcessLauncher_h
</del></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2UIProcessLaunchermacProcessLauncherMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -50,8 +50,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-typedef void (ProcessLauncher::*DidFinishLaunchingProcessFunction)(pid_t, IPC::Connection::Identifier);
-
</del><span class="cx"> static const char* serviceName(const ProcessLauncher::LaunchOptions&amp; launchOptions)
</span><span class="cx"> {
</span><span class="cx">     switch (launchOptions.processType) {
</span><span class="lines">@@ -83,12 +81,25 @@
</span><span class="cx">     return launchOptions.processType == ProcessLauncher::ProcessType::Network;
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><del>-    
-static void connectToService(const ProcessLauncher::LaunchOptions&amp; launchOptions, bool forDevelopment, ProcessLauncher* that, DidFinishLaunchingProcessFunction didFinishLaunchingProcessFunction)
</del><ins>+
+static NSString *systemDirectoryPath()
</ins><span class="cx"> {
</span><del>-    // Create a connection to the WebKit XPC service.
-    auto connection = adoptOSObject(xpc_connection_create(serviceName(launchOptions), 0));
</del><ins>+    static NSString *path = [^{
+#if PLATFORM(IOS_SIMULATOR)
+        char *simulatorRoot = getenv(&quot;SIMULATOR_ROOT&quot;);
+        return simulatorRoot ? [NSString stringWithFormat:@&quot;%s/System/&quot;, simulatorRoot] : @&quot;/System/&quot;;
+#else
+        return @&quot;/System/&quot;;
+#endif
+    }() copy];
</ins><span class="cx"> 
</span><ins>+    return path;
+}
+
+void ProcessLauncher::launchProcess()
+{
+    auto connection = adoptOSObject(xpc_connection_create(serviceName(m_launchOptions), dispatch_get_main_queue()));
+
</ins><span class="cx">     uuid_t uuid;
</span><span class="cx">     uuid_generate(uuid);
</span><span class="cx">     xpc_connection_set_oneshot_instance(connection.get(), uuid);
</span><span class="lines">@@ -111,8 +122,8 @@
</span><span class="cx">     xpc_dictionary_set_value(initializationMessage.get(), &quot;ContainerEnvironmentVariables&quot;, containerEnvironmentVariables.get());
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    auto languagesIterator = launchOptions.extraInitializationData.find(&quot;OverrideLanguages&quot;);
-    if (languagesIterator != launchOptions.extraInitializationData.end()) {
</del><ins>+    auto languagesIterator = m_launchOptions.extraInitializationData.find(&quot;OverrideLanguages&quot;);
+    if (languagesIterator != m_launchOptions.extraInitializationData.end()) {
</ins><span class="cx">         auto languages = adoptOSObject(xpc_array_create(nullptr, 0));
</span><span class="cx">         Vector&lt;String&gt; languageVector;
</span><span class="cx">         languagesIterator-&gt;value.split(&quot;,&quot;, false, languageVector);
</span><span class="lines">@@ -123,11 +134,7 @@
</span><span class="cx"> 
</span><span class="cx">     xpc_connection_set_bootstrap(connection.get(), initializationMessage.get());
</span><span class="cx"> 
</span><del>-    // XPC requires having an event handler, even if it is not used.
-    xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t event) { });
-    xpc_connection_resume(connection.get());
-    
-    if (shouldLeakBoost(launchOptions)) {
</del><ins>+    if (shouldLeakBoost(m_launchOptions)) {
</ins><span class="cx">         auto preBootstrapMessage = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
</span><span class="cx">         xpc_dictionary_set_string(preBootstrapMessage.get(), &quot;message-name&quot;, &quot;pre-bootstrap&quot;);
</span><span class="cx">         xpc_connection_send_message(connection.get(), preBootstrapMessage.get());
</span><span class="lines">@@ -140,6 +147,10 @@
</span><span class="cx">     // Insert a send right so we can send to it.
</span><span class="cx">     mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
</span><span class="cx"> 
</span><ins>+    mach_port_t previousNotificationPort;
+    mach_port_request_notification(mach_task_self(), listeningPort, MACH_NOTIFY_NO_SENDERS, 0, listeningPort, MACH_MSG_TYPE_MAKE_SEND_ONCE, &amp;previousNotificationPort);
+    ASSERT(!previousNotificationPort);
+
</ins><span class="cx">     String clientIdentifier;
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     clientIdentifier = codeSigningIdentifierForCurrentProcess();
</span><span class="lines">@@ -157,7 +168,8 @@
</span><span class="cx">     xpc_dictionary_set_string(bootstrapMessage.get(), &quot;client-identifier&quot;, !clientIdentifier.isEmpty() ? clientIdentifier.utf8().data() : *_NSGetProgname());
</span><span class="cx">     xpc_dictionary_set_string(bootstrapMessage.get(), &quot;ui-process-name&quot;, [[[NSProcessInfo processInfo] processName] UTF8String]);
</span><span class="cx"> 
</span><del>-    if (forDevelopment) {
</del><ins>+    bool isWebKitDevelopmentBuild = ![[[[NSBundle bundleWithIdentifier:@&quot;com.apple.WebKit&quot;] bundlePath] stringByDeletingLastPathComponent] hasPrefix:systemDirectoryPath()];
+    if (isWebKitDevelopmentBuild) {
</ins><span class="cx">         xpc_dictionary_set_fd(bootstrapMessage.get(), &quot;stdout&quot;, STDOUT_FILENO);
</span><span class="cx">         xpc_dictionary_set_fd(bootstrapMessage.get(), &quot;stderr&quot;, STDERR_FILENO);
</span><span class="cx">     }
</span><span class="lines">@@ -164,68 +176,49 @@
</span><span class="cx"> 
</span><span class="cx">     auto extraInitializationData = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
</span><span class="cx"> 
</span><del>-    for (const auto&amp; keyValuePair : launchOptions.extraInitializationData)
</del><ins>+    for (const auto&amp; keyValuePair : m_launchOptions.extraInitializationData)
</ins><span class="cx">         xpc_dictionary_set_string(extraInitializationData.get(), keyValuePair.key.utf8().data(), keyValuePair.value.utf8().data());
</span><span class="cx"> 
</span><span class="cx">     xpc_dictionary_set_value(bootstrapMessage.get(), &quot;extra-initialization-data&quot;, extraInitializationData.get());
</span><span class="cx"> 
</span><del>-    that-&gt;ref();
</del><ins>+    auto weakProcessLauncher = m_weakPtrFactory.createWeakPtr();
+    xpc_connection_set_event_handler(connection.get(), [weakProcessLauncher, listeningPort](xpc_object_t event) {
+        ASSERT(xpc_get_type(event) == XPC_TYPE_ERROR);
</ins><span class="cx"> 
</span><del>-    xpc_connection_send_message_with_reply(connection.get(), bootstrapMessage.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(xpc_object_t reply) {
-        xpc_type_t type = xpc_get_type(reply);
-        if (type == XPC_TYPE_ERROR) {
-            // We failed to launch. Release the send right.
-            mach_port_deallocate(mach_task_self(), listeningPort);
</del><ins>+        auto processLauncher = weakProcessLauncher.get();
+        if (!processLauncher)
+            return;
</ins><span class="cx"> 
</span><del>-            // And the receive right.
-            mach_port_mod_refs(mach_task_self(), listeningPort, MACH_PORT_RIGHT_RECEIVE, -1);
</del><ins>+        if (!processLauncher-&gt;isLaunching())
+            return;
</ins><span class="cx"> 
</span><del>-            RunLoop::main().dispatch([protectedThat = RefPtr&lt;ProcessLauncher&gt;(that), didFinishLaunchingProcessFunction]() mutable {
-                (*protectedThat.*didFinishLaunchingProcessFunction)(0, IPC::Connection::Identifier());
-            });
-        } else {
-            ASSERT(type == XPC_TYPE_DICTIONARY);
</del><ins>+        // We failed to launch. Release the send right.
+        mach_port_deallocate(mach_task_self(), listeningPort);
+
+        // And the receive right.
+        mach_port_mod_refs(mach_task_self(), listeningPort, MACH_PORT_RIGHT_RECEIVE, -1);
+        processLauncher-&gt;didFinishLaunchingProcess(0, IPC::Connection::Identifier());
+    });
+
+    xpc_connection_resume(connection.get());
+
+    ref();
+    xpc_connection_send_message_with_reply(connection.get(), bootstrapMessage.get(), dispatch_get_main_queue(), ^(xpc_object_t reply) {
+        // Errors are handled in the event handler.
+        if (xpc_get_type(reply) != XPC_TYPE_ERROR) {
+            ASSERT(xpc_get_type(reply) == XPC_TYPE_DICTIONARY);
</ins><span class="cx">             ASSERT(!strcmp(xpc_dictionary_get_string(reply, &quot;message-name&quot;), &quot;process-finished-launching&quot;));
</span><span class="cx"> 
</span><span class="cx">             // The process has finished launching, grab the pid from the connection.
</span><span class="cx">             pid_t processIdentifier = xpc_connection_get_pid(connection.get());
</span><span class="cx"> 
</span><del>-            // We've finished launching the process, message back to the main run loop. This takes ownership of the connection.
-            RunLoop::main().dispatch([protectedThat = RefPtr&lt;ProcessLauncher&gt;(that), didFinishLaunchingProcessFunction, processIdentifier, listeningPort, connection] {
-                (*protectedThat.*didFinishLaunchingProcessFunction)(processIdentifier, IPC::Connection::Identifier(listeningPort, connection));
-            });
</del><ins>+            didFinishLaunchingProcess(processIdentifier, IPC::Connection::Identifier(listeningPort, connection));
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        that-&gt;deref();
</del><ins>+        deref();
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void createService(const ProcessLauncher::LaunchOptions&amp; launchOptions, bool forDevelopment, ProcessLauncher* that, DidFinishLaunchingProcessFunction didFinishLaunchingProcessFunction)
-{
-    connectToService(launchOptions, forDevelopment, that, didFinishLaunchingProcessFunction);
-}
-
-static NSString *systemDirectoryPath()
-{
-    static NSString *path = [^{
-#if PLATFORM(IOS_SIMULATOR)
-        char *simulatorRoot = getenv(&quot;SIMULATOR_ROOT&quot;);
-        return simulatorRoot ? [NSString stringWithFormat:@&quot;%s/System/&quot;, simulatorRoot] : @&quot;/System/&quot;;
-#else
-        return @&quot;/System/&quot;;
-#endif
-    }() copy];
-
-    return path;
-}
-
-void ProcessLauncher::launchProcess()
-{
-    bool isWebKitDevelopmentBuild = ![[[[NSBundle bundleWithIdentifier:@&quot;com.apple.WebKit&quot;] bundlePath] stringByDeletingLastPathComponent] hasPrefix:systemDirectoryPath()];
-
-    createService(m_launchOptions, isWebKitDevelopmentBuild, this, &amp;ProcessLauncher::didFinishLaunchingProcess);
-}
-
</del><span class="cx"> void ProcessLauncher::terminateProcess()
</span><span class="cx"> {
</span><span class="cx">     if (m_isLaunching) {
</span></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2UIProcessNetworkNetworkProcessProxycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -297,7 +297,7 @@
</span><span class="cx">     ChildProcessProxy::didFinishLaunching(launcher, connectionIdentifier);
</span><span class="cx"> 
</span><span class="cx">     if (IPC::Connection::identifierIsNull(connectionIdentifier)) {
</span><del>-        // FIXME: Do better cleanup here.
</del><ins>+        networkProcessCrashedOrFailedToLaunch();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6021501branchSourceWebKit2UIProcessWebProcessProxycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/WebProcessProxy.cpp (204425 => 204426)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2016-08-12 21:53:33 UTC (rev 204425)
+++ branches/safari-602.1.50.1-branch/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2016-08-12 21:56:21 UTC (rev 204426)
</span><span class="lines">@@ -613,9 +613,10 @@
</span><span class="cx">     m_processPool-&gt;processDidFinishLaunching(this);
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    xpc_connection_t xpcConnection = connection()-&gt;xpcConnection();
-    ASSERT(xpcConnection);
-    m_throttler.didConnectToProcess(xpc_connection_get_pid(xpcConnection));
</del><ins>+    if (connection()) {
+        if (xpc_connection_t xpcConnection = connection()-&gt;xpcConnection())
+            m_throttler.didConnectToProcess(xpc_connection_get_pid(xpcConnection));
+    }
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>