Skip to content
Permalink
Browse files
Clear-Site-Data: "cache" HTTP header should clear the back/forward …
…cache

https://bugs.webkit.org/show_bug.cgi?id=245553

Reviewed by Brent Fulgham.

`Clear-Site-Data: "cache"` was clearing the HTTP disk cache and the memory cache
entries for the HTTP response origin. In addition to this, it now clear the
back/forward cache entries for this origin too.

* LayoutTests/http/tests/clear-site-data/bfcache-expected.txt: Added.
* LayoutTests/http/tests/clear-site-data/bfcache.html: Added.
* LayoutTests/http/tests/clear-site-data/resources/clear-site-data-and-navigate-back.html: Added.
* LayoutTests/http/tests/clear-site-data/resources/clear-site-data-cache.py: Added.
Add test coverage.

* Source/WebCore/history/BackForwardCache.cpp:
(WebCore::BackForwardCache::clearEntriesForOrigins):
* Source/WebCore/history/BackForwardCache.h:

* Source/WebKit/WebProcess/WebProcess.cpp:
(WebKit::WebProcess::deleteWebsiteDataForOrigins):
Clear the back/forward cache too when we're asked to clear the memory cache. This matches the
behavior of WebProcess::deleteWebsiteData() where clearing the memory cache implies clearing
the back/forward cache too.

Canonical link: https://commits.webkit.org/254798@main
  • Loading branch information
cdumez committed Sep 23, 2022
1 parent 9a9ffd4 commit 5e99c8f621c3966f7de0b5d4c407c26d458bbed1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 0 deletions.
@@ -0,0 +1,11 @@
Tests that the Clear-Site-Data can be used to clear the back/forward cache.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


pageshow - not from cache
PASS wasRestoredFromPageCache is false
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,30 @@
<!-- webkit-test-runner [ UsesBackForwardCache=true ] -->
<!DOCTYPE html>
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
description("Tests that the Clear-Site-Data can be used to clear the back/forward cache.");
jsTestIsAsync = true;

addEventListener("pageshow", function(event) {
debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");

if (!window.sessionStorage.page_cache_clear_site_data_test_started)
return;

wasRestoredFromPageCache = event.persisted;
shouldBeFalse("wasRestoredFromPageCache");
finishJSTest();
});

onload = () => {
if (sessionStorage.page_cache_clear_site_data_test_started)
return;
setTimeout(() => {
sessionStorage.page_cache_clear_site_data_test_started = true;
location.href = "resources/clear-site-data-and-navigate-back.html";
}, 0);
};
</script>
</html>
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body>
<script>
window.addEventListener("load", function() {
fetch("clear-site-data-cache.py").then((r) => {
history.back();
});
});
</script>
</body>
</html>
@@ -0,0 +1,10 @@
#!/usr/bin/env python3

import sys

sys.stdout.write(
'Clear-Site-Data: "cache"\r\n'
'Content-Type: text/html\r\n\r\n'
)

print('FOO')
@@ -71,6 +71,7 @@ media/audio-session-category-at-most-recent-playback.html [ Skip ]

# No support for the Clear-Site-Data header in WebKit1.
imported/w3c/web-platform-tests/clear-site-data [ Skip ]
http/tests/clear-site-data [ Skip ]

# Shared workers are only implemented for WebKit2.
http/tests/navigation/page-cache-shared-worker.html [ Skip ]
@@ -139,6 +139,7 @@ http/tests/model [ Skip ]

# No support for the Clear-Site-Data header in WebKit1.
imported/w3c/web-platform-tests/clear-site-data [ Skip ]
http/tests/clear-site-data [ Skip ]

# color-filters are off by default
webkit.org/b/185076 css3/color-filters [ Skip ]
@@ -47,6 +47,7 @@
#include "Page.h"
#include "Quirks.h"
#include "ScriptDisallowedScope.h"
#include "SecurityOriginHash.h"
#include "Settings.h"
#include "SubframeLoader.h"
#include <pal/Logging.h>
@@ -576,4 +577,19 @@ void BackForwardCache::prune(PruningReason pruningReason)
}
}

void BackForwardCache::clearEntriesForOrigins(const HashSet<RefPtr<SecurityOrigin>>& origins)
{
for (auto it = m_items.begin(); it != m_items.end();) {
// Increment iterator first so it stays valid after the removal.
auto current = it;
++it;
auto itemOrigin = SecurityOrigin::create((*current)->url());
if (origins.contains(itemOrigin.ptr())) {
RELEASE_LOG(BackForwardCache, "BackForwardCache::clearEntriesForOrigins removing item: %s, size: %u / %u", (*current)->identifier().string().utf8().data(), pageCount() - 1, maxSize());
(*current)->setCachedPage(nullptr);
m_items.remove(current);
}
}
}

} // namespace WebCore
@@ -60,6 +60,8 @@ class BackForwardCache {

void removeAllItemsForPage(Page&);

WEBCORE_EXPORT void clearEntriesForOrigins(const HashSet<RefPtr<SecurityOrigin>>&);

unsigned pageCount() const { return m_items.size(); }
WEBCORE_EXPORT unsigned frameCount() const;

@@ -1415,6 +1415,7 @@ void WebProcess::deleteWebsiteDataForOrigins(OptionSet<WebsiteDataType> websiteD
origins.add(originData.securityOrigin());

MemoryCache::singleton().removeResourcesWithOrigins(sessionID(), origins);
BackForwardCache::singleton().clearEntriesForOrigins(origins);
}
completionHandler();
}

0 comments on commit 5e99c8f

Please sign in to comment.