Title: [214078] trunk
Revision
214078
Author
beid...@apple.com
Date
2017-03-16 16:30:09 -0700 (Thu, 16 Mar 2017)

Log Message

Update the WKHTTPCookieStore API to be simpler and add observers.
<rdar://problem/31096000> and https://bugs.webkit.org/show_bug.cgi?id=169776

Reviewed by Alex Christensen.
Source/WebKit2:

When reviewing the API internally we realized the NSHTTPCookieStorage model doesn't
necessarily fit perfectly, and that to handle partitioned cookies going forward we
need to be much simpler right now.

We also realized that we should implement the "cookie store changed" observer for
any clients that might be providing a cookie viewing API.

* UIProcess/API/APIHTTPCookieStore.cpp:
(API::HTTPCookieStore::~HTTPCookieStore):
(API::HTTPCookieStore::deleteCookie):
(API::APIWebCookieManagerProxyObserver::APIWebCookieManagerProxyObserver):
(API::HTTPCookieStore::registerObserver):
(API::HTTPCookieStore::unregisterObserver):
(API::HTTPCookieStore::cookiesDidChange):
(API::HTTPCookieStore::cookieManagerDestroyed):
(API::HTTPCookieStore::registerForNewProcessPoolNotifications):
(API::HTTPCookieStore::unregisterForNewProcessPoolNotifications):
(API::HTTPCookieStore::setCookies): Deleted.
(API::HTTPCookieStore::removeCookiesSinceDate): Deleted.
(API::HTTPCookieStore::setHTTPCookieAcceptPolicy): Deleted.
(API::HTTPCookieStore::getHTTPCookieAcceptPolicy): Deleted.
* UIProcess/API/APIHTTPCookieStore.h:

* UIProcess/API/Cocoa/WKHTTPCookieStore.h:
* UIProcess/API/Cocoa/WKHTTPCookieStore.mm:
(WKHTTPCookieStoreObserver::WKHTTPCookieStoreObserver):
(-[WKHTTPCookieStore dealloc]):
(-[WKHTTPCookieStore allCookies:]):
(-[WKHTTPCookieStore addObserver:]):
(-[WKHTTPCookieStore removeObserver:]):
(-[WKHTTPCookieStore fetchCookies:]): Deleted.
(-[WKHTTPCookieStore fetchCookiesForURL:completionHandler:]): Deleted.
(-[WKHTTPCookieStore setCookies:forURL:mainDocumentURL:completionHandler:]): Deleted.
(-[WKHTTPCookieStore removeCookiesSinceDate:completionHandler:]): Deleted.
(-[WKHTTPCookieStore setCookieAcceptPolicy:completionHandler:]): Deleted.
(kitCookiePolicyToNSCookiePolicy): Deleted.
(-[WKHTTPCookieStore fetchCookieAcceptPolicy:]): Deleted.

* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeNetworkProcess):

* UIProcess/WebCookieManagerProxy.cpp:
(WebKit::WebCookieManagerProxy::~WebCookieManagerProxy):
(WebKit::WebCookieManagerProxy::processPoolDestroyed):
(WebKit::WebCookieManagerProxy::registerObserver):
(WebKit::WebCookieManagerProxy::unregisterObserver):
(WebKit::WebCookieManagerProxy::cookiesDidChange):
(WebKit::WebCookieManagerProxy::setCookieObserverCallback): Deleted.
* UIProcess/WebCookieManagerProxy.h:
(WebKit::WebCookieManagerProxy::Observer::~Observer):

Add the ability for interested clients to listen for the creation of new WebProcessPools,
which is needed by APIHTTPCookieStore:
* UIProcess/WebProcessPool.cpp:
(WebKit::generateListenerIdentifier):
(WebKit::processPoolCreationListenerFunctionMap):
(WebKit::WebProcessPool::registerProcessPoolCreationListener):
(WebKit::WebProcessPool::unregisterProcessPoolCreationListener):
(WebKit::WebProcessPool::create):
* UIProcess/WebProcessPool.h:

* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::processPoolForCookieStorageNotifications):
(WebKit::WebsiteDataStore::isAssociatedProcessPool):
(WebKit::WebsiteDataStore::processPools):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm: Renamed from Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStorage.mm.
(-[CookieObserver cookiesDidChangeInCookieStore:]):
(TEST): Also test delete and observers.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (214077 => 214078)


--- trunk/Source/WebKit2/ChangeLog	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-16 23:30:09 UTC (rev 214078)
@@ -1,3 +1,77 @@
+2017-03-16  Brady Eidson  <beid...@apple.com>
+
+        Update the WKHTTPCookieStore API to be simpler and add observers.
+        <rdar://problem/31096000> and https://bugs.webkit.org/show_bug.cgi?id=169776
+
+        Reviewed by Alex Christensen.
+        
+        When reviewing the API internally we realized the NSHTTPCookieStorage model doesn't
+        necessarily fit perfectly, and that to handle partitioned cookies going forward we
+        need to be much simpler right now.
+        
+        We also realized that we should implement the "cookie store changed" observer for
+        any clients that might be providing a cookie viewing API.
+        
+        * UIProcess/API/APIHTTPCookieStore.cpp:
+        (API::HTTPCookieStore::~HTTPCookieStore):
+        (API::HTTPCookieStore::deleteCookie):
+        (API::APIWebCookieManagerProxyObserver::APIWebCookieManagerProxyObserver):
+        (API::HTTPCookieStore::registerObserver):
+        (API::HTTPCookieStore::unregisterObserver):
+        (API::HTTPCookieStore::cookiesDidChange):
+        (API::HTTPCookieStore::cookieManagerDestroyed):
+        (API::HTTPCookieStore::registerForNewProcessPoolNotifications):
+        (API::HTTPCookieStore::unregisterForNewProcessPoolNotifications):
+        (API::HTTPCookieStore::setCookies): Deleted.
+        (API::HTTPCookieStore::removeCookiesSinceDate): Deleted.
+        (API::HTTPCookieStore::setHTTPCookieAcceptPolicy): Deleted.
+        (API::HTTPCookieStore::getHTTPCookieAcceptPolicy): Deleted.
+        * UIProcess/API/APIHTTPCookieStore.h:
+        
+        * UIProcess/API/Cocoa/WKHTTPCookieStore.h:
+        * UIProcess/API/Cocoa/WKHTTPCookieStore.mm:
+        (WKHTTPCookieStoreObserver::WKHTTPCookieStoreObserver):
+        (-[WKHTTPCookieStore dealloc]):
+        (-[WKHTTPCookieStore allCookies:]):
+        (-[WKHTTPCookieStore addObserver:]):
+        (-[WKHTTPCookieStore removeObserver:]):
+        (-[WKHTTPCookieStore fetchCookies:]): Deleted.
+        (-[WKHTTPCookieStore fetchCookiesForURL:completionHandler:]): Deleted.
+        (-[WKHTTPCookieStore setCookies:forURL:mainDocumentURL:completionHandler:]): Deleted.
+        (-[WKHTTPCookieStore removeCookiesSinceDate:completionHandler:]): Deleted.
+        (-[WKHTTPCookieStore setCookieAcceptPolicy:completionHandler:]): Deleted.
+        (kitCookiePolicyToNSCookiePolicy): Deleted.
+        (-[WKHTTPCookieStore fetchCookieAcceptPolicy:]): Deleted.
+
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeNetworkProcess):
+
+        * UIProcess/WebCookieManagerProxy.cpp:
+        (WebKit::WebCookieManagerProxy::~WebCookieManagerProxy):
+        (WebKit::WebCookieManagerProxy::processPoolDestroyed):
+        (WebKit::WebCookieManagerProxy::registerObserver):
+        (WebKit::WebCookieManagerProxy::unregisterObserver):
+        (WebKit::WebCookieManagerProxy::cookiesDidChange):
+        (WebKit::WebCookieManagerProxy::setCookieObserverCallback): Deleted.
+        * UIProcess/WebCookieManagerProxy.h:
+        (WebKit::WebCookieManagerProxy::Observer::~Observer):
+
+        Add the ability for interested clients to listen for the creation of new WebProcessPools,
+        which is needed by APIHTTPCookieStore:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::generateListenerIdentifier):
+        (WebKit::processPoolCreationListenerFunctionMap):
+        (WebKit::WebProcessPool::registerProcessPoolCreationListener):
+        (WebKit::WebProcessPool::unregisterProcessPoolCreationListener):
+        (WebKit::WebProcessPool::create):
+        * UIProcess/WebProcessPool.h:
+
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::processPoolForCookieStorageNotifications):
+        (WebKit::WebsiteDataStore::isAssociatedProcessPool):
+        (WebKit::WebsiteDataStore::processPools):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2017-03-16  Brian Burg  <bb...@apple.com>
 
         [iOS WK2] Web Automation: implement platform methods for simulating keyboard events

Modified: trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.cpp (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.cpp	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.cpp	2017-03-16 23:30:09 UTC (rev 214078)
@@ -42,6 +42,11 @@
 
 HTTPCookieStore::~HTTPCookieStore()
 {
+    ASSERT(m_observers.isEmpty());
+    ASSERT(!m_observedCookieManagerProxy);
+    ASSERT(!m_cookieManagerProxyObserver);
+
+    unregisterForNewProcessPoolNotifications();
 }
 
 void HTTPCookieStore::cookies(Function<void (const Vector<WebCore::Cookie>&)>&& completionHandler)
@@ -55,17 +60,6 @@
     });
 }
 
-void HTTPCookieStore::cookies(const WebCore::URL& url, Function<void (const Vector<WebCore::Cookie>&)>&& completionHandler)
-{
-    auto& dataStore = m_owningDataStore.websiteDataStore();
-    auto pool = dataStore.processPoolForCookieStorageOperations();
-    auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
-
-    cookieManager->getCookies(dataStore.sessionID(), url, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](const Vector<WebCore::Cookie>& cookies, CallbackBase::Error error) {
-        completionHandler(cookies);
-    });
-}
-
 void HTTPCookieStore::setCookie(const WebCore::Cookie& cookie, Function<void ()>&& completionHandler)
 {
     auto& dataStore = m_owningDataStore.websiteDataStore();
@@ -77,62 +71,125 @@
     });
 }
 
-void HTTPCookieStore::setCookies(const Vector<WebCore::Cookie>& cookies, const WebCore::URL& url, const WebCore::URL& mainDocumentURL, Function<void ()>&& completionHandler)
+void HTTPCookieStore::deleteCookie(const WebCore::Cookie& cookie, Function<void ()>&& completionHandler)
 {
     auto& dataStore = m_owningDataStore.websiteDataStore();
     auto pool = dataStore.processPoolForCookieStorageOperations();
     auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
 
-    cookieManager->setCookies(dataStore.sessionID(), cookies, url, mainDocumentURL, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
+    cookieManager->deleteCookie(dataStore.sessionID(), cookie, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
         completionHandler();
     });
 }
 
-void HTTPCookieStore::deleteCookie(const WebCore::Cookie& cookie, Function<void ()>&& completionHandler)
+class APIWebCookieManagerProxyObserver : public WebCookieManagerProxy::Observer {
+public:
+    explicit APIWebCookieManagerProxyObserver(API::HTTPCookieStore& cookieStore)
+        : m_cookieStore(cookieStore)
+    {
+    }
+
+private:
+    void cookiesDidChange() final
+    {
+        m_cookieStore.cookiesDidChange();
+    }
+
+    void managerDestroyed() final
+    {
+        m_cookieStore.cookieManagerDestroyed();
+    }
+
+    API::HTTPCookieStore& m_cookieStore;
+};
+
+void HTTPCookieStore::registerObserver(Observer& observer)
 {
+    m_observers.add(&observer);
+
+    if (m_cookieManagerProxyObserver)
+        return;
+
+    ASSERT(!m_observedCookieManagerProxy);
+
+    m_cookieManagerProxyObserver = std::make_unique<APIWebCookieManagerProxyObserver>(*this);
+
     auto& dataStore = m_owningDataStore.websiteDataStore();
-    auto pool = dataStore.processPoolForCookieStorageOperations();
-    auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
+    auto* pool = dataStore.processPoolForCookieStorageNotifications();
 
-    cookieManager->deleteCookie(dataStore.sessionID(), cookie, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
-        completionHandler();
-    });
+    if (!pool) {
+        registerForNewProcessPoolNotifications();
+        return;
+    }
+
+    m_observedCookieManagerProxy = pool->supplement<WebKit::WebCookieManagerProxy>();
+    m_observedCookieManagerProxy->registerObserver(dataStore.sessionID(), *m_cookieManagerProxyObserver);
 }
 
-void HTTPCookieStore::removeCookiesSinceDate(std::chrono::system_clock::time_point date, Function<void ()>&& completionHandler)
+void HTTPCookieStore::unregisterObserver(Observer& observer)
 {
-    auto& dataStore = m_owningDataStore.websiteDataStore();
-    auto pool = dataStore.processPoolForCookieStorageOperations();
-    auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
+    m_observers.remove(&observer);
 
-    cookieManager->deleteAllCookiesModifiedSince(dataStore.sessionID(), date, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
-        completionHandler();
-    });
+    if (!m_observers.isEmpty())
+        return;
+
+    if (m_observedCookieManagerProxy)
+        m_observedCookieManagerProxy->unregisterObserver(m_owningDataStore.websiteDataStore().sessionID(), *m_cookieManagerProxyObserver);
+
+    if (m_processPoolCreationListenerIdentifier)
+        WebProcessPool::unregisterProcessPoolCreationListener(m_processPoolCreationListenerIdentifier);
+
+    m_processPoolCreationListenerIdentifier = 0;
+    m_observedCookieManagerProxy = nullptr;
+    m_cookieManagerProxyObserver = nullptr;
 }
 
-void HTTPCookieStore::setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy, Function<void ()>&& completionHandler)
+void HTTPCookieStore::cookiesDidChange()
 {
+    for (auto* observer : m_observers)
+        observer->cookiesDidChange(*this);
+}
+
+void HTTPCookieStore::cookieManagerDestroyed()
+{
     auto& dataStore = m_owningDataStore.websiteDataStore();
-    auto pool = dataStore.processPoolForCookieStorageOperations();
-    auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
 
-    cookieManager->setHTTPCookieAcceptPolicy(dataStore.sessionID(), policy, [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](CallbackBase::Error error) {
-        completionHandler();
-    });
+    m_observedCookieManagerProxy->unregisterObserver(dataStore.sessionID(), *m_cookieManagerProxyObserver);
+    m_observedCookieManagerProxy = nullptr;
+
+    auto* pool = dataStore.processPoolForCookieStorageNotifications();
+
+    if (!pool) {
+        registerForNewProcessPoolNotifications();
+        return;
+    }
+
+    m_observedCookieManagerProxy = pool->supplement<WebKit::WebCookieManagerProxy>();
+    m_observedCookieManagerProxy->registerObserver(dataStore.sessionID(), *m_cookieManagerProxyObserver);
 }
 
-void HTTPCookieStore::getHTTPCookieAcceptPolicy(Function<void (HTTPCookieAcceptPolicy)>&& completionHandler)
+void HTTPCookieStore::registerForNewProcessPoolNotifications()
 {
-    auto& dataStore = m_owningDataStore.websiteDataStore();
-    auto pool = dataStore.processPoolForCookieStorageOperations();
-    auto* cookieManager = pool->supplement<WebKit::WebCookieManagerProxy>();
+    ASSERT(!m_processPoolCreationListenerIdentifier);
 
-    cookieManager->getHTTPCookieAcceptPolicy(dataStore.sessionID(), [pool = WTFMove(pool), completionHandler = WTFMove(completionHandler)](HTTPCookieAcceptPolicy policy, CallbackBase::Error error) {
-        if (error != CallbackBase::Error::None)
-            policy = HTTPCookieAcceptPolicyNever;
+    m_processPoolCreationListenerIdentifier = WebProcessPool::registerProcessPoolCreationListener([this](WebProcessPool& newProcessPool) {
+        ASSERT(m_cookieManagerProxyObserver);
 
-        completionHandler(policy);
+        if (!m_owningDataStore.websiteDataStore().isAssociatedProcessPool(newProcessPool))
+            return;
+
+        m_observedCookieManagerProxy = newProcessPool.supplement<WebKit::WebCookieManagerProxy>();
+        m_observedCookieManagerProxy->registerObserver(m_owningDataStore.websiteDataStore().sessionID(), *m_cookieManagerProxyObserver);
+        unregisterForNewProcessPoolNotifications();
     });
 }
 
+void HTTPCookieStore::unregisterForNewProcessPoolNotifications()
+{
+    if (m_processPoolCreationListenerIdentifier)
+        WebProcessPool::unregisterProcessPoolCreationListener(m_processPoolCreationListenerIdentifier);
+
+    m_processPoolCreationListenerIdentifier = 0;
+}
+
 } // namespace API

Modified: trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.h (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.h	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.h	2017-03-16 23:30:09 UTC (rev 214078)
@@ -28,6 +28,7 @@
 #include "APIObject.h"
 #include "HTTPCookieAcceptPolicy.h"
 #include <wtf/Function.h>
+#include <wtf/HashSet.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -35,8 +36,13 @@
 struct Cookie;
 }
 
+namespace WebKit {
+class WebCookieManagerProxy;
+}
+
 namespace API {
 
+class APIWebCookieManagerProxyObserver;
 class WebsiteDataStore;
 
 class HTTPCookieStore final : public ObjectImpl<Object::Type::HTTPCookieStore> {
@@ -49,21 +55,34 @@
     virtual ~HTTPCookieStore();
 
     void cookies(Function<void (const Vector<WebCore::Cookie>&)>&& completionHandler);
-    void cookies(const WebCore::URL&, Function<void (const Vector<WebCore::Cookie>&)>&& completionHandler);
-
     void setCookie(const WebCore::Cookie&, Function<void ()>&& completionHandler);
-    void setCookies(const Vector<WebCore::Cookie>&, const WebCore::URL&, const WebCore::URL& mainDocumentURL, Function<void ()>&& completionHandler);
     void deleteCookie(const WebCore::Cookie&, Function<void ()>&& completionHandler);
 
-    void removeCookiesSinceDate(std::chrono::system_clock::time_point, Function<void ()>&& completionHandler);
+    class Observer {
+    public:
+        virtual ~Observer() { }
+        virtual void cookiesDidChange(HTTPCookieStore&) = 0;
+    };
 
-    void setHTTPCookieAcceptPolicy(WebKit::HTTPCookieAcceptPolicy, Function<void ()>&& completionHandler);
-    void getHTTPCookieAcceptPolicy(Function<void (WebKit::HTTPCookieAcceptPolicy)>&& completionHandler);
-    
+    void registerObserver(Observer&);
+    void unregisterObserver(Observer&);
+
+    void cookiesDidChange();
+    void cookieManagerDestroyed();
+
 private:
     HTTPCookieStore(WebsiteDataStore&);
 
+    void registerForNewProcessPoolNotifications();
+    void unregisterForNewProcessPoolNotifications();
+
     WebsiteDataStore& m_owningDataStore;
+    HashSet<Observer*> m_observers;
+
+    WebKit::WebCookieManagerProxy* m_observedCookieManagerProxy { nullptr };
+    std::unique_ptr<APIWebCookieManagerProxyObserver> m_cookieManagerProxyObserver;
+
+    uint64_t m_processPoolCreationListenerIdentifier { 0 };
 };
 
 }

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHTTPCookieStore.h (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHTTPCookieStore.h	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHTTPCookieStore.h	2017-03-16 23:30:09 UTC (rev 214078)
@@ -31,6 +31,13 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+@class WKHTTPCookieStore;
+
+@protocol WKHTTPCookieStoreObserver <NSObject>
+@optional
+- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore;
+@end
+
 /*!
  A WKHTTPCookieStore object allows managing the HTTP cookies associated with a particular WKWebsiteDataStore.
  */
@@ -42,13 +49,8 @@
 /*! @abstract Fetches all stored cookies.
  @param completionHandler A block to invoke with the fetched cookies.
  */
-- (void)fetchCookies:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler;
+- (void)allCookies:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler;
 
-/*! @abstract Fetches all of the stored cookies for the given URL.
- @param completionHandler A block to invoke with the fetched cookies.
- */
-- (void)fetchCookiesForURL:(NSURL *)url completionHandler:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler;
-
 /*! @abstract Set a cookie.
  @param cookie The cookie to set.
  @param completionHandler A block to invoke once the cookie has been stored.
@@ -55,36 +57,23 @@
  */
 - (void)setCookie:(NSHTTPCookie *)cookie completionHandler:(nullable void (^)())completionHandler;
 
-/*! @abstract Adds an array cookies to the cookie store, following the cookie accept policy.
- @param cookies The cookies to set.
- @param URL The URL from which the cookies were sent.
- @param mainDocumentURL The main document URL to be used as a base for the "same domain as main document" policy.
- @param completionHandler A block to invoke once the cookies have been stored.
- */
-- (void)setCookies:(NSArray<NSHTTPCookie *> *)cookies forURL:(NSURL *)url mainDocumentURL:(nullable NSURL *)mainDocumentURL completionHandler:(nullable void (^)())completionHandler;
-
 /*! @abstract Delete the specified cookie.
  @param completionHandler A block to invoke once the cookie has been deleted.
  */
 - (void)deleteCookie:(NSHTTPCookie *)cookie completionHandler:(nullable void (^)())completionHandler;
 
-/*! @abstract Delete all cookies from the cookie storage since the provided date.
- @param date The date after which set cookies should be removed.
- @param completionHandler A block to invoke once the cookies have been deleted.
+/*! @abstract Adds a WKHTTPCookieStoreObserver object with the cookie store.
+ @param observer The observer object to add.
+ @discussion The observer is not retained by the receiver. It is your responsibility
+ to unregister the observer before it becomes invalid.
  */
-- (void)removeCookiesSinceDate:(NSDate *)date completionHandler:(nullable void (^)())completionHandler;
+- (void)addObserver:(id<WKHTTPCookieStoreObserver>)observer;
 
-/*! @abstract Sets the cookie accept policy preference of the receiver.
- @param policy The cookie accept policy to set.
- @param completionHandler A block to invoke once the policy has been set.
+/*! @abstract Removes a WKHTTPCookieStoreObserver object from the cookie store.
+ @param observer The observer to remove.
  */
-- (void)setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy completionHandler:(nullable void (^)())completionHandler;
+- (void)removeObserver:(id<WKHTTPCookieStoreObserver>)observer;
 
-/*! @abstract Fetches the cookie accept policy preference of the receiver.
- @param completionHandler A block to invoke with the fetched policy.
- */
-- (void)fetchCookieAcceptPolicy:(void (^)(NSHTTPCookieAcceptPolicy))completionHandler;
-
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHTTPCookieStore.mm (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHTTPCookieStore.mm	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHTTPCookieStore.mm	2017-03-16 23:30:09 UTC (rev 214078)
@@ -28,11 +28,13 @@
 
 #if WK_API_ENABLED
 
-#include "HTTPCookieAcceptPolicy.h"
-#include <WebCore/CFNetworkSPI.h>
-#include <WebCore/Cookie.h>
-#include <WebCore/URL.h>
-#include <wtf/RetainPtr.h>
+#import "HTTPCookieAcceptPolicy.h"
+#import "WeakObjCPtr.h"
+#import <WebCore/CFNetworkSPI.h>
+#import <WebCore/Cookie.h>
+#import <WebCore/URL.h>
+#import <wtf/HashMap.h>
+#import <wtf/RetainPtr.h>
 
 static NSArray<NSHTTPCookie *> *coreCookiesToNSCookies(const Vector<WebCore::Cookie>& coreCookies)
 {
@@ -44,16 +46,37 @@
     return nsCookies;
 }
 
-@implementation WKHTTPCookieStore
+class WKHTTPCookieStoreObserver : public API::HTTPCookieStore::Observer {
+public:
+    explicit WKHTTPCookieStoreObserver(id<WKHTTPCookieStoreObserver> observer)
+        : m_observer(observer)
+    {
+    }
 
+private:
+    void cookiesDidChange(API::HTTPCookieStore& cookieStore) final
+    {
+        [m_observer.get() cookiesDidChangeInCookieStore:WebKit::wrapper(cookieStore)];
+    }
+
+    WebKit::WeakObjCPtr<id<WKHTTPCookieStoreObserver>> m_observer;
+};
+
+@implementation WKHTTPCookieStore {
+    HashMap<id<WKHTTPCookieStoreObserver>, std::unique_ptr<WKHTTPCookieStoreObserver>> _observers;
+}
+
 - (void)dealloc
 {
+    for (auto& observer : _observers.values())
+        _cookieStore->unregisterObserver(*observer);
+
     _cookieStore->API::HTTPCookieStore::~HTTPCookieStore();
 
     [super dealloc];
 }
 
-- (void)fetchCookies:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler
+- (void)allCookies:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler
 {
     _cookieStore->cookies([handler = adoptNS([completionHandler copy])](const Vector<WebCore::Cookie>& cookies) {
         auto rawHandler = (void (^)(NSArray<NSHTTPCookie *> *))handler.get();
@@ -61,14 +84,6 @@
     });
 }
 
-- (void)fetchCookiesForURL:(NSURL *)url completionHandler:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler
-{
-    _cookieStore->cookies(url, [handler = adoptNS([completionHandler copy])](const Vector<WebCore::Cookie>& cookies) {
-        auto rawHandler = (void (^)(NSArray<NSHTTPCookie *> *))handler.get();
-        rawHandler(coreCookiesToNSCookies(cookies));
-    });
-}
-
 - (void)setCookie:(NSHTTPCookie *)cookie completionHandler:(void (^)())completionHandler
 {
     _cookieStore->setCookie(cookie, [handler = adoptNS([completionHandler copy])]() {
@@ -88,67 +103,25 @@
     });
 }
 
-- (void)setCookies:(NSArray<NSHTTPCookie *> *)cookies forURL:(NSURL *)URL mainDocumentURL:(NSURL *)mainDocumentURL completionHandler:(void (^)())completionHandler
+- (void)addObserver:(id<WKHTTPCookieStoreObserver>)observer
 {
-    Vector<WebCore::Cookie> coreCookies;
-    coreCookies.reserveInitialCapacity(cookies.count);
-    for (NSHTTPCookie *cookie : cookies)
-        coreCookies.uncheckedAppend(cookie);
+    auto result = _observers.add(observer, nullptr);
+    if (!result.isNewEntry)
+        return;
 
-    _cookieStore->setCookies(coreCookies, URL, mainDocumentURL, [handler = adoptNS([completionHandler copy])]() {
-        auto rawHandler = (void (^)())handler.get();
-        if (rawHandler)
-            rawHandler();
-    });
+    result.iterator->value = std::make_unique<WKHTTPCookieStoreObserver>(observer);
+    _cookieStore->registerObserver(*result.iterator->value);
 }
 
-- (void)removeCookiesSinceDate:(NSDate *)date completionHandler:(void (^)())completionHandler
+- (void)removeObserver:(id<WKHTTPCookieStoreObserver>)observer
 {
-    auto systemClockTime = std::chrono::system_clock::time_point(std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::duration<double>(date.timeIntervalSince1970)));
+    auto result = _observers.take(observer);
+    if (!result)
+        return;
 
-    _cookieStore->removeCookiesSinceDate(systemClockTime, [handler = adoptNS([completionHandler copy])]() {
-        auto rawHandler = (void (^)())handler.get();
-        if (rawHandler)
-            rawHandler();
-    });
+    _cookieStore->unregisterObserver(*result);
 }
 
-- (void)setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy completionHandler:(void (^)())completionHandler
-{
-    _cookieStore->setHTTPCookieAcceptPolicy(policy, [handler = adoptNS([completionHandler copy])]() {
-        auto rawHandler = (void (^)())handler.get();
-        if (rawHandler)
-            rawHandler();
-    });
-}
-
-static NSHTTPCookieAcceptPolicy kitCookiePolicyToNSCookiePolicy(WebKit::HTTPCookieAcceptPolicy kitPolicy)
-{
-    switch (kitPolicy) {
-    case WebKit::HTTPCookieAcceptPolicyAlways:
-        return NSHTTPCookieAcceptPolicyAlways;
-    case WebKit::HTTPCookieAcceptPolicyNever:
-        return NSHTTPCookieAcceptPolicyNever;
-    case WebKit::HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain:
-        return NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
-    case WebKit::HTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain:
-        // Cast required because of CFNetworkSPI.
-        return static_cast<NSHTTPCookieAcceptPolicy>(NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain);
-    default:
-        ASSERT_NOT_REACHED();
-    }
-
-    return NSHTTPCookieAcceptPolicyNever;
-}
-
-- (void)fetchCookieAcceptPolicy:(void (^)(NSHTTPCookieAcceptPolicy))completionHandler
-{
-    _cookieStore->getHTTPCookieAcceptPolicy([handler = adoptNS([completionHandler copy])](WebKit::HTTPCookieAcceptPolicy policy) {
-        auto rawHandler = (void (^)(NSHTTPCookieAcceptPolicy))handler.get();
-        rawHandler(kitCookiePolicyToNSCookiePolicy(policy));
-    });
-}
-
 #pragma mark WKObject protocol implementation
 
 - (API::Object&)_apiObject

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2017-03-16 23:30:09 UTC (rev 214078)
@@ -296,6 +296,10 @@
 
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
     RetainPtr<CFDataRef> cookieStorageData = adoptCF(CFHTTPCookieStorageCreateIdentifyingData(kCFAllocatorDefault, [[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]));
+
+    static int i = 0;
+    [(NSData *)cookieStorageData.get() writeToFile:[NSString stringWithFormat:@"/Volumes/Data/FujiUser/dump%i.plist", i++] atomically:NO];
+
     ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
     parameters.uiProcessCookieStorageIdentifier.append(CFDataGetBytePtr(cookieStorageData.get()), CFDataGetLength(cookieStorageData.get()));
 #endif

Modified: trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp	2017-03-16 23:30:09 UTC (rev 214078)
@@ -60,6 +60,7 @@
 
 WebCookieManagerProxy::~WebCookieManagerProxy()
 {
+    ASSERT(m_cookieObservers.isEmpty());
 }
 
 void WebCookieManagerProxy::initializeClient(const WKCookieManagerClientBase* client)
@@ -75,6 +76,17 @@
     invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks, CallbackBase::Error::OwnerWasInvalidated);
     invalidateCallbackMap(m_voidCallbacks, CallbackBase::Error::OwnerWasInvalidated);
     invalidateCallbackMap(m_getCookiesCallbacks, CallbackBase::Error::OwnerWasInvalidated);
+
+    Vector<Observer*> observers;
+    for (auto& observerSet : m_cookieObservers.values()) {
+        for (auto* observer : observerSet)
+            observers.append(observer);
+    }
+
+    for (auto* observer : observers)
+        observer->managerDestroyed();
+
+    ASSERT(m_cookieObservers.isEmpty());
 }
 
 void WebCookieManagerProxy::processDidClose(WebProcessProxy*)
@@ -212,19 +224,50 @@
     processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StopObservingCookieChanges(sessionID));
 }
 
-void WebCookieManagerProxy::setCookieObserverCallback(SessionID sessionID, std::function<void ()>&& callback)
+
+void WebCookieManagerProxy::setCookieObserverCallback(WebCore::SessionID sessionID, std::function<void ()>&& callback)
 {
     if (callback)
-        m_cookieObservers.set(sessionID, WTFMove(callback));
+        m_legacyCookieObservers.set(sessionID, WTFMove(callback));
     else
-        m_cookieObservers.remove(sessionID);
+        m_legacyCookieObservers.remove(sessionID);
 }
 
+void WebCookieManagerProxy::registerObserver(WebCore::SessionID sessionID, Observer& observer)
+{
+    auto result = m_cookieObservers.set(sessionID, HashSet<Observer*>());
+    result.iterator->value.add(&observer);
+
+    if (result.isNewEntry)
+        startObservingCookieChanges(sessionID);
+}
+
+void WebCookieManagerProxy::unregisterObserver(WebCore::SessionID sessionID, Observer& observer)
+{
+    auto iterator = m_cookieObservers.find(sessionID);
+    if (iterator == m_cookieObservers.end())
+        return;
+
+    iterator->value.remove(&observer);
+    if (!iterator->value.isEmpty())
+        return;
+
+    m_cookieObservers.remove(iterator);
+    stopObservingCookieChanges(sessionID);
+}
+
 void WebCookieManagerProxy::cookiesDidChange(SessionID sessionID)
 {
     m_client.cookiesDidChange(this);
-    if (auto callback = m_cookieObservers.get(sessionID))
+    if (auto callback = m_legacyCookieObservers.get(sessionID))
         callback();
+
+    auto iterator = m_cookieObservers.find(sessionID);
+    if (iterator == m_cookieObservers.end())
+        return;
+
+    for (auto* observer : iterator->value)
+        observer->cookiesDidChange();
 }
 
 void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(SessionID, HTTPCookieAcceptPolicy policy, Function<void (CallbackBase::Error)>&& callbackFunction)

Modified: trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.h (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.h	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.h	2017-03-16 23:30:09 UTC (rev 214078)
@@ -88,6 +88,16 @@
 
     void setCookieObserverCallback(WebCore::SessionID, std::function<void ()>&&);
 
+    class Observer {
+    public:
+        virtual ~Observer() { }
+        virtual void cookiesDidChange() = 0;
+        virtual void managerDestroyed() = 0;
+    };
+
+    void registerObserver(WebCore::SessionID, Observer&);
+    void unregisterObserver(WebCore::SessionID, Observer&);
+
 #if USE(SOUP)
     void setCookiePersistentStorage(const String& storagePath, uint32_t storageType);
     void getCookiePersistentStorage(String& storagePath, uint32_t& storageType) const;
@@ -128,7 +138,8 @@
     HashMap<uint64_t, RefPtr<VoidCallback>> m_voidCallbacks;
     HashMap<uint64_t, RefPtr<GetCookiesCallback>> m_getCookiesCallbacks;
 
-    HashMap<WebCore::SessionID, std::function<void ()>> m_cookieObservers;
+    HashMap<WebCore::SessionID, std::function<void ()>> m_legacyCookieObservers;
+    HashMap<WebCore::SessionID, HashSet<Observer*>> m_cookieObservers;
 
     WebCookieManagerProxyClient m_client;
 

Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp	2017-03-16 23:30:09 UTC (rev 214078)
@@ -115,10 +115,65 @@
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, processPoolCounter, ("WebProcessPool"));
 
+static uint64_t generateListenerIdentifier()
+{
+    static uint64_t nextIdentifier = 1;
+    return nextIdentifier++;
+}
+
+static HashMap<uint64_t, Function<void(WebProcessPool&)>>& processPoolCreationListenerFunctionMap()
+{
+    static NeverDestroyed<HashMap<uint64_t, Function<void(WebProcessPool&)>>> map;
+    return map;
+}
+
+uint64_t WebProcessPool::registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&& function)
+{
+    ASSERT(function);
+
+    auto identifier = generateListenerIdentifier();
+    processPoolCreationListenerFunctionMap().set(identifier, WTFMove(function));
+    return identifier;
+}
+
+void WebProcessPool::unregisterProcessPoolCreationListener(uint64_t identifier)
+{
+    processPoolCreationListenerFunctionMap().remove(identifier);
+}
+
 Ref<WebProcessPool> WebProcessPool::create(API::ProcessPoolConfiguration& configuration)
 {
     InitializeWebKit2();
-    return adoptRef(*new WebProcessPool(configuration));
+    auto newPool = adoptRef(*new WebProcessPool(configuration));
+
+    auto& listenerMap = processPoolCreationListenerFunctionMap();
+
+    Vector<uint64_t> identifiers;
+    identifiers.reserveInitialCapacity(listenerMap.size());
+    for (auto identifier : listenerMap.keys())
+        identifiers.uncheckedAppend(identifier);
+
+    for (auto identifier : identifiers) {
+        auto iterator = listenerMap.find(identifier);
+        if (iterator == listenerMap.end())
+            continue;
+
+        // To make sure the Function object stays alive until after the function call has been made,
+        // we temporarily move it out of the map.
+        // This protects it from the Function calling unregisterProcessPoolCreationListener thereby
+        // removing itself from the map of listeners.
+        // If the identifier still exists in the map later, we move it back in.
+        Function<void(WebProcessPool&)> function = WTFMove(iterator->value);
+        function(newPool.get());
+
+        iterator = listenerMap.find(identifier);
+        if (iterator != listenerMap.end()) {
+            ASSERT(!iterator->value);
+            iterator->value = WTFMove(function);
+        }
+    }
+
+    return newPool;
 }
 
 static Vector<WebProcessPool*>& processPools()

Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.h (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/WebProcessPool.h	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.h	2017-03-16 23:30:09 UTC (rev 214078)
@@ -399,6 +399,9 @@
     void setCookieStoragePartitioningEnabled(bool);
 #endif
 
+    static uint64_t registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&&);
+    static void unregisterProcessPoolCreationListener(uint64_t identifier);
+
 private:
     void platformInitialize();
 

Modified: trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp	2017-03-16 23:30:09 UTC (rev 214078)
@@ -127,6 +127,12 @@
     return **pools.begin();
 }
 
+WebProcessPool* WebsiteDataStore::processPoolForCookieStorageNotifications()
+{
+    auto pools = processPools(1, false);
+    return pools.isEmpty() ? nullptr : pools.begin()->get();
+}
+
 void WebsiteDataStore::resolveDirectoriesIfNecessary()
 {
     if (m_hasResolvedDirectories)
@@ -1130,8 +1136,24 @@
         m_storageManager->processDidCloseConnection(webProcessProxy, connection);
 }
 
-HashSet<RefPtr<WebProcessPool>> WebsiteDataStore::processPools(size_t count) const
+bool WebsiteDataStore::isAssociatedProcessPool(WebProcessPool& processPool) const
 {
+    if (auto dataStore = processPool.websiteDataStore()) {
+        if (&dataStore->websiteDataStore() == this)
+            return true;
+    } else if (&API::WebsiteDataStore::defaultDataStore()->websiteDataStore() == this) {
+        // If a process pool doesn't have an explicit data store and this is the default WebsiteDataStore,
+        // add that process pool to the set.
+        // FIXME: This behavior is weird and necessitated by the fact that process pools don't always
+        // have a data store; they should.
+        return true;
+    }
+
+    return false;
+}
+
+HashSet<RefPtr<WebProcessPool>> WebsiteDataStore::processPools(size_t count, bool ensureAPoolExists) const
+{
     HashSet<RefPtr<WebProcessPool>> processPools;
     for (auto& process : processes())
         processPools.add(&process->processPool());
@@ -1139,25 +1161,17 @@
     if (processPools.isEmpty()) {
         // Check if we're one of the legacy data stores.
         for (auto& processPool : WebProcessPool::allProcessPools()) {
-            if (auto dataStore = processPool->websiteDataStore()) {
-                if (&dataStore->websiteDataStore() == this) {
-                    processPools.add(processPool);
-                    break;
-                }
-            } else if (&API::WebsiteDataStore::defaultDataStore()->websiteDataStore() == this) {
-                // If a process pool doesn't have an explicit data store and this is the default WebsiteDataStore,
-                // add that process pool to the set.
-                // FIXME: This behavior is weird and necessitated by the fact that process pools don't always
-                // have a data store; they should.
-                processPools.add(processPool);
-            }
+            if (!isAssociatedProcessPool(*processPool))
+                continue;
 
+            processPools.add(processPool);
+
             if (processPools.size() == count)
                 break;
         }
     }
 
-    if (processPools.isEmpty() && count) {
+    if (processPools.isEmpty() && count && ensureAPoolExists) {
         auto processPool = WebProcessPool::create(API::ProcessPoolConfiguration::createWithWebsiteDataStoreConfiguration(m_configuration));
         processPools.add(processPool.ptr());
     }

Modified: trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h (214077 => 214078)


--- trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h	2017-03-16 23:30:09 UTC (rev 214078)
@@ -104,6 +104,8 @@
     StorageManager* storageManager() { return m_storageManager.get(); }
 
     Ref<WebProcessPool> processPoolForCookieStorageOperations();
+    WebProcessPool* processPoolForCookieStorageNotifications();
+    bool isAssociatedProcessPool(WebProcessPool&) const;
 
 private:
     explicit WebsiteDataStore(WebCore::SessionID);
@@ -121,7 +123,7 @@
     void platformDestroy();
     static void platformRemoveRecentSearches(std::chrono::system_clock::time_point);
 
-    HashSet<RefPtr<WebProcessPool>> processPools(size_t count = std::numeric_limits<size_t>::max()) const;
+    HashSet<RefPtr<WebProcessPool>> processPools(size_t count = std::numeric_limits<size_t>::max(), bool ensureAPoolExists = true) const;
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
     Vector<PluginModuleInfo> plugins() const;

Modified: trunk/Tools/ChangeLog (214077 => 214078)


--- trunk/Tools/ChangeLog	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Tools/ChangeLog	2017-03-16 23:30:09 UTC (rev 214078)
@@ -1,3 +1,15 @@
+2017-03-16  Brady Eidson  <beid...@apple.com>
+
+        Update the WKHTTPCookieStore API to be simpler and add observers.
+        <rdar://problem/31096000> and https://bugs.webkit.org/show_bug.cgi?id=169776
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm: Renamed from Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStorage.mm.
+        (-[CookieObserver cookiesDidChangeInCookieStore:]):
+        (TEST): Also test delete and observers.
+
 2017-03-16  Kocsen Chung  <kocsen_ch...@apple.com>
 
         Fix quotes around --pretty format git flag.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (214077 => 214078)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-03-16 23:30:09 UTC (rev 214078)
@@ -154,7 +154,7 @@
 		51BCEE4F1C84F53B0042C82E /* IndexedDBMultiProcess-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */; };
 		51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */; };
 		51CD1C721B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51CD1C711B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html */; };
-		51D124981E763B02002B2820 /* WKHTTPCookieStorage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51D124971E763AF8002B2820 /* WKHTTPCookieStorage.mm */; };
+		51D124981E763B02002B2820 /* WKHTTPCookieStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51D124971E763AF8002B2820 /* WKHTTPCookieStore.mm */; };
 		51D1249B1E785425002B2820 /* CookieManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6F3F29013342FEB00A6BF19 /* CookieManager.cpp */; };
 		51E5C7021919C3B200D8B3E1 /* simple2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51E780361919AFF8001829A2 /* simple2.html */; };
 		51E5C7031919C3B200D8B3E1 /* simple3.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51E780371919AFF8001829A2 /* simple3.html */; };
@@ -1056,7 +1056,7 @@
 		51CB4AD71B3A079C00C1B1C6 /* ModalAlertsSPI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModalAlertsSPI.cpp; sourceTree = "<group>"; };
 		51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ModalAlerts.mm; sourceTree = "<group>"; };
 		51CD1C711B38D48400142CA5 /* modal-alerts-in-new-about-blank-window.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "modal-alerts-in-new-about-blank-window.html"; sourceTree = "<group>"; };
-		51D124971E763AF8002B2820 /* WKHTTPCookieStorage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKHTTPCookieStorage.mm; sourceTree = "<group>"; };
+		51D124971E763AF8002B2820 /* WKHTTPCookieStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKHTTPCookieStore.mm; sourceTree = "<group>"; };
 		51E5C7041919EA5F00D8B3E1 /* ShouldKeepCurrentBackForwardListItemInList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldKeepCurrentBackForwardListItemInList.cpp; sourceTree = "<group>"; };
 		51E6A8921D2F1BEC00C004B6 /* LocalStorageClear.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageClear.mm; sourceTree = "<group>"; };
 		51E6A8951D2F1C7700C004B6 /* LocalStorageClear.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LocalStorageClear.html; sourceTree = "<group>"; };
@@ -1661,7 +1661,7 @@
 				5120C83C1E6750790025B250 /* WebsiteDataStoreCustomPaths.mm */,
 				5C9E56841DF9143D00C9EE33 /* WebsitePolicies.mm */,
 				1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */,
-				51D124971E763AF8002B2820 /* WKHTTPCookieStorage.mm */,
+				51D124971E763AF8002B2820 /* WKHTTPCookieStore.mm */,
 				375E0E151D66674400EFEC2C /* WKNSNumber.mm */,
 				37B47E2E1D64E7CA005F4EFF /* WKObject.mm */,
 				A14AAB611E78D7DE00C1ADC2 /* WKPDFView.mm */,
@@ -2746,7 +2746,7 @@
 				7CCE7EF41A411AE600447C4C /* FindMatches.mm in Sources */,
 				7C83E0401D0A63E300FEBCF3 /* FirstResponderScrollingPosition.mm in Sources */,
 				7C83E0BC1D0A650700FEBCF3 /* FixedLayoutSize.mm in Sources */,
-				51D124981E763B02002B2820 /* WKHTTPCookieStorage.mm in Sources */,
+				51D124981E763B02002B2820 /* WKHTTPCookieStore.mm in Sources */,
 				7CCE7EF51A411AE600447C4C /* ForceRepaint.cpp in Sources */,
 				37B47E301D64E7CA005F4EFF /* WKObject.mm in Sources */,
 				7CCE7EC01A411A7E00447C4C /* FragmentNavigation.mm in Sources */,

Deleted: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStorage.mm (214077 => 214078)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStorage.mm	2017-03-16 23:19:39 UTC (rev 214077)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStorage.mm	2017-03-16 23:30:09 UTC (rev 214078)
@@ -1,119 +0,0 @@
-/*
- * 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"
-
-#import "PlatformUtilities.h"
-#import <WebKit/WKFoundation.h>
-#import <WebKit/WKHTTPCookieStore.h>
-#import <WebKit/WKWebsiteDataStorePrivate.h>
-#import <wtf/RetainPtr.h>
-
-#if WK_API_ENABLED
-
-static bool gotFlag;
-
-TEST(WebKit2, WKHTTPCookieStorage)
-{
-    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
-    [webView loadHTMLString:@"Oh hello" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
-
-    RetainPtr<WKHTTPCookieStore> cookieStore = [WKWebsiteDataStore defaultDataStore]._httpCookieStore;
-
-    NSArray<NSHTTPCookie *> *cookies = nil;
-    [cookieStore fetchCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
-        *cookiesPtr = [nsCookies retain];
-        gotFlag = true;
-    }];
-
-    TestWebKitAPI::Util::run(&gotFlag);
-
-    ASSERT_EQ(cookies.count, 0u);
-    [cookies release];
-
-    gotFlag = false;
-
-    RetainPtr<NSHTTPCookie> cookie1 = [NSHTTPCookie cookieWithProperties:@{
-        NSHTTPCookiePath: @"/",
-        NSHTTPCookieName: @"CookieName",
-        NSHTTPCookieValue: @"CookieValue",
-        NSHTTPCookieDomain: @".www.webkit.org",
-        NSHTTPCookieSecure: @"TRUE",
-        NSHTTPCookieDiscard: @"TRUE",
-        NSHTTPCookieMaximumAge: @"10000",
-    }];
-
-    RetainPtr<NSHTTPCookie> cookie2 = [NSHTTPCookie cookieWithProperties:@{
-        NSHTTPCookiePath: @"/path",
-        NSHTTPCookieName: @"OtherCookieName",
-        NSHTTPCookieValue: @"OtherCookieValue",
-        NSHTTPCookieDomain: @".www.w3c.org",
-        NSHTTPCookieMaximumAge: @"10000",
-    }];
-
-    [cookieStore setCookie:cookie1.get() completionHandler:[](){
-        gotFlag = true;
-    }];
-
-    TestWebKitAPI::Util::run(&gotFlag);
-    gotFlag = false;
-
-    [cookieStore setCookie:cookie2.get() completionHandler:[](){
-        gotFlag = true;
-    }];
-
-    TestWebKitAPI::Util::run(&gotFlag);
-    gotFlag = false;
-
-    [cookieStore fetchCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
-        *cookiesPtr = [nsCookies retain];
-        gotFlag = true;
-    }];
-
-    TestWebKitAPI::Util::run(&gotFlag);
-
-    ASSERT_EQ(cookies.count, 2u);
-
-    for (NSHTTPCookie *cookie : cookies) {
-        if ([cookie.name isEqual:@"CookieName"]) {
-            ASSERT_TRUE([cookie1.get().path isEqualToString:cookie.path]);
-            ASSERT_TRUE([cookie1.get().value isEqualToString:cookie.value]);
-            ASSERT_TRUE([cookie1.get().domain isEqualToString:cookie.domain]);
-            ASSERT_TRUE(cookie1.get().secure);
-            ASSERT_TRUE(cookie1.get().sessionOnly);
-        } else {
-            ASSERT_TRUE([cookie2.get().path isEqualToString:cookie.path]);
-            ASSERT_TRUE([cookie2.get().value isEqualToString:cookie.value]);
-            ASSERT_TRUE([cookie2.get().name isEqualToString:cookie.name]);
-            ASSERT_TRUE([cookie2.get().domain isEqualToString:cookie.domain]);
-            ASSERT_FALSE(cookie2.get().secure);
-            ASSERT_FALSE(cookie2.get().sessionOnly);
-        }
-    }
-
-    [cookies release];
-}
-
-#endif

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm (from rev 214077, trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStorage.mm) (0 => 214078)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm	2017-03-16 23:30:09 UTC (rev 214078)
@@ -0,0 +1,170 @@
+/*
+ * 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"
+
+#import "PlatformUtilities.h"
+#import <WebKit/WKFoundation.h>
+#import <WebKit/WKHTTPCookieStore.h>
+#import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+static bool gotFlag;
+uint64_t observerCallbacks;
+RetainPtr<WKHTTPCookieStore> globalCookieStore;
+
+@interface CookieObserver : NSObject<WKHTTPCookieStoreObserver>
+- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore;
+@end
+
+@implementation CookieObserver
+
+- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore
+{
+    ASSERT_EQ(cookieStore, globalCookieStore.get());
+    ++observerCallbacks;
+}
+
+@end
+
+TEST(WebKit2, WKHTTPCookieStore)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView loadHTMLString:@"Oh hello" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+
+    globalCookieStore = [WKWebsiteDataStore defaultDataStore]._httpCookieStore;
+    RetainPtr<CookieObserver> observer1 = adoptNS([[CookieObserver alloc] init]);
+    RetainPtr<CookieObserver> observer2 = adoptNS([[CookieObserver alloc] init]);
+    [globalCookieStore addObserver:observer1.get()];
+    [globalCookieStore addObserver:observer2.get()];
+
+    NSArray<NSHTTPCookie *> *cookies = nil;
+    [globalCookieStore allCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
+        *cookiesPtr = [nsCookies retain];
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+
+    ASSERT_EQ(cookies.count, 0u);
+    [cookies release];
+
+    gotFlag = false;
+
+    RetainPtr<NSHTTPCookie> cookie1 = [NSHTTPCookie cookieWithProperties:@{
+        NSHTTPCookiePath: @"/",
+        NSHTTPCookieName: @"CookieName",
+        NSHTTPCookieValue: @"CookieValue",
+        NSHTTPCookieDomain: @".www.webkit.org",
+        NSHTTPCookieSecure: @"TRUE",
+        NSHTTPCookieDiscard: @"TRUE",
+        NSHTTPCookieMaximumAge: @"10000",
+    }];
+
+    RetainPtr<NSHTTPCookie> cookie2 = [NSHTTPCookie cookieWithProperties:@{
+        NSHTTPCookiePath: @"/path",
+        NSHTTPCookieName: @"OtherCookieName",
+        NSHTTPCookieValue: @"OtherCookieValue",
+        NSHTTPCookieDomain: @".www.w3c.org",
+        NSHTTPCookieMaximumAge: @"10000",
+    }];
+
+    [globalCookieStore setCookie:cookie1.get() completionHandler:[](){
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    [globalCookieStore setCookie:cookie2.get() completionHandler:[](){
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    [globalCookieStore allCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
+        *cookiesPtr = [nsCookies retain];
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    ASSERT_EQ(cookies.count, 2u);
+    ASSERT_EQ(observerCallbacks, 4u);
+
+    for (NSHTTPCookie *cookie : cookies) {
+        if ([cookie.name isEqual:@"CookieName"]) {
+            ASSERT_TRUE([cookie1.get().path isEqualToString:cookie.path]);
+            ASSERT_TRUE([cookie1.get().value isEqualToString:cookie.value]);
+            ASSERT_TRUE([cookie1.get().domain isEqualToString:cookie.domain]);
+            ASSERT_TRUE(cookie1.get().secure);
+            ASSERT_TRUE(cookie1.get().sessionOnly);
+        } else {
+            ASSERT_TRUE([cookie2.get().path isEqualToString:cookie.path]);
+            ASSERT_TRUE([cookie2.get().value isEqualToString:cookie.value]);
+            ASSERT_TRUE([cookie2.get().name isEqualToString:cookie.name]);
+            ASSERT_TRUE([cookie2.get().domain isEqualToString:cookie.domain]);
+            ASSERT_FALSE(cookie2.get().secure);
+            ASSERT_FALSE(cookie2.get().sessionOnly);
+        }
+    }
+    [cookies release];
+
+    [globalCookieStore deleteCookie:cookie2.get() completionHandler:[](){
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    [globalCookieStore allCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
+        *cookiesPtr = [nsCookies retain];
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    ASSERT_EQ(cookies.count, 1u);
+    ASSERT_EQ(observerCallbacks, 6u);
+
+    for (NSHTTPCookie *cookie : cookies) {
+        ASSERT_TRUE([cookie1.get().path isEqualToString:cookie.path]);
+        ASSERT_TRUE([cookie1.get().value isEqualToString:cookie.value]);
+        ASSERT_TRUE([cookie1.get().domain isEqualToString:cookie.domain]);
+        ASSERT_TRUE(cookie1.get().secure);
+        ASSERT_TRUE(cookie1.get().sessionOnly);
+    }
+    [cookies release];
+
+    [globalCookieStore removeObserver:observer1.get()];
+    [globalCookieStore removeObserver:observer2.get()];
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to