Diff
Modified: trunk/Source/WebKit/ChangeLog (289877 => 289878)
--- trunk/Source/WebKit/ChangeLog 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/ChangeLog 2022-02-16 06:48:03 UTC (rev 289878)
@@ -1,3 +1,68 @@
+2022-02-15 Sihui Liu <[email protected]>
+
+ Migrate IndexedDB and LocalStorage data to GeneralStorageDirectory
+ https://bugs.webkit.org/show_bug.cgi?id=236611
+
+ Reviewed by Chris Dumez.
+
+ Reviewed by Chris Dumez.
+
+ Add a new parameter shouldUseCustomStoragePaths on WebsiteDataStoreConfiguration to specify whether WebKit
+ should use custom storage paths. If the value is true, WebKit will keep using the custom localStorageDirectory
+ and indexedDBDatabaseDirectory paths as it is now. If the value is false, WebKit will migrate data from
+ localStorageDirectory and indexedDBDatabaseDirectory to new paths set by WebKit under generalStorageDirectory.
+
+ API test: WebKit.MigrateLocalStorageDataToGeneralStorageDirectory
+ WebKit.MigrateIndexedDBDataToGeneralStorageDirectory
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::NetworkProcess::addWebsiteDataStore):
+ * NetworkProcess/NetworkSession.cpp:
+ (WebKit::NetworkSession::addStorageManagerSession):
+ * NetworkProcess/NetworkSession.h:
+ * NetworkProcess/storage/LocalStorageManager.cpp:
+ (WebKit::LocalStorageManager::localStorageFilePath):
+ * NetworkProcess/storage/LocalStorageManager.h:
+ * NetworkProcess/storage/NetworkStorageManager.cpp:
+ (WebKit::NetworkStorageManager::create):
+ (WebKit::NetworkStorageManager::NetworkStorageManager):
+ (WebKit::originDirectoryPath):
+ (WebKit::originFilePath):
+ (WebKit::NetworkStorageManager::localOriginStorageManager):
+ * NetworkProcess/storage/NetworkStorageManager.h:
+ * NetworkProcess/storage/OriginStorageManager.cpp:
+ (WebKit::OriginStorageManager::StorageBucket::StorageBucket):
+ (WebKit::OriginStorageManager::StorageBucket::localStorageManager):
+ (WebKit::OriginStorageManager::StorageBucket::idbStorageManager):
+ (WebKit::OriginStorageManager::StorageBucket::isEmpty):
+ (WebKit::OriginStorageManager::StorageBucket::moveData):
+ (WebKit::OriginStorageManager::StorageBucket::resolvedIDBStoragePath):
+ (WebKit::OriginStorageManager::StorageBucket::fetchDataTypesInListFromDisk):
+ (WebKit::OriginStorageManager::StorageBucket::deleteLocalStorageData):
+ (WebKit::OriginStorageManager::StorageBucket::deleteIDBStorageData):
+ (WebKit::OriginStorageManager::StorageBucket::resolvedLocalStoragePath):
+ (WebKit::OriginStorageManager::originFileIdentifier):
+ (WebKit::OriginStorageManager::OriginStorageManager):
+ (WebKit::OriginStorageManager::defaultBucket):
+ (WebKit::OriginStorageManager::quotaManager):
+ (WebKit::OriginStorageManager::StorageBucket::isEmpty const): Deleted.
+ * NetworkProcess/storage/OriginStorageManager.h:
+ * Shared/WebsiteDataStoreParameters.cpp:
+ (WebKit::WebsiteDataStoreParameters::encode const):
+ (WebKit::WebsiteDataStoreParameters::decode):
+ * Shared/WebsiteDataStoreParameters.h:
+ * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
+ * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
+ (-[_WKWebsiteDataStoreConfiguration shouldUseCustomStoragePaths]):
+ (-[_WKWebsiteDataStoreConfiguration setShouldUseCustomStoragePaths:]):
+ * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+ (WebKit::WebsiteDataStore::parameters):
+ * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
+ (WebKit::WebsiteDataStoreConfiguration::copy const):
+ * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
+ (WebKit::WebsiteDataStoreConfiguration::shouldUseCustomStoragePaths const):
+ (WebKit::WebsiteDataStoreConfiguration::setShouldUseCustomStoragePaths):
+
2022-02-15 Patrick Angle <[email protected]>
Web Inspector: [Cocoa] Reentrancy in WebKit::WebInspectorUIProxy::open
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -403,7 +403,8 @@
addSessionStorageQuotaManager(sessionID, parameters.perOriginStorageQuota, parameters.perThirdPartyOriginStorageQuota, parameters.cacheStorageDirectory, parameters.cacheStorageDirectoryExtensionHandle);
if (auto* session = networkSession(sessionID)) {
- session->addStorageManagerSession(parameters.generalStorageDirectory, parameters.generalStorageDirectoryHandle, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle, parameters.indexedDatabaseDirectory, parameters.indexedDatabaseDirectoryExtensionHandle, parameters.cacheStorageDirectory, parameters.perOriginStorageQuota, parameters.perThirdPartyOriginStorageQuota);
+ session->addStorageManagerSession(parameters.generalStorageDirectory, parameters.generalStorageDirectoryHandle, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle, parameters.indexedDatabaseDirectory, parameters.indexedDatabaseDirectoryExtensionHandle, parameters.cacheStorageDirectory, parameters.perOriginStorageQuota, parameters.perThirdPartyOriginStorageQuota, parameters.shouldUseCustomStoragePaths);
+
#if ENABLE(SERVICE_WORKER)
session->addServiceWorkerSession(parameters.serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
#endif
Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -659,7 +659,7 @@
return *m_sharedWorkerServer;
}
-void NetworkSession::addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle, const String& idbStoragePath, SandboxExtension::Handle& idbStoragePathHandle, const String& cacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyQuota)
+void NetworkSession::addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle, const String& idbStoragePath, SandboxExtension::Handle& idbStoragePathHandle, const String& cacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyQuota, bool shouldUseCustomStoragePaths)
{
if (m_storageManager)
return;
@@ -670,7 +670,7 @@
IPC::Connection::UniqueID connectionID;
if (auto* connection = networkProcess().parentProcessConnection())
connectionID = connection->uniqueID();
- m_storageManager = NetworkStorageManager::create(sessionID(), connectionID, generalStoragePath, localStoragePath, idbStoragePath, cacheStoragePath, defaultOriginQuota, defaultThirdPartyQuota);
+ m_storageManager = NetworkStorageManager::create(sessionID(), connectionID, generalStoragePath, localStoragePath, idbStoragePath, cacheStoragePath, defaultOriginQuota, defaultThirdPartyQuota, shouldUseCustomStoragePaths);
}
void NetworkSession::ensureCacheEngine(Function<void(CacheStorage::Engine&)>&& callback)
Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.h (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/NetworkSession.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -215,7 +215,7 @@
WebSharedWorkerServer& ensureSharedWorkerServer();
NetworkStorageManager* storageManager() { return m_storageManager.get(); }
- void addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle, const String& idbStoragePath, SandboxExtension::Handle& idbStoragePathHandle, const String& cacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyQuota);
+ void addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle, const String& idbStoragePath, SandboxExtension::Handle& idbStoragePathHandle, const String& cacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyQuota, bool shouldUseCustomStoragePaths);
CacheStorage::Engine* cacheEngine() { return m_cacheEngine.get(); }
void ensureCacheEngine(Function<void(CacheStorage::Engine&)>&&);
Modified: trunk/Source/WebKit/NetworkProcess/storage/LocalStorageManager.cpp (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/storage/LocalStorageManager.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/storage/LocalStorageManager.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -36,6 +36,7 @@
// Suggested by https://www.w3.org/TR/webstorage/#disk-space
constexpr unsigned localStorageQuotaInBytes = 5 * MB;
constexpr auto fileSuffix = ".localstorage"_s;
+constexpr auto fileName = "localstorage.sqlite3"_s;
// This is intended to be used for existing files.
// We should not include origin in file name.
@@ -75,11 +76,19 @@
String LocalStorageManager::localStorageFilePath(const String& directory, const WebCore::ClientOrigin& origin)
{
if (directory.isEmpty())
- return String { };
+ return emptyString();
return FileSystem::pathByAppendingComponent(directory, originToFileName(origin));
}
+String LocalStorageManager::localStorageFilePath(const String& directory)
+{
+ if (directory.isEmpty())
+ return emptyString();
+
+ return FileSystem::pathByAppendingComponent(directory, fileName);
+}
+
LocalStorageManager::LocalStorageManager(const String& path, StorageAreaRegistry& registry)
: m_path(path)
, m_registry(registry)
Modified: trunk/Source/WebKit/NetworkProcess/storage/LocalStorageManager.h (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/storage/LocalStorageManager.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/storage/LocalStorageManager.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -45,7 +45,8 @@
WTF_MAKE_FAST_ALLOCATED;
public:
static Vector<WebCore::SecurityOriginData> originsOfLocalStorageData(const String& path);
- static String localStorageFilePath(const String& path, const WebCore::ClientOrigin&);
+ static String localStorageFilePath(const String& directory, const WebCore::ClientOrigin&);
+ static String localStorageFilePath(const String& directory);
LocalStorageManager(const String& path, StorageAreaRegistry&);
bool isActive() const;
Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -108,12 +108,12 @@
FileSystem::deleteFile(filePath);
}
-Ref<NetworkStorageManager> NetworkStorageManager::create(PAL::SessionID sessionID, IPC::Connection::UniqueID connection, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota)
+Ref<NetworkStorageManager> NetworkStorageManager::create(PAL::SessionID sessionID, IPC::Connection::UniqueID connection, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota, bool shouldUseCustomPaths)
{
- return adoptRef(*new NetworkStorageManager(sessionID, connection, path, customLocalStoragePath, customIDBStoragePath, customCacheStoragePath, defaultOriginQuota, defaultThirdPartyOriginQuota));
+ return adoptRef(*new NetworkStorageManager(sessionID, connection, path, customLocalStoragePath, customIDBStoragePath, customCacheStoragePath, defaultOriginQuota, defaultThirdPartyOriginQuota, shouldUseCustomPaths));
}
-NetworkStorageManager::NetworkStorageManager(PAL::SessionID sessionID, IPC::Connection::UniqueID connection, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota)
+NetworkStorageManager::NetworkStorageManager(PAL::SessionID sessionID, IPC::Connection::UniqueID connection, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota, bool shouldUseCustomPaths)
: m_sessionID(sessionID)
, m_queue(SuspendableWorkQueue::create("com.apple.WebKit.Storage"))
, m_defaultOriginQuota(defaultOriginQuota)
@@ -122,10 +122,11 @@
{
ASSERT(RunLoop::isMain());
- m_queue->dispatch([this, protectedThis = Ref { *this }, path = path.isolatedCopy(), customLocalStoragePath = crossThreadCopy(customLocalStoragePath), customIDBStoragePath = crossThreadCopy(customIDBStoragePath), customCacheStoragePath = crossThreadCopy(customCacheStoragePath)]() mutable {
+ m_queue->dispatch([this, protectedThis = Ref { *this }, path = path.isolatedCopy(), customLocalStoragePath = crossThreadCopy(customLocalStoragePath), customIDBStoragePath = crossThreadCopy(customIDBStoragePath), customCacheStoragePath = crossThreadCopy(customCacheStoragePath), shouldUseCustomPaths]() mutable {
m_fileSystemStorageHandleRegistry = makeUnique<FileSystemStorageHandleRegistry>();
m_storageAreaRegistry = makeUnique<StorageAreaRegistry>();
m_idbStorageRegistry = makeUnique<IDBStorageRegistry>();
+ m_shouldUseCustomPaths = shouldUseCustomPaths;
m_path = path;
m_customLocalStoragePath = customLocalStoragePath;
m_customIDBStoragePath = customIDBStoragePath;
@@ -211,7 +212,7 @@
static String originDirectoryPath(const String& rootPath, const WebCore::ClientOrigin& origin, FileSystem::Salt salt)
{
if (rootPath.isEmpty())
- return String { };
+ return emptyString();
auto encodedTopOrigin = encode(origin.topOrigin.toString(), salt);
auto encodedOpeningOrigin = encode(origin.clientOrigin.toString(), salt);
@@ -221,8 +222,9 @@
static String originFilePath(const String& directory)
{
if (directory.isEmpty())
- return String { };
- return FileSystem::pathByAppendingComponent(directory, "origin"_s);
+ return emptyString();
+
+ return FileSystem::pathByAppendingComponent(directory, OriginStorageManager::originFileIdentifier());
}
OriginStorageManager& NetworkStorageManager::localOriginStorageManager(const WebCore::ClientOrigin& origin)
@@ -247,7 +249,7 @@
QuotaManager::IncreaseQuotaFunction increaseQuotaFunction = [sessionID = m_sessionID, origin, connection = m_parentConnection] (auto identifier, auto currentQuota, auto currentUsage, auto requestedIncrease) mutable {
IPC::Connection::send(connection, Messages::NetworkProcessProxy::IncreaseQuota(sessionID, origin, identifier, currentQuota, currentUsage, requestedIncrease), 0);
};
- return makeUnique<OriginStorageManager>(quota, WTFMove(increaseQuotaFunction), WTFMove(originDirectory), WTFMove(localStoragePath), WTFMove(idbStoragePath), WTFMove(cacheStoragePath));
+ return makeUnique<OriginStorageManager>(quota, WTFMove(increaseQuotaFunction), WTFMove(originDirectory), WTFMove(localStoragePath), WTFMove(idbStoragePath), WTFMove(cacheStoragePath), m_shouldUseCustomPaths);
}).iterator->value;
}
Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -70,7 +70,7 @@
class NetworkStorageManager final : public IPC::Connection::WorkQueueMessageReceiver {
public:
- static Ref<NetworkStorageManager> create(PAL::SessionID, IPC::Connection::UniqueID, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota);
+ static Ref<NetworkStorageManager> create(PAL::SessionID, IPC::Connection::UniqueID, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota, bool shouldUseCustomPaths);
static bool canHandleTypes(OptionSet<WebsiteDataType>);
void startReceivingMessageFromConnection(IPC::Connection&);
@@ -95,8 +95,7 @@
void resetQuotaUpdatedBasedOnUsageForTesting(const WebCore::ClientOrigin&);
private:
- NetworkStorageManager(PAL::SessionID, const String& path, const String& customLocalStoragePath);
- NetworkStorageManager(PAL::SessionID, IPC::Connection::UniqueID, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota);
+ NetworkStorageManager(PAL::SessionID, IPC::Connection::UniqueID, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota, bool shouldUseCustomPaths);
~NetworkStorageManager();
OriginStorageManager& localOriginStorageManager(const WebCore::ClientOrigin&);
bool removeOriginStorageManagerIfPossible(const WebCore::ClientOrigin&);
@@ -181,6 +180,7 @@
String m_customCacheStoragePath;
uint64_t m_defaultOriginQuota;
uint64_t m_defaultThirdPartyOriginQuota;
+ bool m_shouldUseCustomPaths;
IPC::Connection::UniqueID m_parentConnection;
HashMap<IPC::Connection::UniqueID, HashSet<String>> m_temporaryBlobPathsByConnection;
};
Modified: trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -47,11 +47,12 @@
class OriginStorageManager::StorageBucket {
WTF_MAKE_FAST_ALLOCATED;
public:
- StorageBucket(const String& rootPath, const String& identifier, const String& localStoragePath, const String& idbStoragePath)
+ StorageBucket(const String& rootPath, const String& identifier, const String& localStoragePath, const String& idbStoragePath, bool shouldUseCustomPaths)
: m_rootPath(rootPath)
, m_identifier(identifier)
- , m_localStoragePath(localStoragePath)
- , m_idbStoragePath(idbStoragePath)
+ , m_customLocalStoragePath(localStoragePath)
+ , m_customIDBStoragePath(idbStoragePath)
+ , m_shouldUseCustomPaths(shouldUseCustomPaths)
{
}
@@ -129,7 +130,7 @@
LocalStorageManager& localStorageManager(StorageAreaRegistry& registry)
{
if (!m_localStorageManager)
- m_localStorageManager = makeUnique<LocalStorageManager>(m_localStoragePath, registry);
+ m_localStorageManager = makeUnique<LocalStorageManager>(resolvedLocalStoragePath(), registry);
return *m_localStorageManager;
}
@@ -155,7 +156,7 @@
IDBStorageManager& idbStorageManager(IDBStorageRegistry& registry, IDBStorageManager::QuotaCheckFunction&& quotaCheckFunction)
{
if (!m_idbStorageManager)
- m_idbStorageManager = makeUnique<IDBStorageManager>(m_idbStoragePath, registry, WTFMove(quotaCheckFunction));
+ m_idbStorageManager = makeUnique<IDBStorageManager>(resolvedIDBStoragePath(), registry, WTFMove(quotaCheckFunction));
return *m_idbStorageManager;
}
@@ -175,8 +176,10 @@
|| (m_idbStorageManager && (m_idbStorageManager->hasDataInMemory() || m_idbStorageManager->isActive()));
}
- bool isEmpty() const
+ bool isEmpty()
{
+ ASSERT(!RunLoop::isMain());
+
auto files = FileSystem::listDirectory(m_rootPath);
auto hasValidFile = WTF::anyOf(files, [&](auto file) {
bool isInvalidFile = (file == originFileName);
@@ -188,8 +191,8 @@
if (hasValidFile)
return false;
- FileSystem::deleteEmptyDirectory(m_idbStoragePath);
- return !FileSystem::fileExists(m_localStoragePath) && !FileSystem::fileExists(m_idbStoragePath);
+ auto idbStorageFiles = FileSystem::listDirectory(resolvedIDBStoragePath());
+ return !FileSystem::fileExists(resolvedLocalStoragePath()) && idbStorageFiles.isEmpty();
}
OptionSet<WebsiteDataType> fetchDataTypesInList(OptionSet<WebsiteDataType> types)
@@ -227,17 +230,43 @@
FileSystem::makeAllDirectories(FileSystem::parentPath(path));
FileSystem::moveFile(m_rootPath, path);
- if (!m_localStoragePath.isEmpty() && !localStoragePath.isEmpty()) {
+ auto currentLocalStoragePath = resolvedLocalStoragePath();
+ if (!currentLocalStoragePath.isEmpty() && !localStoragePath.isEmpty()) {
FileSystem::makeAllDirectories(FileSystem::parentPath(localStoragePath));
- WebCore::SQLiteFileSystem::moveDatabaseFile(m_localStoragePath, localStoragePath);
+ WebCore::SQLiteFileSystem::moveDatabaseFile(currentLocalStoragePath, localStoragePath);
}
- if (!m_idbStoragePath.isEmpty() && !idbStoragePath.isEmpty()) {
+ auto currentIDBStoragePath = resolvedIDBStoragePath();
+ if (!currentIDBStoragePath.isEmpty() && !idbStoragePath.isEmpty()) {
FileSystem::makeAllDirectories(FileSystem::parentPath(idbStoragePath));
- WebCore::SQLiteFileSystem::moveDatabaseFile(m_idbStoragePath, idbStoragePath);
+ WebCore::SQLiteFileSystem::moveDatabaseFile(currentIDBStoragePath, idbStoragePath);
}
}
+ String resolvedIDBStoragePath()
+ {
+ ASSERT(!RunLoop::isMain());
+
+ if (!m_resolvedIDBStoragePath.isNull())
+ return m_resolvedIDBStoragePath;
+
+ if (m_shouldUseCustomPaths) {
+ ASSERT(m_customIDBStoragePath.isEmpty() == m_rootPath.isEmpty());
+ m_resolvedIDBStoragePath = m_customIDBStoragePath;
+ } else {
+ auto idbStoragePath = typeStoragePath(StorageType::IndexedDB);
+ if (!m_customIDBStoragePath.isEmpty() && !FileSystem::fileExists(idbStoragePath)) {
+ FileSystem::moveFile(m_customIDBStoragePath, idbStoragePath);
+ FileSystem::makeAllDirectories(idbStoragePath);
+ }
+
+ m_resolvedIDBStoragePath = idbStoragePath;
+ }
+
+ ASSERT(!m_resolvedIDBStoragePath.isNull());
+ return m_resolvedIDBStoragePath;
+ }
+
private:
OptionSet<WebsiteDataType> fetchDataTypesInListFromMemory(OptionSet<WebsiteDataType> types)
{
@@ -269,12 +298,12 @@
}
if (types.contains(WebsiteDataType::LocalStorage) && !result.contains(WebsiteDataType::LocalStorage)) {
- if (FileSystem::fileExists(m_localStoragePath))
+ if (FileSystem::fileExists(resolvedLocalStoragePath()))
result.add(WebsiteDataType::LocalStorage);
}
if (types.contains(WebsiteDataType::IndexedDBDatabases) && !result.contains(WebsiteDataType::IndexedDBDatabases)) {
- if (auto databases = FileSystem::listDirectory(m_idbStoragePath); !databases.isEmpty())
+ if (auto databases = FileSystem::listDirectory(resolvedIDBStoragePath()); !databases.isEmpty())
result.add(WebsiteDataType::IndexedDBDatabases);
}
@@ -291,10 +320,11 @@
void deleteLocalStorageData(WallTime time)
{
- if (FileSystem::fileModificationTime(m_localStoragePath) >= time) {
+ auto currentLocalStoragePath = resolvedLocalStoragePath();
+ if (FileSystem::fileModificationTime(currentLocalStoragePath) >= time) {
if (m_localStorageManager)
m_localStorageManager->clearDataOnDisk();
- WebCore::SQLiteFileSystem::deleteDatabaseFile(m_localStoragePath);
+ WebCore::SQLiteFileSystem::deleteDatabaseFile(currentLocalStoragePath);
}
if (!m_localStorageManager)
@@ -320,20 +350,49 @@
if (m_idbStorageManager)
m_idbStorageManager->closeDatabasesForDeletion();
- FileSystem::deleteAllFilesModifiedSince(m_idbStoragePath, time);
+ FileSystem::deleteAllFilesModifiedSince(resolvedIDBStoragePath(), time);
}
+ String resolvedLocalStoragePath()
+ {
+ if (!m_resolvedLocalStoragePath.isNull())
+ return m_resolvedLocalStoragePath;
+
+ if (m_shouldUseCustomPaths) {
+ ASSERT(m_customLocalStoragePath.isEmpty() == m_rootPath.isEmpty());
+ m_resolvedLocalStoragePath = m_customLocalStoragePath;
+ } else {
+ auto localStoragePath = LocalStorageManager::localStorageFilePath(typeStoragePath(StorageType::LocalStorage));
+ if (!m_customLocalStoragePath.isEmpty() && !FileSystem::fileExists(localStoragePath)) {
+ FileSystem::makeAllDirectories(FileSystem::parentPath(localStoragePath));
+ WebCore::SQLiteFileSystem::moveDatabaseFile(m_customLocalStoragePath, localStoragePath);
+ }
+
+ m_resolvedLocalStoragePath = localStoragePath;
+ }
+
+ return m_resolvedLocalStoragePath;
+ }
+
String m_rootPath;
String m_identifier;
StorageBucketMode m_mode { StorageBucketMode::BestEffort };
std::unique_ptr<FileSystemStorageManager> m_fileSystemStorageManager;
std::unique_ptr<LocalStorageManager> m_localStorageManager;
- String m_localStoragePath;
+ String m_customLocalStoragePath;
+ String m_resolvedLocalStoragePath;
std::unique_ptr<SessionStorageManager> m_sessionStorageManager;
std::unique_ptr<IDBStorageManager> m_idbStorageManager;
- String m_idbStoragePath;
+ String m_customIDBStoragePath;
+ String m_resolvedIDBStoragePath;
+ bool m_shouldUseCustomPaths;
};
+String OriginStorageManager::originFileIdentifier()
+{
+ return originFileName;
+}
+
static Ref<QuotaManager> createQuotaManager(uint64_t quota, const String& idbStoragePath, const String& cacheStoragePath, QuotaManager::IncreaseQuotaFunction&& increaseQuotaFunction)
{
QuotaManager::GetUsageFunction getUsageFunction = [idbStoragePath, cacheStoragePath]() {
@@ -342,12 +401,14 @@
return QuotaManager::create(quota, WTFMove(getUsageFunction), WTFMove(increaseQuotaFunction));
}
-OriginStorageManager::OriginStorageManager(uint64_t quota, QuotaManager::IncreaseQuotaFunction&& increaseQuotaFunction, String&& path, String&& localStoragePath, String&& idbStoragePath, String&& cacheStoragePath)
+OriginStorageManager::OriginStorageManager(uint64_t quota, QuotaManager::IncreaseQuotaFunction&& increaseQuotaFunction, String&& path, String&& customLocalStoragePath, String&& customIDBStoragePath, String&& cacheStoragePath, bool shouldUseCustomPaths)
: m_path(WTFMove(path))
- , m_localStoragePath(WTFMove(localStoragePath))
- , m_idbStoragePath(WTFMove(idbStoragePath))
+ , m_customLocalStoragePath(WTFMove(customLocalStoragePath))
+ , m_customIDBStoragePath(WTFMove(customIDBStoragePath))
, m_cacheStoragePath(WTFMove(cacheStoragePath))
- , m_quotaManager(createQuotaManager(quota, m_idbStoragePath, m_cacheStoragePath, WTFMove(increaseQuotaFunction)))
+ , m_quota(quota)
+ , m_increaseQuotaFunction(WTFMove(increaseQuotaFunction))
+ , m_shouldUseCustomPaths(shouldUseCustomPaths)
{
ASSERT(!RunLoop::isMain());
}
@@ -363,7 +424,7 @@
OriginStorageManager::StorageBucket& OriginStorageManager::defaultBucket()
{
if (!m_defaultBucket)
- m_defaultBucket = makeUnique<StorageBucket>(m_path, "default"_s, m_localStoragePath, m_idbStoragePath);
+ m_defaultBucket = makeUnique<StorageBucket>(m_path, "default"_s, m_customLocalStoragePath, m_customIDBStoragePath, m_shouldUseCustomPaths);
return *m_defaultBucket;
}
@@ -370,7 +431,12 @@
QuotaManager& OriginStorageManager::quotaManager()
{
- return m_quotaManager.get();
+ if (!m_quotaManager) {
+ auto idbStoragePath = defaultBucket().resolvedIDBStoragePath();
+ m_quotaManager = createQuotaManager(m_quota, idbStoragePath, m_cacheStoragePath, std::exchange(m_increaseQuotaFunction, { }));
+ }
+
+ return *m_quotaManager;
}
FileSystemStorageManager& OriginStorageManager::fileSystemStorageManager(FileSystemStorageHandleRegistry& registry)
Modified: trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h (289877 => 289878)
--- trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -43,7 +43,9 @@
class OriginStorageManager {
WTF_MAKE_FAST_ALLOCATED;
public:
- OriginStorageManager(uint64_t quota, QuotaManager::IncreaseQuotaFunction&&, String&& path, String&& localStoragePath, String&& idbStoragePath, String&& cacheStoragePath);
+ static String originFileIdentifier();
+
+ OriginStorageManager(uint64_t quota, QuotaManager::IncreaseQuotaFunction&&, String&& path, String&& cusotmLocalStoragePath, String&& customIDBStoragePath, String&& cacheStoragePath, bool shouldUseCustomPaths);
~OriginStorageManager();
void connectionClosed(IPC::Connection::UniqueID);
@@ -70,11 +72,14 @@
std::unique_ptr<StorageBucket> m_defaultBucket;
String m_path;
+ String m_customLocalStoragePath;
+ String m_customIDBStoragePath;
+ String m_cacheStoragePath;
+ uint64_t m_quota;
+ QuotaManager::IncreaseQuotaFunction m_increaseQuotaFunction;
+ RefPtr<QuotaManager> m_quotaManager;
bool m_persisted { false };
- String m_localStoragePath;
- String m_idbStoragePath;
- String m_cacheStoragePath;
- Ref<QuotaManager> m_quotaManager;
+ bool m_shouldUseCustomPaths;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.cpp (289877 => 289878)
--- trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -52,6 +52,8 @@
encoder << perOriginStorageQuota;
encoder << perThirdPartyOriginStorageQuota;
+
+ encoder << shouldUseCustomStoragePaths;
}
std::optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC::Decoder& decoder)
@@ -155,6 +157,12 @@
if (!perThirdPartyOriginStorageQuota)
return std::nullopt;
parameters.perThirdPartyOriginStorageQuota = *perThirdPartyOriginStorageQuota;
+
+ std::optional<bool> shouldUseCustomStoragePaths;
+ decoder >> shouldUseCustomStoragePaths;
+ if (!shouldUseCustomStoragePaths)
+ return std::nullopt;
+ parameters.shouldUseCustomStoragePaths = *shouldUseCustomStoragePaths;
return parameters;
}
Modified: trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.h (289877 => 289878)
--- trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -73,6 +73,8 @@
uint64_t perOriginStorageQuota;
uint64_t perThirdPartyOriginStorageQuota;
+
+ bool shouldUseCustomStoragePaths { false };
};
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h (289877 => 289878)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -86,6 +86,7 @@
@property (nonatomic, nullable, copy) NSURL *alternativeServicesStorageDirectory WK_API_AVAILABLE(macos(11.0), ios(14.0));
@property (nonatomic, nullable, copy) NSURL *standaloneApplicationURL WK_API_AVAILABLE(macos(11.0), ios(14.0));
@property (nonatomic, nullable, copy) NSURL *generalStorageDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic) BOOL shouldUseCustomStoragePaths WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
// Testing only.
@property (nonatomic) BOOL allLoadsBlockedByDeviceManagementRestrictionsForTesting WK_API_AVAILABLE(macos(10.15), ios(13.0));
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm (289877 => 289878)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm 2022-02-16 06:48:03 UTC (rev 289878)
@@ -351,6 +351,16 @@
_configuration->setGeneralStorageDirectory(url.path);
}
+- (BOOL)shouldUseCustomStoragePaths
+{
+ return _configuration->shouldUseCustomStoragePaths();
+}
+
+- (void)setShouldUseCustomStoragePaths:(BOOL)use
+{
+ _configuration->setShouldUseCustomStoragePaths(use);
+}
+
- (BOOL)deviceManagementRestrictionsEnabled
{
return _configuration->deviceManagementRestrictionsEnabled();
Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (289877 => 289878)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -1879,6 +1879,7 @@
if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(directory))
parameters.generalStorageDirectoryHandle = WTFMove(*handle);
}
+ parameters.shouldUseCustomStoragePaths = configuration().shouldUseCustomStoragePaths();
parameters.perOriginStorageQuota = perOriginStorageQuota();
parameters.perThirdPartyOriginStorageQuota = perThirdPartyOriginStorageQuota();
Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp (289877 => 289878)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp 2022-02-16 06:48:03 UTC (rev 289878)
@@ -66,6 +66,7 @@
copy->m_staleWhileRevalidateEnabled = this->m_staleWhileRevalidateEnabled;
copy->m_cacheStorageDirectory = this->m_cacheStorageDirectory;
copy->m_generalStorageDirectory = this->m_generalStorageDirectory;
+ copy->m_shouldUseCustomStoragePaths = this->m_shouldUseCustomStoragePaths;
copy->m_perOriginStorageQuota = this->m_perOriginStorageQuota;
copy->m_networkCacheDirectory = this->m_networkCacheDirectory;
copy->m_applicationCacheDirectory = this->m_applicationCacheDirectory;
Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h (289877 => 289878)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h 2022-02-16 06:48:03 UTC (rev 289878)
@@ -132,6 +132,9 @@
const String& generalStorageDirectory() const { return m_generalStorageDirectory; }
void setGeneralStorageDirectory(String&& directory) { m_generalStorageDirectory = WTFMove(directory); }
+ bool shouldUseCustomStoragePaths() const { return m_shouldUseCustomStoragePaths; }
+ void setShouldUseCustomStoragePaths(bool use) { m_shouldUseCustomStoragePaths = use; }
+
const String& applicationCacheFlatFileSubdirectoryName() const { return m_applicationCacheFlatFileSubdirectoryName; }
void setApplicationCacheFlatFileSubdirectoryName(String&& directory) { m_applicationCacheFlatFileSubdirectoryName = WTFMove(directory); }
@@ -204,6 +207,7 @@
private:
IsPersistent m_isPersistent { IsPersistent::No };
+ bool m_shouldUseCustomStoragePaths { true };
String m_cacheStorageDirectory;
String m_generalStorageDirectory;
uint64_t m_perOriginStorageQuota;
Modified: trunk/Tools/ChangeLog (289877 => 289878)
--- trunk/Tools/ChangeLog 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Tools/ChangeLog 2022-02-16 06:48:03 UTC (rev 289878)
@@ -1,3 +1,15 @@
+2022-02-15 Sihui Liu <[email protected]>
+
+ Migrate IndexedDB and LocalStorage data to GeneralStorageDirectory
+ https://bugs.webkit.org/show_bug.cgi?id=236611
+
+ Reviewed by Chris Dumez.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/general-storage-directory.salt: Added.
+
2022-02-15 Mark Lam <[email protected]>
Make HeapType an enum class.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (289877 => 289878)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2022-02-16 06:48:03 UTC (rev 289878)
@@ -745,6 +745,7 @@
93625D271CD9741C006DC1F1 /* large-video-without-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93625D261CD973AF006DC1F1 /* large-video-without-audio.html */; };
9368A25E229EFB4700A829CA /* local-storage-process-suspends-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */; };
9368A25F229EFB4700A829CA /* local-storage-process-suspends-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9368A25C229EFB3A00A829CA /* local-storage-process-suspends-2.html */; };
+ 936EC36627BA3B0D00AFA8AE /* general-storage-directory.salt in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936EC36527BA3AF200AFA8AE /* general-storage-directory.salt */; };
936F72801CD7D9EC0068A0FB /* large-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */; };
936F72811CD7D9EC0068A0FB /* large-video-with-audio.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */; };
937A6C8A24357C1700C3A6B0 /* KillWebProcessWithOpenConnection-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 937A6C8824357BF300C3A6B0 /* KillWebProcessWithOpenConnection-1.html */; };
@@ -1357,6 +1358,7 @@
3FBD1B4A1D3D66AB00E6D6FA /* FullscreenLayoutConstraints.html in Copy Resources */,
CDE195B51CFE0B880053D256 /* FullscreenTopContentInset.html in Copy Resources */,
CDBFCC461A9FF49E00A7B691 /* FullscreenZoomInitialFrame.html in Copy Resources */,
+ 936EC36627BA3B0D00AFA8AE /* general-storage-directory.salt in Copy Resources */,
26F52EAD1828827B0023D412 /* geolocationGetCurrentPosition.html in Copy Resources */,
636353A71E98665D0009F8AF /* GeolocationGetCurrentPositionResult.html in Copy Resources */,
26F52EAF18288C230023D412 /* geolocationGetCurrentPositionWithHighAccuracy.html in Copy Resources */,
@@ -2518,6 +2520,7 @@
93625D261CD973AF006DC1F1 /* large-video-without-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-without-audio.html"; sourceTree = "<group>"; };
9368A25C229EFB3A00A829CA /* local-storage-process-suspends-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "local-storage-process-suspends-2.html"; sourceTree = "<group>"; };
9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "local-storage-process-suspends-1.html"; sourceTree = "<group>"; };
+ 936EC36527BA3AF200AFA8AE /* general-storage-directory.salt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "general-storage-directory.salt"; sourceTree = "<group>"; };
936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-with-audio.html"; sourceTree = "<group>"; };
936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "large-video-with-audio.mp4"; sourceTree = "<group>"; };
937A6C8824357BF300C3A6B0 /* KillWebProcessWithOpenConnection-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "KillWebProcessWithOpenConnection-1.html"; sourceTree = "<group>"; };
@@ -4117,6 +4120,7 @@
CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */,
3FBD1B491D39D1DB00E6D6FA /* FullscreenLayoutConstraints.html */,
CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */,
+ 936EC36527BA3AF200AFA8AE /* general-storage-directory.salt */,
636353A61E9861940009F8AF /* GeolocationGetCurrentPositionResult.html */,
07E1F6A11FFC44F90096C7EC /* getDisplayMedia.html */,
467C565121B5ECDF0057516D /* GetSessionCookie.html */,
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm (289877 => 289878)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm 2022-02-16 06:12:08 UTC (rev 289877)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm 2022-02-16 06:48:03 UTC (rev 289878)
@@ -32,6 +32,7 @@
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
#import <_javascript_Core/JSCConfig.h>
+#import <WebCore/SQLiteFileSystem.h>
#import <WebKit/WKHTTPCookieStorePrivate.h>
#import <WebKit/WKPreferencesPrivate.h>
#import <WebKit/WKPreferencesRef.h>
@@ -802,3 +803,141 @@
[fileManager removeItemAtPath:path error:&error];
EXPECT_FALSE(error);
}
+
+TEST(WebKit, MigrateLocalStorageDataToGeneralStorageDirectory)
+{
+ NSURL *localStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/LocalStorage/" stringByExpandingTildeInPath] isDirectory:YES];
+ NSURL *localStorageFile = [localStorageDirectory URLByAppendingPathComponent:@"https_webkit.org_0.localstorage"];
+ NSURL *generalStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/Default" stringByExpandingTildeInPath] isDirectory:YES];
+ NSURL *resourceSalt = [[NSBundle mainBundle] URLForResource:@"general-storage-directory" withExtension:@"salt" subdirectory:@"TestWebKitAPI.resources"];
+ NSURL *newLocalStorageFile = [generalStorageDirectory URLByAppendingPathComponent:@"YUn_wgR51VLVo9lc5xiivAzZ8TMmojoa0IbW323qibs/YUn_wgR51VLVo9lc5xiivAzZ8TMmojoa0IbW323qibs/LocalStorage/localstorage.sqlite3"];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ [fileManager removeItemAtURL:localStorageDirectory error:nil];
+ [fileManager removeItemAtURL:generalStorageDirectory error:nil];
+ [fileManager createDirectoryAtURL:generalStorageDirectory withIntermediateDirectories:YES attributes:nil error:nil];
+ [fileManager copyItemAtURL:resourceSalt toURL:[generalStorageDirectory URLByAppendingPathComponent:@"salt"] error:nil];
+
+ NSString *htmlString = @"<script> \
+ result = localStorage.getItem('testkey'); \
+ if (!result) \
+ result = '[null]'; \
+ window.webkit.messageHandlers.testHandler.postMessage(result); \
+ </script>";
+ auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+ websiteDataStoreConfiguration.get()._webStorageDirectory = localStorageDirectory;
+ websiteDataStoreConfiguration.get().generalStorageDirectory = generalStorageDirectory;
+ websiteDataStoreConfiguration.get().shouldUseCustomStoragePaths = true;
+ auto messageHandler = adoptNS([[WebsiteDataStoreCustomPathsMessageHandler alloc] init]);
+
+ @autoreleasepool {
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ receivedScriptMessage = false;
+ [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ EXPECT_WK_STREQ("[null]", getNextMessage().body);
+ [webView stringByEvaluatingJavaScript:@"localStorage.setItem('testkey', 'testvalue')"];
+
+ // Ensure item is stored by getting it in another WKWebView.
+ auto secondWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ receivedScriptMessage = false;
+ [secondWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ EXPECT_WK_STREQ("testvalue", getNextMessage().body);
+ EXPECT_TRUE([fileManager fileExistsAtPath:localStorageFile.path]);
+ }
+
+ // Create a new WebsiteDataStore that performs migration.
+ websiteDataStoreConfiguration.get().shouldUseCustomStoragePaths = false;
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"];
+ auto thirdWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ receivedScriptMessage = false;
+ [thirdWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ EXPECT_WK_STREQ("testvalue", getNextMessage().body);
+ EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:localStorageFile.path]);
+ EXPECT_TRUE([fileManager fileExistsAtPath:newLocalStorageFile.path]);
+}
+
+TEST(WebKit, MigrateIndexedDBDataToGeneralStorageDirectory)
+{
+ NSURL *indexedDBDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/IndexedDB" stringByExpandingTildeInPath] isDirectory:YES];
+ NSURL *indexedDBOriginDirectory = [indexedDBDirectory URLByAppendingPathComponent:@"v1/https_webkit.org_0"];
+ NSString *indexedDBDatabaseName = @"TestDatabase";
+ NSString *hashedIndexedDBDatabaseName = WebCore::SQLiteFileSystem::computeHashForFileName(indexedDBDatabaseName);
+ NSURL *indexedDBDatabaseDirectory = [indexedDBOriginDirectory URLByAppendingPathComponent:hashedIndexedDBDatabaseName];
+ NSURL *indexedDBFile = [indexedDBDatabaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"];
+ NSURL *generalStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/Default" stringByExpandingTildeInPath] isDirectory:YES];
+ NSURL *resourceSalt = [[NSBundle mainBundle] URLForResource:@"general-storage-directory" withExtension:@"salt" subdirectory:@"TestWebKitAPI.resources"];
+ NSURL *newIndexedDBOriginDirectory = [generalStorageDirectory URLByAppendingPathComponent:@"YUn_wgR51VLVo9lc5xiivAzZ8TMmojoa0IbW323qibs/YUn_wgR51VLVo9lc5xiivAzZ8TMmojoa0IbW323qibs/IndexedDB/"];
+ NSURL *newIndexedDBDirectory = [newIndexedDBOriginDirectory URLByAppendingPathComponent:hashedIndexedDBDatabaseName];
+ NSURL *newIndexedDBFile = [newIndexedDBDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ [fileManager removeItemAtURL:indexedDBDirectory error:nil];
+ [fileManager removeItemAtURL:generalStorageDirectory error:nil];
+ [fileManager createDirectoryAtURL:generalStorageDirectory withIntermediateDirectories:YES attributes:nil error:nil];
+ [fileManager copyItemAtURL:resourceSalt toURL:[generalStorageDirectory URLByAppendingPathComponent:@"salt"] error:nil];
+
+ NSString *htmlString = @"<script> \
+ var request = window.indexedDB.open('TestDatabase'); \
+ var upgradeneededReceived = false; \
+ request._onupgradeneeded_ = function(event) { \
+ var db = event.target.result; \
+ var os = db.createObjectStore('TestObjectStore'); \
+ os.put('value', 'key'); \
+ window.webkit.messageHandlers.testHandler.postMessage('database is created'); \
+ upgradeneededReceived = true; \
+ }; \
+ request._onsuccess_ = function(event) { \
+ if (upgradeneededReceived) \
+ return; \
+ db = event.target.result; \
+ db.transaction('TestObjectStore').objectStore('TestObjectStore').get('key')._onsuccess_ = function(event) { \
+ var result = event.target.result ? event.target.result : '[null]'; \
+ window.webkit.messageHandlers.testHandler.postMessage(result); \
+ }; \
+ }; \
+ </script>";
+ auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+ websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = indexedDBDirectory;
+ websiteDataStoreConfiguration.get().generalStorageDirectory = generalStorageDirectory;
+ websiteDataStoreConfiguration.get().shouldUseCustomStoragePaths = true;
+ auto messageHandler = adoptNS([[WebsiteDataStoreCustomPathsMessageHandler alloc] init]);
+
+ @autoreleasepool {
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ receivedScriptMessage = false;
+ [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ EXPECT_WK_STREQ("database is created", getNextMessage().body);
+
+ // Ensure item is stored by getting it in another WKWebView.
+ auto secondWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ receivedScriptMessage = false;
+ [secondWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ EXPECT_WK_STREQ("value", getNextMessage().body);
+ EXPECT_TRUE([fileManager fileExistsAtPath:indexedDBFile.path]);
+ }
+
+ // Create a new WebsiteDataStore that performs migration.
+ websiteDataStoreConfiguration.get().shouldUseCustomStoragePaths = false;
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"];
+ auto thirdWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ receivedScriptMessage = false;
+ [thirdWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ EXPECT_WK_STREQ("value", getNextMessage().body);
+ EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:indexedDBFile.path]);
+ EXPECT_TRUE([fileManager fileExistsAtPath:newIndexedDBFile.path]);
+}
Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/general-storage-directory.salt (0 => 289878)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/general-storage-directory.salt (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/general-storage-directory.salt 2022-02-16 06:48:03 UTC (rev 289878)
@@ -0,0 +1 @@
+{\xD0\xCC\xFC\xDC:\xBC
\ No newline at end of file