Skip to content

Commit 75a9cce

Browse files
magomezspenap
authored andcommitted
Add a property to WebKitWebsiteDataManager to set the LocalStorage quota.
1 parent c7fd248 commit 75a9cce

19 files changed

Lines changed: 71 additions & 15 deletions

Source/WebCore/page/Settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ LocalStorageDatabasePath:
256256
WebCore:
257257
default: '{ }'
258258

259+
LocalStorageQuota:
260+
type: uint32_t
261+
defaultValue:
262+
WebCore:
263+
default: 5242880
264+
259265
MaximumHTMLParserDOMTreeDepth:
260266
type: uint32_t
261267
defaultValue:

Source/WebCore/storage/StorageNamespaceProvider.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
#include "Document.h"
3030
#include "Page.h"
3131
#include "SecurityOriginData.h"
32+
#include "Settings.h"
3233
#include "StorageArea.h"
3334
#include "StorageNamespace.h"
3435

3536
namespace WebCore {
3637

37-
// Suggested by the HTML5 spec.
38-
unsigned localStorageDatabaseQuotaInBytes = 5 * 1024 * 1024;
39-
4038
StorageNamespaceProvider::StorageNamespaceProvider()
4139
{
4240
}
@@ -53,9 +51,9 @@ Ref<StorageArea> StorageNamespaceProvider::localStorageArea(Document& document)
5351

5452
RefPtr<StorageNamespace> storageNamespace;
5553
if (document.canAccessResource(ScriptExecutionContext::ResourceType::LocalStorage) == ScriptExecutionContext::HasResourceAccess::DefaultForThirdParty)
56-
storageNamespace = transientLocalStorageNamespace(document.topOrigin(), document.page()->sessionID());
54+
storageNamespace = transientLocalStorageNamespace(document.topOrigin(), document.page()->settings().localStorageQuota(), document.page()->sessionID());
5755
else
58-
storageNamespace = localStorageNamespace(document.page()->sessionID());
56+
storageNamespace = localStorageNamespace(document.page()->settings().localStorageQuota(), document.page()->sessionID());
5957

6058
return storageNamespace->storageArea(document.securityOrigin());
6159
}
@@ -69,20 +67,20 @@ Ref<StorageArea> StorageNamespaceProvider::sessionStorageArea(Document& document
6967
return sessionStorageNamespace(document.topOrigin(), *document.page())->storageArea(document.securityOrigin());
7068
}
7169

72-
StorageNamespace& StorageNamespaceProvider::localStorageNamespace(PAL::SessionID sessionID)
70+
StorageNamespace& StorageNamespaceProvider::localStorageNamespace(unsigned quota, PAL::SessionID sessionID)
7371
{
7472
if (!m_localStorageNamespace)
75-
m_localStorageNamespace = createLocalStorageNamespace(localStorageDatabaseQuotaInBytes, sessionID);
73+
m_localStorageNamespace = createLocalStorageNamespace(quota, sessionID);
7674

7775
ASSERT(m_localStorageNamespace->sessionID() == sessionID);
7876
return *m_localStorageNamespace;
7977
}
8078

81-
StorageNamespace& StorageNamespaceProvider::transientLocalStorageNamespace(SecurityOrigin& securityOrigin, PAL::SessionID sessionID)
79+
StorageNamespace& StorageNamespaceProvider::transientLocalStorageNamespace(SecurityOrigin& securityOrigin, unsigned quota, PAL::SessionID sessionID)
8280
{
8381
auto& slot = m_transientLocalStorageNamespaces.add(securityOrigin.data(), nullptr).iterator->value;
8482
if (!slot)
85-
slot = createTransientLocalStorageNamespace(securityOrigin, localStorageDatabaseQuotaInBytes, sessionID);
83+
slot = createTransientLocalStorageNamespace(securityOrigin, quota, sessionID);
8684

8785
ASSERT(slot->sessionID() == sessionID);
8886
return *slot;

Source/WebCore/storage/StorageNamespaceProvider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class StorageNamespaceProvider : public RefCounted<StorageNamespaceProvider> {
6363

6464
private:
6565
friend class Internals;
66-
WEBCORE_EXPORT StorageNamespace& localStorageNamespace(PAL::SessionID);
67-
StorageNamespace& transientLocalStorageNamespace(SecurityOrigin&, PAL::SessionID);
66+
WEBCORE_EXPORT StorageNamespace& localStorageNamespace(unsigned quota, PAL::SessionID);
67+
StorageNamespace& transientLocalStorageNamespace(SecurityOrigin&, unsigned quota, PAL::SessionID);
6868

6969
virtual Ref<StorageNamespace> createLocalStorageNamespace(unsigned quota, PAL::SessionID) = 0;
7070
virtual Ref<StorageNamespace> createTransientLocalStorageNamespace(SecurityOrigin&, unsigned quota, PAL::SessionID) = 0;

Source/WebCore/testing/Internals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3195,7 +3195,7 @@ uint64_t Internals::storageAreaMapCount() const
31953195
if (!page)
31963196
return 0;
31973197

3198-
return page->storageNamespaceProvider().localStorageNamespace(page->sessionID()).storageAreaMapCountForTesting();
3198+
return page->storageNamespaceProvider().localStorageNamespace(page->settings().localStorageQuota(), page->sessionID()).storageAreaMapCountForTesting();
31993199
}
32003200

32013201
uint64_t Internals::elementIdentifier(Element& element) const

Source/WebKit/NetworkProcess/NetworkProcess.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ class NetworkProcess final : public AuxiliaryProcess, private DownloadManager::C
444444
void setEmulatedConditions(PAL::SessionID, std::optional<int64_t>&& bytesPerSecondLimit);
445445
#endif
446446

447+
#if USE(SOUP)
448+
static unsigned localStorageQuota() { return s_localStorageQuota; }
449+
#endif
450+
447451
void deleteWebsiteDataForOrigin(PAL::SessionID, OptionSet<WebsiteDataType>, const WebCore::ClientOrigin&, CompletionHandler<void()>&&);
448452
void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostnames, const Vector<RegistrableDomain>&, CompletionHandler<void()>&&);
449453

@@ -657,6 +661,10 @@ class NetworkProcess final : public AuxiliaryProcess, private DownloadManager::C
657661
CompletionHandler<void()> completionHandler;
658662
};
659663
HashMap<TaskIdentifier, DeleteWebsiteDataTask> m_deleteWebsiteDataTasks;
664+
665+
#if USE(SOUP)
666+
static unsigned s_localStorageQuota;
667+
#endif
660668
};
661669

662670
#if !PLATFORM(COCOA)

Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct NetworkProcessCreationParameters {
6666
WebCore::HTTPCookieAcceptPolicy cookieAcceptPolicy { WebCore::HTTPCookieAcceptPolicy::AlwaysAccept };
6767
Vector<String> languages;
6868
std::optional<MemoryPressureHandler::Configuration> memoryPressureHandlerConfiguration;
69+
uint32_t localStorageQuota;
6970
#endif
7071

7172
Vector<String> urlSchemesRegisteredAsSecure;

Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.serialization.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ headers: "NetworkProcessCreationParameters.h" "AuxiliaryProcessCreationParameter
4444
WebCore::HTTPCookieAcceptPolicy cookieAcceptPolicy
4545
Vector<String> languages
4646
std::optional<MemoryPressureHandler::Configuration> memoryPressureHandlerConfiguration
47+
uint32_t localStorageQuota
4748
#endif
4849

4950
Vector<String> urlSchemesRegisteredAsSecure

Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
namespace WebKit {
5151
using namespace WebCore;
5252

53+
unsigned NetworkProcess::s_localStorageQuota = 5 * MB;
54+
5355
static CString buildAcceptLanguages(const Vector<String>& languages)
5456
{
5557
size_t languagesCount = languages.size();
@@ -155,6 +157,8 @@ void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreati
155157
});
156158
}
157159
#endif
160+
161+
s_localStorageQuota = parameters.localStorageQuota;
158162
}
159163

160164
void NetworkProcess::setIgnoreTLSErrors(PAL::SessionID sessionID, bool ignoreTLSErrors)

Source/WebKit/NetworkProcess/storage/LocalStorageManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "LocalStorageManager.h"
2828

2929
#include "MemoryStorageArea.h"
30+
#include "NetworkProcess.h"
3031
#include "SQLiteStorageArea.h"
3132
#include "StorageAreaRegistry.h"
3233
#include <WebCore/SecurityOriginData.h>
@@ -36,8 +37,6 @@
3637

3738
namespace WebKit {
3839

39-
// Suggested by https://www.w3.org/TR/webstorage/#disk-space
40-
constexpr unsigned localStorageQuotaInBytes = 5 * MB;
4140
constexpr auto s_fileSuffix = ".localstorage"_s;
4241
constexpr auto s_fileName = "localstorage.sqlite3"_s;
4342

@@ -198,7 +197,7 @@ StorageAreaBase& LocalStorageManager::ensureLocalStorageArea(const WebCore::Clie
198197
if (!m_localStorageArea) {
199198
RefPtr<StorageAreaBase> storage;
200199
if (!m_path.isEmpty())
201-
storage = SQLiteStorageArea::create(localStorageQuotaInBytes, origin, m_path, WTFMove(workQueue));
200+
storage = SQLiteStorageArea::create(NetworkProcess::localStorageQuota(), origin, m_path, WTFMove(workQueue));
202201
else
203202
storage = MemoryStorageArea::create(origin, StorageAreaBase::StorageType::Local);
204203

Source/WebKit/Shared/WebPageCreationParameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ struct WebPageCreationParameters {
316316

317317
std::optional<RemotePageParameters> remotePageParameters { };
318318
std::optional<ProvisionalFrameCreationParameters> provisionalFrameCreationParameters { };
319+
uint32_t localStorageQuota;
319320
WebCore::FrameIdentifier mainFrameIdentifier;
320321
String openedMainFrameName;
321322
std::optional<WebCore::FrameIdentifier> mainFrameOpenerIdentifier { };

0 commit comments

Comments
 (0)