summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/WebProcess/mac
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/WebProcess/mac')
-rw-r--r--Source/WebKit2/WebProcess/mac/WebProcessMac.mm98
-rw-r--r--Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm9
2 files changed, 67 insertions, 40 deletions
diff --git a/Source/WebKit2/WebProcess/mac/WebProcessMac.mm b/Source/WebKit2/WebProcess/mac/WebProcessMac.mm
index d394c98..fc06d2c 100644
--- a/Source/WebKit2/WebProcess/mac/WebProcessMac.mm
+++ b/Source/WebKit2/WebProcess/mac/WebProcessMac.mm
@@ -23,23 +23,24 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "WebProcess.h"
-
-#include "SandboxExtension.h"
-#include "WebProcessCreationParameters.h"
-#include <WebCore/MemoryCache.h>
-#include <WebCore/PageCache.h>
-#include <WebKitSystemInterface.h>
-#include <algorithm>
-#include <dispatch/dispatch.h>
-#include <mach/host_info.h>
-#include <mach/mach.h>
-#include <mach/mach_error.h>
+#import "config.h"
+#import "WebProcess.h"
+
+#import "SandboxExtension.h"
+#import "WebProcessCreationParameters.h"
+#import <WebCore/MemoryCache.h>
+#import <WebCore/PageCache.h>
+#import <WebKitSystemInterface.h>
+#import <algorithm>
+#import <dispatch/dispatch.h>
+#import <mach/host_info.h>
+#import <mach/mach.h>
+#import <mach/mach_error.h>
#if ENABLE(WEB_PROCESS_SANDBOX)
-#include <sandbox.h>
-#include <stdlib.h>
-#include <sysexits.h>
+#import <sandbox.h>
+#import <stdlib.h>
+#import <sysexits.h>
#endif
using namespace WebCore;
@@ -75,7 +76,7 @@ void WebProcess::platformSetCacheModel(CacheModel cacheModel)
{
RetainPtr<NSString> nsurlCacheDirectory(AdoptNS, (NSString *)WKCopyFoundationCacheDirectory());
if (!nsurlCacheDirectory)
- nsurlCacheDirectory.adoptNS(NSHomeDirectory());
+ nsurlCacheDirectory = NSHomeDirectory();
// As a fudge factor, use 1000 instead of 1024, in case the reported byte
// count doesn't align exactly to a megabyte boundary.
@@ -109,6 +110,27 @@ void WebProcess::platformClearResourceCaches()
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
+#if ENABLE(WEB_PROCESS_SANDBOX)
+static void appendSandboxParameterPath(Vector<const char*>& vector, const char* name, const char* path)
+{
+ char normalizedPath[PATH_MAX];
+ if (!realpath(path, normalizedPath))
+ normalizedPath[0] = '\0';
+
+ vector.append(name);
+ vector.append(fastStrDup(normalizedPath));
+}
+
+static void appendSandboxParameterConfPath(Vector<const char*>& vector, const char* name, int confID)
+{
+ char path[PATH_MAX];
+ if (confstr(confID, path, PATH_MAX) <= 0)
+ path[0] = '\0';
+
+ appendSandboxParameterPath(vector, name, path);
+}
+#endif
+
static void initializeSandbox(const WebProcessCreationParameters& parameters)
{
#if ENABLE(WEB_PROCESS_SANDBOX)
@@ -117,33 +139,29 @@ static void initializeSandbox(const WebProcessCreationParameters& parameters)
return;
}
+ Vector<const char*> sandboxParameters;
+
+ appendSandboxParameterPath(sandboxParameters, "HOME_DIR", [NSHomeDirectory() fileSystemRepresentation]);
+ appendSandboxParameterPath(sandboxParameters, "WEBKIT2_FRAMEWORK_DIR", [[[[NSBundle bundleForClass:NSClassFromString(@"WKView")] bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation]);
+ appendSandboxParameterConfPath(sandboxParameters, "DARWIN_USER_TEMP_DIR", _CS_DARWIN_USER_TEMP_DIR);
+ appendSandboxParameterConfPath(sandboxParameters, "DARWIN_USER_CACHE_DIR", _CS_DARWIN_USER_CACHE_DIR);
+ appendSandboxParameterPath(sandboxParameters, "WEBKIT_DATABASE_DIR", [(NSString *)parameters.databaseDirectory fileSystemRepresentation]);
+ appendSandboxParameterPath(sandboxParameters, "NSURL_CACHE_DIR", parameters.nsURLCachePath.data());
+ appendSandboxParameterPath(sandboxParameters, "UI_PROCESS_BUNDLE_RESOURCE_DIR", parameters.uiProcessBundleResourcePath.data());
+ sandboxParameters.append(static_cast<const char*>(0));
+
+ const char* profilePath = [[[NSBundle mainBundle] pathForResource:@"com.apple.WebProcess" ofType:@"sb"] fileSystemRepresentation];
+
char* errorBuf;
- char tmpPath[PATH_MAX];
- char tmpRealPath[PATH_MAX];
- char cachePath[PATH_MAX];
- char cacheRealPath[PATH_MAX];
- const char* frameworkPath = [[[[NSBundle bundleForClass:NSClassFromString(@"WKView")] bundlePath] stringByDeletingLastPathComponent] UTF8String];
- const char* profilePath = [[[NSBundle mainBundle] pathForResource:@"com.apple.WebProcess" ofType:@"sb"] UTF8String];
-
- if (confstr(_CS_DARWIN_USER_TEMP_DIR, tmpPath, PATH_MAX) <= 0 || !realpath(tmpPath, tmpRealPath))
- tmpRealPath[0] = '\0';
-
- if (confstr(_CS_DARWIN_USER_CACHE_DIR, cachePath, PATH_MAX) <= 0 || !realpath(cachePath, cacheRealPath))
- cacheRealPath[0] = '\0';
-
- const char* const sandboxParam[] = {
- "WEBKIT2_FRAMEWORK_DIR", frameworkPath,
- "DARWIN_USER_TEMP_DIR", (const char*)tmpRealPath,
- "DARWIN_USER_CACHE_DIR", (const char*)cacheRealPath,
- "NSURL_CACHE_DIR", (const char*)parameters.nsURLCachePath.data(),
- "UI_PROCESS_BUNDLE_RESOURCE_DIR", (const char*)parameters.uiProcessBundleResourcePath.data(),
- NULL
- };
-
- if (sandbox_init_with_parameters(profilePath, SANDBOX_NAMED_EXTERNAL, sandboxParam, &errorBuf)) {
- fprintf(stderr, "WebProcess: couldn't initialize sandbox profile [%s] with framework path [%s], tmp path [%s], cache path [%s]: %s\n", profilePath, frameworkPath, tmpRealPath, cacheRealPath, errorBuf);
+ if (sandbox_init_with_parameters(profilePath, SANDBOX_NAMED_EXTERNAL, sandboxParameters.data(), &errorBuf)) {
+ fprintf(stderr, "WebProcess: couldn't initialize sandbox profile [%s]\n", profilePath);
+ for (size_t i = 0; sandboxParameters[i]; i += 2)
+ fprintf(stderr, "%s=%s\n", sandboxParameters[i], sandboxParameters[i + 1]);
exit(EX_NOPERM);
}
+
+ for (size_t i = 0; sandboxParameters[i]; i += 2)
+ fastFree(const_cast<char*>(sandboxParameters[i + 1]));
#endif
}
diff --git a/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm b/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm
index a44dc23..846d7a1 100644
--- a/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm
+++ b/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm
@@ -23,6 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#import "config.h"
#import "WebProcessMain.h"
#import "CommandLine.h"
@@ -45,6 +46,10 @@
// FIXME: We should be doing this another way.
extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
+@interface NSApplication (WebNSApplicationDetails)
+-(void)_installAutoreleasePoolsOnCurrentThreadIfNecessary;
+@end
+
#define SHOW_CRASH_REPORTER 1
using namespace WebCore;
@@ -88,6 +93,10 @@ int WebProcessMain(const CommandLine& commandLine)
// Initialize AppKit.
[NSApplication sharedApplication];
+ // Installs autorelease pools on the current CFRunLoop which prevents memory from accumulating between user events.
+ // FIXME: Remove when <rdar://problem/8929426> is fixed.
+ [[NSApplication sharedApplication] _installAutoreleasePoolsOnCurrentThreadIfNecessary];
+
#if !defined(BUILDING_ON_SNOW_LEOPARD)
WKAXRegisterRemoteApp();
#endif