Provide identification string and proxy server preferences
This works with libSoup stable, if WebKit uses libSoup.
This commit is contained in:
parent
e1075f1aae
commit
219c6bdf4c
4 changed files with 228 additions and 17 deletions
|
@ -1274,7 +1274,9 @@ cookie_jar_changed_cb (SoupCookieJar* jar,
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_LIBSOUP
|
||||
/* The following code hooks up to any created cookie jar in order to
|
||||
load and save cookies. This is *not* a generally advisable technique
|
||||
but merely a preliminary workaround until WebKit exposes its
|
||||
|
@ -1283,15 +1285,18 @@ static GObjectConstructed old_jar_constructed_cb;
|
|||
static void
|
||||
cookie_jar_constructed_cb (GObject* object)
|
||||
{
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
gchar* config_path;
|
||||
gchar* config_file;
|
||||
SoupCookieJar* jar;
|
||||
#endif
|
||||
|
||||
if (old_jar_constructed_cb)
|
||||
old_jar_constructed_cb (object);
|
||||
g_type_set_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar"), (void*)1);
|
||||
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
config_path = g_build_filename (g_get_user_config_dir (),
|
||||
PACKAGE_NAME, NULL);
|
||||
g_mkdir_with_parents (config_path, 0700);
|
||||
|
@ -1301,6 +1306,7 @@ cookie_jar_constructed_cb (GObject* object)
|
|||
g_signal_connect_data (jar, "changed",
|
||||
G_CALLBACK (cookie_jar_changed_cb), config_file,
|
||||
(GClosureNotify)g_free, 0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1433,12 +1439,22 @@ static void
|
|||
soup_session_constructed_cb (GObject* object)
|
||||
{
|
||||
MidoriApp* app;
|
||||
MidoriWebSettings* settings;
|
||||
SoupSession* session;
|
||||
SoupURI* proxy_uri;
|
||||
|
||||
if (old_session_constructed_cb)
|
||||
old_session_constructed_cb (object);
|
||||
app = g_type_get_qdata (SOUP_TYPE_SESSION,
|
||||
g_quark_from_static_string ("midori-app"));
|
||||
settings = katze_object_get_object (app, "settings");
|
||||
proxy_uri = soup_uri_new (katze_object_get_string (settings, "http-proxy"));
|
||||
g_object_set (object,
|
||||
"user-agent", katze_object_get_string (settings, "ident-string"),
|
||||
"proxy-uri", proxy_uri,
|
||||
NULL);
|
||||
if (proxy_uri)
|
||||
soup_uri_free (proxy_uri);
|
||||
|
||||
session = SOUP_SESSION (object);
|
||||
g_signal_connect (session, "authenticate",
|
||||
|
@ -1566,7 +1582,7 @@ main (int argc,
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
#if HAVE_LIBSOUP
|
||||
/* This is a nasty trick that allows us to manipulate cookies
|
||||
even without having a pointer to the jar. */
|
||||
soup_cookie_jar_get_type ();
|
||||
|
@ -1578,8 +1594,6 @@ main (int argc,
|
|||
old_jar_constructed_cb = G_OBJECT_CLASS (jar_class)->constructed;
|
||||
G_OBJECT_CLASS (jar_class)->constructed = cookie_jar_constructed_cb;
|
||||
}
|
||||
#endif
|
||||
#if HAVE_LIBSOUP
|
||||
/* This is a nasty trick that allows us to manipulate preferences
|
||||
even without having a pointer to the session. */
|
||||
soup_session_get_type ();
|
||||
|
|
|
@ -220,6 +220,16 @@ proxy_download_manager_icon_cb (GtkWidget* entry,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
midori_preferences_notify_identify_as_cb (MidoriWebSettings* settings,
|
||||
GParamSpec* pspec,
|
||||
GtkWidget* entry)
|
||||
{
|
||||
MidoriIdentity identify_as = katze_object_get_enum (settings, "identify-as");
|
||||
|
||||
gtk_widget_set_sensitive (entry, identify_as == MIDORI_IDENT_CUSTOM);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OSX
|
||||
static void
|
||||
midori_preferences_help_clicked_cb (GtkWidget* button,
|
||||
|
@ -480,35 +490,52 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
|
|||
WIDGET_ADD (button, 1, 2, 5, 6);
|
||||
|
||||
/* Page "Network" */
|
||||
#if 0
|
||||
#if HAVE_LIBSOUP
|
||||
/* If a cookie jar was created, WebKit is using Soup */
|
||||
if (g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar")))
|
||||
{
|
||||
PAGE_NEW (GTK_STOCK_NETWORK, _("Network"));
|
||||
FRAME_NEW (_("Network"));
|
||||
TABLE_NEW (2, 2);
|
||||
TABLE_NEW (4, 2);
|
||||
label = katze_property_label (settings, "http-proxy");
|
||||
INDENTED_ADD (label, 0, 1, 0, 1);
|
||||
button = katze_property_proxy (settings, "http-proxy", NULL);
|
||||
FILLED_ADD (button, 1, 2, 0, 1);
|
||||
label = katze_property_label (settings, "cache-size");
|
||||
label = katze_property_label (settings, "identify-as");
|
||||
INDENTED_ADD (label, 0, 1, 1, 2);
|
||||
button = katze_property_proxy (settings, "identify-as", NULL);
|
||||
FILLED_ADD (button, 1, 2, 1, 2);
|
||||
label = katze_property_label (settings, "ident-string");
|
||||
INDENTED_ADD (label, 0, 1, 2, 3);
|
||||
entry = katze_property_proxy (settings, "ident-string", NULL);
|
||||
g_signal_connect (settings, "notify::identify-as",
|
||||
G_CALLBACK (midori_preferences_notify_identify_as_cb), entry);
|
||||
midori_preferences_notify_identify_as_cb (settings, NULL, entry);
|
||||
FILLED_ADD (entry, 1, 2, 2, 3);
|
||||
label = katze_property_label (settings, "cache-size");
|
||||
INDENTED_ADD (label, 0, 1, 3, 4);
|
||||
hbox = gtk_hbox_new (FALSE, 4);
|
||||
entry = katze_property_proxy (settings, "cache-size", NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("MB")),
|
||||
FALSE, FALSE, 0);
|
||||
FILLED_ADD (hbox, 1, 2, 1, 2);
|
||||
FILLED_ADD (hbox, 1, 2, 3, 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Page "Privacy" */
|
||||
PAGE_NEW (GTK_STOCK_INDEX, _("Privacy"));
|
||||
#if HAVE_LIBSOUP_2_25_2
|
||||
/* If a cookie jar was created, WebKit is using Soup */
|
||||
if (g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar")))
|
||||
{
|
||||
FRAME_NEW (_("Web Cookies"));
|
||||
TABLE_NEW (3, 2);
|
||||
label = katze_property_label (settings, "accept-cookies");
|
||||
INDENTED_ADD (label, 0, 1, 0, 1);
|
||||
button = katze_property_proxy (settings, "accept-cookies", NULL);
|
||||
/* If a cookie jar was created, WebKit is using Soup */
|
||||
gtk_widget_set_sensitive (button, g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar")) != NULL);
|
||||
FILLED_ADD (button, 1, 2, 0, 1);
|
||||
button = katze_property_proxy (settings, "original-cookies-only", "blurb");
|
||||
SPANNED_ADD (button, 0, 2, 1, 2);
|
||||
|
@ -516,13 +543,11 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
|
|||
INDENTED_ADD (label, 0, 1, 2, 3);
|
||||
hbox = gtk_hbox_new (FALSE, 4);
|
||||
entry = katze_property_proxy (settings, "maximum-cookie-age", NULL);
|
||||
/* If a cookie jar was created, WebKit is using Soup */
|
||||
gtk_widget_set_sensitive (entry, g_type_get_qdata (SOUP_TYPE_COOKIE_JAR,
|
||||
g_quark_from_static_string ("midori-has-jar")) != NULL);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("days")),
|
||||
FALSE, FALSE, 0);
|
||||
FILLED_ADD (hbox, 1, 2, 2, 3);
|
||||
}
|
||||
#endif
|
||||
FRAME_NEW (_("History"));
|
||||
TABLE_NEW (3, 2);
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
struct _MidoriWebSettings
|
||||
{
|
||||
WebKitWebSettings parent_instance;
|
||||
|
@ -64,9 +68,16 @@ struct _MidoriWebSettings
|
|||
gboolean remember_last_downloaded_files;
|
||||
|
||||
gchar* http_proxy;
|
||||
MidoriIdentity identify_as;
|
||||
gchar* ident_string;
|
||||
gint cache_size;
|
||||
};
|
||||
|
||||
struct _MidoriWebSettingsClass
|
||||
{
|
||||
WebKitWebSettingsClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MidoriWebSettings, midori_web_settings, WEBKIT_TYPE_WEB_SETTINGS)
|
||||
|
||||
enum
|
||||
|
@ -118,6 +129,8 @@ enum
|
|||
PROP_REMEMBER_LAST_DOWNLOADED_FILES,
|
||||
|
||||
PROP_HTTP_PROXY,
|
||||
PROP_IDENTIFY_AS,
|
||||
PROP_IDENT_STRING,
|
||||
PROP_CACHE_SIZE
|
||||
};
|
||||
|
||||
|
@ -150,7 +163,7 @@ midori_preferred_encoding_get_type (void)
|
|||
{ MIDORI_ENCODING_RUSSIAN, "MIDORI_ENCODING_RUSSIAN", N_("Russian (KOI8-R)") },
|
||||
{ MIDORI_ENCODING_UNICODE, "MIDORI_ENCODING_UNICODE", N_("Unicode (UTF-8)") },
|
||||
{ MIDORI_ENCODING_WESTERN, "MIDORI_ENCODING_WESTERN", N_("Western (ISO-8859-1)") },
|
||||
{ MIDORI_ENCODING_WESTERN, "MIDORI_ENCODING_CUSTOM", N_("Custom...") },
|
||||
{ MIDORI_ENCODING_CUSTOM, "MIDORI_ENCODING_CUSTOM", N_("Custom...") },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
type = g_enum_register_static ("MidoriPreferredEncoding", values);
|
||||
|
@ -211,6 +224,25 @@ midori_accept_cookies_get_type (void)
|
|||
return type;
|
||||
}
|
||||
|
||||
GType
|
||||
midori_identity_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
if (!type)
|
||||
{
|
||||
static const GEnumValue values[] = {
|
||||
{ MIDORI_IDENT_MIDORI, "MIDORI_IDENT_MIDORI", N_("Midori") },
|
||||
{ MIDORI_IDENT_SAFARI, "MIDORI_IDENT_SAFARI", N_("Safari") },
|
||||
{ MIDORI_IDENT_FIREFOX, "MIDORI_IDENT_FIREFOX", N_("Firefox") },
|
||||
{ MIDORI_IDENT_EXPLORER, "MIDORI_IDENT_EXPLORER", N_("Internet Explorer") },
|
||||
{ MIDORI_IDENT_CUSTOM, "MIDORI_IDENT_CUSTOM", N_("Custom...") },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
type = g_enum_register_static ("MidoriIdentity", values);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
midori_web_settings_finalize (GObject* object);
|
||||
|
||||
|
@ -538,7 +570,11 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
|
|||
_("What type of cookies to accept"),
|
||||
MIDORI_TYPE_ACCEPT_COOKIES,
|
||||
MIDORI_ACCEPT_COOKIES_ALL,
|
||||
#if HAVE_LIBSOUP
|
||||
G_PARAM_READWRITE));
|
||||
#else
|
||||
G_PARAM_READABLE));
|
||||
#endif
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ORIGINAL_COOKIES_ONLY,
|
||||
|
@ -605,7 +641,52 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
|
|||
_("HTTP Proxy"),
|
||||
_("The proxy used for HTTP connections"),
|
||||
NULL,
|
||||
#if HAVE_LIBSOUP
|
||||
G_PARAM_READWRITE));
|
||||
#else
|
||||
G_PARAM_READABLE));
|
||||
#endif
|
||||
|
||||
/**
|
||||
* MidoriWebSettings:identify-as:
|
||||
*
|
||||
* What to identify as to web pages.
|
||||
*
|
||||
* Since: 0.1.2
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_IDENTIFY_AS,
|
||||
g_param_spec_enum (
|
||||
"identify-as",
|
||||
_("Identify as"),
|
||||
_("What to identify as to web pages"),
|
||||
MIDORI_TYPE_IDENTITY,
|
||||
MIDORI_IDENT_MIDORI,
|
||||
#if HAVE_LIBSOUP
|
||||
G_PARAM_READWRITE));
|
||||
#else
|
||||
G_PARAM_READABLE));
|
||||
#endif
|
||||
|
||||
/**
|
||||
* MidoriWebSettings:ident-string:
|
||||
*
|
||||
* The browser identification string.
|
||||
*
|
||||
* Since: 0.1.2
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_IDENT_STRING,
|
||||
g_param_spec_string (
|
||||
"ident-string",
|
||||
_("Identification string"),
|
||||
_("The application identification string"),
|
||||
NULL,
|
||||
#if HAVE_LIBSOUP
|
||||
G_PARAM_READWRITE));
|
||||
#else
|
||||
G_PARAM_READABLE));
|
||||
#endif
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CACHE_SIZE,
|
||||
|
@ -659,6 +740,69 @@ midori_web_settings_finalize (GObject* object)
|
|||
G_OBJECT_CLASS (midori_web_settings_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
generate_ident_string (MidoriIdentity identify_as)
|
||||
{
|
||||
const gchar* platform =
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
"X11";
|
||||
#elif defined(GDK_WINDOWING_WIN32)
|
||||
"Windows";
|
||||
#elif defined(GDK_WINDOWING_QUARTZ)
|
||||
"Macintosh";
|
||||
#elif defined(GDK_WINDOWING_DIRECTFB)
|
||||
"DirectFB";
|
||||
#else
|
||||
"Unknown";
|
||||
#endif
|
||||
|
||||
const gchar* os =
|
||||
#if defined (HAVE_OSX)
|
||||
/* #if defined (HAVE_X86) */
|
||||
"Intel Mac OS X";
|
||||
/* #else
|
||||
"PPC Mac OS X";
|
||||
#endif */
|
||||
#elif defined (G_OS_UNIX)
|
||||
/* struct utsname name;
|
||||
if (uname (&name) != -1)
|
||||
String::format ("%s %s", name.sysname, name.machine);
|
||||
else
|
||||
"Unknown";*/
|
||||
"Linux";
|
||||
#elif defined (G_OS_WIN32)
|
||||
// FIXME: Windows NT version
|
||||
"Windows";
|
||||
#else
|
||||
"Unknown";
|
||||
#endif
|
||||
|
||||
const gchar* appname = "Midori/" PACKAGE_VERSION;
|
||||
|
||||
const gchar* lang = pango_language_to_string ( gtk_get_default_language ());
|
||||
|
||||
switch (identify_as)
|
||||
{
|
||||
case MIDORI_IDENT_MIDORI:
|
||||
return g_strdup_printf ("%s (%s; %s; U; %s) WebKit/532+",
|
||||
appname, platform, os, lang);
|
||||
case MIDORI_IDENT_SAFARI:
|
||||
return g_strdup_printf ("Mozilla/5.0 (%s; U; %s; %s) "
|
||||
"AppleWebKit/532+ (KHTML, like Gecko) Safari/419.3 %s",
|
||||
platform, os, lang, appname);
|
||||
case MIDORI_IDENT_FIREFOX:
|
||||
return g_strdup_printf ("Mozilla/5.0 (%s; U; %s; %s; rv:1.8.1) "
|
||||
"Gecko/20061010 Firefox/2.0 %s",
|
||||
platform, os, lang, appname);
|
||||
case MIDORI_IDENT_EXPLORER:
|
||||
return g_strdup_printf ("Mozilla/4.0 (compatible; "
|
||||
"MSIE 6.0; Windows NT 5.1; %s) %s",
|
||||
lang, appname);
|
||||
default:
|
||||
return g_strdup_printf ("%s", appname);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
midori_web_settings_set_property (GObject* object,
|
||||
guint prop_id,
|
||||
|
@ -807,6 +951,18 @@ midori_web_settings_set_property (GObject* object,
|
|||
case PROP_HTTP_PROXY:
|
||||
katze_assign (web_settings->http_proxy, g_value_dup_string (value));
|
||||
break;
|
||||
case PROP_IDENTIFY_AS:
|
||||
web_settings->identify_as = g_value_get_enum (value);
|
||||
if (web_settings->identify_as != MIDORI_IDENT_CUSTOM)
|
||||
{
|
||||
gchar* string = generate_ident_string (web_settings->identify_as);
|
||||
g_object_set (object, "ident-string", string, NULL);
|
||||
g_free (string);
|
||||
}
|
||||
break;
|
||||
case PROP_IDENT_STRING:
|
||||
katze_assign (web_settings->ident_string, g_value_dup_string (value));
|
||||
break;
|
||||
case PROP_CACHE_SIZE:
|
||||
web_settings->cache_size = g_value_get_int (value);
|
||||
break;
|
||||
|
@ -947,6 +1103,12 @@ midori_web_settings_get_property (GObject* object,
|
|||
case PROP_HTTP_PROXY:
|
||||
g_value_set_string (value, web_settings->http_proxy);
|
||||
break;
|
||||
case PROP_IDENTIFY_AS:
|
||||
g_value_set_enum (value, web_settings->identify_as);
|
||||
break;
|
||||
case PROP_IDENT_STRING:
|
||||
g_value_set_string (value, web_settings->ident_string);
|
||||
break;
|
||||
case PROP_CACHE_SIZE:
|
||||
g_value_set_int (value, web_settings->cache_size);
|
||||
break;
|
||||
|
|
|
@ -104,10 +104,20 @@ midori_accept_cookies_get_type (void) G_GNUC_CONST;
|
|||
#define MIDORI_TYPE_ACCEPT_COOKIES \
|
||||
(midori_accept_cookies_get_type ())
|
||||
|
||||
struct _MidoriWebSettingsClass
|
||||
typedef enum
|
||||
{
|
||||
WebKitWebSettingsClass parent_class;
|
||||
};
|
||||
MIDORI_IDENT_MIDORI,
|
||||
MIDORI_IDENT_SAFARI,
|
||||
MIDORI_IDENT_FIREFOX,
|
||||
MIDORI_IDENT_EXPLORER,
|
||||
MIDORI_IDENT_CUSTOM
|
||||
} MidoriIdentity;
|
||||
|
||||
GType
|
||||
midori_identity_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#define MIDORI_TYPE_IDENTITY \
|
||||
(midori_identity_get_type ())
|
||||
|
||||
GType
|
||||
midori_web_settings_get_type (void);
|
||||
|
|
Loading…
Reference in a new issue