Vary:Cookie validation doesn't work in private browsing
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2016 11:09:54 +0000 (11:09 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2016 11:09:54 +0000 (11:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158616
Source/WebCore:

rdar://problem/26755067

Reviewed by Darin Adler.

This wasn't implemented because there was no way to get NetworkStorageSession from
a SessionID on WebCore side.

The patch adds a simple WebCore level weak map that allows getting NetworkStorageSessions
from SessionID. This seemed like the cleanest way to do this without a big refactoring
around the currently WebKit2 level SessionTracker.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/network/CacheValidation.cpp:
(WebCore::headerValueForVary):

    Get NetworkStorageSession from SessionID for cookies

(WebCore::verifyVaryingRequestHeaders):
* platform/network/NetworkStorageSession.cpp: Added.

    Add platform independent .cpp for NetworkStorageSession.
    Implement a weak map for SessionID -> NetworkStorageSession.

(WebCore::sessionsMap):
(WebCore::NetworkStorageSession::NetworkStorageSession):
(WebCore::NetworkStorageSession::~NetworkStorageSession):
(WebCore::NetworkStorageSession::forSessionID):

    Get NetworkStorageSession for sessionID.

* platform/network/NetworkStorageSession.h:
(WebCore::NetworkStorageSession::sessionID):
(WebCore::NetworkStorageSession::credentialStorage):
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::NetworkStorageSession::NetworkStorageSession):

    Call to common constructor.

(WebCore::defaultNetworkStorageSession):
* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::NetworkStorageSession):

    Call to common constructor.

(WebCore::defaultSession):
(WebCore::NetworkStorageSession::~NetworkStorageSession): Deleted.

LayoutTests:

Reviewed by Darin Adler.

* http/tests/cache/disk-cache/disk-cache-vary-cookie-expected.txt:
* http/tests/cache/disk-cache/disk-cache-vary-cookie.html:

Exapand the existing test to cover memory cache and private browsing.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/cache/disk-cache/disk-cache-vary-cookie-expected.txt
LayoutTests/http/tests/cache/disk-cache/disk-cache-vary-cookie.html
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/network/CacheValidation.cpp
Source/WebCore/platform/network/NetworkStorageSession.cpp [new file with mode: 0644]
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp

index 8595da3..28e3486 100644 (file)
@@ -1,3 +1,15 @@
+2016-06-10  Antti Koivisto  <antti@apple.com>
+
+        Vary:Cookie validation doesn't work in private browsing
+        https://bugs.webkit.org/show_bug.cgi?id=158616
+
+        Reviewed by Darin Adler.
+
+        * http/tests/cache/disk-cache/disk-cache-vary-cookie-expected.txt:
+        * http/tests/cache/disk-cache/disk-cache-vary-cookie.html:
+
+        Exapand the existing test to cover memory cache and private browsing.
+
 2016-06-10  Benjamin Poulain  <bpoulain@apple.com>
 
         Add support for passive event listeners on touch events
index 8ee540c..d53649c 100644 (file)
@@ -1,8 +1,9 @@
-Test that Vary: Cookie in response is handled by the disk cache.
+Test that Vary: Cookie in response is handled by caches.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
+Testing disk cache
 Setting cookie and loading
 response headers: {"Cache-control":"max-age=100"}
 response source: Network
@@ -31,6 +32,64 @@ response source: Disk cache
 response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
 response source: Disk cache
 
+Testing memory cache
+Setting cookie and loading
+response headers: {"Cache-control":"max-age=100"}
+response source: Network
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Network
+
+Loading again
+response headers: {"Cache-control":"max-age=100"}
+response source: Memory cache
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Memory cache
+
+Changing cookie and loading
+response headers: {"Cache-control":"max-age=100"}
+response source: Memory cache
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Network
+
+Loading again
+response headers: {"Cache-control":"max-age=100"}
+response source: Memory cache
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Memory cache
+
+Testing memory cache in private browsing
+Setting cookie and loading
+response headers: {"Cache-control":"max-age=100"}
+response source: Network
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Network
+
+Loading again
+response headers: {"Cache-control":"max-age=100"}
+response source: Memory cache
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Memory cache
+
+Changing cookie and loading
+response headers: {"Cache-control":"max-age=100"}
+response source: Memory cache
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Network
+
+Loading again
+response headers: {"Cache-control":"max-age=100"}
+response source: Memory cache
+
+response headers: {"Vary":"Cookie","Cache-control":"max-age=100"}
+response source: Memory cache
+
 PASS successfullyParsed is true
 
 TEST COMPLETE
index b9c72ea..4da9fe4 100644 (file)
@@ -3,32 +3,48 @@
 <body>
 <script>
 
-var tests =
-[
-  { responseHeaders: {'Cache-control': 'max-age=100'} },
-  { responseHeaders: {'Vary': 'Cookie', 'Cache-control': 'max-age=100'} },
-];
 
-description("Test that Vary: Cookie in response is handled by the disk cache.");
+description("Test that Vary: Cookie in response is handled by caches.");
 
-debug("Setting cookie and loading");
-document.cookie = "cookie=value";
-loadResources(tests, function () {
-    printResults(tests);
-    debug("Loading again");
-    loadResources(tests, function () {
+function testCookies(testDiskCache, completionHandler)
+{
+    var tests = [
+      { responseHeaders: {'Cache-control': 'max-age=100'} },
+      { responseHeaders: {'Vary': 'Cookie', 'Cache-control': 'max-age=100'} },
+    ];
+
+    var options = { "ClearMemoryCache" : testDiskCache };
+    debug("Setting cookie and loading");
+    document.cookie = "cookie=" + Math.floor((Math.random() * 1000000000000));
+    loadResourcesWithOptions(tests, options, function () {
         printResults(tests);
-        debug("Changing cookie and loading");
-        document.cookie = "cookie=othervalue";
-        loadResources(tests, function () {
+        debug("Loading again");
+        loadResourcesWithOptions(tests, options, function () {
             printResults(tests);
-            debug("Loading again");
-            loadResources(tests, function () {
-               printResults(tests);
-               finishJSTest();
+            debug("Changing cookie and loading");
+            document.cookie = "cookie" + Math.floor((Math.random() * 1000000000000));
+            loadResourcesWithOptions(tests, options, function () {
+                printResults(tests);
+                debug("Loading again");
+                loadResourcesWithOptions(tests, options, function () {
+                   printResults(tests);
+                   completionHandler();
+                });
             });
         });
     });
+}
+
+debug("Testing disk cache");
+testCookies(true, function () {
+    debug("Testing memory cache");
+    testCookies(false, function () {
+        debug("Testing memory cache in private browsing");
+        testRunner.setPrivateBrowsingEnabled(true);
+        testCookies(false, function () {
+            finishJSTest();
+        });
+    });
 });
 
 </script>
index 3205d43..5939413 100644 (file)
@@ -2338,6 +2338,7 @@ set(WebCore_SOURCES
     platform/network/HTTPParsers.cpp
     platform/network/MIMEHeader.cpp
     platform/network/NetworkStateNotifier.cpp
+    platform/network/NetworkStorageSession.cpp
     platform/network/ParsedContentRange.cpp
     platform/network/ParsedContentType.cpp
     platform/network/ProtectionSpaceBase.cpp
index afdbb7a..03eb2f0 100644 (file)
@@ -1,3 +1,55 @@
+2016-06-10  Antti Koivisto  <antti@apple.com>
+
+        Vary:Cookie validation doesn't work in private browsing
+        https://bugs.webkit.org/show_bug.cgi?id=158616
+        rdar://problem/26755067
+
+        Reviewed by Darin Adler.
+
+        This wasn't implemented because there was no way to get NetworkStorageSession from
+        a SessionID on WebCore side.
+
+        The patch adds a simple WebCore level weak map that allows getting NetworkStorageSessions
+        from SessionID. This seemed like the cleanest way to do this without a big refactoring
+        around the currently WebKit2 level SessionTracker.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/network/CacheValidation.cpp:
+        (WebCore::headerValueForVary):
+
+            Get NetworkStorageSession from SessionID for cookies
+
+        (WebCore::verifyVaryingRequestHeaders):
+        * platform/network/NetworkStorageSession.cpp: Added.
+
+            Add platform independent .cpp for NetworkStorageSession.
+            Implement a weak map for SessionID -> NetworkStorageSession.
+
+        (WebCore::sessionsMap):
+        (WebCore::NetworkStorageSession::NetworkStorageSession):
+        (WebCore::NetworkStorageSession::~NetworkStorageSession):
+        (WebCore::NetworkStorageSession::forSessionID):
+
+            Get NetworkStorageSession for sessionID.
+
+        * platform/network/NetworkStorageSession.h:
+        (WebCore::NetworkStorageSession::sessionID):
+        (WebCore::NetworkStorageSession::credentialStorage):
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::NetworkStorageSession::NetworkStorageSession):
+
+            Call to common constructor.
+
+        (WebCore::defaultNetworkStorageSession):
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::NetworkStorageSession):
+
+            Call to common constructor.
+
+        (WebCore::defaultSession):
+        (WebCore::NetworkStorageSession::~NetworkStorageSession): Deleted.
+
 2016-06-10  Ada Chan  <adachan@apple.com>
 
         Use the video element's video box when getting the inline video rect in WebVideoFullscreenManager
index fb7aab8..50de301 100644 (file)
                E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */; };
                E4F9EEF2156D9FFA00D23E7E /* StyleSheetContents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F9EEF0156D84C400D23E7E /* StyleSheetContents.cpp */; };
                E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E4FD02041D0AF2C100D8E57E /* NetworkStorageSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4FD02031D0AF2C100D8E57E /* NetworkStorageSession.cpp */; };
                E51A81DF17298D7700BFCA61 /* JSPerformance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E51A81DE17298D7700BFCA61 /* JSPerformance.cpp */; };
                E526AF3F1727F8F200E41781 /* Performance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E526AF3E1727F8F200E41781 /* Performance.cpp */; };
                E55F497A151B888000BB67DB /* LengthFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E55F4979151B888000BB67DB /* LengthFunctions.cpp */; };
                E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayoutFunctions.h; sourceTree = "<group>"; };
                E4F9EEF0156D84C400D23E7E /* StyleSheetContents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSheetContents.cpp; sourceTree = "<group>"; };
                E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSheetContents.h; sourceTree = "<group>"; };
+               E4FD02031D0AF2C100D8E57E /* NetworkStorageSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkStorageSession.cpp; sourceTree = "<group>"; };
                E51A81DE17298D7700BFCA61 /* JSPerformance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPerformance.cpp; sourceTree = "<group>"; };
                E526AF3E1727F8F200E41781 /* Performance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Performance.cpp; sourceTree = "<group>"; };
                E55F4979151B888000BB67DB /* LengthFunctions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LengthFunctions.cpp; sourceTree = "<group>"; };
                                628D214B12131ED10055DCFC /* NetworkingContext.h */,
                                1A7FA61A0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp */,
                                1A7FA6180DDA3B3A0028F8A5 /* NetworkStateNotifier.h */,
+                               E4FD02031D0AF2C100D8E57E /* NetworkStorageSession.cpp */,
                                E13EF3421684ECF40034C83F /* NetworkStorageSession.h */,
                                CDCD41E51C3DDB0900965D99 /* ParsedContentRange.cpp */,
                                CDCD41E61C3DDB0900965D99 /* ParsedContentRange.h */,
                                A55639D21C6F09E700806D8E /* WorkerConsoleClient.cpp in Sources */,
                                A3E2643014748991005A8588 /* WorkerEventQueue.cpp in Sources */,
                                2E4346480F546A8200B0F1BA /* WorkerGlobalScope.cpp in Sources */,
+                               E4FD02041D0AF2C100D8E57E /* NetworkStorageSession.cpp in Sources */,
                                418C395A1C8DD6990051C8A3 /* WorkerGlobalScopeFetch.cpp in Sources */,
                                5185FCB31BB4C4E80012898F /* WorkerGlobalScopeIndexedDatabase.cpp in Sources */,
                                97F8E665151D4A4B00D2D181 /* WorkerGlobalScopeNotifications.cpp in Sources */,
index 07ee84a..99a1ead 100644 (file)
@@ -338,11 +338,7 @@ static String headerValueForVary(const ResourceRequest& request, const String& h
     // We could fetch the cookie when making the request but that seems overkill as the case is very rare and it
     // is a blocking operation. This should be sufficient to cover reasonable cases.
     if (headerName == httpHeaderNameString(HTTPHeaderName::Cookie)) {
-        if (sessionID != SessionID::defaultSessionID()) {
-            // FIXME: Don't know how to get the cookie. There should be a global way to get NetworkStorageSession from sessionID.
-            return "";
-        }
-        auto& session = NetworkStorageSession::defaultStorageSession();
+        auto& session = NetworkStorageSession::forSessionID(sessionID);
         auto* cookieStrategy = platformStrategies() ? platformStrategies()->cookiesStrategy() : nullptr;
         if (!cookieStrategy)
             return cookieRequestHeaderFieldValue(session, request.firstPartyForCookies(), request.url());
@@ -374,10 +370,6 @@ bool verifyVaryingRequestHeaders(const Vector<std::pair<String, String>>& varyin
         // FIXME: Vary: * in response would ideally trigger a cache delete instead of a store.
         if (varyingRequestHeader.first == "*")
             return false;
-        if (sessionID != SessionID::defaultSessionID() && varyingRequestHeader.first == httpHeaderNameString(HTTPHeaderName::Cookie)) {
-            // FIXME: See the comment in headerValueForVary.
-            return false;
-        }
         String headerValue = headerValueForVary(request, varyingRequestHeader.first, sessionID);
         if (headerValue != varyingRequestHeader.second)
             return false;
diff --git a/Source/WebCore/platform/network/NetworkStorageSession.cpp b/Source/WebCore/platform/network/NetworkStorageSession.cpp
new file mode 100644 (file)
index 0000000..8679776
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * 
+ * 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 "config.h"
+#include "NetworkStorageSession.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
+
+#if USE(SOUP)
+#include "SoupNetworkSession.h"
+#endif
+
+namespace WebCore {
+
+static std::unique_ptr<NetworkStorageSession>& defaultSession()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
+    return session;
+}
+
+static HashMap<SessionID, NetworkStorageSession*>& sessionsMap()
+{
+    static NeverDestroyed<HashMap<SessionID, NetworkStorageSession*>> map;
+    return map;
+}
+
+NetworkStorageSession::NetworkStorageSession(SessionID sessionID)
+    : m_sessionID(sessionID)
+{
+    if (sessionID == SessionID::defaultSessionID())
+        return;
+    ASSERT(!sessionsMap().contains(sessionID));
+    sessionsMap().add(sessionID, this);
+}
+
+NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
+{
+    if (!defaultSession())
+        defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), nullptr);
+    return *defaultSession();
+}
+
+NetworkStorageSession::~NetworkStorageSession()
+{
+    if (m_sessionID == SessionID::defaultSessionID())
+        return;
+    ASSERT(sessionsMap().contains(m_sessionID));
+    sessionsMap().remove(m_sessionID);
+}
+
+NetworkStorageSession& NetworkStorageSession::forSessionID(SessionID sessionID)
+{
+    if (sessionID == SessionID::defaultSessionID())
+        return defaultStorageSession();
+
+    ASSERT(sessionsMap().contains(sessionID));
+    return *sessionsMap().get(sessionID);
+}
+
+void NetworkStorageSession::replaceDefaultSession(std::unique_ptr<NetworkStorageSession> newDefaultSession)
+{
+    defaultSession() = WTFMove(newDefaultSession);
+}
+
+};
index fc45e32..7f394da 100644 (file)
@@ -37,7 +37,6 @@
 
 namespace WebCore {
 
-class NetworkingContext;
 class ResourceRequest;
 class SoupNetworkSession;
 
@@ -49,37 +48,37 @@ public:
 
     WEBCORE_EXPORT static void switchToNewTestingSession();
 
+    static NetworkStorageSession& forSessionID(SessionID);
+
+    WEBCORE_EXPORT ~NetworkStorageSession();
+
     SessionID sessionID() const { return m_sessionID; }
     CredentialStorage& credentialStorage() { return m_credentialStorage; }
 
 #if PLATFORM(COCOA) || USE(CFNETWORK)
-    NetworkStorageSession(SessionID, RetainPtr<CFURLStorageSessionRef>);
+    NetworkStorageSession(SessionID, RetainPtr<CFURLStorageSessionRef>&&);
 
     // May be null, in which case a Foundation default should be used.
     CFURLStorageSessionRef platformSession() { return m_platformSession.get(); }
     WEBCORE_EXPORT RetainPtr<CFHTTPCookieStorageRef> cookieStorage() const;
 #elif USE(SOUP)
     NetworkStorageSession(SessionID, std::unique_ptr<SoupNetworkSession>);
-    ~NetworkStorageSession();
 
     SoupNetworkSession& soupNetworkSession() const;
     void setSoupNetworkSession(std::unique_ptr<SoupNetworkSession>);
-#else
-    NetworkStorageSession(SessionID, NetworkingContext*);
-    ~NetworkStorageSession();
-
-    NetworkingContext* context() const;
 #endif
 
 private:
+    explicit NetworkStorageSession(SessionID);
+
+    static void replaceDefaultSession(std::unique_ptr<NetworkStorageSession>);
+
     SessionID m_sessionID;
 
 #if PLATFORM(COCOA) || USE(CFNETWORK)
     RetainPtr<CFURLStorageSessionRef> m_platformSession;
 #elif USE(SOUP)
     std::unique_ptr<SoupNetworkSession> m_session;
-#else
-    RefPtr<NetworkingContext> m_context;
 #endif
 
     CredentialStorage m_credentialStorage;
index 279d331..f54a4be 100644 (file)
 
 namespace WebCore {
 
-NetworkStorageSession::NetworkStorageSession(SessionID sessionID, RetainPtr<CFURLStorageSessionRef> platformSession)
-    : m_sessionID(sessionID)
-    , m_platformSession(platformSession)
+NetworkStorageSession::NetworkStorageSession(SessionID sessionID, RetainPtr<CFURLStorageSessionRef>&& platformSession)
+    : NetworkStorageSession(sessionID)
 {
-}
-
-static std::unique_ptr<NetworkStorageSession>& defaultNetworkStorageSession()
-{
-    ASSERT(isMainThread());
-    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
-    return session;
+    m_platformSession = WTFMove(platformSession);
 }
 
 void NetworkStorageSession::switchToNewTestingSession()
@@ -59,19 +52,12 @@ void NetworkStorageSession::switchToNewTestingSession()
     // Session name should be short enough for shared memory region name to be under the limit, otehrwise sandbox rules won't work (see <rdar://problem/13642852>).
     String sessionName = String::format("WebKit Test-%u", static_cast<uint32_t>(getCurrentProcessID()));
 #if PLATFORM(COCOA)
-    defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get())));
+    replaceDefaultSession(std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get()))));
 #else
-    defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get(), defaultNetworkStorageSession()->platformSession())));
+    replaceDefaultSession(std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get(), defaultNetworkStorageSession()->platformSession()))));
 #endif
 }
 
-NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
-{
-    if (!defaultNetworkStorageSession())
-        defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), nullptr);
-    return *defaultNetworkStorageSession();
-}
-
 std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(SessionID sessionID, const String& identifierBase)
 {
     RetainPtr<CFStringRef> cfIdentifier = String(identifierBase + ".PrivateBrowsing").createCFString();
@@ -79,7 +65,7 @@ std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrows
 #if PLATFORM(COCOA)
     auto session = std::make_unique<NetworkStorageSession>(sessionID, adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get())));
 #else
-    auto session = std::make_unique<NetworkStorageSession>(sessionID, adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get(), defaultNetworkStorageSession()->platformSession())));
+    auto session = std::make_unique<NetworkStorageSession>(sessionID, adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get(), defaultStorageSession().platformSession())));
 #endif
 
     return session;
index dcda93b..b7034ed 100644 (file)
 namespace WebCore {
 
 NetworkStorageSession::NetworkStorageSession(SessionID sessionID, std::unique_ptr<SoupNetworkSession> session)
-    : m_sessionID(sessionID)
-    , m_session(WTFMove(session))
+    : NetworkStorageSession(sessionID)
 {
-}
-
-NetworkStorageSession::~NetworkStorageSession()
-{
-}
-
-static std::unique_ptr<NetworkStorageSession>& defaultSession()
-{
-    ASSERT(isMainThread());
-    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
-    return session;
-}
-
-NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
-{
-    if (!defaultSession())
-        defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), nullptr);
-    return *defaultSession();
+    m_session = WTFMove(session);
 }
 
 std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(SessionID sessionID, const String&)
@@ -68,7 +50,7 @@ std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrows
 
 void NetworkStorageSession::switchToNewTestingSession()
 {
-    defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), SoupNetworkSession::createTestingSession());
+    replaceDefaultSession(std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), SoupNetworkSession::createTestingSession()));
 }
 
 SoupNetworkSession& NetworkStorageSession::soupNetworkSession() const