CookieManager only works with the default session
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Feb 2017 10:43:14 +0000 (10:43 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Feb 2017 10:43:14 +0000 (10:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168229

Reviewed by Alex Christensen.

Source/WebCore:

Update cookie observer API to use a std::function instead of a function pointer and make it work with multiple
sessions in the backends that support it.

* platform/network/CookieStorage.h:
* platform/network/cf/CookieStorageCFNet.cpp:
(WebCore::cookieChangeCallbackMap):
(WebCore::notifyCookiesChanged):
(WebCore::startObservingCookieChanges):
(WebCore::stopObservingCookieChanges):
* platform/network/mac/CookieStorageMac.mm:
(-[WebCookieStorageObjCAdapter startListeningForCookieChangeNotificationsWithCallback:]):
(-[WebCookieStorageObjCAdapter stopListeningForCookieChangeNotifications]):
(WebCore::startObservingCookieChanges):
(WebCore::stopObservingCookieChanges):
* platform/network/soup/CookieStorageSoup.cpp:
(WebCore::cookieChangeCallbackMap):
(WebCore::soupCookiesChanged):
(WebCore::startObservingCookieChanges):
(WebCore::stopObservingCookieChanges):

Source/WebKit2:

Make CookieManager session aware by adding a SessionID parameter to all its functions, and update all the callers
to pass the default session ID, preserving the current
behavior. WebCookieManagerProxy::startObservingCookieChanges() now also receives an optional callback to be
called on every change.

* UIProcess/API/C/WKCookieManager.cpp:
(WKCookieManagerGetHostnamesWithCookies):
(WKCookieManagerDeleteCookiesForHostname):
(WKCookieManagerDeleteAllCookies):
(WKCookieManagerDeleteAllCookiesModifiedAfterDate):
(WKCookieManagerStartObservingCookieChanges):
(WKCookieManagerStopObservingCookieChanges):
* UIProcess/API/gtk/WebKitCookieManager.cpp:
(_WebKitCookieManagerPrivate::~_WebKitCookieManagerPrivate):
(webkitCookieManagerCreate):
(webkit_cookie_manager_set_persistent_storage):
(webkit_cookie_manager_get_domains_with_cookies):
(webkit_cookie_manager_delete_cookies_for_domain):
(webkit_cookie_manager_delete_all_cookies):
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::addSingleCookie):
(WebKit::WebAutomationSession::deleteAllCookies):
* UIProcess/WebCookieManagerProxy.cpp:
(WebKit::WebCookieManagerProxy::getHostnamesWithCookies):
(WebKit::WebCookieManagerProxy::deleteCookiesForHostname):
(WebKit::WebCookieManagerProxy::deleteAllCookies):
(WebKit::WebCookieManagerProxy::deleteAllCookiesModifiedSince):
(WebKit::WebCookieManagerProxy::addCookie):
(WebKit::WebCookieManagerProxy::startObservingCookieChanges):
(WebKit::WebCookieManagerProxy::stopObservingCookieChanges):
(WebKit::WebCookieManagerProxy::cookiesDidChange):
* UIProcess/WebCookieManagerProxy.h:
* UIProcess/WebCookieManagerProxy.messages.in:
* WebProcess/Cookies/WebCookieManager.cpp:
(WebKit::WebCookieManager::WebCookieManager):
(WebKit::WebCookieManager::getHostnamesWithCookies):
(WebKit::WebCookieManager::deleteCookiesForHostname):
(WebKit::WebCookieManager::deleteAllCookies):
(WebKit::WebCookieManager::deleteAllCookiesModifiedSince):
(WebKit::WebCookieManager::addCookie):
(WebKit::WebCookieManager::startObservingCookieChanges):
(WebKit::WebCookieManager::stopObservingCookieChanges):
* WebProcess/Cookies/WebCookieManager.h:
* WebProcess/Cookies/WebCookieManager.messages.in:

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/CookieStorage.h
Source/WebCore/platform/network/cf/CookieStorageCFNet.cpp
Source/WebCore/platform/network/mac/CookieStorageMac.mm
Source/WebCore/platform/network/soup/CookieStorageSoup.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKCookieManager.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp
Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp
Source/WebKit2/UIProcess/WebCookieManagerProxy.h
Source/WebKit2/UIProcess/WebCookieManagerProxy.messages.in
Source/WebKit2/WebProcess/Cookies/WebCookieManager.cpp
Source/WebKit2/WebProcess/Cookies/WebCookieManager.h
Source/WebKit2/WebProcess/Cookies/WebCookieManager.messages.in

index 27df4de..703d13d 100644 (file)
@@ -1,3 +1,30 @@
+2017-02-14  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        CookieManager only works with the default session
+        https://bugs.webkit.org/show_bug.cgi?id=168229
+
+        Reviewed by Alex Christensen.
+
+        Update cookie observer API to use a std::function instead of a function pointer and make it work with multiple
+        sessions in the backends that support it.
+
+        * platform/network/CookieStorage.h:
+        * platform/network/cf/CookieStorageCFNet.cpp:
+        (WebCore::cookieChangeCallbackMap):
+        (WebCore::notifyCookiesChanged):
+        (WebCore::startObservingCookieChanges):
+        (WebCore::stopObservingCookieChanges):
+        * platform/network/mac/CookieStorageMac.mm:
+        (-[WebCookieStorageObjCAdapter startListeningForCookieChangeNotificationsWithCallback:]):
+        (-[WebCookieStorageObjCAdapter stopListeningForCookieChangeNotifications]):
+        (WebCore::startObservingCookieChanges):
+        (WebCore::stopObservingCookieChanges):
+        * platform/network/soup/CookieStorageSoup.cpp:
+        (WebCore::cookieChangeCallbackMap):
+        (WebCore::soupCookiesChanged):
+        (WebCore::startObservingCookieChanges):
+        (WebCore::stopObservingCookieChanges):
+
 2017-02-13  Antoine Quint  <graouts@apple.com>
 
         REGRESSION: Update volume and scrubbing slider to match HI designs
index 9eca5ec..c5053cc 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef CookieStorage_h
-#define CookieStorage_h
+#pragma once
+
+#include <functional>
 
 namespace WebCore {
 
-// These are always observing the shared cookie storage, even when in private browsing mode.
+class NetworkStorageSession;
 
-typedef void(*CookieChangeCallbackPtr)();
-WEBCORE_EXPORT void startObservingCookieChanges(CookieChangeCallbackPtr);
-WEBCORE_EXPORT void stopObservingCookieChanges();
+WEBCORE_EXPORT void startObservingCookieChanges(const NetworkStorageSession&, std::function<void ()>&&);
+WEBCORE_EXPORT void stopObservingCookieChanges(const NetworkStorageSession&);
 
 }
 
-#endif
index 7e795e2..619b078 100644 (file)
@@ -27,7 +27,9 @@
 #include "CookieStorage.h"
 
 #include "NetworkStorageSession.h"
+#include <wtf/HashMap.h>
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 
 #if PLATFORM(COCOA)
 #include "WebCoreSystemInterface.h"
@@ -41,12 +43,17 @@ namespace WebCore {
 
 #if PLATFORM(WIN)
 
-static CookieChangeCallbackPtr cookieChangeCallback;
+static HashMap<CFHTTPCookieStorageRef, std::function<void ()>>& cookieChangeCallbackMap()
+{
+    static NeverDestroyed<HashMap<CFHTTPCookieStorageRef, std::function<void ()>>> map;
+    return map;
+}
 
-static void notifyCookiesChanged(CFHTTPCookieStorageRef, void *)
+static void notifyCookiesChanged(CFHTTPCookieStorageRef cookieStorage, void *)
 {
-    callOnMainThread([] {
-        cookieChangeCallback();
+    callOnMainThread([cookieStorage] {
+        if (auto callback = cookieChangeCallbackMap().get(cookieStorage))
+            callback();
     });
 }
 
@@ -61,35 +68,35 @@ static inline CFRunLoopRef cookieStorageObserverRunLoop()
     return loaderRunLoop();
 }
 
-void startObservingCookieChanges(CookieChangeCallbackPtr callback)
+void startObservingCookieChanges(const NetworkStorageSession& storageSession, std::function<void ()>&& callback)
 {
     ASSERT(isMainThread());
 
-    ASSERT(!cookieChangeCallback);
-    cookieChangeCallback = callback;
-
     CFRunLoopRef runLoop = cookieStorageObserverRunLoop();
     ASSERT(runLoop);
 
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage();
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = storageSession.cookieStorage();
     ASSERT(cookieStorage);
 
+    ASSERT(cookieChangeCallbackMap().contains(cookieStorage.get()));
+    cookieChangeCallbackMap().add(cookieStorage.get(), WTFMove(callback));
+
     CFHTTPCookieStorageScheduleWithRunLoop(cookieStorage.get(), runLoop, kCFRunLoopCommonModes);
     CFHTTPCookieStorageAddObserver(cookieStorage.get(), runLoop, kCFRunLoopDefaultMode, notifyCookiesChanged, 0);
 }
 
-void stopObservingCookieChanges()
+void stopObservingCookieChanges(const NetworkStorageSession& storageSession)
 {
     ASSERT(isMainThread());
 
-    cookieChangeCallback = 0;
-
     CFRunLoopRef runLoop = cookieStorageObserverRunLoop();
     ASSERT(runLoop);
 
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage();
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = storageSession.cookieStorage();
     ASSERT(cookieStorage);
 
+    cookieChangeCallbackMap().remove(cookieStorage.get());
+
     CFHTTPCookieStorageRemoveObserver(cookieStorage.get(), runLoop, kCFRunLoopDefaultMode, notifyCookiesChanged, 0);
     CFHTTPCookieStorageUnscheduleFromRunLoop(cookieStorage.get(), runLoop, kCFRunLoopCommonModes);
 }
index 8c0e8c5..e782b06 100644 (file)
 using namespace WebCore;
 
 @interface WebCookieStorageObjCAdapter : NSObject {
-    CookieChangeCallbackPtr m_cookieChangeCallback;
+    std::function<void ()> m_cookieChangeCallback;
 }
 -(void)notifyCookiesChangedOnMainThread;
 -(void)cookiesChangedNotificationHandler:(NSNotification *)notification;
--(void)startListeningForCookieChangeNotificationsWithCallback:(CookieChangeCallbackPtr)callback;
+-(void)startListeningForCookieChangeNotificationsWithCallback:(std::function<void ()>&&)callback;
 -(void)stopListeningForCookieChangeNotifications;
 @end
 
@@ -53,17 +53,17 @@ using namespace WebCore;
     [self performSelectorOnMainThread:@selector(notifyCookiesChangedOnMainThread) withObject:nil waitUntilDone:FALSE];
 }
 
--(void)startListeningForCookieChangeNotificationsWithCallback:(CookieChangeCallbackPtr)callback
+-(void)startListeningForCookieChangeNotificationsWithCallback:(std::function<void ()>&&)callback
 {
     ASSERT(!m_cookieChangeCallback);
-    m_cookieChangeCallback = callback;
+    m_cookieChangeCallback = WTFMove(callback);
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cookiesChangedNotificationHandler:) name:NSHTTPCookieManagerCookiesChangedNotification object:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
 }
 
 -(void)stopListeningForCookieChangeNotifications
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSHTTPCookieManagerCookiesChangedNotification object:nil];
-    m_cookieChangeCallback = 0;
+    m_cookieChangeCallback = nullptr;
 }
 
 @end
@@ -72,14 +72,14 @@ namespace WebCore {
 
 static WebCookieStorageObjCAdapter *cookieStorageAdapter;
 
-void startObservingCookieChanges(CookieChangeCallbackPtr callback)
+void startObservingCookieChanges(const NetworkStorageSession&, std::function<void ()>&& callback)
 {
     if (!cookieStorageAdapter)
         cookieStorageAdapter = [[WebCookieStorageObjCAdapter alloc] init];
-    [cookieStorageAdapter startListeningForCookieChangeNotificationsWithCallback:callback];
+    [cookieStorageAdapter startListeningForCookieChangeNotificationsWithCallback:WTFMove(callback)];
 }
 
-void stopObservingCookieChanges()
+void stopObservingCookieChanges(const NetworkStorageSession&)
 {
     // cookieStorageAdapter can be nil here, if the WebProcess crashed and was restarted between
     // when startObservingCookieChanges was called, and stopObservingCookieChanges is currently being called.
index f47fef0..b734966 100644 (file)
 
 #include "NetworkStorageSession.h"
 #include <libsoup/soup.h>
+#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
-static CookieChangeCallbackPtr cookieChangeCallback;
+static HashMap<SoupCookieJar*, std::function<void ()>>& cookieChangeCallbackMap()
+{
+    static NeverDestroyed<HashMap<SoupCookieJar*, std::function<void ()>>> map;
+    return map;
+}
 
 static void soupCookiesChanged(SoupCookieJar* jar)
 {
-    if (jar != NetworkStorageSession::defaultStorageSession().cookieStorage())
-        return;
-    cookieChangeCallback();
+    if (auto callback = cookieChangeCallbackMap().get(jar))
+        callback();
 }
 
-void startObservingCookieChanges(CookieChangeCallbackPtr callback)
+void startObservingCookieChanges(const NetworkStorageSession& storageSession, std::function<void ()>&& callback)
 {
-    ASSERT(!cookieChangeCallback);
-    cookieChangeCallback = callback;
-
-    g_signal_connect(NetworkStorageSession::defaultStorageSession().cookieStorage(), "changed", G_CALLBACK(soupCookiesChanged), 0);
+    auto* jar = storageSession.cookieStorage();
+    ASSERT(!cookieChangeCallbackMap().contains(jar));
+    cookieChangeCallbackMap().add(jar, WTFMove(callback));
+    g_signal_connect(jar, "changed", G_CALLBACK(soupCookiesChanged), nullptr);
 }
 
-void stopObservingCookieChanges()
+void stopObservingCookieChanges(const NetworkStorageSession& storageSession)
 {
-    g_signal_handlers_disconnect_by_func(NetworkStorageSession::defaultStorageSession().cookieStorage(), reinterpret_cast<void*>(soupCookiesChanged), nullptr);
-    cookieChangeCallback = nullptr;
+    auto* jar = storageSession.cookieStorage();
+    ASSERT(cookieChangeCallbackMap().contains(jar));
+    cookieChangeCallbackMap().remove(jar);
+    g_signal_handlers_disconnect_by_func(jar, reinterpret_cast<void*>(soupCookiesChanged), nullptr);
 }
 
 }
index 36d5690..f364d1f 100644 (file)
@@ -1,3 +1,55 @@
+2017-02-14  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        CookieManager only works with the default session
+        https://bugs.webkit.org/show_bug.cgi?id=168229
+
+        Reviewed by Alex Christensen.
+
+        Make CookieManager session aware by adding a SessionID parameter to all its functions, and update all the callers
+        to pass the default session ID, preserving the current
+        behavior. WebCookieManagerProxy::startObservingCookieChanges() now also receives an optional callback to be
+        called on every change.
+
+        * UIProcess/API/C/WKCookieManager.cpp:
+        (WKCookieManagerGetHostnamesWithCookies):
+        (WKCookieManagerDeleteCookiesForHostname):
+        (WKCookieManagerDeleteAllCookies):
+        (WKCookieManagerDeleteAllCookiesModifiedAfterDate):
+        (WKCookieManagerStartObservingCookieChanges):
+        (WKCookieManagerStopObservingCookieChanges):
+        * UIProcess/API/gtk/WebKitCookieManager.cpp:
+        (_WebKitCookieManagerPrivate::~_WebKitCookieManagerPrivate):
+        (webkitCookieManagerCreate):
+        (webkit_cookie_manager_set_persistent_storage):
+        (webkit_cookie_manager_get_domains_with_cookies):
+        (webkit_cookie_manager_delete_cookies_for_domain):
+        (webkit_cookie_manager_delete_all_cookies):
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::addSingleCookie):
+        (WebKit::WebAutomationSession::deleteAllCookies):
+        * UIProcess/WebCookieManagerProxy.cpp:
+        (WebKit::WebCookieManagerProxy::getHostnamesWithCookies):
+        (WebKit::WebCookieManagerProxy::deleteCookiesForHostname):
+        (WebKit::WebCookieManagerProxy::deleteAllCookies):
+        (WebKit::WebCookieManagerProxy::deleteAllCookiesModifiedSince):
+        (WebKit::WebCookieManagerProxy::addCookie):
+        (WebKit::WebCookieManagerProxy::startObservingCookieChanges):
+        (WebKit::WebCookieManagerProxy::stopObservingCookieChanges):
+        (WebKit::WebCookieManagerProxy::cookiesDidChange):
+        * UIProcess/WebCookieManagerProxy.h:
+        * UIProcess/WebCookieManagerProxy.messages.in:
+        * WebProcess/Cookies/WebCookieManager.cpp:
+        (WebKit::WebCookieManager::WebCookieManager):
+        (WebKit::WebCookieManager::getHostnamesWithCookies):
+        (WebKit::WebCookieManager::deleteCookiesForHostname):
+        (WebKit::WebCookieManager::deleteAllCookies):
+        (WebKit::WebCookieManager::deleteAllCookiesModifiedSince):
+        (WebKit::WebCookieManager::addCookie):
+        (WebKit::WebCookieManager::startObservingCookieChanges):
+        (WebKit::WebCookieManager::stopObservingCookieChanges):
+        * WebProcess/Cookies/WebCookieManager.h:
+        * WebProcess/Cookies/WebCookieManager.messages.in:
+
 2017-02-14  Tomas Popela  <tpopela@redhat.com>
 
         Unreviewed, fix documentation typo
index e4a3061..7624bee 100644 (file)
@@ -43,17 +43,17 @@ void WKCookieManagerSetClient(WKCookieManagerRef cookieManagerRef, const WKCooki
 
 void WKCookieManagerGetHostnamesWithCookies(WKCookieManagerRef cookieManagerRef, void* context, WKCookieManagerGetCookieHostnamesFunction callback)
 {
-    toImpl(cookieManagerRef)->getHostnamesWithCookies(toGenericCallbackFunction(context, callback));
+    toImpl(cookieManagerRef)->getHostnamesWithCookies(WebCore::SessionID::defaultSessionID(), toGenericCallbackFunction(context, callback));
 }
 
 void WKCookieManagerDeleteCookiesForHostname(WKCookieManagerRef cookieManagerRef, WKStringRef hostname)
 {
-    toImpl(cookieManagerRef)->deleteCookiesForHostname(toImpl(hostname)->string());
+    toImpl(cookieManagerRef)->deleteCookiesForHostname(WebCore::SessionID::defaultSessionID(), toImpl(hostname)->string());
 }
 
 void WKCookieManagerDeleteAllCookies(WKCookieManagerRef cookieManagerRef)
 {
-    toImpl(cookieManagerRef)->deleteAllCookies();
+    toImpl(cookieManagerRef)->deleteAllCookies(WebCore::SessionID::defaultSessionID());
 }
 
 void WKCookieManagerDeleteAllCookiesModifiedAfterDate(WKCookieManagerRef cookieManagerRef, double date)
@@ -61,7 +61,7 @@ void WKCookieManagerDeleteAllCookiesModifiedAfterDate(WKCookieManagerRef cookieM
     using namespace std::chrono;
 
     auto time = system_clock::time_point(duration_cast<system_clock::duration>(duration<double>(date)));
-    toImpl(cookieManagerRef)->deleteAllCookiesModifiedSince(time);
+    toImpl(cookieManagerRef)->deleteAllCookiesModifiedSince(WebCore::SessionID::defaultSessionID(), time);
 }
 
 void WKCookieManagerSetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager, WKHTTPCookieAcceptPolicy policy)
@@ -76,10 +76,10 @@ void WKCookieManagerGetHTTPCookieAcceptPolicy(WKCookieManagerRef cookieManager,
 
 void WKCookieManagerStartObservingCookieChanges(WKCookieManagerRef cookieManager)
 {
-    toImpl(cookieManager)->startObservingCookieChanges();
+    toImpl(cookieManager)->startObservingCookieChanges(WebCore::SessionID::defaultSessionID());
 }
 
 void WKCookieManagerStopObservingCookieChanges(WKCookieManagerRef cookieManager)
 {
-    toImpl(cookieManager)->stopObservingCookieChanges();
+    toImpl(cookieManager)->stopObservingCookieChanges(WebCore::SessionID::defaultSessionID());
 }
index 6f47f60..c03cc0a 100644 (file)
@@ -55,7 +55,7 @@ enum {
 struct _WebKitCookieManagerPrivate {
     ~_WebKitCookieManagerPrivate()
     {
-        webCookieManager->stopObservingCookieChanges();
+        webCookieManager->stopObservingCookieChanges(WebCore::SessionID::defaultSessionID());
     }
 
     RefPtr<WebCookieManagerProxy> webCookieManager;
@@ -145,7 +145,7 @@ WebKitCookieManager* webkitCookieManagerCreate(WebCookieManagerProxy* webCookieM
         cookiesDidChange
     };
     WKCookieManagerSetClient(toAPI(webCookieManager), &wkCookieManagerClient.base);
-    manager->priv->webCookieManager->startObservingCookieChanges();
+    manager->priv->webCookieManager->startObservingCookieChanges(WebCore::SessionID::defaultSessionID());
 
     return manager;
 }
@@ -169,9 +169,9 @@ void webkit_cookie_manager_set_persistent_storage(WebKitCookieManager* manager,
     g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
     g_return_if_fail(filename);
 
-    manager->priv->webCookieManager->stopObservingCookieChanges();
+    manager->priv->webCookieManager->stopObservingCookieChanges(WebCore::SessionID::defaultSessionID());
     manager->priv->webCookieManager->setCookiePersistentStorage(String::fromUTF8(filename), toSoupCookiePersistentStorageType(storage));
-    manager->priv->webCookieManager->startObservingCookieChanges();
+    manager->priv->webCookieManager->startObservingCookieChanges(WebCore::SessionID::defaultSessionID());
 }
 
 /**
@@ -269,7 +269,7 @@ void webkit_cookie_manager_get_domains_with_cookies(WebKitCookieManager* manager
     g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 
     GTask* task = g_task_new(manager, cancellable, callback, userData);
-    manager->priv->webCookieManager->getHostnamesWithCookies(toGenericCallbackFunction(task, webkitCookieManagerGetDomainsWithCookiesCallback));
+    manager->priv->webCookieManager->getHostnamesWithCookies(WebCore::SessionID::defaultSessionID(), toGenericCallbackFunction(task, webkitCookieManagerGetDomainsWithCookiesCallback));
 }
 
 /**
@@ -305,7 +305,7 @@ void webkit_cookie_manager_delete_cookies_for_domain(WebKitCookieManager* manage
     g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
     g_return_if_fail(domain);
 
-    manager->priv->webCookieManager->deleteCookiesForHostname(String::fromUTF8(domain));
+    manager->priv->webCookieManager->deleteCookiesForHostname(WebCore::SessionID::defaultSessionID(), String::fromUTF8(domain));
 }
 
 /**
@@ -318,5 +318,5 @@ void webkit_cookie_manager_delete_all_cookies(WebKitCookieManager* manager)
 {
     g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 
-    manager->priv->webCookieManager->deleteAllCookies();
+    manager->priv->webCookieManager->deleteAllCookies(WebCore::SessionID::defaultSessionID());
 }
index 228ea53..f748eee 100644 (file)
@@ -727,7 +727,7 @@ void WebAutomationSession::addSingleCookie(ErrorString& errorString, const Strin
         FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The parameter 'httpOnly' was not found.");
 
     WebCookieManagerProxy* cookieManager = m_processPool->supplement<WebCookieManagerProxy>();
-    cookieManager->addCookie(cookie, activeURL.host());
+    cookieManager->addCookie(WebCore::SessionID::defaultSessionID(), cookie, activeURL.host());
 
     callback->sendSuccess();
 }
@@ -742,7 +742,7 @@ void WebAutomationSession::deleteAllCookies(ErrorString& errorString, const Stri
     ASSERT(activeURL.isValid());
 
     WebCookieManagerProxy* cookieManager = m_processPool->supplement<WebCookieManagerProxy>();
-    cookieManager->deleteCookiesForHostname(activeURL.host());
+    cookieManager->deleteCookiesForHostname(WebCore::SessionID::defaultSessionID(), activeURL.host());
 }
 
 #if USE(APPKIT)
index c6ff936..a1b2c6d 100644 (file)
@@ -93,15 +93,15 @@ void WebCookieManagerProxy::derefWebContextSupplement()
     API::Object::deref();
 }
 
-void WebCookieManagerProxy::getHostnamesWithCookies(std::function<void (API::Array*, CallbackBase::Error)> callbackFunction)
+void WebCookieManagerProxy::getHostnamesWithCookies(WebCore::SessionID sessionID, std::function<void (API::Array*, CallbackBase::Error)> callbackFunction)
 {
     auto callback = ArrayCallback::create(WTFMove(callbackFunction));
     uint64_t callbackID = callback->callbackID();
     m_arrayCallbacks.set(callbackID, WTFMove(callback));
 
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::GetHostnamesWithCookies(callbackID));
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::GetHostnamesWithCookies(sessionID, callbackID));
 }
-    
+
 void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hostnames, uint64_t callbackID)
 {
     RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID);
@@ -113,39 +113,44 @@ void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hos
     callback->performCallbackWithReturnValue(API::Array::createStringArray(hostnames).ptr());
 }
 
-void WebCookieManagerProxy::deleteCookiesForHostname(const String& hostname)
+void WebCookieManagerProxy::deleteCookiesForHostname(WebCore::SessionID sessionID, const String& hostname)
 {
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteCookiesForHostname(hostname));
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteCookiesForHostname(sessionID, hostname));
 }
 
-void WebCookieManagerProxy::deleteAllCookies()
+void WebCookieManagerProxy::deleteAllCookies(WebCore::SessionID sessionID)
 {
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookies());
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookies(sessionID));
 }
 
-void WebCookieManagerProxy::deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point time)
+void WebCookieManagerProxy::deleteAllCookiesModifiedSince(WebCore::SessionID sessionID, std::chrono::system_clock::time_point time)
 {
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookiesModifiedSince(time));
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookiesModifiedSince(sessionID, time));
 }
 
-void WebCookieManagerProxy::addCookie(const WebCore::Cookie& cookie, const String& hostname)
+void WebCookieManagerProxy::addCookie(WebCore::SessionID sessionID, const WebCore::Cookie& cookie, const String& hostname)
 {
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::AddCookie(cookie, hostname));
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::AddCookie(sessionID, cookie, hostname));
 }
 
-void WebCookieManagerProxy::startObservingCookieChanges()
+void WebCookieManagerProxy::startObservingCookieChanges(WebCore::SessionID sessionID, std::function<void ()>&& callback)
 {
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges());
+    if (callback)
+        m_cookieObservers.set(sessionID, WTFMove(callback));
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges(sessionID));
 }
 
-void WebCookieManagerProxy::stopObservingCookieChanges()
+void WebCookieManagerProxy::stopObservingCookieChanges(WebCore::SessionID sessionID)
 {
-    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StopObservingCookieChanges());
+    m_cookieObservers.remove(sessionID);
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StopObservingCookieChanges(sessionID));
 }
 
-void WebCookieManagerProxy::cookiesDidChange()
+void WebCookieManagerProxy::cookiesDidChange(WebCore::SessionID sessionID)
 {
     m_client.cookiesDidChange(this);
+    if (auto callback = m_cookieObservers.get(sessionID))
+        callback();
 }
 
 void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy)
index 5466c95..7206ca6 100644 (file)
@@ -31,6 +31,7 @@
 #include "MessageReceiver.h"
 #include "WebContextSupplement.h"
 #include "WebCookieManagerProxyClient.h"
+#include <WebCore/SessionID.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
@@ -64,17 +65,17 @@ public:
 
     void initializeClient(const WKCookieManagerClientBase*);
     
-    void getHostnamesWithCookies(std::function<void (API::Array*, CallbackBase::Error)>);
-    void deleteCookiesForHostname(const String& hostname);
-    void deleteAllCookies();
-    void deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point);
-    void addCookie(const WebCore::Cookie&, const String& hostname);
+    void getHostnamesWithCookies(WebCore::SessionID, std::function<void (API::Array*, CallbackBase::Error)>);
+    void deleteCookiesForHostname(WebCore::SessionID, const String& hostname);
+    void deleteAllCookies(WebCore::SessionID);
+    void deleteAllCookiesModifiedSince(WebCore::SessionID, std::chrono::system_clock::time_point);
+    void addCookie(WebCore::SessionID, const WebCore::Cookie&, const String& hostname);
 
     void setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy);
     void getHTTPCookieAcceptPolicy(std::function<void (HTTPCookieAcceptPolicy, CallbackBase::Error)>);
 
-    void startObservingCookieChanges();
-    void stopObservingCookieChanges();
+    void startObservingCookieChanges(WebCore::SessionID, std::function<void ()>&& = nullptr);
+    void stopObservingCookieChanges(WebCore::SessionID);
 
 #if USE(SOUP)
     void setCookiePersistentStorage(const String& storagePath, uint32_t storageType);
@@ -90,7 +91,7 @@ private:
     void didGetHostnamesWithCookies(const Vector<String>&, uint64_t callbackID);
     void didGetHTTPCookieAcceptPolicy(uint32_t policy, uint64_t callbackID);
 
-    void cookiesDidChange();
+    void cookiesDidChange(WebCore::SessionID);
 
     // WebContextSupplement
     void processPoolDestroyed() override;
@@ -109,6 +110,8 @@ private:
     HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks;
     HashMap<uint64_t, RefPtr<HTTPCookieAcceptPolicyCallback>> m_httpCookieAcceptPolicyCallbacks;
 
+    HashMap<WebCore::SessionID, std::function<void ()>> m_cookieObservers;
+
     WebCookieManagerProxyClient m_client;
 
 #if USE(SOUP)
index 49ac6db..12e0090 100644 (file)
@@ -24,5 +24,5 @@ messages -> WebCookieManagerProxy {
     DidGetHostnamesWithCookies(Vector<String> hostnames, uint64_t callbackID);
     DidGetHTTPCookieAcceptPolicy(uint32_t policy, uint64_t callbackID);
     
-    CookiesDidChange()
+    CookiesDidChange(WebCore::SessionID sessionID)
 }
index e1148a1..a57f937 100644 (file)
@@ -42,8 +42,6 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static WebCookieManager* sharedCookieManager;
-
 const char* WebCookieManager::supplementName()
 {
     return "WebCookieManager";
@@ -53,15 +51,13 @@ WebCookieManager::WebCookieManager(ChildProcess* process)
     : m_process(process)
 {
     m_process->addMessageReceiver(Messages::WebCookieManager::messageReceiverName(), *this);
-
-    ASSERT(!sharedCookieManager);
-    sharedCookieManager = this;
 }
 
-void WebCookieManager::getHostnamesWithCookies(uint64_t callbackID)
+void WebCookieManager::getHostnamesWithCookies(SessionID sessionID, uint64_t callbackID)
 {
     HashSet<String> hostnames;
-    WebCore::getHostnamesWithCookies(NetworkStorageSession::defaultStorageSession(), hostnames);
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        WebCore::getHostnamesWithCookies(*storageSession, hostnames);
 
     Vector<String> hostnameList;
     copyToVector(hostnames, hostnameList);
@@ -69,45 +65,44 @@ void WebCookieManager::getHostnamesWithCookies(uint64_t callbackID)
     m_process->send(Messages::WebCookieManagerProxy::DidGetHostnamesWithCookies(hostnameList, callbackID), 0);
 }
 
-void WebCookieManager::deleteCookiesForHostname(const String& hostname)
-{
-    WebCore::deleteCookiesForHostnames(NetworkStorageSession::defaultStorageSession(), { hostname });
-}
-
-void WebCookieManager::deleteAllCookies()
-{
-    WebCore::deleteAllCookies(NetworkStorageSession::defaultStorageSession());
-}
-
-void WebCookieManager::deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point time)
+void WebCookieManager::deleteCookiesForHostname(SessionID sessionID, const String& hostname)
 {
-    WebCore::deleteAllCookiesModifiedSince(NetworkStorageSession::defaultStorageSession(), time);
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        WebCore::deleteCookiesForHostnames(*storageSession, { hostname });
 }
 
-void WebCookieManager::addCookie(const Cookie& cookie, const String& hostname)
+void WebCookieManager::deleteAllCookies(SessionID sessionID)
 {
-    WebCore::addCookie(NetworkStorageSession::defaultStorageSession(), URL(URL(), hostname), cookie);
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        WebCore::deleteAllCookies(*storageSession);
 }
 
-void WebCookieManager::startObservingCookieChanges()
+void WebCookieManager::deleteAllCookiesModifiedSince(SessionID sessionID, std::chrono::system_clock::time_point time)
 {
-    WebCore::startObservingCookieChanges(cookiesDidChange);
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        WebCore::deleteAllCookiesModifiedSince(*storageSession, time);
 }
 
-void WebCookieManager::stopObservingCookieChanges()
+void WebCookieManager::addCookie(SessionID sessionID, const Cookie& cookie, const String& hostname)
 {
-    WebCore::stopObservingCookieChanges();
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        WebCore::addCookie(*storageSession, URL(URL(), hostname), cookie);
 }
 
-void WebCookieManager::cookiesDidChange()
+void WebCookieManager::startObservingCookieChanges(SessionID sessionID)
 {
-    sharedCookieManager->dispatchCookiesDidChange();
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID)) {
+        WebCore::startObservingCookieChanges(*storageSession, [this, sessionID] {
+            ASSERT(RunLoop::isMain());
+            m_process->send(Messages::WebCookieManagerProxy::CookiesDidChange(sessionID), 0);
+        });
+    }
 }
 
-void WebCookieManager::dispatchCookiesDidChange()
+void WebCookieManager::stopObservingCookieChanges(SessionID sessionID)
 {
-    ASSERT(RunLoop::isMain());
-    m_process->send(Messages::WebCookieManagerProxy::CookiesDidChange(), 0);
+    if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
+        WebCore::stopObservingCookieChanges(*storageSession);
 }
 
 void WebCookieManager::setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy)
index a995866..fc3b2d9 100644 (file)
@@ -30,6 +30,7 @@
 #include "MessageReceiver.h"
 #include "NetworkProcessSupplement.h"
 #include "WebProcessSupplement.h"
+#include <WebCore/SessionID.h>
 #include <stdint.h>
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
@@ -62,22 +63,18 @@ private:
     // IPC::MessageReceiver
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
-    void getHostnamesWithCookies(uint64_t callbackID);
-    void deleteCookiesForHostname(const String&);
-    void deleteAllCookies();
-    void deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point);
-    void addCookie(const WebCore::Cookie&, const String& hostname);
+    void getHostnamesWithCookies(WebCore::SessionID, uint64_t callbackID);
+    void deleteCookiesForHostname(WebCore::SessionID, const String&);
+    void deleteAllCookies(WebCore::SessionID);
+    void deleteAllCookiesModifiedSince(WebCore::SessionID, std::chrono::system_clock::time_point);
+    void addCookie(WebCore::SessionID, const WebCore::Cookie&, const String& hostname);
 
     void platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy);
     void getHTTPCookieAcceptPolicy(uint64_t callbackID);
     HTTPCookieAcceptPolicy platformGetHTTPCookieAcceptPolicy();
 
-    void startObservingCookieChanges();
-    void stopObservingCookieChanges();
-
-    static void cookiesDidChange();
-    void dispatchCookiesDidChange();
-
+    void startObservingCookieChanges(WebCore::SessionID);
+    void stopObservingCookieChanges(WebCore::SessionID);
 
     ChildProcess* m_process;
 };
index c2d16af..5d51536 100644 (file)
  */
  
  messages -> WebCookieManager {
-    void GetHostnamesWithCookies(uint64_t callbackID)
-    void DeleteCookiesForHostname(String hostname)
-    void DeleteAllCookies()
-    void DeleteAllCookiesModifiedSince(std::chrono::system_clock::time_point time)
-    void AddCookie(struct WebCore::Cookie cookie, String hostname)
+    void GetHostnamesWithCookies(WebCore::SessionID sessionID, uint64_t callbackID)
+    void DeleteCookiesForHostname(WebCore::SessionID sessionID, String hostname)
+    void DeleteAllCookies(WebCore::SessionID sessionID)
+    void DeleteAllCookiesModifiedSince(WebCore::SessionID sessionID, std::chrono::system_clock::time_point time)
+    void AddCookie(WebCore::SessionID sessionID, struct WebCore::Cookie cookie, String hostname)
 
     void SetHTTPCookieAcceptPolicy(uint32_t policy)
     void GetHTTPCookieAcceptPolicy(uint64_t callbackID)
     
-    void StartObservingCookieChanges()
-    void StopObservingCookieChanges()
+    void StartObservingCookieChanges(WebCore::SessionID sessionID)
+    void StopObservingCookieChanges(WebCore::SessionID sessionID)
 
 #if USE(SOUP)
     SetCookiePersistentStorage(String storagePath, uint32_t storageType)