diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2012-09-24 18:32:22 +0800 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2012-10-08 16:36:49 +0800 |
commit | 7512839e6add584e184805d3781f9976831a2188 (patch) | |
tree | 6da2c77e35e3bf7e5a7970857ec4ebfa3c77642f | |
parent | 96e1a8a78c9a943a912e315b2900b49563b06947 (diff) | |
download | gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.tar gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.tar.gz gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.tar.bz2 gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.tar.lz gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.tar.xz gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.tar.zst gsoc2013-epiphany-7512839e6add584e184805d3781f9976831a2188.zip |
ephy-embed-prefs: Port user agent to WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=684443
-rw-r--r-- | embed/ephy-embed-prefs.c | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c index 2c9346310..10f508487 100644 --- a/embed/ephy-embed-prefs.c +++ b/embed/ephy-embed-prefs.c @@ -82,14 +82,11 @@ webkit_pref_callback_user_stylesheet (GSettings *settings, } static char * -webkit_pref_get_internal_user_agent (void) +webkit_pref_get_vendor_user_agent (void) { - char *user_agent; - char *webkit_user_agent; - char *vendor_user_agent; + char *vendor_user_agent = NULL; GKeyFile *branding_keyfile; - vendor_user_agent = NULL; branding_keyfile = g_key_file_new (); if (g_key_file_load_from_file (branding_keyfile, SHARE_DIR"/branding.conf", @@ -122,10 +119,44 @@ webkit_pref_get_internal_user_agent (void) g_key_file_free (branding_keyfile); + return vendor_user_agent; +} + #ifdef HAVE_WEBKIT2 - /* TODO: User agent */ - return g_strdup (""); +static const char * +webkit_pref_get_internal_user_agent (void) +{ + static char *user_agent = NULL; + static gboolean initialized = FALSE; + char *vendor_user_agent; + const char *webkit_user_agent; + + if (initialized) + return user_agent; + + initialized = TRUE; + + vendor_user_agent = webkit_pref_get_vendor_user_agent (); + if (!vendor_user_agent) + return NULL; + + webkit_user_agent = webkit_settings_get_user_agent (webkit_settings); + user_agent = g_strdup_printf ("%s %s Epiphany/%s", webkit_user_agent, + vendor_user_agent, VERSION); + g_free (vendor_user_agent); + + return user_agent; +} #else +static char * +webkit_pref_get_internal_user_agent (void) +{ + char *user_agent; + char *webkit_user_agent; + char *vendor_user_agent; + + vendor_user_agent = webkit_pref_get_vendor_user_agent (); + g_object_get (webkit_settings, "user-agent", &webkit_user_agent, NULL); user_agent = g_strconcat (webkit_user_agent, " ", @@ -138,8 +169,8 @@ webkit_pref_get_internal_user_agent (void) g_free (webkit_user_agent); return user_agent; -#endif } +#endif static void webkit_pref_callback_user_agent (GSettings *settings, @@ -147,7 +178,23 @@ webkit_pref_callback_user_agent (GSettings *settings, gpointer data) { #ifdef HAVE_WEBKIT2 - /* TODO: User agent */ + char *value; + const char *internal_user_agent; + + value = g_settings_get_string (settings, key); + if (value != NULL && value[0] != '\0') { + webkit_settings_set_user_agent (webkit_settings, value); + g_free (value); + return; + } + g_free (value); + + internal_user_agent = webkit_pref_get_internal_user_agent (); + if (internal_user_agent) + webkit_settings_set_user_agent (webkit_settings, internal_user_agent); + else + webkit_settings_set_user_agent_with_application_details (webkit_settings, + "Epiphany", VERSION); #else char *value = NULL; static char *internal_user_agent = NULL; |