Skip to content
Permalink
Browse files
Clear SessionStorage of a page when the page is destroyed
https://bugs.webkit.org/show_bug.cgi?id=240683

Reviewed by Chris Dumez.

We should not keep SessionStorage items in memory when they will not be accessed any more.

* Source/WebKit/NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::removeWebPageNetworkParameters):
* Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::clearStorageForWebPage):
* Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h:
* Source/WebKit/NetworkProcess/storage/SessionStorageManager.cpp:
(WebKit::SessionStorageManager::removeNamespace):
* Source/WebKit/NetworkProcess/storage/SessionStorageManager.h:

Canonical link: https://commits.webkit.org/250807@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294562 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
szewai committed May 20, 2022
1 parent 618d3e4 commit 57d367573654c88b2d1097b28829021661952154
Showing 5 changed files with 28 additions and 1 deletion.
@@ -2766,8 +2766,10 @@ void NetworkProcess::addWebPageNetworkParameters(PAL::SessionID sessionID, WebPa

void NetworkProcess::removeWebPageNetworkParameters(PAL::SessionID sessionID, WebPageProxyIdentifier pageID)
{
if (auto* session = networkSession(sessionID))
if (auto* session = networkSession(sessionID)) {
session->removeWebPageNetworkParameters(pageID);
session->storageManager().clearStorageForWebPage(pageID);
}
}

void NetworkProcess::countNonDefaultSessionSets(PAL::SessionID sessionID, CompletionHandler<void(size_t)>&& completionHandler)
@@ -319,6 +319,18 @@ void NetworkStorageManager::clearStorageForTesting(CompletionHandler<void()>&& c
});
}

void NetworkStorageManager::clearStorageForWebPage(WebPageProxyIdentifier pageIdentifier)
{
ASSERT(RunLoop::isMain());

m_queue->dispatch([this, protectedThis = Ref { *this }, pageIdentifier]() mutable {
for (auto& manager : m_localOriginStorageManagers.values()) {
if (auto* sessionStorageManager = manager->existingSessionStorageManager())
sessionStorageManager->removeNamespace(makeObjectIdentifier<StorageNamespaceIdentifierType>(pageIdentifier.toUInt64()));
}
});
}

void NetworkStorageManager::didIncreaseQuota(WebCore::ClientOrigin&& origin, QuotaIncreaseRequestIdentifier identifier, std::optional<uint64_t> newQuota)
{
ASSERT(RunLoop::isMain());
@@ -32,6 +32,7 @@
#include "StorageAreaImplIdentifier.h"
#include "StorageAreaMapIdentifier.h"
#include "StorageNamespaceIdentifier.h"
#include "WebPageProxyIdentifier.h"
#include "WebsiteData.h"
#include <WebCore/ClientOrigin.h>
#include <WebCore/FileSystemHandleIdentifier.h>
@@ -80,6 +81,7 @@ class NetworkStorageManager final : public IPC::Connection::WorkQueueMessageRece
PAL::SessionID sessionID() const { return m_sessionID; }
void close();
void clearStorageForTesting(CompletionHandler<void()>&&);
void clearStorageForWebPage(WebPageProxyIdentifier);
void didIncreaseQuota(WebCore::ClientOrigin&&, QuotaIncreaseRequestIdentifier, std::optional<uint64_t> newQuota);
void fetchData(OptionSet<WebsiteDataType>, CompletionHandler<void(Vector<WebsiteData::Entry>&&)>&&);
void deleteData(OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>&, CompletionHandler<void()>&&);
@@ -62,6 +62,16 @@ void SessionStorageManager::connectionClosed(IPC::Connection::UniqueID connectio
storageArea->removeListener(connection);
}

void SessionStorageManager::removeNamespace(StorageNamespaceIdentifier namespaceIdentifier)
{
auto identifier = m_storageAreasByNamespace.take(namespaceIdentifier);
if (!identifier.isValid())
return;

m_storageAreas.remove(identifier);
m_registry.unregisterStorageArea(identifier);
}

StorageAreaIdentifier SessionStorageManager::addStorageArea(std::unique_ptr<MemoryStorageArea> storageArea, StorageNamespaceIdentifier namespaceIdentifier)
{
auto identifier = storageArea->identifier();
@@ -47,6 +47,7 @@ class SessionStorageManager {
bool hasDataInMemory() const;
void clearData();
void connectionClosed(IPC::Connection::UniqueID);
void removeNamespace(StorageNamespaceIdentifier);

StorageAreaIdentifier connectToSessionStorageArea(IPC::Connection::UniqueID, StorageAreaMapIdentifier, const WebCore::ClientOrigin&, StorageNamespaceIdentifier);
void cancelConnectToSessionStorageArea(IPC::Connection::UniqueID, StorageNamespaceIdentifier);

0 comments on commit 57d3675

Please sign in to comment.