From 3e60f4424b97cae7c460759bf10591e46b2342de Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 9 Oct 2011 12:20:13 +0200 Subject: [PATCH] Introduce Automatic user agent and allow quirks The new Automatic user agent is meant to pick the string that websites most likely check for. Right now this is Safari. Quirks built-in to WebKit are also used. The separate Midori identification has no quirks. Fixes: https://bugs.launchpad.net/midori/+bug/865503 --- katze/katze-utils.c | 5 ++++- midori/midori-websettings.c | 19 ++++++++++++++----- midori/midori-websettings.h | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/katze/katze-utils.c b/katze/katze-utils.c index dccc09e6..d2e2aaf2 100644 --- a/katze/katze-utils.c +++ b/katze/katze-utils.c @@ -496,6 +496,7 @@ g_icon_to_string (GIcon *icon) * "custom-PROPERTY": the last value of an enumeration will be the "custom" * value, where the user may enter text freely, which then updates * the property PROPERTY instead. This applies only to enumerations. + * Since 0.4.2 mnemonics are automatically stripped. * Since 0.2.9 the following hints are also supported: * "languages": the widget will be particularly suitable for choosing * multiple language codes, ie. "de,en_GB". @@ -880,12 +881,14 @@ katze_property_proxy (gpointer object, #endif for (i = 0; i < enum_class->n_values; i++) { - const gchar* label = gettext (enum_class->values[i].value_nick); + const gchar* raw_label = gettext (enum_class->values[i].value_nick); + gchar* label = katze_strip_mnemonics (raw_label); #ifdef HAVE_HILDON_2_2 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), label); #else gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), label); #endif + g_free (label); } #ifdef HAVE_HILDON_2_2 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, value); diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index 670c42b1..ba069163 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -290,7 +290,8 @@ midori_identity_get_type (void) if (!type) { static const GEnumValue values[] = { - { MIDORI_IDENT_MIDORI, "MIDORI_IDENT_MIDORI", N_("Midori") }, + { MIDORI_IDENT_MIDORI, "MIDORI_IDENT_MIDORI", N_("_Automatic") }, + { MIDORI_IDENT_GENUINE, "MIDORI_IDENT_GENUINE", N_("Midori") }, { MIDORI_IDENT_SAFARI, "MIDORI_IDENT_SAFARI", N_("Safari") }, { MIDORI_IDENT_IPHONE, "MIDORI_IDENT_IPHONE", N_("iPhone") }, { MIDORI_IDENT_FIREFOX, "MIDORI_IDENT_FIREFOX", N_("Firefox") }, @@ -1096,7 +1097,8 @@ get_sys_name (void) #endif static gchar* -generate_ident_string (MidoriIdentity identify_as) +generate_ident_string (MidoriWebSettings* web_settings, + MidoriIdentity identify_as) { const gchar* platform = #if HAVE_HILDON @@ -1133,12 +1135,19 @@ generate_ident_string (MidoriIdentity identify_as) const int webcore_major = WEBKIT_USER_AGENT_MAJOR_VERSION; const int webcore_minor = WEBKIT_USER_AGENT_MINOR_VERSION; + #if WEBKIT_CHECK_VERSION (1, 1, 18) + g_object_set (web_settings, "enable-site-specific-quirks", + identify_as != MIDORI_IDENT_GENUINE, NULL); + #endif + switch (identify_as) { - case MIDORI_IDENT_MIDORI: + case MIDORI_IDENT_GENUINE: return g_strdup_printf ("Mozilla/5.0 (%s %s) AppleWebKit/%d.%d+ %s", platform, os, webcore_major, webcore_minor, appname); + case MIDORI_IDENT_MIDORI: case MIDORI_IDENT_SAFARI: + g_object_set (web_settings, "enable-site-specific-quirks", TRUE, NULL); return g_strdup_printf ("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; %s) " "AppleWebKit/%d+ (KHTML, like Gecko) Version/5.0 Safari/%d.%d+ %s", lang, webcore_major, webcore_major, webcore_minor, appname); @@ -1365,7 +1374,7 @@ midori_web_settings_set_property (GObject* object, 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); + gchar* string = generate_ident_string (web_settings, web_settings->identify_as); katze_assign (web_settings->ident_string, string); g_object_set (web_settings, "user-agent", string, NULL); } @@ -1625,7 +1634,7 @@ midori_web_settings_get_property (GObject* object, case PROP_USER_AGENT: if (!g_strcmp0 (web_settings->ident_string, "")) { - gchar* string = generate_ident_string (web_settings->identify_as); + gchar* string = generate_ident_string (web_settings, web_settings->identify_as); katze_assign (web_settings->ident_string, string); } g_value_set_string (value, web_settings->ident_string); diff --git a/midori/midori-websettings.h b/midori/midori-websettings.h index 18094257..0b16ed2c 100644 --- a/midori/midori-websettings.h +++ b/midori/midori-websettings.h @@ -137,7 +137,8 @@ midori_proxy_get_type (void) G_GNUC_CONST; typedef enum { - MIDORI_IDENT_MIDORI, + MIDORI_IDENT_MIDORI /* Automatic */, + MIDORI_IDENT_GENUINE /* Midori */, MIDORI_IDENT_SAFARI, MIDORI_IDENT_IPHONE, MIDORI_IDENT_FIREFOX, -- 2.39.5