<!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>[212067] branches/safari-603-branch</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/212067">212067</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-02-09 22:37:09 -0800 (Thu, 09 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/211915">r211915</a>. rdar://problem/27607520</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchSourceWebKit2ChangeLog">branches/safari-603-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceWebKit2UIProcessNetworkCustomProtocolsmacCustomProtocolManagerProxyMacmm">branches/safari-603-branch/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm</a></li>
<li><a href="#branchessafari603branchToolsChangeLog">branches/safari-603-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari603branchToolsTestWebKitAPITestsWebKit2ObjCCustomProtocolsTestmm">branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari603branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebKit2/ChangeLog (212066 => 212067)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebKit2/ChangeLog        2017-02-10 06:37:06 UTC (rev 212066)
+++ branches/safari-603-branch/Source/WebKit2/ChangeLog        2017-02-10 06:37:09 UTC (rev 212067)
</span><span class="lines">@@ -1,5 +1,32 @@
</span><span class="cx"> 2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r211915. rdar://problem/27607520
+
+    2017-02-08  Andy Estes  &lt;aestes@apple.com&gt;
+
+            Custom protocols should not continue loading after a network process crash
+            https://bugs.webkit.org/show_bug.cgi?id=168028
+            &lt;rdar://problem/27607520&gt;
+
+            Reviewed by Brady Eidson.
+
+            WKCustomProtocolLoaders are meant to be owned by CustomProtocolManagerProxy and have their
+            loads cancelled when CustomProtocolManagerProxy is destroyed. However, WKCustomProtocolLoader
+            creates a NSURLConnection for which it is the client, so NSURLConnection retains it for the
+            duration of the load.
+
+            These loaders should be explicitly cancelled when their CustomProtocolManagerProxy is destroyed.
+
+            New API test: WebKit2CustomProtocolsTest.CloseDuringCustomProtocolLoad
+
+            * UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm:
+            (-[WKCustomProtocolLoader customProtocolManagerProxyDestroyed]): Added. Cancels the
+            _urlConnection and sets _customProtocolManagerProxy to nullptr.
+            (WebKit::CustomProtocolManagerProxy::~CustomProtocolManagerProxy):
+            Called -customProtocolManagerProxyDestroyed on every loader in m_loaderMap.
+
+2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r211893. rdar://problem/30423806
</span><span class="cx"> 
</span><span class="cx">     2017-02-08  Jer Noble  &lt;jer.noble@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari603branchSourceWebKit2UIProcessNetworkCustomProtocolsmacCustomProtocolManagerProxyMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm (212066 => 212067)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm        2017-02-10 06:37:06 UTC (rev 212066)
+++ branches/safari-603-branch/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm        2017-02-10 06:37:09 UTC (rev 212067)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx">     NSURLConnection *_urlConnection;
</span><span class="cx"> }
</span><span class="cx"> - (id)initWithCustomProtocolManagerProxy:(CustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request connection:(Connection *)connection;
</span><ins>+- (void)customProtocolManagerProxyDestroyed;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @implementation WKCustomProtocolLoader
</span><span class="lines">@@ -84,6 +85,13 @@
</span><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)customProtocolManagerProxyDestroyed
+{
+    ASSERT(_customProtocolManagerProxy);
+    _customProtocolManagerProxy = nullptr;
+    [_urlConnection cancel];
+}
+
</ins><span class="cx"> - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
</span><span class="cx"> {
</span><span class="cx">     ResourceError coreError(error);
</span><span class="lines">@@ -139,6 +147,8 @@
</span><span class="cx"> 
</span><span class="cx"> CustomProtocolManagerProxy::~CustomProtocolManagerProxy()
</span><span class="cx"> {
</span><ins>+    for (auto&amp; loader : m_loaderMap)
+        [loader.value customProtocolManagerProxyDestroyed];
</ins><span class="cx">     m_childProcessProxy-&gt;removeMessageReceiver(Messages::CustomProtocolManagerProxy::messageReceiverName());
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari603branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Tools/ChangeLog (212066 => 212067)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Tools/ChangeLog        2017-02-10 06:37:06 UTC (rev 212066)
+++ branches/safari-603-branch/Tools/ChangeLog        2017-02-10 06:37:09 UTC (rev 212067)
</span><span class="lines">@@ -1,5 +1,24 @@
</span><span class="cx"> 2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r211915. rdar://problem/27607520
+
+    2017-02-08  Andy Estes  &lt;aestes@apple.com&gt;
+
+            Custom protocols should not continue loading after a network process crash
+            https://bugs.webkit.org/show_bug.cgi?id=168028
+            &lt;rdar://problem/27607520&gt;
+
+            Reviewed by Brady Eidson.
+
+            * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm:
+            (processGroup):
+            (-[CloseWhileStartingProtocol startLoading]):
+            (-[CloseWhileStartingProtocol stopLoading]):
+            (TestWebKitAPI::runTest):
+            (TestWebKitAPI::TEST):
+
+2017-02-09  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r211891. rdar://problem/30423806
</span><span class="cx"> 
</span><span class="cx">     2017-02-08  Jer Noble  &lt;jer.noble@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari603branchToolsTestWebKitAPITestsWebKit2ObjCCustomProtocolsTestmm"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm (212066 => 212067)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm        2017-02-10 06:37:06 UTC (rev 212066)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm        2017-02-10 06:37:09 UTC (rev 212067)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -32,11 +32,13 @@
</span><span class="cx"> #import &quot;PlatformUtilities.h&quot;
</span><span class="cx"> #import &quot;TestBrowsingContextLoadDelegate.h&quot;
</span><span class="cx"> #import &quot;TestProtocol.h&quot;
</span><ins>+#import &lt;WebKit/WKContextPrivate.h&gt;
+#import &lt;WebKit/WKProcessGroupPrivate.h&gt;
</ins><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if WK_API_ENABLED &amp;&amp; PLATFORM(MAC)
</span><span class="cx"> 
</span><del>-static bool testFinished = false;
</del><ins>+static bool testFinished;
</ins><span class="cx"> 
</span><span class="cx"> @interface CustomProtocolsLoadDelegate : NSObject &lt;WKBrowsingContextLoadDelegate&gt;
</span><span class="cx"> @end
</span><span class="lines">@@ -66,23 +68,70 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+static WKProcessGroup *processGroup()
+{
+    static WKProcessGroup *processGroup = [[WKProcessGroup alloc] init];
+    return processGroup;
+}
+
+@interface CloseWhileStartingProtocol : TestProtocol
+@end
+
+@implementation CloseWhileStartingProtocol
+
+- (void)startLoading
+{
+    dispatch_async(dispatch_get_main_queue(), ^ {
+        WKContextClientV0 client;
+        memset(&amp;client, 0, sizeof(client));
+        client.base.clientInfo = self;
+        client.networkProcessDidCrash = [](WKContextRef context, const void* clientInfo) {
+            auto protocol = (CloseWhileStartingProtocol *)clientInfo;
+            [protocol.client URLProtocol:protocol didFailWithError:[NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil]];
+        };
+        WKContextSetClient([processGroup() _contextRef], &amp;client.base);
+
+        kill(WKContextGetNetworkProcessIdentifier([processGroup() _contextRef]), SIGKILL);
+        [self.client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil]];
+    });
+}
+
+- (void)stopLoading
+{
+    dispatch_async(dispatch_get_main_queue(), ^ {
+        testFinished = true;
+    });
+}
+
+@end
+
</ins><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx"> 
</span><del>-TEST(WebKit2CustomProtocolsTest, MainResource)
</del><ins>+static void runTest()
</ins><span class="cx"> {
</span><del>-    [TestProtocol registerWithScheme:@&quot;http&quot;];
-
-    RetainPtr&lt;WKProcessGroup&gt; processGroup = adoptNS([[WKProcessGroup alloc] init]);
</del><span class="cx">     RetainPtr&lt;WKBrowsingContextGroup&gt; browsingContextGroup = adoptNS([[WKBrowsingContextGroup alloc] initWithIdentifier:@&quot;TestIdentifier&quot;]);
</span><del>-    RetainPtr&lt;WKView&gt; wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup.get() browsingContextGroup:browsingContextGroup.get()]);
</del><ins>+    RetainPtr&lt;WKView&gt; wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup() browsingContextGroup:browsingContextGroup.get()]);
</ins><span class="cx">     RetainPtr&lt;CustomProtocolsLoadDelegate&gt; loadDelegate = adoptNS([[CustomProtocolsLoadDelegate alloc] init]);
</span><span class="cx">     [wkView browsingContextController].loadDelegate = loadDelegate.get();
</span><span class="cx">     [[wkView browsingContextController] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@&quot;%@://redirect?test&quot;, [TestProtocol scheme]]]]];
</span><span class="cx"> 
</span><span class="cx">     Util::run(&amp;testFinished);
</span><ins>+}
+
+TEST(WebKit2CustomProtocolsTest, MainResource)
+{
+    [TestProtocol registerWithScheme:@&quot;http&quot;];
+    runTest();
</ins><span class="cx">     [TestProtocol unregister];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(WebKit2CustomProtocolsTest, CloseDuringCustomProtocolLoad)
+{
+    [CloseWhileStartingProtocol registerWithScheme:@&quot;http&quot;];
+    runTest();
+    [CloseWhileStartingProtocol unregister];
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx"> 
</span><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre>
</div>
</div>

</body>
</html>