Title: [215883] trunk/Source
Revision
215883
Author
beid...@apple.com
Date
2017-04-27 11:40:05 -0700 (Thu, 27 Apr 2017)

Log Message

Update NetworkStorageSession to support multiple persistent sessions and explicitly set cookie storages.
https://bugs.webkit.org/show_bug.cgi?id=171365

Reviewed by Andy Estes.

Source/WebCore:

No new tests (No testable behavior change yet).

* platform/network/NetworkStorageSession.cpp:
(WebCore::NetworkStorageSession::destroySession):
* platform/network/NetworkStorageSession.h:

* platform/network/NetworkStorageSessionStub.cpp:
(WebCore::NetworkStorageSession::ensurePrivateBrowsingSession):
(WebCore::NetworkStorageSession::ensureSession):

* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::createCFStorageSessionForIdentifier):
(WebCore::NetworkStorageSession::NetworkStorageSession):
(WebCore::NetworkStorageSession::switchToNewTestingSession):
(WebCore::NetworkStorageSession::defaultStorageSession):
(WebCore::NetworkStorageSession::ensurePrivateBrowsingSession):
(WebCore::NetworkStorageSession::ensureSession):
(WebCore::NetworkStorageSession::cookieStorage):

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

* platform/spi/cf/CFNetworkSPI.h:

Source/WebKit2:

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (215882 => 215883)


--- trunk/Source/WebCore/ChangeLog	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/ChangeLog	2017-04-27 18:40:05 UTC (rev 215883)
@@ -1,3 +1,34 @@
+2017-04-27  Brady Eidson  <beid...@apple.com>
+
+        Update NetworkStorageSession to support multiple persistent sessions and explicitly set cookie storages.
+        https://bugs.webkit.org/show_bug.cgi?id=171365
+
+        Reviewed by Andy Estes.
+
+        No new tests (No testable behavior change yet).
+
+        * platform/network/NetworkStorageSession.cpp:
+        (WebCore::NetworkStorageSession::destroySession):
+        * platform/network/NetworkStorageSession.h:
+        
+        * platform/network/NetworkStorageSessionStub.cpp:
+        (WebCore::NetworkStorageSession::ensurePrivateBrowsingSession):
+        (WebCore::NetworkStorageSession::ensureSession):
+        
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::createCFStorageSessionForIdentifier):
+        (WebCore::NetworkStorageSession::NetworkStorageSession):
+        (WebCore::NetworkStorageSession::switchToNewTestingSession):
+        (WebCore::NetworkStorageSession::defaultStorageSession):
+        (WebCore::NetworkStorageSession::ensurePrivateBrowsingSession):
+        (WebCore::NetworkStorageSession::ensureSession):
+        (WebCore::NetworkStorageSession::cookieStorage):
+        
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::ensureSession):
+        
+        * platform/spi/cf/CFNetworkSPI.h:
+
 2017-04-27  Zalan Bujtas  <za...@apple.com>
 
         Use text-shadow to visualize simple line layout coverage.

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp (215882 => 215883)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp	2017-04-27 18:40:05 UTC (rev 215883)
@@ -46,6 +46,7 @@
 
 void NetworkStorageSession::destroySession(SessionID sessionID)
 {
+    ASSERT(sessionID != SessionID::defaultSessionID());
     globalSessionMap().remove(sessionID);
 }
 

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (215882 => 215883)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2017-04-27 18:40:05 UTC (rev 215883)
@@ -59,6 +59,7 @@
     WEBCORE_EXPORT static NetworkStorageSession& defaultStorageSession();
     WEBCORE_EXPORT static NetworkStorageSession* storageSession(SessionID);
     WEBCORE_EXPORT static void ensurePrivateBrowsingSession(SessionID, const String& identifierBase = String());
+    WEBCORE_EXPORT static void ensureSession(SessionID, const String& identifierBase = String());
     WEBCORE_EXPORT static void destroySession(SessionID);
     WEBCORE_EXPORT static void forEach(std::function<void(const WebCore::NetworkStorageSession&)>);
 
@@ -72,7 +73,7 @@
 #endif
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
-    NetworkStorageSession(SessionID, RetainPtr<CFURLStorageSessionRef>);
+    NetworkStorageSession(SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&);
 
     // May be null, in which case a Foundation default should be used.
     CFURLStorageSessionRef platformSession() { return m_platformSession.get(); }
@@ -114,6 +115,7 @@
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
     RetainPtr<CFURLStorageSessionRef> m_platformSession;
+    RetainPtr<CFHTTPCookieStorageRef> m_platformCookieStorage;
 #elif USE(SOUP)
     static void cookiesDidChange(NetworkStorageSession*);
 

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSessionStub.cpp (215882 => 215883)


--- trunk/Source/WebCore/platform/network/NetworkStorageSessionStub.cpp	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSessionStub.cpp	2017-04-27 18:40:05 UTC (rev 215883)
@@ -49,11 +49,16 @@
     return m_context.get();
 }
 
-void NetworkStorageSession::ensurePrivateBrowsingSession(SessionID sessionID, const String&)
+void NetworkStorageSession::ensurePrivateBrowsingSession(SessionID, const String&)
 {
     ASSERT_NOT_REACHED();
 }
 
+void NetworkStorageSession::ensureSession(SessionID, const String&)
+{
+    ASSERT_NOT_REACHED();
+}
+
 static std::unique_ptr<NetworkStorageSession>& defaultSession()
 {
     static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;

Modified: trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp (215882 => 215883)


--- trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp	2017-04-27 18:40:05 UTC (rev 215883)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,15 +38,41 @@
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
 
-// FIXME: This file is mostly Cocoa code, not CFNetwork code. This code should be moved.
-
 namespace WebCore {
 
 static bool cookieStoragePartitioningEnabled;
 
-NetworkStorageSession::NetworkStorageSession(SessionID sessionID, RetainPtr<CFURLStorageSessionRef> platformSession)
+static RetainPtr<CFURLStorageSessionRef> createCFStorageSessionForIdentifier(CFStringRef identifier)
+{
+    auto storageSession = adoptCF(_CFURLStorageSessionCreate(kCFAllocatorDefault, identifier, nullptr));
+
+    if (!storageSession)
+        return nullptr;
+
+    auto cache = adoptCF(_CFURLStorageSessionCopyCache(kCFAllocatorDefault, storageSession.get()));
+    if (!cache)
+        return nullptr;
+
+    CFURLCacheSetDiskCapacity(cache.get(), 0);
+
+    auto sharedCache = adoptCF(CFURLCacheCopySharedURLCache());
+    CFURLCacheSetMemoryCapacity(cache.get(), CFURLCacheMemoryCapacity(sharedCache.get()));
+
+    auto cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
+    if (!cookieStorage)
+        return nullptr;
+
+    auto sharedCookieStorage = _CFHTTPCookieStorageGetDefault(kCFAllocatorDefault);
+    auto sharedPolicy = CFHTTPCookieStorageGetCookieAcceptPolicy(sharedCookieStorage);
+    CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), sharedPolicy);
+
+    return storageSession;
+}
+
+NetworkStorageSession::NetworkStorageSession(SessionID sessionID, RetainPtr<CFURLStorageSessionRef>&& platformSession, RetainPtr<CFHTTPCookieStorageRef>&& platformCookieStorage)
     : m_sessionID(sessionID)
-    , m_platformSession(platformSession)
+    , m_platformSession(WTFMove(platformSession))
+    , m_platformCookieStorage(platformCookieStorage ? WTFMove(platformCookieStorage) : cookieStorage())
 {
 }
 
@@ -61,37 +87,61 @@
 {
     // 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()));
+
+    RetainPtr<CFURLStorageSessionRef> session;
 #if PLATFORM(COCOA)
-    defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get())));
+    session = adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get()));
 #else
-    defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get(), defaultNetworkStorageSession()->platformSession())));
+    session = adoptCF(wkCreatePrivateStorageSession(sessionName.createCFString().get(), defaultNetworkStorageSession()->platformSession()));
 #endif
+
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
+    if (session)
+        cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, session.get()));
+
+    defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), WTFMove(session), WTFMove(cookieStorage));
 }
 
 NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
 {
     if (!defaultNetworkStorageSession())
-        defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), nullptr);
+        defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), nullptr, nullptr);
     return *defaultNetworkStorageSession();
 }
 
 void NetworkStorageSession::ensurePrivateBrowsingSession(SessionID sessionID, const String& identifierBase)
 {
-    if (globalSessionMap().contains(sessionID))
+    ASSERT(sessionID.isEphemeral());
+    ensureSession(sessionID, identifierBase);
+}
+
+void NetworkStorageSession::ensureSession(SessionID sessionID, const String& identifierBase)
+{
+    auto addResult = globalSessionMap().add(sessionID, nullptr);
+    if (!addResult.isNewEntry)
         return;
+
     RetainPtr<CFStringRef> cfIdentifier = String(identifierBase + ".PrivateBrowsing").createCFString();
 
+    RetainPtr<CFURLStorageSessionRef> storageSession;
+    if (sessionID.isEphemeral()) {
 #if PLATFORM(COCOA)
-    auto session = std::make_unique<NetworkStorageSession>(sessionID, adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get())));
+        storageSession = adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get()));
 #else
-    auto session = std::make_unique<NetworkStorageSession>(sessionID, adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get(), defaultNetworkStorageSession()->platformSession())));
+        storageSession = adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get(), defaultNetworkStorageSession()->platformSession()));
 #endif
+    } else
+        storageSession = createCFStorageSessionForIdentifier(cfIdentifier.get());
 
-    globalSessionMap().add(sessionID, WTFMove(session));
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = storageSession ? adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get())) : nullptr;
+    addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
 }
 
 RetainPtr<CFHTTPCookieStorageRef> NetworkStorageSession::cookieStorage() const
 {
+    if (m_platformCookieStorage)
+        return m_platformCookieStorage;
+
     if (m_platformSession)
         return adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, m_platformSession.get()));
 

Modified: trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp (215882 => 215883)


--- trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2017-04-27 18:40:05 UTC (rev 215883)
@@ -86,6 +86,11 @@
     globalSessionMap().add(sessionID, std::make_unique<NetworkStorageSession>(sessionID, std::make_unique<SoupNetworkSession>()));
 }
 
+void NetworkStorageSession::ensureSession(SessionID, const String&)
+{
+    // FIXME: Implement
+}
+
 void NetworkStorageSession::switchToNewTestingSession()
 {
     defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), std::make_unique<SoupNetworkSession>());

Modified: trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h (215882 => 215883)


--- trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h	2017-04-27 18:40:05 UTC (rev 215883)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -154,10 +154,16 @@
 WTF_EXTERN_C_BEGIN
 
 #if !PLATFORM(WIN)
+CFURLStorageSessionRef _CFURLStorageSessionCreate(CFAllocatorRef, CFStringRef, CFDictionaryRef);
+CFURLCacheRef _CFURLStorageSessionCopyCache(CFAllocatorRef, CFURLStorageSessionRef);
+
 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
 
 CFURLCacheRef CFURLCacheCopySharedURLCache();
 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
+CFIndex CFURLCacheMemoryCapacity(CFURLCacheRef);
+void CFURLCacheSetDiskCapacity(CFURLCacheRef, CFIndex);
+
 #if PLATFORM(COCOA)
 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
@@ -180,6 +186,7 @@
 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
+CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);

Modified: trunk/Source/WebKit2/ChangeLog (215882 => 215883)


--- trunk/Source/WebKit2/ChangeLog	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebKit2/ChangeLog	2017-04-27 18:40:05 UTC (rev 215883)
@@ -1,3 +1,13 @@
+2017-04-27  Brady Eidson  <beid...@apple.com>
+
+        Update NetworkStorageSession to support multiple persistent sessions and explicitly set cookie storages.
+        https://bugs.webkit.org/show_bug.cgi?id=171365
+
+        Reviewed by Andy Estes.
+
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
+
 2017-04-27  Alex Christensen  <achristen...@webkit.org>
 
         Modernize Frame.h

Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (215882 => 215883)


--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2017-04-27 18:11:03 UTC (rev 215882)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2017-04-27 18:40:05 UTC (rev 215883)
@@ -590,15 +590,10 @@
     setCollectsTimingData();
 #endif
 
-    if (sessionID == WebCore::SessionID::defaultSessionID()) {
-        if (CFHTTPCookieStorageRef storage = WebCore::NetworkStorageSession::defaultStorageSession().cookieStorage().get())
-            configuration.HTTPCookieStorage = [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage] autorelease];
-    } else {
-        auto* storageSession = WebCore::NetworkStorageSession::storageSession(sessionID);
-        RELEASE_ASSERT(storageSession);
-        if (CFHTTPCookieStorageRef storage = storageSession->cookieStorage().get())
-            configuration.HTTPCookieStorage = [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage] autorelease];
-    }
+    auto* storageSession = WebCore::NetworkStorageSession::storageSession(sessionID);
+    RELEASE_ASSERT(storageSession);
+    if (CFHTTPCookieStorageRef storage = storageSession->cookieStorage().get())
+        configuration.HTTPCookieStorage = [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage] autorelease];
 
     m_sessionWithCredentialStorageDelegate = adoptNS([[WKNetworkSessionDelegate alloc] initWithNetworkSession:*this withCredentials:true]);
     m_sessionWithCredentialStorage = [NSURLSession sessionWithConfiguration:configuration delegate:static_cast<id>(m_sessionWithCredentialStorageDelegate.get()) delegateQueue:[NSOperationQueue mainQueue]];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to