Move NetworkStorageSession ownership to NetworkProcess
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Jan 2019 21:28:28 +0000 (21:28 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Jan 2019 21:28:28 +0000 (21:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193580

Reviewed by Geoff Garen.

Source/WebCore:

NetworkStorageSessions used to be owned by a process-global map living in WebCore.
This patch moves the ownership to the WebKit/WebKitLegacy layer.
In WebKitLegacy they are still owned by a process-global map for compatibility.
In WebKit they are owned by a map owned by the NetworkProcess object.
There were three non-NetworkProcess uses of NetworkStorageSessions which have been dealt with thusly:
1. The WebProcess used to clear credentials from a NetworkStorageSession.  Since this was the only use
of a NetworkStorageSession in the WebProcess we can conclude there were no credentials to clear,
so this code was removed with no change in behavior.
2. The WebProcess used NetworkStorageSessions to get persistent credentials.  This was turned
into a static method that does the same thing.  We should audit these calls and decide if we really want them.
3. The UIProcess used NetworkStorageSessions in APIHTTPCookieStore to interact with the default cookie
storage on Cocoa platforms.  This has been replaced by functions that do the same thing directly.

* platform/network/CredentialStorage.h:
* platform/network/NetworkStorageSession.cpp:
(WebCore::NetworkStorageSession::processMayUseCookieAPI):
(WebCore::NetworkStorageSession::globalSessionMap): Deleted.
(WebCore::NetworkStorageSession::storageSession): Deleted.
(WebCore::NetworkStorageSession::destroySession): Deleted.
(WebCore::NetworkStorageSession::forEach): Deleted.
* platform/network/NetworkStorageSession.h:
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier):
(WebCore::createCFStorageSessionForIdentifier): Deleted.
(WebCore::defaultNetworkStorageSession): Deleted.
(WebCore::NetworkStorageSession::switchToNewTestingSession): Deleted.
(WebCore::NetworkStorageSession::defaultStorageSession): Deleted.
(WebCore::NetworkStorageSession::ensureSession): Deleted.
* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::SocketStreamHandleImpl::getStoredCONNECTProxyCredentials):
* platform/network/cocoa/CookieStorageObserver.h:
* platform/network/curl/NetworkStorageSessionCurl.cpp:
(WebCore::defaultSession): Deleted.
(WebCore::NetworkStorageSession::defaultStorageSession): Deleted.
(WebCore::NetworkStorageSession::ensureSession): Deleted.
(WebCore::NetworkStorageSession::switchToNewTestingSession): Deleted.
* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::clearSoupNetworkSessionAndCookieStorage):
(WebCore::defaultSession): Deleted.
(WebCore::NetworkStorageSession::defaultStorageSession): Deleted.
(WebCore::NetworkStorageSession::ensureSession): Deleted.
(WebCore::NetworkStorageSession::switchToNewTestingSession): Deleted.

Source/WebKit:

* NetworkProcess/Cookies/WebCookieManager.cpp:
(WebKit::WebCookieManager::WebCookieManager):
(WebKit::WebCookieManager::getHostnamesWithCookies):
(WebKit::WebCookieManager::deleteCookiesForHostname):
(WebKit::WebCookieManager::deleteAllCookies):
(WebKit::WebCookieManager::deleteCookie):
(WebKit::WebCookieManager::deleteAllCookiesModifiedSince):
(WebKit::WebCookieManager::getAllCookies):
(WebKit::WebCookieManager::getCookies):
(WebKit::WebCookieManager::setCookie):
(WebKit::WebCookieManager::setCookies):
(WebKit::WebCookieManager::startObservingCookieChanges):
(WebKit::WebCookieManager::stopObservingCookieChanges):
* NetworkProcess/Cookies/WebCookieManager.h:
* NetworkProcess/Cookies/mac/WebCookieManagerMac.mm:
(WebKit::WebCookieManager::platformSetHTTPCookieAcceptPolicy):
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::storageSession):
(WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
(WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM):
(WebKit::NetworkConnectionToWebProcess::cookiesEnabled):
(WebKit::NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue):
(WebKit::NetworkConnectionToWebProcess::getRawCookies):
(WebKit::NetworkConnectionToWebProcess::deleteCookie):
(WebKit::NetworkConnectionToWebProcess::removeStorageAccessForFrame):
(WebKit::NetworkConnectionToWebProcess::removeStorageAccessForAllFramesOnPage):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::clearCachedCredentials):
(WebKit::NetworkProcess::switchToNewTestingSession):
(WebKit::NetworkProcess::ensureSession):
(WebKit::NetworkProcess::storageSession const):
(WebKit::NetworkProcess::defaultStorageSession const):
(WebKit::NetworkProcess::forEachNetworkStorageSession):
(WebKit::NetworkProcess::destroySession):
(WebKit::NetworkProcess::updatePrevalentDomainsToBlockCookiesFor):
(WebKit::NetworkProcess::setAgeCapForClientSideCookies):
(WebKit::NetworkProcess::hasStorageAccessForFrame):
(WebKit::NetworkProcess::getAllStorageAccessEntries):
(WebKit::NetworkProcess::grantStorageAccess):
(WebKit::NetworkProcess::removeAllStorageAccess):
(WebKit::NetworkProcess::removePrevalentDomains):
(WebKit::NetworkProcess::setCacheMaxAgeCapForPrevalentResources):
(WebKit::NetworkProcess::resetCacheMaxAgeCapForPrevalentResources):
(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::validateCacheEntryForMaxAgeCapValidation):
(WebKit::NetworkResourceLoader::logCookieInformation const):
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::networkStorageSession const):
* NetworkProcess/NetworkStorageSessionProvider.h:
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::makeUseDecision):
(WebKit::NetworkCache::Cache::retrieve):
(WebKit::NetworkCache::Cache::makeEntry):
(WebKit::NetworkCache::Cache::makeRedirectEntry):
(WebKit::NetworkCache::Cache::update):
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
(WebKit::NetworkCache::SpeculativeLoad::willSendRedirectedRequest):
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformSyncAllCookies):
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]):
(-[WKNetworkSessionDelegate URLSession:task:_schemeUpgraded:completionHandler:]):
(-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
* SourcesCocoa.txt:
* UIProcess/API/APIHTTPCookieStore.cpp:
(API::HTTPCookieStore::~HTTPCookieStore):
(API::HTTPCookieStore::cookies):
(API::HTTPCookieStore::setCookie):
(API::HTTPCookieStore::deleteCookie):
(API::HTTPCookieStore::registerObserver):
(API::HTTPCookieStore::unregisterObserver):
(API::HTTPCookieStore::registerForNewProcessPoolNotifications):
(API::HTTPCookieStore::flushDefaultUIProcessCookieStore):
(API::HTTPCookieStore::getAllDefaultUIProcessCookieStoreCookies):
(API::HTTPCookieStore::setCookieInDefaultUIProcessCookieStore):
(API::HTTPCookieStore::deleteCookieFromDefaultUIProcessCookieStore):
(API::HTTPCookieStore::startObservingChangesToDefaultUIProcessCookieStore):
(API::HTTPCookieStore::stopObservingChangesToDefaultUIProcessCookieStore):
* UIProcess/API/APIHTTPCookieStore.h:
* UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm: Added.
(API::HTTPCookieStore::flushDefaultUIProcessCookieStore):
(API::HTTPCookieStore::getAllDefaultUIProcessCookieStoreCookies):
(API::HTTPCookieStore::setCookieInDefaultUIProcessCookieStore):
(API::HTTPCookieStore::deleteCookieFromDefaultUIProcessCookieStore):
(API::HTTPCookieStore::startObservingChangesToDefaultUIProcessCookieStore):
(API::HTTPCookieStore::stopObservingChangesToDefaultUIProcessCookieStore):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::clearCachedCredentials):
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::getAuthenticationInfo):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::deleteWebsiteData):
(WebKit::WebProcess::clearCachedCredentials): Deleted.
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

Source/WebKitLegacy:

* WebCoreSupport/NetworkStorageSessionMap.cpp: Added.
(defaultNetworkStorageSession):
(globalSessionMap):
(NetworkStorageSessionMap::storageSession):
(NetworkStorageSessionMap::defaultStorageSession):
(NetworkStorageSessionMap::switchToNewTestingSession):
(NetworkStorageSessionMap::ensureSession):
(NetworkStorageSessionMap::destroySession):
* WebCoreSupport/NetworkStorageSessionMap.h: Added.
* WebCoreSupport/PageStorageSessionProvider.h:
* WebKitLegacy.xcodeproj/project.pbxproj:

Source/WebKitLegacy/mac:

* Misc/WebCache.mm:
(+[WebCache clearCachedCredentials]):
* Misc/WebDownload.mm:
(-[WebDownloadInternal download:didReceiveAuthenticationChallenge:]):
* Plugins/WebBaseNetscapePluginView.mm:
(WebKit::getAuthenticationInfo):
* WebCoreSupport/WebFrameNetworkingContext.mm:
(WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebFrameNetworkingContext::destroyPrivateBrowsingSession):
(WebFrameNetworkingContext::storageSession const):
* WebView/WebPreferences.mm:
(+[WebPreferences _switchNetworkLoaderToNewTestingSession]):
(+[WebPreferences _clearNetworkLoaderSession]):
(+[WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:]):

Source/WebKitLegacy/win:

* WebCoreSupport/WebFrameNetworkingContext.cpp:
(WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
(WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebFrameNetworkingContext::destroyPrivateBrowsingSession):
(WebFrameNetworkingContext::storageSession const):
* WebDownloadCFNet.cpp:
(WebDownload::didReceiveAuthenticationChallenge):
* WebPreferences.cpp:
(WebPreferences::clearNetworkLoaderSession):
(WebPreferences::switchNetworkLoaderToNewTestingSession):

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

65 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/CredentialStorage.h
Source/WebCore/platform/network/NetworkStorageSession.cpp
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp
Source/WebCore/platform/network/cocoa/CookieStorageObserver.h
Source/WebCore/platform/network/curl/CurlResourceHandleDelegate.cpp
Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp
Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp
Source/WebCore/platform/network/soup/DNSResolveQueueSoup.cpp
Source/WebCore/platform/network/soup/DNSResolveQueueSoup.h
Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/Cookies/WebCookieManager.cpp
Source/WebKit/NetworkProcess/Cookies/WebCookieManager.h
Source/WebKit/NetworkProcess/Cookies/mac/WebCookieManagerMac.mm
Source/WebKit/NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp
Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h
Source/WebKit/NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/NetworkSession.cpp
Source/WebKit/NetworkProcess/NetworkStorageSessionProvider.h
Source/WebKit/NetworkProcess/cache/NetworkCache.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp
Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm
Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Source/WebKit/NetworkProcess/curl/RemoteNetworkingContextCurl.cpp
Source/WebKit/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit/NetworkProcess/soup/NetworkProcessMainSoup.cpp
Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp
Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp
Source/WebKit/NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/API/APIHTTPCookieStore.cpp
Source/WebKit/UIProcess/API/APIHTTPCookieStore.h
Source/WebKit/UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm [new file with mode: 0644]
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Plugins/PluginView.cpp
Source/WebKit/WebProcess/WebCoreSupport/curl/WebFrameNetworkingContext.cpp
Source/WebKit/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in
Source/WebKit/WebProcess/soup/WebProcessSoup.cpp
Source/WebKitLegacy/CMakeLists.txt
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.cpp [new file with mode: 0644]
Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.h [new file with mode: 0644]
Source/WebKitLegacy/WebCoreSupport/PageStorageSessionProvider.h
Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/Misc/WebCache.mm
Source/WebKitLegacy/mac/Misc/WebDownload.mm
Source/WebKitLegacy/mac/Plugins/WebBaseNetscapePluginView.mm
Source/WebKitLegacy/mac/WebCoreSupport/WebFrameNetworkingContext.mm
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebCoreSupport/WebFrameNetworkingContext.cpp
Source/WebKitLegacy/win/WebDownloadCFNet.cpp
Source/WebKitLegacy/win/WebPreferences.cpp

index a1ee260..965aae8 100644 (file)
@@ -1,3 +1,53 @@
+2019-01-22  Alex Christensen  <achristensen@webkit.org>
+
+        Move NetworkStorageSession ownership to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=193580
+
+        Reviewed by Geoff Garen.
+
+        NetworkStorageSessions used to be owned by a process-global map living in WebCore.
+        This patch moves the ownership to the WebKit/WebKitLegacy layer.
+        In WebKitLegacy they are still owned by a process-global map for compatibility.
+        In WebKit they are owned by a map owned by the NetworkProcess object.
+        There were three non-NetworkProcess uses of NetworkStorageSessions which have been dealt with thusly:
+        1. The WebProcess used to clear credentials from a NetworkStorageSession.  Since this was the only use
+        of a NetworkStorageSession in the WebProcess we can conclude there were no credentials to clear,
+        so this code was removed with no change in behavior.
+        2. The WebProcess used NetworkStorageSessions to get persistent credentials.  This was turned
+        into a static method that does the same thing.  We should audit these calls and decide if we really want them.
+        3. The UIProcess used NetworkStorageSessions in APIHTTPCookieStore to interact with the default cookie
+        storage on Cocoa platforms.  This has been replaced by functions that do the same thing directly.
+
+        * platform/network/CredentialStorage.h:
+        * platform/network/NetworkStorageSession.cpp:
+        (WebCore::NetworkStorageSession::processMayUseCookieAPI):
+        (WebCore::NetworkStorageSession::globalSessionMap): Deleted.
+        (WebCore::NetworkStorageSession::storageSession): Deleted.
+        (WebCore::NetworkStorageSession::destroySession): Deleted.
+        (WebCore::NetworkStorageSession::forEach): Deleted.
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier):
+        (WebCore::createCFStorageSessionForIdentifier): Deleted.
+        (WebCore::defaultNetworkStorageSession): Deleted.
+        (WebCore::NetworkStorageSession::switchToNewTestingSession): Deleted.
+        (WebCore::NetworkStorageSession::defaultStorageSession): Deleted.
+        (WebCore::NetworkStorageSession::ensureSession): Deleted.
+        * platform/network/cf/SocketStreamHandleImplCFNet.cpp:
+        (WebCore::SocketStreamHandleImpl::getStoredCONNECTProxyCredentials):
+        * platform/network/cocoa/CookieStorageObserver.h:
+        * platform/network/curl/NetworkStorageSessionCurl.cpp:
+        (WebCore::defaultSession): Deleted.
+        (WebCore::NetworkStorageSession::defaultStorageSession): Deleted.
+        (WebCore::NetworkStorageSession::ensureSession): Deleted.
+        (WebCore::NetworkStorageSession::switchToNewTestingSession): Deleted.
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::clearSoupNetworkSessionAndCookieStorage):
+        (WebCore::defaultSession): Deleted.
+        (WebCore::NetworkStorageSession::defaultStorageSession): Deleted.
+        (WebCore::NetworkStorageSession::ensureSession): Deleted.
+        (WebCore::NetworkStorageSession::switchToNewTestingSession): Deleted.
+
 2019-01-22  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Audit: provide a way to get related Accessibility nodes for a given node
index f4ceb72..52f7a44 100644 (file)
@@ -44,7 +44,7 @@ public:
     WEBCORE_EXPORT void remove(const String&, const ProtectionSpace&);
 
     // OS persistent storage.
-    WEBCORE_EXPORT Credential getFromPersistentStorage(const ProtectionSpace&);
+    WEBCORE_EXPORT static Credential getFromPersistentStorage(const ProtectionSpace&);
 
     WEBCORE_EXPORT void clearCredentials();
 
index 4b77e47..84cc570 100644 (file)
@@ -42,36 +42,10 @@ namespace WebCore {
 
 bool NetworkStorageSession::m_processMayUseCookieAPI = false;
 
-HashMap<PAL::SessionID, std::unique_ptr<NetworkStorageSession>>& NetworkStorageSession::globalSessionMap()
-{
-    static NeverDestroyed<HashMap<PAL::SessionID, std::unique_ptr<NetworkStorageSession>>> map;
-    return map;
-}
-
-NetworkStorageSession* NetworkStorageSession::storageSession(PAL::SessionID sessionID)
-{
-    if (sessionID == PAL::SessionID::defaultSessionID())
-        return &defaultStorageSession();
-    return globalSessionMap().get(sessionID);
-}
-
-void NetworkStorageSession::destroySession(PAL::SessionID sessionID)
-{
-    ASSERT(sessionID != PAL::SessionID::defaultSessionID());
-    globalSessionMap().remove(sessionID);
-}
-
-void NetworkStorageSession::forEach(const WTF::Function<void(const WebCore::NetworkStorageSession&)>& functor)
-{
-    functor(defaultStorageSession());
-    for (auto& storageSession : globalSessionMap().values())
-        functor(*storageSession);
-}
-
 bool NetworkStorageSession::processMayUseCookieAPI()
 {
     return m_processMayUseCookieAPI;
-};
+}
 
 void NetworkStorageSession::permitProcessToUseCookieAPI(bool value)
 {
index ca1e7f9..457e435 100644 (file)
@@ -74,16 +74,9 @@ enum class IncludeSecureCookies : bool;
 class NetworkStorageSession {
     WTF_MAKE_NONCOPYABLE(NetworkStorageSession); WTF_MAKE_FAST_ALLOCATED;
 public:
-    WEBCORE_EXPORT static NetworkStorageSession& defaultStorageSession();
-    WEBCORE_EXPORT static NetworkStorageSession* storageSession(PAL::SessionID);
-    WEBCORE_EXPORT static void ensureSession(PAL::SessionID, const String& identifierBase = String());
-    WEBCORE_EXPORT static void destroySession(PAL::SessionID);
-    WEBCORE_EXPORT static void forEach(const WTF::Function<void(const WebCore::NetworkStorageSession&)>&);
     WEBCORE_EXPORT static void permitProcessToUseCookieAPI(bool);
     WEBCORE_EXPORT static bool processMayUseCookieAPI();
 
-    WEBCORE_EXPORT static void switchToNewTestingSession();
-
     PAL::SessionID sessionID() const { return m_sessionID; }
     CredentialStorage& credentialStorage() { return m_credentialStorage; }
 
@@ -92,16 +85,16 @@ public:
 #endif
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
-    WEBCORE_EXPORT static void ensureSession(PAL::SessionID, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&&);
-    NetworkStorageSession(PAL::SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&);
-    explicit NetworkStorageSession(PAL::SessionID);
+    WEBCORE_EXPORT static RetainPtr<CFURLStorageSessionRef> createCFStorageSessionForIdentifier(CFStringRef identifier);
+    WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&);
+    WEBCORE_EXPORT explicit NetworkStorageSession(PAL::SessionID);
 
     // May be null, in which case a Foundation default should be used.
     CFURLStorageSessionRef platformSession() { return m_platformSession.get(); }
     WEBCORE_EXPORT RetainPtr<CFHTTPCookieStorageRef> cookieStorage() const;
     WEBCORE_EXPORT static void setStorageAccessAPIEnabled(bool);
 #elif USE(SOUP)
-    NetworkStorageSession(PAL::SessionID, std::unique_ptr<SoupNetworkSession>&&);
+    WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID, std::unique_ptr<SoupNetworkSession>&&);
     ~NetworkStorageSession();
 
     SoupNetworkSession* soupNetworkSession() const { return m_session.get(); };
@@ -113,7 +106,7 @@ public:
     void getCredentialFromPersistentStorage(const ProtectionSpace&, GCancellable*, Function<void (Credential&&)>&& completionHandler);
     void saveCredentialToPersistentStorage(const ProtectionSpace&, const Credential&);
 #elif USE(CURL)
-    NetworkStorageSession(PAL::SessionID, NetworkingContext*);
+    WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID, NetworkingContext*);
     ~NetworkStorageSession();
 
     const CookieJarCurl& cookieStorage() const { return m_cookieStorage; };
@@ -124,7 +117,7 @@ public:
 
     NetworkingContext* context() const;
 #else
-    NetworkStorageSession(PAL::SessionID, NetworkingContext*);
+    WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID, NetworkingContext*);
     ~NetworkStorageSession();
 
     NetworkingContext* context() const;
@@ -166,7 +159,6 @@ public:
 #endif
 
 private:
-    static HashMap<PAL::SessionID, std::unique_ptr<NetworkStorageSession>>& globalSessionMap();
     PAL::SessionID m_sessionID;
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
index abb1067..09d86d0 100644 (file)
@@ -40,7 +40,7 @@ namespace WebCore {
 
 static bool storageAccessAPIEnabled;
 
-static RetainPtr<CFURLStorageSessionRef> createCFStorageSessionForIdentifier(CFStringRef identifier)
+RetainPtr<CFURLStorageSessionRef> NetworkStorageSession::createCFStorageSessionForIdentifier(CFStringRef identifier)
 {
     auto storageSession = adoptCF(_CFURLStorageSessionCreate(kCFAllocatorDefault, identifier, nullptr));
 
@@ -85,66 +85,6 @@ NetworkStorageSession::NetworkStorageSession(PAL::SessionID sessionID)
 {
 }
 
-
-static std::unique_ptr<NetworkStorageSession>& defaultNetworkStorageSession()
-{
-    ASSERT(isMainThread());
-    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
-    return session;
-}
-
-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()));
-
-    auto session = adoptCF(createPrivateStorageSession(sessionName.createCFString().get()));
-
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
-    if (NetworkStorageSession::processMayUseCookieAPI()) {
-        ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-        if (session)
-            cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, session.get()));
-    }
-
-    defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(PAL::SessionID::defaultSessionID(), WTFMove(session), WTFMove(cookieStorage));
-}
-
-NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
-{
-    if (!defaultNetworkStorageSession())
-        defaultNetworkStorageSession() = std::make_unique<NetworkStorageSession>(PAL::SessionID::defaultSessionID());
-    return *defaultNetworkStorageSession();
-}
-
-void NetworkStorageSession::ensureSession(PAL::SessionID sessionID, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&& cookieStorage)
-{
-    auto addResult = globalSessionMap().add(sessionID, nullptr);
-    if (!addResult.isNewEntry)
-        return;
-
-    RetainPtr<CFStringRef> cfIdentifier = String(identifierBase + ".PrivateBrowsing").createCFString();
-
-    RetainPtr<CFURLStorageSessionRef> storageSession;
-    if (sessionID.isEphemeral())
-        storageSession = adoptCF(createPrivateStorageSession(cfIdentifier.get()));
-    else
-        storageSession = createCFStorageSessionForIdentifier(cfIdentifier.get());
-
-    if (NetworkStorageSession::processMayUseCookieAPI()) {
-        ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-        if (!cookieStorage && storageSession)
-            cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
-    }
-
-    addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
-}
-
-void NetworkStorageSession::ensureSession(PAL::SessionID sessionID, const String& identifierBase)
-{
-    ensureSession(sessionID, identifierBase, nullptr);
-}
-
 RetainPtr<CFHTTPCookieStorageRef> NetworkStorageSession::cookieStorage() const
 {
     if (!processMayUseCookieAPI())
index 78732e1..b703b64 100644 (file)
@@ -370,7 +370,7 @@ bool SocketStreamHandleImpl::getStoredCONNECTProxyCredentials(const ProtectionSp
     // Try system credential storage first, matching HTTP behavior (CFNetwork only asks the client for password if it couldn't find it in Keychain).
     Credential storedCredential;
     if (auto* storageSession = m_storageSessionProvider ? m_storageSessionProvider->storageSession() : nullptr) {
-        storedCredential = storageSession->credentialStorage().getFromPersistentStorage(protectionSpace);
+        storedCredential = CredentialStorage::getFromPersistentStorage(protectionSpace);
         if (storedCredential.isEmpty())
             storedCredential = storageSession->credentialStorage().get(m_credentialPartition, protectionSpace);
     }
index 8e7733c..0278cee 100644 (file)
@@ -35,18 +35,19 @@ OBJC_CLASS WebCookieObserverAdapter;
 
 namespace WebCore {
 
-class CookieStorageObserver : public ThreadSafeRefCounted<CookieStorageObserver> {
+class WEBCORE_EXPORT CookieStorageObserver : public ThreadSafeRefCounted<CookieStorageObserver> {
 public:
     static Ref<CookieStorageObserver> create(NSHTTPCookieStorage *);
-    CookieStorageObserver(NSHTTPCookieStorage *);
     ~CookieStorageObserver();
 
-    void startObserving(WTF::Function<void()>&& callback);
+    void startObserving(Function<void()>&& callback);
     void stopObserving();
 
     void cookiesDidChange();
 
 private:
+    CookieStorageObserver(NSHTTPCookieStorage *);
+
     RetainPtr<NSHTTPCookieStorage> m_cookieStorage;
     bool m_hasRegisteredInternalsForNotifications { false };
     RetainPtr<WebCookieObserverAdapter> m_observerAdapter;
index cf8e99f..769deee 100644 (file)
@@ -89,7 +89,7 @@ static void handleCookieHeaders(const CurlResponse& response)
 {
     static const auto setCookieHeader = "set-cookie: ";
 
-    const auto& storageSession = NetworkStorageSession::defaultStorageSession();
+    const auto& storageSession = *d()->m_context->storageSession(PAL::SessionID::defaultSessionID());
     const auto& cookieJar = storageSession.cookieStorage();
     for (const auto& header : response.headers) {
         if (header.startsWithIgnoringASCIICase(setCookieHeader)) {
index ce9a2ff..a342ec5 100644 (file)
@@ -87,30 +87,6 @@ CookieJarDB& NetworkStorageSession::cookieDatabase() const
     return m_cookieDatabase;
 }
 
-static std::unique_ptr<NetworkStorageSession>& defaultSession()
-{
-    ASSERT(isMainThread());
-    static std::unique_ptr<NetworkStorageSession> session;
-    return session;
-}
-
-NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
-{
-    if (!defaultSession())
-        defaultSession() = std::make_unique<NetworkStorageSession>(PAL::SessionID::defaultSessionID(), nullptr);
-    return *defaultSession();
-}
-
-void NetworkStorageSession::ensureSession(PAL::SessionID, const String&)
-{
-    // FIXME: Implement for WebKit to use.
-}
-
-void NetworkStorageSession::switchToNewTestingSession()
-{
-    // FIXME: Implement for WebKit to use.
-}
-
 void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, const String& value) const
 {
     cookieStorage().setCookiesFromDOM(*this, firstParty, sameSiteInfo, url, frameID, pageID, value);
index 0eee883..db55409 100644 (file)
@@ -145,7 +145,7 @@ Ref<CurlRequest> ResourceHandle::createCurlRequest(ResourceRequest&& request, Re
     if (status == RequestStatus::NewRequest) {
         addCacheValidationHeaders(request);
 
-        auto& storageSession = NetworkStorageSession::defaultStorageSession();
+        auto& storageSession = *d->m_context->storageSession(PAL::SessionID::defaultSessionID());
         auto& cookieJar = storageSession.cookieStorage();
         auto includeSecureCookies = request.url().protocolIs("https") ? IncludeSecureCookies::Yes : IncludeSecureCookies::No;
         String cookieHeaderField = cookieJar.cookieRequestHeaderFieldValue(storageSession, request.firstPartyForCookies(), SameSiteInfo::create(request), request.url(), WTF::nullopt, WTF::nullopt, includeSecureCookies).first;
@@ -231,7 +231,7 @@ void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChall
         URL urlToStore;
         if (challenge.failureResponse().httpStatusCode() == 401)
             urlToStore = challenge.failureResponse().url();
-        NetworkStorageSession::defaultStorageSession().credentialStorage().set(partition, credential, challenge.protectionSpace(), urlToStore);
+        d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().set(partition, credential, challenge.protectionSpace(), urlToStore);
 
         restartRequestWithCredential(challenge.protectionSpace(), credential);
 
@@ -246,16 +246,16 @@ void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChall
             // The stored credential wasn't accepted, stop using it.
             // There is a race condition here, since a different credential might have already been stored by another ResourceHandle,
             // but the observable effect should be very minor, if any.
-            NetworkStorageSession::defaultStorageSession().credentialStorage().remove(partition, challenge.protectionSpace());
+            d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().remove(partition, challenge.protectionSpace());
         }
 
         if (!challenge.previousFailureCount()) {
-            Credential credential = NetworkStorageSession::defaultStorageSession().credentialStorage().get(partition, challenge.protectionSpace());
+            Credential credential = d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().get(partition, challenge.protectionSpace());
             if (!credential.isEmpty() && credential != d->m_initialCredential) {
                 ASSERT(credential.persistence() == CredentialPersistenceNone);
                 if (challenge.failureResponse().httpStatusCode() == 401) {
                     // Store the credential back, possibly adding it as a default for this directory.
-                    NetworkStorageSession::defaultStorageSession().credentialStorage().set(partition, credential, challenge.protectionSpace(), challenge.failureResponse().url());
+                    d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().set(partition, credential, challenge.protectionSpace(), challenge.failureResponse().url());
                 }
 
                 restartRequestWithCredential(challenge.protectionSpace(), credential);
@@ -289,7 +289,7 @@ void ResourceHandle::receivedCredential(const AuthenticationChallenge& challenge
     if (shouldUseCredentialStorage()) {
         if (challenge.failureResponse().httpStatusCode() == 401) {
             URL urlToStore = challenge.failureResponse().url();
-            NetworkStorageSession::defaultStorageSession().credentialStorage().set(partition, credential, challenge.protectionSpace(), urlToStore);
+            d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().set(partition, credential, challenge.protectionSpace(), urlToStore);
         }
     }
 
@@ -346,13 +346,13 @@ Optional<Credential> ResourceHandle::getCredential(const ResourceRequest& reques
         if (credential.isEmpty()) {
             // <rdar://problem/7174050> - For URLs that match the paths of those previously challenged for HTTP Basic authentication, 
             // try and reuse the credential preemptively, as allowed by RFC 2617.
-            d->m_initialCredential = NetworkStorageSession::defaultStorageSession().credentialStorage().get(partition, request.url());
+            d->m_initialCredential = d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().get(partition, request.url());
         } else if (!redirect) {
             // If there is already a protection space known for the URL, update stored credentials
             // before sending a request. This makes it possible to implement logout by sending an
             // XMLHttpRequest with known incorrect credentials, and aborting it immediately (so that
             // an authentication dialog doesn't pop up).
-            NetworkStorageSession::defaultStorageSession().credentialStorage().set(partition, credential, request.url());
+            d->m_context->storageSession(PAL::SessionID::defaultSessionID())->credentialStorage().set(partition, credential, request.url());
         }
     }
 
index c80a7c9..ed2c4eb 100644 (file)
@@ -33,7 +33,9 @@
 #include "SoupNetworkSession.h"
 #include <libsoup/soup.h>
 #include <wtf/CompletionHandler.h>
+#include <wtf/Function.h>
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/glib/GUniquePtr.h>
 #include <wtf/text/CString.h>
 
@@ -76,10 +78,21 @@ static void proxyResolvedForHttpsUriCallback(GObject* source, GAsyncResult* resu
     didResolveProxy(G_PROXY_RESOLVER(source), result, &isUsingHttpsProxy, static_cast<bool*>(userData));
 }
 
+Function<NetworkStorageSession&()>& globalDefaultNetworkStorageSessionAccessor()
+{
+    static NeverDestroyed<Function<NetworkStorageSession&()>> accessor;
+    return accessor.get();
+}
+
+void DNSResolveQueueSoup::setGlobalDefaultNetworkStorageSessionAccessor(Function<NetworkStorageSession&()>&& accessor)
+{
+    globalDefaultNetworkStorageSessionAccessor() = WTFMove(accessor);
+}
+
 void DNSResolveQueueSoup::updateIsUsingProxy()
 {
     GRefPtr<GProxyResolver> resolver;
-    g_object_get(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
+    g_object_get(globalDefaultNetworkStorageSessionAccessor()().getOrCreateSoupNetworkSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
     ASSERT(resolver);
 
     g_proxy_resolver_lookup_async(resolver.get(), "http://example.com/", nullptr, proxyResolvedForHttpUriCallback, &m_isUsingProxy);
@@ -162,7 +175,7 @@ void DNSResolveQueueSoup::platformResolve(const String& hostname)
 {
     ASSERT(isMainThread());
 
-    soup_session_prefetch_dns(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
+    soup_session_prefetch_dns(globalDefaultNetworkStorageSessionAccessor()().getOrCreateSoupNetworkSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
 }
 
 void DNSResolveQueueSoup::resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&& completionHandler)
@@ -171,7 +184,7 @@ void DNSResolveQueueSoup::resolve(const String& hostname, uint64_t identifier, D
 
     auto address = adoptGRef(soup_address_new(hostname.utf8().data(), 0));
     auto cancellable = adoptGRef(g_cancellable_new());
-    soup_address_resolve_async(address.get(), soup_session_get_async_context(WebCore::NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession()), cancellable.get(), resolvedWithObserverCallback, this);
+    soup_address_resolve_async(address.get(), soup_session_get_async_context(WebCore::globalDefaultNetworkStorageSessionAccessor()().getOrCreateSoupNetworkSession().soupSession()), cancellable.get(), resolvedWithObserverCallback, this);
 
     g_object_set_data(G_OBJECT(address.get()), "identifier", GUINT_TO_POINTER(identifier));
 
index b86a6b1..572034f 100644 (file)
 
 namespace WebCore {
 
+class NetworkStorageSession;
+
 class DNSResolveQueueSoup final : public DNSResolveQueue {
 public:
     using CompletionAndCancelHandlers = std::pair<WebCore::DNSCompletionHandler, GRefPtr<GCancellable>>;
 
     DNSResolveQueueSoup() = default;
+    static void setGlobalDefaultNetworkStorageSessionAccessor(Function<NetworkStorageSession&()>&&);
     void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
     void stopResolve(uint64_t identifier) final;
 
index 8995fd2..e75113a 100644 (file)
@@ -65,31 +65,6 @@ NetworkStorageSession::~NetworkStorageSession()
     g_signal_handlers_disconnect_matched(m_cookieStorage.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
 }
 
-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>(PAL::SessionID::defaultSessionID(), nullptr);
-    return *defaultSession();
-}
-
-void NetworkStorageSession::ensureSession(PAL::SessionID sessionID, const String&)
-{
-    ASSERT(!globalSessionMap().contains(sessionID));
-    globalSessionMap().add(sessionID, std::make_unique<NetworkStorageSession>(sessionID, std::make_unique<SoupNetworkSession>(sessionID)));
-}
-
-void NetworkStorageSession::switchToNewTestingSession()
-{
-    defaultSession() = std::make_unique<NetworkStorageSession>(PAL::SessionID::defaultSessionID(), std::make_unique<SoupNetworkSession>());
-}
-
 SoupNetworkSession& NetworkStorageSession::getOrCreateSoupNetworkSession() const
 {
     if (!m_session)
@@ -99,7 +74,6 @@ SoupNetworkSession& NetworkStorageSession::getOrCreateSoupNetworkSession() const
 
 void NetworkStorageSession::clearSoupNetworkSessionAndCookieStorage()
 {
-    ASSERT(defaultSession().get() == this);
     m_session = nullptr;
     m_cookieObserverHandler = nullptr;
     m_cookieStorage = nullptr;
index 5269f6e..f63f368 100644 (file)
@@ -1,3 +1,115 @@
+2019-01-22  Alex Christensen  <achristensen@webkit.org>
+
+        Move NetworkStorageSession ownership to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=193580
+
+        Reviewed by Geoff Garen.
+
+        * NetworkProcess/Cookies/WebCookieManager.cpp:
+        (WebKit::WebCookieManager::WebCookieManager):
+        (WebKit::WebCookieManager::getHostnamesWithCookies):
+        (WebKit::WebCookieManager::deleteCookiesForHostname):
+        (WebKit::WebCookieManager::deleteAllCookies):
+        (WebKit::WebCookieManager::deleteCookie):
+        (WebKit::WebCookieManager::deleteAllCookiesModifiedSince):
+        (WebKit::WebCookieManager::getAllCookies):
+        (WebKit::WebCookieManager::getCookies):
+        (WebKit::WebCookieManager::setCookie):
+        (WebKit::WebCookieManager::setCookies):
+        (WebKit::WebCookieManager::startObservingCookieChanges):
+        (WebKit::WebCookieManager::stopObservingCookieChanges):
+        * NetworkProcess/Cookies/WebCookieManager.h:
+        * NetworkProcess/Cookies/mac/WebCookieManagerMac.mm:
+        (WebKit::WebCookieManager::platformSetHTTPCookieAcceptPolicy):
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::storageSession):
+        (WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
+        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM):
+        (WebKit::NetworkConnectionToWebProcess::cookiesEnabled):
+        (WebKit::NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue):
+        (WebKit::NetworkConnectionToWebProcess::getRawCookies):
+        (WebKit::NetworkConnectionToWebProcess::deleteCookie):
+        (WebKit::NetworkConnectionToWebProcess::removeStorageAccessForFrame):
+        (WebKit::NetworkConnectionToWebProcess::removeStorageAccessForAllFramesOnPage):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        (WebKit::NetworkProcess::clearCachedCredentials):
+        (WebKit::NetworkProcess::switchToNewTestingSession):
+        (WebKit::NetworkProcess::ensureSession):
+        (WebKit::NetworkProcess::storageSession const):
+        (WebKit::NetworkProcess::defaultStorageSession const):
+        (WebKit::NetworkProcess::forEachNetworkStorageSession):
+        (WebKit::NetworkProcess::destroySession):
+        (WebKit::NetworkProcess::updatePrevalentDomainsToBlockCookiesFor):
+        (WebKit::NetworkProcess::setAgeCapForClientSideCookies):
+        (WebKit::NetworkProcess::hasStorageAccessForFrame):
+        (WebKit::NetworkProcess::getAllStorageAccessEntries):
+        (WebKit::NetworkProcess::grantStorageAccess):
+        (WebKit::NetworkProcess::removeAllStorageAccess):
+        (WebKit::NetworkProcess::removePrevalentDomains):
+        (WebKit::NetworkProcess::setCacheMaxAgeCapForPrevalentResources):
+        (WebKit::NetworkProcess::resetCacheMaxAgeCapForPrevalentResources):
+        (WebKit::NetworkProcess::fetchWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::validateCacheEntryForMaxAgeCapValidation):
+        (WebKit::NetworkResourceLoader::logCookieInformation const):
+        * NetworkProcess/NetworkSession.cpp:
+        (WebKit::NetworkSession::networkStorageSession const):
+        * NetworkProcess/NetworkStorageSessionProvider.h:
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::makeUseDecision):
+        (WebKit::NetworkCache::Cache::retrieve):
+        (WebKit::NetworkCache::Cache::makeEntry):
+        (WebKit::NetworkCache::Cache::makeRedirectEntry):
+        (WebKit::NetworkCache::Cache::update):
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
+        (WebKit::NetworkCache::SpeculativeLoad::willSendRedirectedRequest):
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformSyncAllCookies):
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]):
+        (-[WKNetworkSessionDelegate URLSession:task:_schemeUpgraded:completionHandler:]):
+        (-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
+        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
+        * SourcesCocoa.txt:
+        * UIProcess/API/APIHTTPCookieStore.cpp:
+        (API::HTTPCookieStore::~HTTPCookieStore):
+        (API::HTTPCookieStore::cookies):
+        (API::HTTPCookieStore::setCookie):
+        (API::HTTPCookieStore::deleteCookie):
+        (API::HTTPCookieStore::registerObserver):
+        (API::HTTPCookieStore::unregisterObserver):
+        (API::HTTPCookieStore::registerForNewProcessPoolNotifications):
+        (API::HTTPCookieStore::flushDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::getAllDefaultUIProcessCookieStoreCookies):
+        (API::HTTPCookieStore::setCookieInDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::deleteCookieFromDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::startObservingChangesToDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::stopObservingChangesToDefaultUIProcessCookieStore):
+        * UIProcess/API/APIHTTPCookieStore.h:
+        * UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm: Added.
+        (API::HTTPCookieStore::flushDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::getAllDefaultUIProcessCookieStoreCookies):
+        (API::HTTPCookieStore::setCookieInDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::deleteCookieFromDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::startObservingChangesToDefaultUIProcessCookieStore):
+        (API::HTTPCookieStore::stopObservingChangesToDefaultUIProcessCookieStore):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::clearCachedCredentials):
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::getAuthenticationInfo):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::deleteWebsiteData):
+        (WebKit::WebProcess::clearCachedCredentials): Deleted.
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2019-01-22  Per Arne Vollan  <pvollan@apple.com>
 
         [macOS] Adjust logging policy in WebKit's sandbox
index 1fb415e..5ebeac3 100644 (file)
@@ -46,7 +46,7 @@ const char* WebCookieManager::supplementName()
     return "WebCookieManager";
 }
 
-WebCookieManager::WebCookieManager(ChildProcess& process)
+WebCookieManager::WebCookieManager(NetworkProcess& process)
     : m_process(process)
 {
     m_process.addMessageReceiver(Messages::WebCookieManager::messageReceiverName(), *this);
@@ -57,7 +57,7 @@ WebCookieManager::~WebCookieManager() = default;
 void WebCookieManager::getHostnamesWithCookies(PAL::SessionID sessionID, CallbackID callbackID)
 {
     HashSet<String> hostnames;
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->getHostnamesWithCookies(hostnames);
 
     m_process.send(Messages::WebCookieManagerProxy::DidGetHostnamesWithCookies(copyToVector(hostnames), callbackID), 0);
@@ -65,20 +65,20 @@ void WebCookieManager::getHostnamesWithCookies(PAL::SessionID sessionID, Callbac
 
 void WebCookieManager::deleteCookiesForHostname(PAL::SessionID sessionID, const String& hostname)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->deleteCookiesForHostnames({ hostname });
 }
 
 
 void WebCookieManager::deleteAllCookies(PAL::SessionID sessionID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->deleteAllCookies();
 }
 
 void WebCookieManager::deleteCookie(PAL::SessionID sessionID, const Cookie& cookie, CallbackID callbackID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->deleteCookie(cookie);
 
     m_process.send(Messages::WebCookieManagerProxy::DidDeleteCookies(callbackID), 0);
@@ -86,7 +86,7 @@ void WebCookieManager::deleteCookie(PAL::SessionID sessionID, const Cookie& cook
 
 void WebCookieManager::deleteAllCookiesModifiedSince(PAL::SessionID sessionID, WallTime time, CallbackID callbackID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->deleteAllCookiesModifiedSince(time);
 
     m_process.send(Messages::WebCookieManagerProxy::DidDeleteCookies(callbackID), 0);
@@ -95,7 +95,7 @@ void WebCookieManager::deleteAllCookiesModifiedSince(PAL::SessionID sessionID, W
 void WebCookieManager::getAllCookies(PAL::SessionID sessionID, CallbackID callbackID)
 {
     Vector<Cookie> cookies;
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         cookies = storageSession->getAllCookies();
 
     m_process.send(Messages::WebCookieManagerProxy::DidGetCookies(cookies, callbackID), 0);
@@ -104,7 +104,7 @@ void WebCookieManager::getAllCookies(PAL::SessionID sessionID, CallbackID callba
 void WebCookieManager::getCookies(PAL::SessionID sessionID, const URL& url, CallbackID callbackID)
 {
     Vector<Cookie> cookies;
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         cookies = storageSession->getCookies(url);
 
     m_process.send(Messages::WebCookieManagerProxy::DidGetCookies(cookies, callbackID), 0);
@@ -112,7 +112,7 @@ void WebCookieManager::getCookies(PAL::SessionID sessionID, const URL& url, Call
 
 void WebCookieManager::setCookie(PAL::SessionID sessionID, const Cookie& cookie, CallbackID callbackID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->setCookie(cookie);
 
     m_process.send(Messages::WebCookieManagerProxy::DidSetCookies(callbackID), 0);
@@ -120,7 +120,7 @@ void WebCookieManager::setCookie(PAL::SessionID sessionID, const Cookie& cookie,
 
 void WebCookieManager::setCookies(PAL::SessionID sessionID, const Vector<Cookie>& cookies, const URL& url, const URL& mainDocumentURL, CallbackID callbackID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         storageSession->setCookies(cookies, url, mainDocumentURL);
 
     m_process.send(Messages::WebCookieManagerProxy::DidSetCookies(callbackID), 0);
@@ -134,7 +134,7 @@ void WebCookieManager::notifyCookiesDidChange(PAL::SessionID sessionID)
 
 void WebCookieManager::startObservingCookieChanges(PAL::SessionID sessionID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID)) {
+    if (auto* storageSession = m_process.storageSession(sessionID)) {
         WebCore::startObservingCookieChanges(*storageSession, [this, sessionID] {
             notifyCookiesDidChange(sessionID);
         });
@@ -143,7 +143,7 @@ void WebCookieManager::startObservingCookieChanges(PAL::SessionID sessionID)
 
 void WebCookieManager::stopObservingCookieChanges(PAL::SessionID sessionID)
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = m_process.storageSession(sessionID))
         WebCore::stopObservingCookieChanges(*storageSession);
 }
 
index 523fdbe..88722e7 100644 (file)
@@ -45,12 +45,12 @@ struct Cookie;
 
 namespace WebKit {
 
-class ChildProcess;
+class NetworkProcess;
 
 class WebCookieManager : public NetworkProcessSupplement, public IPC::MessageReceiver {
     WTF_MAKE_NONCOPYABLE(WebCookieManager);
 public:
-    WebCookieManager(ChildProcess&);
+    WebCookieManager(NetworkProcess&);
     ~WebCookieManager();
 
     static const char* supplementName();
@@ -86,7 +86,7 @@ private:
     void startObservingCookieChanges(PAL::SessionID);
     void stopObservingCookieChanges(PAL::SessionID);
 
-    ChildProcess& m_process;
+    NetworkProcess& m_process;
 };
 
 } // namespace WebKit
index 0ca4260..7148e71 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "WebCookieManager.h"
 
+#import "NetworkProcess.h"
 #import "NetworkSession.h"
 #import <WebCore/NetworkStorageSession.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
@@ -40,7 +41,7 @@ void WebCookieManager::platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy
 
     [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:static_cast<NSHTTPCookieAcceptPolicy>(policy)];
 
-    NetworkStorageSession::forEach([&] (const NetworkStorageSession& networkStorageSession) {
+    m_process.forEachNetworkStorageSession([&] (const auto& networkStorageSession) {
         if (auto cookieStorage = networkStorageSession.cookieStorage())
             CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
     });
index aa68499..1e34baf 100644 (file)
@@ -27,6 +27,7 @@
 #include "WebCookieManager.h"
 
 #include "ChildProcess.h"
+#include "NetworkProcess.h"
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
@@ -51,14 +52,14 @@ void WebCookieManager::platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy
         break;
     }
 
-    NetworkStorageSession::forEach([soupPolicy] (const NetworkStorageSession& session) {
+    m_process.forEachNetworkStorageSession([soupPolicy] (const auto& session) {
         soup_cookie_jar_set_accept_policy(session.cookieStorage(), soupPolicy);
     });
 }
 
 HTTPCookieAcceptPolicy WebCookieManager::platformGetHTTPCookieAcceptPolicy()
 {
-    switch (soup_cookie_jar_get_accept_policy(NetworkStorageSession::defaultStorageSession().cookieStorage())) {
+    switch (soup_cookie_jar_get_accept_policy(m_process.defaultStorageSession().cookieStorage())) {
     case SOUP_COOKIE_JAR_ACCEPT_ALWAYS:
         return HTTPCookieAcceptPolicyAlways;
     case SOUP_COOKIE_JAR_ACCEPT_NEVER:
@@ -85,7 +86,7 @@ void WebCookieManager::setCookiePersistentStorage(const String& storagePath, uin
         ASSERT_NOT_REACHED();
     }
 
-    auto& storageSession = NetworkStorageSession::defaultStorageSession();
+    auto& storageSession = m_process.defaultStorageSession();
     soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(storageSession.cookieStorage()));
     storageSession.setCookieStorage(jar.get());
 }
index af2cbc0..dc79eeb 100644 (file)
@@ -96,6 +96,8 @@ public:
 
 #if PLATFORM(COCOA)
     void registerProtocolClass(NSURLSessionConfiguration*);
+#endif
+#if PLATFORM(COCOA) || USE(SOUP)
     static void networkProcessCreated(NetworkProcess&);
 #endif
 
index 5bfa50e..c585bf7 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
+RefPtr<NetworkProcess>& lastCreatedNetworkProcess()
+{
+    static NeverDestroyed<RefPtr<NetworkProcess>> networkProcess;
+    return networkProcess.get();
+}
+
+void LegacyCustomProtocolManager::networkProcessCreated(NetworkProcess& networkProcess)
+{
+    lastCreatedNetworkProcess() = &networkProcess;
+}
+
 LegacyCustomProtocolManager::WebSoupRequestAsyncData::WebSoupRequestAsyncData(GRefPtr<GTask>&& requestTask, WebKitSoupRequestGeneric* requestGeneric)
     : task(WTFMove(requestTask))
     , request(requestGeneric)
@@ -91,7 +102,7 @@ void LegacyCustomProtocolManager::registerScheme(const String& scheme)
     auto* genericRequestClass = static_cast<SoupRequestClass*>(g_type_class_peek(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
     ASSERT(genericRequestClass);
     genericRequestClass->schemes = const_cast<const char**>(reinterpret_cast<char**>(m_registeredSchemes->pdata));
-    NetworkStorageSession::forEach([](const WebCore::NetworkStorageSession& session) {
+    lastCreatedNetworkProcess()->forEachNetworkStorageSession([](const auto& session) {
         if (auto* soupSession = session.soupNetworkSession())
             soupSession->setupCustomProtocols();
     });
index 0666b1e..e634147 100644 (file)
@@ -408,18 +408,18 @@ void NetworkConnectionToWebProcess::didFinishPreconnection(uint64_t preconnectio
     m_connection->send(Messages::NetworkProcessConnection::DidFinishPreconnection(preconnectionIdentifier, error), 0);
 }
 
-static NetworkStorageSession& storageSession(PAL::SessionID sessionID)
+static NetworkStorageSession& storageSession(const NetworkProcess& networkProcess, PAL::SessionID sessionID)
 {
     ASSERT(sessionID.isValid());
     if (sessionID != PAL::SessionID::defaultSessionID()) {
-        if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* storageSession = networkProcess.storageSession(sessionID))
             return *storageSession;
 
         // 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("Non-default storage session 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.");
     }
-    return NetworkStorageSession::defaultStorageSession();
+    return networkProcess.defaultStorageSession();
 }
 
 void NetworkConnectionToWebProcess::startDownload(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedName)
@@ -448,7 +448,7 @@ void NetworkConnectionToWebProcess::convertMainResourceLoadToDownload(PAL::Sessi
 
 void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
 {
-    auto& networkStorageSession = storageSession(sessionID);
+    auto& networkStorageSession = storageSession(networkProcess(), sessionID);
     std::tie(cookieString, secureCookiesAccessed) = networkStorageSession.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
     if (auto session = networkProcess().networkSession(sessionID)) {
@@ -460,7 +460,7 @@ void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, cons
 
 void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, const String& cookieString)
 {
-    auto& networkStorageSession = storageSession(sessionID);
+    auto& networkStorageSession = storageSession(networkProcess(), sessionID);
     networkStorageSession.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
     if (auto session = networkProcess().networkSession(sessionID)) {
@@ -472,22 +472,22 @@ void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID,
 
 void NetworkConnectionToWebProcess::cookiesEnabled(PAL::SessionID sessionID, bool& result)
 {
-    result = storageSession(sessionID).cookiesEnabled();
+    result = storageSession(networkProcess(), sessionID).cookiesEnabled();
 }
 
 void NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
 {
-    std::tie(cookieString, secureCookiesAccessed) = storageSession(sessionID).cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    std::tie(cookieString, secureCookiesAccessed) = storageSession(networkProcess(), sessionID).cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 void NetworkConnectionToWebProcess::getRawCookies(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, Vector<Cookie>& result)
 {
-    storageSession(sessionID).getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, result);
+    storageSession(networkProcess(), sessionID).getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, result);
 }
 
 void NetworkConnectionToWebProcess::deleteCookie(PAL::SessionID sessionID, const URL& url, const String& cookieName)
 {
-    storageSession(sessionID).deleteCookie(url, cookieName);
+    storageSession(networkProcess(), sessionID).deleteCookie(url, cookieName);
 }
 
 void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, SandboxExtension::Handle&& extensionHandle, const String& contentType)
@@ -562,7 +562,7 @@ void NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession()
 void NetworkConnectionToWebProcess::removeStorageAccessForFrame(PAL::SessionID sessionID, uint64_t frameID, uint64_t pageID)
 {
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = networkProcess().storageSession(sessionID))
         storageSession->removeStorageAccessForFrame(frameID, pageID);
 #else
     UNUSED_PARAM(sessionID);
@@ -574,7 +574,7 @@ void NetworkConnectionToWebProcess::removeStorageAccessForFrame(PAL::SessionID s
 void NetworkConnectionToWebProcess::removeStorageAccessForAllFramesOnPage(PAL::SessionID sessionID, uint64_t pageID)
 {
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
-    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* storageSession = networkProcess().storageSession(sessionID))
         storageSession->removeStorageAccessForAllFramesOnPage(pageID);
 #else
     UNUSED_PARAM(sessionID);
index 2a98b30..92441ec 100644 (file)
 #include "NetworkSessionCocoa.h"
 #endif
 
+#if USE(SOUP)
+#include <WebCore/DNSResolveQueueSoup.h>
+#endif
+
 #if ENABLE(SERVICE_WORKER)
 #include "WebSWServerToContextConnectionMessages.h"
 #endif
@@ -142,14 +146,21 @@ NetworkProcess::NetworkProcess()
     addSupplement<WebCookieManager>();
 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
     addSupplement<LegacyCustomProtocolManager>();
-#if PLATFORM(COCOA)
-    LegacyCustomProtocolManager::networkProcessCreated(*this);
 #endif
+#if PLATFORM(COCOA) || USE(SOUP)
+    LegacyCustomProtocolManager::networkProcessCreated(*this);
 #endif
 #if ENABLE(PROXIMITY_NETWORKING)
     addSupplement<NetworkProximityManager>();
 #endif
 
+#if USE(SOUP)
+    DNSResolveQueueSoup::setGlobalDefaultNetworkStorageSessionAccessor([this] {
+        return defaultStorageSession();
+    });
+    defaultStorageSession().clearSoupNetworkSessionAndCookieStorage();
+#endif
+
     NetworkStateNotifier::singleton().addListener([this](bool isOnLine) {
         auto webProcessConnections = m_webProcessConnections;
         for (auto& webProcessConnection : webProcessConnections)
@@ -302,7 +313,7 @@ void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&&
     setCanHandleHTTPSServerTrustEvaluation(parameters.canHandleHTTPSServerTrustEvaluation);
 
     if (parameters.shouldUseTestingNetworkSession)
-        NetworkStorageSession::switchToNewTestingSession();
+        switchToNewTestingSession();
 
     SandboxExtension::consumePermanently(parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsDirectoryExtensionHandle);
 
@@ -436,7 +447,7 @@ void NetworkProcess::createNetworkConnectionToWebProcess(bool isServiceWorkerPro
 
 void NetworkProcess::clearCachedCredentials()
 {
-    NetworkStorageSession::defaultStorageSession().credentialStorage().clearCredentials();
+    defaultStorageSession().credentialStorage().clearCredentials();
     if (auto* networkSession = this->networkSession(PAL::SessionID::defaultSessionID()))
         networkSession->clearCredentials();
     else
@@ -457,6 +468,78 @@ void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters
     RemoteNetworkingContext::ensureWebsiteDataStoreSession(*this, WTFMove(parameters));
 }
 
+void NetworkProcess::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()));
+
+    auto session = adoptCF(WebCore::createPrivateStorageSession(sessionName.createCFString().get()));
+
+#if PLATFORM(COCOA)
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
+    if (WebCore::NetworkStorageSession::processMayUseCookieAPI()) {
+        ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+        if (session)
+            cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, session.get()));
+    }
+
+    m_defaultNetworkStorageSession = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID(), WTFMove(session), WTFMove(cookieStorage));
+#elif USE(SOUP)
+    m_defaultNetworkStorageSession = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID(), std::make_unique<WebCore::SoupNetworkSession>());
+#endif
+}
+
+#if PLATFORM(COCOA)
+void NetworkProcess::ensureSession(const PAL::SessionID& sessionID, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&& cookieStorage)
+#else
+void NetworkProcess::ensureSession(const PAL::SessionID& sessionID, const String& identifierBase)
+#endif
+{
+    auto addResult = m_networkStorageSessions.add(sessionID, nullptr);
+    if (!addResult.isNewEntry)
+        return;
+
+#if PLATFORM(COCOA)
+    RetainPtr<CFURLStorageSessionRef> storageSession;
+    RetainPtr<CFStringRef> cfIdentifier = String(identifierBase + ".PrivateBrowsing").createCFString();
+    if (sessionID.isEphemeral())
+        storageSession = adoptCF(createPrivateStorageSession(cfIdentifier.get()));
+    else
+        storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(cfIdentifier.get());
+
+    if (NetworkStorageSession::processMayUseCookieAPI()) {
+        ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+        if (!cookieStorage && storageSession)
+            cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
+    }
+
+    addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
+#elif USE(SOUP)
+    addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, std::make_unique<SoupNetworkSession>(sessionID));
+#endif
+}
+
+WebCore::NetworkStorageSession* NetworkProcess::storageSession(const PAL::SessionID& sessionID) const
+{
+    if (sessionID == PAL::SessionID::defaultSessionID())
+        return &defaultStorageSession();
+    return m_networkStorageSessions.get(sessionID);
+}
+
+WebCore::NetworkStorageSession& NetworkProcess::defaultStorageSession() const
+{
+    if (!m_defaultNetworkStorageSession)
+        m_defaultNetworkStorageSession = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID());
+    return *m_defaultNetworkStorageSession;
+}
+
+void NetworkProcess::forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>& functor)
+{
+    functor(defaultStorageSession());
+    for (auto& storageSession : m_networkStorageSessions.values())
+        functor(*storageSession);
+}
+
 NetworkSession* NetworkProcess::networkSession(const PAL::SessionID& sessionID) const
 {
     return m_networkSessions.get(sessionID);
@@ -471,7 +554,7 @@ void NetworkProcess::destroySession(const PAL::SessionID& sessionID)
 {
     if (auto session = m_networkSessions.take(sessionID))
         session->get().invalidateAndCancel();
-    NetworkStorageSession::destroySession(sessionID);
+    m_networkStorageSessions.remove(sessionID);
     m_sessionsControlledByAutomation.remove(sessionID);
     CacheStorage::Engine::destroyEngine(*this, sessionID);
 
@@ -511,7 +594,7 @@ void NetworkProcess::dumpResourceLoadStatistics(PAL::SessionID sessionID, uint64
 
 void NetworkProcess::updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID sessionID, const Vector<String>& domainsToBlock, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         networkStorageSession->setPrevalentDomainsToBlockCookiesFor(domainsToBlock);
     parentProcessConnection()->send(Messages::NetworkProcessProxy::DidUpdateBlockCookies(contextId), 0);
 }
@@ -545,7 +628,7 @@ void NetworkProcess::isVeryPrevalentResource(PAL::SessionID sessionID, const Str
 
 void NetworkProcess::setAgeCapForClientSideCookies(PAL::SessionID sessionID, Optional<Seconds> seconds, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         networkStorageSession->setAgeCapForClientSideCookies(seconds);
     parentProcessConnection()->send(Messages::NetworkProcessProxy::DidSetAgeCapForClientSideCookies(contextId), 0);
 }
@@ -756,7 +839,7 @@ void NetworkProcess::setLastSeen(PAL::SessionID sessionID, const String& resourc
 
 void NetworkProcess::hasStorageAccessForFrame(PAL::SessionID sessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         parentProcessConnection()->send(Messages::NetworkProcessProxy::StorageAccessOperationResult(networkStorageSession->hasStorageAccess(resourceDomain, firstPartyDomain, frameID, pageID), contextId), 0);
     else
         ASSERT_NOT_REACHED();
@@ -764,7 +847,7 @@ void NetworkProcess::hasStorageAccessForFrame(PAL::SessionID sessionID, const St
 
 void NetworkProcess::getAllStorageAccessEntries(PAL::SessionID sessionID, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         parentProcessConnection()->send(Messages::NetworkProcessProxy::AllStorageAccessEntriesResult(networkStorageSession->getAllStorageAccessEntries(), contextId), 0);
     else
         ASSERT_NOT_REACHED();
@@ -794,7 +877,7 @@ void NetworkProcess::requestStorageAccess(PAL::SessionID sessionID, const String
 void NetworkProcess::grantStorageAccess(PAL::SessionID sessionID, const String& resourceDomain, const String& firstPartyDomain, Optional<uint64_t> frameID, uint64_t pageID, bool userWasPrompted, uint64_t contextId)
 {
     bool isStorageGranted = false;
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID)) {
+    if (auto* networkStorageSession = storageSession(sessionID)) {
         networkStorageSession->grantStorageAccess(resourceDomain, firstPartyDomain, frameID, pageID);
         ASSERT(networkStorageSession->hasStorageAccess(resourceDomain, firstPartyDomain, frameID, pageID));
         isStorageGranted = true;
@@ -843,7 +926,7 @@ void NetworkProcess::clearUserInteraction(PAL::SessionID sessionID, const String
 
 void NetworkProcess::removeAllStorageAccess(PAL::SessionID sessionID, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         networkStorageSession->removeAllStorageAccess();
     else
         ASSERT_NOT_REACHED();
@@ -852,13 +935,13 @@ void NetworkProcess::removeAllStorageAccess(PAL::SessionID sessionID, uint64_t c
 
 void NetworkProcess::removePrevalentDomains(PAL::SessionID sessionID, const Vector<String>& domains)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         networkStorageSession->removePrevalentDomains(domains);
 }
 
 void NetworkProcess::setCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, Seconds seconds, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         networkStorageSession->setCacheMaxAgeCapForPrevalentResources(Seconds { seconds });
     else
         ASSERT_NOT_REACHED();
@@ -936,7 +1019,7 @@ void NetworkProcess::setResourceLoadStatisticsDebugMode(PAL::SessionID sessionID
 
 void NetworkProcess::resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, uint64_t contextId)
 {
-    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+    if (auto* networkStorageSession = storageSession(sessionID))
         networkStorageSession->resetCacheMaxAgeCapForPrevalentResources();
     else
         ASSERT_NOT_REACHED();
@@ -1013,13 +1096,13 @@ void NetworkProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websit
     }));
 
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             networkStorageSession->getHostnamesWithCookies(callbackAggregator->m_websiteData.hostNamesWithCookies);
     }
 
     if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
-        if (NetworkStorageSession::storageSession(sessionID))
-            callbackAggregator->m_websiteData.originsWithCredentials = NetworkStorageSession::storageSession(sessionID)->credentialStorage().originsWithCredentials();
+        if (storageSession(sessionID))
+            callbackAggregator->m_websiteData.originsWithCredentials = storageSession(sessionID)->credentialStorage().originsWithCredentials();
     }
 
     if (websiteDataTypes.contains(WebsiteDataType::DOMCache)) {
@@ -1030,7 +1113,7 @@ void NetworkProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websit
 
 #if PLATFORM(COCOA)
     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             getHostNamesWithHSTSCache(*networkStorageSession, callbackAggregator->m_websiteData.hostNamesWithHSTSCache);
     }
 #endif
@@ -1069,19 +1152,19 @@ void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<Websi
 {
 #if PLATFORM(COCOA)
     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             clearHSTSCache(*networkStorageSession, modifiedSince);
     }
 #endif
 
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             networkStorageSession->deleteAllCookiesModifiedSince(modifiedSince);
     }
 
     if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
-        if (NetworkStorageSession::storageSession(sessionID))
-            NetworkStorageSession::storageSession(sessionID)->credentialStorage().clearCredentials();
+        if (auto* session = storageSession(sessionID))
+            session->credentialStorage().clearCredentials();
     }
 
     auto clearTasksHandler = WTF::CallbackAggregator::create([this, callbackID] {
@@ -1149,13 +1232,13 @@ static void clearDiskCacheEntries(NetworkCache::Cache* cache, const Vector<Secur
 void NetworkProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, const Vector<SecurityOriginData>& originDatas, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostNames, uint64_t callbackID)
 {
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             networkStorageSession->deleteCookiesForHostnames(cookieHostNames);
     }
 
 #if PLATFORM(COCOA)
     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             deleteHSTSCacheForHostNames(*networkStorageSession, HSTSCacheHostNames);
     }
 #endif
@@ -1253,7 +1336,7 @@ void NetworkProcess::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersi
 
     Vector<String> hostnamesWithCookiesToDelete;
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID)) {
+        if (auto* networkStorageSession = storageSession(sessionID)) {
             networkStorageSession->getHostnamesWithCookies(websiteDataStore.hostNamesWithCookies);
             hostnamesWithCookiesToDelete = filterForTopLevelDomains(topPrivatelyControlledDomains, websiteDataStore.hostNamesWithCookies);
             networkStorageSession->deleteCookiesForHostnames(hostnamesWithCookiesToDelete);
@@ -1263,7 +1346,7 @@ void NetworkProcess::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersi
     Vector<String> hostnamesWithHSTSToDelete;
 #if PLATFORM(COCOA)
     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID)) {
+        if (auto* networkStorageSession = storageSession(sessionID)) {
             getHostNamesWithHSTSCache(*networkStorageSession, websiteDataStore.hostNamesWithHSTSCache);
             hostnamesWithHSTSToDelete = filterForTopLevelDomains(topPrivatelyControlledDomains, websiteDataStore.hostNamesWithHSTSCache);
             deleteHSTSCacheForHostNames(*networkStorageSession, hostnamesWithHSTSToDelete);
@@ -1274,8 +1357,8 @@ void NetworkProcess::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersi
     /*
     // FIXME: No API to delete credentials by origin
     if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
-        if (NetworkStorageSession::storageSession(sessionID))
-            websiteDataStore.originsWithCredentials = NetworkStorageSession::storageSession(sessionID)->credentialStorage().originsWithCredentials();
+        if (storageSession(sessionID))
+            websiteDataStore.originsWithCredentials = storageSession(sessionID)->credentialStorage().originsWithCredentials();
     }
     */
     
@@ -1385,21 +1468,21 @@ void NetworkProcess::topPrivatelyControlledDomainsWithWebsiteData(PAL::SessionID
     
     Vector<String> hostnamesWithCookiesToDelete;
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             networkStorageSession->getHostnamesWithCookies(websiteDataStore.hostNamesWithCookies);
     }
     
     Vector<String> hostnamesWithHSTSToDelete;
 #if PLATFORM(COCOA)
     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
-        if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        if (auto* networkStorageSession = storageSession(sessionID))
             getHostNamesWithHSTSCache(*networkStorageSession, websiteDataStore.hostNamesWithHSTSCache);
     }
 #endif
 
     if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
-        if (NetworkStorageSession::storageSession(sessionID))
-            websiteDataStore.originsWithCredentials = NetworkStorageSession::storageSession(sessionID)->credentialStorage().originsWithCredentials();
+        if (auto* networkStorageSession = storageSession(sessionID))
+            websiteDataStore.originsWithCredentials = networkStorageSession->credentialStorage().originsWithCredentials();
     }
     
     if (websiteDataTypes.contains(WebsiteDataType::DOMCache)) {
index 59794a2..afbebbd 100644 (file)
 #include <wtf/RetainPtr.h>
 #include <wtf/WeakPtr.h>
 
+#if PLATFORM(COCOA)
+typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
+#endif
+
 namespace IPC {
 class FormDataReference;
 }
@@ -132,6 +136,16 @@ public:
     NetworkSession* networkSession(const PAL::SessionID&) const override;
     void destroySession(const PAL::SessionID&);
     
+    void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
+    WebCore::NetworkStorageSession* storageSession(const PAL::SessionID&) const;
+    WebCore::NetworkStorageSession& defaultStorageSession() const;
+    void switchToNewTestingSession();
+#if PLATFORM(COCOA)
+    void ensureSession(const PAL::SessionID&, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
+#else
+    void ensureSession(const PAL::SessionID&, const String& identifier);
+#endif
+
     bool canHandleHTTPSServerTrustEvaluation() const { return m_canHandleHTTPSServerTrustEvaluation; }
 
     void processWillSuspendImminently(bool& handled);
@@ -426,6 +440,8 @@ private:
     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
     HashMap<PAL::SessionID, Vector<CacheStorageParametersCallback>> m_cacheStorageParametersCallbacks;
     HashMap<PAL::SessionID, Ref<NetworkSession>> m_networkSessions;
+    HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
+    mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
 
 #if PLATFORM(COCOA)
     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
index d48efb1..9df0d76 100644 (file)
@@ -609,7 +609,7 @@ Optional<Seconds> NetworkResourceLoader::validateCacheEntryForMaxAgeCapValidatio
     }
     
     if (!existingCacheEntryMatchesNewResponse) {
-        if (auto networkStorageSession = WebCore::NetworkStorageSession::storageSession(sessionID()))
+        if (auto* networkStorageSession = m_connection->networkProcess().storageSession(sessionID()))
             return networkStorageSession->maxAgeCacheCap(request);
     }
 #endif
@@ -970,7 +970,7 @@ void NetworkResourceLoader::logCookieInformation() const
 {
     ASSERT(shouldLogCookieInformation(m_connection, sessionID()));
 
-    auto networkStorageSession = WebCore::NetworkStorageSession::storageSession(sessionID());
+    auto* networkStorageSession = m_connection->networkProcess().storageSession(sessionID());
     ASSERT(networkStorageSession);
 
     logCookieInformation(m_connection, "NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, originalRequest().firstPartyForCookies(), SameSiteInfo::create(originalRequest()), originalRequest().url(), originalRequest().httpReferrer(), frameID(), pageID(), identifier());
index 21798a1..ad51538 100644 (file)
@@ -60,7 +60,7 @@ Ref<NetworkSession> NetworkSession::create(NetworkProcess& networkProcess, Netwo
 
 NetworkStorageSession& NetworkSession::networkStorageSession() const
 {
-    auto* storageSession = NetworkStorageSession::storageSession(m_sessionID);
+    auto* storageSession = m_networkProcess->storageSession(m_sessionID);
     RELEASE_ASSERT(storageSession);
     return *storageSession;
 }
index 04ac475..8aa9204 100644 (file)
@@ -45,7 +45,7 @@ private:
     WebCore::NetworkStorageSession* storageSession() const final
     {
         if (m_networkProcess)
-            return WebCore::NetworkStorageSession::storageSession(m_sessionID);
+            return m_networkProcess->storageSession(m_sessionID);
         return nullptr;
     }
 
index 9db7d76..8747ede 100644 (file)
@@ -30,6 +30,7 @@
 #include "NetworkCacheSpeculativeLoadManager.h"
 #include "NetworkCacheStatistics.h"
 #include "NetworkCacheStorage.h"
+#include "NetworkProcess.h"
 #include <WebCore/CacheValidation.h>
 #include <WebCore/FileSystem.h>
 #include <WebCore/HTTPHeaderNames.h>
@@ -184,14 +185,14 @@ static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response,
     return responseHasExpired(response, timestamp, requestDirectives.maxStale);
 }
 
-static UseDecision makeUseDecision(const Entry& entry, const WebCore::ResourceRequest& request)
+static UseDecision makeUseDecision(NetworkProcess& networkProcess, const Entry& entry, const WebCore::ResourceRequest& request)
 {
     // The request is conditional so we force revalidation from the network. We merely check the disk cache
     // so we can update the cache entry.
     if (request.isConditional() && !entry.redirectRequest())
         return UseDecision::Validate;
 
-    if (!WebCore::verifyVaryingRequestHeaders(WebCore::NetworkStorageSession::defaultStorageSession(), entry.varyingRequestHeaders(), request))
+    if (!WebCore::verifyVaryingRequestHeaders(networkProcess.defaultStorageSession(), entry.varyingRequestHeaders(), request))
         return UseDecision::NoDueToVaryingHeaderMismatch;
 
     // We never revalidate in the case of a history navigation.
@@ -305,9 +306,9 @@ void Cache::retrieve(const WebCore::ResourceRequest& request, const GlobalFrameI
 
 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
     if (canUseSpeculativeRevalidation && m_speculativeLoadManager->canRetrieve(storageKey, request, frameID)) {
-        m_speculativeLoadManager->retrieve(storageKey, [request, completionHandler = WTFMove(completionHandler), info = WTFMove(info)](std::unique_ptr<Entry> entry) mutable {
+        m_speculativeLoadManager->retrieve(storageKey, [networkProcess = makeRef(networkProcess()), request, completionHandler = WTFMove(completionHandler), info = WTFMove(info)](std::unique_ptr<Entry> entry) mutable {
             info.wasSpeculativeLoad = true;
-            if (entry && WebCore::verifyVaryingRequestHeaders(WebCore::NetworkStorageSession::defaultStorageSession(), entry->varyingRequestHeaders(), request))
+            if (entry && WebCore::verifyVaryingRequestHeaders(networkProcess->defaultStorageSession(), entry->varyingRequestHeaders(), request))
                 completeRetrieve(WTFMove(completionHandler), WTFMove(entry), info);
             else
                 completeRetrieve(WTFMove(completionHandler), nullptr, info);
@@ -333,7 +334,7 @@ void Cache::retrieve(const WebCore::ResourceRequest& request, const GlobalFrameI
 
         auto entry = Entry::decodeStorageRecord(*record);
 
-        auto useDecision = entry ? makeUseDecision(*entry, request) : UseDecision::NoDueToDecodeFailure;
+        auto useDecision = entry ? makeUseDecision(networkProcess(), *entry, request) : UseDecision::NoDueToDecodeFailure;
         switch (useDecision) {
         case UseDecision::Use:
             break;
@@ -364,12 +365,12 @@ void Cache::completeRetrieve(RetrieveCompletionHandler&& handler, std::unique_pt
     
 std::unique_ptr<Entry> Cache::makeEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData)
 {
-    return std::make_unique<Entry>(makeCacheKey(request), response, WTFMove(responseData), WebCore::collectVaryingRequestHeaders(WebCore::NetworkStorageSession::defaultStorageSession(), request, response));
+    return std::make_unique<Entry>(makeCacheKey(request), response, WTFMove(responseData), WebCore::collectVaryingRequestHeaders(networkProcess().defaultStorageSession(), request, response));
 }
 
 std::unique_ptr<Entry> Cache::makeRedirectEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& redirectRequest)
 {
-    return std::make_unique<Entry>(makeCacheKey(request), response, redirectRequest, WebCore::collectVaryingRequestHeaders(WebCore::NetworkStorageSession::defaultStorageSession(), request, response));
+    return std::make_unique<Entry>(makeCacheKey(request), response, redirectRequest, WebCore::collectVaryingRequestHeaders(networkProcess().defaultStorageSession(), request, response));
 }
 
 std::unique_ptr<Entry> Cache::store(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, Function<void(MappedBody&)>&& completionHandler)
@@ -453,7 +454,7 @@ std::unique_ptr<Entry> Cache::update(const WebCore::ResourceRequest& originalReq
     WebCore::ResourceResponse response = existingEntry.response();
     WebCore::updateResponseHeadersAfterRevalidation(response, validatingResponse);
 
-    auto updateEntry = std::make_unique<Entry>(existingEntry.key(), response, existingEntry.buffer(), WebCore::collectVaryingRequestHeaders(WebCore::NetworkStorageSession::defaultStorageSession(), originalRequest, response));
+    auto updateEntry = std::make_unique<Entry>(existingEntry.key(), response, existingEntry.buffer(), WebCore::collectVaryingRequestHeaders(networkProcess().defaultStorageSession(), originalRequest, response));
     auto updateRecord = updateEntry->encodeAsStorageRecord();
 
     m_storage->store(updateRecord, { });
index 7afaf20..7156fd6 100644 (file)
@@ -74,7 +74,7 @@ void SpeculativeLoad::willSendRedirectedRequest(ResourceRequest&& request, Resou
 
     Optional<Seconds> maxAgeCap;
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
-    if (auto networkStorageSession = WebCore::NetworkStorageSession::storageSession(PAL::SessionID::defaultSessionID()))
+    if (auto* networkStorageSession = m_cache->networkProcess().storageSession(PAL::SessionID::defaultSessionID()))
         maxAgeCap = networkStorageSession->maxAgeCacheCap(request);
 #endif
     m_cacheEntry = m_cache->storeRedirect(request, redirectResponse, redirectRequest, maxAgeCap);
index 7f5928b..839b4a5 100644 (file)
@@ -231,7 +231,7 @@ void NetworkProcess::platformSyncAllCookies(CompletionHandler<void()>&& completi
 
 #if HAVE(FOUNDATION_WITH_SAVE_COOKIES_WITH_COMPLETION_HANDLER)
     RefPtr<CallbackAggregator> callbackAggregator = CallbackAggregator::create(WTFMove(completionHander));
-    WebCore::NetworkStorageSession::forEach([&] (auto& networkStorageSession) {
+    forEachNetworkStorageSession([&] (auto& networkStorageSession) {
         saveCookies(networkStorageSession.nsCookieStorage(), [callbackAggregator] { });
     });
 #else
index 932935d..f6ad49f 100644 (file)
@@ -447,7 +447,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
 
         bool shouldIgnoreHSTS = false;
 #if HAVE(CFNETWORK_WITH_IGNORE_HSTS) && ENABLE(RESOURCE_LOAD_STATISTICS)        
-        shouldIgnoreHSTS = schemeWasUpgradedDueToDynamicHSTS(request) && WebCore::NetworkStorageSession::storageSession(_session->sessionID())->shouldBlockCookies(request, networkDataTask->frameID(), networkDataTask->pageID());
+        shouldIgnoreHSTS = schemeWasUpgradedDueToDynamicHSTS(request) && _session->networkProcess().storageSession(_session->sessionID())->shouldBlockCookies(request, networkDataTask->frameID(), networkDataTask->pageID());
         if (shouldIgnoreHSTS) {
             request = downgradeRequest(request);
             ASSERT([request.URL.scheme isEqualToString:@"http"]);
@@ -480,7 +480,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
     if (auto* networkDataTask = [self existingTask:task]) {
         bool shouldIgnoreHSTS = false;
 #if HAVE(CFNETWORK_WITH_IGNORE_HSTS) && ENABLE(RESOURCE_LOAD_STATISTICS)
-        shouldIgnoreHSTS = schemeWasUpgradedDueToDynamicHSTS(request) && WebCore::NetworkStorageSession::storageSession(_session->sessionID())->shouldBlockCookies(request, networkDataTask->frameID(), networkDataTask->pageID());
+        shouldIgnoreHSTS = schemeWasUpgradedDueToDynamicHSTS(request) && _session->networkProcess().storageSession(_session->sessionID())->shouldBlockCookies(request, networkDataTask->frameID(), networkDataTask->pageID());
         if (shouldIgnoreHSTS) {
             request = downgradeRequest(request);
             ASSERT([request.URL.scheme isEqualToString:@"http"]);
@@ -551,7 +551,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
         WebCore::AuthenticationChallenge authenticationChallenge(challenge);
         auto completionHandlerCopy = Block_copy(completionHandler);
         auto sessionID = _session->sessionID();
-        auto challengeCompletionHandler = [completionHandlerCopy, sessionID, authenticationChallenge, taskIdentifier, partition = networkDataTask->partition()](WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential)
+        auto challengeCompletionHandler = [networkProcess = makeRef(_session->networkProcess()), completionHandlerCopy, sessionID, authenticationChallenge, taskIdentifier, partition = networkDataTask->partition()](WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential)
         {
 #if !LOG_DISABLED
             LOG(NetworkSession, "%llu didReceiveChallenge completionHandler %d", taskIdentifier, disposition);
@@ -568,7 +568,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
                 URL urlToStore;
                 if (authenticationChallenge.failureResponse().httpStatusCode() == 401)
                     urlToStore = authenticationChallenge.failureResponse().url();
-                if (auto storageSession = WebCore::NetworkStorageSession::storageSession(sessionID))
+                if (auto storageSession = networkProcess->storageSession(sessionID))
                     storageSession->credentialStorage().set(partition, nonPersistentCredential, authenticationChallenge.protectionSpace(), urlToStore);
                 else
                     ASSERT_NOT_REACHED();
@@ -916,7 +916,7 @@ NetworkSessionCocoa::NetworkSessionCocoa(NetworkProcess& networkProcess, Network
     configuration._companionProxyPreference = NSURLSessionCompanionProxyPreferencePreferDirectToCloud;
 #endif
 
-    auto* storageSession = WebCore::NetworkStorageSession::storageSession(parameters.sessionID);
+    auto* storageSession = networkProcess.storageSession(parameters.sessionID);
     RELEASE_ASSERT(storageSession);
 
     NSHTTPCookieStorage* cookieStorage;
index 32c2d3e..fc2501e 100644 (file)
@@ -38,10 +38,10 @@ using namespace WebCore;
 void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
 {
     auto sessionID = parameters.networkSessionParameters.sessionID;
-    if (NetworkStorageSession::storageSession(sessionID))
+    if (networkProcess.storageSession(sessionID))
         return;
 
-    NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
+    networkProcess.ensureSession(sessionID, String::number(sessionID.sessionID()));
     networkProcess.setSession(sessionID, NetworkSession::create(networkProcess, WTFMove(parameters.networkSessionParameters)));
 }
 
index 55aebec..f6d6dec 100644 (file)
@@ -44,7 +44,7 @@ using namespace WebCore;
 void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
 {
     auto sessionID = parameters.networkSessionParameters.sessionID;
-    if (NetworkStorageSession::storageSession(sessionID))
+    if (networkProcess.storageSession(sessionID))
         return;
 
     String base = networkProcess.uiProcessBundleIdentifier();
@@ -58,9 +58,9 @@ void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& netw
     if (!sessionID.isEphemeral() && !parameters.uiProcessCookieStorageIdentifier.isEmpty())
         uiProcessCookieStorage = cookieStorageFromIdentifyingData(parameters.uiProcessCookieStorageIdentifier);
 
-    NetworkStorageSession::ensureSession(sessionID, base + '.' + String::number(sessionID.sessionID()), WTFMove(uiProcessCookieStorage));
+    networkProcess.ensureSession(sessionID, base + '.' + String::number(sessionID.sessionID()), WTFMove(uiProcessCookieStorage));
 
-    auto* session = NetworkStorageSession::storageSession(sessionID);
+    auto* session = networkProcess.storageSession(sessionID);
     for (const auto& cookie : parameters.pendingCookies)
         session->setCookie(cookie);
 
index b5598b4..0c5f19f 100644 (file)
@@ -37,7 +37,6 @@ class NetworkProcessMain final: public ChildProcessMainBase {
 public:
     void platformFinalize() override
     {
-        WebCore::NetworkStorageSession::defaultStorageSession().clearSoupNetworkSessionAndCookieStorage();
     }
 };
 
index 882b145..c7ce1d2 100644 (file)
@@ -95,7 +95,7 @@ void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languag
 {
     auto acceptLanguages = buildAcceptLanguages(languages);
     SoupNetworkSession::setInitialAcceptLanguages(acceptLanguages);
-    NetworkStorageSession::forEach([&acceptLanguages](const WebCore::NetworkStorageSession& session) {
+    forEachNetworkStorageSession([&acceptLanguages](const auto& session) {
         if (auto* soupSession = session.soupNetworkSession())
             soupSession->setAcceptLanguages(acceptLanguages);
     });
@@ -168,7 +168,7 @@ void NetworkProcess::platformTerminate()
 void NetworkProcess::setNetworkProxySettings(const SoupNetworkProxySettings& settings)
 {
     SoupNetworkSession::setProxySettings(settings);
-    NetworkStorageSession::forEach([](const NetworkStorageSession& session) {
+    forEachNetworkStorageSession([](const auto& session) {
         if (auto* soupSession = session.soupNetworkSession())
             soupSession->setupProxy();
     });
index 487221d..60fca87 100644 (file)
@@ -46,7 +46,7 @@ NetworkSessionSoup::NetworkSessionSoup(NetworkProcess& networkProcess, NetworkSe
 
 NetworkSessionSoup::~NetworkSessionSoup()
 {
-    if (auto* storageSession = NetworkStorageSession::storageSession(m_sessionID))
+    if (auto* storageSession = networkProcess().storageSession(m_sessionID))
         storageSession->setCookieObserverHandler(nullptr);
 }
 
index 59ef32a..0f6c9d1 100644 (file)
@@ -38,10 +38,10 @@ using namespace WebCore;
 void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
 {
     auto sessionID = parameters.networkSessionParameters.sessionID;
-    if (NetworkStorageSession::storageSession(sessionID))
+    if (networkProcess.storageSession(sessionID))
         return;
 
-    NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
+    networkProcess.ensureSession(sessionID, String::number(sessionID.sessionID()));
     networkProcess.setSession(sessionID, NetworkSession::create(networkProcess, WTFMove(parameters.networkSessionParameters)));
 }
 
index 5dee761..66964cd 100644 (file)
@@ -255,6 +255,7 @@ UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm
 UIProcess/API/Cocoa/_WKWebsitePolicies.mm
 UIProcess/API/Cocoa/APIAttachmentCocoa.mm
 UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm
+UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm
 UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm
 UIProcess/API/Cocoa/APIWebsiteDataStoreCocoa.mm
 UIProcess/API/Cocoa/LegacyBundleForClass.mm
index ad92157..42fc6ac 100644 (file)
@@ -49,71 +49,70 @@ HTTPCookieStore::~HTTPCookieStore()
     ASSERT(m_observers.isEmpty());
     ASSERT(!m_observedCookieManagerProxy);
     ASSERT(!m_cookieManagerProxyObserver);
-    ASSERT(!m_observingUIProcessCookies);
 
     unregisterForNewProcessPoolNotifications();
 }
 
-void HTTPCookieStore::cookies(Function<void(const Vector<WebCore::Cookie>&)>&& completionHandler)
+void HTTPCookieStore::cookies(CompletionHandler<void(const Vector<WebCore::Cookie>&)>&& completionHandler)
 {
     auto* pool = m_owningDataStore->processPoolForCookieStorageOperations();
     if (!pool) {
         Vector<WebCore::Cookie> allCookies;
         if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID())
-            allCookies = WebCore::NetworkStorageSession::defaultStorageSession().getAllCookies();
+            allCookies = getAllDefaultUIProcessCookieStoreCookies();
         allCookies.appendVector(m_owningDataStore->pendingCookies());
 
-        callOnMainThread([completionHandler = WTFMove(completionHandler), allCookies]() {
+        callOnMainThread([completionHandler = WTFMove(completionHandler), allCookies] () mutable {
             completionHandler(allCookies);
         });
         return;
     }
 
     auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
-    cookieManager->getAllCookies(m_owningDataStore->sessionID(), [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](const Vector<WebCore::Cookie>& cookies, CallbackBase::Error error) {
+    cookieManager->getAllCookies(m_owningDataStore->sessionID(), [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)] (const Vector<WebCore::Cookie>& cookies, CallbackBase::Error error) mutable {
         completionHandler(cookies);
     });
 }
 
-void HTTPCookieStore::setCookie(const WebCore::Cookie& cookie, Function<void ()>&& completionHandler)
+void HTTPCookieStore::setCookie(const WebCore::Cookie& cookie, CompletionHandler<void()>&& completionHandler)
 {
     auto* pool = m_owningDataStore->processPoolForCookieStorageOperations();
     if (!pool) {
         // FIXME: pendingCookies used for defaultSession because session cookies cannot be propagated to Network Process with uiProcessCookieStorageIdentifier.
         if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID() && !cookie.session)
-            WebCore::NetworkStorageSession::defaultStorageSession().setCookie(cookie);
+            setCookieInDefaultUIProcessCookieStore(cookie);
         else
             m_owningDataStore->addPendingCookie(cookie);
 
-        callOnMainThread([completionHandler = WTFMove(completionHandler)]() {
+        callOnMainThread([completionHandler = WTFMove(completionHandler)] () mutable {
             completionHandler();
         });
         return;
     }
 
     auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
-    cookieManager->setCookie(m_owningDataStore->sessionID(), cookie, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
+    cookieManager->setCookie(m_owningDataStore->sessionID(), cookie, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)] (CallbackBase::Error error) mutable {
         completionHandler();
     });
 }
 
-void HTTPCookieStore::deleteCookie(const WebCore::Cookie& cookie, Function<void ()>&& completionHandler)
+void HTTPCookieStore::deleteCookie(const WebCore::Cookie& cookie, CompletionHandler<void()>&& completionHandler)
 {
     auto* pool = m_owningDataStore->processPoolForCookieStorageOperations();
     if (!pool) {
         if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID() && !cookie.session)
-            WebCore::NetworkStorageSession::defaultStorageSession().deleteCookie(cookie);
+            deleteCookieFromDefaultUIProcessCookieStore(cookie);
         else
             m_owningDataStore->removePendingCookie(cookie);
 
-        callOnMainThread([completionHandler = WTFMove(completionHandler)]() {
+        callOnMainThread([completionHandler = WTFMove(completionHandler)] () mutable {
             completionHandler();
         });
         return;
     }
 
     auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
-    cookieManager->deleteCookie(m_owningDataStore->sessionID(), cookie, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
+    cookieManager->deleteCookie(m_owningDataStore->sessionID(), cookie, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) mutable {
         completionHandler();
     });
 }
@@ -156,12 +155,11 @@ void HTTPCookieStore::registerObserver(Observer& observer)
         ASSERT(!m_observingUIProcessCookies);
 
         // Listen for cookie notifications in the UIProcess in the meantime.
-        WebCore::startObservingCookieChanges(WebCore::NetworkStorageSession::defaultStorageSession(), [this] () {
+        startObservingChangesToDefaultUIProcessCookieStore([this] () {
             cookiesDidChange();
         });
 
         m_observingUIProcessCookies = true;
-
         return;
     }
 
@@ -180,7 +178,7 @@ void HTTPCookieStore::unregisterObserver(Observer& observer)
         m_observedCookieManagerProxy->unregisterObserver(m_owningDataStore->sessionID(), *m_cookieManagerProxyObserver);
 
     if (m_observingUIProcessCookies)
-        WebCore::stopObservingCookieChanges(WebCore::NetworkStorageSession::defaultStorageSession());
+        stopObservingChangesToDefaultUIProcessCookieStore();
 
     if (m_processPoolCreationListenerIdentifier)
         WebProcessPool::unregisterProcessPoolCreationListener(m_processPoolCreationListenerIdentifier);
@@ -221,7 +219,7 @@ void HTTPCookieStore::registerForNewProcessPoolNotifications()
 
         // Now that an associated process pool exists, we need to flush the UI process cookie store
         // to make sure any changes are reflected within the new process pool.
-        WebCore::NetworkStorageSession::defaultStorageSession().flushCookieStore();
+        flushDefaultUIProcessCookieStore();
         newProcessPool.ensureNetworkProcess();
 
         if (m_cookieManagerProxyObserver) {
@@ -240,4 +238,13 @@ void HTTPCookieStore::unregisterForNewProcessPoolNotifications()
     m_processPoolCreationListenerIdentifier = 0;
 }
 
+#if !PLATFORM(COCOA)
+void HTTPCookieStore::flushDefaultUIProcessCookieStore() { }
+Vector<WebCore::Cookie> HTTPCookieStore::getAllDefaultUIProcessCookieStoreCookies() { return { }; }
+void HTTPCookieStore::setCookieInDefaultUIProcessCookieStore(const WebCore::Cookie&) { }
+void HTTPCookieStore::deleteCookieFromDefaultUIProcessCookieStore(const WebCore::Cookie&) { }
+void HTTPCookieStore::startObservingChangesToDefaultUIProcessCookieStore(Function<void()>&&) { }
+void HTTPCookieStore::stopObservingChangesToDefaultUIProcessCookieStore() { }
+#endif
+    
 } // namespace API
index 90fde7d..cfda3e1 100644 (file)
 #include "APIObject.h"
 #include "HTTPCookieAcceptPolicy.h"
 #include <WebCore/Cookie.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/Forward.h>
-#include <wtf/Function.h>
 #include <wtf/HashSet.h>
 
 namespace WebCore {
 struct Cookie;
+class CookieStorageObserver;
 }
 
 namespace WebKit {
@@ -55,9 +56,9 @@ public:
 
     virtual ~HTTPCookieStore();
 
-    void cookies(Function<void (const Vector<WebCore::Cookie>&)>&& completionHandler);
-    void setCookie(const WebCore::Cookie&, Function<void ()>&& completionHandler);
-    void deleteCookie(const WebCore::Cookie&, Function<void ()>&& completionHandler);
+    void cookies(CompletionHandler<void(const Vector<WebCore::Cookie>&)>&&);
+    void setCookie(const WebCore::Cookie&, CompletionHandler<void()>&&);
+    void deleteCookie(const WebCore::Cookie&, CompletionHandler<void()>&&);
 
     class Observer {
     public:
@@ -77,6 +78,13 @@ private:
     void registerForNewProcessPoolNotifications();
     void unregisterForNewProcessPoolNotifications();
 
+    static void flushDefaultUIProcessCookieStore();
+    static Vector<WebCore::Cookie> getAllDefaultUIProcessCookieStoreCookies();
+    static void setCookieInDefaultUIProcessCookieStore(const WebCore::Cookie&);
+    static void deleteCookieFromDefaultUIProcessCookieStore(const WebCore::Cookie&);
+    void startObservingChangesToDefaultUIProcessCookieStore(Function<void()>&&);
+    void stopObservingChangesToDefaultUIProcessCookieStore();
+    
     Ref<WebKit::WebsiteDataStore> m_owningDataStore;
     HashSet<Observer*> m_observers;
 
@@ -85,6 +93,7 @@ private:
     bool m_observingUIProcessCookies { false };
 
     uint64_t m_processPoolCreationListenerIdentifier { 0 };
+    RefPtr<WebCore::CookieStorageObserver> m_defaultUIProcessObserver;
 };
 
 }
diff --git a/Source/WebKit/UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm b/Source/WebKit/UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm
new file mode 100644 (file)
index 0000000..a72d729
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2019 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 "APIHTTPCookieStore.h"
+
+#include <WebCore/Cookie.h>
+#include <WebCore/CookieStorageObserver.h>
+#include <pal/spi/cf/CFNetworkSPI.h>
+
+namespace API {
+
+void HTTPCookieStore::flushDefaultUIProcessCookieStore()
+{
+    [[NSHTTPCookieStorage sharedHTTPCookieStorage] _saveCookies];
+}
+
+Vector<WebCore::Cookie> HTTPCookieStore::getAllDefaultUIProcessCookieStoreCookies()
+{
+    NSArray<NSHTTPCookie *> *cookiesArray = [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies;
+    Vector<WebCore::Cookie> cookiesVector;
+    cookiesVector.reserveInitialCapacity(cookiesArray.count);
+    for (NSHTTPCookie *cookie in cookiesArray)
+        cookiesVector.uncheckedAppend({ cookie });
+    return cookiesVector;
+}
+
+void HTTPCookieStore::setCookieInDefaultUIProcessCookieStore(const WebCore::Cookie& cookie)
+{
+    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
+}
+
+void HTTPCookieStore::deleteCookieFromDefaultUIProcessCookieStore(const WebCore::Cookie& cookie)
+{
+    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
+}
+
+void HTTPCookieStore::startObservingChangesToDefaultUIProcessCookieStore(Function<void()>&& function)
+{
+    stopObservingChangesToDefaultUIProcessCookieStore();
+    m_defaultUIProcessObserver = WebCore::CookieStorageObserver::create([NSHTTPCookieStorage sharedHTTPCookieStorage]);
+    m_defaultUIProcessObserver->startObserving(WTFMove(function));
+}
+
+void HTTPCookieStore::stopObservingChangesToDefaultUIProcessCookieStore()
+{
+    if (auto observer = std::exchange(m_defaultUIProcessObserver, nullptr))
+        observer->stopObserving();
+}
+
+} // namespace API
index 23c58fa..2ca7638 100644 (file)
@@ -1629,7 +1629,6 @@ void WebProcessPool::setAllowsAnySSLCertificateForWebSocket(bool allows)
 
 void WebProcessPool::clearCachedCredentials()
 {
-    sendToAllProcesses(Messages::WebProcess::ClearCachedCredentials());
     if (m_networkProcess)
         m_networkProcess->send(Messages::NetworkProcess::ClearCachedCredentials(), 0);
 }
index 444a62e..959e283 100644 (file)
                5C9EF2E721F058F9003BDC56 /* NetworkStorageSessionProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkStorageSessionProvider.h; sourceTree = "<group>"; };
                5CA26D7F217ABBB600F97A35 /* WKSafeBrowsingWarning.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKSafeBrowsingWarning.mm; sourceTree = "<group>"; };
                5CA26D80217ABBB600F97A35 /* WKSafeBrowsingWarning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSafeBrowsingWarning.h; sourceTree = "<group>"; };
+               5CA46E7A21F1A23900CE86B4 /* APIHTTPCookieStoreCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = APIHTTPCookieStoreCocoa.mm; path = UIProcess/API/Cocoa/APIHTTPCookieStoreCocoa.mm; sourceTree = SOURCE_ROOT; };
                5CA98549210BEB5A0057EB6B /* SafeBrowsingWarning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SafeBrowsingWarning.h; sourceTree = "<group>"; };
                5CA9854B210BEB730057EB6B /* SafeBrowsingWarningCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SafeBrowsingWarningCocoa.mm; sourceTree = "<group>"; };
                5CADDE0D2151AA010067D309 /* AuthenticationChallengeDisposition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AuthenticationChallengeDisposition.h; sourceTree = "<group>"; };
                                5CB2378D1DF0E0C200117AA3 /* _WKWebsitePoliciesInternal.h */,
                                F41056612130699A0092281D /* APIAttachmentCocoa.mm */,
                                7CEFA9601AC0999300B910FD /* APIContentRuleListStoreCocoa.mm */,
+                               5CA46E7A21F1A23900CE86B4 /* APIHTTPCookieStoreCocoa.mm */,
                                FED3C1DA1B447AE800E0EB7F /* APISerializedScriptValueCocoa.mm */,
                                1A3635AB1A3145E500ED6197 /* APIWebsiteDataStoreCocoa.mm */,
                                1AFDE64319510B5500C48FFA /* LegacyBundleForClass.mm */,
index 173fd89..0d7fbe1 100644 (file)
@@ -1602,11 +1602,7 @@ bool PluginView::getAuthenticationInfo(const ProtectionSpace& protectionSpace, S
     if (!contentDocument)
         return false;
 
-    String partitionName = contentDocument->topDocument().domainForCachePartition();
-    Credential credential = NetworkStorageSession::defaultStorageSession().credentialStorage().get(partitionName, protectionSpace);
-    if (credential.isEmpty())
-        credential = NetworkStorageSession::defaultStorageSession().credentialStorage().getFromPersistentStorage(protectionSpace);
-
+    auto credential = CredentialStorage::getFromPersistentStorage(protectionSpace);
     if (!credential.hasPassword())
         return false;
 
index 2dbe46f..1086007 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&)
 {
-    auto sessionID = parameters.networkSessionParameters.sessionID;
-    ASSERT(isMainThread());
-    ASSERT(sessionID.isEphemeral());
-
-    if (NetworkStorageSession::storageSession(sessionID))
-        return;
-
-    // FIXME: Implement to ensure a data storage session.
 }
 
 WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
index 94b6bb7..d3c4803 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&)
 {
-    auto sessionID = parameters.networkSessionParameters.sessionID;
-    ASSERT(RunLoop::isMain());
-
-    if (NetworkStorageSession::storageSession(sessionID))
-        return;
-
-    NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
 }
 
 WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
index 33bae57..df947bb 100644 (file)
@@ -578,11 +578,6 @@ void WebProcess::setCacheModel(CacheModel cacheModel)
     platformSetCacheModel(cacheModel);
 }
 
-void WebProcess::clearCachedCredentials()
-{
-    NetworkStorageSession::defaultStorageSession().credentialStorage().clearCredentials();
-}
-
 WebPage* WebProcess::focusedWebPage() const
 {    
     for (auto& page : m_pageMap.values()) {
@@ -1299,11 +1294,6 @@ void WebProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDa
 
         CrossOriginPreflightResultCache::singleton().clear();
     }
-
-    if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
-        if (WebCore::NetworkStorageSession::storageSession(sessionID))
-            NetworkStorageSession::storageSession(sessionID)->credentialStorage().clearCredentials();
-    }
 }
 
 void WebProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, const Vector<WebCore::SecurityOriginData>& originDatas)
index 8a85cdb..1977845 100644 (file)
@@ -266,8 +266,6 @@ private:
 
     void processSuspensionCleanupTimerFired();
 
-    void clearCachedCredentials();
-
     void platformTerminate();
 
     void markIsNoLongerPrewarmed();
index e44a23f..c9e30c1 100644 (file)
@@ -51,8 +51,6 @@ messages -> WebProcess LegacyReceiver {
     UserPreferredLanguagesChanged(Vector<String> languages)
     FullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled)
 
-    ClearCachedCredentials()
-
     # Plug-ins.
     DidAddPlugInAutoStartOriginHash(uint32_t hash, WallTime expirationTime, PAL::SessionID sessionID)
     ResetPlugInAutoStartOriginDefaultHashes(HashMap<uint32_t,WallTime> hashes)
index 1493cae..7058876 100644 (file)
@@ -64,10 +64,6 @@ void WebProcess::platformTerminate()
 void WebProcess::setNetworkProxySettings(const WebCore::SoupNetworkProxySettings& settings)
 {
     WebCore::SoupNetworkSession::setProxySettings(settings);
-    WebCore::NetworkStorageSession::forEach([](const WebCore::NetworkStorageSession& session) {
-        if (auto* soupSession = session.soupNetworkSession())
-            soupSession->setupProxy();
-    });
 }
 
 } // namespace WebKit
index 04076fc..7fb8058 100644 (file)
@@ -12,6 +12,7 @@ set(WebKitLegacy_SOURCES
     Storage/WebDatabaseProvider.cpp
     Storage/WebStorageNamespaceProvider.cpp
 
+    WebCoreSupport/NetworkStorageSessionMap.cpp
     WebCoreSupport/WebResourceLoadScheduler.cpp
     WebCoreSupport/WebViewGroup.cpp
 )
index 9a77fd3..14d9eb2 100644 (file)
@@ -1,3 +1,22 @@
+2019-01-22  Alex Christensen  <achristensen@webkit.org>
+
+        Move NetworkStorageSession ownership to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=193580
+
+        Reviewed by Geoff Garen.
+
+        * WebCoreSupport/NetworkStorageSessionMap.cpp: Added.
+        (defaultNetworkStorageSession):
+        (globalSessionMap):
+        (NetworkStorageSessionMap::storageSession):
+        (NetworkStorageSessionMap::defaultStorageSession):
+        (NetworkStorageSessionMap::switchToNewTestingSession):
+        (NetworkStorageSessionMap::ensureSession):
+        (NetworkStorageSessionMap::destroySession):
+        * WebCoreSupport/NetworkStorageSessionMap.h: Added.
+        * WebCoreSupport/PageStorageSessionProvider.h:
+        * WebKitLegacy.xcodeproj/project.pbxproj:
+
 2019-01-15  Darin Adler  <darin@apple.com>
 
         Use references rather than pointers for register/unregister functions, and more
diff --git a/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.cpp b/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.cpp
new file mode 100644 (file)
index 0000000..6340c3c
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2019 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. ``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
+ * 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 "NetworkStorageSessionMap.h"
+
+#include <WebCore/NetworkStorageSession.h>
+#include <pal/SessionID.h>
+#include <wtf/ProcessID.h>
+#include <wtf/ProcessPrivilege.h>
+
+static std::unique_ptr<WebCore::NetworkStorageSession>& defaultNetworkStorageSession()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<std::unique_ptr<WebCore::NetworkStorageSession>> session;
+    return session;
+}
+
+static HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>>& globalSessionMap()
+{
+    static NeverDestroyed<HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>>> map;
+    return map;
+}
+
+WebCore::NetworkStorageSession* NetworkStorageSessionMap::storageSession(const PAL::SessionID& sessionID)
+{
+    if (sessionID == PAL::SessionID::defaultSessionID())
+        return &defaultStorageSession();
+    return globalSessionMap().get(sessionID);
+}
+
+WebCore::NetworkStorageSession& NetworkStorageSessionMap::defaultStorageSession()
+{
+    if (!defaultNetworkStorageSession())
+        defaultNetworkStorageSession() = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID());
+    return *defaultNetworkStorageSession();
+}
+
+void NetworkStorageSessionMap::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()));
+
+    auto session = adoptCF(WebCore::createPrivateStorageSession(sessionName.createCFString().get()));
+
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
+    if (WebCore::NetworkStorageSession::processMayUseCookieAPI()) {
+        ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+        if (session)
+            cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, session.get()));
+    }
+
+    defaultNetworkStorageSession() = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID(), WTFMove(session), WTFMove(cookieStorage));
+}
+
+void NetworkStorageSessionMap::ensureSession(const PAL::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())
+        storageSession = adoptCF(WebCore::createPrivateStorageSession(cfIdentifier.get()));
+    else
+        storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(cfIdentifier.get());
+
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
+    if (WebCore::NetworkStorageSession::processMayUseCookieAPI()) {
+        ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+        if (storageSession)
+            cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
+    }
+
+    addResult.iterator->value = std::make_unique<WebCore::NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
+}
+
+void NetworkStorageSessionMap::destroySession(const PAL::SessionID& sessionID)
+{
+    globalSessionMap().remove(sessionID);
+}
diff --git a/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.h b/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.h
new file mode 100644 (file)
index 0000000..a304cac
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 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. ``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
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/text/WTFString.h>
+
+namespace PAL {
+class SessionID;
+}
+
+namespace WebCore {
+class NetworkStorageSession;
+}
+
+class NetworkStorageSessionMap {
+public:
+    static WebCore::NetworkStorageSession* storageSession(const PAL::SessionID&);
+    static WebCore::NetworkStorageSession& defaultStorageSession();
+    static void switchToNewTestingSession();
+    static void ensureSession(const PAL::SessionID&, const String& identifierBase = String());
+    static void destroySession(const PAL::SessionID&);
+};
index 4d84f1a..756eabf 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "NetworkStorageSessionMap.h"
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/Page.h>
 #include <WebCore/StorageSessionProvider.h>
@@ -37,7 +38,7 @@ public:
     WebCore::NetworkStorageSession* storageSession() const
     {
         if (m_page)
-            return WebCore::NetworkStorageSession::storageSession(m_page->sessionID());
+            return NetworkStorageSessionMap::storageSession(m_page->sessionID());
         return nullptr;
     }
 
index b3ca2f8..ee25750 100644 (file)
                598AD92A1201CF3B00ABAE4E /* WebDeviceOrientationProviderMockInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 598AD9291201CF3B00ABAE4E /* WebDeviceOrientationProviderMockInternal.h */; };
                598ADA461202275000ABAE4E /* WebDeviceOrientationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 598ADA451202275000ABAE4E /* WebDeviceOrientationProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5C9EF2F521F061BE003BDC56 /* PageStorageSessionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C9EF2F421F061BE003BDC56 /* PageStorageSessionProvider.h */; };
+               5CA46E7821F1451D00CE86B4 /* NetworkStorageSessionMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CA46E7621F1451D00CE86B4 /* NetworkStorageSessionMap.h */; };
+               5CA46E7921F1451D00CE86B4 /* NetworkStorageSessionMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CA46E7721F1451D00CE86B4 /* NetworkStorageSessionMap.cpp */; };
                5CE44F4A206D70EA003EFD01 /* PingHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CE44F49206D70E9003EFD01 /* PingHandle.h */; };
                5D7BF8140C2A1D90008CE06D /* WebInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D7BF8120C2A1D90008CE06D /* WebInspector.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5D7BF8150C2A1D90008CE06D /* WebInspector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5D7BF8130C2A1D90008CE06D /* WebInspector.mm */; };
                598AD9291201CF3B00ABAE4E /* WebDeviceOrientationProviderMockInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebDeviceOrientationProviderMockInternal.h; sourceTree = "<group>"; };
                598ADA451202275000ABAE4E /* WebDeviceOrientationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebDeviceOrientationProvider.h; sourceTree = "<group>"; };
                5C9EF2F421F061BE003BDC56 /* PageStorageSessionProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PageStorageSessionProvider.h; path = WebCoreSupport/PageStorageSessionProvider.h; sourceTree = SOURCE_ROOT; };
+               5CA46E7621F1451D00CE86B4 /* NetworkStorageSessionMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkStorageSessionMap.h; path = WebCoreSupport/NetworkStorageSessionMap.h; sourceTree = SOURCE_ROOT; };
+               5CA46E7721F1451D00CE86B4 /* NetworkStorageSessionMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkStorageSessionMap.cpp; path = WebCoreSupport/NetworkStorageSessionMap.cpp; sourceTree = SOURCE_ROOT; };
                5CE44F49206D70E9003EFD01 /* PingHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PingHandle.h; path = WebCoreSupport/PingHandle.h; sourceTree = SOURCE_ROOT; };
                5D7BF8120C2A1D90008CE06D /* WebInspector.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebInspector.h; sourceTree = "<group>"; };
                5D7BF8130C2A1D90008CE06D /* WebInspector.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebInspector.mm; sourceTree = "<group>"; };
                                A10C1D4418202FFB0036883A /* ios */,
                                B82958D1132707D0000D0E79 /* CorrectionPanel.h */,
                                B82958D2132707D0000D0E79 /* CorrectionPanel.mm */,
+                               5CA46E7721F1451D00CE86B4 /* NetworkStorageSessionMap.cpp */,
+                               5CA46E7621F1451D00CE86B4 /* NetworkStorageSessionMap.h */,
                                5C9EF2F421F061BE003BDC56 /* PageStorageSessionProvider.h */,
                                5CE44F49206D70E9003EFD01 /* PingHandle.h */,
                                7C01CB81173435C900C5D807 /* PopupMenuMac.h */,
                                1AAF5CEA0EDDE1FE008D883D /* NetscapePluginHostManager.h in Headers */,
                                1AAF5CEC0EDDE1FE008D883D /* NetscapePluginHostProxy.h in Headers */,
                                1AAF5CEE0EDDE1FE008D883D /* NetscapePluginInstanceProxy.h in Headers */,
+                               5CA46E7821F1451D00CE86B4 /* NetworkStorageSessionMap.h in Headers */,
                                E1531BD82187B954002E3F81 /* NSURLDownloadSPI.h in Headers */,
                                93D4379B1D57ABEF00AB85EA /* ObjCEventListener.h in Headers */,
                                93D4379D1D57ABEF00AB85EA /* ObjCNodeFilterCondition.h in Headers */,
                                1AAF5CEB0EDDE1FE008D883D /* NetscapePluginHostManager.mm in Sources */,
                                1AAF5CED0EDDE1FE008D883D /* NetscapePluginHostProxy.mm in Sources */,
                                1AAF5CEF0EDDE1FE008D883D /* NetscapePluginInstanceProxy.mm in Sources */,
+                               5CA46E7921F1451D00CE86B4 /* NetworkStorageSessionMap.cpp in Sources */,
                                939810DD0824BF01008DF038 /* npapi.mm in Sources */,
                                93D4379C1D57ABEF00AB85EA /* ObjCEventListener.mm in Sources */,
                                93D4379E1D57ABEF00AB85EA /* ObjCNodeFilterCondition.mm in Sources */,
index ad6b937..c07f40f 100644 (file)
@@ -1,3 +1,25 @@
+2019-01-22  Alex Christensen  <achristensen@webkit.org>
+
+        Move NetworkStorageSession ownership to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=193580
+
+        Reviewed by Geoff Garen.
+
+        * Misc/WebCache.mm:
+        (+[WebCache clearCachedCredentials]):
+        * Misc/WebDownload.mm:
+        (-[WebDownloadInternal download:didReceiveAuthenticationChallenge:]):
+        * Plugins/WebBaseNetscapePluginView.mm:
+        (WebKit::getAuthenticationInfo):
+        * WebCoreSupport/WebFrameNetworkingContext.mm:
+        (WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebFrameNetworkingContext::destroyPrivateBrowsingSession):
+        (WebFrameNetworkingContext::storageSession const):
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences _switchNetworkLoaderToNewTestingSession]):
+        (+[WebPreferences _clearNetworkLoaderSession]):
+        (+[WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:]):
+
 2019-01-22  Daniel Bates  <dabates@apple.com>
 
         [iOS] Interpret text key commands on keydown and app key commands on keypress
index 857055d..3b6cd92 100644 (file)
@@ -25,6 +25,7 @@
 
 #import "WebCache.h"
 
+#import "NetworkStorageSessionMap.h"
 #import "WebApplicationCacheInternal.h"
 #import "WebNSObjectExtras.h"
 #import "WebPreferences.h"
@@ -54,7 +55,7 @@
 class DefaultStorageSessionProvider : public WebCore::StorageSessionProvider {
     WebCore::NetworkStorageSession* storageSession() const final
     {
-        return &WebCore::NetworkStorageSession::defaultStorageSession();
+        return &NetworkStorageSessionMap::defaultStorageSession();
     }
 };
 
@@ -223,7 +224,7 @@ class DefaultStorageSessionProvider : public WebCore::StorageSessionProvider {
 + (void)clearCachedCredentials
 {
     [WebView _makeAllWebViewsPerformSelector:@selector(_clearCredentials)];
-    WebCore::NetworkStorageSession::defaultStorageSession().credentialStorage().clearCredentials();
+    NetworkStorageSessionMap::defaultStorageSession().credentialStorage().clearCredentials();
 }
 
 @end
index 0177047..df54d11 100644 (file)
@@ -28,6 +28,8 @@
 
 #import <WebKitLegacy/WebDownload.h>
 
+#import "NetworkStorageSessionMap.h"
+#import "WebTypesInternal.h"
 #import <Foundation/NSURLAuthenticationChallenge.h>
 #import <WebCore/AuthenticationMac.h>
 #import <WebCore/Credential.h>
@@ -38,8 +40,6 @@
 #import <pal/spi/cocoa/NSURLDownloadSPI.h>
 #import <wtf/Assertions.h>
 
-#import "WebTypesInternal.h"
-
 using namespace WebCore;
 
 @interface WebDownloadInternal : NSObject <NSURLDownloadDelegate> {
@@ -95,7 +95,7 @@ using namespace WebCore;
 #if !PLATFORM(IOS_FAMILY)
     // Try previously stored credential first.
     if (![challenge previousFailureCount]) {
-        NSURLCredential *credential = NetworkStorageSession::defaultStorageSession().credentialStorage().get(emptyString(), ProtectionSpace([challenge protectionSpace])).nsCredential();
+        NSURLCredential *credential = NetworkStorageSessionMap::defaultStorageSession().credentialStorage().get(emptyString(), ProtectionSpace([challenge protectionSpace])).nsCredential();
         if (credential) {
             [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
             return;
index 0f96582..9f8acb4 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "WebBaseNetscapePluginView.h"
 
+#import "NetworkStorageSessionMap.h"
 #import "WebFrameInternal.h"
 #import "WebKitLogging.h"
 #import "WebKitNSStringExtras.h"
@@ -872,7 +873,7 @@ bool getAuthenticationInfo(const char* protocolStr, const char* hostStr, int32_t
     
     RetainPtr<NSURLProtectionSpace> protectionSpace = adoptNS([[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:protocol realm:realm authenticationMethod:authenticationMethod]);
     
-    NSURLCredential *credential = WebCore::NetworkStorageSession::defaultStorageSession().credentialStorage().get(emptyString(), ProtectionSpace(protectionSpace.get())).nsCredential();
+    NSURLCredential *credential = NetworkStorageSessionMap::defaultStorageSession().credentialStorage().get(emptyString(), ProtectionSpace(protectionSpace.get())).nsCredential();
     if (!credential)
         credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace.get()];
     if (!credential)
index 3030a4b..0a06ea3 100644 (file)
@@ -25,6 +25,7 @@
 
 #import "WebFrameNetworkingContext.h"
 
+#import "NetworkStorageSessionMap.h"
 #import "WebFrameInternal.h"
 #import "WebViewPrivate.h"
 #import <WebCore/FrameLoader.h>
@@ -46,14 +47,14 @@ using namespace WebCore;
 NetworkStorageSession& WebFrameNetworkingContext::ensurePrivateBrowsingSession()
 {
     ASSERT(isMainThread());
-    NetworkStorageSession::ensureSession(PAL::SessionID::legacyPrivateSessionID(), [[NSBundle mainBundle] bundleIdentifier]);
-    return *NetworkStorageSession::storageSession(PAL::SessionID::legacyPrivateSessionID());
+    NetworkStorageSessionMap::ensureSession(PAL::SessionID::legacyPrivateSessionID(), [[NSBundle mainBundle] bundleIdentifier]);
+    return *NetworkStorageSessionMap::storageSession(PAL::SessionID::legacyPrivateSessionID());
 }
 
 void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
 {
     ASSERT(isMainThread());
-    NetworkStorageSession::destroySession(PAL::SessionID::legacyPrivateSessionID());
+    NetworkStorageSessionMap::destroySession(PAL::SessionID::legacyPrivateSessionID());
 }
 
 bool WebFrameNetworkingContext::localFileContentSniffingEnabled() const
@@ -94,10 +95,10 @@ NetworkStorageSession* WebFrameNetworkingContext::storageSession() const
 {
     ASSERT(isMainThread());
     if (frame() && frame()->page() && frame()->page()->sessionID().isEphemeral()) {
-        if (auto* session = NetworkStorageSession::storageSession(PAL::SessionID::legacyPrivateSessionID()))
+        if (auto* session = NetworkStorageSessionMap::storageSession(PAL::SessionID::legacyPrivateSessionID()))
             return session;
         // Some requests may still be coming shortly before WebCore updates the session ID and after WebKit destroys the private browsing session.
         LOG_ERROR("Invalid session ID. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
     }
-    return &NetworkStorageSession::defaultStorageSession();
+    return &NetworkStorageSessionMap::defaultStorageSession();
 }
index 3361b2f..5cdab7b 100644 (file)
@@ -30,6 +30,7 @@
 #import "WebPreferencesPrivate.h"
 #import "WebPreferenceKeysPrivate.h"
 
+#import "NetworkStorageSessionMap.h"
 #import "WebApplicationCache.h"
 #import "WebFrameNetworkingContext.h"
 #import "WebKitLogging.h"
@@ -1877,18 +1878,18 @@ static NSString *classIBCreatorID = nil;
 #if PLATFORM(IOS_FAMILY)
     WebThreadLock();
 #endif
-    NetworkStorageSession::switchToNewTestingSession();
+    NetworkStorageSessionMap::switchToNewTestingSession();
 }
 
 + (void)_clearNetworkLoaderSession
 {
-    NetworkStorageSession::defaultStorageSession().deleteAllCookies();
+    NetworkStorageSessionMap::defaultStorageSession().deleteAllCookies();
 }
 
 + (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
 {
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage();
-    ASSERT(cookieStorage); // Will fail when NetworkStorageSession::switchToNewTestingSession() was not called beforehand.
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSessionMap::defaultStorageSession().cookieStorage();
+    ASSERT(cookieStorage); // Will fail when NetworkStorageSessionMap::switchToNewTestingSession() was not called beforehand.
     CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
 }
 
index 15c71d7..4a6c903 100644 (file)
@@ -1,3 +1,21 @@
+2019-01-22  Alex Christensen  <achristensen@webkit.org>
+
+        Move NetworkStorageSession ownership to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=193580
+
+        Reviewed by Geoff Garen.
+
+        * WebCoreSupport/WebFrameNetworkingContext.cpp:
+        (WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
+        (WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebFrameNetworkingContext::destroyPrivateBrowsingSession):
+        (WebFrameNetworkingContext::storageSession const):
+        * WebDownloadCFNet.cpp:
+        (WebDownload::didReceiveAuthenticationChallenge):
+        * WebPreferences.cpp:
+        (WebPreferences::clearNetworkLoaderSession):
+        (WebPreferences::switchNetworkLoaderToNewTestingSession):
+
 2019-01-15  Darin Adler  <darin@apple.com>
 
         Use references rather than pointers for register/unregister functions, and more
index 9513096..f134f3c 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "WebFrameNetworkingContext.h"
 
+#include "NetworkStorageSessionMap.h"
 #include "WebView.h"
 #include <WebCore/FrameLoader.h>
 #include <WebCore/FrameLoaderClient.h>
@@ -50,10 +51,10 @@ static String& identifierBase()
 #if USE(CFURLCONNECTION)
 void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(WebKitCookieStorageAcceptPolicy policy)
 {
-    if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage())
+    if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSessionMap::defaultStorageSession().cookieStorage())
         CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
 
-    if (auto privateSession = NetworkStorageSession::storageSession(PAL::SessionID::legacyPrivateSessionID()))
+    if (auto privateSession = NetworkStorageSessionMap::storageSession(PAL::SessionID::legacyPrivateSessionID()))
         CFHTTPCookieStorageSetCookieAcceptPolicy(privateSession->cookieStorage().get(), policy);
 }
 #endif
@@ -70,7 +71,7 @@ NetworkStorageSession& WebFrameNetworkingContext::ensurePrivateBrowsingSession()
 #if USE(CFURLCONNECTION)
     ASSERT(isMainThread());
 
-    if (auto privateSession = NetworkStorageSession::storageSession(PAL::SessionID::legacyPrivateSessionID()))
+    if (auto privateSession = NetworkStorageSessionMap::storageSession(PAL::SessionID::legacyPrivateSessionID()))
         return *privateSession;
 
     String base;
@@ -81,17 +82,17 @@ NetworkStorageSession& WebFrameNetworkingContext::ensurePrivateBrowsingSession()
     } else
         base = identifierBase();
 
-    NetworkStorageSession::ensureSession(PAL::SessionID::legacyPrivateSessionID(), base);
+    NetworkStorageSessionMap::ensureSession(PAL::SessionID::legacyPrivateSessionID(), base);
 
 #endif
-    return *NetworkStorageSession::storageSession(PAL::SessionID::legacyPrivateSessionID());
+    return *NetworkStorageSessionMap::storageSession(PAL::SessionID::legacyPrivateSessionID());
 }
 
 void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    NetworkStorageSession::destroySession(PAL::SessionID::legacyPrivateSessionID());
+    NetworkStorageSessionMap::destroySession(PAL::SessionID::legacyPrivateSessionID());
 }
 
 ResourceError WebFrameNetworkingContext::blockedError(const ResourceRequest& request) const
@@ -104,7 +105,7 @@ NetworkStorageSession* WebFrameNetworkingContext::storageSession() const
     ASSERT(isMainThread());
 
     if (frame() && frame()->page()->usesEphemeralSession())
-        return NetworkStorageSession::storageSession(PAL::SessionID::legacyPrivateSessionID());
+        return NetworkStorageSessionMap::storageSession(PAL::SessionID::legacyPrivateSessionID());
 
-    return &NetworkStorageSession::defaultStorageSession();
+    return &NetworkStorageSessionMap::defaultStorageSession();
 }
index 1ef72fd..5e47a48 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "DefaultDownloadDelegate.h"
 #include "MarshallingHelpers.h"
+#include "NetworkStorageSessionMap.h"
 #include "WebError.h"
 #include "WebKit.h"
 #include "WebKitLogging.h"
@@ -376,7 +377,7 @@ void WebDownload::didReceiveAuthenticationChallenge(CFURLAuthChallengeRef challe
 {
     // Try previously stored credential first.
     if (!CFURLAuthChallengeGetPreviousFailureCount(challenge)) {
-        Credential credential = WebCore::NetworkStorageSession::defaultStorageSession().credentialStorage().get(emptyString(), core(CFURLAuthChallengeGetProtectionSpace(challenge)));
+        Credential credential = NetworkStorageSessionMap::defaultStorageSession().credentialStorage().get(emptyString(), core(CFURLAuthChallengeGetProtectionSpace(challenge)));
         if (!credential.isEmpty()) {
             RetainPtr<CFURLCredentialRef> cfCredential = adoptCF(createCF(credential));
             CFURLDownloadUseCredential(m_download.get(), cfCredential.get(), challenge);
index 59be0c4..a631b91 100644 (file)
@@ -27,6 +27,7 @@
 #include "WebKitDLL.h"
 #include "WebPreferences.h"
 
+#include "NetworkStorageSessionMap.h"
 #include "WebNotificationCenter.h"
 #include "WebPreferenceKeysPrivate.h"
 
@@ -2118,13 +2119,13 @@ HRESULT WebPreferences::mediaPreloadingEnabled(_Out_ BOOL* enabled)
 
 HRESULT WebPreferences::clearNetworkLoaderSession()
 {
-    NetworkStorageSession::defaultStorageSession().deleteAllCookies();
+    NetworkStorageSessionMap::defaultStorageSession().deleteAllCookies();
     return S_OK;
 }
 
 HRESULT WebPreferences::switchNetworkLoaderToNewTestingSession()
 {
-    NetworkStorageSession::switchToNewTestingSession();
+    NetworkStorageSessionMap::switchToNewTestingSession();
     return S_OK;
 }