From 772ed3bc762f49c57fd4349fb0f4feac6e62057e Mon Sep 17 00:00:00 2001 From: Matthew Finkel Date: Fri, 13 Jun 2025 16:32:05 +0200 Subject: [PATCH] [Experimental] Further relax general deletion of script-written website data to 400 days https://bugs.webkit.org/show_bug.cgi?id=293793 rdar://152095900 Reviewed by NOBODY (OOPS!). 274398@main introduced a "long" DataRemovalFrequency that was set at 30 operational days. This patch extends that lifetime to 400 operational days. This roughly aligns web storage with the proposed upper-limit on cookie age [0] (although the cookie age is strictly based on calendar days). We may change this behavior in the future, again. This patch fixes some flakey tests by giving ResourceLoadStatisticsStore::processStatisticsAndDataRecords a completion handler that is called when the process completes. It seems like our thread hopping performance has regressed a bit since these tests were written. This patch also adds a new test that verifies the state of the website data and database after 399 days. The code changes make explicit how each time period is used: - deletion of prevalent domain data (30 operation days) - deletion of script-written website data when link decoration filtering is disabled (7 operational days) - deletion of script-written website data when link decoration filtering is enabled (400 operational days) [0] https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-cookie-lifetime-limits * LayoutTests/http/tests/resourceLoadStatistics/operating-dates-all-website-data-removed.html: * LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html: * LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt: * LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion.html: * LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion-expected.txt: Copied from LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt. * LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion.html: Copied from LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion.html. * LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt: * LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration.html: * LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt: * LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt: * Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp: (WebKit::ResourceLoadStatisticsStore::processStatisticsAndDataRecords): (WebKit::ResourceLoadStatisticsStore::scheduleStatisticsProcessingRequestIfNecessary): (WebKit::ResourceLoadStatisticsStore::resetParametersToDefaultValues): (WebKit::ResourceLoadStatisticsStore::grantStorageAccess): (WebKit::ResourceLoadStatisticsStore::grantStorageAccessInternal): (WebKit::ResourceLoadStatisticsStore::logUserInteraction): (WebKit::ResourceLoadStatisticsStore::areAllUnpartitionedThirdPartyCookiesBlockedUnder): (WebKit::ResourceLoadStatisticsStore::hasHadRecentWebPushInteraction const): (WebKit::ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction): (WebKit::ResourceLoadStatisticsStore::shouldRemoveAllWebsiteDataFor): (WebKit::ResourceLoadStatisticsStore::shouldRemoveAllButCookiesFor): (WebKit::ResourceLoadStatisticsStore::updateOperatingDatesParameters): (WebKit::ResourceLoadStatisticsStore::includeTodayAsOperatingDateIfNecessary): (WebKit::ResourceLoadStatisticsStore::hasStatisticsExpired const): * Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h: * Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::scheduleStatisticsAndDataRecordsProcessing): (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated): (WebKit::WebResourceLoadStatisticsStore::hasHadUserInteraction): --- ...rating-dates-all-website-data-removed.html | 2 +- ...ent-resource-without-user-interaction.html | 2 +- ...ecoration-after-long-deletion-expected.txt | 12 +- ...d-link-decoration-after-long-deletion.html | 4 +- ...coration-before-long-deletion-expected.txt | 37 +++ ...-link-decoration-before-long-deletion.html | 301 ++++++++++++++++++ ...ed-to-without-link-decoration-expected.txt | 12 +- ...-navigated-to-without-link-decoration.html | 2 +- ...ecoration-after-long-deletion-expected.txt | 12 +- ...ed-to-without-link-decoration-expected.txt | 12 +- .../ResourceLoadStatisticsStore.cpp | 58 ++-- .../Classifier/ResourceLoadStatisticsStore.h | 9 +- .../WebResourceLoadStatisticsStore.cpp | 15 +- 13 files changed, 417 insertions(+), 61 deletions(-) create mode 100644 LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion-expected.txt create mode 100644 LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion.html diff --git a/LayoutTests/http/tests/resourceLoadStatistics/operating-dates-all-website-data-removed.html b/LayoutTests/http/tests/resourceLoadStatistics/operating-dates-all-website-data-removed.html index 92b315ef30bfd..28610845f3d47 100644 --- a/LayoutTests/http/tests/resourceLoadStatistics/operating-dates-all-website-data-removed.html +++ b/LayoutTests/http/tests/resourceLoadStatistics/operating-dates-all-website-data-removed.html @@ -239,7 +239,7 @@ function runTest() { setEnableFeature(true, function () { testRunner.setStatisticsExpiredStatistic(originUnderTest, - 30, // numberOfOperatingDaysPassed + 400, // numberOfOperatingDaysPassed true, // hasUserInteraction false, // isScheduledForAllButCookieDataRemoval, true, // isPrevalent diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html index c7fbc68ec6e9a..1ae2edf07eca5 100644 --- a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html +++ b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html @@ -41,7 +41,7 @@ testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false); testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0); await testRunner.statisticsProcessStatisticsAndDataRecords(); - setTimeout("finishTest()", 1000); + setTimeout("finishTest()", 2000); }); }); } diff --git a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt index 9971c8ca9eea1..08060c94ba2f0 100644 --- a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt +++ b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt @@ -7,12 +7,12 @@ Check that script-writeable website data gets removed after a navigation with fi 1 day(s): LocalStorage entry does exist. 1 day(s): IDB entry does exist. -30 day(s): Client-side cookie does not exist. -30 day(s): Client-side persistent cookie does not exist. -30 day(s): HttpOnly cookie exists. -30 day(s): Regular server-side cookie exists. -30 day(s): LocalStorage entry does not exist. -30 day(s): IDB entry does not exist. +400 day(s): Client-side cookie does not exist. +400 day(s): Client-side persistent cookie does not exist. +400 day(s): HttpOnly cookie exists. +400 day(s): Regular server-side cookie exists. +400 day(s): LocalStorage entry does not exist. +400 day(s): IDB entry does not exist. Resource load statistics: diff --git a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion.html b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion.html index c34e11fd62d65..679c3c994c1e7 100644 --- a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion.html +++ b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion.html @@ -17,7 +17,7 @@ const serverSideCookieName = "server-side-cookie"; const clientSideCookieName = "client-side-cookie"; const clientSidePersistentCookieName = "client-side-persistent-cookie"; - const targetOperationalDays = 30; + const targetOperationalDays = 400; let currentOperationalDays = 1; @@ -44,7 +44,7 @@ let cookies = internals.getCookies(); let potentialCookies = { "http-only-cookie": 1, "server-side-cookie": 1, "client-side-cookie": 1, "client-side-persistent-cookie": 1 }; if (!cookies.length) - testFailed(`${currentOperationalDays} day(s): script-accessible deletion: No cookies found.`); + addOutput(`${currentOperationalDays} day(s): script-accessible deletion: No cookies found.`); for (let cookie of cookies) { let cookieType; diff --git a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion-expected.txt new file mode 100644 index 0000000000000..9a95d3d05a2d9 --- /dev/null +++ b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion-expected.txt @@ -0,0 +1,37 @@ +Check that script-writeable website data does not get removed after a navigation with filtered link decoration from a prevalent resource but before the Long data removal period. + +1 day(s): Client-side cookie exists. +1 day(s): Client-side persistent cookie exists. +1 day(s): HttpOnly cookie exists. +1 day(s): Regular server-side cookie exists. +1 day(s): LocalStorage entry does exist. +1 day(s): IDB entry does exist. + +399 day(s): Client-side cookie exists. +399 day(s): Client-side persistent cookie exists. +399 day(s): HttpOnly cookie exists. +399 day(s): Regular server-side cookie exists. +399 day(s): LocalStorage entry does exist. +399 day(s): IDB entry does exist. + + +Resource load statistics: + +Registrable domain: 127.0.0.1 + hadUserInteraction: Yes + mostRecentUserInteraction: -1 + grandfathered: No + TopFrameLinkDecorationsFrom: + localhost + DataRemovalFrequency: Long + isPrevalentResource: No + isVeryPrevalentResource: No + dataRecordsRemoved: 0 +Registrable domain: localhost + hadUserInteraction: No + mostRecentUserInteraction: -1 + grandfathered: No + DataRemovalFrequency: Never + isPrevalentResource: Yes + isVeryPrevalentResource: No + dataRecordsRemoved: 0 diff --git a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion.html b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion.html new file mode 100644 index 0000000000000..fd25f1b5c8736 --- /dev/null +++ b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-before-long-deletion.html @@ -0,0 +1,301 @@ + + + + + + + +
Check that script-writeable website data does not get removed after a navigation with filtered link decoration from a prevalent resource but before the Long data removal period.
+
+
+
+ + + diff --git a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt index 697f2e1607c37..376af7bad21db 100644 --- a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt +++ b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt @@ -7,12 +7,12 @@ Check that script-writeable website data gets removed after a navigation without 1 day(s): LocalStorage entry does exist. 1 day(s): IDB entry does exist. -30 day(s): Client-side cookie does not exist. -30 day(s): Client-side persistent cookie does not exist. -30 day(s): HttpOnly cookie exists. -30 day(s): Regular server-side cookie exists. -30 day(s): LocalStorage entry does not exist. -30 day(s): IDB entry does not exist. +400 day(s): Client-side cookie does not exist. +400 day(s): Client-side persistent cookie does not exist. +400 day(s): HttpOnly cookie exists. +400 day(s): Regular server-side cookie exists. +400 day(s): LocalStorage entry does not exist. +400 day(s): IDB entry does not exist. Resource load statistics: diff --git a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration.html b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration.html index 7cc1ae69e795a..87afc70e5cbe2 100644 --- a/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration.html +++ b/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration.html @@ -17,7 +17,7 @@ const serverSideCookieName = "server-side-cookie"; const clientSideCookieName = "client-side-cookie"; const clientSidePersistentCookieName = "client-side-persistent-cookie"; - const targetOperationalDays = 30; + const targetOperationalDays = 400; let currentOperationalDays = 1; diff --git a/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt b/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt index aeb97108b1181..5f8487f5a6008 100644 --- a/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt +++ b/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-filtered-link-decoration-after-long-deletion-expected.txt @@ -7,12 +7,12 @@ Check that script-writeable website data gets removed after a navigation with fi 1 day(s): LocalStorage entry does exist. 1 day(s): IDB entry does exist. -30 day(s): Client-side cookie exists. -30 day(s): Client-side persistent cookie exists. -30 day(s): HttpOnly cookie exists. -30 day(s): Regular server-side cookie exists. -30 day(s): LocalStorage entry does not exist. -30 day(s): IDB entry does not exist. +400 day(s): Client-side cookie exists. +400 day(s): Client-side persistent cookie exists. +400 day(s): HttpOnly cookie exists. +400 day(s): Regular server-side cookie exists. +400 day(s): LocalStorage entry does not exist. +400 day(s): IDB entry does not exist. Resource load statistics: diff --git a/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt b/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt index 6e20adea766d5..4f68c1a0354a9 100644 --- a/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt +++ b/LayoutTests/platform/glib/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-without-link-decoration-expected.txt @@ -7,12 +7,12 @@ Check that script-writeable website data gets removed after a navigation without 1 day(s): LocalStorage entry does exist. 1 day(s): IDB entry does exist. -30 day(s): Client-side cookie exists. -30 day(s): Client-side persistent cookie exists. -30 day(s): HttpOnly cookie exists. -30 day(s): Regular server-side cookie exists. -30 day(s): LocalStorage entry does not exist. -30 day(s): IDB entry does not exist. +400 day(s): Client-side cookie exists. +400 day(s): Client-side persistent cookie exists. +400 day(s): HttpOnly cookie exists. +400 day(s): Regular server-side cookie exists. +400 day(s): LocalStorage entry does not exist. +400 day(s): IDB entry does not exist. Resource load statistics: diff --git a/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp b/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp index 0444e7e99d9db..2dd8b9e90efdb 100644 --- a/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp +++ b/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp @@ -69,8 +69,10 @@ using namespace WebCore; #define ITP_RELEASE_LOG_DATABASE_ERROR(fmt, ...) RELEASE_LOG_ERROR(ResourceLoadStatistics, "%p - [sessionID=%" PRIu64 ", error=%d, message=%" PRIVATE_LOG_STRING "] - ResourceLoadStatisticsStore::" fmt, this, m_sessionID.toUInt64(), m_database.lastError(), m_database.lastErrorMsg(), ##__VA_ARGS__) -constexpr unsigned operatingDatesWindowLong { 30 }; // days -constexpr unsigned operatingDatesWindowShort { 7 }; // days +constexpr unsigned operatingDatesWindowPrevalentDomain { 30 }; // days + +constexpr unsigned operatingDatesWindowScriptWrittenStorageShort { 7 }; // days +constexpr unsigned operatingDatesWindowScriptWrittenStorageLong { 400 }; // days constexpr Seconds operatingTimeWindowForLiveOnTesting { 1_h }; constexpr Seconds minimumStatisticsProcessingInterval { 5_s }; @@ -440,22 +442,25 @@ void ResourceLoadStatisticsStore::removeDataRecords(CompletionHandler&& }); } -void ResourceLoadStatisticsStore::processStatisticsAndDataRecords() +void ResourceLoadStatisticsStore::processStatisticsAndDataRecords(CompletionHandler&& completionHandler) { ASSERT(!RunLoop::isMain()); if (m_parameters.shouldClassifyResourcesBeforeDataRecordsRemoval) classifyPrevalentResources(); - removeDataRecords([weakThis = WeakPtr { *this }] () mutable { + removeDataRecords([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable { ASSERT(!RunLoop::isMain()); RefPtr protectedThis = weakThis.get(); - if (!protectedThis) + if (!protectedThis) { + completionHandler(); return; + } protectedThis->pruneStatisticsIfNeeded(); protectedThis->logTestingEvent("Storage Synced"_s); + completionHandler(); }); } @@ -539,7 +544,7 @@ void ResourceLoadStatisticsStore::scheduleStatisticsProcessingRequestIfNecessary } protectedThis->updateCookieBlocking([]() { }); - protectedThis->processStatisticsAndDataRecords(); + protectedThis->processStatisticsAndDataRecords([]() { }); }); } @@ -672,8 +677,9 @@ void ResourceLoadStatisticsStore::resetParametersToDefaultValues() m_appBoundDomains.clear(); m_timeAdvanceForTesting = { }; m_operatingDatesSize = 0; - m_shortWindowOperatingDate = std::nullopt; - m_longWindowOperatingDate = std::nullopt; + m_longWindowOperatingDatePrevalentDomain = std::nullopt; + m_shortWindowOperatingDateScriptWritten = std::nullopt; + m_longWindowOperatingDateScriptWritten = std::nullopt; } void ResourceLoadStatisticsStore::logTestingEvent(String&& event) @@ -1781,7 +1787,7 @@ void ResourceLoadStatisticsStore::grantStorageAccess(SubFrameDomain&& subFrameDo ASSERT(subFrameStatus.first == AddedRecord::No); #if ASSERT_ENABLED if (canRequestStorageAccessWithoutUserInteraction == CanRequestStorageAccessWithoutUserInteraction::No) - ASSERT(protectedThis->hasHadUserInteraction(subFrameDomain, OperatingDatesWindow::Long)); + ASSERT(protectedThis->hasHadUserInteraction(subFrameDomain, OperatingDatesWindow::LongScriptWritten)); #endif protectedThis->insertDomainRelationshipList(storageAccessUnderTopFrameDomainsQuery, HashSet({ topFrameDomain }), *subFrameStatus.second); } @@ -1838,7 +1844,7 @@ void ResourceLoadStatisticsStore::grantStorageAccessInternal(SubFrameDomain&& su ASSERT(subFrameStatus.first == AddedRecord::No); #if ASSERT_ENABLED if (canRequestStorageAccessWithoutUserInteraction == CanRequestStorageAccessWithoutUserInteraction::No) - ASSERT(hasHadUserInteraction(subFrameDomain, OperatingDatesWindow::Long)); + ASSERT(hasHadUserInteraction(subFrameDomain, OperatingDatesWindow::LongScriptWritten)); #endif ASSERT(hasUserGrantedStorageAccessThroughPrompt(*subFrameStatus.second, topFrameDomain) == StorageAccessPromptWasShown::Yes); #endif @@ -2029,7 +2035,7 @@ void ResourceLoadStatisticsStore::logUserInteraction(const TopFrameDomain& domai if (!ensureResourceStatisticsForRegistrableDomain(domain, "logUserInteraction"_s).second) return completionHandler(); - bool didHavePreviousUserInteraction = hasHadUserInteraction(domain, OperatingDatesWindow::Long); + bool didHavePreviousUserInteraction = hasHadUserInteraction(domain, OperatingDatesWindow::LongScriptWritten); setUserInteraction(domain, true, nowTime(m_timeAdvanceForTesting)); if (didHavePreviousUserInteraction) { @@ -2552,7 +2558,8 @@ bool ResourceLoadStatisticsStore::areAllUnpartitionedThirdPartyCookiesBlockedUnd #endif return true; - if (thirdPartyCookieBlockingMode() == ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction && !hasHadUserInteraction(topFrameDomain, OperatingDatesWindow::Long)) + auto window = isPrevalentResource(topFrameDomain) ? OperatingDatesWindow::LongPrevalent : OperatingDatesWindow::LongScriptWritten; + if (thirdPartyCookieBlockingMode() == ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction && !hasHadUserInteraction(topFrameDomain, window)) return true; return false; @@ -2740,7 +2747,7 @@ void ResourceLoadStatisticsStore::clearGrandfathering(Vector&& domainI bool ResourceLoadStatisticsStore::hasHadRecentWebPushInteraction(const DomainData& resourceStatistic) const { - return resourceStatistic.mostRecentWebPushInteractionTime && !hasStatisticsExpired(resourceStatistic.mostRecentWebPushInteractionTime, OperatingDatesWindow::Long); + return resourceStatistic.mostRecentWebPushInteractionTime && !hasStatisticsExpired(resourceStatistic.mostRecentWebPushInteractionTime, OperatingDatesWindow::LongScriptWritten); } bool ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction(const DomainData& resourceStatistic, OperatingDatesWindow operatingDatesWindow) @@ -2748,7 +2755,7 @@ bool ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction(const Dom if (resourceStatistic.hadUserInteraction && hasStatisticsExpired(resourceStatistic.mostRecentUserInteractionTime, operatingDatesWindow)) { // Drop privacy sensitive data if we no longer need it. - if (operatingDatesWindow == OperatingDatesWindow::Long) + if (operatingDatesWindow == OperatingDatesWindow::LongScriptWritten) clearUserInteraction(resourceStatistic.registrableDomain, [] { }); return false; @@ -2759,7 +2766,7 @@ bool ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction(const Dom bool ResourceLoadStatisticsStore::shouldRemoveAllWebsiteDataFor(const DomainData& resourceStatistic, bool shouldCheckForGrandfathering) { - return isPrevalentResource(resourceStatistic.registrableDomain) && !hasHadUnexpiredRecentUserInteraction(resourceStatistic, OperatingDatesWindow::Long) && (!shouldCheckForGrandfathering || !resourceStatistic.grandfathered); + return isPrevalentResource(resourceStatistic.registrableDomain) && !hasHadUnexpiredRecentUserInteraction(resourceStatistic, OperatingDatesWindow::LongPrevalent) && (!shouldCheckForGrandfathering || !resourceStatistic.grandfathered); } bool ResourceLoadStatisticsStore::shouldRemoveAllButCookiesFor(const DomainData& resourceStatistic, bool shouldCheckForGrandfathering) @@ -2772,7 +2779,7 @@ bool ResourceLoadStatisticsStore::shouldRemoveAllButCookiesFor(const DomainData& case FirstPartyWebsiteDataRemovalMode::AllButCookies: [[fallthrough]]; case FirstPartyWebsiteDataRemovalMode::None: - window = resourceStatistic.dataRemovalFrequency == DataRemovalFrequency::Short ? OperatingDatesWindow::Short : OperatingDatesWindow::Long; + window = resourceStatistic.dataRemovalFrequency == DataRemovalFrequency::Short ? OperatingDatesWindow::ShortScriptWritten : OperatingDatesWindow::LongScriptWritten; break; case FirstPartyWebsiteDataRemovalMode::AllButCookiesLiveOnTestingTimeout: window = OperatingDatesWindow::ForLiveOnTesting; @@ -3220,8 +3227,9 @@ void ResourceLoadStatisticsStore::updateOperatingDatesParameters() } }; - updateWindowOperatingDate(m_shortWindowOperatingDate, operatingDatesWindowShort); - updateWindowOperatingDate(m_longWindowOperatingDate, operatingDatesWindowLong); + updateWindowOperatingDate(m_shortWindowOperatingDateScriptWritten, operatingDatesWindowScriptWrittenStorageShort); + updateWindowOperatingDate(m_longWindowOperatingDateScriptWritten, operatingDatesWindowScriptWrittenStorageLong); + updateWindowOperatingDate(m_longWindowOperatingDatePrevalentDomain, operatingDatesWindowPrevalentDomain); } void ResourceLoadStatisticsStore::includeTodayAsOperatingDateIfNecessary() @@ -3237,7 +3245,7 @@ void ResourceLoadStatisticsStore::includeTodayAsOperatingDateIfNecessary() auto transactionScope = beginTransactionIfNecessary(); - int rowsToPrune = m_operatingDatesSize - operatingDatesWindowLong + 1; + int rowsToPrune = m_operatingDatesSize - operatingDatesWindowPrevalentDomain + 1; if (rowsToPrune > 0) { auto deleteLeastRecentOperatingDateStatement = m_database.prepareStatement("DELETE FROM OperatingDates ORDER BY year, month, monthDay LIMIT ?;"_s); if (!deleteLeastRecentOperatingDateStatement @@ -3266,12 +3274,16 @@ bool ResourceLoadStatisticsStore::hasStatisticsExpired(WallTime mostRecentUserIn ASSERT(!RunLoop::isMain()); switch (operatingDatesWindow) { - case OperatingDatesWindow::Long: - if (m_longWindowOperatingDate && OperatingDate::fromWallTime(mostRecentUserInteractionTime) < *m_longWindowOperatingDate) + case OperatingDatesWindow::LongPrevalent: + if (m_longWindowOperatingDatePrevalentDomain && OperatingDate::fromWallTime(mostRecentUserInteractionTime) < *m_longWindowOperatingDatePrevalentDomain) + return true; + break; + case OperatingDatesWindow::LongScriptWritten: + if (m_longWindowOperatingDateScriptWritten && OperatingDate::fromWallTime(mostRecentUserInteractionTime) < *m_longWindowOperatingDateScriptWritten) return true; break; - case OperatingDatesWindow::Short: - if (m_shortWindowOperatingDate && OperatingDate::fromWallTime(mostRecentUserInteractionTime) < *m_shortWindowOperatingDate) + case OperatingDatesWindow::ShortScriptWritten: + if (m_shortWindowOperatingDateScriptWritten && OperatingDate::fromWallTime(mostRecentUserInteractionTime) < *m_shortWindowOperatingDateScriptWritten) return true; break; case OperatingDatesWindow::ForLiveOnTesting: diff --git a/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h b/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h index d8916271c0edb..ee300e9e79d84 100644 --- a/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h +++ b/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h @@ -80,7 +80,7 @@ class OperatingDate { int m_monthDay { 0 }; // [1, 31]. }; -enum class OperatingDatesWindow : uint8_t { Long, Short, ForLiveOnTesting, ForReproTesting }; +enum class OperatingDatesWindow : uint8_t { LongPrevalent, ShortScriptWritten, LongScriptWritten, ForLiveOnTesting, ForReproTesting }; enum class CookieAccess : uint8_t { CannotRequest, BasedOnCookiePolicy, OnlyIfGranted }; enum class CanRequestStorageAccessWithoutUserInteraction : bool { No, Yes }; enum class DataRemovalFrequency : uint8_t { Never, Short, Long }; @@ -113,7 +113,7 @@ class ResourceLoadStatisticsStore final : public RefCountedAndCanMakeWeakPtr aggregatedThirdPartyData() const; void updateCookieBlocking(CompletionHandler&&); - void processStatisticsAndDataRecords(); + void processStatisticsAndDataRecords(CompletionHandler&&); void cancelPendingStatisticsProcessingRequest(); void mergeStatistics(Vector&&); void runIncrementalVacuumCommand(); @@ -412,8 +412,9 @@ class ResourceLoadStatisticsStore final : public RefCountedAndCanMakeWeakPtr m_longWindowOperatingDate; - std::optional m_shortWindowOperatingDate; + std::optional m_longWindowOperatingDatePrevalentDomain; + std::optional m_shortWindowOperatingDateScriptWritten; + std::optional m_longWindowOperatingDateScriptWritten; OperatingDate m_mostRecentOperatingDate; WebCore::ThirdPartyCookieBlockingMode m_thirdPartyCookieBlockingMode { WebCore::ThirdPartyCookieBlockingMode::All }; WebCore::SameSiteStrictEnforcementEnabled m_sameSiteStrictEnforcementEnabled { WebCore::SameSiteStrictEnforcementEnabled::No }; diff --git a/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp b/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp index f9f4713af51d2..32997b4ce1866 100644 --- a/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp +++ b/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp @@ -265,9 +265,14 @@ void WebResourceLoadStatisticsStore::scheduleStatisticsAndDataRecordsProcessing( ASSERT(RunLoop::isMain()); postTask([completionHandler = WTFMove(completionHandler)](auto& store) mutable { - if (RefPtr statisticsStore = store.m_statisticsStore) - statisticsStore->processStatisticsAndDataRecords(); - postTaskReply(WTFMove(completionHandler)); + if (RefPtr statisticsStore = store.m_statisticsStore) { + statisticsStore->processStatisticsAndDataRecords([weakStore = ThreadSafeWeakPtr { store }, completionHandler = WTFMove(completionHandler)] () mutable { + if (RefPtr store = weakStore.get()) + store->postTaskReply(WTFMove(completionHandler)); + else + completionHandler(); + }); + } }); } @@ -314,7 +319,7 @@ void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(VectorlogTestingEvent("Statistics Updated"_s); }); }); - statisticsStore->processStatisticsAndDataRecords(); + statisticsStore->processStatisticsAndDataRecords([] { }); }); } @@ -882,7 +887,7 @@ void WebResourceLoadStatisticsStore::hasHadUserInteraction(RegistrableDomain&& d return hasHadUserInteractionEphemeral(domain, WTFMove(completionHandler)); postTask([domain = WTFMove(domain).isolatedCopy(), completionHandler = WTFMove(completionHandler)](auto& store) mutable { - bool hadUserInteraction = store.m_statisticsStore ? RefPtr { store.m_statisticsStore }->hasHadUserInteraction(domain, OperatingDatesWindow::Long) : false; + bool hadUserInteraction = store.m_statisticsStore ? RefPtr { store.m_statisticsStore }->hasHadUserInteraction(domain, OperatingDatesWindow::LongScriptWritten) : false; postTaskReply([hadUserInteraction, completionHandler = WTFMove(completionHandler)]() mutable { completionHandler(hadUserInteraction); });