Implement basic site data policy and unit tests
See: https://bugs.launchpad.net/midori/+bug/836729
This commit is contained in:
parent
307c79274d
commit
4c142e7688
3 changed files with 109 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "midori-websettings.h"
|
||||
|
||||
#include "sokoke.h"
|
||||
#include <midori/midori-core.h> /* Vala API */
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
@ -85,6 +86,7 @@ struct _MidoriWebSettings
|
|||
|
||||
gint clear_private_data;
|
||||
gchar* clear_data;
|
||||
gchar* site_data_rules;
|
||||
#if !WEBKIT_CHECK_VERSION (1, 3, 13)
|
||||
gboolean enable_dns_prefetching;
|
||||
#endif
|
||||
|
@ -174,6 +176,7 @@ enum
|
|||
|
||||
PROP_CLEAR_PRIVATE_DATA,
|
||||
PROP_CLEAR_DATA,
|
||||
PROP_SITE_DATA_RULES,
|
||||
PROP_ENABLE_DNS_PREFETCHING,
|
||||
PROP_STRIP_REFERER,
|
||||
PROP_ENFORCE_FONT_FAMILY,
|
||||
|
@ -1027,6 +1030,22 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
|
|||
_("The data selected for deletion"),
|
||||
NULL,
|
||||
flags));
|
||||
/**
|
||||
* MidoriWebSettings:site-data-rules:
|
||||
*
|
||||
* Rules for accepting, denying and preserving cookies and other data.
|
||||
* See midori_web_settings_get_site_data_policy() for details.
|
||||
*
|
||||
* Since: 0.4.4
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SITE_DATA_RULES,
|
||||
g_param_spec_string (
|
||||
"site-data-rules",
|
||||
"Rules for accepting, denying and preserving cookies and other data",
|
||||
"Cookies, HTML5 databases, local storage and application cache blocking",
|
||||
NULL,
|
||||
flags));
|
||||
#if !WEBKIT_CHECK_VERSION (1, 3, 13)
|
||||
/**
|
||||
* MidoriWebSettings:enable-dns-prefetching:
|
||||
|
@ -1206,6 +1225,45 @@ midori_web_settings_has_plugin_support (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* midori_web_settings_get_site_data_policy:
|
||||
*
|
||||
* Tests if @uri may store site data.
|
||||
*
|
||||
* Returns: a #MidoriSiteDataPolicy
|
||||
*
|
||||
* Since: 0.4.4
|
||||
**/
|
||||
MidoriSiteDataPolicy
|
||||
midori_web_settings_get_site_data_policy (MidoriWebSettings* settings,
|
||||
const gchar* uri)
|
||||
{
|
||||
/*
|
||||
* Values prefixed with "-" are always blocked
|
||||
* Values prefixed with "+" are always accepted
|
||||
* Values prefixed with "!" are not cleared in Clear Private Data
|
||||
* FIXME: "*" is a wildcard
|
||||
* FIXME: indicate type of storage the rule applies to
|
||||
* FIXME: support matching of the whole URI
|
||||
**/
|
||||
MidoriSiteDataPolicy policy = MIDORI_SITE_DATA_UNDETERMINED;
|
||||
gchar* hostname = midori_uri_parse_hostname (uri, NULL);
|
||||
const gchar* match = strstr (settings->site_data_rules, hostname ? hostname : uri);
|
||||
if (match != NULL && match != settings->site_data_rules)
|
||||
{
|
||||
const gchar* prefix = match - 1;
|
||||
if (*prefix == '-')
|
||||
policy = MIDORI_SITE_DATA_BLOCK;
|
||||
else if (*prefix == '+')
|
||||
policy = MIDORI_SITE_DATA_ACCEPT;
|
||||
else if (*prefix == '!')
|
||||
policy = MIDORI_SITE_DATA_PRESERVE;
|
||||
else
|
||||
g_warning ("%s: Matched with no prefix '%s'", G_STRFUNC, match);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
#if (!HAVE_OSX && defined (G_OS_UNIX)) || defined (G_OS_WIN32)
|
||||
static gchar*
|
||||
get_sys_name (gchar** architecture)
|
||||
|
@ -1570,6 +1628,9 @@ midori_web_settings_set_property (GObject* object,
|
|||
case PROP_CLEAR_DATA:
|
||||
katze_assign (web_settings->clear_data, g_value_dup_string (value));
|
||||
break;
|
||||
case PROP_SITE_DATA_RULES:
|
||||
katze_assign (web_settings->site_data_rules, g_value_dup_string (value));
|
||||
break;
|
||||
#if !WEBKIT_CHECK_VERSION (1, 3, 13)
|
||||
case PROP_ENABLE_DNS_PREFETCHING:
|
||||
web_settings->enable_dns_prefetching = g_value_get_boolean (value);
|
||||
|
@ -1875,6 +1936,9 @@ midori_web_settings_get_property (GObject* object,
|
|||
case PROP_CLEAR_DATA:
|
||||
g_value_set_string (value, web_settings->clear_data);
|
||||
break;
|
||||
case PROP_SITE_DATA_RULES:
|
||||
g_value_set_string (value, web_settings->site_data_rules);
|
||||
break;
|
||||
#if !WEBKIT_CHECK_VERSION (1, 3, 13)
|
||||
case PROP_ENABLE_DNS_PREFETCHING:
|
||||
g_value_set_boolean (value, web_settings->enable_dns_prefetching);
|
||||
|
|
|
@ -176,6 +176,18 @@ midori_web_settings_get_system_name (gchar** architecture,
|
|||
gboolean
|
||||
midori_web_settings_has_plugin_support (void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MIDORI_SITE_DATA_UNDETERMINED,
|
||||
MIDORI_SITE_DATA_BLOCK,
|
||||
MIDORI_SITE_DATA_ACCEPT,
|
||||
MIDORI_SITE_DATA_PRESERVE,
|
||||
} MidoriSiteDataPolicy;
|
||||
|
||||
MidoriSiteDataPolicy
|
||||
midori_web_settings_get_site_data_policy (MidoriWebSettings* settings,
|
||||
const gchar* uri);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MIDORI_WEB_SETTINGS_H__ */
|
||||
|
|
|
@ -94,6 +94,38 @@ browser_tooltips (void)
|
|||
g_error ("Tooltip errors");
|
||||
}
|
||||
|
||||
static void
|
||||
browser_site_data (void)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
const gchar* url;
|
||||
MidoriSiteDataPolicy policy;
|
||||
} PolicyItem;
|
||||
|
||||
static const PolicyItem items[] = {
|
||||
{ "google.com", MIDORI_SITE_DATA_BLOCK },
|
||||
{ "facebook.com", MIDORI_SITE_DATA_BLOCK },
|
||||
{ "bugzilla.gnome.org", MIDORI_SITE_DATA_PRESERVE },
|
||||
{ "bugs.launchpad.net", MIDORI_SITE_DATA_ACCEPT },
|
||||
};
|
||||
|
||||
const gchar* rules = "-google.com,-facebook.com,!bugzilla.gnome.org,+bugs.launchpad.net";
|
||||
MidoriWebSettings* settings = g_object_new (MIDORI_TYPE_WEB_SETTINGS,
|
||||
"site-data-rules", rules, NULL);
|
||||
|
||||
guint i;
|
||||
for (i = 0; i < G_N_ELEMENTS (items); i++)
|
||||
{
|
||||
MidoriSiteDataPolicy policy = midori_web_settings_get_site_data_policy (
|
||||
settings, items[i].url);
|
||||
if (policy != items[i].policy)
|
||||
g_error ("Match '%s' yields %d but %d expected",
|
||||
items[i].url, policy, items[i].policy);
|
||||
}
|
||||
g_object_unref (settings);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char** argv)
|
||||
|
@ -106,6 +138,7 @@ main (int argc,
|
|||
|
||||
g_test_add_func ("/browser/create", browser_create);
|
||||
g_test_add_func ("/browser/tooltips", browser_tooltips);
|
||||
g_test_add_func ("/browser/site_data", browser_site_data);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue