Add ability to configure document.cookie lifetime cap through user defaults
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Nov 2018 04:50:03 +0000 (04:50 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Nov 2018 04:50:03 +0000 (04:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191480
<rdar://problem/45240871>

Reviewed by Chris Dumez.

Source/WebCore:

No new tests. Existing test makes sure we don't regress.

This change makes the capped lifetime in seconds configurable through
user defaults.

* platform/network/NetworkStorageSession.h:
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::NetworkStorageSession::setAgeCapForClientSideCookies):
(WebCore::NetworkStorageSession::setShouldCapLifetimeForClientSideCookies): Deleted.
    Renamed setAgeCapForClientSideCookies().
* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::filterCookies):
(WebCore::NetworkStorageSession::setCookiesFromDOM const):

Source/WebKit:

This change makes the capped lifetime in seconds configurable through
user defaults.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::setAgeCapForClientSideCookies):
(WebKit::NetworkProcess::setShouldCapLifetimeForClientSideCookies): Deleted.
    Renamed setAgeCapForClientSideCookies().
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm:
(WebKit::ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded):
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::setAgeCapForClientSideCookies):
(WebKit::NetworkProcessProxy::didSetAgeCapForClientSideCookies):
(WebKit::NetworkProcessProxy::setShouldCapLifetimeForClientSideCookies): Deleted.
    Renamed setAgeCapForClientSideCookies().
(WebKit::NetworkProcessProxy::didSetShouldCapLifetimeForClientSideCookies): Deleted.
    Renamed didSetAgeCapForClientSideCookies().
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/Network/NetworkProcessProxy.messages.in:
* UIProcess/ResourceLoadStatisticsMemoryStore.cpp:
(WebKit::ResourceLoadStatisticsMemoryStore::setAgeCapForClientSideCookies):
(WebKit::ResourceLoadStatisticsMemoryStore::updateClientSideCookiesAgeCap):
(WebKit::ResourceLoadStatisticsMemoryStore::didCreateNetworkProcess):
    New function that handles all the things that need to be done when a network
    process has been created.
* UIProcess/ResourceLoadStatisticsMemoryStore.h:
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::didCreateNetworkProcess):
    Now just calls the corresponding function on its memory store where all the
    configuration parameters are available.
* UIProcess/WebResourceLoadStatisticsStore.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::setAgeCapForClientSideCookies):
(WebKit::WebsiteDataStore::setShouldCapLifetimeForClientSideCookies): Deleted.
    Renamed setAgeCapForClientSideCookies().
* UIProcess/WebsiteData/WebsiteDataStore.h:

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp
Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.h
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

index aa2d1a8..b6df381 100644 (file)
@@ -1,3 +1,25 @@
+2018-11-09  John Wilander  <wilander@apple.com>
+
+        Add ability to configure document.cookie lifetime cap through user defaults
+        https://bugs.webkit.org/show_bug.cgi?id=191480
+        <rdar://problem/45240871>
+
+        Reviewed by Chris Dumez.
+
+        No new tests. Existing test makes sure we don't regress.
+
+        This change makes the capped lifetime in seconds configurable through
+        user defaults.
+
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::NetworkStorageSession::setAgeCapForClientSideCookies):
+        (WebCore::NetworkStorageSession::setShouldCapLifetimeForClientSideCookies): Deleted.
+            Renamed setAgeCapForClientSideCookies().
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::filterCookies):
+        (WebCore::NetworkStorageSession::setCookiesFromDOM const):
+
 2018-11-09  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r238047.
index e24f3a5..3e277ee 100644 (file)
@@ -104,7 +104,7 @@ public:
     WEBCORE_EXPORT bool shouldBlockCookies(const ResourceRequest&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     WEBCORE_EXPORT bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     WEBCORE_EXPORT void setPrevalentDomainsToBlockCookiesFor(const Vector<String>&);
-    WEBCORE_EXPORT void setShouldCapLifetimeForClientSideCookies(bool value);
+    WEBCORE_EXPORT void setAgeCapForClientSideCookies(std::optional<Seconds>);
     WEBCORE_EXPORT void removePrevalentDomains(const Vector<String>& domains);
     WEBCORE_EXPORT bool hasStorageAccess(const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID) const;
     WEBCORE_EXPORT Vector<String> getAllStorageAccessEntries() const;
@@ -195,7 +195,7 @@ private:
     HashMap<uint64_t, HashMap<uint64_t, String, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> m_framesGrantedStorageAccess;
     HashMap<uint64_t, HashMap<String, String>, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> m_pagesGrantedStorageAccess;
     std::optional<Seconds> m_cacheMaxAgeCapForPrevalentResources { };
-    bool m_shouldCapLifetimeForClientSideCookies { false };
+    std::optional<Seconds> m_ageCapForClientSideCookies { };
 #endif
 
 #if PLATFORM(COCOA)
index ffd6a61..4b6d43b 100644 (file)
@@ -273,9 +273,9 @@ std::optional<Seconds> NetworkStorageSession::maxAgeCacheCap(const ResourceReque
     return std::nullopt;
 }
 
-void NetworkStorageSession::setShouldCapLifetimeForClientSideCookies(bool value)
+void NetworkStorageSession::setAgeCapForClientSideCookies(std::optional<Seconds> seconds)
 {
-    m_shouldCapLifetimeForClientSideCookies = value;
+    m_ageCapForClientSideCookies = seconds;
 }
 
 void NetworkStorageSession::setPrevalentDomainsToBlockCookiesFor(const Vector<String>& domains)
index a9f2585..e13eb37 100644 (file)
@@ -260,13 +260,12 @@ static NSArray *httpCookiesForURL(CFHTTPCookieStorageRef cookieStorage, NSURL *f
     return cookiesForURL(nsCookieStorage.get(), url, firstParty, sameSiteInfo);
 }
 
-static RetainPtr<NSArray> filterCookies(NSArray *unfilteredCookies, bool shouldCapLifetime)
+static RetainPtr<NSArray> filterCookies(NSArray *unfilteredCookies, std::optional<Seconds> cappedLifetime)
 {
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
     NSUInteger count = [unfilteredCookies count];
     RetainPtr<NSMutableArray> filteredCookies = adoptNS([[NSMutableArray alloc] initWithCapacity:count]);
 
-    const NSTimeInterval secondsPerWeek = 7 * 24 * 60 * 60;
     for (NSUInteger i = 0; i < count; ++i) {
         NSHTTPCookie *cookie = (NSHTTPCookie *)[unfilteredCookies objectAtIndex:i];
 
@@ -281,10 +280,10 @@ static RetainPtr<NSArray> filterCookies(NSArray *unfilteredCookies, bool shouldC
             continue;
 
         // Cap lifetime of persistent, client-side cookies to a week.
-        if (shouldCapLifetime && ![cookie isSessionOnly]) {
-            if (!cookie.expiresDate || cookie.expiresDate.timeIntervalSinceNow > secondsPerWeek) {
+        if (cappedLifetime && ![cookie isSessionOnly]) {
+            if (!cookie.expiresDate || cookie.expiresDate.timeIntervalSinceNow > cappedLifetime->seconds()) {
                 RetainPtr<NSMutableDictionary<NSHTTPCookiePropertyKey, id>> properties = adoptNS([[cookie properties] mutableCopy]);
-                RetainPtr<NSDate> dateInAWeek = adoptNS([[NSDate alloc] initWithTimeIntervalSinceNow:secondsPerWeek]);
+                RetainPtr<NSDate> dateInAWeek = adoptNS([[NSDate alloc] initWithTimeIntervalSinceNow:cappedLifetime->seconds()]);
                 [properties setObject:dateInAWeek.get() forKey:NSHTTPCookieExpires];
                 cookie = [NSHTTPCookie cookieWithProperties:properties.get()];
             }
@@ -405,7 +404,7 @@ void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameS
 #endif
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
-    RetainPtr<NSArray> filteredCookies = filterCookies(unfilteredCookies, m_shouldCapLifetimeForClientSideCookies);
+    RetainPtr<NSArray> filteredCookies = filterCookies(unfilteredCookies, m_ageCapForClientSideCookies);
 #else
     RetainPtr<NSArray> filteredCookies = filterCookies(unfilteredCookies, false);
 #endif
index 597ba28..ee34406 100644 (file)
@@ -1,3 +1,49 @@
+2018-11-09  John Wilander  <wilander@apple.com>
+
+        Add ability to configure document.cookie lifetime cap through user defaults
+        https://bugs.webkit.org/show_bug.cgi?id=191480
+        <rdar://problem/45240871>
+
+        Reviewed by Chris Dumez.
+
+        This change makes the capped lifetime in seconds configurable through
+        user defaults.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::setAgeCapForClientSideCookies):
+        (WebKit::NetworkProcess::setShouldCapLifetimeForClientSideCookies): Deleted.
+            Renamed setAgeCapForClientSideCookies().
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm:
+        (WebKit::ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded):
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::setAgeCapForClientSideCookies):
+        (WebKit::NetworkProcessProxy::didSetAgeCapForClientSideCookies):
+        (WebKit::NetworkProcessProxy::setShouldCapLifetimeForClientSideCookies): Deleted.
+            Renamed setAgeCapForClientSideCookies().
+        (WebKit::NetworkProcessProxy::didSetShouldCapLifetimeForClientSideCookies): Deleted.
+            Renamed didSetAgeCapForClientSideCookies().
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/Network/NetworkProcessProxy.messages.in:
+        * UIProcess/ResourceLoadStatisticsMemoryStore.cpp:
+        (WebKit::ResourceLoadStatisticsMemoryStore::setAgeCapForClientSideCookies):
+        (WebKit::ResourceLoadStatisticsMemoryStore::updateClientSideCookiesAgeCap):
+        (WebKit::ResourceLoadStatisticsMemoryStore::didCreateNetworkProcess):
+            New function that handles all the things that need to be done when a network
+            process has been created.
+        * UIProcess/ResourceLoadStatisticsMemoryStore.h:
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::didCreateNetworkProcess):
+            Now just calls the corresponding function on its memory store where all the
+            configuration parameters are available.
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::setAgeCapForClientSideCookies):
+        (WebKit::WebsiteDataStore::setShouldCapLifetimeForClientSideCookies): Deleted.
+            Renamed setAgeCapForClientSideCookies().
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2018-11-09  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r238047.
index 073f34f..17b0167 100644 (file)
@@ -510,11 +510,11 @@ void NetworkProcess::updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID sess
     parentProcessConnection()->send(Messages::NetworkProcessProxy::DidUpdateBlockCookies(contextId), 0);
 }
 
-void NetworkProcess::setShouldCapLifetimeForClientSideCookies(PAL::SessionID sessionID, bool value, uint64_t contextId)
+void NetworkProcess::setAgeCapForClientSideCookies(PAL::SessionID sessionID, std::optional<Seconds> seconds, uint64_t contextId)
 {
     if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
-        networkStorageSession->setShouldCapLifetimeForClientSideCookies(value);
-    parentProcessConnection()->send(Messages::NetworkProcessProxy::DidSetShouldCapLifetimeForClientSideCookies(contextId), 0);
+        networkStorageSession->setAgeCapForClientSideCookies(seconds);
+    parentProcessConnection()->send(Messages::NetworkProcessProxy::DidSetAgeCapForClientSideCookies(contextId), 0);
 }
 
 void NetworkProcess::hasStorageAccessForFrame(PAL::SessionID sessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, uint64_t contextId)
index b2a23fe..4291b07 100644 (file)
@@ -159,7 +159,7 @@ public:
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<String>& domainsToBlock, uint64_t contextId);
-    void setShouldCapLifetimeForClientSideCookies(PAL::SessionID, bool value, uint64_t contextId);
+    void setAgeCapForClientSideCookies(PAL::SessionID, std::optional<Seconds>, uint64_t contextId);
     void hasStorageAccessForFrame(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, uint64_t contextId);
     void getAllStorageAccessEntries(PAL::SessionID, uint64_t contextId);
     void grantStorageAccess(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, uint64_t contextId);
index c42f5a1..099b7b8 100644 (file)
@@ -83,7 +83,7 @@ messages -> NetworkProcess LegacyReceiver {
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     UpdatePrevalentDomainsToBlockCookiesFor(PAL::SessionID sessionID, Vector<String> domainsToBlock, uint64_t contextId)
-    SetShouldCapLifetimeForClientSideCookies(PAL::SessionID sessionID, bool value, uint64_t contextId)
+    SetAgeCapForClientSideCookies(PAL::SessionID sessionID, std::optional<Seconds> seconds, uint64_t contextId)
     HasStorageAccessForFrame(PAL::SessionID sessionID, String resourceDomain, String firstPartyDomain, uint64_t frameID, uint64_t pageID, uint64_t contextId)
     GetAllStorageAccessEntries(PAL::SessionID sessionID, uint64_t contextId)
     GrantStorageAccess(PAL::SessionID sessionID, String resourceDomain, String firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, uint64_t contextId)
index 8d9d1bb..652bc1d 100644 (file)
@@ -56,6 +56,10 @@ void ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded()
         Seconds cacheMaxAgeCapForPrevalentResources([[NSUserDefaults standardUserDefaults] doubleForKey:@"ResourceLoadStatisticsCacheMaxAgeCap"]);
         if (cacheMaxAgeCapForPrevalentResources > 0_s && cacheMaxAgeCapForPrevalentResources <= 24_h * 365)
             setCacheMaxAgeCap(cacheMaxAgeCapForPrevalentResources);
+        
+        Seconds clientSideCookiesAgeCap([[NSUserDefaults standardUserDefaults] doubleForKey:@"ResourceLoadStatisticsClientSideCookiesAgeCap"]);
+        if (clientSideCookiesAgeCap > 0_s && clientSideCookiesAgeCap <= 24_h * 365)
+            setAgeCapForClientSideCookies(clientSideCookiesAgeCap);
     });
 }
 
index 3780f22..e107f5b 100644 (file)
@@ -415,7 +415,7 @@ void NetworkProcessProxy::didUpdateBlockCookies(uint64_t callbackId)
     m_updateBlockCookiesCallbackMap.take(callbackId)();
 }
 
-void NetworkProcessProxy::setShouldCapLifetimeForClientSideCookies(PAL::SessionID sessionID, ShouldCapLifetimeForClientSideCookies shouldCapLifetime, CompletionHandler<void()>&& completionHandler)
+void NetworkProcessProxy::setAgeCapForClientSideCookies(PAL::SessionID sessionID, std::optional<Seconds> seconds, CompletionHandler<void()>&& completionHandler)
 {
     if (!canSendMessage()) {
         completionHandler();
@@ -427,10 +427,10 @@ void NetworkProcessProxy::setShouldCapLifetimeForClientSideCookies(PAL::SessionI
         completionHandler();
     });
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
-    send(Messages::NetworkProcess::SetShouldCapLifetimeForClientSideCookies(sessionID, shouldCapLifetime == ShouldCapLifetimeForClientSideCookies::Yes, callbackId), 0);
+    send(Messages::NetworkProcess::SetAgeCapForClientSideCookies(sessionID, seconds, callbackId), 0);
 }
 
-void NetworkProcessProxy::didSetShouldCapLifetimeForClientSideCookies(uint64_t callbackId)
+void NetworkProcessProxy::didSetAgeCapForClientSideCookies(uint64_t callbackId)
 {
     m_updateBlockCookiesCallbackMap.take(callbackId)();
 }
index dc9add1..33240e3 100644 (file)
@@ -79,7 +79,7 @@ public:
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<String>& domainsToBlock, CompletionHandler<void()>&&);
-    void setShouldCapLifetimeForClientSideCookies(PAL::SessionID, ShouldCapLifetimeForClientSideCookies, CompletionHandler<void()>&&);
+    void setAgeCapForClientSideCookies(PAL::SessionID, std::optional<Seconds>, CompletionHandler<void()>&&);
     void hasStorageAccessForFrame(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(bool)>&& callback);
     void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String>&& domains)>&&);
     void grantStorageAccess(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, CompletionHandler<void(bool)>&& callback);
@@ -145,7 +145,7 @@ private:
     void logDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     void didUpdateBlockCookies(uint64_t contextId);
-    void didSetShouldCapLifetimeForClientSideCookies(uint64_t contextId);
+    void didSetAgeCapForClientSideCookies(uint64_t contextId);
     void storageAccessRequestResult(bool wasGranted, uint64_t contextId);
     void allStorageAccessEntriesResult(Vector<String>&& domains, uint64_t contextId);
     void didRemoveAllStorageAccess(uint64_t contextId);
index 05d442f..cd96afc 100644 (file)
@@ -43,7 +43,7 @@ messages -> NetworkProcessProxy LegacyReceiver {
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     DidUpdateBlockCookies(uint64_t callbackId)
-    DidSetShouldCapLifetimeForClientSideCookies(uint64_t callbackId)
+    DidSetAgeCapForClientSideCookies(uint64_t callbackId)
     StorageAccessRequestResult(bool wasGranted, uint64_t contextId)
     AllStorageAccessEntriesResult(Vector<String> domains, uint64_t contextId)
     DidRemoveAllStorageAccess(uint64_t contextId)
index 6d99be9..c9d22f6 100644 (file)
@@ -848,6 +848,27 @@ void ResourceLoadStatisticsMemoryStore::updateCacheMaxAgeCap()
     });
 }
 
+void ResourceLoadStatisticsMemoryStore::setAgeCapForClientSideCookies(Seconds seconds)
+{
+    ASSERT(!RunLoop::isMain());
+    ASSERT(seconds >= 0_s);
+    
+    m_parameters.clientSideCookiesAgeCapTime = seconds;
+    updateClientSideCookiesAgeCap();
+}
+
+void ResourceLoadStatisticsMemoryStore::updateClientSideCookiesAgeCap()
+{
+    ASSERT(!RunLoop::isMain());
+
+#if ENABLE(RESOURCE_LOAD_STATISTICS)
+    RunLoop::main().dispatch([store = makeRef(m_store), seconds = m_parameters.clientSideCookiesAgeCapTime] () {
+        if (auto* websiteDataStore = store->websiteDataStore())
+            websiteDataStore->setAgeCapForClientSideCookies(seconds, [] { });
+    });
+#endif
+}
+
 bool ResourceLoadStatisticsMemoryStore::shouldRemoveDataRecords() const
 {
     ASSERT(!RunLoop::isMain());
@@ -1264,4 +1285,13 @@ void ResourceLoadStatisticsMemoryStore::removeAllStorageAccess(CompletionHandler
     });
 }
 
+void ResourceLoadStatisticsMemoryStore::didCreateNetworkProcess()
+{
+    ASSERT(!RunLoop::isMain());
+
+    updateCookieBlocking([]() { });
+    updateCacheMaxAgeCap();
+    updateClientSideCookiesAgeCap();
+}
+
 } // namespace WebKit
index d2e886e..65b3f18 100644 (file)
@@ -112,8 +112,6 @@ public:
     void setTimeToLiveUserInteraction(Seconds);
     void setMinimumTimeBetweenDataRecordsRemoval(Seconds);
     void setGrandfatheringTime(Seconds);
-    void setCacheMaxAgeCap(Seconds);
-    void updateCacheMaxAgeCap();
     void setResourceLoadStatisticsDebugMode(bool);
     bool isDebugModeEnabled() const { return m_debugModeEnabled; };
     void setPrevalentResourceForDebugMode(const String& domain);
@@ -130,6 +128,8 @@ public:
 
     void setLastSeen(const String& primaryDomain, Seconds);
 
+    void didCreateNetworkProcess();
+
 private:
     static bool shouldBlockAndKeepCookies(const WebCore::ResourceLoadStatistics&);
     static bool shouldBlockAndPurgeCookies(const WebCore::ResourceLoadStatistics&);
@@ -152,6 +152,10 @@ private:
     void pruneStatisticsIfNeeded();
     WebCore::ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
     Vector<String> topPrivatelyControlledDomainsToRemoveWebsiteDataFor();
+    void setCacheMaxAgeCap(Seconds);
+    void updateCacheMaxAgeCap();
+    void setAgeCapForClientSideCookies(Seconds);
+    void updateClientSideCookiesAgeCap();
 
 #if PLATFORM(COCOA)
     void registerUserDefaultsIfNeeded();
@@ -164,6 +168,7 @@ private:
         Seconds minimumTimeBetweenDataRecordsRemoval { 1_h };
         Seconds grandfatheringTime { 24_h * 7 };
         Seconds cacheMaxAgeCapTime { 24_h * 7 };
+        Seconds clientSideCookiesAgeCapTime { 24_h * 7 };
         bool shouldNotifyPagesWhenDataRecordsWereScanned { false };
         bool shouldClassifyResourcesBeforeDataRecordsRemoval { true };
         bool shouldSubmitTelemetry { true };
index 6ad079d..03412a7 100644 (file)
@@ -329,14 +329,8 @@ void WebResourceLoadStatisticsStore::didCreateNetworkProcess()
     postTask([this] {
         if (!m_memoryStore)
             return;
-        m_memoryStore->updateCookieBlocking([]() { });
-        m_memoryStore->updateCacheMaxAgeCap();
+        m_memoryStore->didCreateNetworkProcess();
     });
-
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
-    if (m_websiteDataStore)
-        m_websiteDataStore->setShouldCapLifetimeForClientSideCookies(ShouldCapLifetimeForClientSideCookies::Yes, []() { });
-#endif
 }
 
 void WebResourceLoadStatisticsStore::removeAllStorageAccess(CompletionHandler<void()>&& completionHandler)
index 75811b3..72d9908 100644 (file)
@@ -140,6 +140,8 @@ public:
 
     void didCreateNetworkProcess();
 
+    WebsiteDataStore* websiteDataStore() { return m_websiteDataStore.get(); }
+
 private:
     explicit WebResourceLoadStatisticsStore(WebsiteDataStore&);
 
index 0ebe0bb..b90c142 100644 (file)
@@ -1266,13 +1266,13 @@ void WebsiteDataStore::updatePrevalentDomainsToBlockCookiesFor(const Vector<Stri
     }
 }
 
-void WebsiteDataStore::setShouldCapLifetimeForClientSideCookies(ShouldCapLifetimeForClientSideCookies shouldCapLifetime, CompletionHandler<void()>&& completionHandler)
+void WebsiteDataStore::setAgeCapForClientSideCookies(std::optional<Seconds> seconds, CompletionHandler<void()>&& completionHandler)
 {
     auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
     
     for (auto& processPool : processPools()) {
         if (auto* process = processPool->networkProcess())
-            process->setShouldCapLifetimeForClientSideCookies(m_sessionID, shouldCapLifetime, [processPool, callbackAggregator = callbackAggregator.copyRef()] { });
+            process->setAgeCapForClientSideCookies(m_sessionID, seconds, [processPool, callbackAggregator = callbackAggregator.copyRef()] { });
     }
 }
 
index 99ea686..852b6bb 100644 (file)
@@ -78,8 +78,6 @@ enum class StorageAccessPromptStatus;
 struct PluginModuleInfo;
 #endif
 
-enum class ShouldCapLifetimeForClientSideCookies { No, Yes };
-
 class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver, public Identified<WebsiteDataStore>, public CanMakeWeakPtr<WebsiteDataStore>  {
 public:
     constexpr static uint64_t defaultCacheStoragePerOriginQuota = 50 * 1024 * 1024;
@@ -142,7 +140,7 @@ public:
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     void updatePrevalentDomainsToBlockCookiesFor(const Vector<String>& domainsToBlock, CompletionHandler<void()>&&);
-    void setShouldCapLifetimeForClientSideCookies(ShouldCapLifetimeForClientSideCookies, CompletionHandler<void()>&&);
+    void setAgeCapForClientSideCookies(std::optional<Seconds>, CompletionHandler<void()>&&);
     void hasStorageAccessForFrameHandler(const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(bool hasAccess)>&&);
     void getAllStorageAccessEntries(uint64_t pageID, CompletionHandler<void(Vector<String>&& domains)>&&);
     void grantStorageAccessHandler(const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, CompletionHandler<void(bool wasGranted)>&&);