Create a NetworkSession for each SessionID
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 00:50:27 +0000 (00:50 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 00:50:27 +0000 (00:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150857

Reviewed by Anders Carlsson.

This patch renames SessionTracker::session to storageSession and makes a parallel
structure for NetworkSessions.  NetworkSession and NetworkStorageSession should eventually
become the same class in WebCore.  Because not everybody uses NetworkSessions yet,
we keep them separate but created, destroyed, and managed together.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::storageSession):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::startNetworkLoad):
(WebKit::NetworkResourceLoader::abort):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/NetworkSession.h:
(WebKit::NetworkSessionTaskClient::~NetworkSessionTaskClient):
(WebKit::NetworkDataTask::client):
(WebKit::NetworkDataTask::clearClient):
(WebKit::NetworkingDataTask::client): Deleted.
(WebKit::NetworkingDataTask::clearClient): Deleted.
(WebKit::NetworkSession::~NetworkSession): Deleted.
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::configurationForType):
(WebKit::defaultNetworkSession):
(WebKit::NetworkSession::defaultSession):
(WebKit::NetworkSession::NetworkSession):
(WebKit::NetworkSession::~NetworkSession):
(WebKit::NetworkSession::createDataTaskWithRequest):
(WebKit::NetworkSession::dataTaskForIdentifier):
(WebKit::NetworkDataTask::NetworkDataTask):
(WebKit::NetworkDataTask::~NetworkDataTask):
(WebKit::NetworkDataTask::cancel):
(WebKit::NetworkDataTask::resume):
(WebKit::NetworkDataTask::taskIdentifier):
(WebKit::NetworkSession::create): Deleted.
(WebKit::NetworkSession::singleton): Deleted.
(WebKit::NetworkingDataTask::NetworkingDataTask): Deleted.
(WebKit::NetworkingDataTask::~NetworkingDataTask): Deleted.
(WebKit::NetworkingDataTask::suspend): Deleted.
(WebKit::NetworkingDataTask::resume): Deleted.
(WebKit::NetworkingDataTask::taskIdentifier): Deleted.
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::storageSession):
(WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession):
* Shared/SessionTracker.cpp:
(WebKit::staticStorageSessionMap):
(WebKit::identifierBase):
(WebKit::SessionTracker::storageSessionMap):
(WebKit::SessionTracker::getIdentifierBase):
(WebKit::SessionTracker::storageSession):
(WebKit::staticSessionMap):
(WebKit::SessionTracker::networkSession):
(WebKit::SessionTracker::sessionID):
(WebKit::SessionTracker::setSession):
(WebKit::SessionTracker::destroySession):
(WebKit::SessionTracker::sessionMap): Deleted.
(WebKit::SessionTracker::session): Deleted.
* Shared/SessionTracker.h:
* WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
(WebKit::WebFrameNetworkingContext::storageSession):
* WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
(WebKit::WebFrameNetworkingContext::storageSession):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191998 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit2/NetworkProcess/NetworkProcess.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h
Source/WebKit2/NetworkProcess/NetworkSession.h
Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit2/Shared/SessionTracker.cpp
Source/WebKit2/Shared/SessionTracker.h
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm
Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp

index 927f8df79053f5578de6ccb4fdd1893e4af89ba2..49d69e18c2e7118aa1ded4e1fcbbcd5142b96a48 100644 (file)
@@ -1,3 +1,78 @@
+2015-11-03  Alex Christensen  <achristensen@webkit.org>
+
+        Create a NetworkSession for each SessionID
+        https://bugs.webkit.org/show_bug.cgi?id=150857
+
+        Reviewed by Anders Carlsson.
+
+        This patch renames SessionTracker::session to storageSession and makes a parallel
+        structure for NetworkSessions.  NetworkSession and NetworkStorageSession should eventually
+        become the same class in WebCore.  Because not everybody uses NetworkSessions yet,
+        we keep them separate but created, destroyed, and managed together.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::storageSession):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::fetchWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::startNetworkLoad):
+        (WebKit::NetworkResourceLoader::abort):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/NetworkSession.h:
+        (WebKit::NetworkSessionTaskClient::~NetworkSessionTaskClient):
+        (WebKit::NetworkDataTask::client):
+        (WebKit::NetworkDataTask::clearClient):
+        (WebKit::NetworkingDataTask::client): Deleted.
+        (WebKit::NetworkingDataTask::clearClient): Deleted.
+        (WebKit::NetworkSession::~NetworkSession): Deleted.
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::configurationForType):
+        (WebKit::defaultNetworkSession):
+        (WebKit::NetworkSession::defaultSession):
+        (WebKit::NetworkSession::NetworkSession):
+        (WebKit::NetworkSession::~NetworkSession):
+        (WebKit::NetworkSession::createDataTaskWithRequest):
+        (WebKit::NetworkSession::dataTaskForIdentifier):
+        (WebKit::NetworkDataTask::NetworkDataTask):
+        (WebKit::NetworkDataTask::~NetworkDataTask):
+        (WebKit::NetworkDataTask::cancel):
+        (WebKit::NetworkDataTask::resume):
+        (WebKit::NetworkDataTask::taskIdentifier):
+        (WebKit::NetworkSession::create): Deleted.
+        (WebKit::NetworkSession::singleton): Deleted.
+        (WebKit::NetworkingDataTask::NetworkingDataTask): Deleted.
+        (WebKit::NetworkingDataTask::~NetworkingDataTask): Deleted.
+        (WebKit::NetworkingDataTask::suspend): Deleted.
+        (WebKit::NetworkingDataTask::resume): Deleted.
+        (WebKit::NetworkingDataTask::taskIdentifier): Deleted.
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::storageSession):
+        (WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession):
+        * Shared/SessionTracker.cpp:
+        (WebKit::staticStorageSessionMap):
+        (WebKit::identifierBase):
+        (WebKit::SessionTracker::storageSessionMap):
+        (WebKit::SessionTracker::getIdentifierBase):
+        (WebKit::SessionTracker::storageSession):
+        (WebKit::staticSessionMap):
+        (WebKit::SessionTracker::networkSession):
+        (WebKit::SessionTracker::sessionID):
+        (WebKit::SessionTracker::setSession):
+        (WebKit::SessionTracker::destroySession):
+        (WebKit::SessionTracker::sessionMap): Deleted.
+        (WebKit::SessionTracker::session): Deleted.
+        * Shared/SessionTracker.h:
+        * WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
+        (WebKit::WebFrameNetworkingContext::storageSession):
+        * WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
+        (WebKit::WebFrameNetworkingContext::storageSession):
+
 2015-11-03  Ryuan Choi  <ryuan.choi@navercorp.com>
 
         [CoordinatedGraphics] invisible webview should not paint the content
index 455f8d93a6cf7c5d9f3b9674728e4a69336f841a..0a23b7f04ad1bb3f1f5cc0e2508eaa94174a9b47 100644 (file)
@@ -168,9 +168,9 @@ void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname)
 static NetworkStorageSession& storageSession(SessionID sessionID)
 {
     if (sessionID.isEphemeral()) {
-        NetworkStorageSession* privateSession = SessionTracker::session(sessionID);
-        if (privateSession)
-            return *privateSession;
+        NetworkStorageSession* privateStorageSession = SessionTracker::storageSession(sessionID);
+        if (privateStorageSession)
+            return *privateStorageSession;
         // Some requests with private browsing mode requested may still be coming shortly after NetworkProcess was told to destroy its session.
         // FIXME: Find a way to track private browsing sessions more rigorously.
         LOG_ERROR("Private browsing was requested, but there was no session for it. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
index 321b927ffed0bdf631b6d9ce382b7866e53d30b9..d1d1fa8ea30b308157290eb1ef4ff62d07848da4 100644 (file)
@@ -337,7 +337,7 @@ void NetworkProcess::fetchWebsiteData(SessionID sessionID, uint64_t websiteDataT
     }));
 
     if (websiteDataTypes & WebsiteDataTypeCookies) {
-        if (auto* networkStorageSession = SessionTracker::session(sessionID))
+        if (auto* networkStorageSession = SessionTracker::storageSession(sessionID))
             getHostnamesWithCookies(*networkStorageSession, callbackAggregator->m_websiteData.hostNamesWithCookies);
     }
 
@@ -352,13 +352,13 @@ void NetworkProcess::deleteWebsiteData(SessionID sessionID, uint64_t websiteData
 {
 #if PLATFORM(COCOA)
     if (websiteDataTypes & WebsiteDataTypeHSTSCache) {
-        if (auto* networkStorageSession = SessionTracker::session(sessionID))
+        if (auto* networkStorageSession = SessionTracker::storageSession(sessionID))
             clearHSTSCache(*networkStorageSession, modifiedSince);
     }
 #endif
 
     if (websiteDataTypes & WebsiteDataTypeCookies) {
-        if (auto* networkStorageSession = SessionTracker::session(sessionID))
+        if (auto* networkStorageSession = SessionTracker::storageSession(sessionID))
             deleteAllCookiesModifiedSince(*networkStorageSession, modifiedSince);
     }
 
@@ -418,7 +418,7 @@ static void clearDiskCacheEntries(const Vector<SecurityOriginData>& origins, std
 void NetworkProcess::deleteWebsiteDataForOrigins(SessionID sessionID, uint64_t websiteDataTypes, const Vector<SecurityOriginData>& origins, const Vector<String>& cookieHostNames, uint64_t callbackID)
 {
     if (websiteDataTypes & WebsiteDataTypeCookies) {
-        if (auto* networkStorageSession = SessionTracker::session(sessionID))
+        if (auto* networkStorageSession = SessionTracker::storageSession(sessionID))
             deleteCookiesForHostnames(*networkStorageSession, cookieHostNames);
     }
 
index 776d7ccd2bd73f0ce33050c720e354279a6b155a..0846a5047cd0b5c281d9c56741dfda49a7a5f779 100644 (file)
@@ -38,6 +38,7 @@
 #include "NetworkProcessConnectionMessages.h"
 #include "NetworkResourceLoadParameters.h"
 #include "RemoteNetworkingContext.h"
+#include "SessionTracker.h"
 #include "ShareableResource.h"
 #include "SharedMemory.h"
 #include "WebCoreArgumentCoders.h"
@@ -189,7 +190,7 @@ void NetworkResourceLoader::startNetworkLoad()
     bool shouldSniff = m_parameters.contentSniffingPolicy == SniffContent;
 #if USE(NETWORK_SESSION)
     UNUSED_PARAM(shouldSniff); // FIXME: Use this.
-    m_task = NetworkSession::singleton()->createDataTaskWithRequest(m_currentRequest, *this);
+    m_task = SessionTracker::networkSession(sessionID())->createDataTaskWithRequest(m_currentRequest, *this);
     m_task->resume();
 #else
     m_handle = ResourceHandle::create(m_networkingContext.get(), m_currentRequest, this, m_defersLoading, shouldSniff);
@@ -252,7 +253,7 @@ void NetworkResourceLoader::abort()
 
 #if USE(NETWORK_SESSION)
     if (m_task)
-        m_task->suspend();
+        m_task->cancel();
     // FIXME: Do something with the network cache here.
     notImplemented();
 #else
index 44ab90bb50dd054d87704010e2075c130f201318..8b423dc84f23d7889a7e680cb22681de5e9748a1 100644 (file)
@@ -213,7 +213,7 @@ private:
 
     RefPtr<RemoteNetworkingContext> m_networkingContext;
 #if USE(NETWORK_SESSION)
-    RefPtr<NetworkingDataTask> m_task;
+    RefPtr<NetworkDataTask> m_task;
 #else
     RefPtr<WebCore::ResourceHandle> m_handle;
 #endif
index 742a616a3f51b678c0addf055a2b3601d903bc8b..9723ff4d4f96dd8596a023d6dfa89227a689cb01 100644 (file)
@@ -31,6 +31,7 @@ OBJC_CLASS NSURLSessionDataTask;
 OBJC_CLASS NSOperationQueue;
 OBJC_CLASS NetworkSessionDelegate;
 
+#include <WebCore/SessionID.h>
 #include <wtf/HashMap.h>
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
@@ -74,48 +75,53 @@ public:
     virtual ~NetworkSessionTaskClient() { }
 };
 
-class NetworkingDataTask : public RefCounted<NetworkingDataTask> {
+class NetworkDataTask : public RefCounted<NetworkDataTask> {
     friend class NetworkSession;
 public:
-    void suspend();
+    void cancel();
     void resume();
 
     uint64_t taskIdentifier();
 
-    ~NetworkingDataTask();
+    ~NetworkDataTask();
 
     NetworkSessionTaskClient* client() { return m_client; }
     void clearClient() { m_client = nullptr; }
 
 private:
-    explicit NetworkingDataTask(NetworkSession&, NetworkSessionTaskClient&, RetainPtr<NSURLSessionDataTask>);
-
     NetworkSession& m_session;
-    RetainPtr<NSURLSessionDataTask> m_task;
     NetworkSessionTaskClient* m_client;
+#if PLATFORM(COCOA)
+    explicit NetworkDataTask(NetworkSession&, NetworkSessionTaskClient&, RetainPtr<NSURLSessionDataTask>&&);
+    RetainPtr<NSURLSessionDataTask> m_task;
+#else
+    explicit NetworkDataTask(NetworkSession&, NetworkSessionTaskClient&);
+#endif
 };
 
-class NetworkSession : public RefCounted<NetworkSession> {
-    friend class NetworkingDataTask;
+class NetworkSession {
+    friend class NetworkDataTask;
 public:
     enum class Type {
         Normal,
         Ephemeral
     };
+    NetworkSession(Type, WebCore::SessionID);
+    ~NetworkSession() { ASSERT(m_dataTaskMap.isEmpty()); }
 
-    Ref<NetworkingDataTask> createDataTaskWithRequest(const WebCore::ResourceRequest&, NetworkSessionTaskClient&);
+    static NetworkSession& defaultSession();
+    
+    Ref<NetworkDataTask> createDataTaskWithRequest(const WebCore::ResourceRequest&, NetworkSessionTaskClient&);
 
-    static Ref<NetworkSession> singleton(); // FIXME: This shouldn't actually be a singleton.
-    NetworkingDataTask* dataTaskForIdentifier(uint64_t);
+    NetworkDataTask* dataTaskForIdentifier(uint64_t);
 
-    ~NetworkSession() { ASSERT(m_dataTaskMap.isEmpty()); }
 private:
-    static Ref<NetworkSession> create(Type);
-
-    NetworkSession(Type);
-    HashMap<uint64_t, NetworkingDataTask*> m_dataTaskMap;
+    WebCore::SessionID m_sessionID;
+    HashMap<uint64_t, NetworkDataTask*> m_dataTaskMap;
+#if PLATFORM(COCOA)
     RetainPtr<NSURLSession> m_session;
     RetainPtr<NetworkSessionDelegate> m_sessionDelegate;
+#endif
 };
 
 } // namespace WebKit
index 73371b1b8f8b16fc975b6f7e8edd57d38628e64a..5a02250ea4305937982cadef606125f61bc28c08 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebCore/AuthenticationChallenge.h>
 #import <WebCore/CFNetworkSPI.h>
 #import <WebCore/Credential.h>
+#import <WebCore/NetworkStorageSession.h>
 #import <WebCore/ResourceError.h>
 #import <WebCore/ResourceRequest.h>
 #import <WebCore/ResourceResponse.h>
@@ -158,17 +159,6 @@ static NSURLSessionAuthChallengeDisposition toNSURLSessionAuthChallengeDispositi
 
 namespace WebKit {
     
-Ref<NetworkSession> NetworkSession::create(Type type)
-{
-    return adoptRef(*new NetworkSession(type));
-}
-
-Ref<NetworkSession> NetworkSession::singleton()
-{
-    static NeverDestroyed<Ref<NetworkSession>> sharedInstance(NetworkSession::create(Type::Normal));
-    return sharedInstance.get().copyRef();
-}
-    
 static NSURLSessionConfiguration *configurationForType(NetworkSession::Type type)
 {
     switch (type) {
@@ -179,41 +169,48 @@ static NSURLSessionConfiguration *configurationForType(NetworkSession::Type type
     }
 }
 
-NetworkSession::NetworkSession(Type type)
+NetworkSession& NetworkSession::defaultSession()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<NetworkSession> session(NetworkSession::Type::Normal, WebCore::SessionID::defaultSessionID());
+    return session;
+}
+
+NetworkSession::NetworkSession(Type type, WebCore::SessionID sessionID)
+    : m_sessionID(sessionID)
 {
     m_sessionDelegate = adoptNS([[NetworkSessionDelegate alloc] initWithNetworkSession:*this]);
 
     NSURLSessionConfiguration *configuration = configurationForType(type);
-    // FIXME: Use SessionTracker to make sure the correct cookie storage is used once there is more than one NetworkSession.
-    if (auto* session = SessionTracker::session(WebCore::SessionID::defaultSessionID())) {
-        if (CFHTTPCookieStorageRef storage = session->cookieStorage().get())
+    if (auto* storageSession = SessionTracker::storageSession(sessionID)) {
+        if (CFHTTPCookieStorageRef storage = storageSession->cookieStorage().get())
             configuration.HTTPCookieStorage = [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage] autorelease];
     }
     m_session = [NSURLSession sessionWithConfiguration:configuration delegate:static_cast<id>(m_sessionDelegate.get()) delegateQueue:[NSOperationQueue mainQueue]];
 }
 
-Ref<NetworkingDataTask> NetworkSession::createDataTaskWithRequest(const WebCore::ResourceRequest& request, NetworkSessionTaskClient& client)
+Ref<NetworkDataTask> NetworkSession::createDataTaskWithRequest(const WebCore::ResourceRequest& request, NetworkSessionTaskClient& client)
 {
-    return adoptRef(*new NetworkingDataTask(*this, client, [m_session dataTaskWithRequest:request.nsURLRequest(WebCore::UpdateHTTPBody)]));
+    return adoptRef(*new NetworkDataTask(*this, client, [m_session dataTaskWithRequest:request.nsURLRequest(WebCore::UpdateHTTPBody)]));
 }
 
-NetworkingDataTask* NetworkSession::dataTaskForIdentifier(uint64_t taskIdentifier)
+NetworkDataTask* NetworkSession::dataTaskForIdentifier(uint64_t taskIdentifier)
 {
     ASSERT(isMainThread());
     return m_dataTaskMap.get(taskIdentifier);
 }
 
-NetworkingDataTask::NetworkingDataTask(NetworkSession& session, NetworkSessionTaskClient& client, RetainPtr<NSURLSessionDataTask> task)
+NetworkDataTask::NetworkDataTask(NetworkSession& session, NetworkSessionTaskClient& client, RetainPtr<NSURLSessionDataTask>&& task)
     : m_session(session)
-    , m_task(task)
     , m_client(&client)
+    , m_task(WTF::move(task))
 {
     ASSERT(!m_session.m_dataTaskMap.contains(taskIdentifier()));
     ASSERT(isMainThread());
     m_session.m_dataTaskMap.add(taskIdentifier(), this);
 }
 
-NetworkingDataTask::~NetworkingDataTask()
+NetworkDataTask::~NetworkDataTask()
 {
     ASSERT(m_session.m_dataTaskMap.contains(taskIdentifier()));
     ASSERT(m_session.m_dataTaskMap.get(taskIdentifier()) == this);
@@ -221,17 +218,17 @@ NetworkingDataTask::~NetworkingDataTask()
     m_session.m_dataTaskMap.remove(taskIdentifier());
 }
 
-void NetworkingDataTask::suspend()
+void NetworkDataTask::cancel()
 {
-    [m_task suspend];
+    [m_task cancel];
 }
 
-void NetworkingDataTask::resume()
+void NetworkDataTask::resume()
 {
     [m_task resume];
 }
 
-uint64_t NetworkingDataTask::taskIdentifier()
+uint64_t NetworkDataTask::taskIdentifier()
 {
     return [m_task taskIdentifier];
 }
index b4d41a56c9007a705429c88ff818ee8ca986bbfc..223be3684d5a6643f451975686619e3a5e57db91 100644 (file)
@@ -27,6 +27,7 @@
 #import "RemoteNetworkingContext.h"
 
 #import "NetworkProcess.h"
+#import "NetworkSession.h"
 #import "SessionTracker.h"
 #import "WebErrors.h"
 #import <WebCore/ResourceError.h>
@@ -55,7 +56,7 @@ bool RemoteNetworkingContext::localFileContentSniffingEnabled() const
 
 NetworkStorageSession& RemoteNetworkingContext::storageSession() const
 {
-    NetworkStorageSession* session = SessionTracker::session(m_sessionID);
+    NetworkStorageSession* session = SessionTracker::storageSession(m_sessionID);
     if (session)
         return *session;
     // Some requests may still be coming shortly after NetworkProcess was told to destroy its session.
@@ -89,11 +90,15 @@ void RemoteNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID)
 {
     ASSERT(sessionID.isEphemeral());
 
-    if (SessionTracker::session(sessionID))
+    if (SessionTracker::storageSession(sessionID))
         return;
 
     ASSERT(!SessionTracker::getIdentifierBase().isNull());
-    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(SessionTracker::getIdentifierBase() + '.' + String::number(sessionID.sessionID())));
+    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(SessionTracker::getIdentifierBase() + '.' + String::number(sessionID.sessionID()))
+#if USE(NETWORK_SESSION)
+        , std::make_unique<NetworkSession>(NetworkSession::Type::Ephemeral, sessionID)
+#endif
+    );
 }
 
 }
index ac79a9d5d470e3cac43d29547111db457e855610..d51d0c1cd1441c40ca2270455ddab14fd9995ef4 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "SessionTracker.h"
 
+#include "NetworkSession.h"
+#include <WebCore/NetworkStorageSession.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RunLoop.h>
 
@@ -33,12 +35,12 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>& staticSessionMap()
+static HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>& staticStorageSessionMap()
 {
     ASSERT(RunLoop::isMain());
 
     static NeverDestroyed<HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>> map;
-    return map.get();
+    return map;
 }
 
 static HashMap<const NetworkStorageSession*, SessionID>& storageSessionToID()
@@ -46,7 +48,7 @@ static HashMap<const NetworkStorageSession*, SessionID>& storageSessionToID()
     ASSERT(RunLoop::isMain());
 
     static NeverDestroyed<HashMap<const NetworkStorageSession*, SessionID>> map;
-    return map.get();
+    return map;
 }
 
 static String& identifierBase()
@@ -57,9 +59,9 @@ static String& identifierBase()
     return base;
 }
 
-const HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>& SessionTracker::sessionMap()
+const HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>& SessionTracker::storageSessionMap()
 {
-    return staticSessionMap();
+    return staticStorageSessionMap();
 }
 
 const String& SessionTracker::getIdentifierBase()
@@ -67,12 +69,29 @@ const String& SessionTracker::getIdentifierBase()
     return identifierBase();
 }
 
-NetworkStorageSession* SessionTracker::session(SessionID sessionID)
+NetworkStorageSession* SessionTracker::storageSession(SessionID sessionID)
 {
     if (sessionID == SessionID::defaultSessionID())
         return &NetworkStorageSession::defaultStorageSession();
+    return staticStorageSessionMap().get(sessionID);
+}
+
+#if USE(NETWORK_SESSION)
+static HashMap<SessionID, std::unique_ptr<NetworkSession>>& staticSessionMap()
+{
+    ASSERT(RunLoop::isMain());
+    
+    static NeverDestroyed<HashMap<SessionID, std::unique_ptr<NetworkSession>>> map;
+    return map;
+}
+
+NetworkSession* SessionTracker::networkSession(SessionID sessionID)
+{
+    if (sessionID == SessionID::defaultSessionID())
+        return &NetworkSession::defaultSession();
     return staticSessionMap().get(sessionID);
 }
+#endif
 
 SessionID SessionTracker::sessionID(const NetworkStorageSession& session)
 {
@@ -81,19 +100,32 @@ SessionID SessionTracker::sessionID(const NetworkStorageSession& session)
     return storageSessionToID().get(&session);
 }
 
-void SessionTracker::setSession(SessionID sessionID, std::unique_ptr<NetworkStorageSession> session)
+void SessionTracker::setSession(SessionID sessionID, std::unique_ptr<NetworkStorageSession> storageSession
+#if USE(NETWORK_SESSION)
+    , std::unique_ptr<NetworkSession> session
+#endif
+)
 {
+    ASSERT(storageSession);
     ASSERT(sessionID != SessionID::defaultSessionID());
-    storageSessionToID().set(session.get(), sessionID);
+    storageSessionToID().set(storageSession.get(), sessionID);
+    staticStorageSessionMap().set(sessionID, WTF::move(storageSession));
+#if USE(NETWORK_SESSION)
+    ASSERT(session);
     staticSessionMap().set(sessionID, WTF::move(session));
+#endif
 }
 
 void SessionTracker::destroySession(SessionID sessionID)
 {
     ASSERT(RunLoop::isMain());
-    if (staticSessionMap().contains(sessionID)) {
-        storageSessionToID().remove(session(sessionID));
+    if (staticStorageSessionMap().contains(sessionID)) {
+#if USE(NETWORK_SESSION)
+        ASSERT_WITH_MESSAGE(staticSessionMap().contains(sessionID), "NetworkSessions and NetworkStorageSessions should always be created, deleted, and managed as pairs");
         staticSessionMap().remove(sessionID);
+#endif
+        storageSessionToID().remove(storageSession(sessionID));
+        staticStorageSessionMap().remove(sessionID);
     }
 }
 
index 9e80b2fe0a07f4404f08d2ef01971855c141c264..af4555ef2a2231d8cbd14b04a734935981eae936 100644 (file)
 #ifndef SessionTracker_h
 #define SessionTracker_h
 
-#include <WebCore/NetworkStorageSession.h>
+namespace WebCore {
+class NetworkStorageSession;
+}
+
 #include <WebCore/SessionID.h>
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
-#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebKit {
 
+class NetworkSession;
+
 class SessionTracker {
     WTF_MAKE_NONCOPYABLE(SessionTracker);
 public:
-    // FIXME: sessionMap()'s returned map does not include default session.
-    static const HashMap<WebCore::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>>& sessionMap();
+    // FIXME: storageSessionMap()'s returned map does not include default session.
+    static const HashMap<WebCore::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>>& storageSessionMap();
+
     static const String& getIdentifierBase();
-    static WebCore::NetworkStorageSession* session(WebCore::SessionID);
+    static WebCore::NetworkStorageSession* storageSession(WebCore::SessionID);
     static WebCore::SessionID sessionID(const WebCore::NetworkStorageSession&);
-    static void setSession(WebCore::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>);
+    static void setSession(WebCore::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>
+#if USE(NETWORK_SESSION)
+        , std::unique_ptr<NetworkSession>
+#endif
+    );
     static void destroySession(WebCore::SessionID);
     static void setIdentifierBase(const String&);
+    
+#if USE(NETWORK_SESSION)
+    // FIXME: A NetworkSession and a NetworkStorageSession should be the same object once NETWORK_SESSION is used by default.
+    static NetworkSession* networkSession(WebCore::SessionID);
+#endif
 };
 
 } // namespace WebKit
index 7fe49f552b11db537f32b563cb34a55e592fa7b1..7b1328decc2a3c08b0a38b37e9c3b1c5f6355ced 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WebFrameNetworkingContext.h"
 
+#include "NetworkSession.h"
 #include "SessionTracker.h"
 #include "WebCookieManager.h"
 #include "WebPage.h"
@@ -47,7 +48,7 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID
 {
     ASSERT(sessionID.isEphemeral());
 
-    if (SessionTracker::session(sessionID))
+    if (SessionTracker::storageSession(sessionID))
         return;
 
     String base;
@@ -56,7 +57,11 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID
     else
         base = SessionTracker::getIdentifierBase();
 
-    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(base + '.' + String::number(sessionID.sessionID())));
+    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(base + '.' + String::number(sessionID.sessionID()))
+#if USE(NETWORK_SESSION)
+        , std::make_unique<NetworkSession>(NetworkSession::Type::Ephemeral, sessionID)
+#endif
+    );
 }
 
 void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAcceptPolicy policy)
@@ -66,7 +71,7 @@ void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAc
     if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage())
         WKSetHTTPCookieAcceptPolicy(cookieStorage.get(), policy);
 
-    for (const auto& session : SessionTracker::sessionMap().values()) {
+    for (const auto& session : SessionTracker::storageSessionMap().values()) {
         if (session)
             WKSetHTTPCookieAcceptPolicy(session->cookieStorage().get(), policy);
     }
@@ -110,8 +115,8 @@ NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
 {
     ASSERT(RunLoop::isMain());
     if (frame()) {
-        if (NetworkStorageSession* session = SessionTracker::session(frame()->page()->sessionID()))
-            return *session;
+        if (auto* storageSession = SessionTracker::storageSession(frame()->page()->sessionID()))
+            return *storageSession;
         // Some requests may still be coming shortly after WebProcess was told to destroy its session.
         LOG_ERROR("Invalid session ID. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
     }
index 40f642b0320c1a73569711faeda090855880079d..38a4245af4adce9dd1fb6a82ad8052931f3cc1f0 100644 (file)
@@ -45,7 +45,7 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID
 {
     ASSERT(isMainThread());
 
-    if (SessionTracker::session(sessionID))
+    if (SessionTracker::storageSession(sessionID))
         return;
 
     SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(String::number(sessionID.sessionID())));
@@ -72,7 +72,7 @@ void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAc
     SoupNetworkSession& soupSession = NetworkStorageSession::defaultStorageSession().soupNetworkSession();
     soup_cookie_jar_set_accept_policy(soupSession.cookieJar(), soupPolicy);
 
-    for (const auto& session : SessionTracker::sessionMap().values()) {
+    for (const auto& session : SessionTracker::storageSessionMap().values()) {
         if (session)
             soup_cookie_jar_set_accept_policy(session->soupNetworkSession().cookieJar(), soupPolicy);
     }
@@ -86,7 +86,7 @@ WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
 NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
 {
     if (frame() && frame()->page()->usesEphemeralSession())
-        return *SessionTracker::session(SessionID::legacyPrivateSessionID());
+        return *SessionTracker::storageSession(SessionID::legacyPrivateSessionID());
 
     return NetworkStorageSession::defaultStorageSession();
 }