Add SPI to _WKWebsiteDataStoreConfiguration for configuring application cache storage...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jul 2019 17:21:09 +0000 (17:21 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jul 2019 17:21:09 +0000 (17:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199954

Reviewed by Geoff Garen.

Source/WebKit:

This is a step towards removing WebsiteDataStore::legacyDefaultDataStoreConfiguration
Covered by a new API test.

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _initWithConfiguration:]):
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
(-[_WKWebsiteDataStoreConfiguration applicationCacheDirectory]):
(-[_WKWebsiteDataStoreConfiguration setApplicationCacheDirectory:]):
(-[_WKWebsiteDataStoreConfiguration applicationCacheFlatFileSubdirectoryName]):
(-[_WKWebsiteDataStoreConfiguration setApplicationCacheFlatFileSubdirectoryName:]):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::sendWebProcessDataStoreParameters):
* UIProcess/WebsiteData/WebsiteDataStore.h:
(WebKit::WebsiteDataStore::applicationCacheFlatFileSubdirectoryName const):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247686 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm

index c9fd200..c651661 100644 (file)
@@ -1,5 +1,28 @@
 2019-07-22  Alex Christensen  <achristensen@webkit.org>
 
+        Add SPI to _WKWebsiteDataStoreConfiguration for configuring application cache storage location
+        https://bugs.webkit.org/show_bug.cgi?id=199954
+
+        Reviewed by Geoff Garen.
+
+        This is a step towards removing WebsiteDataStore::legacyDefaultDataStoreConfiguration
+        Covered by a new API test.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _initWithConfiguration:]):
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
+        (-[_WKWebsiteDataStoreConfiguration applicationCacheDirectory]):
+        (-[_WKWebsiteDataStoreConfiguration setApplicationCacheDirectory:]):
+        (-[_WKWebsiteDataStoreConfiguration applicationCacheFlatFileSubdirectoryName]):
+        (-[_WKWebsiteDataStoreConfiguration setApplicationCacheFlatFileSubdirectoryName:]):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::sendWebProcessDataStoreParameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        (WebKit::WebsiteDataStore::applicationCacheFlatFileSubdirectoryName const):
+
+2019-07-22  Alex Christensen  <achristensen@webkit.org>
+
         Add SPI _WKProcessPoolConfiguration.javaScriptConfigurationDirectory
         https://bugs.webkit.org/show_bug.cgi?id=199917
 
index 2d10a0b..528f9d9 100644 (file)
@@ -252,6 +252,10 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
             config->setNetworkCacheDirectory(configuration.networkCacheDirectory.path);
         if (configuration.deviceIdHashSaltsStorageDirectory)
             config->setDeviceIdHashSaltsStorageDirectory(configuration.deviceIdHashSaltsStorageDirectory.path);
+        if (configuration.applicationCacheDirectory)
+            config->setApplicationCacheDirectory(configuration.applicationCacheDirectory.path);
+        if (configuration.applicationCacheFlatFileSubdirectoryName)
+            config->setApplicationCacheFlatFileSubdirectoryName(configuration.applicationCacheFlatFileSubdirectoryName);
     } else {
         RELEASE_ASSERT(!configuration._webStorageDirectory);
         RELEASE_ASSERT(!configuration._webSQLDatabaseDirectory);
@@ -262,6 +266,7 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
         RELEASE_ASSERT(!configuration._serviceWorkerRegistrationDirectory);
         RELEASE_ASSERT(!configuration.networkCacheDirectory);
         RELEASE_ASSERT(!configuration.deviceIdHashSaltsStorageDirectory);
+        RELEASE_ASSERT(!configuration.applicationCacheDirectory);
     }
 
     if (configuration.sourceApplicationBundleIdentifier)
index 0d3cc63..c88fc88 100644 (file)
@@ -55,6 +55,8 @@ WK_CLASS_AVAILABLE(macos(10.13), ios(11.0))
 @property (nonatomic, copy, setter=_setServiceWorkerRegistrationDirectory:) NSURL *_serviceWorkerRegistrationDirectory WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
 @property (nonatomic, nullable, copy) NSURL *networkCacheDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, nullable, copy) NSURL *deviceIdHashSaltsStorageDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, nullable, copy) NSURL *applicationCacheDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, nullable, copy) NSString *applicationCacheFlatFileSubdirectoryName WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 // Testing only.
 @property (nonatomic) BOOL allLoadsBlockedByDeviceManagementRestrictionsForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
index e8aecbf..ef1ed91 100644 (file)
@@ -223,6 +223,31 @@ static void checkURLArgument(NSURL *url)
     _configuration->setSourceApplicationSecondaryIdentifier(identifier);
 }
 
+- (NSURL *)applicationCacheDirectory
+{
+    return [NSURL fileURLWithPath:_configuration->applicationCacheDirectory() isDirectory:YES];
+}
+
+- (void)setApplicationCacheDirectory:(NSURL *)url
+{
+    if (!_configuration->isPersistent())
+        [NSException raise:NSInvalidArgumentException format:@"Cannot set applicationCacheDirectory on a non-persistent _WKWebsiteDataStoreConfiguration."];
+    checkURLArgument(url);
+    _configuration->setApplicationCacheDirectory(url.path);
+}
+
+- (NSString *)applicationCacheFlatFileSubdirectoryName
+{
+    return _configuration->applicationCacheFlatFileSubdirectoryName();
+}
+
+- (void)setApplicationCacheFlatFileSubdirectoryName:(NSString *)name
+{
+    if (!_configuration->isPersistent())
+        [NSException raise:NSInvalidArgumentException format:@"Cannot set applicationCacheFlatFileSubdirectoryName on a non-persistent _WKWebsiteDataStoreConfiguration."];
+    _configuration->setApplicationCacheFlatFileSubdirectoryName(name);
+}
+
 - (BOOL)deviceManagementRestrictionsEnabled
 {
     return _configuration->deviceManagementRestrictionsEnabled();
index 5b43996..ca2d209 100644 (file)
@@ -870,7 +870,9 @@ void WebProcessPool::sendWebProcessDataStoreParameters(WebProcessProxy& process,
         parameters.applicationCacheDirectory = m_resolvedPaths.applicationCacheDirectory;
     if (!parameters.applicationCacheDirectory.isEmpty())
         SandboxExtension::createHandleWithoutResolvingPath(parameters.applicationCacheDirectory, SandboxExtension::Type::ReadWrite, parameters.applicationCacheDirectoryExtensionHandle);
-    parameters.applicationCacheFlatFileSubdirectoryName = m_configuration->applicationCacheFlatFileSubdirectoryName();
+    parameters.applicationCacheFlatFileSubdirectoryName = websiteDataStore.applicationCacheFlatFileSubdirectoryName();
+    if (parameters.applicationCacheFlatFileSubdirectoryName.isEmpty())
+        parameters.applicationCacheFlatFileSubdirectoryName = m_configuration->applicationCacheFlatFileSubdirectoryName();
 
     parameters.webSQLDatabaseDirectory = websiteDataStore.resolvedDatabaseDirectory();
     if (parameters.webSQLDatabaseDirectory.isEmpty())
index cf760fc..5dc9bca 100644 (file)
@@ -182,6 +182,7 @@ public:
     void setCacheMaxAgeCapForPrevalentResources(Seconds, CompletionHandler<void()>&&);
     void resetCacheMaxAgeCapForPrevalentResources(CompletionHandler<void()>&&);
     void resolveDirectoriesIfNecessary();
+    const String& applicationCacheFlatFileSubdirectoryName() const { return m_configuration->applicationCacheFlatFileSubdirectoryName(); }
     const String& resolvedApplicationCacheDirectory() const { return m_resolvedConfiguration->applicationCacheDirectory(); }
     const String& resolvedLocalStorageDirectory() const { return m_resolvedConfiguration->localStorageDirectory(); }
     const String& resolvedNetworkCacheDirectory() const { return m_resolvedConfiguration->networkCacheDirectory(); }
index 7cb4597..25d5db1 100644 (file)
@@ -1,5 +1,15 @@
 2019-07-22  Alex Christensen  <achristensen@webkit.org>
 
+        Add SPI to _WKWebsiteDataStoreConfiguration for configuring application cache storage location
+        https://bugs.webkit.org/show_bug.cgi?id=199954
+
+        Reviewed by Geoff Garen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+        (TEST):
+
+2019-07-22  Alex Christensen  <achristensen@webkit.org>
+
         Add SPI _WKProcessPoolConfiguration.javaScriptConfigurationDirectory
         https://bugs.webkit.org/show_bug.cgi?id=199917
 
index 5f5ca5e..030cdea 100644 (file)
@@ -554,3 +554,60 @@ TEST(WebKit, NetworkCacheDirectory)
     [fileManager removeItemAtPath:path error:&error];
     EXPECT_FALSE(error);
 }
+
+TEST(WebKit, ApplicationCacheDirectories)
+{
+    using namespace TestWebKitAPI;
+    TCPServer server([] (int socket) {
+        TCPServer::read(socket);
+        const char* firstResponse =
+        "HTTP/1.1 200 OK\r\n"
+        "Content-Length: 31\r\n\r\n"
+        "<html manifest='test.appcache'>";
+        TCPServer::write(socket, firstResponse, strlen(firstResponse));
+        
+        TCPServer::read(socket);
+        const char* secondResponse =
+        "HTTP/1.1 200 OK\r\n"
+        "Content-Length: 35\r\n\r\n"
+        "CACHE MANIFEST\n"
+        "index.html\n"
+        "test.mp4\n";
+        TCPServer::write(socket, secondResponse, strlen(secondResponse));
+
+        TCPServer::read(socket);
+        TCPServer::write(socket, firstResponse, strlen(firstResponse));
+        
+        const char* videoResponse =
+        "HTTP/1.1 200 OK\r\n"
+        "Content-Type: video/test\r\n"
+        "Content-Length: 5\r\n\r\n"
+        "test!";
+        TCPServer::read(socket);
+        TCPServer::write(socket, videoResponse, strlen(videoResponse));
+    });
+    
+    NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"CustomPathsTest"] isDirectory:YES];
+    NSString *path = tempDir.path;
+    NSString *subdirectoryPath = [path stringByAppendingPathComponent:@"testsubdirectory"];
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    EXPECT_FALSE([fileManager fileExistsAtPath:subdirectoryPath]);
+
+    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+
+    [websiteDataStoreConfiguration setApplicationCacheDirectory:tempDir];
+    [websiteDataStoreConfiguration setApplicationCacheFlatFileSubdirectoryName:@"testsubdirectory"];
+    
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [webViewConfiguration setWebsiteDataStore:[[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease]];
+    
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/index.html", server.port()]]]];
+
+    while (![fileManager fileExistsAtPath:subdirectoryPath])
+        Util::spinRunLoop();
+
+    NSError *error = nil;
+    [fileManager removeItemAtPath:path error:&error];
+    EXPECT_FALSE(error);
+}