From: Daniel Carl Date: Sun, 3 Nov 2013 18:14:57 +0000 (+0100) Subject: Allow to set cookie accept policy. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=e22151dc1ae217e2e4a89cd8b0611050d08fea7b;p=vimb.git Allow to set cookie accept policy. New setting ':set cookie-accept={always,never,origin}'. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index a753dd2..ff815f6 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -653,6 +653,10 @@ Foreground color for the none selected completion items. .B completion-font (string) Font used for the completion items. .TP +.B cookie-accept (string) +Cookie accept policy {`always', `never', `origin' (accept all non-third-party +cookies)}. +.TP .B cookie-timeout (int) Cookie timeout in seconds. .TP diff --git a/src/setting.c b/src/setting.c index f2082b3..a1e9ded 100644 --- a/src/setting.c +++ b/src/setting.c @@ -29,7 +29,10 @@ extern VbCore vb; static Arg *char_to_arg(const char *str, const Type type); static void print_value(const Setting *s, void *value); static gboolean webkit(const Setting *s, const SettingType type); +#ifdef FEATURE_COOKIE +static gboolean cookie_accept(const Setting *s, const SettingType type); static gboolean cookie_timeout(const Setting *s, const SettingType type); +#endif static gboolean scrollstep(const Setting *s, const SettingType type); static gboolean status_color_bg(const Setting *s, const SettingType type); static gboolean status_color_fg(const Setting *s, const SettingType type); @@ -80,7 +83,10 @@ static Setting default_settings[] = { {NULL, "stylesheet", TYPE_BOOLEAN, user_style, {0}}, {NULL, "proxy", TYPE_BOOLEAN, proxy, {0}}, +#ifdef FEATURE_COOKIE {NULL, "cookie-timeout", TYPE_INTEGER, cookie_timeout, {0}}, + {NULL, "cookie-accept", TYPE_CHAR, cookie_accept, {0}}, +#endif {NULL, "strict-ssl", TYPE_BOOLEAN, strict_ssl, {0}}, {NULL, "strict-focus", TYPE_BOOLEAN, strict_focus, {0}}, @@ -369,6 +375,43 @@ static gboolean webkit(const Setting *s, const SettingType type) return true; } + +#ifdef FEATURE_COOKIE +static gboolean cookie_accept(const Setting *s, const SettingType type) +{ + int i, policy; + SoupCookieJar *jar; + static struct { + SoupCookieJarAcceptPolicy policy; + char* name; + } map[] = { + {SOUP_COOKIE_JAR_ACCEPT_ALWAYS, "always"}, + {SOUP_COOKIE_JAR_ACCEPT_NEVER, "never"}, + {SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY, "origin"}, + }; + + jar = (SoupCookieJar*)soup_session_get_feature(vb.session, SOUP_TYPE_COOKIE_JAR); + + if (type == SETTING_GET) { + g_object_get(jar, SOUP_COOKIE_JAR_ACCEPT_POLICY, &policy, NULL); + for (i = 0; i < LENGTH(map); i++) { + if (policy == map[i].policy) { + print_value(s, map[i].name); + return true; + } + } + } else { + for (i = 0; i < LENGTH(map); i++) { + if (!strcmp(map[i].name, s->arg.s)) { + g_object_set(jar, SOUP_COOKIE_JAR_ACCEPT_POLICY, map[i].policy, NULL); + return true; + } + } + } + + return false; +} + static gboolean cookie_timeout(const Setting *s, const SettingType type) { if (type == SETTING_GET) { @@ -379,6 +422,7 @@ static gboolean cookie_timeout(const Setting *s, const SettingType type) return true; } +#endif static gboolean scrollstep(const Setting *s, const SettingType type) {