Start of support for multiple WebsiteDataStore/SessionIDs per process
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Apr 2017 20:48:40 +0000 (20:48 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Apr 2017 20:48:40 +0000 (20:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171422

Reviewed by Geoffrey Garen.

Source/WebCore:

Covered by API tests.

* platform/network/NetworkStorageSession.h:
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::NetworkStorageSession::ensureSession):
* platform/spi/cf/CFNetworkSPI.h:

Source/WebKit2:

* CMakeLists.txt:
* WebKit2.xcodeproj/project.pbxproj:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::addWebsiteDataStore):
(WebKit::NetworkProcess::destroySession):
(WebKit::NetworkProcess::destroyPrivateBrowsingSession): Deleted.
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:

* NetworkProcess/RemoteNetworkingContext.h:
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
* NetworkProcess/soup/RemoteNetworkingContextSoup.cpp:
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):

* Shared/WebsiteDataStoreParameters.cpp: Copied from Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h.
(WebKit::WebsiteDataStoreParameters::WebsiteDataStoreParameters):
(WebKit::WebsiteDataStoreParameters::encode):
(WebKit::WebsiteDataStoreParameters::decode):
* Shared/WebsiteDataStoreParameters.h: Copied from Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h.

* UIProcess/API/APIWebsiteDataStore.cpp:
(API::WebsiteDataStore::defaultDataStore):
(API::WebsiteDataStore::createLegacy):
(API::WebsiteDataStore::WebsiteDataStore):
(API::WebsiteDataStore::create): Deleted.
* UIProcess/API/APIWebsiteDataStore.h:

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _initWithConfiguration:]):

* UIProcess/API/gtk/WebKitWebsiteDataManager.cpp:
(webkitWebsiteDataManagerCreate):
(webkitWebsiteDataManagerGetDataStore):

* UIProcess/WebPageProxy.cpp:
(WebKit::m_weakPtrFactory):
* UIProcess/WebPageProxy.h:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::WebProcessPool):
(WebKit::WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled):
(WebKit::WebProcessPool::pageAddedToProcess):
(WebKit::WebProcessPool::pageRemovedFromProcess):

* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::create):
(WebKit::WebsiteDataStore::WebsiteDataStore):
(WebKit::WebsiteDataStore::~WebsiteDataStore):
(WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.h:

* WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.h:
* WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
(WebKit::WebFrameNetworkingContext::ensureWebsiteDataStoreSession):
(WebKit::WebFrameNetworkingContext::storageSession):
* WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
(WebKit::WebFrameNetworkingContext::ensureWebsiteDataStoreSession):
* WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h:

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::addWebsiteDataStore):
(WebKit::WebProcess::destroySession):
(WebKit::WebProcess::destroyPrivateBrowsingSession): Deleted.
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
* WebProcess/cocoa/WebProcessCocoa.mm:

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/WebsiteDataStoreCustomPaths.mm:
(TEST):

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

36 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/spi/cf/CFNetworkSPI.h
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit2/NetworkProcess/NetworkProcess.cpp
Source/WebKit2/NetworkProcess/NetworkProcess.h
Source/WebKit2/NetworkProcess/NetworkProcess.messages.in
Source/WebKit2/NetworkProcess/RemoteNetworkingContext.h
Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit2/NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
Source/WebKit2/Shared/WebsiteDataStoreParameters.cpp [new file with mode: 0644]
Source/WebKit2/Shared/WebsiteDataStoreParameters.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/APIWebsiteDataStore.cpp
Source/WebKit2/UIProcess/API/APIWebsiteDataStore.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.h
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm
Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp
Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/WebProcess.messages.in
Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsiteDataStoreCustomPaths.mm

index ce04692..10cf06f 100644 (file)
@@ -1,3 +1,17 @@
+2017-04-28  Brady Eidson  <beidson@apple.com>
+
+        Start of support for multiple WebsiteDataStore/SessionIDs per process
+        https://bugs.webkit.org/show_bug.cgi?id=171422
+
+        Reviewed by Geoffrey Garen.
+
+        Covered by API tests.
+
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::NetworkStorageSession::ensureSession):
+        * platform/spi/cf/CFNetworkSPI.h:
+
 2017-04-28  Chris Dumez  <cdumez@apple.com>
 
         URLSearchParams should be reflective
index af4bb39..7ce0d98 100644 (file)
@@ -73,6 +73,7 @@ public:
 #endif
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
+    WEBCORE_EXPORT static void ensureSession(SessionID, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&&);
     NetworkStorageSession(SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&);
 
     // May be null, in which case a Foundation default should be used.
index 702d708..5a48781 100644 (file)
@@ -115,7 +115,7 @@ void NetworkStorageSession::ensurePrivateBrowsingSession(SessionID sessionID, co
     ensureSession(sessionID, identifierBase);
 }
 
-void NetworkStorageSession::ensureSession(SessionID sessionID, const String& identifierBase)
+void NetworkStorageSession::ensureSession(SessionID sessionID, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&& cookieStorage)
 {
     auto addResult = globalSessionMap().add(sessionID, nullptr);
     if (!addResult.isNewEntry)
@@ -133,10 +133,17 @@ void NetworkStorageSession::ensureSession(SessionID sessionID, const String& ide
     } else
         storageSession = createCFStorageSessionForIdentifier(cfIdentifier.get());
 
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = storageSession ? adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get())) : nullptr;
+    if (!cookieStorage && storageSession)
+        cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
+
     addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
 }
 
+void NetworkStorageSession::ensureSession(SessionID sessionID, const String& identifierBase)
+{
+    ensureSession(sessionID, identifierBase, nullptr);
+}
+
 RetainPtr<CFHTTPCookieStorageRef> NetworkStorageSession::cookieStorage() const
 {
     if (m_platformCookieStorage)
index 02438fa..f92d56a 100644 (file)
@@ -184,6 +184,8 @@ extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
 
 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
+CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromFile(CFAllocatorRef, CFURLRef, CFHTTPCookieStorageRef);
+
 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
 CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
index 3e425c4..4fcee1b 100644 (file)
@@ -212,6 +212,7 @@ set(WebKit2_SOURCES
     Shared/WebTouchEvent.cpp
     Shared/WebUserContentControllerDataTypes.cpp
     Shared/WebWheelEvent.cpp
+    Shared/WebsiteDataStoreParameters.cpp
 
     Shared/API/APIArray.cpp
     Shared/API/APIData.cpp
index 11310b5..55f55b9 100644 (file)
@@ -1,3 +1,82 @@
+2017-04-28  Brady Eidson  <beidson@apple.com>
+
+        Start of support for multiple WebsiteDataStore/SessionIDs per process
+        https://bugs.webkit.org/show_bug.cgi?id=171422
+
+        Reviewed by Geoffrey Garen.
+
+        * CMakeLists.txt:
+        * WebKit2.xcodeproj/project.pbxproj:
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::addWebsiteDataStore):
+        (WebKit::NetworkProcess::destroySession):
+        (WebKit::NetworkProcess::destroyPrivateBrowsingSession): Deleted.
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+
+        * NetworkProcess/RemoteNetworkingContext.h:
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
+        * NetworkProcess/soup/RemoteNetworkingContextSoup.cpp:
+        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
+
+        * Shared/WebsiteDataStoreParameters.cpp: Copied from Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h.
+        (WebKit::WebsiteDataStoreParameters::WebsiteDataStoreParameters):
+        (WebKit::WebsiteDataStoreParameters::encode):
+        (WebKit::WebsiteDataStoreParameters::decode):
+        * Shared/WebsiteDataStoreParameters.h: Copied from Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h.
+
+        * UIProcess/API/APIWebsiteDataStore.cpp:
+        (API::WebsiteDataStore::defaultDataStore):
+        (API::WebsiteDataStore::createLegacy):
+        (API::WebsiteDataStore::WebsiteDataStore):
+        (API::WebsiteDataStore::create): Deleted.
+        * UIProcess/API/APIWebsiteDataStore.h:
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _initWithConfiguration:]):
+
+        * UIProcess/API/gtk/WebKitWebsiteDataManager.cpp:
+        (webkitWebsiteDataManagerCreate):
+        (webkitWebsiteDataManagerGetDataStore):
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::m_weakPtrFactory):
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::WebProcessPool):
+        (WebKit::WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled):
+        (WebKit::WebProcessPool::pageAddedToProcess):
+        (WebKit::WebProcessPool::pageRemovedFromProcess):
+
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::create):
+        (WebKit::WebsiteDataStore::WebsiteDataStore):
+        (WebKit::WebsiteDataStore::~WebsiteDataStore):
+        (WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
+        * WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.h:
+        * WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
+        (WebKit::WebFrameNetworkingContext::ensureWebsiteDataStoreSession):
+        (WebKit::WebFrameNetworkingContext::storageSession):
+        * WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
+        (WebKit::WebFrameNetworkingContext::ensureWebsiteDataStoreSession):
+        * WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h:
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::addWebsiteDataStore):
+        (WebKit::WebProcess::destroySession):
+        (WebKit::WebProcess::destroyPrivateBrowsingSession): Deleted.
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+
 2017-04-28  Youenn Fablet  <youenn@apple.com>
 
         Adding a runtime flag specific to MediaDevices
index 7d3d729..1dfa437 100644 (file)
@@ -245,12 +245,14 @@ void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname)
 
 static NetworkStorageSession& storageSession(SessionID sessionID)
 {
-    if (sessionID.isEphemeral()) {
-        if (auto* privateStorageSession = NetworkStorageSession::storageSession(sessionID))
-            return *privateStorageSession;
+    ASSERT(sessionID.isValid());
+    if (sessionID != SessionID::defaultSessionID()) {
+        if (auto* storageSession = NetworkStorageSession::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("Private browsing was requested, but there was no session for it. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
+        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();
 }
index a97239e..9630d4f 100644 (file)
@@ -291,7 +291,12 @@ void NetworkProcess::ensurePrivateBrowsingSession(SessionID sessionID)
     RemoteNetworkingContext::ensurePrivateBrowsingSession(sessionID);
 }
 
-void NetworkProcess::destroyPrivateBrowsingSession(SessionID sessionID)
+void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters)
+{
+    RemoteNetworkingContext::ensureWebsiteDataStoreSession(WTFMove(parameters));
+}
+
+void NetworkProcess::destroySession(SessionID sessionID)
 {
     SessionTracker::destroySession(sessionID);
 }
index 30052ca..60ed6f1 100644 (file)
@@ -61,6 +61,7 @@ class NetworkResourceLoader;
 enum class WebsiteDataFetchOption;
 enum class WebsiteDataType;
 struct NetworkProcessCreationParameters;
+struct WebsiteDataStoreParameters;
 
 class NetworkProcess : public ChildProcess, private DownloadManager::Client {
     WTF_MAKE_NONCOPYABLE(NetworkProcess);
@@ -159,7 +160,8 @@ private:
     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
     void initializeNetworkProcess(NetworkProcessCreationParameters&&);
     void createNetworkConnectionToWebProcess();
-    void destroyPrivateBrowsingSession(WebCore::SessionID);
+    void addWebsiteDataStore(WebsiteDataStoreParameters&&);
+    void destroySession(WebCore::SessionID);
 
     void fetchWebsiteData(WebCore::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
     void deleteWebsiteData(WebCore::SessionID, OptionSet<WebsiteDataType>, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID);
index 9fa3051..d5b8c6c 100644 (file)
@@ -36,7 +36,8 @@ messages -> NetworkProcess LegacyReceiver {
     ClearCachedCredentials()
 
     EnsurePrivateBrowsingSession(WebCore::SessionID sessionID)
-    DestroyPrivateBrowsingSession(WebCore::SessionID sessionID)
+    AddWebsiteDataStore(struct WebKit::WebsiteDataStoreParameters websiteDataStoreParameters);
+    DestroySession(WebCore::SessionID sessionID)
 
     FetchWebsiteData(WebCore::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, OptionSet<WebKit::WebsiteDataFetchOption> fetchOptions, uint64_t callbackID)
     DeleteWebsiteData(WebCore::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
index d22fc9d..376e966 100644 (file)
@@ -32,6 +32,8 @@
 
 namespace WebKit {
 
+struct WebsiteDataStoreParameters;
+
 class RemoteNetworkingContext final : public WebCore::NetworkingContext {
 public:
     static Ref<RemoteNetworkingContext> create(WebCore::SessionID sessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
@@ -42,6 +44,7 @@ public:
 
     // FIXME: Remove platform-specific code and use SessionTracker.
     static void ensurePrivateBrowsingSession(WebCore::SessionID);
+    static void ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&);
 
     bool shouldClearReferrerOnHTTPSToHTTPRedirect() const override { return m_shouldClearReferrerOnHTTPSToHTTPRedirect; }
 
index 36f4cf7..f78b8f6 100644 (file)
@@ -31,6 +31,7 @@
 #import "NetworkSession.h"
 #import "SessionTracker.h"
 #import "WebErrors.h"
+#import "WebsiteDataStoreParameters.h"
 #import <WebCore/NetworkStorageSession.h>
 #import <WebCore/ResourceError.h>
 #import <WebKitSystemInterface.h>
@@ -100,4 +101,34 @@ void RemoteNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID)
 #endif
 }
 
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+{
+    if (NetworkStorageSession::storageSession(parameters.sessionID))
+        return;
+
+    String base;
+    if (SessionTracker::getIdentifierBase().isNull())
+        base = [[NSBundle mainBundle] bundleIdentifier];
+    else
+        base = SessionTracker::getIdentifierBase();
+
+#if PLATFORM(IOS)
+    SandboxExtension::consumePermanently(parameters.cookieStorageDirectoryExtensionHandle);
+#endif
+
+    RetainPtr<CFHTTPCookieStorageRef> uiProcessCookieStorage;
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    RetainPtr<CFDataRef> cookieStorageData = adoptCF(CFDataCreate(kCFAllocatorDefault, parameters.uiProcessCookieStorageIdentifier.data(), parameters.uiProcessCookieStorageIdentifier.size()));
+    uiProcessCookieStorage = adoptCF(CFHTTPCookieStorageCreateFromIdentifyingData(kCFAllocatorDefault, cookieStorageData.get()));
+#endif
+
+    NetworkStorageSession::ensureSession(parameters.sessionID, base + '.' + String::number(parameters.sessionID.sessionID()), WTFMove(uiProcessCookieStorage));
+
+#if USE(NETWORK_SESSION)
+    auto networkSession = NetworkSession::create(parameters.sessionID, NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>());
+    SessionTracker::setSession(parameters.sessionID, WTFMove(networkSession));
+#endif
+}
+
 }
index 2dba105..0ea8070 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "NetworkSession.h"
 #include "SessionTracker.h"
+#include "WebsiteDataStoreParameters.h"
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceHandle.h>
@@ -58,6 +59,11 @@ void RemoteNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID)
     SessionTracker::setSession(sessionID, NetworkSession::create(sessionID));
 }
 
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&)
+{
+    // FIXME: Implement.
+}
+
 NetworkStorageSession& RemoteNetworkingContext::storageSession() const
 {
     if (auto session = NetworkStorageSession::storageSession(m_sessionID))
diff --git a/Source/WebKit2/Shared/WebsiteDataStoreParameters.cpp b/Source/WebKit2/Shared/WebsiteDataStoreParameters.cpp
new file mode 100644 (file)
index 0000000..eaf029b
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * 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 "WebsiteDataStoreParameters.h"
+
+#include "WebCoreArgumentCoders.h"
+
+namespace WebKit {
+
+
+WebsiteDataStoreParameters::WebsiteDataStoreParameters()
+{
+}
+
+void WebsiteDataStoreParameters::encode(IPC::Encoder& encoder) const
+{
+    encoder << sessionID;
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    encoder << uiProcessCookieStorageIdentifier;
+#endif
+#if PLATFORM(IOS)
+    encoder << cookieStorageDirectoryExtensionHandle;
+#endif
+}
+
+bool WebsiteDataStoreParameters::decode(IPC::Decoder& decoder, WebsiteDataStoreParameters& parameters)
+{
+    if (!decoder.decode(parameters.sessionID))
+        return false;
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    if (!decoder.decode(parameters.uiProcessCookieStorageIdentifier))
+        return false;
+#endif
+
+#if PLATFORM(IOS)
+    if (!decoder.decode(parameters.cookieStorageDirectoryExtensionHandle))
+        return false;
+#endif
+
+    return true;
+}
+
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Shared/WebsiteDataStoreParameters.h b/Source/WebKit2/Shared/WebsiteDataStoreParameters.h
new file mode 100644 (file)
index 0000000..a04ca52
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * 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.
+ */
+
+#pragma once
+
+#include "SandboxExtension.h"
+#include <WebCore/SessionID.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace IPC {
+class Decoder;
+class Encoder;
+}
+
+namespace WebKit {
+
+struct WebsiteDataStoreParameters {
+    WebsiteDataStoreParameters();
+
+    void encode(IPC::Encoder&) const;
+    static bool decode(IPC::Decoder&, WebsiteDataStoreParameters&);
+
+    WebCore::SessionID sessionID;
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    Vector<uint8_t> uiProcessCookieStorageIdentifier;
+#endif
+#if PLATFORM(IOS)
+    SandboxExtension::Handle cookieStorageDirectoryExtensionHandle;
+#endif
+};
+
+} // namespace WebKit
index f957a62..4e8ca1b 100644 (file)
@@ -35,7 +35,7 @@ Ref<WebsiteDataStore> WebsiteDataStore::defaultDataStore()
 {
     WebKit::InitializeWebKit2();
 
-    static WebsiteDataStore* defaultDataStore = adoptRef(new WebsiteDataStore(defaultDataStoreConfiguration())).leakRef();
+    static WebsiteDataStore* defaultDataStore = adoptRef(new WebsiteDataStore(defaultDataStoreConfiguration(), WebCore::SessionID::defaultSessionID())).leakRef();
 
     return *defaultDataStore;
 }
@@ -45,9 +45,9 @@ Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistentDataStore()
     return adoptRef(*new WebsiteDataStore);
 }
 
-Ref<WebsiteDataStore> WebsiteDataStore::create(WebKit::WebsiteDataStore::Configuration configuration)
+Ref<WebsiteDataStore> WebsiteDataStore::createLegacy(WebKit::WebsiteDataStore::Configuration configuration)
 {
-    return adoptRef(*new WebsiteDataStore(WTFMove(configuration)));
+    return adoptRef(*new WebsiteDataStore(WTFMove(configuration), WebCore::SessionID::defaultSessionID()));
 }
 
 WebsiteDataStore::WebsiteDataStore()
@@ -55,8 +55,8 @@ WebsiteDataStore::WebsiteDataStore()
 {
 }
 
-WebsiteDataStore::WebsiteDataStore(WebKit::WebsiteDataStore::Configuration configuration)
-    : m_websiteDataStore(WebKit::WebsiteDataStore::create(WTFMove(configuration)))
+WebsiteDataStore::WebsiteDataStore(WebKit::WebsiteDataStore::Configuration configuration, WebCore::SessionID sessionID)
+    : m_websiteDataStore(WebKit::WebsiteDataStore::create(WTFMove(configuration), sessionID))
 {
 }
 
index b392fd6..238c6c4 100644 (file)
@@ -37,9 +37,9 @@ class WebsiteDataStore final : public ObjectImpl<Object::Type::WebsiteDataStore>
 public:
     static Ref<WebsiteDataStore> defaultDataStore();
     static Ref<WebsiteDataStore> createNonPersistentDataStore();
-    static Ref<WebsiteDataStore> create(WebKit::WebsiteDataStore::Configuration);
+    static Ref<WebsiteDataStore> createLegacy(WebKit::WebsiteDataStore::Configuration);
 
-    explicit WebsiteDataStore(WebKit::WebsiteDataStore::Configuration);
+    explicit WebsiteDataStore(WebKit::WebsiteDataStore::Configuration, WebCore::SessionID);
     virtual ~WebsiteDataStore();
 
     bool isPersistent();
index 6f8d7d5..a122f3f 100644 (file)
@@ -163,7 +163,7 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
     if (configuration._cookieStorageDirectory)
         config.cookieStorageDirectory = configuration._cookieStorageDirectory.path;
 
-    API::Object::constructInWrapper<API::WebsiteDataStore>(self, config);
+    API::Object::constructInWrapper<API::WebsiteDataStore>(self, config, WebCore::SessionID::generatePersistentSessionID());
 
     return self;
 }
index d0a9119..c4e340e 100644 (file)
@@ -350,7 +350,7 @@ static void webkit_website_data_manager_class_init(WebKitWebsiteDataManagerClass
 WebKitWebsiteDataManager* webkitWebsiteDataManagerCreate(WebsiteDataStore::Configuration&& configuration)
 {
     WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(g_object_new(WEBKIT_TYPE_WEBSITE_DATA_MANAGER, nullptr));
-    manager->priv->websiteDataStore = API::WebsiteDataStore::create(WTFMove(configuration));
+    manager->priv->websiteDataStore = API::WebsiteDataStore::createLegacy(WTFMove(configuration));
 
     return manager;
 }
@@ -369,7 +369,7 @@ API::WebsiteDataStore& webkitWebsiteDataManagerGetDataStore(WebKitWebsiteDataMan
         configuration.webSQLDatabaseDirectory = !priv->webSQLDirectory ?
             API::WebsiteDataStore::defaultWebSQLDatabaseDirectory() : WebCore::stringFromFileSystemRepresentation(priv->webSQLDirectory.get());
         configuration.mediaKeysStorageDirectory = API::WebsiteDataStore::defaultMediaKeysStorageDirectory();
-        priv->websiteDataStore = API::WebsiteDataStore::create(WTFMove(configuration));
+        priv->websiteDataStore = API::WebsiteDataStore::createLegacy(WTFMove(configuration));
     }
 
     return *priv->websiteDataStore;
index bd029ba..7c6b86f 100644 (file)
@@ -489,11 +489,6 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
 
     m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this);
 
-    if (m_sessionID.isEphemeral()) {
-        m_process->processPool().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(m_sessionID));
-        m_process->processPool().sendToAllProcesses(Messages::WebProcess::EnsurePrivateBrowsingSession(m_sessionID));
-    }
-
 #if PLATFORM(COCOA)
     const CFIndex activityStateChangeRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit - 1;
     m_activityStateChangeDispatcher = std::make_unique<RunLoopObserver>(activityStateChangeRunLoopOrder, [this] {
index 8ae32e0..27023a4 100644 (file)
@@ -301,6 +301,8 @@ public:
     const API::PageConfiguration& configuration() const;
 
     uint64_t pageID() const { return m_pageID; }
+
+    // FIXME: Don't keep a separate sessionID - Rely on the WebsiteDataStore
     WebCore::SessionID sessionID() const { return m_sessionID; }
 
     WebFrameProxy* mainFrame() const { return m_mainFrame.get(); }
@@ -1841,6 +1843,9 @@ private:
 #endif
 
     const uint64_t m_pageID;
+
+
+    // FIXME: Don't keep a separate sessionID - Rely on the WebsiteDataStore
     const WebCore::SessionID m_sessionID;
 
     bool m_isPageSuspended;
index ee4847c..45292f0 100644 (file)
@@ -68,6 +68,7 @@
 #include "WebProcessPoolMessages.h"
 #include "WebProcessProxy.h"
 #include "WebsiteDataStore.h"
+#include "WebsiteDataStoreParameters.h"
 #include <WebCore/ApplicationCacheStorage.h>
 #include <WebCore/Language.h>
 #include <WebCore/LinkHash.h>
@@ -229,7 +230,7 @@ WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration)
     , m_shouldUseFontSmoothing(true)
     , m_memorySamplerEnabled(false)
     , m_memorySamplerInterval(1400.0)
-    , m_websiteDataStore(m_configuration->shouldHaveLegacyDataStore() ? API::WebsiteDataStore::create(legacyWebsiteDataStoreConfiguration(m_configuration)) : API::WebsiteDataStore::defaultDataStore())
+    , m_websiteDataStore(m_configuration->shouldHaveLegacyDataStore() ? API::WebsiteDataStore::createLegacy(legacyWebsiteDataStoreConfiguration(m_configuration)) : API::WebsiteDataStore::defaultDataStore())
 #if PLATFORM(MAC)
     , m_highPerformanceGraphicsUsageSampler(std::make_unique<HighPerformanceGraphicsUsageSampler>(*this))
     , m_perActivityStateCPUUsageSampler(std::make_unique<PerActivityStateCPUUsageSampler>(*this))
@@ -570,13 +571,13 @@ void WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled(bool private
         if (privateBrowsingEnabled)
             networkProcess()->send(Messages::NetworkProcess::EnsurePrivateBrowsingSession(SessionID::legacyPrivateSessionID()), 0);
         else
-            networkProcess()->send(Messages::NetworkProcess::DestroyPrivateBrowsingSession(SessionID::legacyPrivateSessionID()), 0);
+            networkProcess()->send(Messages::NetworkProcess::DestroySession(SessionID::legacyPrivateSessionID()), 0);
     }
 
     if (privateBrowsingEnabled)
         sendToAllProcesses(Messages::WebProcess::EnsurePrivateBrowsingSession(SessionID::legacyPrivateSessionID()));
     else
-        sendToAllProcesses(Messages::WebProcess::DestroyPrivateBrowsingSession(SessionID::legacyPrivateSessionID()));
+        sendToAllProcesses(Messages::WebProcess::DestroySession(SessionID::legacyPrivateSessionID()));
 }
 
 void (*s_invalidMessageCallback)(WKStringRef messageName);
@@ -929,6 +930,15 @@ void WebProcessPool::pageAddedToProcess(WebPageProxy& page)
 {
     auto result = m_sessionToPagesMap.add(page.sessionID(), HashSet<WebPageProxy*>()).iterator->value.add(&page);
     ASSERT_UNUSED(result, result.isNewEntry);
+
+    auto sessionID = page.sessionID();
+    if (sessionID.isEphemeral()) {
+        sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(sessionID));
+        page.process().send(Messages::WebProcess::EnsurePrivateBrowsingSession(sessionID), 0);
+    } else if (sessionID != SessionID::defaultSessionID()) {
+        sendToNetworkingProcess(Messages::NetworkProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()));
+        page.process().send(Messages::WebProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()), 0);
+    }
 }
 
 void WebProcessPool::pageRemovedFromProcess(WebPageProxy& page)
@@ -947,11 +957,8 @@ void WebProcessPool::pageRemovedFromProcess(WebPageProxy& page)
             return;
 
         // The last user of this non-default SessionID is gone, so clean it up in the child processes.
-
-        // FIXME: Remove this ASSERT and change these messages once multiple persistent sessions exist.
-        ASSERT(sessionID.isEphemeral());
-        networkProcess()->send(Messages::NetworkProcess::DestroyPrivateBrowsingSession(sessionID), 0);
-        page.process().send(Messages::WebProcess::DestroyPrivateBrowsingSession(sessionID), 0);
+        networkProcess()->send(Messages::NetworkProcess::DestroySession(sessionID), 0);
+        page.process().send(Messages::WebProcess::DestroySession(sessionID), 0);
     }
 }
 
index 9c79881..0c400db 100644 (file)
@@ -28,6 +28,8 @@
 
 #import "StorageManager.h"
 #import "WebResourceLoadStatisticsStore.h"
+#import "WebsiteDataStoreParameters.h"
+#import <WebCore/CFNetworkSPI.h>
 #import <WebCore/SearchPopupMenuCocoa.h>
 #import <wtf/NeverDestroyed.h>
 
@@ -46,6 +48,34 @@ static Vector<WebsiteDataStore*>& dataStoresWithStorageManagers()
     return dataStoresWithStorageManagers;
 }
 
+WebsiteDataStoreParameters WebsiteDataStore::parameters()
+{
+    WebsiteDataStoreParameters parameters;
+
+    parameters.sessionID = m_sessionID;
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    if (m_uiProcessCookieStorageIdentifier.isEmpty()) {
+        auto cookiePath = resolvedCookieStorageDirectory().utf8();
+        auto url = adoptCF(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)cookiePath.data(), (CFIndex)cookiePath.length(), true));
+        m_cfCookieStorage = adoptCF(CFHTTPCookieStorageCreateFromFile(kCFAllocatorDefault, url.get(), nullptr));
+        auto cfData = adoptCF(CFHTTPCookieStorageCreateIdentifyingData(kCFAllocatorDefault, m_cfCookieStorage.get()));
+
+        m_uiProcessCookieStorageIdentifier.append(CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()));
+    }
+
+    parameters.uiProcessCookieStorageIdentifier = m_uiProcessCookieStorageIdentifier;
+#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+
+#if PLATFORM(IOS)
+    String cookieStorageDirectory = resolvedCookieStorageDirectory();
+    if (!cookieStorageDirectory.isEmpty())
+        SandboxExtension::createHandleForReadWriteDirectory(cookieStorageDirectory, parameters.cookieStorageDirectoryExtensionHandle);
+#endif
+
+    return parameters;
+}
+
 void WebsiteDataStore::platformInitialize()
 {
     if (!m_storageManager)
index 462d50c..f55ebb1 100644 (file)
@@ -36,6 +36,7 @@
 #include "WebResourceLoadStatisticsStore.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include "WebsiteData.h"
+#include "WebsiteDataStoreParameters.h"
 #include <WebCore/ApplicationCacheStorage.h>
 #include <WebCore/DatabaseTracker.h>
 #include <WebCore/HTMLMediaElement.h>
@@ -63,14 +64,14 @@ Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistent()
     return adoptRef(*new WebsiteDataStore(WebCore::SessionID::generateEphemeralSessionID()));
 }
 
-Ref<WebsiteDataStore> WebsiteDataStore::create(Configuration configuration)
+Ref<WebsiteDataStore> WebsiteDataStore::create(Configuration configuration, WebCore::SessionID sessionID)
 {
-    return adoptRef(*new WebsiteDataStore(WTFMove(configuration)));
+    return adoptRef(*new WebsiteDataStore(WTFMove(configuration), sessionID));
 }
 
-WebsiteDataStore::WebsiteDataStore(Configuration configuration)
+WebsiteDataStore::WebsiteDataStore(Configuration configuration, WebCore::SessionID sessionID)
     : m_identifier(generateIdentifier())
-    , m_sessionID(WebCore::SessionID::defaultSessionID())
+    , m_sessionID(sessionID)
     , m_configuration(WTFMove(configuration))
     , m_storageManager(StorageManager::create(m_configuration.localStorageDirectory))
     , m_resourceLoadStatistics(WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory))
@@ -92,9 +93,9 @@ WebsiteDataStore::~WebsiteDataStore()
 {
     platformDestroy();
 
-    if (m_sessionID.isEphemeral()) {
+    if (m_sessionID.isValid() && m_sessionID != WebCore::SessionID::defaultSessionID()) {
         for (auto& processPool : WebProcessPool::allProcessPools())
-            processPool->sendToNetworkingProcess(Messages::NetworkProcess::DestroyPrivateBrowsingSession(m_sessionID));
+            processPool->sendToNetworkingProcess(Messages::NetworkProcess::DestroySession(m_sessionID));
     }
 }
 
@@ -114,6 +115,7 @@ void WebsiteDataStore::resolveDirectoriesIfNecessary()
     m_resolvedConfiguration.mediaCacheDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration.mediaCacheDirectory);
     m_resolvedConfiguration.mediaKeysStorageDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration.mediaKeysStorageDirectory);
     m_resolvedConfiguration.webSQLDatabaseDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration.webSQLDatabaseDirectory);
+    m_resolvedConfiguration.cookieStorageDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration.cookieStorageDirectory);
 
     if (!m_configuration.javaScriptConfigurationDirectory.isEmpty())
         m_resolvedConfiguration.javaScriptConfigurationDirectory = resolvePathForSandboxExtension(m_configuration.javaScriptConfigurationDirectory);
@@ -1235,4 +1237,13 @@ void WebsiteDataStore::registerSharedResourceLoadObserver()
 #endif
 }
 
+#if !PLATFORM(COCOA)
+WebsiteDataStoreParameters WebsiteDataStore::parameters()
+{
+    // FIXME: Implement.
+
+    return { };
+}
+#endif
+
 }
index 506d09c..9c71e6d 100644 (file)
 #include <wtf/WorkQueue.h>
 #include <wtf/text/WTFString.h>
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+#include <WebCore/CFNetworkSPI.h>
+#endif
+
 namespace WebCore {
 class SecurityOrigin;
 }
@@ -50,6 +54,7 @@ class WebResourceLoadStatisticsStore;
 enum class WebsiteDataFetchOption;
 enum class WebsiteDataType;
 struct WebsiteDataRecord;
+struct WebsiteDataStoreParameters;
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
 struct PluginModuleInfo;
@@ -72,7 +77,7 @@ public:
         String cookieStorageDirectory;
     };
     static Ref<WebsiteDataStore> createNonPersistent();
-    static Ref<WebsiteDataStore> create(Configuration);
+    static Ref<WebsiteDataStore> create(Configuration, WebCore::SessionID);
     virtual ~WebsiteDataStore();
 
     uint64_t identifier() const { return m_identifier; }
@@ -108,9 +113,11 @@ public:
     WebProcessPool* processPoolForCookieStorageOperations();
     bool isAssociatedProcessPool(WebProcessPool&) const;
 
+    WebsiteDataStoreParameters parameters();
+
 private:
     explicit WebsiteDataStore(WebCore::SessionID);
-    explicit WebsiteDataStore(Configuration);
+    explicit WebsiteDataStore(Configuration, WebCore::SessionID);
 
     // WebProcessLifetimeObserver.
     void webPageWasAdded(WebPageProxy&) override;
@@ -145,6 +152,11 @@ private:
     const RefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics;
 
     Ref<WorkQueue> m_queue;
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    Vector<uint8_t> m_uiProcessCookieStorageIdentifier;
+    RetainPtr<CFHTTPCookieStorageRef> m_cfCookieStorage;
+#endif
 };
 
 }
index 2b35b66..cd0853a 100644 (file)
                511B24A7132E095700065A0C /* WebIconDatabaseProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B24A5132E095700065A0C /* WebIconDatabaseProxy.h */; };
                511B24AA132E097200065A0C /* WebIconDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511B24A8132E097200065A0C /* WebIconDatabase.cpp */; };
                511B24AB132E097200065A0C /* WebIconDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B24A9132E097200065A0C /* WebIconDatabase.h */; };
+               511F7D411EB1BCF500E47B83 /* WebsiteDataStoreParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */; };
+               511F7D421EB1BCF800E47B83 /* WebsiteDataStoreParameters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511F7D3F1EB1BCEE00E47B83 /* WebsiteDataStoreParameters.cpp */; };
                511F8A7B138B460900A95F44 /* SecItemShimLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F8A77138B460900A95F44 /* SecItemShimLibrary.h */; };
                511F8A81138B485D00A95F44 /* SecItemShimLibrary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */; };
                5120C8311E54EDDE0025B250 /* LocalStorageDatabaseTrackerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5120C8301E54E2650025B250 /* LocalStorageDatabaseTrackerIOS.mm */; };
                511B24A5132E095700065A0C /* WebIconDatabaseProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebIconDatabaseProxy.h; path = IconDatabase/WebIconDatabaseProxy.h; sourceTree = "<group>"; };
                511B24A8132E097200065A0C /* WebIconDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebIconDatabase.cpp; sourceTree = "<group>"; };
                511B24A9132E097200065A0C /* WebIconDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIconDatabase.h; sourceTree = "<group>"; };
+               511F7D3F1EB1BCEE00E47B83 /* WebsiteDataStoreParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebsiteDataStoreParameters.cpp; sourceTree = "<group>"; };
+               511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteDataStoreParameters.h; sourceTree = "<group>"; };
                511F8A77138B460900A95F44 /* SecItemShimLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SecItemShimLibrary.h; path = ../../WebProcess/mac/SecItemShimLibrary.h; sourceTree = "<group>"; };
                511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SecItemShimLibrary.mm; path = ../../WebProcess/mac/SecItemShimLibrary.mm; sourceTree = "<group>"; };
                5120C8301E54E2650025B250 /* LocalStorageDatabaseTrackerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageDatabaseTrackerIOS.mm; sourceTree = "<group>"; };
                                3760881C150413E900FC82C7 /* WebRenderObject.cpp */,
                                3760881D150413E900FC82C7 /* WebRenderObject.h */,
                                5C9E567F1DF7930900C9EE33 /* WebsitePolicies.h */,
+                               511F7D3F1EB1BCEE00E47B83 /* WebsiteDataStoreParameters.cpp */,
+                               511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */,
                                8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */,
                                8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */,
                                C0337DD7127A51B6008FF4F4 /* WebTouchEvent.cpp */,
                        path = NetworkProcess/cache;
                        sourceTree = "<group>";
                };
-               F4D7BCCA1EA494FA00C421D3 /* Recovered References */ = {
-                       isa = PBXGroup;
-                       children = (
-                               C58CDF281887548B00871536 /* InteractionInformationAtPosition.h */,
-                       );
-                       name = "Recovered References";
-                       sourceTree = "<group>";
-               };
                F638955A133BF57D008941D5 /* mac */ = {
                        isa = PBXGroup;
                        children = (
                                E152551B17011819003D7ADB /* NetworkResourceLoaderMessages.h in Headers */,
                                5C1426F01C23F80900D41183 /* NetworkResourceLoadParameters.h in Headers */,
                                413075AC1DE85F370039EC69 /* NetworkRTCMonitor.h in Headers */,
+                               511F7D411EB1BCF500E47B83 /* WebsiteDataStoreParameters.h in Headers */,
                                41DC45961E3D6E2200B11F51 /* NetworkRTCProvider.h in Headers */,
                                413075AB1DE85F330039EC69 /* NetworkRTCSocket.h in Headers */,
                                5C20CBA01BB1ECD800895BB1 /* NetworkSession.h in Headers */,
                                515BE1B71D5A94FD00DD7C68 /* UIGamepadProviderMac.mm in Sources */,
                                1A64245F12DE29A100CAAE2C /* UpdateInfo.cpp in Sources */,
                                1AC1336718565B5700F3EC05 /* UserData.cpp in Sources */,
+                               511F7D421EB1BCF800E47B83 /* WebsiteDataStoreParameters.cpp in Sources */,
                                07297F9E1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.cpp in Sources */,
                                15739BBC1B42040300D258C1 /* UserMediaPermissionRequestManager.cpp in Sources */,
                                4A3CC18A19B063E700D14AEF /* UserMediaPermissionRequestManagerProxy.cpp in Sources */,
index 0def4a4..b3d9bc9 100644 (file)
@@ -33,6 +33,8 @@
 
 namespace WebKit {
 
+struct WebsiteDataStoreParameters;
+
 class WebFrameNetworkingContext : public WebCore::FrameNetworkingContext {
 public:
     static Ref<WebFrameNetworkingContext> create(WebFrame* frame)
@@ -42,6 +44,7 @@ public:
 
     // FIXME: remove platform-specific code and use SessionTracker
     static void ensurePrivateBrowsingSession(WebCore::SessionID);
+    static void ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&);
 
     static void setCookieAcceptPolicyForAllContexts(HTTPCookieAcceptPolicy);
 
index 59c609c..485914f 100644 (file)
@@ -31,6 +31,7 @@
 #include "WebCookieManager.h"
 #include "WebPage.h"
 #include "WebProcess.h"
+#include "WebsiteDataStoreParameters.h"
 #include <WebCore/CFNetworkSPI.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
@@ -65,6 +66,36 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID
 #endif
 }
 
+void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+{
+    if (NetworkStorageSession::storageSession(parameters.sessionID))
+        return;
+
+    String base;
+    if (SessionTracker::getIdentifierBase().isNull())
+        base = [[NSBundle mainBundle] bundleIdentifier];
+    else
+        base = SessionTracker::getIdentifierBase();
+
+#if PLATFORM(IOS)
+    SandboxExtension::consumePermanently(parameters.cookieStorageDirectoryExtensionHandle);
+#endif
+
+    RetainPtr<CFHTTPCookieStorageRef> uiProcessCookieStorage;
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    RetainPtr<CFDataRef> cookieStorageData = adoptCF(CFDataCreate(kCFAllocatorDefault, parameters.uiProcessCookieStorageIdentifier.data(), parameters.uiProcessCookieStorageIdentifier.size()));
+    uiProcessCookieStorage = adoptCF(CFHTTPCookieStorageCreateFromIdentifyingData(kCFAllocatorDefault, cookieStorageData.get()));
+#endif
+
+    NetworkStorageSession::ensureSession(parameters.sessionID, base + '.' + String::number(parameters.sessionID.sessionID()), WTFMove(uiProcessCookieStorage));
+
+#if USE(NETWORK_SESSION)
+    auto networkSession = NetworkSession::create(parameters.sessionID);
+    SessionTracker::setSession(parameters.sessionID, WTFMove(networkSession));
+#endif
+}
+
 void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAcceptPolicy policy)
 {
     [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:static_cast<NSHTTPCookieAcceptPolicy>(policy)];
@@ -109,7 +140,7 @@ NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
         if (auto* storageSession = WebCore::NetworkStorageSession::storageSession(frame()->page()->sessionID()))
             return *storageSession;
         // Some requests may still be coming shortly after WebProcess was told to destroy its session.
-        LOG_ERROR("Invalid session ID. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
+        LOG_ERROR("WEB Invalid session ID. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
     }
     return NetworkStorageSession::defaultStorageSession();
 }
index a6476f1..b5b021f 100644 (file)
@@ -52,6 +52,11 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID
     SessionTracker::setSession(sessionID, NetworkSession::create(sessionID));
 }
 
+void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&)
+{
+    // FIXME: Implement
+}
+
 WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
     : FrameNetworkingContext(frame->coreFrame())
 {
index 5dfa8db..83f659b 100644 (file)
@@ -34,6 +34,7 @@ namespace WebKit {
 
 class WebFrame;
 class WebFrameLoaderClient;
+struct WebsiteDataStoreParameters;
 
 class WebFrameNetworkingContext : public WebCore::FrameNetworkingContext {
 public:
@@ -43,6 +44,7 @@ public:
     }
 
     static void ensurePrivateBrowsingSession(WebCore::SessionID);
+    static void ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&);
 
     WebFrameLoaderClient* webFrameLoaderClient() const;
 
index 4f03a6f..187eef9 100644 (file)
@@ -513,7 +513,12 @@ void WebProcess::ensurePrivateBrowsingSession(SessionID sessionID)
     WebFrameNetworkingContext::ensurePrivateBrowsingSession(sessionID);
 }
 
-void WebProcess::destroyPrivateBrowsingSession(SessionID sessionID)
+void WebProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters)
+{
+    WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WTFMove(parameters));
+}
+
+void WebProcess::destroySession(SessionID sessionID)
 {
     SessionTracker::destroySession(sessionID);
 }
index 82f44b1..b5b69f8 100644 (file)
@@ -95,6 +95,7 @@ struct WebPageGroupData;
 struct WebPreferencesStore;
 struct WebProcessCreationParameters;
 struct WebsiteData;
+struct WebsiteDataStoreParameters;
 
 #if ENABLE(DATABASE_PROCESS)
 class WebToDatabaseProcessConnection;
@@ -180,8 +181,9 @@ public:
     void setCacheModel(uint32_t);
 
     void ensurePrivateBrowsingSession(WebCore::SessionID);
-    void destroyPrivateBrowsingSession(WebCore::SessionID);
     void ensureLegacyPrivateBrowsingSessionInNetworkProcess();
+    void addWebsiteDataStore(WebsiteDataStoreParameters&&);
+    void destroySession(WebCore::SessionID);
 
     void pageDidEnterWindow(uint64_t pageID);
     void pageWillLeaveWindow(uint64_t pageID);
index b5b8cc1..680bf4d 100644 (file)
@@ -46,9 +46,9 @@ messages -> WebProcess LegacyReceiver {
 
     ClearCachedCredentials()
 
-    // Legacy private browsing session is per process. Individual pages or page groups may use the private session or the default one as appropriate.
     EnsurePrivateBrowsingSession(WebCore::SessionID sessionID)
-    DestroyPrivateBrowsingSession(WebCore::SessionID sessionID)
+    AddWebsiteDataStore(struct WebKit::WebsiteDataStoreParameters websiteDataStoreParameters);
+    DestroySession(WebCore::SessionID sessionID)
 
     # Plug-ins.
     DidAddPlugInAutoStartOriginHash(uint32_t hash, double expirationTime, WebCore::SessionID sessionID)
index caec46b..0104cb4 100644 (file)
@@ -45,6 +45,7 @@
 #import "WebPage.h"
 #import "WebProcessCreationParameters.h"
 #import "WebProcessProxyMessages.h"
+#import "WebsiteDataStoreParameters.h"
 #import <JavaScriptCore/Options.h>
 #import <WebCore/AXObjectCache.h>
 #import <WebCore/CFNetworkSPI.h>
index 6a151a9..57f6749 100644 (file)
@@ -1,3 +1,13 @@
+2017-04-28  Brady Eidson  <beidson@apple.com>
+
+        Start of support for multiple WebsiteDataStore/SessionIDs per process
+        https://bugs.webkit.org/show_bug.cgi?id=171422
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsiteDataStoreCustomPaths.mm:
+        (TEST):
+
 2017-04-28  Youenn Fablet  <youenn@apple.com>
 
         Adding a runtime flag specific to MediaDevices
index f534ee1..8f52014 100644 (file)
@@ -79,15 +79,25 @@ TEST(WebKit2, WebsiteDataStoreCustomPaths)
     NSURL *localStoragePath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/LocalStorage/" stringByExpandingTildeInPath]];
     NSURL *cookieStoragePath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/CookieStorage/" stringByExpandingTildeInPath]];
 
+    NSURL *defaultSQLPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/WebSQL/" stringByExpandingTildeInPath]];
+    NSURL *defaultIDBPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/" stringByExpandingTildeInPath]];
+    NSURL *defaultLocalStoragePath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/LocalStorage/" stringByExpandingTildeInPath]];
+
     [[NSFileManager defaultManager] removeItemAtURL:sqlPath error:nil];
     [[NSFileManager defaultManager] removeItemAtURL:idbPath error:nil];
     [[NSFileManager defaultManager] removeItemAtURL:localStoragePath error:nil];
     [[NSFileManager defaultManager] removeItemAtURL:cookieStoragePath error:nil];
+    [[NSFileManager defaultManager] removeItemAtURL:defaultSQLPath error:nil];
+    [[NSFileManager defaultManager] removeItemAtURL:defaultIDBPath error:nil];
+    [[NSFileManager defaultManager] removeItemAtURL:defaultLocalStoragePath error:nil];
 
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:sqlPath.path]);
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:idbPath.path]);
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:localStoragePath.path]);
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:cookieStoragePath.path]);
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:defaultSQLPath.path]);
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:defaultIDBPath.path]);
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:defaultLocalStoragePath.path]);
 
     _WKWebsiteDataStoreConfiguration *websiteDataStoreConfiguration = [[_WKWebsiteDataStoreConfiguration alloc] init];
     websiteDataStoreConfiguration._webSQLDatabaseDirectory = sqlPath;
@@ -111,12 +121,17 @@ TEST(WebKit2, WebsiteDataStoreCustomPaths)
 
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:sqlPath.path]);
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:localStoragePath.path]);
-    
-    // FIXME: Once this API works this should be true, and there should be a file that contains the bytes "testkey=value"
+
+    // FIXME: This should be true, but comes up false. Possibly a CFNetwork issue. Being explored in <rdar://problem/31666275>
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:cookieStoragePath.path]);
-    
-    // FIXME: <rdar://problem/30785618> - We don't yet support IDB database processes at custom paths per WebsiteDataStore
-    // EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:idbPath]);
+
+    // FIXME: <rdar://problem/30785618> - We don't yet support IDB database processes at custom paths per WebsiteDataStore (These should be flipped)
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:idbPath.path]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:defaultIDBPath.path]);
+
+    // FIXME: The default SQL and LocalStorage paths are being used for something, but they shouldn't be. (theses should be false, not true)
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:defaultSQLPath.path]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:defaultLocalStoragePath.path]);
 }
 
 #endif