<rdar://problem/9127270> and https://bugs.webkit.org/show_bug.cgi?id=56282
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Mar 2011 05:47:55 +0000 (05:47 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Mar 2011 05:47:55 +0000 (05:47 +0000)
Reviewed by Sam Weinig.

Pass the path along with creation parameters:
* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:

Add SPI to set the path:
* UIProcess/API/C/WKContext.cpp:
(WKContextSetLocalStorageDirectory):
* UIProcess/API/C/WKContextPrivate.h:

Pass the path along in the process creation parameters:
* UIProcess/WebContext.cpp:
(WebKit::WebContext::ensureWebProcess):
(WebKit::WebContext::localStorageDirectory):
* UIProcess/WebContext.h:
(WebKit::WebContext::setLocalStorageDirectory):

* UIProcess/gtk/WebContextGtk.cpp:
(WebKit::WebContext::platformDefaultLocalStorageDirectory):
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::platformDefaultLocalStorageDirectory):
* UIProcess/qt/WebContextQt.cpp:
(WebKit::WebContext::platformDefaultLocalStorageDirectory):
* UIProcess/win/WebContextWin.cpp:
(WebKit::WebContext::platformDefaultLocalStorageDirectory):

Include the path with settings updates, because WebCore needs it set on the Settings object:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
* WebProcess/WebProcess.h:
(WebKit::WebProcess::localStorageDirectory):

Sandboxing stuff:
* WebProcess/com.apple.WebProcess.sb:
* WebProcess/mac/WebProcessMac.mm:
(WebKit::initializeSandbox):

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

16 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebProcessCreationParameters.cpp
Source/WebKit2/Shared/WebProcessCreationParameters.h
Source/WebKit2/UIProcess/API/C/WKContext.cpp
Source/WebKit2/UIProcess/API/C/WKContextPrivate.h
Source/WebKit2/UIProcess/WebContext.cpp
Source/WebKit2/UIProcess/WebContext.h
Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp
Source/WebKit2/UIProcess/mac/WebContextMac.mm
Source/WebKit2/UIProcess/qt/WebContextQt.cpp
Source/WebKit2/UIProcess/win/WebContextWin.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/com.apple.WebProcess.sb
Source/WebKit2/WebProcess/mac/WebProcessMac.mm

index 4270a3c..71e3681 100644 (file)
@@ -1,3 +1,50 @@
+2011-03-13  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <rdar://problem/9127270> and https://bugs.webkit.org/show_bug.cgi?id=56282
+
+        Pass the path along with creation parameters:
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+
+        Add SPI to set the path:
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextSetLocalStorageDirectory):
+        * UIProcess/API/C/WKContextPrivate.h:
+
+        Pass the path along in the process creation parameters:
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::ensureWebProcess):
+        (WebKit::WebContext::localStorageDirectory):
+        * UIProcess/WebContext.h:
+        (WebKit::WebContext::setLocalStorageDirectory):
+
+        * UIProcess/gtk/WebContextGtk.cpp:
+        (WebKit::WebContext::platformDefaultLocalStorageDirectory):
+        * UIProcess/mac/WebContextMac.mm:
+        (WebKit::WebContext::platformDefaultLocalStorageDirectory):
+        * UIProcess/qt/WebContextQt.cpp:
+        (WebKit::WebContext::platformDefaultLocalStorageDirectory):
+        * UIProcess/win/WebContextWin.cpp:
+        (WebKit::WebContext::platformDefaultLocalStorageDirectory):
+
+        Include the path with settings updates, because WebCore needs it set on the Settings object:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        * WebProcess/WebProcess.h:
+        (WebKit::WebProcess::localStorageDirectory):
+
+        Sandboxing stuff:
+        * WebProcess/com.apple.WebProcess.sb:
+        * WebProcess/mac/WebProcessMac.mm:
+        (WebKit::initializeSandbox):
+
 2011-03-12  Jer Noble  <jer.noble@apple.com>
 
         Reviewed by Mark Rowe.
index 360c6d7..cdb40a0 100644 (file)
@@ -51,6 +51,7 @@ void WebProcessCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) con
     encoder->encode(injectedBundlePathExtensionHandle);
     encoder->encode(applicationCacheDirectory);
     encoder->encode(databaseDirectory);
+    encoder->encode(localStorageDirectory);
     encoder->encode(urlSchemesRegistererdAsEmptyDocument);
     encoder->encode(urlSchemesRegisteredAsSecure);
     encoder->encode(urlSchemesForWhichDomainRelaxationIsForbidden);
@@ -92,6 +93,8 @@ bool WebProcessCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, Web
         return false;
     if (!decoder->decode(parameters.databaseDirectory))
         return false;
+    if (!decoder->decode(parameters.localStorageDirectory))
+        return false;
     if (!decoder->decode(parameters.urlSchemesRegistererdAsEmptyDocument))
         return false;
     if (!decoder->decode(parameters.urlSchemesRegisteredAsSecure))
index a57be99..7adf73e 100644 (file)
@@ -54,6 +54,7 @@ struct WebProcessCreationParameters {
 
     String applicationCacheDirectory;
     String databaseDirectory;
+    String localStorageDirectory;
     Vector<String> urlSchemesRegistererdAsEmptyDocument;
     Vector<String> urlSchemesRegisteredAsSecure;
     Vector<String> urlSchemesForWhichDomainRelaxationIsForbidden;
index 561dc33..ca7829f 100644 (file)
@@ -207,3 +207,8 @@ void WKContextSetDatabaseDirectory(WKContextRef contextRef, WKStringRef database
 {
     toImpl(contextRef)->setDatabaseDirectory(toImpl(databaseDirectory)->string());
 }
+
+void WKContextSetLocalStorageDirectory(WKContextRef contextRef, WKStringRef localStorageDirectory)
+{
+    toImpl(contextRef)->setLocalStorageDirectory(toImpl(localStorageDirectory)->string());
+}
index bcd24a5..e515e76 100644 (file)
@@ -54,9 +54,10 @@ WK_EXPORT void WKContextRegisterURLSchemeAsSecure(WKContextRef context, WKString
 
 WK_EXPORT void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef context, WKStringRef urlScheme);
 
-// FIXME: This function is only effective if called before the Web process is launched. But
-// we should really change this setting to be on WebPreferences and changeable at runtime.
+// FIXME: These functions are only effective if called before the Web process is launched. But
+// we should really change these settings to be on WebPreferences and changeable at runtime.
 WK_EXPORT void WKContextSetDatabaseDirectory(WKContextRef context, WKStringRef databaseDirectory);
+WK_EXPORT void WKContextSetLocalStorageDirectory(WKContextRef context, WKStringRef localStorageDirectory);
 
 #ifdef __cplusplus
 }
index 4cccbe9..631a9ba 100644 (file)
@@ -222,6 +222,7 @@ void WebContext::ensureWebProcess()
     parameters.languageCode = defaultLanguage();
     parameters.applicationCacheDirectory = applicationCacheDirectory();
     parameters.databaseDirectory = databaseDirectory();
+    parameters.localStorageDirectory = localStorageDirectory();
     parameters.clearResourceCaches = m_clearResourceCachesForNewWebProcess;
     parameters.clearApplicationCache = m_clearApplicationCacheForNewWebProcess;
 #if PLATFORM(MAC)
@@ -729,4 +730,12 @@ String WebContext::databaseDirectory() const
     return platformDefaultDatabaseDirectory();
 }
 
+String WebContext::localStorageDirectory() const
+{
+    if (!m_overrideLocalStorageDirectory.isEmpty())
+        return m_overrideLocalStorageDirectory;
+
+    return platformDefaultLocalStorageDirectory();
+}
+
 } // namespace WebKit
index f6a4e62..1ae2143 100644 (file)
@@ -153,6 +153,7 @@ public:
     static Statistics& statistics();
 
     void setDatabaseDirectory(const String& dir) { m_overrideDatabaseDirectory = dir; }
+    void setLocalStorageDirectory(const String& dir) { m_overrideLocalStorageDirectory = dir; }
 
     void ensureWebProcess();
 
@@ -189,6 +190,9 @@ private:
     String databaseDirectory() const;
     String platformDefaultDatabaseDirectory() const;
 
+    String localStorageDirectory() const;
+    String platformDefaultLocalStorageDirectory() const;
+    
     ProcessModel m_processModel;
     
     // FIXME: In the future, this should be one or more WebProcessProxies.
@@ -237,6 +241,7 @@ private:
 #endif
 
     String m_overrideDatabaseDirectory;
+    String m_overrideLocalStorageDirectory;
 };
 
 } // namespace WebKit
index d67726c..7ff1c47 100644 (file)
@@ -46,4 +46,9 @@ String WebContext::platformDefaultDatabaseDirectory() const
     return WTF::String::fromUTF8(g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL));
 }
 
+String WebContext::platformDefaultLocalStorageDirectory() const
+{
+    return WTF::String::fromUTF8(g_build_filename(g_get_user_data_dir(), "webkit", "localstorage", NULL));
+}
+
 } // namespace WebKit
index 498b6e7..6841ec7 100644 (file)
@@ -35,6 +35,7 @@ using namespace WebCore;
 
 NSString *WebDatabaseDirectoryDefaultsKey = @"WebDatabaseDirectory";
 NSString *WebKitLocalCacheDefaultsKey = @"WebKitLocalCache";
+NSString *WebStorageDirectoryDefaultsKey = @"WebKitLocalStorageDatabasePathPreferenceKey";
 
 namespace WebKit {
 
@@ -107,5 +108,13 @@ String WebContext::platformDefaultDatabaseDirectory() const
     return [databasesDirectory stringByStandardizingPath];
 }
 
+String WebContext::platformDefaultLocalStorageDirectory() const
+{
+    NSString *localStorageDirectory = [[NSUserDefaults standardUserDefaults] objectForKey:WebStorageDirectoryDefaultsKey];
+    if (!localStorageDirectory || ![localStorageDirectory isKindOfClass:[NSString class]])
+        localStorageDirectory = @"~/Library/WebKit/LocalStorage";
+    return [localStorageDirectory stringByStandardizingPath];
+}
+
 } // namespace WebKit
 
index c1301d5..972be11 100644 (file)
@@ -53,4 +53,10 @@ String WebContext::platformDefaultDatabaseDirectory() const
     return "";
 }
 
+String WebContext::platformDefaultLocalStorageDirectory() const
+{
+    // FIXME: Implement.
+    return "";
+}
+
 } // namespace WebKit
index 26708d7..c7c8c1e 100644 (file)
@@ -81,5 +81,10 @@ String WebContext::platformDefaultDatabaseDirectory() const
     return WebCore::pathByAppendingComponent(WebCore::localUserSpecificStorageDirectory(), "Databases");
 }
 
+String WebContext::platformDefaultLocalStorageDirectory() const
+{
+    return WebCore::pathByAppendingComponent(WebCore::localUserSpecificStorageDirectory(), "LocalStorage");
+}
+
 } // namespace WebKit
 
index 573e405..7817290 100644 (file)
@@ -1392,6 +1392,10 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
     settings->setFullScreenEnabled(store.getBoolValueForKey(WebPreferencesKey::fullScreenEnabledKey()));
 #endif
 
+#if ENABLE(DOM_STORAGE)
+    settings->setLocalStorageDatabasePath(WebProcess::shared().localStorageDirectory());
+#endif
+
     platformPreferencesDidChange(store);
 }
 
index e39acc4..2d23864 100644 (file)
@@ -62,6 +62,7 @@
 #include <WebCore/SchemeRegistry.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/Settings.h>
+#include <WebCore/StorageTracker.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RandomNumber.h>
 
@@ -175,6 +176,11 @@ void WebProcess::initializeWebProcess(const WebProcessCreationParameters& parame
     WebDatabaseManager::initialize(parameters.databaseDirectory);
 #endif
 
+#if ENABLE(DOM_STORAGE)
+    StorageTracker::initializeTracker(parameters.localStorageDirectory);
+    m_localStorageDirectory = parameters.localStorageDirectory;
+#endif
+    
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
     if (!parameters.applicationCacheDirectory.isEmpty())
         cacheStorage().setCacheDirectory(parameters.applicationCacheDirectory);
index 5faf886..82e1e12 100644 (file)
@@ -119,6 +119,8 @@ public:
     WebGeolocationManager& geolocationManager() { return m_geolocationManager; }
 
     void clearResourceCaches(uint32_t cachesToClear = AllResourceCaches);
+    
+    const String& localStorageDirectory() const { return m_localStorageDirectory; }
 
 private:
     WebProcess();
@@ -204,6 +206,8 @@ private:
 
     TextCheckerState m_textCheckerState;
     WebGeolocationManager m_geolocationManager;
+    
+    String m_localStorageDirectory;
 };
 
 } // namespace WebKit
index d5921d0..fa81666 100644 (file)
 (if (positive? (string-length (param "WEBKIT_DATABASE_DIR")))
     (allow file* (subpath (param "WEBKIT_DATABASE_DIR"))))
 
+;; LocalStorage dir
+(if (positive? (string-length (param "WEBKIT_LOCALSTORAGE_DIR")))
+    (allow file* (subpath (param "WEBKIT_LOCALSTORAGE_DIR"))))
+    
 ;; The NSURLCache directory.
 (if (positive? (string-length (param "NSURL_CACHE_DIR")))
     (allow file* (subpath (param "NSURL_CACHE_DIR"))))
index bd45049..e535aea 100644 (file)
@@ -156,6 +156,7 @@ static void initializeSandbox(const WebProcessCreationParameters& parameters)
     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, "WEBKIT_LOCALSTORAGE_DIR", [(NSString *)parameters.localStorageDirectory 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));