Add network and application cache directories to WebsiteDataStore
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2015 23:37:04 +0000 (23:37 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2015 23:37:04 +0000 (23:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143063

Reviewed by Sam Weinig.

Create a WebKit directory under ~/Library/Caches/<Bundle ID> for non-sandboxed applications,
and ~/Library/Caches for sandboxed applications. Create NetworkCache and OfflineWebApplicationCache
subdirectories. These directories will be used with the modern WebKit API.

* UIProcess/API/APIWebsiteDataStore.h:
* UIProcess/API/Cocoa/APIWebsiteDataStoreCocoa.mm:
(API::WebsiteDataStore::cacheDirectoryFileSystemRepresentation):
(API::WebsiteDataStore::defaultDataStoreConfiguration):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::WebsiteDataStore):
* UIProcess/WebsiteData/WebsiteDataStore.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIWebsiteDataStore.h
Source/WebKit2/UIProcess/API/Cocoa/APIWebsiteDataStoreCocoa.mm
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/MiniBrowser/MiniBrowser.entitlements [new file with mode: 0644]
Tools/MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj

index 9f8b01b4d0e09376aab3ff521f98d4f526684745..d6afdc271812a67894be7b7c3d61845f63be1c18 100644 (file)
@@ -1,3 +1,22 @@
+2015-03-25  Anders Carlsson  <andersca@apple.com>
+
+        Add network and application cache directories to WebsiteDataStore
+        https://bugs.webkit.org/show_bug.cgi?id=143063
+
+        Reviewed by Sam Weinig.
+
+        Create a WebKit directory under ~/Library/Caches/<Bundle ID> for non-sandboxed applications,
+        and ~/Library/Caches for sandboxed applications. Create NetworkCache and OfflineWebApplicationCache
+        subdirectories. These directories will be used with the modern WebKit API.
+
+        * UIProcess/API/APIWebsiteDataStore.h:
+        * UIProcess/API/Cocoa/APIWebsiteDataStoreCocoa.mm:
+        (API::WebsiteDataStore::cacheDirectoryFileSystemRepresentation):
+        (API::WebsiteDataStore::defaultDataStoreConfiguration):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::WebsiteDataStore):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2015-03-25  Sam Weinig  <sam@webkit.org>
 
         Address additional review feedback from https://bugs.webkit.org/show_bug.cgi?id=143059.
index c155fa36f185c0ce833c7c75fa64a047b57711dc..08075f9242a4cf7d20115207017939635cdc383a 100644 (file)
@@ -44,6 +44,7 @@ public:
 
     WebKit::WebsiteDataStore& websiteDataStore() { return *m_websiteDataStore; }
 
+    static String cacheDirectoryFileSystemRepresentation(const String& directoryName);
     static String websiteDataDirectoryFileSystemRepresentation(const String& directoryName);
 
 private:
index a363d9b8e27e205b2a39ff534ed49c9f2a4ac655..fa788949ed60f3f60dc93d603b141fb2d354407b 100644 (file)
 
 namespace API {
 
+String WebsiteDataStore::cacheDirectoryFileSystemRepresentation(const String& directoryName)
+{
+    static dispatch_once_t onceToken;
+    static NSURL *cacheURL;
+
+    dispatch_once(&onceToken, ^{
+        NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nullptr create:NO error:nullptr];
+        if (!url)
+            RELEASE_ASSERT_NOT_REACHED();
+
+        if (!WebKit::processHasContainer()) {
+            NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
+            if (!bundleIdentifier)
+                bundleIdentifier = [NSProcessInfo processInfo].processName;
+            url = [url URLByAppendingPathComponent:bundleIdentifier isDirectory:YES];
+        }
+
+        cacheURL = [[url URLByAppendingPathComponent:@"WebKit" isDirectory:YES] retain];
+    });
+
+    NSURL *url = [cacheURL URLByAppendingPathComponent:directoryName isDirectory:YES];
+    if (![[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
+        LOG_ERROR("Failed to create directory %@", url);
+
+    return url.absoluteURL.path.fileSystemRepresentation;
+}
+
 String WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation(const String& directoryName)
 {
     static dispatch_once_t onceToken;
@@ -61,11 +88,13 @@ String WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation(const Stri
 
 WebKit::WebsiteDataStore::Configuration WebsiteDataStore::defaultDataStoreConfiguration()
 {
-    // FIXME: Fill everything in.
     WebKit::WebsiteDataStore::Configuration configuration;
 
-    configuration.localStorageDirectory = websiteDataDirectoryFileSystemRepresentation("LocalStorage");
+    configuration.networkCacheDirectory = cacheDirectoryFileSystemRepresentation("NetworkCache");
+    configuration.applicationCacheDirectory = cacheDirectoryFileSystemRepresentation("OfflineWebApplicationCache");
+
     configuration.webSQLDatabaseDirectory = websiteDataDirectoryFileSystemRepresentation("WebSQL");
+    configuration.localStorageDirectory = websiteDataDirectoryFileSystemRepresentation("LocalStorage");
 
     return configuration;
 }
index cde4ed621a565dcd97e752911a090ae60e189c90..e0d0a6e346be46b6b9ed7ec0d1d378ea28d0cbf7 100644 (file)
@@ -64,6 +64,8 @@ RefPtr<WebsiteDataStore> WebsiteDataStore::create(Configuration configuration)
 WebsiteDataStore::WebsiteDataStore(Configuration configuration)
     : m_identifier(generateIdentifier())
     , m_sessionID(WebCore::SessionID::defaultSessionID())
+    , m_networkCacheDirectory(WTF::move(configuration.networkCacheDirectory))
+    , m_applicationCacheDirectory(WTF::move(configuration.applicationCacheDirectory))
     , m_webSQLDatabaseDirectory(WTF::move(configuration.webSQLDatabaseDirectory))
     , m_storageManager(StorageManager::create(WTF::move(configuration.localStorageDirectory)))
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
index ebc8f3d1e0df176c6fb031b9c2dd253383902722..a617a7c61e82add6e5a888ae6dd54007b19942dc 100644 (file)
@@ -45,6 +45,9 @@ struct WebsiteDataRecord;
 class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver {
 public:
     struct Configuration {
+        String networkCacheDirectory;
+        String applicationCacheDirectory;
+
         String webSQLDatabaseDirectory;
         String localStorageDirectory;
     };
@@ -83,6 +86,9 @@ private:
     const uint64_t m_identifier;
     const WebCore::SessionID m_sessionID;
 
+    const String m_networkCacheDirectory;
+    const String m_applicationCacheDirectory;
+
     const String m_webSQLDatabaseDirectory;
     const RefPtr<StorageManager> m_storageManager;
 
diff --git a/Tools/MiniBrowser/MiniBrowser.entitlements b/Tools/MiniBrowser/MiniBrowser.entitlements
new file mode 100644 (file)
index 0000000..ee95ab7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>com.apple.security.app-sandbox</key>
+       <true/>
+       <key>com.apple.security.network.client</key>
+       <true/>
+</dict>
+</plist>
index 0196d0979f847d725e65746b8427e28e4cac0cee..9552aba1f408b4f5a0bfaee018b3d2505b1223c5 100644 (file)
@@ -54,6 +54,7 @@
                0FE643A2161FAC660059E3FF /* WK1BrowserWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WK1BrowserWindowController.h; path = mac/WK1BrowserWindowController.h; sourceTree = "<group>"; };
                0FE643A3161FAC660059E3FF /* WK1BrowserWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WK1BrowserWindowController.m; path = mac/WK1BrowserWindowController.m; sourceTree = "<group>"; };
                1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+               1AFF1A6C1AC35D45007AB10C /* MiniBrowser.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = MiniBrowser.entitlements; sourceTree = "<group>"; };
                1AFFEF751860EE6700DA465E /* MiniBrowser.wkbundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MiniBrowser.wkbundle; sourceTree = BUILT_PRODUCTS_DIR; };
                1AFFEF761860EE6800DA465E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
                1AFFEF781860EE6800DA465E /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
                080E96DDFE201D6D7F000001 /* MiniBrowser */ = {
                        isa = PBXGroup;
                        children = (
+                               1AFF1A6C1AC35D45007AB10C /* MiniBrowser.entitlements */,
                                256AC3D80F4B6AC300CF3369 /* AppDelegate.h */,
                                256AC3D90F4B6AC300CF3369 /* AppDelegate.m */,
                                0FE6439F161FA8940059E3FF /* BrowserWindowController.h */,
                        isa = PBXProject;
                        attributes = {
                                LastUpgradeCheck = 0600;
+                               TargetAttributes = {
+                                       8D1107260486CEB800E47090 = {
+                                               SystemCapabilities = {
+                                                       com.apple.Sandbox = {
+                                                               enabled = 1;
+                                                       };
+                                               };
+                                       };
+                               };
                        };
                        buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MiniBrowser" */;
                        compatibilityVersion = "Xcode 3.2";
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = BCA8CBDF11E578A000812FB7 /* MiniBrowser.xcconfig */;
                        buildSettings = {
+                               CODE_SIGN_ENTITLEMENTS = MiniBrowser.entitlements;
+                               CODE_SIGN_IDENTITY = "";
                        };
                        name = Debug;
                };
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = BCA8CBDF11E578A000812FB7 /* MiniBrowser.xcconfig */;
                        buildSettings = {
+                               CODE_SIGN_ENTITLEMENTS = MiniBrowser.entitlements;
+                               CODE_SIGN_IDENTITY = "";
                        };
                        name = Release;
                };