⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285746 in webkit


Ignore:
Timestamp:
Nov 12, 2021, 3:11:42 PM (5 years ago)
Author:
sihui_liu@apple.com
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.
Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r285742 r285746  
     12021-11-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Set default general storage directory to websiteDataDirectory
     4        https://bugs.webkit.org/show_bug.cgi?id=232985
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        New API test: FileSystemAccess.MigrateToNewStorageDirectory
     9
     10        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
     11        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     12        (WebKit::WebsiteDataStore::defaultGeneralStorageDirectory):
     13
    1142021-11-12  Timothy Hatcher  <timothy@apple.com>
    215
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h

    r284591 r285746  
    8383@property (nonatomic, nullable, copy) NSURL *alternativeServicesStorageDirectory WK_API_AVAILABLE(macos(11.0), ios(14.0));
    8484@property (nonatomic, nullable, copy) NSURL *standaloneApplicationURL WK_API_AVAILABLE(macos(11.0), ios(14.0));
    85 @property (nonatomic, nullable, copy) NSURL *storageDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     85@property (nonatomic, nullable, copy) NSURL *generalStorageDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    8686
    8787// Testing only.
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r284968 r285746  
    279279String WebsiteDataStore::defaultGeneralStorageDirectory()
    280280{
    281     return cacheDirectoryFileSystemRepresentation("Storage");
     281    auto directory = websiteDataDirectoryFileSystemRepresentation("Default");
     282
     283    static dispatch_once_t onceToken;
     284    dispatch_once(&onceToken, ^{
     285        // This is the old storage directory, and there might be files left here.
     286        auto oldDirectory = cacheDirectoryFileSystemRepresentation("Storage", ShouldCreateDirectory::No);
     287        NSFileManager *fileManager = [NSFileManager defaultManager];
     288        NSArray *files = [fileManager contentsOfDirectoryAtPath:oldDirectory error:0];
     289        if (files) {
     290            for (NSString *fileName in files) {
     291                if (![fileName length])
     292                    continue;
     293
     294                NSString *path = [directory stringByAppendingPathComponent:fileName];
     295                NSString *oldPath = [oldDirectory stringByAppendingPathComponent:fileName];
     296                [fileManager moveItemAtPath:oldPath toPath:path error:nil];
     297            }
     298        }
     299        [fileManager removeItemAtPath:oldDirectory error:nil];
     300    });
     301
     302    return directory;
    282303}
    283304
  • trunk/Tools/ChangeLog

    r285741 r285746  
     12021-11-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Set default general storage directory to websiteDataDirectory
     4        https://bugs.webkit.org/show_bug.cgi?id=232985
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm:
     10        * TestWebKitAPI/Tests/WebKitCocoa/file-system-access.salt: Added.
     11
    1122021-11-12  Peng Liu  <peng.liu6@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r285547 r285746  
    733733                935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */; };
    734734                935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */; };
     735                9358C33C273ED07B00F3B38C /* file-system-access.salt in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9358C33B273ED06A00F3B38C /* file-system-access.salt */; };
    735736                9360270625A3CF7600367670 /* speechrecognition-basic.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9360270525A3B28E00367670 /* speechrecognition-basic.html */; };
    736737                9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
     
    10761077                F4C8797F2059D8D3009CD00B /* ScrollViewInsetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4C8797E2059D8D3009CD00B /* ScrollViewInsetTests.mm */; };
    10771078                F4CD74C620FDACFA00DE3794 /* text-with-async-script.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CD74C520FDACF500DE3794 /* text-with-async-script.html */; };
    1078                 F4CD74C920FDB49600DE3794 /* TestURLSchemeHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CD74C820FDB49600DE3794 /* TestURLSchemeHandler.mm */; };
    10791079                F4CF32802366552200D3AD07 /* EnterKeyHintTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CF327F2366552200D3AD07 /* EnterKeyHintTests.mm */; };
    10801080                F4CFCDDA249FC9E400527482 /* SpaceOnly.otf in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CFCDD8249FC9D900527482 /* SpaceOnly.otf */; };
    10811081                F4D060082734A1AB008FA67A /* simple-editor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D060072734A08C008FA67A /* simple-editor.html */; };
    1082                 F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */; };
    10831082                F4D4F3B61E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm */; };
    10841083                F4D4F3B91E4E36E400BB2767 /* DragAndDropTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */; };
     
    13091308                                7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */,
    13101309                                CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */,
     1310                                9358C33C273ED07B00F3B38C /* file-system-access.salt in Copy Resources */,
    13111311                                F41AB9A31EF4696B0083FA08 /* file-uploading.html in Copy Resources */,
    13121312                                BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */,
     
    24502450                934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = IndexedDB.sqlite3; sourceTree = "<group>"; };
    24512451                93575C551D30366E000D604D /* focus-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "focus-inputs.html"; sourceTree = "<group>"; };
     2452                9358C33B273ED06A00F3B38C /* file-system-access.salt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "file-system-access.salt"; sourceTree = "<group>"; };
    24522453                9360270525A3B28E00367670 /* speechrecognition-basic.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "speechrecognition-basic.html"; sourceTree = "<group>"; };
    24532454                9361002814DC957B0061379D /* lots-of-iframes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-iframes.html"; sourceTree = "<group>"; };
     
    40014002                                7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */,
    40024003                                CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
     4004                                9358C33B273ED06A00F3B38C /* file-system-access.salt */,
    40034005                                F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
    40044006                                49D2E5C12731E37400BCCAED /* file-with-iframe.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm

    r285547 r285746  
    100100    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"webkit"];
    101101
    102     // load first web view & start test
    103102    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
    104103    [webView loadHTMLString:mainFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]];
     
    132131}
    133132
     133static NSString *basicString = @"<script> \
     134    async function open() \
     135    { \
     136        try { \
     137            var rootHandle = await navigator.storage.getDirectory(); \
     138            var fileHandle = await rootHandle.getFileHandle('file-system-access.txt', { 'create' : false }); \
     139            window.webkit.messageHandlers.testHandler.postMessage('file is opened'); \
     140        } catch (err) { \
     141            window.webkit.messageHandlers.testHandler.postMessage('error: ' + err.name + ' - ' + err.message); \
     142        } \
     143    } \
     144    open(); \
     145    </script>";
     146
     147TEST(FileSystemAccess, MigrateToNewStorageDirectory)
     148{
     149    NSString *hashedOrigin = @"Rpva_lVGHjojRmxI7eh92UpdZVvdH0OCis2MNCM-nDo";
     150    NSString *storageType = @"FileSystem";
     151    NSString *fileName = @"file-system-access.txt";
     152   
     153    NSFileManager *fileManager = [NSFileManager defaultManager];
     154
     155    // This is old value returned by WebsiteDataStore::defaultGeneralStorageDirectory().
     156    NSString *oldStorageDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/com.apple.WebKit.TestWebKitAPI/WebKit/Storage/"];
     157    [fileManager removeItemAtPath:oldStorageDirectory error:nil];
     158    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:oldStorageDirectory]);
     159   
     160    // Copy baked files to old directory.
     161    NSString *oldFileSystemDirectory = [NSString pathWithComponents:@[oldStorageDirectory, hashedOrigin, hashedOrigin, storageType]];
     162    [fileManager createDirectoryAtURL:[NSURL fileURLWithPath:oldFileSystemDirectory] withIntermediateDirectories:YES attributes:nil error:nil];
     163    NSString *oldFilePath = [oldFileSystemDirectory stringByAppendingPathComponent:fileName];
     164    [fileManager createFileAtPath:oldFilePath contents:nil attributes:nil];
     165    EXPECT_TRUE([fileManager fileExistsAtPath:oldFilePath]);
     166
     167    NSString *resourceSaltPath = [[NSBundle mainBundle] URLForResource:@"file-system-access" withExtension:@"salt" subdirectory:@"TestWebKitAPI.resources"].path;
     168    NSString *oldSaltPath = [oldStorageDirectory stringByAppendingPathComponent:@"salt"];
     169    [fileManager copyItemAtPath:resourceSaltPath toPath:oldSaltPath error:nil];
     170    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:oldSaltPath]);
     171
     172    // This is current value returned by WebsiteDataStore::defaultGeneralStorageDirectory().
     173    NSString *newStorageDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/Default/"];
     174    [fileManager removeItemAtPath:newStorageDirectory error:nil];
     175    NSString *newFilePath = [NSString pathWithComponents:@[newStorageDirectory, hashedOrigin, hashedOrigin, storageType, fileName]];
     176    EXPECT_FALSE([fileManager fileExistsAtPath:newFilePath]);
     177
     178    // Invoke WebsiteDataStore::defaultGeneralStorageDirectory() to trigger migration.
     179    NSString *currentStorageDirectory = [[[WKWebsiteDataStore defaultDataStore] _configuration] generalStorageDirectory].path;
     180    EXPECT_WK_STREQ(newStorageDirectory, currentStorageDirectory);
     181    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:oldFilePath]);
     182    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:newFilePath]);
     183
     184    // Ensure file can be opened after migration: test page only opens the file if it exists.
     185    auto handler = adoptNS([[FileSystemAccessMessageHandler alloc] init]);
     186    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     187    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
     188    auto preferences = [configuration preferences];
     189    preferences._fileSystemAccessEnabled = YES;
     190    preferences._storageAPIEnabled = YES;
     191
     192    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
     193    [webView loadHTMLString:basicString baseURL:[NSURL URLWithString:@"https://webkit.org"]];
     194    TestWebKitAPI::Util::run(&receivedScriptMessage);
     195    receivedScriptMessage = false;
     196    EXPECT_WK_STREQ(@"file is opened", [lastScriptMessage body]);
     197}
     198
    134199#endif // USE(APPLE_INTERNAL_SDK)
Note: See TracChangeset for help on using the changeset viewer.