[GTK] Add initial WebKitWebsiteDataManager API for process configuration options
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jun 2015 07:51:32 +0000 (07:51 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jun 2015 07:51:32 +0000 (07:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146149

Reviewed by Sergio Villar Senin.

Source/WebKit2:

Add WebKitWebsiteDataManager to replace the different ways we have
to configure data store
directories. WebKitWebContext:indexed-db-directory property has
been removed, since it was added only in trunk, and
WebKitWebContext:local-storage-directory has been deprecated. The
method webkit_web_context_set_disk_cache_directory() has been
deprecated too in favor of WebKitWebsiteDataManager.

* PlatformGTK.cmake: Add new files to compilation.
* UIProcess/API/gtk/WebKitPrivate.h: Move networkCacheSubdirectory
definition here.
* UIProcess/API/gtk/WebKitWebContext.cpp:
(webkitWebContextGetProperty): Replace indexed-db-directory getter
with website-data-manager one.
(webkitWebContextSetProperty): Replace indexed-db-directory setter
with website-data-manager one.
(webkitWebContextConstructed): Use the user provided
WebKitWebsiteDataManager to configure the context or create a
default WebKitWebsiteDataManager if not provided.
(webkit_web_context_class_init): Replace indexed-db-directory
property with website-data-manager.
(webkit_web_context_new_with_website_data_manager):
(webkit_web_context_get_website_data_manager):
(webkitWebContextCreatePageForWebView): Get the WebsiteDataStore
from the WebKitWebsiteDataManager.
* UIProcess/API/gtk/WebKitWebContext.h:
* UIProcess/API/gtk/WebKitWebsiteDataManager.cpp: Added.
(webkitWebsiteDataManagerGetProperty):
(webkitWebsiteDataManagerSetProperty):
(webkit_website_data_manager_class_init):
(webkitWebsiteDataManagerCreate):
(webkitWebsiteDataManagerGetDataStore):
(webkit_website_data_manager_new):
(webkit_website_data_manager_get_local_storage_directory):
(webkit_website_data_manager_get_disk_cache_directory):
(webkit_website_data_manager_get_offline_application_cache_directory):
(webkit_website_data_manager_get_indexeddb_directory):
(webkit_website_data_manager_get_websql_directory):
* UIProcess/API/gtk/WebKitWebsiteDataManager.h: Added.
* UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h: Added.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
* UIProcess/API/gtk/docs/webkit2gtk-4.0.types: Add webkit_website_data_manager_get_type.
* UIProcess/API/gtk/webkit2.h: Include WebKitWebsiteDataManager.h.

Tools:

Update unit tests to use WebKitWebsiteDataManager.

* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
(testWebContextConfiguration):
(serverCallback):
* TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h:
(Test::Test): Use WebKitWebsiteDataManager and set all possible
values to ensure unit tests don't write outside the temporary directory.
(Test::~Test): Explicitly reset the web context to ensure its
objects are released before the leaks check.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::wait): Fix the GSource used, since we are receiving
a double in seconds, but using g_timeout_add_seconds() that
expects an unsigned in seconds. Use GMainLoopSource to correctly
handle the value and simplify the code.

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

15 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0.types
Source/WebKit2/UIProcess/API/gtk/webkit2.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp
Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h
Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp

index 176bff7..088e6b1 100644 (file)
@@ -1,5 +1,56 @@
 2015-06-25  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Add initial WebKitWebsiteDataManager API for process configuration options
+        https://bugs.webkit.org/show_bug.cgi?id=146149
+
+        Reviewed by Sergio Villar Senin.
+
+        Add WebKitWebsiteDataManager to replace the different ways we have
+        to configure data store
+        directories. WebKitWebContext:indexed-db-directory property has
+        been removed, since it was added only in trunk, and
+        WebKitWebContext:local-storage-directory has been deprecated. The
+        method webkit_web_context_set_disk_cache_directory() has been
+        deprecated too in favor of WebKitWebsiteDataManager.
+
+        * PlatformGTK.cmake: Add new files to compilation.
+        * UIProcess/API/gtk/WebKitPrivate.h: Move networkCacheSubdirectory
+        definition here.
+        * UIProcess/API/gtk/WebKitWebContext.cpp:
+        (webkitWebContextGetProperty): Replace indexed-db-directory getter
+        with website-data-manager one.
+        (webkitWebContextSetProperty): Replace indexed-db-directory setter
+        with website-data-manager one.
+        (webkitWebContextConstructed): Use the user provided
+        WebKitWebsiteDataManager to configure the context or create a
+        default WebKitWebsiteDataManager if not provided.
+        (webkit_web_context_class_init): Replace indexed-db-directory
+        property with website-data-manager.
+        (webkit_web_context_new_with_website_data_manager):
+        (webkit_web_context_get_website_data_manager):
+        (webkitWebContextCreatePageForWebView): Get the WebsiteDataStore
+        from the WebKitWebsiteDataManager.
+        * UIProcess/API/gtk/WebKitWebContext.h:
+        * UIProcess/API/gtk/WebKitWebsiteDataManager.cpp: Added.
+        (webkitWebsiteDataManagerGetProperty):
+        (webkitWebsiteDataManagerSetProperty):
+        (webkit_website_data_manager_class_init):
+        (webkitWebsiteDataManagerCreate):
+        (webkitWebsiteDataManagerGetDataStore):
+        (webkit_website_data_manager_new):
+        (webkit_website_data_manager_get_local_storage_directory):
+        (webkit_website_data_manager_get_disk_cache_directory):
+        (webkit_website_data_manager_get_offline_application_cache_directory):
+        (webkit_website_data_manager_get_indexeddb_directory):
+        (webkit_website_data_manager_get_websql_directory):
+        * UIProcess/API/gtk/WebKitWebsiteDataManager.h: Added.
+        * UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h: Added.
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0.types: Add webkit_website_data_manager_get_type.
+        * UIProcess/API/gtk/webkit2.h: Include WebKitWebsiteDataManager.h.
+
+2015-06-25  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Do not use legacy data store options in WebKit2 GTK+ API
         https://bugs.webkit.org/show_bug.cgi?id=146145
 
index 691c641..532383e 100644 (file)
@@ -251,6 +251,9 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/gtk/WebKitWebViewBaseAccessible.h
     UIProcess/API/gtk/WebKitWebViewBasePrivate.h
     UIProcess/API/gtk/WebKitWebViewPrivate.h
+    UIProcess/API/gtk/WebKitWebsiteDataManager.cpp
+    UIProcess/API/gtk/WebKitWebsiteDataManager.h
+    UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h
     UIProcess/API/gtk/WebKitWindowProperties.cpp
     UIProcess/API/gtk/WebKitWindowProperties.h
     UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h
@@ -399,6 +402,7 @@ set(WebKit2GTK_INSTALLED_HEADERS
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebResource.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebView.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebViewBase.h
+    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebsiteDataManager.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWindowProperties.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/webkit2.h
 )
index 0f8908c..34e17fb 100644 (file)
@@ -127,4 +127,10 @@ enum SnapshotRegion {
     SnapshotRegionFullDocument
 };
 
+#if ENABLE(NETWORK_CACHE)
+static const char networkCacheSubdirectory[] = "WebKitCache";
+#else
+static const char networkCacheSubdirectory[] = "webkit";
+#endif
+
 #endif // WebKitPrivate_h
index 1557f50..7664558 100644 (file)
@@ -47,6 +47,7 @@
 #include "WebKitWebContextPrivate.h"
 #include "WebKitWebViewBasePrivate.h"
 #include "WebKitWebViewPrivate.h"
+#include "WebKitWebsiteDataManagerPrivate.h"
 #include "WebNotificationManagerProxy.h"
 #include <WebCore/FileSystem.h>
 #include <WebCore/IconDatabase.h>
@@ -102,7 +103,7 @@ enum {
     PROP_0,
 
     PROP_LOCAL_STORAGE_DIRECTORY,
-    PROP_INDEXED_DB_DIRECTORY
+    PROP_WEBSITE_DATA_MANAGER
 };
 
 enum {
@@ -173,7 +174,7 @@ struct _WebKitWebContextPrivate {
 #if ENABLE(NOTIFICATIONS)
     RefPtr<WebKitNotificationProvider> notificationProvider;
 #endif
-    RefPtr<WebsiteDataStore> websiteDataStore;
+    GRefPtr<WebKitWebsiteDataManager> websiteDataManager;
 
     CString faviconDatabaseDirectory;
     WebKitTLSErrorsPolicy tlsErrorsPolicy;
@@ -238,8 +239,8 @@ static void webkitWebContextGetProperty(GObject* object, guint propID, GValue* v
     case PROP_LOCAL_STORAGE_DIRECTORY:
         g_value_set_string(value, context->priv->localStorageDirectory.data());
         break;
-    case PROP_INDEXED_DB_DIRECTORY:
-        g_value_set_string(value, context->priv->indexedDBDirectory.data());
+    case PROP_WEBSITE_DATA_MANAGER:
+        g_value_set_object(value, webkit_web_context_get_website_data_manager(context));
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec);
@@ -254,9 +255,11 @@ static void webkitWebContextSetProperty(GObject* object, guint propID, const GVa
     case PROP_LOCAL_STORAGE_DIRECTORY:
         context->priv->localStorageDirectory = g_value_get_string(value);
         break;
-    case PROP_INDEXED_DB_DIRECTORY:
-        context->priv->indexedDBDirectory = g_value_get_string(value);
+    case PROP_WEBSITE_DATA_MANAGER: {
+        gpointer manager = g_value_get_object(value);
+        context->priv->websiteDataManager = manager ? WEBKIT_WEBSITE_DATA_MANAGER(manager) : nullptr;
         break;
+    }
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec);
     }
@@ -286,14 +289,20 @@ static void webkitWebContextConstructed(GObject* object)
 
     WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(object);
     WebKitWebContextPrivate* priv = webContext->priv;
-    if (!priv->localStorageDirectory.isNull())
+    if (priv->websiteDataManager) {
+        configuration.setLocalStorageDirectory(WebCore::filenameToString(webkit_website_data_manager_get_local_storage_directory(priv->websiteDataManager.get())));
+        configuration.setDiskCacheDirectory(WebCore::pathByAppendingComponent(WebCore::filenameToString(webkit_website_data_manager_get_disk_cache_directory(priv->websiteDataManager.get())), networkCacheSubdirectory));
+        configuration.setApplicationCacheDirectory(WebCore::filenameToString(webkit_website_data_manager_get_offline_application_cache_directory(priv->websiteDataManager.get())));
+        configuration.setIndexedDBDatabaseDirectory(WebCore::filenameToString(webkit_website_data_manager_get_indexeddb_directory(priv->websiteDataManager.get())));
+        configuration.setWebSQLDatabaseDirectory(WebCore::filenameToString(webkit_website_data_manager_get_websql_directory(priv->websiteDataManager.get())));
+    } else if (!priv->localStorageDirectory.isNull())
         configuration.setLocalStorageDirectory(WebCore::filenameToString(priv->localStorageDirectory.data()));
-    if (!priv->indexedDBDirectory.isNull())
-        configuration.setIndexedDBDatabaseDirectory(WebCore::filenameToString(priv->indexedDBDirectory.data()));
 
     priv->context = WebProcessPool::create(configuration);
 
-    priv->websiteDataStore = WebsiteDataStore::create(websiteDataStoreConfigurationForWebProcessPoolConfiguration(configuration));
+    if (!priv->websiteDataManager)
+        priv->websiteDataManager = webkitWebsiteDataManagerCreate(websiteDataStoreConfigurationForWebProcessPoolConfiguration(configuration));
+
     priv->requestManager = priv->context->supplement<WebSoupCustomProtocolRequestManager>();
 
     priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_FAIL;
@@ -344,6 +353,8 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass
      * The directory where local storage data will be saved.
      *
      * Since: 2.8
+     *
+     * Deprecated: 2.10. Use #WebKitWebsiteDataManager:local-storage-directory instead.
      */
     g_object_class_install_property(
         gObjectClass,
@@ -356,20 +367,20 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass
             static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
 
     /**
-     * WebKitWebContext:indexed-db-directory:
+     * WebKitWebContext:website-data-manager:
      *
-     * The directory where IndexedDB databases will be saved.
+     * The #WebKitWebsiteDataManager associated with this context.
      *
      * Since: 2.10
      */
     g_object_class_install_property(
         gObjectClass,
-        PROP_INDEXED_DB_DIRECTORY,
-        g_param_spec_string(
-            "indexed-db-directory",
-            _("IndexedDB Directory"),
-            _("The directory where IndexedDB databases will be saved"),
-            nullptr,
+        PROP_WEBSITE_DATA_MANAGER,
+        g_param_spec_object(
+            "website-data-manager",
+            _("Website Data Manager"),
+            _("The WebKitWebsiteDataManager associated with this context"),
+            WEBKIT_TYPE_WEBSITE_DATA_MANAGER,
             static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
 
     /**
@@ -444,6 +455,40 @@ WebKitWebContext* webkit_web_context_new(void)
 }
 
 /**
+ * webkit_web_context_new_with_website_data_manager:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Create a new #WebKitWebContext with a #WebKitWebsiteDataManager.
+ *
+ * Returns: (transfer full): a newly created #WebKitWebContext
+ *
+ * Since: 2.10
+ */
+WebKitWebContext* webkit_web_context_new_with_website_data_manager(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, "website-data-manager", manager, nullptr));
+}
+
+/**
+ * webkit_web_context_get_website_data_manager:
+ * @context: the #WebKitWebContext
+ *
+ * Get the #WebKitWebsiteDataManager of @context.
+ *
+ * Returns: (transfer none): a #WebKitWebsiteDataManager
+ *
+ * Since: 2.10
+ */
+WebKitWebsiteDataManager* webkit_web_context_get_website_data_manager(WebKitWebContext* context)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
+
+    return context->priv->websiteDataManager.get();
+}
+
+/**
  * webkit_web_context_set_cache_model:
  * @context: the #WebKitWebContext
  * @cache_model: a #WebKitCacheModel
@@ -1039,17 +1084,18 @@ void webkit_web_context_set_web_extensions_initialization_user_data(WebKitWebCon
  * Set the directory where disk cache files will be stored
  * This method must be called before loading anything in this context, otherwise
  * it will not have any effect.
+ *
+ * Note that this method overrides the directory set in the #WebKitWebsiteDataManager,
+ * but it doesn't change the value returned by webkit_website_data_manager_get_disk_cache_directory()
+ * since the #WebKitWebsiteDataManager is immutable.
+ *
+ * Deprecated: 2.10. Use webkit_web_context_new_with_website_data_manager() instead.
  */
 void webkit_web_context_set_disk_cache_directory(WebKitWebContext* context, const char* directory)
 {
     g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
     g_return_if_fail(directory);
 
-#if ENABLE(NETWORK_CACHE)
-    static const char networkCacheSubdirectory[] = "WebKitCache";
-#else
-    static const char networkCacheSubdirectory[] = "webkit";
-#endif
     context->priv->context->configuration().setDiskCacheDirectory(WebCore::pathByAppendingComponent(WebCore::filenameToString(directory), networkCacheSubdirectory));
 }
 
@@ -1232,8 +1278,8 @@ void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebVi
     webPageConfiguration.preferences = webkitSettingsGetPreferences(webkit_web_view_get_settings(webView));
     webPageConfiguration.relatedPage = relatedView ? webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(relatedView)) : nullptr;
     webPageConfiguration.userContentController = userContentManager ? webkitUserContentManagerGetUserContentControllerProxy(userContentManager) : nullptr;
-    webPageConfiguration.websiteDataStore = context->priv->websiteDataStore.get();
-    webPageConfiguration.sessionID = context->priv->websiteDataStore->sessionID();
+    webPageConfiguration.websiteDataStore = &webkitWebsiteDataManagerGetDataStore(context->priv->websiteDataManager.get());
+    webPageConfiguration.sessionID = webPageConfiguration.websiteDataStore->sessionID();
     webkitWebViewBaseCreateWebPage(webViewBase, context->priv->context.get(), WTF::move(webPageConfiguration));
 
     WebPageProxy* page = webkitWebViewBaseGetPage(webViewBase);
index 8c428c2..4da45d9 100644 (file)
@@ -31,6 +31,7 @@
 #include <webkit2/WebKitFaviconDatabase.h>
 #include <webkit2/WebKitSecurityManager.h>
 #include <webkit2/WebKitURISchemeRequest.h>
+#include <webkit2/WebKitWebsiteDataManager.h>
 
 G_BEGIN_DECLS
 
@@ -148,6 +149,12 @@ webkit_web_context_get_default                      (void);
 WEBKIT_API WebKitWebContext *
 webkit_web_context_new                              (void);
 
+WEBKIT_API WebKitWebContext *
+webkit_web_context_new_with_website_data_manager    (WebKitWebsiteDataManager      *manager);
+
+WEBKIT_API WebKitWebsiteDataManager *
+webkit_web_context_get_website_data_manager         (WebKitWebContext              *context);
+
 WEBKIT_API void
 webkit_web_context_set_cache_model                  (WebKitWebContext              *context,
                                                      WebKitCacheModel               cache_model);
@@ -234,7 +241,7 @@ WEBKIT_API void
 webkit_web_context_prefetch_dns                     (WebKitWebContext              *context,
                                                      const gchar                   *hostname);
 
-WEBKIT_API void
+WEBKIT_DEPRECATED_FOR(webkit_web_context_new_with_website_data_manager) void
 webkit_web_context_set_disk_cache_directory         (WebKitWebContext              *context,
                                                      const gchar                   *directory);
 
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp
new file mode 100644 (file)
index 0000000..b2a9b89
--- /dev/null
@@ -0,0 +1,485 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitWebsiteDataManager.h"
+
+#include "APIWebsiteDataStore.h"
+#include "WebKitWebsiteDataManagerPrivate.h"
+#include <WebCore/FileSystem.h>
+#include <glib/gi18n-lib.h>
+#include <wtf/glib/GUniquePtr.h>
+
+using namespace WebKit;
+
+/**
+ * SECTION: WebKitWebsiteDataManager
+ * @Short_description: Website data manager
+ * @Title: WebKitWebsiteDataManager
+ * @See_also: #WebKitWebContext
+ *
+ * WebKitWebsiteDataManager allows you to manage the data that websites
+ * can store in the client file system like databases or caches.
+ * You can use WebKitWebsiteDataManager to configure the local directories
+ * where the Website data will be stored, by creating a new manager with
+ * webkit_website_data_manager_new() passing the values you want to set.
+ * You can set all the possible configuration values or only some of them,
+ * a default value will be used automatically for the configuration options
+ * not provided. #WebKitWebsiteDataManager:base-data-directory and
+ * #WebKitWebsiteDataManager:base-cache-directory are two special properties
+ * that can be used to set a common base directory for all Website data and
+ * caches. It's possible to provide both, a base directory and a specific value,
+ * but in that case, the specific value takes precedence over the base directory.
+ * The newly created WebKitWebsiteDataManager must be passed as a construct property
+ * to a #WebKitWebContext, you can use webkit_web_context_new_with_website_data_manager()
+ * to create a new #WebKitWebContext with a WebKitWebsiteDataManager.
+ * In case you don't want to set any specific configuration, you don't need to create
+ * a WebKitWebsiteDataManager, the #WebKitWebContext will create a WebKitWebsiteDataManager
+ * with the default configuration. To get the WebKitWebsiteDataManager of a #WebKitWebContext
+ * you can use webkit_web_context_get_website_data_manager().
+ *
+ * Since: 2.10
+ */
+
+enum {
+    PROP_0,
+
+    PROP_BASE_DATA_DIRECTORY,
+    PROP_BASE_CACHE_DIRECTORY,
+    PROP_LOCAL_STORAGE_DIRECTORY,
+    PROP_DISK_CACHE_DIRECTORY,
+    PROP_APPLICATION_CACHE_DIRECTORY,
+    PROP_INDEXEDDB_DIRECTORY,
+    PROP_WEBSQL_DIRECTORY
+};
+
+struct _WebKitWebsiteDataManagerPrivate {
+    RefPtr<WebsiteDataStore> websiteDataStore;
+    GUniquePtr<char> baseDataDirectory;
+    GUniquePtr<char> baseCacheDirectory;
+    GUniquePtr<char> localStorageDirectory;
+    GUniquePtr<char> diskCacheDirectory;
+    GUniquePtr<char> applicationCacheDirectory;
+    GUniquePtr<char> indexedDBDirectory;
+    GUniquePtr<char> webSQLDirectory;
+};
+
+WEBKIT_DEFINE_TYPE(WebKitWebsiteDataManager, webkit_website_data_manager, G_TYPE_OBJECT)
+
+static void webkitWebsiteDataManagerGetProperty(GObject* object, guint propID, GValue* value, GParamSpec* paramSpec)
+{
+    WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(object);
+
+    switch (propID) {
+    case PROP_BASE_DATA_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_base_data_directory(manager));
+        break;
+    case PROP_BASE_CACHE_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_base_cache_directory(manager));
+        break;
+    case PROP_LOCAL_STORAGE_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_local_storage_directory(manager));
+        break;
+    case PROP_DISK_CACHE_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_disk_cache_directory(manager));
+        break;
+    case PROP_APPLICATION_CACHE_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_offline_application_cache_directory(manager));
+        break;
+    case PROP_INDEXEDDB_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_indexeddb_directory(manager));
+        break;
+    case PROP_WEBSQL_DIRECTORY:
+        g_value_set_string(value, webkit_website_data_manager_get_websql_directory(manager));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec);
+    }
+}
+
+static void webkitWebsiteDataManagerSetProperty(GObject* object, guint propID, const GValue* value, GParamSpec* paramSpec)
+{
+    WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(object);
+
+    switch (propID) {
+    case PROP_BASE_DATA_DIRECTORY:
+        manager->priv->baseDataDirectory.reset(g_value_dup_string(value));
+        break;
+    case PROP_BASE_CACHE_DIRECTORY:
+        manager->priv->baseCacheDirectory.reset(g_value_dup_string(value));
+        break;
+    case PROP_LOCAL_STORAGE_DIRECTORY:
+        manager->priv->localStorageDirectory.reset(g_value_dup_string(value));
+        break;
+    case PROP_DISK_CACHE_DIRECTORY:
+        manager->priv->diskCacheDirectory.reset(g_value_dup_string(value));
+        break;
+    case PROP_APPLICATION_CACHE_DIRECTORY:
+        manager->priv->applicationCacheDirectory.reset(g_value_dup_string(value));
+        break;
+    case PROP_INDEXEDDB_DIRECTORY:
+        manager->priv->indexedDBDirectory.reset(g_value_dup_string(value));
+        break;
+    case PROP_WEBSQL_DIRECTORY:
+        manager->priv->webSQLDirectory.reset(g_value_dup_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec);
+    }
+}
+
+static void webkitWebsiteDataManagerConstructed(GObject* object)
+{
+    G_OBJECT_CLASS(webkit_website_data_manager_parent_class)->constructed(object);
+
+    WebKitWebsiteDataManagerPrivate* priv = WEBKIT_WEBSITE_DATA_MANAGER(object)->priv;
+    if (priv->baseDataDirectory) {
+        if (!priv->localStorageDirectory)
+            priv->localStorageDirectory.reset(g_build_filename(priv->baseDataDirectory.get(), "localstorage", nullptr));
+        if (!priv->indexedDBDirectory)
+            priv->indexedDBDirectory.reset(g_build_filename(priv->baseDataDirectory.get(), "databases", "indexeddb", nullptr));
+        if (!priv->webSQLDirectory)
+            priv->webSQLDirectory.reset(g_build_filename(priv->baseDataDirectory.get(), "databases", nullptr));
+    }
+
+    if (priv->baseCacheDirectory) {
+        if (!priv->diskCacheDirectory)
+            priv->diskCacheDirectory.reset(g_strdup(priv->baseCacheDirectory.get()));
+        if (!priv->applicationCacheDirectory)
+            priv->applicationCacheDirectory.reset(g_build_filename(priv->baseCacheDirectory.get(), "applications", nullptr));
+    }
+}
+
+static void webkit_website_data_manager_class_init(WebKitWebsiteDataManagerClass* findClass)
+{
+    GObjectClass* gObjectClass = G_OBJECT_CLASS(findClass);
+
+    gObjectClass->get_property = webkitWebsiteDataManagerGetProperty;
+    gObjectClass->set_property = webkitWebsiteDataManagerSetProperty;
+    gObjectClass->constructed = webkitWebsiteDataManagerConstructed;
+
+    /**
+     * WebKitWebsiteDataManager:base-data-directory:
+     *
+     * The base directory for Website data. This is used as a base directory
+     * for any Website data when no specific data directory has been provided.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_BASE_DATA_DIRECTORY,
+        g_param_spec_string(
+            "base-data-directory",
+            _("Base Data Directory"),
+            _("The base directory for Website data"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitWebsiteDataManager:base-cache-directory:
+     *
+     * The base directory for Website cache. This is used as a base directory
+     * for any Website cache when no specific cache directory has been provided.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_BASE_CACHE_DIRECTORY,
+        g_param_spec_string(
+            "base-cache-directory",
+            _("Base Cache Directory"),
+            _("The base directory for Website cache"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitWebsiteDataManager:local-storage-directory:
+     *
+     * The directory where local storage data will be stored.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_LOCAL_STORAGE_DIRECTORY,
+        g_param_spec_string(
+            "local-storage-directory",
+            _("Local Storage Directory"),
+            _("The directory where local storage data will be stored"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitWebsiteDataManager:disk-cache-directory:
+     *
+     * The directory where HTTP disk cache will be stored.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_DISK_CACHE_DIRECTORY,
+        g_param_spec_string(
+            "disk-cache-directory",
+            _("Disk Cache Directory"),
+            _("The directory where HTTP disk cache will be stored"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitWebsiteDataManager:offline-application-cache-directory:
+     *
+     * The directory where offline web application cache will be stored.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_APPLICATION_CACHE_DIRECTORY,
+        g_param_spec_string(
+            "offline-application-cache-directory",
+            _("Offline Web Application Cache Directory"),
+            _("The directory where offline web application cache will be stored"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitWebsiteDataManager:indexeddb-directory:
+     *
+     * The directory where IndexedDB databases will be stored.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_INDEXEDDB_DIRECTORY,
+        g_param_spec_string(
+            "indexeddb-directory",
+            _("IndexedDB Directory"),
+            _("The directory where IndexedDB databases will be stored"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
+     * WebKitWebsiteDataManager:websql-directory:
+     *
+     * The directory where WebSQL databases will be stored.
+     *
+     * Since: 2.10
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_WEBSQL_DIRECTORY,
+        g_param_spec_string(
+            "websql-directory",
+            _("WebSQL Directory"),
+            _("The directory where WebSQL databases will be stored"),
+            nullptr,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+}
+
+WebKitWebsiteDataManager* webkitWebsiteDataManagerCreate(WebsiteDataStore::Configuration&& configuration)
+{
+    WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(g_object_new(WEBKIT_TYPE_WEBSITE_DATA_MANAGER, nullptr));
+    manager->priv->websiteDataStore = WebsiteDataStore::create(WTF::move(configuration));
+
+    return manager;
+}
+
+WebsiteDataStore& webkitWebsiteDataManagerGetDataStore(WebKitWebsiteDataManager* manager)
+{
+    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
+    if (!priv->websiteDataStore) {
+        WebsiteDataStore::Configuration configuration;
+        configuration.localStorageDirectory = !priv->localStorageDirectory ?
+            API::WebsiteDataStore::defaultLocalStorageDirectory() : WebCore::filenameToString(priv->localStorageDirectory.get());
+        configuration.networkCacheDirectory = !priv->diskCacheDirectory ?
+            API::WebsiteDataStore::defaultNetworkCacheDirectory() : WebCore::pathByAppendingComponent(WebCore::filenameToString(priv->diskCacheDirectory.get()), networkCacheSubdirectory);
+        configuration.applicationCacheDirectory = !priv->applicationCacheDirectory ?
+            API::WebsiteDataStore::defaultApplicationCacheDirectory() : WebCore::filenameToString(priv->applicationCacheDirectory.get());
+        configuration.webSQLDatabaseDirectory = !priv->webSQLDirectory ?
+            API::WebsiteDataStore::defaultWebSQLDatabaseDirectory() : WebCore::filenameToString(priv->webSQLDirectory.get());
+        configuration.mediaKeysStorageDirectory = API::WebsiteDataStore::defaultMediaKeysStorageDirectory();
+        priv->websiteDataStore = WebsiteDataStore::create(WTF::move(configuration));
+    }
+
+    return *priv->websiteDataStore;
+}
+
+/**
+ * webkit_website_data_manager_new:
+ * @first_option_name: name of the first option to set
+ * @...: value of first option, followed by more options, %NULL-terminated
+ *
+ * Creates a new #WebKitWebsiteDataManager with the given options. It must
+ * be passed as construction parameter of a #WebKitWebContext.
+ *
+ * Returns: (transfer full): the newly created #WebKitWebsiteDataManager
+ *
+ * Since: 2.10
+ */
+WebKitWebsiteDataManager* webkit_website_data_manager_new(const gchar* firstOptionName, ...)
+{
+    va_list args;
+    va_start(args, firstOptionName);
+    WebKitWebsiteDataManager* manager = WEBKIT_WEBSITE_DATA_MANAGER(g_object_new_valist(WEBKIT_TYPE_WEBSITE_DATA_MANAGER, firstOptionName, args));
+    va_end(args);
+
+    return manager;
+}
+
+/**
+ * webkit_website_data_manager_get_base_data_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:base-data-directory property.
+ *
+ * Returns: the base directory for Website data, or %NULL if
+ *    #WebKitWebsiteDataManager:base-data-directory was not provided.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_base_data_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    return manager->priv->baseDataDirectory.get();
+}
+
+/**
+ * webkit_website_data_manager_get_base_cache_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:base-cache-directory property.
+ *
+ * Returns: the base directory for Website cache, or %NULL if
+ *    #WebKitWebsiteDataManager:base-cache-directory was not provided.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_base_cache_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    return manager->priv->baseCacheDirectory.get();
+}
+
+/**
+ * webkit_website_data_manager_get_local_storage_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:local-storage-directory property.
+ *
+ * Returns: the directory where local storage data is stored.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_local_storage_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
+    if (!priv->localStorageDirectory)
+        priv->localStorageDirectory.reset(g_strdup(API::WebsiteDataStore::defaultLocalStorageDirectory().utf8().data()));
+    return priv->localStorageDirectory.get();
+}
+
+/**
+ * webkit_website_data_manager_get_disk_cache_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:disk-cache-directory property.
+ *
+ * Returns: the directory where HTTP disk cache is stored.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_disk_cache_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
+    if (!priv->diskCacheDirectory) {
+        // The default directory already has the subdirectory.
+        priv->diskCacheDirectory.reset(g_strdup(WebCore::directoryName(API::WebsiteDataStore::defaultNetworkCacheDirectory()).utf8().data()));
+    }
+    return priv->diskCacheDirectory.get();
+}
+
+/**
+ * webkit_website_data_manager_get_offline_application_cache_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:offline-application-cache-directory property.
+ *
+ * Returns: the directory where offline web application cache is stored.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_offline_application_cache_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
+    if (!priv->applicationCacheDirectory)
+        priv->applicationCacheDirectory.reset(g_strdup(API::WebsiteDataStore::defaultApplicationCacheDirectory().utf8().data()));
+    return priv->applicationCacheDirectory.get();
+}
+
+/**
+ * webkit_website_data_manager_get_indexeddb_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:indexeddb-directory property.
+ *
+ * Returns: the directory where IndexedDB databases are stored.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_indexeddb_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
+    if (!priv->indexedDBDirectory)
+        priv->indexedDBDirectory.reset(g_strdup(API::WebsiteDataStore::defaultIndexedDBDatabaseDirectory().utf8().data()));
+    return priv->indexedDBDirectory.get();
+}
+
+/**
+ * webkit_website_data_manager_get_websql_directory:
+ * @manager: a #WebKitWebsiteDataManager
+ *
+ * Get the #WebKitWebsiteDataManager:websql-directory property.
+ *
+ * Returns: the directory where WebSQL databases are stored.
+ *
+ * Since: 2.10
+ */
+const gchar* webkit_website_data_manager_get_websql_directory(WebKitWebsiteDataManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
+
+    WebKitWebsiteDataManagerPrivate* priv = manager->priv;
+    if (!priv->webSQLDirectory)
+        priv->webSQLDirectory.reset(g_strdup(API::WebsiteDataStore::defaultWebSQLDatabaseDirectory().utf8().data()));
+    return priv->webSQLDirectory.get();
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.h
new file mode 100644 (file)
index 0000000..e9d8591
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitWebsiteDataManager_h
+#define WebKitWebsiteDataManager_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_WEBSITE_DATA_MANAGER            (webkit_website_data_manager_get_type())
+#define WEBKIT_WEBSITE_DATA_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEBSITE_DATA_MANAGER, WebKitWebsiteDataManager))
+#define WEBKIT_IS_WEBSITE_DATA_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEBSITE_DATA_MANAGER))
+#define WEBKIT_WEBSITE_DATA_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEBSITE_DATA_MANAGER, WebKitWebsiteDataManagerClass))
+#define WEBKIT_IS_WEBSITE_DATA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEBSITE_DATA_MANAGER))
+#define WEBKIT_WEBSITE_DATA_MANAGER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEBSITE_DATA_MANAGER, WebKitWebsiteDataManagerClass))
+
+typedef struct _WebKitWebsiteDataManager        WebKitWebsiteDataManager;
+typedef struct _WebKitWebsiteDataManagerClass   WebKitWebsiteDataManagerClass;
+typedef struct _WebKitWebsiteDataManagerPrivate WebKitWebsiteDataManagerPrivate;
+
+struct _WebKitWebsiteDataManager {
+    GObject parent;
+
+    WebKitWebsiteDataManagerPrivate *priv;
+};
+
+struct _WebKitWebsiteDataManagerClass {
+    GObjectClass parent_class;
+
+    void (*_webkit_reserved0) (void);
+    void (*_webkit_reserved1) (void);
+    void (*_webkit_reserved2) (void);
+    void (*_webkit_reserved3) (void);
+};
+
+WEBKIT_API GType
+webkit_website_data_manager_get_type                                (void);
+
+WEBKIT_API WebKitWebsiteDataManager *
+webkit_website_data_manager_new                                     (const gchar              *first_option_name,
+                                                                     ...);
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_base_data_directory                 (WebKitWebsiteDataManager *manager);
+
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_base_cache_directory                 (WebKitWebsiteDataManager *manager);
+
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_local_storage_directory             (WebKitWebsiteDataManager *manager);
+
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_disk_cache_directory                (WebKitWebsiteDataManager *manager);
+
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_offline_application_cache_directory (WebKitWebsiteDataManager *manager);
+
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_indexeddb_directory                 (WebKitWebsiteDataManager *manager);
+
+WEBKIT_API const gchar *
+webkit_website_data_manager_get_websql_directory                    (WebKitWebsiteDataManager *manager);
+
+G_END_DECLS
+
+#endif
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h
new file mode 100644 (file)
index 0000000..38a7823
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitWebsiteDataManagerPrivate_h
+#define WebKitWebsiteDataManagerPrivate_h
+
+#include "WebKitPrivate.h"
+#include "WebsiteDataStore.h"
+
+WebKitWebsiteDataManager* webkitWebsiteDataManagerCreate(WebKit::WebsiteDataStore::Configuration&&);
+WebKit::WebsiteDataStore& webkitWebsiteDataManagerGetDataStore(WebKitWebsiteDataManager*);
+
+#endif // WebKitWebsiteDataManagerPrivate_h
index e502bd7..cd870a5 100644 (file)
@@ -29,6 +29,8 @@ WebKitProcessModel
 WebKitTLSErrorsPolicy
 webkit_web_context_get_default
 webkit_web_context_new
+webkit_web_context_new_with_website_data_manager
+webkit_web_context_get_website_data_manager
 webkit_web_context_get_cache_model
 webkit_web_context_set_cache_model
 webkit_web_context_clear_cache
@@ -1147,6 +1149,32 @@ webkit_security_manager_get_type
 </SECTION>
 
 <SECTION>
+<FILE>WebKitWebsiteDataManager</FILE>
+WebKitWebsiteDataManager
+webkit_website_data_manager_new
+webkit_website_data_manager_get_base_data_directory
+webkit_website_data_manager_get_base_cache_directory
+webkit_website_data_manager_get_local_storage_directory
+webkit_website_data_manager_get_disk_cache_directory
+webkit_website_data_manager_get_offline_application_cache_directory
+webkit_website_data_manager_get_indexeddb_directory
+webkit_website_data_manager_get_websql_directory
+
+<SUBSECTION Standard>
+WebKitWebsiteDataManagerClass
+WEBKIT_TYPE_WEBSITE_DATA_MANAGER
+WEBKIT_WEBSITE_DATA_MANAGER
+WEBKIT_IS_WEBSITE_DATA_MANAGER
+WEBKIT_WEBSITE_DATA_MANAGER_CLASS
+WEBKIT_IS_WEBSITE_DATA_MANAGER_CLASS
+WEBKIT_WEBSITE_DATA_MANAGER_GET_CLASS
+
+<SUBSECTION Private>
+WebKitWebsiteDataManagerPrivate
+webkit_website_data_manager_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitWebExtension</FILE>
 WebKitWebExtension
 WebKitWebExtensionInitializeFunction
index 819af58..b52646e 100644 (file)
@@ -29,3 +29,4 @@ webkit_frame_get_type
 webkit_certificate_info_get_type
 webkit_user_content_manager_get_type
 webkit_web_hit_test_result_get_type
+webkit_website_data_manager_get_type
index d9bc920..14371b4 100644 (file)
@@ -72,6 +72,7 @@
 #include <webkit2/WebKitWebResource.h>
 #include <webkit2/WebKitWebView.h>
 #include <webkit2/WebKitWebViewBase.h>
+#include <webkit2/WebKitWebsiteDataManager.h>
 #include <webkit2/WebKitWindowProperties.h>
 
 #undef __WEBKIT2_H_INSIDE__
index e4da3c3..faf2495 100644 (file)
@@ -1,3 +1,26 @@
+2015-06-25  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial WebKitWebsiteDataManager API for process configuration options
+        https://bugs.webkit.org/show_bug.cgi?id=146149
+
+        Reviewed by Sergio Villar Senin.
+
+        Update unit tests to use WebKitWebsiteDataManager.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
+        (testWebContextConfiguration):
+        (serverCallback):
+        * TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h:
+        (Test::Test): Use WebKitWebsiteDataManager and set all possible
+        values to ensure unit tests don't write outside the temporary directory.
+        (Test::~Test): Explicitly reset the web context to ensure its
+        objects are released before the leaks check.
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+        (WebViewTest::wait): Fix the GSource used, since we are receiving
+        a double in seconds, but using g_timeout_add_seconds() that
+        expects an unsigned in seconds. Use GMainLoopSource to correctly
+        handle the value and simplify the code.
+
 2015-06-24  Jason Marcell  <jmarcell@apple.com>
 
         Work towards: Add status of Safari projects on iOS Dashboard on build-safari
index d8e21b7..feb7ff1 100644 (file)
@@ -39,14 +39,86 @@ static void testWebContextDefault(Test* test, gconstpointer)
 
 static void testWebContextConfiguration(WebViewTest* test, gconstpointer)
 {
+    WebKitWebsiteDataManager* manager = webkit_web_context_get_website_data_manager(test->m_webContext.get());
+    g_assert(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager));
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(manager));
+
+    // Base directories are not used by TestMain.
+    g_assert(!webkit_website_data_manager_get_base_data_directory(manager));
+    g_assert(!webkit_website_data_manager_get_base_cache_directory(manager));
+
     GUniquePtr<char> localStorageDirectory(g_build_filename(Test::dataDirectory(), "local-storage", nullptr));
+    g_assert_cmpstr(localStorageDirectory.get(), ==, webkit_website_data_manager_get_local_storage_directory(manager));
     g_assert(g_file_test(localStorageDirectory.get(), G_FILE_TEST_IS_DIR));
 
     test->loadURI(kServer->getURIForPath("/empty").data());
     test->waitUntilLoadFinished();
     test->runJavaScriptAndWaitUntilFinished("window.indexedDB.open('TestDatabase');", nullptr);
     GUniquePtr<char> indexedDBDirectory(g_build_filename(Test::dataDirectory(), "indexeddb", nullptr));
+    g_assert_cmpstr(indexedDBDirectory.get(), ==, webkit_website_data_manager_get_indexeddb_directory(manager));
     g_assert(g_file_test(indexedDBDirectory.get(), G_FILE_TEST_IS_DIR));
+
+    test->loadURI(kServer->getURIForPath("/appcache").data());
+    test->waitUntilLoadFinished();
+    GUniquePtr<char> applicationCacheDirectory(g_build_filename(Test::dataDirectory(), "appcache", nullptr));
+    g_assert_cmpstr(applicationCacheDirectory.get(), ==, webkit_website_data_manager_get_offline_application_cache_directory(manager));
+    GUniquePtr<char> applicationCacheDatabase(g_build_filename(applicationCacheDirectory.get(), "ApplicationCache.db", nullptr));
+    unsigned triesCount = 4;
+    while (!g_file_test(applicationCacheDatabase.get(), G_FILE_TEST_IS_REGULAR) && --triesCount)
+        test->wait(0.25);
+    g_assert(triesCount);
+
+
+    GUniquePtr<char> webSQLDirectory(g_build_filename(Test::dataDirectory(), "websql", nullptr));
+    g_assert_cmpstr(webSQLDirectory.get(), ==, webkit_website_data_manager_get_websql_directory(manager));
+#if 0 // FIXME: We need API to set the database quota for an origin to be able to test this.
+    test->runJavaScriptAndWaitUntilFinished("db = openDatabase(\"TestDatabase\", \"1.0\", \"TestDatabase\", 1);", &error);
+    g_assert(g_file_test(webSQLDirectory.get(), G_FILE_TEST_IS_DIR));
+#endif
+
+    GUniquePtr<char> diskCacheDirectory(g_build_filename(Test::dataDirectory(), "disk-cache", nullptr));
+    g_assert_cmpstr(diskCacheDirectory.get(), ==, webkit_website_data_manager_get_disk_cache_directory(manager));
+    g_assert(g_file_test(diskCacheDirectory.get(), G_FILE_TEST_IS_DIR));
+
+    // The default context should have a different manager with different configuration.
+    WebKitWebsiteDataManager* defaultManager = webkit_web_context_get_website_data_manager(webkit_web_context_get_default());
+    g_assert(WEBKIT_IS_WEBSITE_DATA_MANAGER(defaultManager));
+    g_assert(manager != defaultManager);
+    g_assert_cmpstr(webkit_website_data_manager_get_local_storage_directory(manager), !=, webkit_website_data_manager_get_local_storage_directory(defaultManager));
+    g_assert_cmpstr(webkit_website_data_manager_get_indexeddb_directory(manager), !=, webkit_website_data_manager_get_indexeddb_directory(defaultManager));
+    g_assert_cmpstr(webkit_website_data_manager_get_disk_cache_directory(manager), !=, webkit_website_data_manager_get_disk_cache_directory(defaultManager));
+    g_assert_cmpstr(webkit_website_data_manager_get_offline_application_cache_directory(manager), !=, webkit_website_data_manager_get_offline_application_cache_directory(defaultManager));
+    g_assert_cmpstr(webkit_website_data_manager_get_websql_directory(manager), !=, webkit_website_data_manager_get_websql_directory(defaultManager));
+
+    // Using Test::dataDirectory() we get the default configuration but for a differrent prefix.
+    GRefPtr<WebKitWebsiteDataManager> baseDataManager = adoptGRef(webkit_website_data_manager_new("base-data-directory", Test::dataDirectory(), "base-cache-directory", Test::dataDirectory(), nullptr));
+    g_assert(WEBKIT_IS_WEBSITE_DATA_MANAGER(baseDataManager.get()));
+
+    localStorageDirectory.reset(g_build_filename(Test::dataDirectory(), "localstorage", nullptr));
+    g_assert_cmpstr(webkit_website_data_manager_get_local_storage_directory(baseDataManager.get()), ==, localStorageDirectory.get());
+
+    indexedDBDirectory.reset(g_build_filename(Test::dataDirectory(), "databases", "indexeddb", nullptr));
+    g_assert_cmpstr(webkit_website_data_manager_get_indexeddb_directory(baseDataManager.get()), ==, indexedDBDirectory.get());
+
+    applicationCacheDirectory.reset(g_build_filename(Test::dataDirectory(), "applications", nullptr));
+    g_assert_cmpstr(webkit_website_data_manager_get_offline_application_cache_directory(baseDataManager.get()), ==, applicationCacheDirectory.get());
+
+    webSQLDirectory.reset(g_build_filename(Test::dataDirectory(), "databases", nullptr));
+    g_assert_cmpstr(webkit_website_data_manager_get_websql_directory(baseDataManager.get()), ==, webSQLDirectory.get());
+
+    g_assert_cmpstr(webkit_website_data_manager_get_disk_cache_directory(baseDataManager.get()), ==, Test::dataDirectory());
+
+    // Any specific configuration provided takes precedence over base dirs.
+    indexedDBDirectory.reset(g_build_filename(Test::dataDirectory(), "mycustomindexeddb", nullptr));
+    applicationCacheDirectory.reset(g_build_filename(Test::dataDirectory(), "mycustomappcache", nullptr));
+    baseDataManager = adoptGRef(webkit_website_data_manager_new("base-data-directory", Test::dataDirectory(), "base-cache-directory", Test::dataDirectory(),
+        "indexeddb-directory", indexedDBDirectory.get(), "offline-application-cache-directory", applicationCacheDirectory.get(), nullptr));
+    g_assert_cmpstr(webkit_website_data_manager_get_indexeddb_directory(baseDataManager.get()), ==, indexedDBDirectory.get());
+    g_assert_cmpstr(webkit_website_data_manager_get_offline_application_cache_directory(baseDataManager.get()), ==, applicationCacheDirectory.get());
+    // The resutl should be the same as previous manager.
+    g_assert_cmpstr(webkit_website_data_manager_get_local_storage_directory(baseDataManager.get()), ==, localStorageDirectory.get());
+    g_assert_cmpstr(webkit_website_data_manager_get_websql_directory(baseDataManager.get()), ==, webSQLDirectory.get());
+    g_assert_cmpstr(webkit_website_data_manager_get_disk_cache_directory(baseDataManager.get()), ==, Test::dataDirectory());
 }
 
 class PluginsTest: public Test {
@@ -351,6 +423,20 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
         soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, emptyHTML, strlen(emptyHTML));
         soup_message_body_complete(message->response_body);
         soup_message_set_status(message, SOUP_STATUS_OK);
+    } else if (g_str_equal(path, "/appcache")) {
+        const char* appcacheHTML = "<html manifest=appcache.manifest><body></body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, appcacheHTML, strlen(appcacheHTML));
+        soup_message_body_complete(message->response_body);
+        soup_message_set_status(message, SOUP_STATUS_OK);
+    } else if (g_str_equal(path, "/appcache.manifest")) {
+        const char* appcacheManifest = "CACHE MANIFEST\nCACHE:\nappcache/foo.txt\n";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, appcacheManifest, strlen(appcacheManifest));
+        soup_message_body_complete(message->response_body);
+        soup_message_set_status(message, SOUP_STATUS_OK);
+    } else if (g_str_equal(path, "/appcache/foo.txt")) {
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, "foo", 3);
+        soup_message_body_complete(message->response_body);
+        soup_message_set_status(message, SOUP_STATUS_OK);
     } else
         soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
 }
index 8eaf8e0..6054fe0 100644 (file)
@@ -69,19 +69,22 @@ public:
     {
         GUniquePtr<char> localStorageDirectory(g_build_filename(dataDirectory(), "local-storage", nullptr));
         GUniquePtr<char> indexedDBDirectory(g_build_filename(dataDirectory(), "indexeddb", nullptr));
-        m_webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT,
-            "local-storage-directory", localStorageDirectory.get(),
-            "indexed-db-directory", indexedDBDirectory.get(),
-            nullptr)));
-
-        g_signal_connect(m_webContext.get(), "initialize-web-extensions", G_CALLBACK(initializeWebExtensionsCallback), this);
         GUniquePtr<char> diskCacheDirectory(g_build_filename(dataDirectory(), "disk-cache", nullptr));
-        webkit_web_context_set_disk_cache_directory(m_webContext.get(), diskCacheDirectory.get());
+        GUniquePtr<char> applicationCacheDirectory(g_build_filename(dataDirectory(), "appcache", nullptr));
+        GUniquePtr<char> webSQLDirectory(g_build_filename(dataDirectory(), "websql", nullptr));
+        GRefPtr<WebKitWebsiteDataManager> websiteDataManager = adoptGRef(webkit_website_data_manager_new(
+            "local-storage-directory", localStorageDirectory.get(), "indexeddb-directory", indexedDBDirectory.get(),
+            "disk-cache-directory", diskCacheDirectory.get(), "offline-application-cache-directory", applicationCacheDirectory.get(),
+            "websql-directory", webSQLDirectory.get(), nullptr));
+
+        m_webContext = adoptGRef(webkit_web_context_new_with_website_data_manager(websiteDataManager.get()));
+        g_signal_connect(m_webContext.get(), "initialize-web-extensions", G_CALLBACK(initializeWebExtensionsCallback), this);
     }
 
     ~Test()
     {
         g_signal_handlers_disconnect_matched(m_webContext.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
+        m_webContext = nullptr;
         if (m_watchedObjects.isEmpty())
             return;
 
index 3865492..14f2c14 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <JavaScriptCore/JSRetainPtr.h>
 #include <WebCore/GUniquePtrGtk.h>
+#include <wtf/glib/GMainLoopSource.h>
 
 WebViewTest::WebViewTest(WebKitUserContentManager* userContentManager)
     : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", m_webContext.get(), "user-content-manager", userContentManager, nullptr))))
@@ -179,15 +180,10 @@ void WebViewTest::quitMainLoopAfterProcessingPendingEvents()
     quitMainLoop();
 }
 
-static gboolean quitMainLoopIdleCallback(WebViewTest* test)
-{
-    test->quitMainLoop();
-    return FALSE;
-}
-
 void WebViewTest::wait(double seconds)
 {
-    g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(quitMainLoopIdleCallback), this);
+    GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy("WebViewTest wait", [this] { quitMainLoop(); },
+        std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(seconds)));
     g_main_loop_run(m_mainLoop);
 }