Expose the location of website data
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jun 2014 23:36:45 +0000 (23:36 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jun 2014 23:36:45 +0000 (23:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134000
<rdar://problem/17350498>

Reviewed by Dan Bernstein.

Also, remove the bundle ID from the website data path for containerized apps.

* Shared/mac/SandboxUtilities.cpp:
(WebKit::processIsAppSandboxed):
* Shared/mac/SandboxUtilities.h:
* UIProcess/API/Cocoa/WKProcessPool.mm:
(+[WKProcessPool _websiteDataURLForContainerWithURL:]):
(websiteDataDirectoryURL):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/SandboxUtilities.cpp
Source/WebKit2/Shared/mac/SandboxUtilities.h
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h

index b4f33b6..301225f 100644 (file)
@@ -1,3 +1,21 @@
+2014-06-17  Anders Carlsson  <andersca@apple.com>
+
+        Expose the location of website data
+        https://bugs.webkit.org/show_bug.cgi?id=134000
+        <rdar://problem/17350498>
+
+        Reviewed by Dan Bernstein.
+
+        Also, remove the bundle ID from the website data path for containerized apps.
+
+        * Shared/mac/SandboxUtilities.cpp:
+        (WebKit::processIsAppSandboxed):
+        * Shared/mac/SandboxUtilities.h:
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (+[WKProcessPool _websiteDataURLForContainerWithURL:]):
+        (websiteDataDirectoryURL):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+
 2014-06-17  Jeremy Jones  <jeremyj@apple.com>
 
         Improve enter and exit fullscreen transition by using two step transition.
index 9276e41..0e9558d 100644 (file)
 #include "config.h"
 #include "SandboxUtilities.h"
 
+#include <array>
+
 #if __has_include(<sandbox/private.h>)
 #import <sandbox/private.h>
 #else
 enum sandbox_filter_type {
     SANDBOX_FILTER_NONE,
 };
-extern "C"
+extern "C" {
 int sandbox_check(pid_t, const char *operation, enum sandbox_filter_type, ...);
+int sandbox_container_path_for_pid(pid_t, char *buffer, size_t bufsize);
+}
 #endif
 
 namespace WebKit {
@@ -43,4 +47,24 @@ bool processIsSandboxed(pid_t pid)
     return sandbox_check(pid, nullptr, SANDBOX_FILTER_NONE);
 }
 
+static bool processHasContainer(pid_t pid)
+{
+    std::array<char, MAXPATHLEN> path;
+
+    if (sandbox_container_path_for_pid(pid, path.data(), path.size()))
+        return false;
+
+    if (!path[0])
+        return false;
+
+    return true;
+}
+
+bool processHasContainer()
+{
+    static bool hasContainer = processHasContainer(getpid());
+
+    return hasContainer;
+}
+
 }
index 7a9e0f2..903ae1b 100644 (file)
@@ -31,6 +31,7 @@
 namespace WebKit {
 
 bool processIsSandboxed(pid_t);
+bool processHasContainer();
 
 }
 
index e75652b..ce7abc2 100644 (file)
@@ -32,6 +32,7 @@
 #import "DownloadClient.h"
 #import "HistoryClient.h"
 #import "ProcessModel.h"
+#import "SandboxUtilities.h"
 #import "WKObject.h"
 #import "WeakObjCPtr.h"
 #import "WebCertificateInfo.h"
@@ -104,6 +105,13 @@ enum : NSUInteger {
 
 @implementation WKProcessPool (WKPrivate)
 
++ (NSURL *)_websiteDataURLForContainerWithURL:(NSURL *)containerURL
+{
+    NSURL *url = [containerURL URLByAppendingPathComponent:@"Library" isDirectory:YES];
+    url = [url URLByAppendingPathComponent:@"WebKit" isDirectory:YES];
+    return [url URLByAppendingPathComponent:@"WebsiteData" isDirectory:YES];
+}
+
 static NSURL *websiteDataDirectoryURL(NSString *directoryName)
 {
     static dispatch_once_t onceToken;
@@ -116,11 +124,12 @@ static NSURL *websiteDataDirectoryURL(NSString *directoryName)
 
         url = [url URLByAppendingPathComponent:@"WebKit" isDirectory:YES];
 
-        NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
-        if (!bundleIdentifier)
-            bundleIdentifier = [NSProcessInfo processInfo].processName;
-
-        url = [url URLByAppendingPathComponent:bundleIdentifier isDirectory:YES];
+        if (!WebKit::processHasContainer()) {
+            NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
+            if (!bundleIdentifier)
+                bundleIdentifier = [NSProcessInfo processInfo].processName;
+            url = [url URLByAppendingPathComponent:bundleIdentifier isDirectory:YES];
+        }
 
         websiteDataURL = [[url URLByAppendingPathComponent:@"WebsiteData" isDirectory:YES] retain];
     });
index 7ae2faa..8ed3e02 100644 (file)
@@ -44,6 +44,8 @@
 
 @property (nonatomic, weak, setter=_setDownloadDelegate:) id <_WKDownloadDelegate> _downloadDelegate;
 
++ (NSURL *)_websiteDataURLForContainerWithURL:(NSURL *)containerURL;
+
 @end
 
 #endif