Source/WebKit2/ChangeLog

 12012-03-28 Carlos Garcia Campos <cgarcia@igalia.com>
 2
 3 [GTK] Initial cookies API for WebKit2 GTK+ API
 4 https://bugs.webkit.org/show_bug.cgi?id=82441
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * GNUmakefile.am: Add new files to compilation.
 9 * UIProcess/API/gtk/WebKitCookieManager.cpp: Added.
 10 (webkit_cookie_manager_init):
 11 (webkitCookieManagerFinalize):
 12 (webkit_cookie_manager_class_init):
 13 (webkitCookieManagerCreate): Create a new WebKitCookieManager for
 14 the given WKCookieManagerRef.
 15 (webkit_cookie_manager_set_accept_policy): Set the cookie
 16 acceptance policy.
 17 (webkitCookieManagerGetAcceptPolicyCallback): Callback called by
 18 the C API when the cookie acceptance policy has been received.
 19 (webkit_cookie_manager_get_accept_policy): Asynchronously get the
 20 cookie acceptance policy.
 21 (webkit_cookie_manager_get_accept_policy_finish): Finish async
 22 operation started by webkit_cookie_manager_get_accept_policy()
 23 returning the cookie acceptance policy.
 24 (webkitCookieManagerGetDomainsWithCookiesCallback): Callback
 25 called by the C API when the list of hostnames with cookies has
 26 been received.
 27 (webkit_cookie_manager_get_domains_with_cookies): Asynchronously
 28 get the list of domains with cookies.
 29 (webkit_cookie_manager_get_domains_with_cookies_finish): Finish
 30 async operation started by
 31 webkit_cookie_manager_get_domains_with_cookies() returning the
 32 list of domains.
 33 (webkit_cookie_manager_delete_cookies_for_domain): Delete all
 34 cookies for the given domain.
 35 (webkit_cookie_manager_delete_all_cookies): Delete all cookies.
 36 * UIProcess/API/gtk/WebKitCookieManager.h: Added.
 37 * UIProcess/API/gtk/WebKitCookieManagerPrivate.h: Added.
 38 * UIProcess/API/gtk/WebKitWebContext.cpp:
 39 (webkit_web_context_get_cookie_manager): Get the
 40 WebKitCookieManager associated with the web context.
 41 * UIProcess/API/gtk/WebKitWebContext.h:
 42 * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new chapter for
 43 WebKitCookieManager.
 44 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
 45 * UIProcess/API/gtk/docs/webkit2gtk.types: Add
 46 webkit_cookie_manager_get_type.
 47 * UIProcess/API/gtk/tests/GNUmakefile.am:
 48 * UIProcess/API/gtk/tests/TestCookieManager.cpp: Added.
 49 (testCookieManagerAcceptPolicy):
 50 (testCookieManagerDeleteCookies):
 51 (serverCallback):
 52 (beforeAll):
 53 (afterAll):
 54 * UIProcess/API/gtk/webkit2.h: Include WebKitCookieManager.h.
 55
1562012-03-27 Carlos Garcia Campos <cgarcia@igalia.com>
257
358 Implement WebFrameNetworkingContext for soup in WebKit2

Source/WebKit2/GNUmakefile.am

@@nodist_libwebkit2gtkinclude_HEADERS = \
8686libwebkit2gtkinclude_HEADERS = \
8787 $(WebKit2)/UIProcess/API/gtk/WebKitBackForwardList.h \
8888 $(WebKit2)/UIProcess/API/gtk/WebKitBackForwardListItem.h \
 89 $(WebKit2)/UIProcess/API/gtk/WebKitCookieManager.h \
8990 $(WebKit2)/UIProcess/API/gtk/WebKitDefines.h \
9091 $(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \
9192 $(WebKit2)/UIProcess/API/gtk/WebKitEditingCommands.h \

@@webkit2_sources += \
545546 Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.h \
546547 Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp \
547548 Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h \
 549 Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.h \
 550 Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp \
 551 Source/WebKit2/UIProcess/API/gtk/WebKitCookieManagerPrivate.h \
548552 Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h \
549553 Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp \
550554 Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h \

Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp

 1/*
 2 * Copyright (C) 2012 Igalia S.L.
 3 *
 4 * This library is free software; you can redistribute it and/or
 5 * modify it under the terms of the GNU Lesser General Public
 6 * License as published by the Free Software Foundation; either
 7 * version 2,1 of the License, or (at your option) any later version.
 8 *
 9 * This library is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 * Library General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU Library General Public License
 15 * along with this library; see the file COPYING.LIB. If not, write to
 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17 * Boston, MA 02110-1301, USA.
 18 */
 19
 20#include "config.h"
 21#include "WebKitCookieManager.h"
 22
 23#include "WebKitCookieManagerPrivate.h"
 24#include "WebKitEnumTypes.h"
 25#include <wtf/gobject/GRefPtr.h>
 26#include <wtf/text/CString.h>
 27
 28using namespace WebKit;
 29
 30struct _WebKitCookieManagerPrivate {
 31 WKRetainPtr<WKCookieManagerRef> wkCookieManager;
 32};
 33
 34G_DEFINE_TYPE(WebKitCookieManager, webkit_cookie_manager, G_TYPE_OBJECT)
 35
 36COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS, kWKHTTPCookieAcceptPolicyAlways);
 37COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER, kWKHTTPCookieAcceptPolicyNever);
 38COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY, kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain);
 39
 40static void webkit_cookie_manager_init(WebKitCookieManager* manager)
 41{
 42 WebKitCookieManagerPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(manager, WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManagerPrivate);
 43 manager->priv = priv;
 44 new (priv) WebKitCookieManagerPrivate();
 45}
 46
 47static void webkitCookieManagerFinalize(GObject* object)
 48{
 49 WEBKIT_COOKIE_MANAGER(object)->priv->~WebKitCookieManagerPrivate();
 50 G_OBJECT_CLASS(webkit_cookie_manager_parent_class)->finalize(object);
 51}
 52
 53static void webkit_cookie_manager_class_init(WebKitCookieManagerClass* findClass)
 54{
 55 GObjectClass* gObjectClass = G_OBJECT_CLASS(findClass);
 56 gObjectClass->finalize = webkitCookieManagerFinalize;
 57
 58 g_type_class_add_private(findClass, sizeof(WebKitCookieManagerPrivate));
 59}
 60
 61WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef wkCookieManager)
 62{
 63 WebKitCookieManager* manager = WEBKIT_COOKIE_MANAGER(g_object_new(WEBKIT_TYPE_COOKIE_MANAGER, NULL));
 64 manager->priv->wkCookieManager = wkCookieManager;
 65 return manager;
 66}
 67
 68/**
 69 * webkit_cookie_manager_set_accept_policy:
 70 * @cookie_manager: a #WebKitCookieManager
 71 * @policy: a #WebKitCookieAcceptPolicy
 72 *
 73 * Set the cookie acceptance policy of @cookie_manager as @policy.
 74 */
 75void webkit_cookie_manager_set_accept_policy(WebKitCookieManager* manager, WebKitCookieAcceptPolicy policy)
 76{
 77 g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 78
 79 WKCookieManagerSetHTTPCookieAcceptPolicy(manager->priv->wkCookieManager.get(), policy);
 80}
 81
 82static void webkitCookieManagerGetAcceptPolicyCallback(WKHTTPCookieAcceptPolicy policy, WKErrorRef, void* context)
 83{
 84 GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context));
 85 g_simple_async_result_set_op_res_gpointer(result.get(), GUINT_TO_POINTER(policy), 0);
 86 g_simple_async_result_complete(result.get());
 87}
 88
 89/**
 90 * webkit_cookie_manager_get_accept_policy:
 91 * @cookie_manager: a #WebKitCookieManager
 92 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
 93 * @user_data: (closure): the data to pass to callback function
 94 *
 95 * Asynchronously get the cookie acceptance policy of @cookie_manager.
 96 *
 97 * When the operation is finished, @callback will be called. You can then call
 98 * webkit_cookie_manager_get_accept_policy_finish() to get the result of the operation.
 99 */
 100void webkit_cookie_manager_get_accept_policy(WebKitCookieManager* manager, GAsyncReadyCallback callback, gpointer userData)
 101{
 102 g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 103
 104 GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(manager), callback, userData,
 105 reinterpret_cast<gpointer>(webkit_cookie_manager_get_accept_policy));
 106 WKCookieManagerGetHTTPCookieAcceptPolicy(manager->priv->wkCookieManager.get(), result, webkitCookieManagerGetAcceptPolicyCallback);
 107}
 108
 109/**
 110 * webkit_cookie_manager_get_accept_policy_finish:
 111 * @cookie_manager: a #WebKitCookieManager
 112 * @result: a #GAsyncResult
 113 * @error: return location for error or %NULL to ignore
 114 *
 115 * Finish an asynchronous operation started with webkit_cookie_manager_get_accept_policy().
 116 *
 117 * Returns: the cookie acceptance policy of @cookie_manager as a #WebKitCookieAcceptPolicy.
 118 */
 119WebKitCookieAcceptPolicy webkit_cookie_manager_get_accept_policy_finish(WebKitCookieManager* manager, GAsyncResult* result, GError** error)
 120{
 121 g_return_val_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager), WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
 122 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
 123
 124 GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
 125 g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_cookie_manager_get_accept_policy);
 126
 127 if (g_simple_async_result_propagate_error(simpleResult, error))
 128 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
 129
 130 return static_cast<WebKitCookieAcceptPolicy>(GPOINTER_TO_UINT(g_simple_async_result_get_op_res_gpointer(simpleResult)));
 131}
 132
 133static void webkitCookieManagerGetDomainsWithCookiesCallback(WKArrayRef wkDomains, WKErrorRef, void* context)
 134{
 135 GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context));
 136 GPtrArray* domains = g_ptr_array_new_with_free_func(g_free);
 137 for (size_t i = 0; i < WKArrayGetSize(wkDomains); ++i) {
 138 WKStringRef wkDomain = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkDomains, i));
 139 String domain = toImpl(wkDomain)->string();
 140 if (domain.isEmpty())
 141 continue;
 142 g_ptr_array_add(domains, g_strdup(domain.utf8().data()));
 143 }
 144 g_ptr_array_add(domains, 0);
 145 g_simple_async_result_set_op_res_gpointer(result.get(), domains, reinterpret_cast<GDestroyNotify>(g_ptr_array_unref));
 146 g_simple_async_result_complete(result.get());
 147}
 148
 149/**
 150 * webkit_cookie_manager_get_domains_with_cookies:
 151 * @cookie_manager: a #WebKitCookieManager
 152 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
 153 * @user_data: (closure): the data to pass to callback function
 154 *
 155 * Asynchronously get the list of domains for which @cookie_manager contains cookies.
 156 *
 157 * When the operation is finished, @callback will be called. You can then call
 158 * webkit_cookie_manager_get_domains_with_cookies_finish() to get the result of the operation.
 159 */
 160void webkit_cookie_manager_get_domains_with_cookies(WebKitCookieManager* manager, GAsyncReadyCallback callback, gpointer userData)
 161{
 162 g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 163
 164 GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(manager), callback, userData,
 165 reinterpret_cast<gpointer>(webkit_cookie_manager_get_domains_with_cookies));
 166 WKCookieManagerGetHostnamesWithCookies(manager->priv->wkCookieManager.get(), result, webkitCookieManagerGetDomainsWithCookiesCallback);
 167}
 168
 169/**
 170 * webkit_cookie_manager_get_domains_with_cookies_finish:
 171 * @cookie_manager: a #WebKitCookieManager
 172 * @result: a #GAsyncResult
 173 * @error: return location for error or %NULL to ignore
 174 *
 175 * Finish an asynchronous operation started with webkit_cookie_manager_get_domains_with_cookies().
 176 * The return value is a %NULL terminated list of strings which should
 177 * be released with g_strfreev().
 178 *
 179 * Returns: (transfer full) (array zero-terminated=1): A %NULL terminated array of domain names
 180 * or %NULL in case of error.
 181 */
 182gchar** webkit_cookie_manager_get_domains_with_cookies_finish(WebKitCookieManager* manager, GAsyncResult* result, GError** error)
 183{
 184 g_return_val_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager), 0);
 185 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0);
 186
 187 GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
 188 g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_cookie_manager_get_domains_with_cookies);
 189
 190 if (g_simple_async_result_propagate_error(simpleResult, error))
 191 return 0;
 192
 193 GPtrArray* domains = static_cast<GPtrArray*>(g_simple_async_result_get_op_res_gpointer(simpleResult));
 194 return reinterpret_cast<char**>(g_ptr_array_free(domains, FALSE));
 195}
 196
 197/**
 198 * webkit_cookie_manager_delete_cookies_for_domain:
 199 * @cookie_manager: a #WebKitCookieManager
 200 * @domain: a domain name
 201 *
 202 * Remove all cookies of @cookie_manager for the given @domain.
 203 */
 204void webkit_cookie_manager_delete_cookies_for_domain(WebKitCookieManager* manager, const gchar* domain)
 205{
 206 g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 207 g_return_if_fail(domain);
 208
 209 WKRetainPtr<WKStringRef> wkDomain(AdoptWK, WKStringCreateWithUTF8CString(domain));
 210 WKCookieManagerDeleteCookiesForHostname(manager->priv->wkCookieManager.get(), wkDomain.get());
 211}
 212
 213/**
 214 * webkit_cookie_manager_delete_all_cookies:
 215 * @cookie_manager: a #WebKitCookieManager
 216 *
 217 * Delete all cookies of @cookie_manager
 218 */
 219void webkit_cookie_manager_delete_all_cookies(WebKitCookieManager* manager)
 220{
 221 g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
 222
 223 WKCookieManagerDeleteAllCookies(manager->priv->wkCookieManager.get());
 224}

Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.h

 1/*
 2 * Copyright (C) 2012 Igalia S.L.
 3 *
 4 * This library is free software; you can redistribute it and/or
 5 * modify it under the terms of the GNU Lesser General Public
 6 * License as published by the Free Software Foundation; either
 7 * version 2,1 of the License, or (at your option) any later version.
 8 *
 9 * This library is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 * Library General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU Library General Public License
 15 * along with this library; see the file COPYING.LIB. If not, write to
 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17 * Boston, MA 02110-1301, USA.
 18 */
 19
 20#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
 21#error "Only <webkit2/webkit2.h> can be included directly."
 22#endif
 23
 24#ifndef WebKitCookieManager_h
 25#define WebKitCookieManager_h
 26
 27#include <gio/gio.h>
 28#include <glib-object.h>
 29#include <webkit2/WebKitDefines.h>
 30
 31G_BEGIN_DECLS
 32
 33#define WEBKIT_TYPE_COOKIE_MANAGER (webkit_cookie_manager_get_type())
 34#define WEBKIT_COOKIE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManager))
 35#define WEBKIT_IS_COOKIE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_COOKIE_MANAGER))
 36#define WEBKIT_COOKIE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManagerClass))
 37#define WEBKIT_IS_COOKIE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_COOKIE_MANAGER))
 38#define WEBKIT_COOKIE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_COOKIE_MANAGER, WebKitCookieManagerClass))
 39
 40typedef struct _WebKitCookieManager WebKitCookieManager;
 41typedef struct _WebKitCookieManagerClass WebKitCookieManagerClass;
 42typedef struct _WebKitCookieManagerPrivate WebKitCookieManagerPrivate;
 43
 44/**
 45 * WebKitCookieAcceptPolicy:
 46 * @WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS: Accept all cookies unconditionally.
 47 * @WEBKIT_COOKIE_POLICY_ACCEPT_NEVER: Reject all cookies unconditionally.
 48 * @WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY: Accept only cookies set by the main document loaded.
 49 *
 50 * Enum values used to denote the cookie acceptance policies.
 51 */
 52typedef enum {
 53 WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS,
 54 WEBKIT_COOKIE_POLICY_ACCEPT_NEVER,
 55 WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY
 56} WebKitCookieAcceptPolicy;
 57
 58struct _WebKitCookieManager {
 59 GObject parent;
 60
 61 WebKitCookieManagerPrivate *priv;
 62};
 63
 64struct _WebKitCookieManagerClass {
 65 GObjectClass parent_class;
 66};
 67
 68WEBKIT_API GType
 69webkit_cookie_manager_get_type (void);
 70
 71WEBKIT_API void
 72webkit_cookie_manager_set_accept_policy (WebKitCookieManager *cookie_manager,
 73 WebKitCookieAcceptPolicy policy);
 74
 75WEBKIT_API void
 76webkit_cookie_manager_get_accept_policy (WebKitCookieManager *cookie_manager,
 77 GAsyncReadyCallback callback,
 78 gpointer user_data);
 79
 80WEBKIT_API WebKitCookieAcceptPolicy
 81webkit_cookie_manager_get_accept_policy_finish (WebKitCookieManager *cookie_manager,
 82 GAsyncResult *result,
 83 GError **error);
 84
 85WEBKIT_API void
 86webkit_cookie_manager_get_domains_with_cookies (WebKitCookieManager *cookie_manager,
 87 GAsyncReadyCallback callback,
 88 gpointer user_data);
 89
 90WEBKIT_API gchar **
 91webkit_cookie_manager_get_domains_with_cookies_finish (WebKitCookieManager *cookie_manager,
 92 GAsyncResult *result,
 93 GError **error);
 94
 95WEBKIT_API void
 96webkit_cookie_manager_delete_cookies_for_domain (WebKitCookieManager *cookie_manager,
 97 const gchar *domain);
 98
 99WEBKIT_API void
 100webkit_cookie_manager_delete_all_cookies (WebKitCookieManager *cookie_manager);
 101
 102G_END_DECLS
 103
 104#endif

Source/WebKit2/UIProcess/API/gtk/WebKitCookieManagerPrivate.h

 1/*
 2 * Copyright (C) 2012 Igalia S.L.
 3 *
 4 * This library is free software; you can redistribute it and/or
 5 * modify it under the terms of the GNU Library General Public
 6 * License as published by the Free Software Foundation; either
 7 * version 2 of the License, or (at your option) any later version.
 8 *
 9 * This library is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 * Library General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU Library General Public License
 15 * along with this library; see the file COPYING.LIB. If not, write to
 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17 * Boston, MA 02110-1301, USA.
 18 */
 19
 20#ifndef WebKitCookieManagerPrivate_h
 21#define WebKitCookieManagerPrivate_h
 22
 23#include "WebKitCookieManager.h"
 24#include "WebKitPrivate.h"
 25
 26WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef);
 27
 28#endif // WebKitCookieManagerPrivate_h

Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

2121#include "WebKitWebContext.h"
2222
2323#include "WebContext.h"
 24#include "WebKitCookieManagerPrivate.h"
2425#include "WebKitDownloadClient.h"
2526#include "WebKitDownloadPrivate.h"
2627#include "WebKitPrivate.h"

@@enum {
3940
4041struct _WebKitWebContextPrivate {
4142 WKRetainPtr<WKContextRef> context;
 43
 44 GRefPtr<WebKitCookieManager> cookieManager;
4245};
4346
4447static guint signals[LAST_SIGNAL] = { 0, };

@@WebKitDownload* webkit_web_context_download_uri(WebKitWebContext* context, const
215218 return download;
216219}
217220
 221/**
 222 * webkit_web_context_get_cookie_manager:
 223 * @context: a #WebKitWebContext
 224 *
 225 * Get the #WebKitCookieManager of @context.
 226 *
 227 * Returns: (transfer none): the #WebKitCookieManager of @context.
 228 */
 229WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* context)
 230{
 231 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
 232
 233 WebKitWebContextPrivate* priv = context->priv;
 234 if (!priv->cookieManager)
 235 priv->cookieManager = adoptGRef(webkitCookieManagerCreate(WKContextGetCookieManager(priv->context.get())));
 236
 237 return priv->cookieManager.get();
 238}
 239
218240WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload)
219241{
220242 GRefPtr<WebKitDownload> download = downloadsMap().get(wkDownload);

Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h

2525#define WebKitWebContext_h
2626
2727#include <glib-object.h>
 28#include <webkit2/WebKitCookieManager.h>
2829#include <webkit2/WebKitDefines.h>
2930#include <webkit2/WebKitDownload.h>
3031

@@struct _WebKitWebContextClass {
7980};
8081
8182WEBKIT_API GType
82 webkit_web_context_get_type (void);
 83webkit_web_context_get_type (void);
8384
8485WEBKIT_API WebKitWebContext *
85 webkit_web_context_get_default (void);
 86webkit_web_context_get_default (void);
8687
8788WEBKIT_API void
88 webkit_web_context_set_cache_model (WebKitWebContext *context,
89  WebKitCacheModel cache_model);
 89webkit_web_context_set_cache_model (WebKitWebContext *context,
 90 WebKitCacheModel cache_model);
9091WEBKIT_API WebKitCacheModel
91 webkit_web_context_get_cache_model (WebKitWebContext *context);
 92webkit_web_context_get_cache_model (WebKitWebContext *context);
9293
9394WEBKIT_API WebKitDownload *
94 webkit_web_context_download_uri (WebKitWebContext *context,
95  const gchar *uri);
 95webkit_web_context_download_uri (WebKitWebContext *context,
 96 const gchar *uri);
 97
 98WEBKIT_API WebKitCookieManager *
 99webkit_web_context_get_cookie_manager (WebKitWebContext *context);
96100
97101G_END_DECLS
98102

Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

2929 <xi:include href="xml/WebKitWebResource.xml"/>
3030 <xi:include href="xml/WebKitError.xml"/>
3131 <xi:include href="xml/WebKitFindController.xml"/>
 32 <xi:include href="xml/WebKitCookieManager.xml"/>
3233 </chapter>
3334
3435 <index id="index-all">

Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

@@webkit_web_context_get_default
2828webkit_web_context_get_cache_model
2929webkit_web_context_set_cache_model
3030webkit_web_context_download_uri
 31webkit_web_context_get_cookie_manager
3132
3233<SUBSECTION Standard>
3334WebKitWebContextClass

@@WEBKIT_FIND_CONTROLLER_GET_CLASS
546547WebKitFindControllerPrivate
547548webkit_find_controller_get_type
548549</SECTION>
 550
 551<SECTION>
 552<FILE>WebKitCookieManager</FILE>
 553WebKitCookieManager
 554WebKitCookieAcceptPolicy
 555webkit_cookie_manager_set_accept_policy
 556webkit_cookie_manager_get_accept_policy
 557webkit_cookie_manager_get_accept_policy_finish
 558webkit_cookie_manager_get_domains_with_cookies
 559webkit_cookie_manager_get_domains_with_cookies_finish
 560webkit_cookie_manager_delete_cookies_for_domain
 561webkit_cookie_manager_delete_all_cookies
 562
 563<SUBSECTION Standard>
 564WebKitCookieManagerClass
 565WEBKIT_TYPE_COOKIE_MANAGER
 566WEBKIT_COOKIE_MANAGER
 567WEBKIT_IS_COOKIE_MANAGER
 568WEBKIT_COOKIE_MANAGER_CLASS
 569WEBKIT_IS_COOKIE_MANAGER_CLASS
 570WEBKIT_COOKIE_MANAGER_GET_CLASS
 571
 572<SUBSECTION Private>
 573WebKitCookieManagerPrivate
 574webkit_cookie_manager_get_type
 575</SECTION>

Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types

@@webkit_find_controller_get_type
1313webkit_script_dialog_get_type
1414webkit_javascript_result_get_type
1515webkit_web_resource_get_type
 16webkit_cookie_manager_get_type

Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am

@@if ENABLE_WEBKIT2
22
33TEST_PROGS += \
44 Programs/WebKit2APITests/TestBackForwardList \
 5 Programs/WebKit2APITests/TestCookieManager \
56 Programs/WebKit2APITests/TestDownloads \
67 Programs/WebKit2APITests/TestLoaderClient \
78 Programs/WebKit2APITests/TestPrinting \

@@Programs_WebKit2APITests_TestResources_CPPFLAGS = $(webkit2_tests_cppflags)
142143Programs_WebKit2APITests_TestResources_LDADD = $(webkit2_tests_ldadd)
143144Programs_WebKit2APITests_TestResources_LDFLAGS = $(webkit2_tests_ldflags)
144145
 146Programs_WebKit2APITests_TestCookieManager_SOURCES = \
 147 Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp
 148Programs_WebKit2APITests_TestCookieManager_CPPFLAGS = $(webkit2_tests_cppflags)
 149Programs_WebKit2APITests_TestCookieManager_LDADD = $(webkit2_tests_ldadd)
 150Programs_WebKit2APITests_TestCookieManager_LDFLAGS = $(webkit2_tests_ldflags)
 151
145152endif # ENABLE_WEBKIT2

Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp

 1/*
 2 * Copyright (C) 2012 Igalia S.L.
 3 *
 4 * This library is free software; you can redistribute it and/or
 5 * modify it under the terms of the GNU Library General Public
 6 * License as published by the Free Software Foundation; either
 7 * version 2 of the License, or (at your option) any later version.
 8 *
 9 * This library is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 * Library General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU Library General Public License
 15 * along with this library; see the file COPYING.LIB. If not, write to
 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17 * Boston, MA 02110-1301, USA.
 18 */
 19
 20#include "config.h"
 21
 22#include "WebKitTestServer.h"
 23#include "WebViewTest.h"
 24
 25static WebKitTestServer* kServer;
 26
 27static const char* kFirstPartyDomain = "127.0.0.1";
 28static const char* kThirdPartyDomain = "localhost";
 29static const char* kIndexHtmlFormat =
 30 "<html><body>"
 31 " <p>WebKitGTK+ Cookie Manager test</p>"
 32 " <img src='http://localhost:%u/image.png' width=5 height=5></img>"
 33 "</body></html>";
 34
 35class CookieManagerTest: public WebViewTest {
 36public:
 37 MAKE_GLIB_TEST_FIXTURE(CookieManagerTest);
 38
 39 CookieManagerTest()
 40 : WebViewTest()
 41 , m_cookieManager(webkit_web_context_get_cookie_manager(webkit_web_view_get_context(m_webView)))
 42 , m_acceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY)
 43 , m_domains(0)
 44 {
 45 }
 46
 47 ~CookieManagerTest()
 48 {
 49 g_strfreev(m_domains);
 50 }
 51
 52 static void getAcceptPolicyReadyCallback(GObject* object, GAsyncResult* result, gpointer userData)
 53 {
 54 GOwnPtr<GError> error;
 55 WebKitCookieAcceptPolicy policy = webkit_cookie_manager_get_accept_policy_finish(WEBKIT_COOKIE_MANAGER(object), result, &error.outPtr());
 56 g_assert(!error.get());
 57
 58 CookieManagerTest* test = static_cast<CookieManagerTest*>(userData);
 59 test->m_acceptPolicy = policy;
 60 g_main_loop_quit(test->m_mainLoop);
 61 }
 62
 63 WebKitCookieAcceptPolicy getAcceptPolicy()
 64 {
 65 m_acceptPolicy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
 66 webkit_cookie_manager_get_accept_policy(m_cookieManager, getAcceptPolicyReadyCallback, this);
 67 g_main_loop_run(m_mainLoop);
 68
 69 return m_acceptPolicy;
 70 }
 71
 72 void setAcceptPolicy(WebKitCookieAcceptPolicy policy)
 73 {
 74 webkit_cookie_manager_set_accept_policy(m_cookieManager, policy);
 75 }
 76
 77 static void getDomainsReadyCallback(GObject* object, GAsyncResult* result, gpointer userData)
 78 {
 79 GOwnPtr<GError> error;
 80 char** domains = webkit_cookie_manager_get_domains_with_cookies_finish(WEBKIT_COOKIE_MANAGER(object), result, &error.outPtr());
 81 g_assert(!error.get());
 82
 83 CookieManagerTest* test = static_cast<CookieManagerTest*>(userData);
 84 test->m_domains = domains;
 85 g_main_loop_quit(test->m_mainLoop);
 86 }
 87
 88 char** getDomains()
 89 {
 90 g_strfreev(m_domains);
 91 m_domains = 0;
 92 webkit_cookie_manager_get_domains_with_cookies(m_cookieManager, getDomainsReadyCallback, this);
 93 g_main_loop_run(m_mainLoop);
 94
 95 return m_domains;
 96 }
 97
 98 void deleteCookiesForDomain(const char* domain)
 99 {
 100 webkit_cookie_manager_delete_cookies_for_domain(m_cookieManager, domain);
 101 }
 102
 103 void deleteAllCookies()
 104 {
 105 webkit_cookie_manager_delete_all_cookies(m_cookieManager);
 106 }
 107
 108 WebKitCookieManager* m_cookieManager;
 109 WebKitCookieAcceptPolicy m_acceptPolicy;
 110 char** m_domains;
 111};
 112
 113static void testCookieManagerAcceptPolicy(CookieManagerTest* test, gconstpointer)
 114{
 115 // Default policy is NO_THIRD_PARTY.
 116 g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
 117 test->loadURI(kServer->getURIForPath("/index.html").data());
 118 test->waitUntilLoadFinished();
 119 char** domains = test->getDomains();
 120 g_assert(domains);
 121 g_assert_cmpint(g_strv_length(domains), ==, 1);
 122 g_assert_cmpstr(domains[0], ==, kFirstPartyDomain);
 123 test->deleteAllCookies();
 124
 125 test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
 126 g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
 127 test->loadURI(kServer->getURIForPath("/index.html").data());
 128 test->waitUntilLoadFinished();
 129 domains = test->getDomains();
 130 g_assert(domains);
 131 g_assert_cmpint(g_strv_length(domains), ==, 2);
 132 g_assert_cmpstr(domains[0], ==, kFirstPartyDomain);
 133 g_assert_cmpstr(domains[1], ==, kThirdPartyDomain);
 134 test->deleteAllCookies();
 135
 136 test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
 137 g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
 138 test->loadURI(kServer->getURIForPath("/index.html").data());
 139 test->waitUntilLoadFinished();
 140 domains = test->getDomains();
 141 g_assert(domains);
 142 g_assert_cmpint(g_strv_length(domains), ==, 0);
 143}
 144
 145static void testCookieManagerDeleteCookies(CookieManagerTest* test, gconstpointer)
 146{
 147 test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
 148 test->loadURI(kServer->getURIForPath("/index.html").data());
 149 test->waitUntilLoadFinished();
 150 g_assert_cmpint(g_strv_length(test->getDomains()), ==, 2);
 151
 152 // Delete first party cookies.
 153 test->deleteCookiesForDomain(kFirstPartyDomain);
 154 g_assert_cmpint(g_strv_length(test->getDomains()), ==, 1);
 155
 156 // Delete third party cookies.
 157 test->deleteCookiesForDomain(kThirdPartyDomain);
 158 g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0);
 159
 160 test->loadURI(kServer->getURIForPath("/index.html").data());
 161 test->waitUntilLoadFinished();
 162 g_assert_cmpint(g_strv_length(test->getDomains()), ==, 2);
 163
 164 // Delete all cookies.
 165 test->deleteAllCookies();
 166 g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0);
 167}
 168
 169static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 170{
 171 if (message->method != SOUP_METHOD_GET) {
 172 soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
 173 return;
 174 }
 175
 176 soup_message_set_status(message, SOUP_STATUS_OK);
 177 if (g_str_equal(path, "/index.html")) {
 178 char* indexHtml = g_strdup_printf(kIndexHtmlFormat, soup_server_get_port(server));
 179 soup_message_headers_replace(message->response_headers, "Set-Cookie", "foo=bar");
 180 soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, indexHtml, strlen(indexHtml));
 181 } else if (g_str_equal(path, "/image.png"))
 182 soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux");
 183 else
 184 g_assert_not_reached();
 185 soup_message_body_complete(message->response_body);
 186}
 187
 188void beforeAll()
 189{
 190 kServer = new WebKitTestServer();
 191 kServer->run(serverCallback);
 192
 193 CookieManagerTest::add("WebKitCookieManager", "accept-policy", testCookieManagerAcceptPolicy);
 194 CookieManagerTest::add("WebKitCookieManager", "delete-cookies", testCookieManagerDeleteCookies);
 195}
 196
 197void afterAll()
 198{
 199 delete kServer;
 200}

Source/WebKit2/UIProcess/API/gtk/webkit2.h

2525
2626#include <webkit2/WebKitBackForwardList.h>
2727#include <webkit2/WebKitBackForwardListItem.h>
 28#include <webkit2/WebKitCookieManager.h>
2829#include <webkit2/WebKitDefines.h>
2930#include <webkit2/WebKitDownload.h>
3031#include <webkit2/WebKitEditingCommands.h>