[webkit-gtk] New API to add and retrieve (full) cookies via the CookieManager

Mario Sanchez Prada mario at webkit.org
Thu Oct 5 04:31:38 PDT 2017

Hi all,

I've been talking about this with Carlos and Michael during the Web Engines
Hackfest, but I think it would be nice to send a mail here commenting on the
new API I'd like to propose. But first of all, some higher-level background:

At the moment, WebKitCookieManager does allow to do a few interesting things
such as retrieving a list of domains with cookies installed from and
deleting cookies for a given domain (or all of them), which is great to
implement the usual "Delete cookies" dialog in web browsers. Additionally,
it also allows specifying where you want to store the SQLite database on
disk with `set_persistent_storage()`, which is convenient when you don't
want to use the default location for some reason (e.g. gnome-online-accounts
uses this).

However, there's no API at the moment to *add* cookies to an existing
session, nor to retrieve "full" cookies either (you can retrieve a list of
domains with cookies, but not the cookies themselves), which makes it
complicated to implement a better mechanism to improve the integration of
components such as gnome-online-accounts with the rest of the desktop. For
instance, in Endless we'd like to be able to reuse the cookie stored by
gnome-online-accounts so that you don't have to login again in your
favourite online service from the browser (or from any app) if you already
did it in g-o-a.

Thus, being able add and retrieve cookies would be very useful, so here
comes a proposal for a new API:

webkit_cookie_manager_add_cookie (WebKitCookieManager *manager,
                                  const gchar *url,
                                  SoupCookie *cookie,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data);

 * @url: The URL of the originating request. Will also be used
         internally to set the cookie's domain in case that's
         not specified along with the #SoupCookie parameter

 * @cookie: The cookie to be inserted. Since libsoup expects
            #SoupCookie to have a domain specified, you should
            always try to set it even if it's the same than @url.

webkit_cookie_manager_add_cookie_finish (WebKitCookieManager *manager,
                                         GAsyncResult *result,
                                         GError **error);

 * Returns %TRUE if the cookie was added, otherwise it returns %FALSE
   with @error set accordingly.

webkit_cookie_manager_get_cookies (WebKitCookieManager *manager,
                                   const gchar *domain,
                                   GCancellable *cancellable,
                                   GAsyncReadyCallback callback,
                                   gpointer user_data);

 * @domain: The URL of the domain you want to get a list of all
            its cookies for.

webkit_cookie_manager_get_cookies_finish (WebKitCookieManager *manager,
                                          GAsyncResult *result,
                                          GError **error);

 * Returns a #GList of #SoupCookie with the list of cookies for the
   domain requested, otherwise it returns %NULL with @error set accordingly.

Any thoughts?


PS: Filed a new bug for this: https://bugs.webkit.org/show_bug.cgi?id=177932

More information about the webkit-gtk mailing list