<!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>[210374] trunk/Source</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/210374">210374</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-01-05 13:27:50 -0800 (Thu, 05 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[SOUP] Network process crash in WebKit::CustomProtocolManagerImpl::didFailWithError
https://bugs.webkit.org/show_bug.cgi?id=165082

Patch by Carlos Garcia Campos &lt;cgarcia@igalia.com&gt; on 2017-01-05
Reviewed by Alex Christensen.

Source/WebCore:

Simplified WebKitSoupRequestGenericClient.

* platform/network/soup/WebKitSoupRequestGeneric.cpp:
(webkitSoupRequestGenericSendAsync):
(webkitSoupRequestGenericSendFinish):
(webkitSoupRequestGenericGetRequest):
* platform/network/soup/WebKitSoupRequestGeneric.h:
* platform/network/soup/WebKitSoupRequestGenericClient.h:

Source/WebKit2:

CustomProtocolManager uses a Workqueue to receive the IPC messages since <a href="http://trac.webkit.org/projects/webkit/changeset/149194">r149194</a>. Then we added the Soup
implementation adopting that approach, but without making our implementation thread safe. The crash happens
because the CustomProtocolManager implementation is used by two threads at the same time, the main thread
because of a ping load (probably caused by an image load in the unload handler, I haven't been able to
reproduce the crash) and the work queue thread. The reasons to make CustomProtocolManager use a WorkQueue
are no longer valid because CustomProtocolManager is now only used in the network process and sync loads don't
use any nested run loop, they are just an IPC sync message. So this patch makes CustomProtocolManager a normal
message receiver again to ensure messages are handled in the main thread. It also adds the common implementation
to a new CustomProtocolManager.cpp file shared by Cocoa and Soup based ports.

* CMakeLists.txt: Add CustomProtocolManager.cpp.
* NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:
(-[WKCustomProtocol initWithRequest:cachedResponse:client:]): Use new CustomProtocolManager API.
(-[WKCustomProtocol startLoading]): Ditto.
(-[WKCustomProtocol stopLoading]): Ditto.
(WebKit::CustomProtocolManager::registerProtocolClass): Register the NSURLProtocol class when not using the
network session.
(WebKit::CustomProtocolManager::didFailWithError): removeCustomProtocol now receives an ID.
(WebKit::CustomProtocolManager::didFinishLoading): Ditto.
* NetworkProcess/CustomProtocols/CustomProtocolManager.cpp: Added.
(WebKit::generateCustomProtocolID): Moved from CustomProtocolManagerCocoa.mm and CustomProtocolManagerSoup.cpp.
(WebKit::CustomProtocolManager::supplementName): Ditto.
(WebKit::CustomProtocolManager::CustomProtocolManager): Also removes the work queue initialization.
(WebKit::CustomProtocolManager::initialize): Copied and modernized the loop.
(WebKit::CustomProtocolManager::addCustomProtocol): Copied from CustomProtocolManagerCocoa.mm.
(WebKit::CustomProtocolManager::removeCustomProtocol): Ditto.
(WebKit::CustomProtocolManager::startLoading): Send the StartLoading message to the proxy.
(WebKit::CustomProtocolManager::stopLoading): Send the StopLoading message to the proxy.
* NetworkProcess/CustomProtocols/CustomProtocolManager.h:
* NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp: Removed.
* NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.h: Removed.
* NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp: Moved the implementation from
CustomProtocolManagerImpl and updated to the new CustomProtocolManager API.
(WebKit::CustomProtocolManager::WebSoupRequestAsyncData::WebSoupRequestAsyncData):
(WebKit::CustomProtocolManager::WebSoupRequestAsyncData::~WebSoupRequestAsyncData):
(WebKit::CustomProtocolManager::registerProtocolClass):
(WebKit::CustomProtocolManager::registerScheme):
(WebKit::CustomProtocolManager::supportsScheme):
(WebKit::CustomProtocolManager::didFailWithError):
(WebKit::CustomProtocolManager::didLoadData):
(WebKit::CustomProtocolManager::didReceiveResponse):
(WebKit::CustomProtocolManager::didFinishLoading):
(WebKit::CustomProtocolManager::wasRedirectedToRequest):
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::globalCustomProtocolManager):
(WebKit::NetworkSessionCocoa::defaultSession):
CustomProtocolManager is no longer refcounted, so just pass a pointer.
A static pointer has the same lifetime as the NetworkProcess object in the NetworkProcess,
and in the WebProcess it will remain nullptr, just like it used to.
* PlatformEfl.cmake:
* PlatformGTK.cmake:
* WebKit2.xcodeproj/project.pbxproj:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworksoupWebKitSoupRequestGenericcpp">trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworksoupWebKitSoupRequestGenerich">trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworksoupWebKitSoupRequestGenericClienth">trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGenericClient.h</a></li>
<li><a href="#trunkSourceWebKit2CMakeListstxt">trunk/Source/WebKit2/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessCustomProtocolsCocoaCustomProtocolManagerCocoamm">trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessCustomProtocolsCustomProtocolManagerh">trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessCustomProtocolssoupCustomProtocolManagerSoupcpp">trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscocoaNetworkSessionCocoamm">trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2PlatformEflcmake">trunk/Source/WebKit2/PlatformEfl.cmake</a></li>
<li><a href="#trunkSourceWebKit2PlatformGTKcmake">trunk/Source/WebKit2/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2NetworkProcessCustomProtocolsCustomProtocolManagercpp">trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.cpp</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2NetworkProcessCustomProtocolssoupCustomProtocolManagerImplcpp">trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessCustomProtocolssoupCustomProtocolManagerImplh">trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebCore/ChangeLog        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2017-01-05  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [SOUP] Network process crash in WebKit::CustomProtocolManagerImpl::didFailWithError
+        https://bugs.webkit.org/show_bug.cgi?id=165082
+
+        Reviewed by Alex Christensen.
+
+        Simplified WebKitSoupRequestGenericClient.
+
+        * platform/network/soup/WebKitSoupRequestGeneric.cpp:
+        (webkitSoupRequestGenericSendAsync):
+        (webkitSoupRequestGenericSendFinish):
+        (webkitSoupRequestGenericGetRequest):
+        * platform/network/soup/WebKitSoupRequestGeneric.h:
+        * platform/network/soup/WebKitSoupRequestGenericClient.h:
+
</ins><span class="cx"> 2017-01-05  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Turn preferLowPowerWebGLRendering setting on by default
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworksoupWebKitSoupRequestGenericcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.cpp (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.cpp        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.cpp        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -50,15 +50,14 @@
</span><span class="cx"> {
</span><span class="cx">     WebKitSoupRequestGenericClient* client = WEBKIT_SOUP_REQUEST_GENERIC_GET_CLASS(request)-&gt;client;
</span><span class="cx">     ASSERT(client);
</span><del>-    client-&gt;start(g_task_new(request, cancellable, callback, userData));
</del><ins>+    client-&gt;startRequest(adoptGRef(g_task_new(request, cancellable, callback, userData)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static GInputStream* webkitSoupRequestGenericSendFinish(SoupRequest* request, GAsyncResult* result, GError** error)
</span><span class="cx"> {
</span><span class="cx">     g_return_val_if_fail(g_task_is_valid(result, request), nullptr);
</span><del>-    WebKitSoupRequestGenericClient* client = WEBKIT_SOUP_REQUEST_GENERIC_GET_CLASS(request)-&gt;client;
-    ASSERT(client);
-    return client-&gt;finish(G_TASK(result), error);
</del><ins>+    auto* inputStream = g_task_propagate_pointer(G_TASK(result), error);
+    return inputStream ? G_INPUT_STREAM(inputStream) : nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static goffset webkitSoupRequestGenericGetContentLength(SoupRequest* request)
</span><span class="lines">@@ -100,7 +99,7 @@
</span><span class="cx">     request-&gt;priv-&gt;resourceRequest = resourceRequest;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const ResourceRequest* webkitSoupRequestGenericGetRequest(WebKitSoupRequestGeneric* request)
</del><ins>+const ResourceRequest&amp; webkitSoupRequestGenericGetRequest(WebKitSoupRequestGeneric* request)
</ins><span class="cx"> {
</span><del>-    return &amp;request-&gt;priv-&gt;resourceRequest;
</del><ins>+    return request-&gt;priv-&gt;resourceRequest;
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworksoupWebKitSoupRequestGenerich"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.h (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.h        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGeneric.h        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx"> void webkitSoupRequestGenericSetContentLength(WebKitSoupRequestGeneric*, goffset contentLength);
</span><span class="cx"> void webkitSoupRequestGenericSetContentType(WebKitSoupRequestGeneric*, const char* mimeType);
</span><span class="cx"> void webkitSoupRequestGenericSetRequest(WebKitSoupRequestGeneric*, const WebCore::ResourceRequest&amp;);
</span><del>-const WebCore::ResourceRequest* webkitSoupRequestGenericGetRequest(WebKitSoupRequestGeneric*);
</del><ins>+const WebCore::ResourceRequest&amp; webkitSoupRequestGenericGetRequest(WebKitSoupRequestGeneric*);
</ins><span class="cx"> 
</span><span class="cx"> G_END_DECLS
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworksoupWebKitSoupRequestGenericClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGenericClient.h (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGenericClient.h        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebCore/platform/network/soup/WebKitSoupRequestGenericClient.h        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -17,11 +17,10 @@
</span><span class="cx">  * Boston, MA 02110-1301, USA.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef WebKitSoupRequestGenericClient_h
-#define WebKitSoupRequestGenericClient_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><del>-typedef struct _GError GError;
-typedef struct _GInputStream GInputStream;
</del><ins>+#include &lt;wtf/glib/GRefPtr.h&gt;
+
</ins><span class="cx"> typedef struct _GTask GTask;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -28,10 +27,8 @@
</span><span class="cx"> 
</span><span class="cx"> class WebKitSoupRequestGenericClient {
</span><span class="cx"> public:
</span><del>-    virtual void start(GTask*) = 0;
-    virtual GInputStream* finish(GTask*, GError**) = 0;
</del><ins>+    virtual void startRequest(GRefPtr&lt;GTask&gt;&amp;&amp;) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><del>-#endif // WebKitSoupRequestGenericClient_h
</del></span></pre></div>
<a id="trunkSourceWebKit2CMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/CMakeLists.txt (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/CMakeLists.txt        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/CMakeLists.txt        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -93,6 +93,8 @@
</span><span class="cx"> endif ()
</span><span class="cx"> 
</span><span class="cx"> set(NetworkProcess_COMMON_SOURCES
</span><ins>+    NetworkProcess/CustomProtocols/CustomProtocolManager.cpp
+
</ins><span class="cx">     NetworkProcess/NetworkConnectionToWebProcess.cpp
</span><span class="cx">     NetworkProcess/NetworkDataTask.cpp
</span><span class="cx">     NetworkProcess/NetworkDataTaskBlob.cpp
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/ChangeLog        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -1,3 +1,63 @@
</span><ins>+2017-01-05  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [SOUP] Network process crash in WebKit::CustomProtocolManagerImpl::didFailWithError
+        https://bugs.webkit.org/show_bug.cgi?id=165082
+
+        Reviewed by Alex Christensen.
+
+        CustomProtocolManager uses a Workqueue to receive the IPC messages since r149194. Then we added the Soup
+        implementation adopting that approach, but without making our implementation thread safe. The crash happens
+        because the CustomProtocolManager implementation is used by two threads at the same time, the main thread
+        because of a ping load (probably caused by an image load in the unload handler, I haven't been able to
+        reproduce the crash) and the work queue thread. The reasons to make CustomProtocolManager use a WorkQueue
+        are no longer valid because CustomProtocolManager is now only used in the network process and sync loads don't
+        use any nested run loop, they are just an IPC sync message. So this patch makes CustomProtocolManager a normal
+        message receiver again to ensure messages are handled in the main thread. It also adds the common implementation
+        to a new CustomProtocolManager.cpp file shared by Cocoa and Soup based ports.
+
+        * CMakeLists.txt: Add CustomProtocolManager.cpp.
+        * NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:
+        (-[WKCustomProtocol initWithRequest:cachedResponse:client:]): Use new CustomProtocolManager API.
+        (-[WKCustomProtocol startLoading]): Ditto.
+        (-[WKCustomProtocol stopLoading]): Ditto.
+        (WebKit::CustomProtocolManager::registerProtocolClass): Register the NSURLProtocol class when not using the
+        network session.
+        (WebKit::CustomProtocolManager::didFailWithError): removeCustomProtocol now receives an ID.
+        (WebKit::CustomProtocolManager::didFinishLoading): Ditto.
+        * NetworkProcess/CustomProtocols/CustomProtocolManager.cpp: Added.
+        (WebKit::generateCustomProtocolID): Moved from CustomProtocolManagerCocoa.mm and CustomProtocolManagerSoup.cpp.
+        (WebKit::CustomProtocolManager::supplementName): Ditto.
+        (WebKit::CustomProtocolManager::CustomProtocolManager): Also removes the work queue initialization.
+        (WebKit::CustomProtocolManager::initialize): Copied and modernized the loop.
+        (WebKit::CustomProtocolManager::addCustomProtocol): Copied from CustomProtocolManagerCocoa.mm.
+        (WebKit::CustomProtocolManager::removeCustomProtocol): Ditto.
+        (WebKit::CustomProtocolManager::startLoading): Send the StartLoading message to the proxy.
+        (WebKit::CustomProtocolManager::stopLoading): Send the StopLoading message to the proxy.
+        * NetworkProcess/CustomProtocols/CustomProtocolManager.h:
+        * NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp: Removed.
+        * NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.h: Removed.
+        * NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp: Moved the implementation from
+        CustomProtocolManagerImpl and updated to the new CustomProtocolManager API.
+        (WebKit::CustomProtocolManager::WebSoupRequestAsyncData::WebSoupRequestAsyncData):
+        (WebKit::CustomProtocolManager::WebSoupRequestAsyncData::~WebSoupRequestAsyncData):
+        (WebKit::CustomProtocolManager::registerProtocolClass):
+        (WebKit::CustomProtocolManager::registerScheme):
+        (WebKit::CustomProtocolManager::supportsScheme):
+        (WebKit::CustomProtocolManager::didFailWithError):
+        (WebKit::CustomProtocolManager::didLoadData):
+        (WebKit::CustomProtocolManager::didReceiveResponse):
+        (WebKit::CustomProtocolManager::didFinishLoading):
+        (WebKit::CustomProtocolManager::wasRedirectedToRequest):
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::globalCustomProtocolManager):
+        (WebKit::NetworkSessionCocoa::defaultSession):
+        CustomProtocolManager is no longer refcounted, so just pass a pointer.
+        A static pointer has the same lifetime as the NetworkProcess object in the NetworkProcess,
+        and in the WebProcess it will remain nullptr, just like it used to.
+        * PlatformEfl.cmake:
+        * PlatformGTK.cmake:
+        * WebKit2.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2017-01-05  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Use WTF::Function instead of std::function in network cache code
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessCustomProtocolsCocoaCustomProtocolManagerCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -26,14 +26,9 @@
</span><span class="cx"> #import &quot;config.h&quot;
</span><span class="cx"> #import &quot;CustomProtocolManager.h&quot;
</span><span class="cx"> 
</span><del>-#import &quot;ChildProcess.h&quot;
</del><span class="cx"> #import &quot;CustomProtocolManagerMessages.h&quot;
</span><del>-#import &quot;CustomProtocolManagerProxyMessages.h&quot;
</del><span class="cx"> #import &quot;DataReference.h&quot;
</span><span class="cx"> #import &quot;NetworkProcess.h&quot;
</span><del>-#import &quot;NetworkProcessCreationParameters.h&quot;
-#import &quot;WebCoreArgumentCoders.h&quot;
-#import &quot;WebProcessCreationParameters.h&quot;
</del><span class="cx"> #import &lt;Foundation/NSURLSession.h&gt;
</span><span class="cx"> #import &lt;WebCore/NSURLConnectionSPI.h&gt;
</span><span class="cx"> #import &lt;WebCore/URL.h&gt;
</span><span class="lines">@@ -44,16 +39,6 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace WebKit;
</span><span class="cx"> 
</span><del>-namespace WebKit {
-
-static uint64_t generateCustomProtocolID()
-{
-    static uint64_t uniqueCustomProtocolID = 0;
-    return ++uniqueCustomProtocolID;
-}
-
-} // namespace WebKit
-
</del><span class="cx"> @interface WKCustomProtocol : NSURLProtocol {
</span><span class="cx"> @private
</span><span class="cx">     uint64_t _customProtocolID;
</span><span class="lines">@@ -89,11 +74,11 @@
</span><span class="cx">     self = [super initWithRequest:request cachedResponse:cachedResponse client:client];
</span><span class="cx">     if (!self)
</span><span class="cx">         return nil;
</span><del>-    
-    _customProtocolID = generateCustomProtocolID();
</del><ins>+
+    if (auto* customProtocolManager = NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;())
+        _customProtocolID = customProtocolManager-&gt;addCustomProtocol(self);
</ins><span class="cx">     _initializationRunLoop = CFRunLoopGetCurrent();
</span><del>-    if (auto* customProtocolManager = NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;())
-        customProtocolManager-&gt;addCustomProtocol(self);
</del><ins>+
</ins><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -105,14 +90,14 @@
</span><span class="cx"> - (void)startLoading
</span><span class="cx"> {
</span><span class="cx">     if (auto* customProtocolManager = NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;())
</span><del>-        customProtocolManager-&gt;childProcess()-&gt;send(Messages::CustomProtocolManagerProxy::StartLoading(self.customProtocolID, [self request]), 0);
</del><ins>+        customProtocolManager-&gt;startLoading(self.customProtocolID, [self request]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)stopLoading
</span><span class="cx"> {
</span><span class="cx">     if (auto* customProtocolManager = NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;()) {
</span><del>-        customProtocolManager-&gt;childProcess()-&gt;send(Messages::CustomProtocolManagerProxy::StopLoading(self.customProtocolID), 0);
-        customProtocolManager-&gt;removeCustomProtocol(self);
</del><ins>+        customProtocolManager-&gt;stopLoading(self.customProtocolID);
+        customProtocolManager-&gt;removeCustomProtocol(self.customProtocolID);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -120,47 +105,13 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-const char* CustomProtocolManager::supplementName()
</del><ins>+void CustomProtocolManager::registerProtocolClass()
</ins><span class="cx"> {
</span><del>-    return &quot;CustomProtocolManager&quot;;
-}
-
-CustomProtocolManager::CustomProtocolManager(ChildProcess* childProcess)
-    : m_childProcess(childProcess)
-    , m_messageQueue(WorkQueue::create(&quot;com.apple.WebKit.CustomProtocolManager&quot;))
-{
-    WebCore::UTF8Encoding();
-}
-
-void CustomProtocolManager::initializeConnection(IPC::Connection* connection)
-{
-    connection-&gt;addWorkQueueMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), m_messageQueue.get(), this);
-}
-
-void CustomProtocolManager::initialize(const NetworkProcessCreationParameters&amp; parameters)
-{
</del><span class="cx"> #if !USE(NETWORK_SESSION)
</span><span class="cx">     [NSURLProtocol registerClass:[WKCustomProtocol class]];
</span><span class="cx"> #endif
</span><del>-
-    for (size_t i = 0; i &lt; parameters.urlSchemesRegisteredForCustomProtocols.size(); ++i)
-        registerScheme(parameters.urlSchemesRegisteredForCustomProtocols[i]);
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CustomProtocolManager::addCustomProtocol(WKCustomProtocol *customProtocol)
-{
-    ASSERT(customProtocol);
-    LockHolder locker(m_customProtocolMapMutex);
-    m_customProtocolMap.add(customProtocol.customProtocolID, customProtocol);
-}
-
-void CustomProtocolManager::removeCustomProtocol(WKCustomProtocol *customProtocol)
-{
-    ASSERT(customProtocol);
-    LockHolder locker(m_customProtocolMapMutex);
-    m_customProtocolMap.remove(customProtocol.customProtocolID);
-}
-
</del><span class="cx"> #if USE(NETWORK_SESSION)
</span><span class="cx"> void CustomProtocolManager::registerProtocolClass(NSURLSessionConfiguration *configuration)
</span><span class="cx"> {
</span><span class="lines">@@ -174,7 +125,7 @@
</span><span class="cx">     LockHolder locker(m_registeredSchemesMutex);
</span><span class="cx">     m_registeredSchemes.add(scheme);
</span><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> void CustomProtocolManager::unregisterScheme(const String&amp; scheme)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!scheme.isNull());
</span><span class="lines">@@ -210,7 +161,7 @@
</span><span class="cx">         [[protocol client] URLProtocol:protocol.get() didFailWithError:nsError.get()];
</span><span class="cx">     });
</span><span class="cx"> 
</span><del>-    removeCustomProtocol(protocol.get());
</del><ins>+    removeCustomProtocol(customProtocolID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CustomProtocolManager::didLoadData(uint64_t customProtocolID, const IPC::DataReference&amp; data)
</span><span class="lines">@@ -249,7 +200,7 @@
</span><span class="cx">         [[protocol client] URLProtocolDidFinishLoading:protocol.get()];
</span><span class="cx">     });
</span><span class="cx"> 
</span><del>-    removeCustomProtocol(protocol.get());
</del><ins>+    removeCustomProtocol(customProtocolID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CustomProtocolManager::wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest&amp; request, const WebCore::ResourceResponse&amp; redirectResponse)
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessCustomProtocolsCustomProtocolManagercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.cpp (0 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.cpp                                (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.cpp        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -0,0 +1,88 @@
</span><ins>+/*
+ * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * 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.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;CustomProtocolManager.h&quot;
+
+#include &quot;ChildProcess.h&quot;
+#include &quot;CustomProtocolManagerMessages.h&quot;
+#include &quot;CustomProtocolManagerProxyMessages.h&quot;
+#include &quot;NetworkProcessCreationParameters.h&quot;
+#include &quot;WebCoreArgumentCoders.h&quot;
+#include &lt;WebCore/ResourceRequest.h&gt;
+
+namespace WebKit {
+
+static uint64_t generateCustomProtocolID()
+{
+    static uint64_t uniqueCustomProtocolID = 0;
+    return ++uniqueCustomProtocolID;
+}
+
+const char* CustomProtocolManager::supplementName()
+{
+    return &quot;CustomProtocolManager&quot;;
+}
+
+CustomProtocolManager::CustomProtocolManager(ChildProcess* childProcess)
+    : m_childProcess(childProcess)
+{
+    m_childProcess-&gt;addMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), *this);
+}
+
+void CustomProtocolManager::initialize(const NetworkProcessCreationParameters&amp; parameters)
+{
+    registerProtocolClass();
+
+    for (const auto&amp; scheme : parameters.urlSchemesRegisteredForCustomProtocols)
+        registerScheme(scheme);
+}
+
+uint64_t CustomProtocolManager::addCustomProtocol(CustomProtocol&amp;&amp; customProtocol)
+{
+    LockHolder locker(m_customProtocolMapMutex);
+    auto customProtocolID = generateCustomProtocolID();
+    m_customProtocolMap.add(customProtocolID, WTFMove(customProtocol));
+    return customProtocolID;
+}
+
+void CustomProtocolManager::removeCustomProtocol(uint64_t customProtocolID)
+{
+    LockHolder locker(m_customProtocolMapMutex);
+    m_customProtocolMap.remove(customProtocolID);
+}
+
+void CustomProtocolManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest&amp; request)
+{
+    m_childProcess-&gt;send(Messages::CustomProtocolManagerProxy::StartLoading(customProtocolID, request));
+}
+
+void CustomProtocolManager::stopLoading(uint64_t customProtocolID)
+{
+    m_childProcess-&gt;send(Messages::CustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
+}
+
+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessCustomProtocolsCustomProtocolManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.h (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.h        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/CustomProtocolManager.h        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -23,27 +23,30 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef CustomProtocolManager_h
-#define CustomProtocolManager_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><del>-#include &quot;Connection.h&quot;
</del><ins>+#include &quot;MessageReceiver.h&quot;
</ins><span class="cx"> #include &quot;NetworkProcessSupplement.h&quot;
</span><del>-#include &lt;wtf/WorkQueue.h&gt;
</del><ins>+#include &lt;wtf/HashMap.h&gt;
+#include &lt;wtf/HashSet.h&gt;
+#include &lt;wtf/text/StringHash.h&gt;
</ins><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><del>-#include &lt;wtf/HashMap.h&gt;
-#include &lt;wtf/HashSet.h&gt;
</del><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><del>-#include &lt;wtf/Threading.h&gt;
-#include &lt;wtf/text/StringHash.h&gt;
</del><span class="cx"> OBJC_CLASS NSURLSessionConfiguration;
</span><span class="cx"> OBJC_CLASS WKCustomProtocol;
</span><del>-#else
-#include &quot;CustomProtocolManagerImpl.h&quot;
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(SOUP)
+#include &lt;wtf/glib/GRefPtr.h&gt;
</ins><span class="cx"> 
</span><ins>+typedef struct _GCancellable GCancellable;
+typedef struct _GInputStream GInputStream;
+typedef struct _GTask GTask;
+typedef struct _WebKitSoupRequestGeneric WebKitSoupRequestGeneric;
+#endif
+
</ins><span class="cx"> namespace IPC {
</span><span class="cx"> class DataReference;
</span><span class="cx"> } // namespace IPC
</span><span class="lines">@@ -59,7 +62,7 @@
</span><span class="cx"> class ChildProcess;
</span><span class="cx"> struct NetworkProcessCreationParameters;
</span><span class="cx"> 
</span><del>-class CustomProtocolManager : public NetworkProcessSupplement, public IPC::Connection::WorkQueueMessageReceiver {
</del><ins>+class CustomProtocolManager : public NetworkProcessSupplement, public IPC::MessageReceiver {
</ins><span class="cx">     WTF_MAKE_NONCOPYABLE(CustomProtocolManager);
</span><span class="cx"> public:
</span><span class="cx">     explicit CustomProtocolManager(ChildProcess*);
</span><span class="lines">@@ -66,24 +69,36 @@
</span><span class="cx"> 
</span><span class="cx">     static const char* supplementName();
</span><span class="cx"> 
</span><del>-    ChildProcess* childProcess() const { return m_childProcess; }
-
</del><span class="cx">     void registerScheme(const String&amp;);
</span><span class="cx">     void unregisterScheme(const String&amp;);
</span><span class="cx">     bool supportsScheme(const String&amp;);
</span><del>-    
</del><ins>+
</ins><span class="cx"> #if PLATFORM(COCOA)
</span><del>-    void addCustomProtocol(WKCustomProtocol *);
-    void removeCustomProtocol(WKCustomProtocol *);
-#if USE(NETWORK_SESSION)
-    void registerProtocolClass(NSURLSessionConfiguration *);
</del><ins>+    typedef RetainPtr&lt;WKCustomProtocol&gt; CustomProtocol;
</ins><span class="cx"> #endif
</span><ins>+#if USE(SOUP)
+    struct WebSoupRequestAsyncData {
+        WebSoupRequestAsyncData(GRefPtr&lt;GTask&gt;&amp;&amp;, WebKitSoupRequestGeneric*);
+        ~WebSoupRequestAsyncData();
+
+        GRefPtr&lt;GTask&gt; task;
+        WebKitSoupRequestGeneric* request;
+        GRefPtr&lt;GCancellable&gt; cancellable;
+        GRefPtr&lt;GInputStream&gt; stream;
+    };
+    typedef std::unique_ptr&lt;WebSoupRequestAsyncData&gt; CustomProtocol;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    uint64_t addCustomProtocol(CustomProtocol&amp;&amp;);
+    void removeCustomProtocol(uint64_t customProtocolID);
+    void startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest&amp;);
+    void stopLoading(uint64_t customProtocolID);
+
+#if PLATFORM(COCOA) &amp;&amp; USE(NETWORK_SESSION)
+    void registerProtocolClass(NSURLSessionConfiguration*);
+#endif
+
</ins><span class="cx"> private:
</span><del>-    // ChildProcessSupplement
-    void initializeConnection(IPC::Connection*) override;
-
</del><span class="cx">     // NetworkProcessSupplement
</span><span class="cx">     void initialize(const NetworkProcessCreationParameters&amp;) override;
</span><span class="cx"> 
</span><span class="lines">@@ -96,26 +111,27 @@
</span><span class="cx">     void didFinishLoading(uint64_t customProtocolID);
</span><span class="cx">     void wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp; redirectResponse);
</span><span class="cx"> 
</span><ins>+    void registerProtocolClass();
+
</ins><span class="cx">     ChildProcess* m_childProcess;
</span><del>-    Ref&lt;WorkQueue&gt; m_messageQueue;
</del><span class="cx"> 
</span><ins>+    typedef HashMap&lt;uint64_t, CustomProtocol&gt; CustomProtocolMap;
+    CustomProtocolMap m_customProtocolMap;
+    Lock m_customProtocolMapMutex;
+
</ins><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     HashSet&lt;String, ASCIICaseInsensitiveHash&gt; m_registeredSchemes;
</span><span class="cx">     Lock m_registeredSchemesMutex;
</span><span class="cx"> 
</span><del>-    typedef HashMap&lt;uint64_t, RetainPtr&lt;WKCustomProtocol&gt;&gt; CustomProtocolMap;
-    CustomProtocolMap m_customProtocolMap;
-    Lock m_customProtocolMapMutex;
-    
</del><span class="cx">     // WKCustomProtocol objects can be removed from the m_customProtocolMap from multiple threads.
</span><span class="cx">     // We return a RetainPtr here because it is unsafe to return a raw pointer since the object might immediately be destroyed from a different thread.
</span><span class="cx">     RetainPtr&lt;WKCustomProtocol&gt; protocolForID(uint64_t customProtocolID);
</span><del>-#else
-    // FIXME: Move mac specific code to CustomProtocolManagerImpl.
-    std::unique_ptr&lt;CustomProtocolManagerImpl&gt; m_impl;
</del><span class="cx"> #endif
</span><ins>+
+#if USE(SOUP)
+    GRefPtr&lt;GPtrArray&gt; m_registeredSchemes;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><del>-#endif // CustomProtocolManager_h
</del></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessCustomProtocolssoupCustomProtocolManagerImplcpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -1,212 +0,0 @@
</span><del>-/*
- * Copyright (C) 2014 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include &quot;config.h&quot;
-#include &quot;CustomProtocolManagerImpl.h&quot;
-
-#include &quot;ChildProcess.h&quot;
-#include &quot;CustomProtocolManagerProxyMessages.h&quot;
-#include &quot;DataReference.h&quot;
-#include &quot;WebCoreArgumentCoders.h&quot;
-#include &quot;WebKitSoupRequestInputStream.h&quot;
-#include &lt;WebCore/ResourceError.h&gt;
-#include &lt;WebCore/ResourceRequest.h&gt;
-#include &lt;WebCore/ResourceResponse.h&gt;
-#include &lt;WebCore/SoupNetworkSession.h&gt;
-#include &lt;WebCore/WebKitSoupRequestGeneric.h&gt;
-
-namespace WebKit {
-
-static uint64_t generateCustomProtocolID()
-{
-    static uint64_t uniqueCustomProtocolID = 0;
-    return ++uniqueCustomProtocolID;
-}
-
-struct WebSoupRequestAsyncData {
-    WebSoupRequestAsyncData(GTask* task, WebKitSoupRequestGeneric* requestGeneric)
-        : task(task)
-        , request(requestGeneric)
-        , cancellable(g_task_get_cancellable(task))
-    {
-        // If the struct contains a null request, it is because the request failed.
-        g_object_add_weak_pointer(G_OBJECT(request), reinterpret_cast&lt;void**&gt;(&amp;request));
-    }
-
-    ~WebSoupRequestAsyncData()
-    {
-        if (request)
-            g_object_remove_weak_pointer(G_OBJECT(request), reinterpret_cast&lt;void**&gt;(&amp;request));
-    }
-
-    bool requestFailed()
-    {
-        return g_cancellable_is_cancelled(cancellable.get()) || !request;
-    }
-
-    GRefPtr&lt;GTask&gt; releaseTask()
-    {
-        GTask* returnValue = task;
-        task = nullptr;
-        return adoptGRef(returnValue);
-    }
-
-    GTask* task;
-    WebKitSoupRequestGeneric* request;
-    GRefPtr&lt;GCancellable&gt; cancellable;
-    GRefPtr&lt;GInputStream&gt; stream;
-};
-
-CustomProtocolManagerImpl::CustomProtocolManagerImpl(ChildProcess* childProcess)
-    : m_childProcess(childProcess)
-    , m_schemes(adoptGRef(g_ptr_array_new_with_free_func(g_free)))
-{
-}
-
-CustomProtocolManagerImpl::~CustomProtocolManagerImpl()
-{
-}
-
-void CustomProtocolManagerImpl::registerScheme(const String&amp; scheme)
-{
-    if (m_schemes-&gt;len)
-        g_ptr_array_remove_index_fast(m_schemes.get(), m_schemes-&gt;len - 1);
-    g_ptr_array_add(m_schemes.get(), g_strdup(scheme.utf8().data()));
-    g_ptr_array_add(m_schemes.get(), nullptr);
-
-    SoupSession* session = WebCore::SoupNetworkSession::defaultSession().soupSession();
-    SoupRequestClass* genericRequestClass = static_cast&lt;SoupRequestClass*&gt;(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
-    genericRequestClass-&gt;schemes = const_cast&lt;const char**&gt;(reinterpret_cast&lt;char**&gt;(m_schemes-&gt;pdata));
-    static_cast&lt;WebKitSoupRequestGenericClass*&gt;(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC))-&gt;client = this;
-    soup_session_add_feature_by_type(session, WEBKIT_TYPE_SOUP_REQUEST_GENERIC);
-}
-
-bool CustomProtocolManagerImpl::supportsScheme(const String&amp; scheme)
-{
-    if (scheme.isNull())
-        return false;
-
-    CString cScheme = scheme.utf8();
-    for (unsigned i = 0; i &lt; m_schemes-&gt;len; ++i) {
-        if (cScheme == static_cast&lt;char*&gt;(g_ptr_array_index(m_schemes.get(), i)))
-            return true;
-    }
-
-    return false;
-}
-
-void CustomProtocolManagerImpl::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&amp; error)
-{
-    WebSoupRequestAsyncData* data = m_customProtocolMap.get(customProtocolID);
-    ASSERT(data);
-
-    // Either we haven't started reading the stream yet, in which case we need to complete the
-    // task first, or we failed reading it and the task was already completed by didLoadData().
-    ASSERT(!data-&gt;stream || !data-&gt;task);
-
-    if (!data-&gt;stream) {
-        GRefPtr&lt;GTask&gt; task = data-&gt;releaseTask();
-        ASSERT(task.get());
-        g_task_return_new_error(task.get(), g_quark_from_string(error.domain().utf8().data()),
-            error.errorCode(), &quot;%s&quot;, error.localizedDescription().utf8().data());
-    } else
-        webkitSoupRequestInputStreamDidFailWithError(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get()), error);
-
-    m_customProtocolMap.remove(customProtocolID);
-}
-
-void CustomProtocolManagerImpl::didLoadData(uint64_t customProtocolID, const IPC::DataReference&amp; dataReference)
-{
-    WebSoupRequestAsyncData* data = m_customProtocolMap.get(customProtocolID);
-    // The data might have been removed from the request map if a previous chunk failed
-    // and a new message was sent by the UI process before being notified about the failure.
-    if (!data)
-        return;
-
-    if (!data-&gt;stream) {
-        GRefPtr&lt;GTask&gt; task = data-&gt;releaseTask();
-        ASSERT(task.get());
-
-        goffset soupContentLength = soup_request_get_content_length(SOUP_REQUEST(g_task_get_source_object(task.get())));
-        uint64_t contentLength = soupContentLength == -1 ? 0 : static_cast&lt;uint64_t&gt;(soupContentLength);
-        if (!dataReference.size()) {
-            // Empty reply, just create and empty GMemoryInputStream.
-            data-&gt;stream = g_memory_input_stream_new();
-        } else if (dataReference.size() == contentLength) {
-            // We don't expect more data, so we can just create a GMemoryInputStream with all the data.
-            data-&gt;stream = g_memory_input_stream_new_from_data(g_memdup(dataReference.data(), dataReference.size()), contentLength, g_free);
-        } else {
-            // We expect more data chunks from the UI process.
-            data-&gt;stream = webkitSoupRequestInputStreamNew(contentLength);
-            webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get()), dataReference.data(), dataReference.size());
-        }
-        g_task_return_pointer(task.get(), data-&gt;stream.get(), g_object_unref);
-        return;
-    }
-
-    if (data-&gt;requestFailed()) {
-        // ResourceRequest failed or it was cancelled. It doesn't matter here the error or if it was cancelled,
-        // because that's already handled by the resource handle client, we just want to notify the UI process
-        // to stop reading data from the user input stream. If UI process already sent all the data we simply
-        // finish silently.
-        if (!webkitSoupRequestInputStreamFinished(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get())))
-            m_childProcess-&gt;send(Messages::CustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
-
-        return;
-    }
-
-    webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get()), dataReference.data(), dataReference.size());
-}
-
-void CustomProtocolManagerImpl::didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&amp; response)
-{
-    WebSoupRequestAsyncData* data = m_customProtocolMap.get(customProtocolID);
-    // The data might have been removed from the request map if an error happened even before this point.
-    if (!data)
-        return;
-
-    ASSERT(data-&gt;task);
-
-    WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(data-&gt;task));
-    webkitSoupRequestGenericSetContentLength(request, response.expectedContentLength() ? response.expectedContentLength() : -1);
-    webkitSoupRequestGenericSetContentType(request, !response.mimeType().isEmpty() ? response.mimeType().utf8().data() : 0);
-}
-
-void CustomProtocolManagerImpl::didFinishLoading(uint64_t customProtocolID)
-{
-    ASSERT(m_customProtocolMap.contains(customProtocolID));
-    m_customProtocolMap.remove(customProtocolID);
-}
-
-void CustomProtocolManagerImpl::start(GTask* task)
-{
-    uint64_t customProtocolID = generateCustomProtocolID();
-    WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(task));
-    m_customProtocolMap.set(customProtocolID, std::make_unique&lt;WebSoupRequestAsyncData&gt;(task, request));
-
-    m_childProcess-&gt;send(Messages::CustomProtocolManagerProxy::StartLoading(customProtocolID, *webkitSoupRequestGenericGetRequest(request)), 0);
-}
-
-GInputStream* CustomProtocolManagerImpl::finish(GTask* task, GError** error)
-{
-    gpointer inputStream = g_task_propagate_pointer(task, error);
-    return inputStream ? G_INPUT_STREAM(inputStream) : 0;
-}
-
-} // namespace WebKit
</del></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessCustomProtocolssoupCustomProtocolManagerImplh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.h (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.h        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.h        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -1,67 +0,0 @@
</span><del>-/*
- * Copyright (C) 2014 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef CustomProtocolManagerImpl_h
-#define CustomProtocolManagerImpl_h
-
-#include &lt;WebCore/WebKitSoupRequestGenericClient.h&gt;
-#include &lt;wtf/HashMap.h&gt;
-#include &lt;wtf/glib/GRefPtr.h&gt;
-#include &lt;wtf/text/WTFString.h&gt;
-
-namespace IPC {
-class DataReference;
-} // namespace IPC
-
-namespace WebCore {
-class ResourceError;
-class ResourceResponse;
-} // namespace WebCore
-
-namespace WebKit {
-
-class ChildProcess;
-struct WebSoupRequestAsyncData;
-
-class CustomProtocolManagerImpl : public WebCore::WebKitSoupRequestGenericClient {
-    WTF_MAKE_NONCOPYABLE(CustomProtocolManagerImpl);
-public:
-    explicit CustomProtocolManagerImpl(ChildProcess*);
-    ~CustomProtocolManagerImpl();
-
-    void registerScheme(const String&amp;);
-    bool supportsScheme(const String&amp;);
-
-    void didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&amp;);
-    void didLoadData(uint64_t customProtocolID, const IPC::DataReference&amp;);
-    void didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&amp;);
-    void didFinishLoading(uint64_t customProtocolID);
-
-private:
-    void start(GTask*) final;
-    GInputStream* finish(GTask*, GError**) final;
-
-    ChildProcess* m_childProcess;
-    GRefPtr&lt;GPtrArray&gt; m_schemes;
-    HashMap&lt;uint64_t, std::unique_ptr&lt;WebSoupRequestAsyncData&gt;&gt; m_customProtocolMap;
-};
-
-} // namespace WebKit
-
-#endif // CustomProtocolManagerImpl_h
</del></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessCustomProtocolssoupCustomProtocolManagerSoupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -20,41 +20,77 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;CustomProtocolManager.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;ChildProcess.h&quot;
-#include &quot;CustomProtocolManagerImpl.h&quot;
</del><span class="cx"> #include &quot;CustomProtocolManagerMessages.h&quot;
</span><del>-#include &quot;NetworkProcessCreationParameters.h&quot;
-#include &quot;WebProcessCreationParameters.h&quot;
</del><ins>+#include &quot;DataReference.h&quot;
+#include &quot;NetworkProcess.h&quot;
+#include &quot;WebKitSoupRequestInputStream.h&quot;
</ins><span class="cx"> #include &lt;WebCore/NotImplemented.h&gt;
</span><ins>+#include &lt;WebCore/ResourceError.h&gt;
+#include &lt;WebCore/ResourceRequest.h&gt;
+#include &lt;WebCore/ResourceResponse.h&gt;
+#include &lt;WebCore/SoupNetworkSession.h&gt;
+#include &lt;WebCore/WebKitSoupRequestGeneric.h&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
</ins><span class="cx"> 
</span><ins>+using namespace WebCore;
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-const char* CustomProtocolManager::supplementName()
-{
-    return &quot;CustomProtocolManager&quot;;
-}
</del><span class="cx"> 
</span><del>-CustomProtocolManager::CustomProtocolManager(ChildProcess* childProcess)
-    : m_childProcess(childProcess)
-    , m_messageQueue(WorkQueue::create(&quot;com.apple.WebKit.CustomProtocolManager&quot;))
-    , m_impl(std::make_unique&lt;CustomProtocolManagerImpl&gt;(childProcess))
</del><ins>+CustomProtocolManager::WebSoupRequestAsyncData::WebSoupRequestAsyncData(GRefPtr&lt;GTask&gt;&amp;&amp; requestTask, WebKitSoupRequestGeneric* requestGeneric)
+    : task(WTFMove(requestTask))
+    , request(requestGeneric)
+    , cancellable(g_task_get_cancellable(task.get()))
</ins><span class="cx"> {
</span><ins>+    // If the struct contains a null request, it is because the request failed.
+    g_object_add_weak_pointer(G_OBJECT(request), reinterpret_cast&lt;void**&gt;(&amp;request));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CustomProtocolManager::initializeConnection(IPC::Connection* connection)
</del><ins>+CustomProtocolManager::WebSoupRequestAsyncData::~WebSoupRequestAsyncData()
</ins><span class="cx"> {
</span><del>-    connection-&gt;addWorkQueueMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), m_messageQueue.get(), this);
</del><ins>+    if (request)
+        g_object_remove_weak_pointer(G_OBJECT(request), reinterpret_cast&lt;void**&gt;(&amp;request));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CustomProtocolManager::initialize(const NetworkProcessCreationParameters&amp; parameters)
</del><ins>+class CustomProtocolRequestClient final : public WebKitSoupRequestGenericClient {
+public:
+    static CustomProtocolRequestClient&amp; singleton()
+    {
+        static NeverDestroyed&lt;CustomProtocolRequestClient&gt; client;
+        return client;
+    }
+
+private:
+    void startRequest(GRefPtr&lt;GTask&gt;&amp;&amp; task) override
+    {
+        WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(task.get()));
+        auto* customProtocolManager = NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;();
+        if (!customProtocolManager)
+            return;
+
+        auto customProtocolID = customProtocolManager-&gt;addCustomProtocol(std::make_unique&lt;CustomProtocolManager::WebSoupRequestAsyncData&gt;(WTFMove(task), request));
+        customProtocolManager-&gt;startLoading(customProtocolID, webkitSoupRequestGenericGetRequest(request));
+    }
+};
+
+void CustomProtocolManager::registerProtocolClass()
</ins><span class="cx"> {
</span><del>-    for (size_t i = 0; i &lt; parameters.urlSchemesRegisteredForCustomProtocols.size(); ++i)
-        registerScheme(parameters.urlSchemesRegisteredForCustomProtocols[i]);
</del><ins>+    static_cast&lt;WebKitSoupRequestGenericClass*&gt;(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC))-&gt;client = &amp;CustomProtocolRequestClient::singleton();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CustomProtocolManager::registerScheme(const String&amp; scheme)
</span><span class="cx"> {
</span><del>-    m_impl-&gt;registerScheme(scheme);
</del><ins>+    if (!m_registeredSchemes)
+        m_registeredSchemes = adoptGRef(g_ptr_array_new_with_free_func(g_free));
+
+    if (m_registeredSchemes-&gt;len)
+        g_ptr_array_remove_index_fast(m_registeredSchemes.get(), m_registeredSchemes-&gt;len - 1);
+    g_ptr_array_add(m_registeredSchemes.get(), g_strdup(scheme.utf8().data()));
+    g_ptr_array_add(m_registeredSchemes.get(), nullptr);
+
+    auto* genericRequestClass = static_cast&lt;SoupRequestClass*&gt;(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
+    genericRequestClass-&gt;schemes = const_cast&lt;const char**&gt;(reinterpret_cast&lt;char**&gt;(m_registeredSchemes-&gt;pdata));
+    soup_session_add_feature_by_type(SoupNetworkSession::defaultSession().soupSession(), WEBKIT_TYPE_SOUP_REQUEST_GENERIC);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CustomProtocolManager::unregisterScheme(const String&amp;)
</span><span class="lines">@@ -64,30 +100,102 @@
</span><span class="cx"> 
</span><span class="cx"> bool CustomProtocolManager::supportsScheme(const String&amp; scheme)
</span><span class="cx"> {
</span><del>-    return m_impl-&gt;supportsScheme(scheme);
</del><ins>+    if (scheme.isNull())
+        return false;
+
+    CString cScheme = scheme.utf8();
+    for (unsigned i = 0; i &lt; m_registeredSchemes-&gt;len; ++i) {
+        if (cScheme == static_cast&lt;char*&gt;(g_ptr_array_index(m_registeredSchemes.get(), i)))
+            return true;
+    }
+
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CustomProtocolManager::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&amp; error)
</del><ins>+void CustomProtocolManager::didFailWithError(uint64_t customProtocolID, const ResourceError&amp; error)
</ins><span class="cx"> {
</span><del>-    m_impl-&gt;didFailWithError(customProtocolID, error);
</del><ins>+    auto* data = m_customProtocolMap.get(customProtocolID);
+    ASSERT(data);
+
+    // Either we haven't started reading the stream yet, in which case we need to complete the
+    // task first, or we failed reading it and the task was already completed by didLoadData().
+    ASSERT(!data-&gt;stream || !data-&gt;task);
+
+    if (!data-&gt;stream) {
+        GRefPtr&lt;GTask&gt; task = std::exchange(data-&gt;task, nullptr);
+        ASSERT(task.get());
+        g_task_return_new_error(task.get(), g_quark_from_string(error.domain().utf8().data()),
+            error.errorCode(), &quot;%s&quot;, error.localizedDescription().utf8().data());
+    } else
+        webkitSoupRequestInputStreamDidFailWithError(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get()), error);
+
+    removeCustomProtocol(customProtocolID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CustomProtocolManager::didLoadData(uint64_t customProtocolID, const IPC::DataReference&amp; dataReference)
</span><span class="cx"> {
</span><del>-    m_impl-&gt;didLoadData(customProtocolID, dataReference);
</del><ins>+    auto* data = m_customProtocolMap.get(customProtocolID);
+    // The data might have been removed from the request map if a previous chunk failed
+    // and a new message was sent by the UI process before being notified about the failure.
+    if (!data)
+        return;
+
+    if (!data-&gt;stream) {
+        GRefPtr&lt;GTask&gt; task = std::exchange(data-&gt;task, nullptr);
+        ASSERT(task.get());
+
+        goffset soupContentLength = soup_request_get_content_length(SOUP_REQUEST(g_task_get_source_object(task.get())));
+        uint64_t contentLength = soupContentLength == -1 ? 0 : static_cast&lt;uint64_t&gt;(soupContentLength);
+        if (!dataReference.size()) {
+            // Empty reply, just create and empty GMemoryInputStream.
+            data-&gt;stream = g_memory_input_stream_new();
+        } else if (dataReference.size() == contentLength) {
+            // We don't expect more data, so we can just create a GMemoryInputStream with all the data.
+            data-&gt;stream = g_memory_input_stream_new_from_data(g_memdup(dataReference.data(), dataReference.size()), contentLength, g_free);
+        } else {
+            // We expect more data chunks from the UI process.
+            data-&gt;stream = webkitSoupRequestInputStreamNew(contentLength);
+            webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get()), dataReference.data(), dataReference.size());
+        }
+        g_task_return_pointer(task.get(), data-&gt;stream.get(), g_object_unref);
+        return;
+    }
+
+    if (g_cancellable_is_cancelled(data-&gt;cancellable.get()) || !data-&gt;request) {
+        // ResourceRequest failed or it was cancelled. It doesn't matter here the error or if it was cancelled,
+        // because that's already handled by the resource handle client, we just want to notify the UI process
+        // to stop reading data from the user input stream. If UI process already sent all the data we simply
+        // finish silently.
+        if (!webkitSoupRequestInputStreamFinished(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get())))
+            stopLoading(customProtocolID);
+
+        return;
+    }
+
+    webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data-&gt;stream.get()), dataReference.data(), dataReference.size());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CustomProtocolManager::didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&amp; response, uint32_t)
</del><ins>+void CustomProtocolManager::didReceiveResponse(uint64_t customProtocolID, const ResourceResponse&amp; response, uint32_t)
</ins><span class="cx"> {
</span><del>-    m_impl-&gt;didReceiveResponse(customProtocolID, response);
</del><ins>+    auto* data = m_customProtocolMap.get(customProtocolID);
+    // The data might have been removed from the request map if an error happened even before this point.
+    if (!data)
+        return;
+
+    ASSERT(data-&gt;task);
+
+    WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(data-&gt;task.get()));
+    webkitSoupRequestGenericSetContentLength(request, response.expectedContentLength() ? response.expectedContentLength() : -1);
+    webkitSoupRequestGenericSetContentType(request, !response.mimeType().isEmpty() ? response.mimeType().utf8().data() : 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CustomProtocolManager::didFinishLoading(uint64_t customProtocolID)
</span><span class="cx"> {
</span><del>-    m_impl-&gt;didFinishLoading(customProtocolID);
</del><ins>+    ASSERT(m_customProtocolMap.contains(customProtocolID));
+    removeCustomProtocol(customProtocolID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CustomProtocolManager::wasRedirectedToRequest(uint64_t, const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp;)
</del><ins>+void CustomProtocolManager::wasRedirectedToRequest(uint64_t, const ResourceRequest&amp;, const ResourceResponse&amp;)
</ins><span class="cx"> {
</span><span class="cx">     notImplemented();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscocoaNetworkSessionCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -320,10 +320,10 @@
</span><span class="cx">     return [NSURLSessionConfiguration defaultSessionConfiguration];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static RefPtr&lt;CustomProtocolManager&gt;&amp; globalCustomProtocolManager()
</del><ins>+static CustomProtocolManager*&amp; globalCustomProtocolManager()
</ins><span class="cx"> {
</span><del>-    static NeverDestroyed&lt;RefPtr&lt;CustomProtocolManager&gt;&gt; customProtocolManager;
-    return customProtocolManager.get();
</del><ins>+    static CustomProtocolManager* customProtocolManager { nullptr };
+    return customProtocolManager;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static RetainPtr&lt;CFDataRef&gt;&amp; globalSourceApplicationAuditTokenData()
</span><span class="lines">@@ -396,7 +396,7 @@
</span><span class="cx"> NetworkSession&amp; NetworkSessionCocoa::defaultSession()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><del>-    static NetworkSession* session = &amp;NetworkSessionCocoa::create(WebCore::SessionID::defaultSessionID(), globalCustomProtocolManager().get()).leakRef();
</del><ins>+    static NetworkSession* session = &amp;NetworkSessionCocoa::create(WebCore::SessionID::defaultSessionID(), globalCustomProtocolManager()).leakRef();
</ins><span class="cx">     return *session;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformEflcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PlatformEfl.cmake (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PlatformEfl.cmake        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/PlatformEfl.cmake        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -1,7 +1,6 @@
</span><span class="cx"> list(APPEND WebKit2_SOURCES
</span><span class="cx">     DatabaseProcess/efl/DatabaseProcessMainEfl.cpp
</span><span class="cx"> 
</span><del>-    NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp
</del><span class="cx">     NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp
</span><span class="cx"> 
</span><span class="cx">     NetworkProcess/Downloads/efl/DownloadSoupErrorsEfl.cpp
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PlatformGTK.cmake (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PlatformGTK.cmake        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/PlatformGTK.cmake        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -28,7 +28,6 @@
</span><span class="cx"> list(APPEND WebKit2_SOURCES
</span><span class="cx">     DatabaseProcess/gtk/DatabaseProcessMainGtk.cpp
</span><span class="cx"> 
</span><del>-    NetworkProcess/CustomProtocols/soup/CustomProtocolManagerImpl.cpp
</del><span class="cx">     NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp
</span><span class="cx"> 
</span><span class="cx">     NetworkProcess/Downloads/gtk/DownloadSoupErrorsGtk.cpp
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (210373 => 210374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2017-01-05 21:03:12 UTC (rev 210373)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2017-01-05 21:27:50 UTC (rev 210374)
</span><span class="lines">@@ -1108,6 +1108,7 @@
</span><span class="cx">                 5CBC9B8D1C65279C00A8FDCF /* NetworkDataTaskCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */; };
</span><span class="cx">                 5CBC9B8E1C652CA000A8FDCF /* NetworkDataTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */; };
</span><span class="cx">                 5CE85B201C88E64B0070BFCE /* PingLoad.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CE85B1F1C88E6430070BFCE /* PingLoad.h */; };
</span><ins>+                5CFECB041E1ED1CC00F88504 /* CustomProtocolManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CFECB031E1ED1C800F88504 /* CustomProtocolManager.cpp */; };
</ins><span class="cx">                 6501BD1A12F1243400E9F248 /* WKBundleInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */; };
</span><span class="cx">                 659C551E130006410025C0C2 /* InjectedBundlePageResourceLoadClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */; };
</span><span class="cx">                 65B86F1E12F11DE300B7DD8A /* WKBundleInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 65B86F1812F11D7B00B7DD8A /* WKBundleInspector.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -3245,6 +3246,7 @@
</span><span class="cx">                 5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTask.h; path = NetworkProcess/NetworkDataTask.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkDataTaskCocoa.mm; path = NetworkProcess/cocoa/NetworkDataTaskCocoa.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5CE85B1F1C88E6430070BFCE /* PingLoad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PingLoad.h; path = NetworkProcess/PingLoad.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                5CFECB031E1ED1C800F88504 /* CustomProtocolManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomProtocolManager.cpp; path = NetworkProcess/CustomProtocols/CustomProtocolManager.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 5D442A5516D5856700AC3331 /* PluginService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PluginService.entitlements; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5DAD73F1116FF90C00EE5396 /* BaseTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = BaseTarget.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageResourceLoadClient.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -5921,6 +5923,7 @@
</span><span class="cx">                 5C1426F21C23F82D00D41183 /* CustomProtocols */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                5CFECB031E1ED1C800F88504 /* CustomProtocolManager.cpp */,
</ins><span class="cx">                                 5C14271A1C23F8BF00D41183 /* Cocoa */,
</span><span class="cx">                                 5C1427141C23F8B000D41183 /* CustomProtocolManager.h */,
</span><span class="cx">                                 5C1427151C23F8B000D41183 /* CustomProtocolManager.messages.in */,
</span><span class="lines">@@ -9490,6 +9493,7 @@
</span><span class="cx">                                 1A043977124D034800FFBFB5 /* PluginProcess.cpp in Sources */,
</span><span class="cx">                                 1A0EC907124C0AB8007EF4A5 /* PluginProcessConnection.cpp in Sources */,
</span><span class="cx">                                 1A0EC910124C0AF5007EF4A5 /* PluginProcessConnectionManager.cpp in Sources */,
</span><ins>+                                5CFECB041E1ED1CC00F88504 /* CustomProtocolManager.cpp in Sources */,
</ins><span class="cx">                                 1A7865B916CAC71500ACE83A /* PluginProcessConnectionManagerMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 1A2BB6D014117B4D000F35D4 /* PluginProcessConnectionMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 1A2D90D31281C966001EB962 /* PluginProcessCreationParameters.cpp in Sources */,
</span></span></pre>
</div>
</div>

</body>
</html>