+2012-04-11 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ [GTK] Initial cookies API for WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=82441
+
+ Reviewed by Gustavo Noronha Silva.
+
+ * GNUmakefile.am: Add new files to compilation.
+ * UIProcess/API/gtk/WebKitCookieManager.cpp: Added.
+ (webkit_cookie_manager_init):
+ (webkitCookieManagerFinalize):
+ (webkit_cookie_manager_class_init):
+ (webkitCookieManagerCreate): Create a new WebKitCookieManager for
+ the given WKCookieManagerRef.
+ (webkit_cookie_manager_set_accept_policy): Set the cookie
+ acceptance policy.
+ (webkitCookieManagerGetAcceptPolicyCallback): Callback called by
+ the C API when the cookie acceptance policy has been received.
+ (webkit_cookie_manager_get_accept_policy): Asynchronously get the
+ cookie acceptance policy.
+ (webkit_cookie_manager_get_accept_policy_finish): Finish async
+ operation started by webkit_cookie_manager_get_accept_policy()
+ returning the cookie acceptance policy.
+ (webkitCookieManagerGetDomainsWithCookiesCallback): Callback
+ called by the C API when the list of hostnames with cookies has
+ been received.
+ (webkit_cookie_manager_get_domains_with_cookies): Asynchronously
+ get the list of domains with cookies.
+ (webkit_cookie_manager_get_domains_with_cookies_finish): Finish
+ async operation started by
+ webkit_cookie_manager_get_domains_with_cookies() returning the
+ list of domains.
+ (webkit_cookie_manager_delete_cookies_for_domain): Delete all
+ cookies for the given domain.
+ (webkit_cookie_manager_delete_all_cookies): Delete all cookies.
+ * UIProcess/API/gtk/WebKitCookieManager.h: Added.
+ * UIProcess/API/gtk/WebKitCookieManagerPrivate.h: Added.
+ * UIProcess/API/gtk/WebKitWebContext.cpp:
+ (webkit_web_context_get_cookie_manager): Get the
+ WebKitCookieManager associated with the web context.
+ * UIProcess/API/gtk/WebKitWebContext.h:
+ * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new chapter for
+ WebKitCookieManager.
+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+ * UIProcess/API/gtk/docs/webkit2gtk.types: Add
+ webkit_cookie_manager_get_type.
+ * UIProcess/API/gtk/tests/GNUmakefile.am:
+ * UIProcess/API/gtk/tests/TestCookieManager.cpp: Added.
+ (testCookieManagerAcceptPolicy):
+ (testCookieManagerDeleteCookies):
+ (serverCallback):
+ (beforeAll):
+ (afterAll):
+ * UIProcess/API/gtk/webkit2.h: Include WebKitCookieManager.h.
+
2012-04-10 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>
[Qt] InspectorServer: Add an API level auto test
libwebkit2gtkinclude_HEADERS = \
$(WebKit2)/UIProcess/API/gtk/WebKitBackForwardList.h \
$(WebKit2)/UIProcess/API/gtk/WebKitBackForwardListItem.h \
+ $(WebKit2)/UIProcess/API/gtk/WebKitCookieManager.h \
$(WebKit2)/UIProcess/API/gtk/WebKitDefines.h \
$(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \
$(WebKit2)/UIProcess/API/gtk/WebKitEditingCommands.h \
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.h \
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h \
+ Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.h \
+ Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp \
+ Source/WebKit2/UIProcess/API/gtk/WebKitCookieManagerPrivate.h \
Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h \
Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h \
--- /dev/null
+/*
+ * Copyright (C) 2012 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 "WebKitCookieManager.h"
+
+#include "WebKitCookieManagerPrivate.h"
+#include "WebKitEnumTypes.h"
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+using namespace WebKit;
+
+struct _WebKitCookieManagerPrivate {
+ WKRetainPtr<WKCookieManagerRef> wkCookieManager;
+};
+
+G_DEFINE_TYPE(WebKitCookieManager, webkit_cookie_manager, G_TYPE_OBJECT)
+
+COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS, kWKHTTPCookieAcceptPolicyAlways);
+COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER, kWKHTTPCookieAcceptPolicyNever);
+COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY, kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain);
+
+static void webkit_cookie_manager_init(WebKitCookieManager* manager)
+{
+ WebKitCookieManagerPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(manager, WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManagerPrivate);
+ manager->priv = priv;
+ new (priv) WebKitCookieManagerPrivate();
+}
+
+static void webkitCookieManagerFinalize(GObject* object)
+{
+ WEBKIT_COOKIE_MANAGER(object)->priv->~WebKitCookieManagerPrivate();
+ G_OBJECT_CLASS(webkit_cookie_manager_parent_class)->finalize(object);
+}
+
+static void webkit_cookie_manager_class_init(WebKitCookieManagerClass* findClass)
+{
+ GObjectClass* gObjectClass = G_OBJECT_CLASS(findClass);
+ gObjectClass->finalize = webkitCookieManagerFinalize;
+
+ g_type_class_add_private(findClass, sizeof(WebKitCookieManagerPrivate));
+}
+
+WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef wkCookieManager)
+{
+ WebKitCookieManager* manager = WEBKIT_COOKIE_MANAGER(g_object_new(WEBKIT_TYPE_COOKIE_MANAGER, NULL));
+ manager->priv->wkCookieManager = wkCookieManager;
+ return manager;
+}
+
+/**
+ * webkit_cookie_manager_set_accept_policy:
+ * @cookie_manager: a #WebKitCookieManager
+ * @policy: a #WebKitCookieAcceptPolicy
+ *
+ * Set the cookie acceptance policy of @cookie_manager as @policy.
+ */
+void webkit_cookie_manager_set_accept_policy(WebKitCookieManager* manager, WebKitCookieAcceptPolicy policy)
+{
+ g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
+
+ WKCookieManagerSetHTTPCookieAcceptPolicy(manager->priv->wkCookieManager.get(), policy);
+}
+
+static void webkitCookieManagerGetAcceptPolicyCallback(WKHTTPCookieAcceptPolicy policy, WKErrorRef, void* context)
+{
+ GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context));
+ g_simple_async_result_set_op_res_gpointer(result.get(), GUINT_TO_POINTER(policy), 0);
+ g_simple_async_result_complete(result.get());
+}
+
+/**
+ * webkit_cookie_manager_get_accept_policy:
+ * @cookie_manager: a #WebKitCookieManager
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously get the cookie acceptance policy of @cookie_manager.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * webkit_cookie_manager_get_accept_policy_finish() to get the result of the operation.
+ */
+void webkit_cookie_manager_get_accept_policy(WebKitCookieManager* manager, GAsyncReadyCallback callback, gpointer userData)
+{
+ g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
+
+ GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(manager), callback, userData,
+ reinterpret_cast<gpointer>(webkit_cookie_manager_get_accept_policy));
+ WKCookieManagerGetHTTPCookieAcceptPolicy(manager->priv->wkCookieManager.get(), result, webkitCookieManagerGetAcceptPolicyCallback);
+}
+
+/**
+ * webkit_cookie_manager_get_accept_policy_finish:
+ * @cookie_manager: a #WebKitCookieManager
+ * @result: a #GAsyncResult
+ * @error: return location for error or %NULL to ignore
+ *
+ * Finish an asynchronous operation started with webkit_cookie_manager_get_accept_policy().
+ *
+ * Returns: the cookie acceptance policy of @cookie_manager as a #WebKitCookieAcceptPolicy.
+ */
+WebKitCookieAcceptPolicy webkit_cookie_manager_get_accept_policy_finish(WebKitCookieManager* manager, GAsyncResult* result, GError** error)
+{
+ g_return_val_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager), WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
+ g_return_val_if_fail(G_IS_ASYNC_RESULT(result), WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
+
+ GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
+ g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_cookie_manager_get_accept_policy);
+
+ if (g_simple_async_result_propagate_error(simpleResult, error))
+ return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
+
+ return static_cast<WebKitCookieAcceptPolicy>(GPOINTER_TO_UINT(g_simple_async_result_get_op_res_gpointer(simpleResult)));
+}
+
+static void webkitCookieManagerGetDomainsWithCookiesCallback(WKArrayRef wkDomains, WKErrorRef, void* context)
+{
+ GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context));
+ GPtrArray* domains = g_ptr_array_new_with_free_func(g_free);
+ for (size_t i = 0; i < WKArrayGetSize(wkDomains); ++i) {
+ WKStringRef wkDomain = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkDomains, i));
+ String domain = toImpl(wkDomain)->string();
+ if (domain.isEmpty())
+ continue;
+ g_ptr_array_add(domains, g_strdup(domain.utf8().data()));
+ }
+ g_ptr_array_add(domains, 0);
+ g_simple_async_result_set_op_res_gpointer(result.get(), domains, reinterpret_cast<GDestroyNotify>(g_ptr_array_unref));
+ g_simple_async_result_complete(result.get());
+}
+
+/**
+ * webkit_cookie_manager_get_domains_with_cookies:
+ * @cookie_manager: a #WebKitCookieManager
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously get the list of domains for which @cookie_manager contains cookies.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * webkit_cookie_manager_get_domains_with_cookies_finish() to get the result of the operation.
+ */
+void webkit_cookie_manager_get_domains_with_cookies(WebKitCookieManager* manager, GAsyncReadyCallback callback, gpointer userData)
+{
+ g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
+
+ GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(manager), callback, userData,
+ reinterpret_cast<gpointer>(webkit_cookie_manager_get_domains_with_cookies));
+ WKCookieManagerGetHostnamesWithCookies(manager->priv->wkCookieManager.get(), result, webkitCookieManagerGetDomainsWithCookiesCallback);
+}
+
+/**
+ * webkit_cookie_manager_get_domains_with_cookies_finish:
+ * @cookie_manager: a #WebKitCookieManager
+ * @result: a #GAsyncResult
+ * @error: return location for error or %NULL to ignore
+ *
+ * Finish an asynchronous operation started with webkit_cookie_manager_get_domains_with_cookies().
+ * The return value is a %NULL terminated list of strings which should
+ * be released with g_strfreev().
+ *
+ * Returns: (transfer full) (array zero-terminated=1): A %NULL terminated array of domain names
+ * or %NULL in case of error.
+ */
+gchar** webkit_cookie_manager_get_domains_with_cookies_finish(WebKitCookieManager* manager, GAsyncResult* result, GError** error)
+{
+ g_return_val_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager), 0);
+ g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0);
+
+ GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
+ g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_cookie_manager_get_domains_with_cookies);
+
+ if (g_simple_async_result_propagate_error(simpleResult, error))
+ return 0;
+
+ GPtrArray* domains = static_cast<GPtrArray*>(g_simple_async_result_get_op_res_gpointer(simpleResult));
+ return reinterpret_cast<char**>(g_ptr_array_free(domains, FALSE));
+}
+
+/**
+ * webkit_cookie_manager_delete_cookies_for_domain:
+ * @cookie_manager: a #WebKitCookieManager
+ * @domain: a domain name
+ *
+ * Remove all cookies of @cookie_manager for the given @domain.
+ */
+void webkit_cookie_manager_delete_cookies_for_domain(WebKitCookieManager* manager, const gchar* domain)
+{
+ g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
+ g_return_if_fail(domain);
+
+ WKRetainPtr<WKStringRef> wkDomain(AdoptWK, WKStringCreateWithUTF8CString(domain));
+ WKCookieManagerDeleteCookiesForHostname(manager->priv->wkCookieManager.get(), wkDomain.get());
+}
+
+/**
+ * webkit_cookie_manager_delete_all_cookies:
+ * @cookie_manager: a #WebKitCookieManager
+ *
+ * Delete all cookies of @cookie_manager
+ */
+void webkit_cookie_manager_delete_all_cookies(WebKitCookieManager* manager)
+{
+ g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
+
+ WKCookieManagerDeleteAllCookies(manager->priv->wkCookieManager.get());
+}
--- /dev/null
+/*
+ * Copyright (C) 2012 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 WebKitCookieManager_h
+#define WebKitCookieManager_h
+
+#include <gio/gio.h>
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_COOKIE_MANAGER (webkit_cookie_manager_get_type())
+#define WEBKIT_COOKIE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManager))
+#define WEBKIT_IS_COOKIE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_COOKIE_MANAGER))
+#define WEBKIT_COOKIE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManagerClass))
+#define WEBKIT_IS_COOKIE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_COOKIE_MANAGER))
+#define WEBKIT_COOKIE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManagerClass))
+
+typedef struct _WebKitCookieManager WebKitCookieManager;
+typedef struct _WebKitCookieManagerClass WebKitCookieManagerClass;
+typedef struct _WebKitCookieManagerPrivate WebKitCookieManagerPrivate;
+
+/**
+ * WebKitCookieAcceptPolicy:
+ * @WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS: Accept all cookies unconditionally.
+ * @WEBKIT_COOKIE_POLICY_ACCEPT_NEVER: Reject all cookies unconditionally.
+ * @WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY: Accept only cookies set by the main document loaded.
+ *
+ * Enum values used to denote the cookie acceptance policies.
+ */
+typedef enum {
+ WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS,
+ WEBKIT_COOKIE_POLICY_ACCEPT_NEVER,
+ WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY
+} WebKitCookieAcceptPolicy;
+
+struct _WebKitCookieManager {
+ GObject parent;
+
+ WebKitCookieManagerPrivate *priv;
+};
+
+struct _WebKitCookieManagerClass {
+ GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_cookie_manager_get_type (void);
+
+WEBKIT_API void
+webkit_cookie_manager_set_accept_policy (WebKitCookieManager *cookie_manager,
+ WebKitCookieAcceptPolicy policy);
+
+WEBKIT_API void
+webkit_cookie_manager_get_accept_policy (WebKitCookieManager *cookie_manager,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+WEBKIT_API WebKitCookieAcceptPolicy
+webkit_cookie_manager_get_accept_policy_finish (WebKitCookieManager *cookie_manager,
+ GAsyncResult *result,
+ GError **error);
+
+WEBKIT_API void
+webkit_cookie_manager_get_domains_with_cookies (WebKitCookieManager *cookie_manager,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+WEBKIT_API gchar **
+webkit_cookie_manager_get_domains_with_cookies_finish (WebKitCookieManager *cookie_manager,
+ GAsyncResult *result,
+ GError **error);
+
+WEBKIT_API void
+webkit_cookie_manager_delete_cookies_for_domain (WebKitCookieManager *cookie_manager,
+ const gchar *domain);
+
+WEBKIT_API void
+webkit_cookie_manager_delete_all_cookies (WebKitCookieManager *cookie_manager);
+
+G_END_DECLS
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2012 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 WebKitCookieManagerPrivate_h
+#define WebKitCookieManagerPrivate_h
+
+#include "WebKitCookieManager.h"
+#include "WebKitPrivate.h"
+
+WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef);
+
+#endif // WebKitCookieManagerPrivate_h
#include "WebKitWebContext.h"
#include "WebContext.h"
+#include "WebKitCookieManagerPrivate.h"
#include "WebKitDownloadClient.h"
#include "WebKitDownloadPrivate.h"
#include "WebKitPrivate.h"
struct _WebKitWebContextPrivate {
WKRetainPtr<WKContextRef> context;
+
+ GRefPtr<WebKitCookieManager> cookieManager;
};
static guint signals[LAST_SIGNAL] = { 0, };
return download;
}
+/**
+ * webkit_web_context_get_cookie_manager:
+ * @context: a #WebKitWebContext
+ *
+ * Get the #WebKitCookieManager of @context.
+ *
+ * Returns: (transfer none): the #WebKitCookieManager of @context.
+ */
+WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* context)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
+
+ WebKitWebContextPrivate* priv = context->priv;
+ if (!priv->cookieManager)
+ priv->cookieManager = adoptGRef(webkitCookieManagerCreate(WKContextGetCookieManager(priv->context.get())));
+
+ return priv->cookieManager.get();
+}
+
WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload)
{
GRefPtr<WebKitDownload> download = downloadsMap().get(wkDownload);
#define WebKitWebContext_h
#include <glib-object.h>
+#include <webkit2/WebKitCookieManager.h>
#include <webkit2/WebKitDefines.h>
#include <webkit2/WebKitDownload.h>
};
WEBKIT_API GType
-webkit_web_context_get_type (void);
+webkit_web_context_get_type (void);
WEBKIT_API WebKitWebContext *
-webkit_web_context_get_default (void);
+webkit_web_context_get_default (void);
WEBKIT_API void
-webkit_web_context_set_cache_model (WebKitWebContext *context,
- WebKitCacheModel cache_model);
+webkit_web_context_set_cache_model (WebKitWebContext *context,
+ WebKitCacheModel cache_model);
WEBKIT_API WebKitCacheModel
-webkit_web_context_get_cache_model (WebKitWebContext *context);
+webkit_web_context_get_cache_model (WebKitWebContext *context);
WEBKIT_API WebKitDownload *
-webkit_web_context_download_uri (WebKitWebContext *context,
- const gchar *uri);
+webkit_web_context_download_uri (WebKitWebContext *context,
+ const gchar *uri);
+
+WEBKIT_API WebKitCookieManager *
+webkit_web_context_get_cookie_manager (WebKitWebContext *context);
G_END_DECLS
<xi:include href="xml/WebKitWebResource.xml"/>
<xi:include href="xml/WebKitError.xml"/>
<xi:include href="xml/WebKitFindController.xml"/>
+ <xi:include href="xml/WebKitCookieManager.xml"/>
</chapter>
<index id="index-all">
webkit_web_context_get_cache_model
webkit_web_context_set_cache_model
webkit_web_context_download_uri
+webkit_web_context_get_cookie_manager
<SUBSECTION Standard>
WebKitWebContextClass
WebKitFindControllerPrivate
webkit_find_controller_get_type
</SECTION>
+
+<SECTION>
+<FILE>WebKitCookieManager</FILE>
+WebKitCookieManager
+WebKitCookieAcceptPolicy
+webkit_cookie_manager_set_accept_policy
+webkit_cookie_manager_get_accept_policy
+webkit_cookie_manager_get_accept_policy_finish
+webkit_cookie_manager_get_domains_with_cookies
+webkit_cookie_manager_get_domains_with_cookies_finish
+webkit_cookie_manager_delete_cookies_for_domain
+webkit_cookie_manager_delete_all_cookies
+
+<SUBSECTION Standard>
+WebKitCookieManagerClass
+WEBKIT_TYPE_COOKIE_MANAGER
+WEBKIT_COOKIE_MANAGER
+WEBKIT_IS_COOKIE_MANAGER
+WEBKIT_COOKIE_MANAGER_CLASS
+WEBKIT_IS_COOKIE_MANAGER_CLASS
+WEBKIT_COOKIE_MANAGER_GET_CLASS
+
+<SUBSECTION Private>
+WebKitCookieManagerPrivate
+webkit_cookie_manager_get_type
+</SECTION>
webkit_script_dialog_get_type
webkit_javascript_result_get_type
webkit_web_resource_get_type
+webkit_cookie_manager_get_type
TEST_PROGS += \
Programs/WebKit2APITests/TestBackForwardList \
+ Programs/WebKit2APITests/TestCookieManager \
Programs/WebKit2APITests/TestDownloads \
Programs/WebKit2APITests/TestLoaderClient \
Programs/WebKit2APITests/TestPrinting \
Programs_WebKit2APITests_TestResources_LDADD = $(webkit2_tests_ldadd)
Programs_WebKit2APITests_TestResources_LDFLAGS = $(webkit2_tests_ldflags)
+Programs_WebKit2APITests_TestCookieManager_SOURCES = \
+ Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp
+Programs_WebKit2APITests_TestCookieManager_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestCookieManager_LDADD = $(webkit2_tests_ldadd)
+Programs_WebKit2APITests_TestCookieManager_LDFLAGS = $(webkit2_tests_ldflags)
+
endif # ENABLE_WEBKIT2
--- /dev/null
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include "config.h"
+
+#include "WebKitTestServer.h"
+#include "WebViewTest.h"
+
+static WebKitTestServer* kServer;
+
+static const char* kFirstPartyDomain = "127.0.0.1";
+static const char* kThirdPartyDomain = "localhost";
+static const char* kIndexHtmlFormat =
+ "<html><body>"
+ " <p>WebKitGTK+ Cookie Manager test</p>"
+ " <img src='http://localhost:%u/image.png' width=5 height=5></img>"
+ "</body></html>";
+
+class CookieManagerTest: public WebViewTest {
+public:
+ MAKE_GLIB_TEST_FIXTURE(CookieManagerTest);
+
+ CookieManagerTest()
+ : WebViewTest()
+ , m_cookieManager(webkit_web_context_get_cookie_manager(webkit_web_view_get_context(m_webView)))
+ , m_acceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY)
+ , m_domains(0)
+ {
+ }
+
+ ~CookieManagerTest()
+ {
+ g_strfreev(m_domains);
+ }
+
+ static void getAcceptPolicyReadyCallback(GObject* object, GAsyncResult* result, gpointer userData)
+ {
+ GOwnPtr<GError> error;
+ WebKitCookieAcceptPolicy policy = webkit_cookie_manager_get_accept_policy_finish(WEBKIT_COOKIE_MANAGER(object), result, &error.outPtr());
+ g_assert(!error.get());
+
+ CookieManagerTest* test = static_cast<CookieManagerTest*>(userData);
+ test->m_acceptPolicy = policy;
+ g_main_loop_quit(test->m_mainLoop);
+ }
+
+ WebKitCookieAcceptPolicy getAcceptPolicy()
+ {
+ m_acceptPolicy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
+ webkit_cookie_manager_get_accept_policy(m_cookieManager, getAcceptPolicyReadyCallback, this);
+ g_main_loop_run(m_mainLoop);
+
+ return m_acceptPolicy;
+ }
+
+ void setAcceptPolicy(WebKitCookieAcceptPolicy policy)
+ {
+ webkit_cookie_manager_set_accept_policy(m_cookieManager, policy);
+ }
+
+ static void getDomainsReadyCallback(GObject* object, GAsyncResult* result, gpointer userData)
+ {
+ GOwnPtr<GError> error;
+ char** domains = webkit_cookie_manager_get_domains_with_cookies_finish(WEBKIT_COOKIE_MANAGER(object), result, &error.outPtr());
+ g_assert(!error.get());
+
+ CookieManagerTest* test = static_cast<CookieManagerTest*>(userData);
+ test->m_domains = domains;
+ g_main_loop_quit(test->m_mainLoop);
+ }
+
+ char** getDomains()
+ {
+ g_strfreev(m_domains);
+ m_domains = 0;
+ webkit_cookie_manager_get_domains_with_cookies(m_cookieManager, getDomainsReadyCallback, this);
+ g_main_loop_run(m_mainLoop);
+
+ return m_domains;
+ }
+
+ void deleteCookiesForDomain(const char* domain)
+ {
+ webkit_cookie_manager_delete_cookies_for_domain(m_cookieManager, domain);
+ }
+
+ void deleteAllCookies()
+ {
+ webkit_cookie_manager_delete_all_cookies(m_cookieManager);
+ }
+
+ WebKitCookieManager* m_cookieManager;
+ WebKitCookieAcceptPolicy m_acceptPolicy;
+ char** m_domains;
+};
+
+static void testCookieManagerAcceptPolicy(CookieManagerTest* test, gconstpointer)
+{
+ // Default policy is NO_THIRD_PARTY.
+ g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
+ test->loadURI(kServer->getURIForPath("/index.html").data());
+ test->waitUntilLoadFinished();
+ char** domains = test->getDomains();
+ g_assert(domains);
+ g_assert_cmpint(g_strv_length(domains), ==, 1);
+ g_assert_cmpstr(domains[0], ==, kFirstPartyDomain);
+ test->deleteAllCookies();
+
+ test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+ g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+ test->loadURI(kServer->getURIForPath("/index.html").data());
+ test->waitUntilLoadFinished();
+ domains = test->getDomains();
+ g_assert(domains);
+ g_assert_cmpint(g_strv_length(domains), ==, 2);
+ g_assert_cmpstr(domains[0], ==, kFirstPartyDomain);
+ g_assert_cmpstr(domains[1], ==, kThirdPartyDomain);
+ test->deleteAllCookies();
+
+ test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
+ g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
+ test->loadURI(kServer->getURIForPath("/index.html").data());
+ test->waitUntilLoadFinished();
+ domains = test->getDomains();
+ g_assert(domains);
+ g_assert_cmpint(g_strv_length(domains), ==, 0);
+}
+
+static void testCookieManagerDeleteCookies(CookieManagerTest* test, gconstpointer)
+{
+ test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+ test->loadURI(kServer->getURIForPath("/index.html").data());
+ test->waitUntilLoadFinished();
+ g_assert_cmpint(g_strv_length(test->getDomains()), ==, 2);
+
+ // Delete first party cookies.
+ test->deleteCookiesForDomain(kFirstPartyDomain);
+ g_assert_cmpint(g_strv_length(test->getDomains()), ==, 1);
+
+ // Delete third party cookies.
+ test->deleteCookiesForDomain(kThirdPartyDomain);
+ g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0);
+
+ test->loadURI(kServer->getURIForPath("/index.html").data());
+ test->waitUntilLoadFinished();
+ g_assert_cmpint(g_strv_length(test->getDomains()), ==, 2);
+
+ // Delete all cookies.
+ test->deleteAllCookies();
+ g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0);
+}
+
+static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
+{
+ if (message->method != SOUP_METHOD_GET) {
+ soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
+ return;
+ }
+
+ soup_message_set_status(message, SOUP_STATUS_OK);
+ if (g_str_equal(path, "/index.html")) {
+ char* indexHtml = g_strdup_printf(kIndexHtmlFormat, soup_server_get_port(server));
+ soup_message_headers_replace(message->response_headers, "Set-Cookie", "foo=bar");
+ soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, indexHtml, strlen(indexHtml));
+ } else if (g_str_equal(path, "/image.png"))
+ soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux");
+ else
+ g_assert_not_reached();
+ soup_message_body_complete(message->response_body);
+}
+
+void beforeAll()
+{
+ kServer = new WebKitTestServer();
+ kServer->run(serverCallback);
+
+ CookieManagerTest::add("WebKitCookieManager", "accept-policy", testCookieManagerAcceptPolicy);
+ CookieManagerTest::add("WebKitCookieManager", "delete-cookies", testCookieManagerDeleteCookies);
+}
+
+void afterAll()
+{
+ delete kServer;
+}
#include <webkit2/WebKitBackForwardList.h>
#include <webkit2/WebKitBackForwardListItem.h>
+#include <webkit2/WebKitCookieManager.h>
#include <webkit2/WebKitDefines.h>
#include <webkit2/WebKitDownload.h>
#include <webkit2/WebKitEditingCommands.h>