<!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>[211915] 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/211915">211915</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2017-02-08 17:57:21 -0800 (Wed, 08 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>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.

Source/WebKit2:

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.

Tools:

* TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm:
(processGroup):
(-[CloseWhileStartingProtocol startLoading]):
(-[CloseWhileStartingProtocol stopLoading]):
(TestWebKitAPI::runTest):
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessNetworkCustomProtocolsmacCustomProtocolManagerProxyMacmm">trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2ObjCCustomProtocolsTestmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (211914 => 211915)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Source/WebKit2/ChangeLog        2017-02-09 01:57:21 UTC (rev 211915)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+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.
+
</ins><span class="cx"> 2017-02-08  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] WKRemoteObjectCoder doesn’t handle CGSize
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessNetworkCustomProtocolsmacCustomProtocolManagerProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm (211914 => 211915)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm        2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm        2017-02-09 01:57:21 UTC (rev 211915)
</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="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (211914 => 211915)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Tools/ChangeLog        2017-02-09 01:57:21 UTC (rev 211915)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+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):
+
</ins><span class="cx"> 2017-02-08  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] WKRemoteObjectCoder doesn’t handle CGSize
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2ObjCCustomProtocolsTestmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm (211914 => 211915)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm        2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm        2017-02-09 01:57:21 UTC (rev 211915)
</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>