Add SPI _WKProcessPoolConfiguration.javaScriptConfigurationDirectory
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jul 2019 17:19:29 +0000 (17:19 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jul 2019 17:19:29 +0000 (17:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199917

Reviewed by Sam Weinig.

Source/WebKit:

* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration javaScriptConfigurationDirectory]):
(-[_WKProcessPoolConfiguration setJavaScriptConfigurationDirectory:]):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::sendWebProcessDataStoreParameters):

Tools:

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

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm

index ae1863a..c9fd200 100644 (file)
@@ -1,3 +1,17 @@
+2019-07-22  Alex Christensen  <achristensen@webkit.org>
+
+        Add SPI _WKProcessPoolConfiguration.javaScriptConfigurationDirectory
+        https://bugs.webkit.org/show_bug.cgi?id=199917
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        (-[_WKProcessPoolConfiguration javaScriptConfigurationDirectory]):
+        (-[_WKProcessPoolConfiguration setJavaScriptConfigurationDirectory:]):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::sendWebProcessDataStoreParameters):
+
 2019-07-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [SOUP] WebSockets: use new api to send text messages
index fdd411f..eea4297 100644 (file)
@@ -45,6 +45,8 @@ WK_CLASS_AVAILABLE(macos(10.10), ios(8.0))
 @property (nonatomic) NSUInteger wirelessContextIdentifier WK_API_DEPRECATED("Use of this API is no longer necessary and can be removed", ios(10.12, WK_IOS_TBA));
 #endif
 
+@property (nonatomic, nullable, copy) NSURL *javaScriptConfigurationDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 // Network Process properties
 // FIXME: These should be be per-session/data store when we support multiple non-persistent sessions/data stores.
 
index dec574c..2192d87 100644 (file)
     return _processPoolConfiguration->setAttrStyleEnabled(enabled);
 }
 
+- (NSURL *)javaScriptConfigurationDirectory
+{
+    return [NSURL fileURLWithPath:_processPoolConfiguration->javaScriptConfigurationDirectory() isDirectory:YES];
+}
+
+- (void)setJavaScriptConfigurationDirectory:(NSURL *)directory
+{
+    if (directory && ![directory isFileURL])
+        [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", directory];
+    _processPoolConfiguration->setJavaScriptConfigurationDirectory(directory.path);
+}
+
 - (NSArray<NSURL *> *)additionalReadAccessAllowedURLs
 {
     auto paths = _processPoolConfiguration->additionalReadAccessAllowedPaths();
index a20fa29..5b43996 100644 (file)
@@ -890,11 +890,13 @@ void WebProcessPool::sendWebProcessDataStoreParameters(WebProcessProxy& process,
     if (!parameters.mediaKeyStorageDirectory.isEmpty())
         SandboxExtension::createHandleWithoutResolvingPath(parameters.mediaKeyStorageDirectory, SandboxExtension::Type::ReadWrite, parameters.mediaKeyStorageDirectoryExtensionHandle);
 
-    if (javaScriptConfigurationFileEnabled()) {
+    
+    if (auto& directory = configuration().javaScriptConfigurationDirectory(); !directory.isEmpty())
+        parameters.javaScriptConfigurationDirectory = directory;
+    if (javaScriptConfigurationFileEnabled())
         parameters.javaScriptConfigurationDirectory = websiteDataStore.resolvedJavaScriptConfigurationDirectory();
-        if (!parameters.javaScriptConfigurationDirectory.isEmpty())
-            SandboxExtension::createHandleWithoutResolvingPath(parameters.javaScriptConfigurationDirectory, SandboxExtension::Type::ReadWrite, parameters.javaScriptConfigurationDirectoryExtensionHandle);
-    }
+    if (!parameters.javaScriptConfigurationDirectory.isEmpty())
+        SandboxExtension::createHandleWithoutResolvingPath(parameters.javaScriptConfigurationDirectory, SandboxExtension::Type::ReadWrite, parameters.javaScriptConfigurationDirectoryExtensionHandle);
 
     parameters.resourceLoadStatisticsEnabled = websiteDataStore.resourceLoadStatisticsEnabled();
 
index 2a8ccbf..7cb4597 100644 (file)
@@ -1,3 +1,13 @@
+2019-07-22  Alex Christensen  <achristensen@webkit.org>
+
+        Add SPI _WKProcessPoolConfiguration.javaScriptConfigurationDirectory
+        https://bugs.webkit.org/show_bug.cgi?id=199917
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm:
+        (TEST):
+
 2019-07-22  Aakash Jain  <aakash_jain@apple.com>
 
         [ews-build] ReRunWebKitTests should use similar logic for evaluateCommand as RunWebKitTests
index d3b530d..d6143af 100644 (file)
  */
 
 #import "config.h"
-#import <WebKit/WKFoundation.h>
 
+#import "Utilities.h"
+#import <WebKit/WKFoundation.h>
+#import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <wtf/RetainPtr.h>
 
@@ -81,3 +83,39 @@ TEST(WKProcessPoolConfiguration, Copy)
     EXPECT_EQ([configuration pageCacheEnabled], [copy pageCacheEnabled]);
     EXPECT_EQ([configuration suppressesConnectionTerminationOnSystemChange], [copy suppressesConnectionTerminationOnSystemChange]);
 }
+
+TEST(WKProcessPoolConfiguration, JavaScriptConfiguration)
+{
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"CustomPathsTest"] isDirectory:YES];
+    NSError *error = nil;
+    BOOL success = [fileManager createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:&error];
+    EXPECT_TRUE(success);
+    EXPECT_FALSE(error);
+
+    NSData *contents = [@""
+    "processName =~ /WebContent/ {\n"
+        "logFile = \"Log.txt\"\n"
+        "jscOptions {\n"
+            "dumpOptions = 1\n"
+            "dumpDFGDisassembly = true\n"
+        "}\n"
+    "}"
+    "" dataUsingEncoding:NSUTF8StringEncoding];
+    BOOL result = [contents writeToURL:[tempDir URLByAppendingPathComponent:@"JSC.config"] atomically:YES];
+    EXPECT_TRUE(result);
+
+    auto poolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
+    [poolConfiguration setJavaScriptConfigurationDirectory:tempDir];
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [webViewConfiguration setProcessPool:[[[WKProcessPool alloc] _initWithConfiguration:poolConfiguration.get()] autorelease]];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    [webView loadHTMLString:@"<html>hello</html>" baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+
+    NSString *path = [tempDir URLByAppendingPathComponent:@"Log.txt"].path;
+    while (![fileManager fileExistsAtPath:path])
+        TestWebKitAPI::Util::spinRunLoop();
+    [fileManager removeItemAtPath:tempDir.path error:&error];
+    EXPECT_FALSE(error);
+}