Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ITP should hold off longer on deleting website data for domains with …
…WebPush that the user interacts with

https://bugs.webkit.org/show_bug.cgi?id=244609
<rdar://99148432>

Reviewed by Alex Christensen.

* Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::hasHadRecentWebPushInteraction const):
    New convenience function.
(WebKit::ResourceLoadStatisticsDatabaseStore::registrableDomainsToDeleteOrRestrictWebsiteDataFor):
    Now checks hasHadRecentWebPushInteraction() and exempts the domain if true.
* Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
    Updated the ITPCleanup test to cover the new behavior.

Canonical link: https://commits.webkit.org/254048@main
  • Loading branch information
johnwilander authored and achristensen07 committed Sep 1, 2022
1 parent b3e3f37 commit c5e9bfe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Expand Up @@ -2302,6 +2302,11 @@ void ResourceLoadStatisticsDatabaseStore::clearGrandfathering(Vector<unsigned>&&
}
}

bool ResourceLoadStatisticsDatabaseStore::hasHadRecentWebPushInteraction(const DomainData& resourceStatistic) const
{
return resourceStatistic.mostRecentWebPushInteractionTime && !hasStatisticsExpired(resourceStatistic.mostRecentWebPushInteractionTime, OperatingDatesWindow::Long);
}

bool ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction(const DomainData& resourceStatistic, OperatingDatesWindow operatingDatesWindow)
{
if (resourceStatistic.hadUserInteraction && hasStatisticsExpired(resourceStatistic.mostRecentUserInteractionTime, operatingDatesWindow)) {
Expand Down Expand Up @@ -2384,10 +2389,17 @@ RegistrableDomainsToDeleteOrRestrictWebsiteDataFor ResourceLoadStatisticsDatabas
Vector<DomainData> domains = this->domains();
Vector<unsigned> domainIDsToClearGrandfathering;
for (auto& statistic : domains) {
// Domains permanently configured to be exempt. This can be home screen web applications, app-bound domains, or similar.
if (shouldExemptFromWebsiteDataDeletion(statistic.registrableDomain))
continue;

// Domains with WebPush that the user interacts with continuously should keep their data.
if (hasHadRecentWebPushInteraction(statistic))
continue;

if (auto mostRecentUserInteractionTime = this->mostRecentUserInteractionTime(statistic))
oldestUserInteraction = std::min(oldestUserInteraction, *mostRecentUserInteractionTime);

if (shouldRemoveAllWebsiteDataFor(statistic, shouldCheckForGrandfathering)) {
toDeleteOrRestrictFor.domainsToDeleteAllCookiesFor.append(statistic.registrableDomain);
toDeleteOrRestrictFor.domainsToDeleteAllScriptWrittenStorageFor.append(statistic.registrableDomain);
Expand Down
Expand Up @@ -175,6 +175,7 @@ class ResourceLoadStatisticsDatabaseStore final : public ResourceLoadStatisticsS
unsigned topFrameUniqueRedirectsToSinceSameSiteStrictEnforcement;
};
Vector<DomainData> domains() const;
bool hasHadRecentWebPushInteraction(const DomainData&) const;
bool hasHadUnexpiredRecentUserInteraction(const DomainData&, OperatingDatesWindow);
void clearGrandfathering(Vector<unsigned>&&);
WebCore::StorageAccessPromptWasShown hasUserGrantedStorageAccessThroughPrompt(unsigned domainID, const RegistrableDomain&);
Expand Down
6 changes: 3 additions & 3 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm
Expand Up @@ -627,7 +627,7 @@ function log(msg)
auto tempDir = setUpTestWebPushD();
using namespace TestWebKitAPI;

NSError *error;
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtURL:adoptNS([_WKWebsiteDataStoreConfiguration new]).get()._resourceLoadStatisticsDirectory error:&error];
EXPECT_NULL(error);

Expand Down Expand Up @@ -736,9 +736,9 @@ HTTPServer server({
testPush(expectPushAfterITPCleanupToSucceed);
};

// FIXME: This time interval should change when rdar://92694600 is fixed.
runTestWithInterval(3600 * 24 * 0, true);
runTestWithInterval(3600 * 24 * 5, true);
runTestWithInterval(3600 * 24 * 29, true);
runTestWithInterval(3600 * 24 * 31, false);
runTestWithInterval(3600 * 24 * 50, false);
runTestWithInterval(3600 * 24 * 100, false);

Expand Down

0 comments on commit c5e9bfe

Please sign in to comment.