<!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>[196384] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/196384">196384</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2016-02-10 12:56:11 -0800 (Wed, 10 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix assertions when loading from WebProcess
https://bugs.webkit.org/show_bug.cgi?id=154079

Reviewed by Anders Carlsson.

Assertions were failing, mostly when using NetworkProcess, and mostly involving Top Sites.
When we do loading from the WebProcess (which we should eventually not allow), we were sometimes
using a private browsing session that did not exist because the UIProcess had told the NetworkProcess
to create a private browsing session with the given SessionID, but the WebProcess was not told about
the private browsing session.
Also, sometimes we were calling NetworkProcess::singleton() from the WebProcess, which caused problems
with the PlatformStrategies object being reset.  This prevents that, too.

* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::NetworkLoad):
Added an assertion that we have a network session when we have just made a NetworkingContext with the given SessionID.
* NetworkProcess/NetworkSession.h:
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::NetworkSession::defaultSession):
(WebKit::NetworkSession::NetworkSession):
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession):
Call NetworkProcess::singleton only when we know we are in the network process.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
* WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
Tell the WebProcesses about the new private session, too.  Sometimes they use the new private session.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::ensurePrivateBrowsingSession):
(WebKit::WebProcess::destroyPrivateBrowsingSession):
Removed useless macros that were always true for all WK2 clients.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkLoadcpp">trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkSessionh">trunk/Source/WebKit2/NetworkProcess/NetworkSession.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscocoaNetworkSessionCocoamm">trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessmacRemoteNetworkingContextmm">trunk/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportmacWebFrameNetworkingContextmm">trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/ChangeLog        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2016-02-10  Alex Christensen  &lt;achristensen@webkit.org&gt;
+
+        Fix assertions when loading from WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=154079
+
+        Reviewed by Anders Carlsson.
+
+        Assertions were failing, mostly when using NetworkProcess, and mostly involving Top Sites.
+        When we do loading from the WebProcess (which we should eventually not allow), we were sometimes
+        using a private browsing session that did not exist because the UIProcess had told the NetworkProcess
+        to create a private browsing session with the given SessionID, but the WebProcess was not told about
+        the private browsing session.
+        Also, sometimes we were calling NetworkProcess::singleton() from the WebProcess, which caused problems
+        with the PlatformStrategies object being reset.  This prevents that, too.
+
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::NetworkLoad):
+        Added an assertion that we have a network session when we have just made a NetworkingContext with the given SessionID.
+        * NetworkProcess/NetworkSession.h:
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::NetworkSession::defaultSession):
+        (WebKit::NetworkSession::NetworkSession):
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession):
+        Call NetworkProcess::singleton only when we know we are in the network process.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        * WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        Tell the WebProcesses about the new private session, too.  Sometimes they use the new private session.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::ensurePrivateBrowsingSession):
+        (WebKit::WebProcess::destroyPrivateBrowsingSession):
+        Removed useless macros that were always true for all WK2 clients.
+
</ins><span class="cx"> 2016-02-10  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] Stop installing the legacy processes
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkLoadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">     } else
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><span class="cx"> #else
</span><ins>+    ASSERT(SessionTracker::storageSession(parameters.sessionID));
</ins><span class="cx">     m_handle = ResourceHandle::create(m_networkingContext.get(), parameters.request, this, parameters.defersLoading, parameters.contentSniffingPolicy == SniffContent);
</span><span class="cx"> #endif
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkSession.h (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkSession.h        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkSession.h        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -41,6 +41,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+class CustomProtocolManager;
+
</ins><span class="cx"> class NetworkSession {
</span><span class="cx">     friend class NetworkDataTask;
</span><span class="cx"> public:
</span><span class="lines">@@ -48,7 +50,7 @@
</span><span class="cx">         Normal,
</span><span class="cx">         Ephemeral
</span><span class="cx">     };
</span><del>-    NetworkSession(Type, WebCore::SessionID);
</del><ins>+    NetworkSession(Type, WebCore::SessionID, CustomProtocolManager*);
</ins><span class="cx">     ~NetworkSession();
</span><span class="cx"> 
</span><span class="cx">     static NetworkSession&amp; defaultSession();
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscocoaNetworkSessionCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -210,17 +210,17 @@
</span><span class="cx"> NetworkSession&amp; NetworkSession::defaultSession()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><del>-    static NeverDestroyed&lt;NetworkSession&gt; session(NetworkSession::Type::Normal, WebCore::SessionID::defaultSessionID());
</del><ins>+    static NeverDestroyed&lt;NetworkSession&gt; session(NetworkSession::Type::Normal, WebCore::SessionID::defaultSessionID(), NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;());
</ins><span class="cx">     return session;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-NetworkSession::NetworkSession(Type type, WebCore::SessionID sessionID)
</del><ins>+NetworkSession::NetworkSession(Type type, WebCore::SessionID sessionID, CustomProtocolManager* customProtocolManager)
</ins><span class="cx"> {
</span><span class="cx">     m_sessionDelegate = adoptNS([[WKNetworkSessionDelegate alloc] initWithNetworkSession:*this]);
</span><span class="cx"> 
</span><span class="cx">     NSURLSessionConfiguration *configuration = configurationForType(type);
</span><span class="cx"> 
</span><del>-    if (auto* customProtocolManager = NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;())
</del><ins>+    if (customProtocolManager)
</ins><span class="cx">         customProtocolManager-&gt;registerProtocolClass(configuration);
</span><span class="cx">     
</span><span class="cx"> #if HAVE(TIMINGDATAOPTIONS)
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessmacRemoteNetworkingContextmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #import &quot;config.h&quot;
</span><span class="cx"> #import &quot;RemoteNetworkingContext.h&quot;
</span><span class="cx"> 
</span><ins>+#import &quot;CustomProtocolManager.h&quot;
</ins><span class="cx"> #import &quot;NetworkProcess.h&quot;
</span><span class="cx"> #import &quot;NetworkSession.h&quot;
</span><span class="cx"> #import &quot;SessionTracker.h&quot;
</span><span class="lines">@@ -101,7 +102,7 @@
</span><span class="cx"> 
</span><span class="cx">     SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(base + '.' + String::number(sessionID.sessionID()))
</span><span class="cx"> #if USE(NETWORK_SESSION)
</span><del>-        , std::make_unique&lt;NetworkSession&gt;(NetworkSession::Type::Ephemeral, sessionID)
</del><ins>+        , std::make_unique&lt;NetworkSession&gt;(NetworkSession::Type::Ephemeral, sessionID, NetworkProcess::singleton().supplement&lt;CustomProtocolManager&gt;())
</ins><span class="cx"> #endif
</span><span class="cx">     );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -481,8 +481,10 @@
</span><span class="cx"> 
</span><span class="cx">     m_process-&gt;addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this);
</span><span class="cx"> 
</span><del>-    if (m_sessionID.isEphemeral())
</del><ins>+    if (m_sessionID.isEphemeral()) {
</ins><span class="cx">         m_process-&gt;processPool().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(m_sessionID));
</span><ins>+        m_process-&gt;processPool().sendToAllProcesses(Messages::WebProcess::EnsurePrivateBrowsingSession(m_sessionID));
+    }
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     const CFIndex viewStateChangeRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit - 1;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportmacWebFrameNetworkingContextmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -60,7 +60,7 @@
</span><span class="cx"> 
</span><span class="cx">     SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(base + '.' + String::number(sessionID.sessionID()))
</span><span class="cx"> #if USE(NETWORK_SESSION)
</span><del>-        , std::make_unique&lt;NetworkSession&gt;(NetworkSession::Type::Ephemeral, sessionID)
</del><ins>+        , std::make_unique&lt;NetworkSession&gt;(NetworkSession::Type::Ephemeral, sessionID, nullptr)
</ins><span class="cx"> #endif
</span><span class="cx">     );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (196383 => 196384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2016-02-10 20:47:04 UTC (rev 196383)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2016-02-10 20:56:11 UTC (rev 196384)
</span><span class="lines">@@ -468,16 +468,12 @@
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::ensurePrivateBrowsingSession(SessionID sessionID)
</span><span class="cx"> {
</span><del>-#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(SOUP)
</del><span class="cx">     WebFrameNetworkingContext::ensurePrivateBrowsingSession(sessionID);
</span><del>-#endif
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::destroyPrivateBrowsingSession(SessionID sessionID)
</span><span class="cx"> {
</span><del>-#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(SOUP)
</del><span class="cx">     SessionTracker::destroySession(sessionID);
</span><del>-#endif
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETSCAPE_PLUGIN_API)
</span></span></pre>
</div>
</div>

</body>
</html>