Diff
Modified: trunk/Source/WebCore/ChangeLog (290531 => 290532)
--- trunk/Source/WebCore/ChangeLog 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Source/WebCore/ChangeLog 2022-02-25 23:45:34 UTC (rev 290532)
@@ -1,3 +1,25 @@
+2022-02-25 Sihui Liu <[email protected]>
+
+ Regression(r242729): m_origin in IDBDatabaseIdentifier is incorrect
+ https://bugs.webkit.org/show_bug.cgi?id=237044
+
+ Reviewed by Youenn Fablet.
+
+ In r242729, we swapped top origin and opening origin in m_origin (it is a ClientOrigin) of IDBDatabaseIdentifier.
+ This can cause trouble since IndexedDB operation will be processed by wrong OriginStorageManager
+ (OriginStorageManager is identified by ClientOrigin). To fix this issue, we need to swap it back.
+
+ New test: IndexedDB.IndexedDBThirdPartyStorageLayout
+
+ * Modules/indexeddb/IDBDatabaseIdentifier.cpp:
+ (WebCore::IDBDatabaseIdentifier::IDBDatabaseIdentifier):
+ (WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot const):
+ (WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot):
+ * Modules/indexeddb/IDBDatabaseIdentifier.h:
+ * Modules/indexeddb/server/IDBServer.cpp:
+ (WebCore::IDBServer::IDBServer::getAllDatabaseNamesAndVersions):
+ (WebCore::IDBServer::IDBServer::diskUsage):
+
2022-02-25 Chris Dumez <[email protected]>
SharedArrayBuffer posted to AudioWorkletProcessor is not actually shared with the main thread
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp (290531 => 290532)
--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp 2022-02-25 23:45:34 UTC (rev 290532)
@@ -35,7 +35,7 @@
IDBDatabaseIdentifier::IDBDatabaseIdentifier(const String& databaseName, SecurityOriginData&& openingOrigin, SecurityOriginData&& mainFrameOrigin, bool isTransient)
: m_databaseName(databaseName)
- , m_origin { WTFMove(openingOrigin), WTFMove(mainFrameOrigin) }
+ , m_origin { WTFMove(mainFrameOrigin), WTFMove(openingOrigin) }
, m_isTransient(isTransient)
{
// The empty string is a valid database name, but a null string is not.
@@ -55,19 +55,19 @@
String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const String& rootDirectory, const String& versionString) const
{
- return databaseDirectoryRelativeToRoot(m_origin.topOrigin, m_origin.clientOrigin, rootDirectory, versionString);
+ return databaseDirectoryRelativeToRoot(m_origin, rootDirectory, versionString);
}
-String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const SecurityOriginData& topLevelOrigin, const SecurityOriginData& openingOrigin, const String& rootDirectory, const String& versionString)
+String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const ClientOrigin& origin, const String& rootDirectory, const String& versionString)
{
String versionDirectory = FileSystem::pathByAppendingComponent(rootDirectory, versionString);
- String mainFrameDirectory = FileSystem::pathByAppendingComponent(versionDirectory, topLevelOrigin.databaseIdentifier());
+ String mainFrameDirectory = FileSystem::pathByAppendingComponent(versionDirectory, origin.topOrigin.databaseIdentifier());
// If the opening origin and main frame origins are the same, there is no partitioning.
- if (openingOrigin == topLevelOrigin)
+ if (origin.topOrigin == origin.clientOrigin)
return mainFrameDirectory;
- return FileSystem::pathByAppendingComponent(mainFrameDirectory, openingOrigin.databaseIdentifier());
+ return FileSystem::pathByAppendingComponent(mainFrameDirectory, origin.clientOrigin.databaseIdentifier());
}
#if !LOG_DISABLED
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h (290531 => 290532)
--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h 2022-02-25 23:45:34 UTC (rev 290532)
@@ -70,7 +70,7 @@
bool isTransient() const { return m_isTransient; }
String databaseDirectoryRelativeToRoot(const String& rootDirectory, const String& versionString="v1") const;
- WEBCORE_EXPORT static String databaseDirectoryRelativeToRoot(const SecurityOriginData& topLevelOrigin, const SecurityOriginData& openingOrigin, const String& rootDirectory, const String& versionString);
+ WEBCORE_EXPORT static String databaseDirectoryRelativeToRoot(const ClientOrigin&, const String& rootDirectory, const String& versionString);
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<IDBDatabaseIdentifier> decode(Decoder&);
Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (290531 => 290532)
--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2022-02-25 23:45:34 UTC (rev 290532)
@@ -530,10 +530,10 @@
result.append(WTFMove(*nameAndVersion));
}
- String oldDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v0");
+ auto oldDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin, m_databaseDirectoryPath, "v0");
getDatabaseNameAndVersionFromOriginDirectory(oldDirectory, visitedDatabasePaths, result);
- String directory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v1");
+ auto directory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin, m_databaseDirectoryPath, "v1");
getDatabaseNameAndVersionFromOriginDirectory(directory, visitedDatabasePaths, result);
auto connection = m_connectionMap.get(serverConnectionIdentifier);
@@ -758,8 +758,8 @@
{
ASSERT(!isMainThread());
- auto oldVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, rootDirectory, "v0"_str);
- auto newVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, rootDirectory, "v1"_str);
+ auto oldVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin, rootDirectory, "v0"_str);
+ auto newVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin, rootDirectory, "v1"_str);
return SQLiteIDBBackingStore::databasesSizeForDirectory(oldVersionOriginDirectory) + SQLiteIDBBackingStore::databasesSizeForDirectory(newVersionOriginDirectory);
}
Modified: trunk/Source/WebKit/ChangeLog (290531 => 290532)
--- trunk/Source/WebKit/ChangeLog 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Source/WebKit/ChangeLog 2022-02-25 23:45:34 UTC (rev 290532)
@@ -1,3 +1,14 @@
+2022-02-25 Sihui Liu <[email protected]>
+
+ Regression(r242729): m_origin in IDBDatabaseIdentifier is incorrect
+ https://bugs.webkit.org/show_bug.cgi?id=237044
+
+ Reviewed by Youenn Fablet.
+
+ * NetworkProcess/storage/IDBStorageManager.cpp:
+ (WebKit::migrateOriginData):
+ (WebKit::IDBStorageManager::idbStorageOriginDirectory):
+
2022-02-25 Per Arne Vollan <[email protected]>
Make sure there is a default Networking process to provide the Launch Services database
Modified: trunk/Source/WebKit/NetworkProcess/storage/IDBStorageManager.cpp (290531 => 290532)
--- trunk/Source/WebKit/NetworkProcess/storage/IDBStorageManager.cpp 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Source/WebKit/NetworkProcess/storage/IDBStorageManager.cpp 2022-02-25 23:45:34 UTC (rev 290532)
@@ -28,6 +28,7 @@
#include "IDBStorageRegistry.h"
#include <WebCore/IDBRequestData.h>
+#include <WebCore/IDBServer.h>
#include <WebCore/MemoryIDBBackingStore.h>
#include <WebCore/SQLiteFileSystem.h>
#include <WebCore/SQLiteIDBBackingStore.h>
@@ -44,6 +45,10 @@
FileSystem::makeAllDirectories(newOriginDirectory);
for (auto& name : fileNames) {
+ // This is an origin directory for third-party data.
+ if (auto origin = WebCore::SecurityOriginData::fromDatabaseIdentifier(name))
+ continue;
+
String childPath = FileSystem::realPath(FileSystem::pathByAppendingComponent(oldOriginDirectory, name));
String newName = WebCore::SQLiteFileSystem::computeHashForFileName(WebCore::IDBServer::SQLiteIDBBackingStore::decodeDatabaseName(name));
auto newChildPath = FileSystem::pathByAppendingComponent(newOriginDirectory, newName);
@@ -58,8 +63,8 @@
if (rootDirectory.isEmpty())
return emptyString();
- String originDirectory = WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, rootDirectory, "v1");
- String oldOriginDirectory = WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, rootDirectory, "v0");
+ auto originDirectory = WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin, rootDirectory, "v1");
+ auto oldOriginDirectory = WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin, rootDirectory, "v0");
migrateOriginData(oldOriginDirectory, originDirectory);
return originDirectory;
Modified: trunk/Tools/ChangeLog (290531 => 290532)
--- trunk/Tools/ChangeLog 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Tools/ChangeLog 2022-02-25 23:45:34 UTC (rev 290532)
@@ -1,3 +1,14 @@
+2022-02-25 Sihui Liu <[email protected]>
+
+ Regression(r242729): m_origin in IDBDatabaseIdentifier is incorrect
+ https://bugs.webkit.org/show_bug.cgi?id=237044
+
+ Reviewed by Youenn Fablet.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm:
+ (-[IndexedDBMessageHandler userContentController:didReceiveScriptMessage:]):
+ (TEST):
+
2022-02-25 Alex Christensen <[email protected]>
Re-add YouTubePluginReplacement, removed in r285252
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm (290531 => 290532)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm 2022-02-25 23:29:21 UTC (rev 290531)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm 2022-02-25 23:45:34 UTC (rev 290532)
@@ -29,12 +29,14 @@
#import "PlatformUtilities.h"
#import "Test.h"
#import "TestURLSchemeHandler.h"
-#import <WebKit/WebKit.h>
+#import <WebKit/WKPreferencesRef.h>
+#import <WebKit/WKPreferencesRefPrivate.h>
#import <WebKit/WKProcessPoolPrivate.h>
#import <WebKit/WKUserContentControllerPrivate.h>
#import <WebKit/WKWebViewConfigurationPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
#import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <WebKit/WebKit.h>
#import <WebKit/_WKProcessPoolConfiguration.h>
#import <WebKit/_WKUserStyleSheet.h>
#import <wtf/RetainPtr.h>
@@ -47,7 +49,7 @@
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
receivedScriptMessage = true;
- lastScriptMessage = message;
+ scriptMessages.append(message);
}
@end
@@ -65,11 +67,11 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- RetainPtr<NSString> string1 = (NSString *)[lastScriptMessage body];
+ RetainPtr<NSString> string1 = (NSString *)[getNextMessage() body];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- RetainPtr<NSString> string2 = (NSString *)[lastScriptMessage body];
+ RetainPtr<NSString> string2 = (NSString *)[getNextMessage() body];
// Ditch this web view (ditching its web process)
webView = nil;
@@ -85,7 +87,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- RetainPtr<NSString> string3 = (NSString *)[lastScriptMessage body];
+ RetainPtr<NSString> string3 = (NSString *)[getNextMessage() body];
EXPECT_WK_STREQ(@"UpgradeNeeded", string1.get());
EXPECT_WK_STREQ(@"Success", string2.get());
@@ -108,11 +110,11 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- RetainPtr<NSString> string1 = (NSString *)[lastScriptMessage body];
+ RetainPtr<NSString> string1 = (NSString *)[getNextMessage() body];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- RetainPtr<NSString> string2 = (NSString *)[lastScriptMessage body];
+ RetainPtr<NSString> string2 = (NSString *)[getNextMessage() body];
auto webViewPid1 = [webView _webProcessIdentifier];
// Ditch this web view (ditching its web process)
@@ -126,7 +128,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- RetainPtr<NSString> string3 = (NSString *)[lastScriptMessage body];
+ RetainPtr<NSString> string3 = (NSString *)[getNextMessage() body];
auto webViewPid2 = [webView _webProcessIdentifier];
EXPECT_NE(webViewPid1, webViewPid2);
@@ -240,7 +242,7 @@
[webView loadHTMLString:mainFrameStringPersistence baseURL:[NSURL URLWithString:@"http://webkit.org"]];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(expectedResult, (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(expectedResult, (NSString *)[getNextMessage() body]);
}
TEST(IndexedDB, IndexedDBThirdPartyFrameHasAccess)
@@ -302,7 +304,7 @@
[secondWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"iframe://"]]];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ( @"database is created - put item success", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ( @"database is created - put item success", (NSString *)[getNextMessage() body]);
readyToContinue = false;
[[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:websiteDataTypes.get() completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {
@@ -322,6 +324,50 @@
loadTestPageInWebView(thirdWebView.get(), @"database is created - put item success");
}
+TEST(IndexedDB, IndexedDBThirdPartyStorageLayout)
+{
+ NSURL *resourceSalt = [[NSBundle mainBundle] URLForResource:@"general-storage-directory" withExtension:@"salt" subdirectory:@"TestWebKitAPI.resources"];
+ NSURL *generalStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/Default" stringByExpandingTildeInPath] isDirectory:YES];
+ NSURL *webkitOriginFile = [generalStorageDirectory URLByAppendingPathComponent:@"EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/origin"];
+ NSURL *webkitIframeOriginFile = [generalStorageDirectory URLByAppendingPathComponent:@"EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/vudvbMlKXj1m6RibnVvc8PdAdcXZsNE6ON_Al7yqOsg/origin"];
+ NSURL *iframeWebKitOriginFile = [generalStorageDirectory URLByAppendingPathComponent:@"vudvbMlKXj1m6RibnVvc8PdAdcXZsNE6ON_Al7yqOsg/EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/origin"];
+ NSURL *idbDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/IndexedDB" stringByExpandingTildeInPath] isDirectory:YES];
+ NSString *hashedDatabaseName = WebCore::SQLiteFileSystem::computeHashForFileName("IndexedDBThirdPartyFrameHasAccess");
+ NSURL *webkitIframeDatabaseFile = [NSURL fileURLWithPath:[NSString pathWithComponents:@[idbDirectory.path, @"v1/http_webkit.org_0/iframe__0/", hashedDatabaseName, @"IndexedDB.sqlite3"]]];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ [fileManager removeItemAtURL:generalStorageDirectory error:nil];
+ [fileManager createDirectoryAtURL:generalStorageDirectory withIntermediateDirectories:YES attributes:nil error:nil];
+ [fileManager copyItemAtURL:resourceSalt toURL:[generalStorageDirectory URLByAppendingPathComponent:@"salt"] error:nil];
+ [fileManager removeItemAtURL:idbDirectory error:nil];
+
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+ websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbDirectory;
+ websiteDataStoreConfiguration.get().generalStorageDirectory = generalStorageDirectory;
+ [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
+ auto handler = adoptNS([[IndexedDBMessageHandler alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+ auto schemeHandler = adoptNS([[TestURLSchemeHandler alloc] init]);
+ [schemeHandler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
+ auto response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:0 textEncodingName:nil]);
+ [task didReceiveResponse:response.get()];
+ [task didReceiveData:[NSData dataWithBytes:iframeBytesPersistence length:strlen(iframeBytesPersistence)]];
+ [task didFinish];
+ }];
+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"iframe"];
+ // Allowing third-party frame to store data on disk.
+ auto preferences = (__bridge WKPreferencesRef)[configuration preferences];
+ WKPreferencesSetStorageBlockingPolicy(preferences, kWKAllowAllStorage);
+
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ loadTestPageInWebView(webView.get(), @"database is created - put item success");
+
+ EXPECT_TRUE([fileManager fileExistsAtPath:webkitOriginFile.path]);
+ EXPECT_TRUE([fileManager fileExistsAtPath:webkitIframeOriginFile.path]);
+ EXPECT_FALSE([fileManager fileExistsAtPath:iframeWebKitOriginFile.path]);
+ EXPECT_TRUE([fileManager fileExistsAtPath:webkitIframeDatabaseFile.path]);
+}
+
static const char* workerBytes = R"TESTRESOURCE(
try {
var request = indexedDB.open('IndexedDBThirdPartyWorkerHasAccess');
@@ -456,18 +502,18 @@
[webView loadHTMLString:getDatabasesString baseURL:[NSURL URLWithString:@"http://apple.com"]];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"databases: [{\"name\":\"IndexedDBGetDatabases\",\"version\":1}]", [lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"databases: [{\"name\":\"IndexedDBGetDatabases\",\"version\":1}]", [getNextMessage() body]);
[webView evaluateJavaScript:@"loadFrame()" completionHandler:nil];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"child frame databases: []", [lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"child frame databases: []", [getNextMessage() body]);
auto secondWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
[secondWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"webkit://"]]];
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"main frame databases: []", [lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"main frame databases: []", [getNextMessage() body]);
// Getting databases should not create files on disk.
NSURL *idbDirectoryURL = [[WKWebsiteDataStore defaultDataStore] _indexedDBDatabaseDirectory];