Title: [257888] trunk/Source
Revision
257888
Author
cdu...@apple.com
Date
2020-03-04 15:28:12 -0800 (Wed, 04 Mar 2020)

Log Message

Adopt new and improved CFNetwork SPI for cookie change notifications
https://bugs.webkit.org/show_bug.cgi?id=208594
<rdar://problem/60053313>

Reviewed by Alex Christensen.

Source/WebCore:

Adopt new and improved CFNetwork SPI for cookie change notifications. Notifications are now per domain
and the domain matches one of the domains we listen for cookie changes on.

This also fixes a bug where httpOnly cookies would be sent to the WebContent processes in cookie change
notifications, even though the WebProcesses are not interested in those.

* platform/network/NetworkStorageSession.h:
* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::NetworkStorageSession::registerCookieChangeListenersIfNecessary):

Source/WebCore/PAL:

Add new CFNetwork SPI.

* pal/spi/cf/CFNetworkSPI.h:

Source/WebKit:

Adopt new and improved CFNetwork SPI for cookie change notifications. Notifications are now per domain
and the domain matches one of the domains we listen for cookie changes on.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::cookiesDeleted):
(WebKit::NetworkConnectionToWebProcess::allCookiesDeleted):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::cookiesDeleted):
(WebKit::NetworkProcessConnection::allCookiesDeleted):
* WebProcess/Network/NetworkProcessConnection.h:
* WebProcess/Network/NetworkProcessConnection.messages.in:
* WebProcess/WebPage/WebCookieCache.cpp:
(WebKit::WebCookieCache::cookiesDeleted):
(WebKit::WebCookieCache::allCookiesDeleted):
* WebProcess/WebPage/WebCookieCache.h:
* WebProcess/WebPage/WebCookieJar.cpp:
(WebKit::WebCookieJar::cookiesDeleted):
(WebKit::WebCookieJar::allCookiesDeleted):
* WebProcess/WebPage/WebCookieJar.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257887 => 257888)


--- trunk/Source/WebCore/ChangeLog	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebCore/ChangeLog	2020-03-04 23:28:12 UTC (rev 257888)
@@ -1,3 +1,21 @@
+2020-03-04  Chris Dumez  <cdu...@apple.com>
+
+        Adopt new and improved CFNetwork SPI for cookie change notifications
+        https://bugs.webkit.org/show_bug.cgi?id=208594
+        <rdar://problem/60053313>
+
+        Reviewed by Alex Christensen.
+
+        Adopt new and improved CFNetwork SPI for cookie change notifications. Notifications are now per domain
+        and the domain matches one of the domains we listen for cookie changes on.
+
+        This also fixes a bug where httpOnly cookies would be sent to the WebContent processes in cookie change
+        notifications, even though the WebProcesses are not interested in those.
+
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::NetworkStorageSession::registerCookieChangeListenersIfNecessary):
+
 2020-03-04  Alex Christensen  <achristen...@webkit.org>
 
         Add SPI to evaluate _javascript_ in an iframe

Modified: trunk/Source/WebCore/PAL/ChangeLog (257887 => 257888)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-03-04 23:28:12 UTC (rev 257888)
@@ -1,3 +1,15 @@
+2020-03-04  Chris Dumez  <cdu...@apple.com>
+
+        Adopt new and improved CFNetwork SPI for cookie change notifications
+        https://bugs.webkit.org/show_bug.cgi?id=208594
+        <rdar://problem/60053313>
+
+        Reviewed by Alex Christensen.
+
+        Add new CFNetwork SPI.
+
+        * pal/spi/cf/CFNetworkSPI.h:
+
 2020-03-03  Jiten Mehta  <jme...@apple.com>
 
         Adopt HTTP Alternative Services Storage

Modified: trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h (257887 => 257888)


--- trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2020-03-04 23:28:12 UTC (rev 257888)
@@ -417,9 +417,12 @@
 @interface NSHTTPCookieStorage ()
 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
 - (void)_setSubscribedDomainsForCookieChanges:(NSSet<NSString*>* __nullable)domainList;
+- (NSArray* __nullable)_getCookiesForDomain:(NSString*)domain;
+- (void)_setCookiesChangedHandler:(void(^__nullable)(NSArray<NSHTTPCookie*>* addedCookies, NSString* domainForChangedCookie))cookiesChangedHandler onQueue:(dispatch_queue_t __nullable)queue;
+- (void)_setCookiesRemovedHandler:(void(^__nullable)(NSArray<NSHTTPCookie*>* __nullable removedCookies, NSString* __nullable domainForRemovedCookies, bool removeAllCookies))cookiesRemovedHandler onQueue:(dispatch_queue_t __nullable)queue;
+// FIXME: The following 2 should be removed are only kept to ensure smooth transition to the new _setCookiesChangedHandler / _setCookiesRemovedHandler SPI.
 - (void)_setCookiesAddedHandler:(void(^__nullable)(NSArray<NSHTTPCookie*>* addedCookies, NSURL* __nullable urlForAddedCookies))cookiesAddedHandler onQueue:(dispatch_queue_t __nullable)queue;
 - (void)_setCookiesDeletedHandler:(void(^__nullable)(NSArray<NSHTTPCookie*>* __nullable deletedCookies, bool deletedAllCookies))cookiesDeletedHandler onQueue:(dispatch_queue_t __nullable)queue;
-- (NSArray* __nullable)_getCookiesForDomain:(NSString*)domain;
 @end
 
 @interface NSURLResponse ()

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (257887 => 257888)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2020-03-04 23:28:12 UTC (rev 257888)
@@ -86,7 +86,8 @@
 public:
     virtual ~CookieChangeObserver() { }
     virtual void cookiesAdded(const String& host, const Vector<WebCore::Cookie>&) = 0;
-    virtual void cookiesDeleted() = 0;
+    virtual void cookiesDeleted(const String& host, const Vector<WebCore::Cookie>&) = 0;
+    virtual void allCookiesDeleted() = 0;
 };
 #endif
 

Modified: trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm (257887 => 257888)


--- trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2020-03-04 23:28:12 UTC (rev 257888)
@@ -584,26 +584,72 @@
         return;
 
     m_didRegisterCookieListeners = true;
-    [nsCookieStorage() _setCookiesAddedHandler:^(NSArray<NSHTTPCookie *> * nsCookies, NSURL *urlForAddedCookies) {
-        Vector<Cookie> cookies = nsCookiesToCookieVector(nsCookies);
-        auto host = URL(urlForAddedCookies).host().toString();
-        RELEASE_ASSERT(!host.isNull());
-        // FIXME: This is inefficient. Unfortunately, CFNetwork sends us notifications for hosts that do not match exactly the ones we
-        // are listening for (e.g. 'secure.hulu.com instead of 'www.hulu.com' for). See <rdar://problem/59973630>.
-        auto registrableDomain = RegistrableDomain::uncheckedCreateFromHost(host);
-        for (auto& pair : m_cookieChangeObservers) {
-            if (RegistrableDomain::uncheckedCreateFromHost(pair.key) == registrableDomain) {
-                for (auto* observer : pair.value)
-                    observer->cookiesAdded(pair.key, cookies);
+
+    if ([nsCookieStorage() respondsToSelector:@selector(_setCookiesChangedHandler:onQueue:)]) {
+        [nsCookieStorage() _setCookiesChangedHandler:^(NSArray<NSHTTPCookie*>* addedCookies, NSString* domainForChangedCookie) {
+            String host = domainForChangedCookie;
+            auto it = m_cookieChangeObservers.find(host);
+            if (it == m_cookieChangeObservers.end())
+                return;
+            auto cookies = nsCookiesToCookieVector(addedCookies, [](NSHTTPCookie *cookie) { return !cookie.HTTPOnly; });
+            if (cookies.isEmpty())
+                return;
+            for (auto* observer : it->value)
+                observer->cookiesAdded(host, cookies);
+        } onQueue:dispatch_get_main_queue()];
+    } else {
+        // Old SPI.
+        // FIXME: This could can be removed after a while. It is only kept to ensure a smooth transition to the new SPI.
+        [nsCookieStorage() _setCookiesAddedHandler:^(NSArray<NSHTTPCookie *> * nsCookies, NSURL *urlForAddedCookies) {
+            auto cookies = nsCookiesToCookieVector(nsCookies, [](NSHTTPCookie *cookie) { return !cookie.HTTPOnly; });
+            if (cookies.isEmpty())
+                return;
+            auto host = URL(urlForAddedCookies).host().toString();
+            RELEASE_ASSERT(!host.isNull());
+            // FIXME: This is inefficient. Unfortunately, CFNetwork sends us notifications for hosts that do not match exactly the ones we
+            // are listening for (e.g. 'secure.hulu.com instead of 'www.hulu.com' for). See <rdar://problem/59973630>.
+            auto registrableDomain = RegistrableDomain::uncheckedCreateFromHost(host);
+            for (auto& pair : m_cookieChangeObservers) {
+                if (RegistrableDomain::uncheckedCreateFromHost(pair.key) == registrableDomain) {
+                    for (auto* observer : pair.value)
+                        observer->cookiesAdded(pair.key, cookies);
+                }
             }
-        }
-    } onQueue:dispatch_get_main_queue()];
-    [nsCookieStorage() _setCookiesDeletedHandler:^(NSArray<NSHTTPCookie *> *, bool /*deletedAllCookies*/) {
-        for (auto& observers : m_cookieChangeObservers.values()) {
-            for (auto* observer : observers)
-                observer->cookiesDeleted();
-        }
-    } onQueue:dispatch_get_main_queue()];
+        } onQueue:dispatch_get_main_queue()];
+    }
+
+    if ([nsCookieStorage() respondsToSelector:@selector(_setCookiesRemovedHandler:onQueue:)]) {
+        [nsCookieStorage() _setCookiesRemovedHandler:^(NSArray<NSHTTPCookie*>* removedCookies, NSString* domainForRemovedCookies, bool removeAllCookies)
+        {
+            if (removeAllCookies) {
+                for (auto& observers : m_cookieChangeObservers.values()) {
+                    for (auto* observer : observers)
+                        observer->allCookiesDeleted();
+                }
+                return;
+            }
+
+            String host = domainForRemovedCookies;
+            auto it = m_cookieChangeObservers.find(host);
+            if (it == m_cookieChangeObservers.end())
+                return;
+
+            auto cookies = nsCookiesToCookieVector(removedCookies, [](NSHTTPCookie *cookie) { return !cookie.HTTPOnly; });
+            if (cookies.isEmpty())
+                return;
+            for (auto* observer : it->value)
+                observer->cookiesDeleted(host, cookies);
+        } onQueue:dispatch_get_main_queue()];
+    } else {
+        // Old SPI.
+        // FIXME: This could can be removed after a while. It is only kept to ensure a smooth transition to the new SPI.
+        [nsCookieStorage() _setCookiesDeletedHandler:^(NSArray<NSHTTPCookie *> *, bool /*deletedAllCookies*/) {
+            for (auto& observers : m_cookieChangeObservers.values()) {
+                for (auto* observer : observers)
+                    observer->allCookiesDeleted();
+            }
+        } onQueue:dispatch_get_main_queue()];
+    }
 }
 
 void NetworkStorageSession::unregisterCookieChangeListenersIfNecessary()

Modified: trunk/Source/WebKit/ChangeLog (257887 => 257888)


--- trunk/Source/WebKit/ChangeLog	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/ChangeLog	2020-03-04 23:28:12 UTC (rev 257888)
@@ -1,3 +1,32 @@
+2020-03-04  Chris Dumez  <cdu...@apple.com>
+
+        Adopt new and improved CFNetwork SPI for cookie change notifications
+        https://bugs.webkit.org/show_bug.cgi?id=208594
+        <rdar://problem/60053313>
+
+        Reviewed by Alex Christensen.
+
+        Adopt new and improved CFNetwork SPI for cookie change notifications. Notifications are now per domain
+        and the domain matches one of the domains we listen for cookie changes on.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::cookiesDeleted):
+        (WebKit::NetworkConnectionToWebProcess::allCookiesDeleted):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * WebProcess/Network/NetworkProcessConnection.cpp:
+        (WebKit::NetworkProcessConnection::cookiesDeleted):
+        (WebKit::NetworkProcessConnection::allCookiesDeleted):
+        * WebProcess/Network/NetworkProcessConnection.h:
+        * WebProcess/Network/NetworkProcessConnection.messages.in:
+        * WebProcess/WebPage/WebCookieCache.cpp:
+        (WebKit::WebCookieCache::cookiesDeleted):
+        (WebKit::WebCookieCache::allCookiesDeleted):
+        * WebProcess/WebPage/WebCookieCache.h:
+        * WebProcess/WebPage/WebCookieJar.cpp:
+        (WebKit::WebCookieJar::cookiesDeleted):
+        (WebKit::WebCookieJar::allCookiesDeleted):
+        * WebProcess/WebPage/WebCookieJar.h:
+
 2020-03-04  Alex Christensen  <achristen...@webkit.org>
 
         Add SPI to evaluate _javascript_ in an iframe

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (257887 => 257888)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2020-03-04 23:28:12 UTC (rev 257888)
@@ -681,11 +681,16 @@
     connection().send(Messages::NetworkProcessConnection::CookiesAdded(host, cookies), 0);
 }
 
-void NetworkConnectionToWebProcess::cookiesDeleted()
+void NetworkConnectionToWebProcess::cookiesDeleted(const String& host, const Vector<WebCore::Cookie>& cookies)
 {
-    connection().send(Messages::NetworkProcessConnection::CookiesDeleted(), 0);
+    connection().send(Messages::NetworkProcessConnection::CookiesDeleted(host, cookies), 0);
 }
 
+void NetworkConnectionToWebProcess::allCookiesDeleted()
+{
+    connection().send(Messages::NetworkProcessConnection::AllCookiesDeleted(), 0);
+}
+
 #endif
 
 void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, SandboxExtension::Handle&& extensionHandle, const String& contentType)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h (257887 => 257888)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h	2020-03-04 23:28:12 UTC (rev 257888)
@@ -279,7 +279,8 @@
 
     // WebCore::CookieChangeObserver.
     void cookiesAdded(const String& host, const Vector<WebCore::Cookie>&) final;
-    void cookiesDeleted() final;
+    void cookiesDeleted(const String& host, const Vector<WebCore::Cookie>&) final;
+    void allCookiesDeleted() final;
 #endif
 
     struct ResourceNetworkActivityTracker {

Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp	2020-03-04 23:28:12 UTC (rev 257888)
@@ -241,10 +241,15 @@
     WebProcess::singleton().cookieJar().cookiesAdded(host, cookies);
 }
 
-void NetworkProcessConnection::cookiesDeleted()
+void NetworkProcessConnection::cookiesDeleted(const String& host, const Vector<WebCore::Cookie>& cookies)
 {
-    WebProcess::singleton().cookieJar().cookiesDeleted();
+    WebProcess::singleton().cookieJar().cookiesDeleted(host, cookies);
 }
+
+void NetworkProcessConnection::allCookiesDeleted()
+{
+    WebProcess::singleton().cookieJar().allCookiesDeleted();
+}
 #endif
 
 #if ENABLE(SHAREABLE_RESOURCE)

Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h	2020-03-04 23:28:12 UTC (rev 257888)
@@ -86,7 +86,8 @@
 
 #if HAVE(COOKIE_CHANGE_LISTENER_API)
     void cookiesAdded(const String& host, const Vector<WebCore::Cookie>&);
-    void cookiesDeleted();
+    void cookiesDeleted(const String& host, const Vector<WebCore::Cookie>&);
+    void allCookiesDeleted();
 #endif
 
 private:

Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in	2020-03-04 23:28:12 UTC (rev 257888)
@@ -33,7 +33,8 @@
 
 #if HAVE(COOKIE_CHANGE_LISTENER_API)
     CookiesAdded(String host, Vector<struct WebCore::Cookie> cookies);
-    CookiesDeleted();
+    CookiesDeleted(String host, Vector<struct WebCore::Cookie> cookies);
+    AllCookiesDeleted();
 #endif
 
     CheckProcessLocalPortForActivity(struct WebCore::MessagePortIdentifier port) -> (WebCore::MessagePortChannelProvider::HasActivity hasActivity) Async

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.cpp (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.cpp	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.cpp	2020-03-04 23:28:12 UTC (rev 257888)
@@ -76,8 +76,17 @@
         inMemoryStorageSession().setCookie(cookie);
 }
 
-void WebCookieCache::cookiesDeleted()
+void WebCookieCache::cookiesDeleted(const String& host, const Vector<WebCore::Cookie>& cookies)
 {
+    if (!m_hostsWithInMemoryStorage.contains(host))
+        return;
+
+    for (auto& cookie : cookies)
+        inMemoryStorageSession().deleteCookie(cookie);
+}
+
+void WebCookieCache::allCookiesDeleted()
+{
     clear();
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.h (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.h	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.h	2020-03-04 23:28:12 UTC (rev 257888)
@@ -45,7 +45,8 @@
     void setCookiesFromDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, const String& cookieString);
 
     void cookiesAdded(const String& host, const Vector<WebCore::Cookie>&);
-    void cookiesDeleted();
+    void cookiesDeleted(const String& host, const Vector<WebCore::Cookie>&);
+    void allCookiesDeleted();
 
     void clear();
     void clearForHost(const String&);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebCookieJar.cpp (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/WebPage/WebCookieJar.cpp	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebCookieJar.cpp	2020-03-04 23:28:12 UTC (rev 257888)
@@ -161,11 +161,16 @@
     m_cache.cookiesAdded(host, cookies);
 }
 
-void WebCookieJar::cookiesDeleted()
+void WebCookieJar::cookiesDeleted(const String& host, const Vector<WebCore::Cookie>& cookies)
 {
-    m_cache.cookiesDeleted();
+    m_cache.cookiesDeleted(host, cookies);
 }
 
+void WebCookieJar::allCookiesDeleted()
+{
+    m_cache.allCookiesDeleted();
+}
+
 void WebCookieJar::clearCache()
 {
     m_cache.clear();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebCookieJar.h (257887 => 257888)


--- trunk/Source/WebKit/WebProcess/WebPage/WebCookieJar.h	2020-03-04 23:28:03 UTC (rev 257887)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebCookieJar.h	2020-03-04 23:28:12 UTC (rev 257888)
@@ -48,7 +48,8 @@
     void deleteCookie(const WebCore::Document&, const URL&, const String& cookieName) final;
 
     void cookiesAdded(const String& host, const Vector<WebCore::Cookie>&);
-    void cookiesDeleted();
+    void cookiesDeleted(const String& host, const Vector<WebCore::Cookie>&);
+    void allCookiesDeleted();
 
 private:
     WebCookieJar();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to