From 35ed21b8d041c63d07fad25aad1879543ce7a484 Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Fri, 6 Aug 2010 01:53:37 +0800 Subject: [PATCH] Add simple cookies support --- globalconf.h | 3 +++ luakit.c | 9 +++++++++ widgets/webview.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/globalconf.h b/globalconf.h index ed81063..9806186 100644 --- a/globalconf.h +++ b/globalconf.h @@ -23,12 +23,15 @@ #define LUAKIT_LUA_LIB_PATH "/usr/share/luakit/lib" #define LUAKIT_OBJECT_REGISTRY_KEY "luakit.object.registry" +#define LUAKIT_CONFIG_DIR ".config/luakit/" #include #include #include "common/signal.h" typedef struct { + /* Path to the config directory */ + gchar *base_directory; /* Path to the current config file */ gchar *confpath; /* Lua VM state */ diff --git a/luakit.c b/luakit.c index d4887c9..fb6986a 100644 --- a/luakit.c +++ b/luakit.c @@ -124,6 +124,14 @@ init_lua(gchar **uris) xdgWipeHandle(&xdg); } +void +init_directories() +{ + /* create luakit directory */ + globalconf.base_directory = g_build_filename(g_get_home_dir(), LUAKIT_CONFIG_DIR, NULL); + g_mkdir_with_parents(globalconf.base_directory, 0771); +} + int main(int argc, char *argv[]) { gchar **uris = NULL; @@ -138,6 +146,7 @@ main(int argc, char *argv[]) { /* parse command line opts and get uris to load */ uris = parseopts(argc, argv); + init_directories(); init_lua(uris); gtk_main(); return EXIT_SUCCESS; diff --git a/widgets/webview.c b/widgets/webview.c index 3ae06f9..35f16a4 100644 --- a/widgets/webview.c +++ b/widgets/webview.c @@ -23,8 +23,14 @@ #include "widgets/common.h" #include #include +#include #include "math.h" +static struct { + SoupSession *session; + SoupCookieJar *cookiejar; +} Soup = { NULL, NULL }; + typedef enum { BOOL, CHAR, INT, FLOAT, DOUBLE } property_value_type; typedef union { @@ -596,6 +602,15 @@ widget_webview(widget_t *w) w->newindex = luaH_webview_newindex; w->destructor = webview_destructor; + /* init soup session & cookies handling */ + if (!Soup.session) { + Soup.session = webkit_get_default_session(); + gchar *cookie_file = g_build_filename(globalconf.base_directory, "cookies.txt", NULL); + Soup.cookiejar = soup_cookie_jar_text_new(cookie_file, FALSE); + soup_session_add_feature(Soup.session, (SoupSessionFeature*) Soup.cookiejar); + g_free(cookie_file); + } + GtkWidget *view = webkit_web_view_new(); w->widget = gtk_scrolled_window_new(NULL, NULL); g_object_set_data(G_OBJECT(w->widget), "widget", w); -- 2.11.4.GIT