Title: [285746] trunk
Revision
285746
Author
sihui_...@apple.com
Date
2021-11-12 15:11:42 -0800 (Fri, 12 Nov 2021)

Log Message

Set default general storage directory to websiteDataDirectory
https://bugs.webkit.org/show_bug.cgi?id=232985

Reviewed by Geoffrey Garen.

Source/WebKit:

New API test: FileSystemAccess.MigrateToNewStorageDirectory

* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::defaultGeneralStorageDirectory):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm:
* TestWebKitAPI/Tests/WebKitCocoa/file-system-access.salt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (285745 => 285746)


--- trunk/Source/WebKit/ChangeLog	2021-11-12 23:00:38 UTC (rev 285745)
+++ trunk/Source/WebKit/ChangeLog	2021-11-12 23:11:42 UTC (rev 285746)
@@ -1,3 +1,16 @@
+2021-11-12  Sihui Liu  <sihui_...@apple.com>
+
+        Set default general storage directory to websiteDataDirectory
+        https://bugs.webkit.org/show_bug.cgi?id=232985
+
+        Reviewed by Geoffrey Garen.
+
+        New API test: FileSystemAccess.MigrateToNewStorageDirectory
+
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::defaultGeneralStorageDirectory):
+
 2021-11-12  Timothy Hatcher  <timo...@apple.com>
 
         Remove non-completionHandler version of -[WKWebView _loadServiceWorker:]

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h (285745 => 285746)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h	2021-11-12 23:00:38 UTC (rev 285745)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h	2021-11-12 23:11:42 UTC (rev 285746)
@@ -82,7 +82,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 *storageDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, nullable, copy) NSURL *generalStorageDirectory 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/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (285745 => 285746)


--- trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2021-11-12 23:00:38 UTC (rev 285745)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2021-11-12 23:11:42 UTC (rev 285746)
@@ -278,7 +278,28 @@
 
 String WebsiteDataStore::defaultGeneralStorageDirectory()
 {
-    return cacheDirectoryFileSystemRepresentation("Storage");
+    auto directory = websiteDataDirectoryFileSystemRepresentation("Default");
+
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        // This is the old storage directory, and there might be files left here.
+        auto oldDirectory = cacheDirectoryFileSystemRepresentation("Storage", ShouldCreateDirectory::No);
+        NSFileManager *fileManager = [NSFileManager defaultManager];
+        NSArray *files = [fileManager contentsOfDirectoryAtPath:oldDirectory error:0];
+        if (files) {
+            for (NSString *fileName in files) {
+                if (![fileName length])
+                    continue;
+
+                NSString *path = [directory stringByAppendingPathComponent:fileName];
+                NSString *oldPath = [oldDirectory stringByAppendingPathComponent:fileName];
+                [fileManager moveItemAtPath:oldPath toPath:path error:nil];
+            }
+        }
+        [fileManager removeItemAtPath:oldDirectory error:nil];
+    });
+
+    return directory;
 }
 
 String WebsiteDataStore::defaultNetworkCacheDirectory()

Modified: trunk/Tools/ChangeLog (285745 => 285746)


--- trunk/Tools/ChangeLog	2021-11-12 23:00:38 UTC (rev 285745)
+++ trunk/Tools/ChangeLog	2021-11-12 23:11:42 UTC (rev 285746)
@@ -1,3 +1,14 @@
+2021-11-12  Sihui Liu  <sihui_...@apple.com>
+
+        Set default general storage directory to websiteDataDirectory
+        https://bugs.webkit.org/show_bug.cgi?id=232985
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/file-system-access.salt: Added.
+
 2021-11-12  Peng Liu  <peng.l...@apple.com>
 
         Promote WKPreferences._fullScreenEnabled to API

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (285745 => 285746)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-11-12 23:00:38 UTC (rev 285745)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-11-12 23:11:42 UTC (rev 285746)
@@ -732,6 +732,7 @@
 		935786CC20F6A2700000CDFC /* IndexedDB.sqlite3-wal in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */; };
 		935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */; };
 		935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */; };
+		9358C33C273ED07B00F3B38C /* file-system-access.salt in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9358C33B273ED06A00F3B38C /* file-system-access.salt */; };
 		9360270625A3CF7600367670 /* speechrecognition-basic.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9360270525A3B28E00367670 /* speechrecognition-basic.html */; };
 		9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
 		93625D271CD9741C006DC1F1 /* large-video-without-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93625D261CD973AF006DC1F1 /* large-video-without-audio.html */; };
@@ -1075,11 +1076,9 @@
 		F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
 		F4C8797F2059D8D3009CD00B /* ScrollViewInsetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4C8797E2059D8D3009CD00B /* ScrollViewInsetTests.mm */; };
 		F4CD74C620FDACFA00DE3794 /* text-with-async-script.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CD74C520FDACF500DE3794 /* text-with-async-script.html */; };
-		F4CD74C920FDB49600DE3794 /* TestURLSchemeHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CD74C820FDB49600DE3794 /* TestURLSchemeHandler.mm */; };
 		F4CF32802366552200D3AD07 /* EnterKeyHintTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CF327F2366552200D3AD07 /* EnterKeyHintTests.mm */; };
 		F4CFCDDA249FC9E400527482 /* SpaceOnly.otf in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CFCDD8249FC9D900527482 /* SpaceOnly.otf */; };
 		F4D060082734A1AB008FA67A /* simple-editor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D060072734A08C008FA67A /* simple-editor.html */; };
-		F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */; };
 		F4D4F3B61E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm */; };
 		F4D4F3B91E4E36E400BB2767 /* DragAndDropTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */; };
 		F4D5D69525AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */; };
@@ -1308,6 +1307,7 @@
 				C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */,
 				7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */,
 				CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */,
+				9358C33C273ED07B00F3B38C /* file-system-access.salt in Copy Resources */,
 				F41AB9A31EF4696B0083FA08 /* file-uploading.html in Copy Resources */,
 				BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */,
 				49D2E5C22731E3BC00BCCAED /* file-with-iframe.html in Copy Resources */,
@@ -2449,6 +2449,7 @@
 		934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IndexedDB.sqlite3-shm"; sourceTree = "<group>"; };
 		934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = IndexedDB.sqlite3; sourceTree = "<group>"; };
 		93575C551D30366E000D604D /* focus-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "focus-inputs.html"; sourceTree = "<group>"; };
+		9358C33B273ED06A00F3B38C /* file-system-access.salt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "file-system-access.salt"; sourceTree = "<group>"; };
 		9360270525A3B28E00367670 /* speechrecognition-basic.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "speechrecognition-basic.html"; sourceTree = "<group>"; };
 		9361002814DC957B0061379D /* lots-of-iframes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-iframes.html"; sourceTree = "<group>"; };
 		93625D261CD973AF006DC1F1 /* large-video-without-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-without-audio.html"; sourceTree = "<group>"; };
@@ -4000,6 +4001,7 @@
 				F407FE381F1D0DE60017CF25 /* enormous.svg */,
 				7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */,
 				CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
+				9358C33B273ED06A00F3B38C /* file-system-access.salt */,
 				F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
 				49D2E5C12731E37400BCCAED /* file-with-iframe.html */,
 				A17EAC542083056E0084B41B /* find.pdf */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm (285745 => 285746)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm	2021-11-12 23:00:38 UTC (rev 285745)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm	2021-11-12 23:11:42 UTC (rev 285746)
@@ -99,7 +99,6 @@
     }];
     [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"webkit"];
 
-    // load first web view & start test
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
     [webView loadHTMLString:mainFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]];
     TestWebKitAPI::Util::run(&receivedScriptMessage);
@@ -131,4 +130,70 @@
     EXPECT_WK_STREQ(@"success: write 10 bytes", [lastScriptMessage body]);
 }
 
+static NSString *basicString = @"<script> \
+    async function open() \
+    { \
+        try { \
+            var rootHandle = await navigator.storage.getDirectory(); \
+            var fileHandle = await rootHandle.getFileHandle('file-system-access.txt', { 'create' : false }); \
+            window.webkit.messageHandlers.testHandler.postMessage('file is opened'); \
+        } catch (err) { \
+            window.webkit.messageHandlers.testHandler.postMessage('error: ' + err.name + ' - ' + err.message); \
+        } \
+    } \
+    open(); \
+    </script>";
+
+TEST(FileSystemAccess, MigrateToNewStorageDirectory)
+{
+    NSString *hashedOrigin = @"Rpva_lVGHjojRmxI7eh92UpdZVvdH0OCis2MNCM-nDo";
+    NSString *storageType = @"FileSystem";
+    NSString *fileName = @"file-system-access.txt";
+    
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+
+    // This is old value returned by WebsiteDataStore::defaultGeneralStorageDirectory().
+    NSString *oldStorageDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/com.apple.WebKit.TestWebKitAPI/WebKit/Storage/"];
+    [fileManager removeItemAtPath:oldStorageDirectory error:nil];
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:oldStorageDirectory]);
+    
+    // Copy baked files to old directory.
+    NSString *oldFileSystemDirectory = [NSString pathWithComponents:@[oldStorageDirectory, hashedOrigin, hashedOrigin, storageType]];
+    [fileManager createDirectoryAtURL:[NSURL fileURLWithPath:oldFileSystemDirectory] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *oldFilePath = [oldFileSystemDirectory stringByAppendingPathComponent:fileName];
+    [fileManager createFileAtPath:oldFilePath contents:nil attributes:nil];
+    EXPECT_TRUE([fileManager fileExistsAtPath:oldFilePath]);
+
+    NSString *resourceSaltPath = [[NSBundle mainBundle] URLForResource:@"file-system-access" withExtension:@"salt" subdirectory:@"TestWebKitAPI.resources"].path;
+    NSString *oldSaltPath = [oldStorageDirectory stringByAppendingPathComponent:@"salt"];
+    [fileManager copyItemAtPath:resourceSaltPath toPath:oldSaltPath error:nil];
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:oldSaltPath]);
+
+    // This is current value returned by WebsiteDataStore::defaultGeneralStorageDirectory().
+    NSString *newStorageDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/Default/"];
+    [fileManager removeItemAtPath:newStorageDirectory error:nil];
+    NSString *newFilePath = [NSString pathWithComponents:@[newStorageDirectory, hashedOrigin, hashedOrigin, storageType, fileName]];
+    EXPECT_FALSE([fileManager fileExistsAtPath:newFilePath]);
+
+    // Invoke WebsiteDataStore::defaultGeneralStorageDirectory() to trigger migration.
+    NSString *currentStorageDirectory = [[[WKWebsiteDataStore defaultDataStore] _configuration] generalStorageDirectory].path;
+    EXPECT_WK_STREQ(newStorageDirectory, currentStorageDirectory);
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:oldFilePath]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:newFilePath]);
+
+    // Ensure file can be opened after migration: test page only opens the file if it exists.
+    auto handler = adoptNS([[FileSystemAccessMessageHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+    auto preferences = [configuration preferences];
+    preferences._fileSystemAccessEnabled = YES;
+    preferences._storageAPIEnabled = YES;
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView loadHTMLString:basicString baseURL:[NSURL URLWithString:@"https://webkit.org"]];
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+    receivedScriptMessage = false;
+    EXPECT_WK_STREQ(@"file is opened", [lastScriptMessage body]);
+}
+
 #endif // USE(APPLE_INTERNAL_SDK)

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-system-access.salt (0 => 285746)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-system-access.salt	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-system-access.salt	2021-11-12 23:11:42 UTC (rev 285746)
@@ -0,0 +1 @@
+Y\x92\xF9u	3$
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to