aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorVincent Untz <vuntz@gnome.org>2009-12-19 03:32:51 +0800
committerXan Lopez <xan@gnome.org>2009-12-19 03:40:06 +0800
commite896b194fbff39b480c571483c7d549865f38960 (patch)
treece631db5e6d7cb3fb2e57d5448fd7193ad9f095e /embed
parentdcdebec53b1da88a6b3477d13437af2c53ac73b4 (diff)
downloadgsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.tar
gsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.tar.gz
gsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.tar.bz2
gsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.tar.lz
gsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.tar.xz
gsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.tar.zst
gsoc2013-epiphany-e896b194fbff39b480c571483c7d549865f38960.zip
Add custom user-agent support
We default to the WebKitGTK+ user agent with Epiphany and the version appended to it. This can be overriden/modified in two ways: - The gconf key /apps/epiphany/general/user_agent has the maximum priority, and if it's set it will be always used. - If the gconf key is not set, vendors can still customize the UA by placing a branding.conf file in the share data directory. One example would be: [User Agent] Vendor=SUSE VendorSub=11.2 VendorComment=2.29.94-1 And the result would be: Mozilla/5.0 (X11; U; Linux i686; fr-fr) AppleWebKit/531.2+ (KHTML, like Gecko) Safari/531.2+ SUSE/11.2 (2.29.94-1) Epiphany/2.29.94 Bug #580903 Signed-off-by: Xan Lopez <xan@gnome.org>
Diffstat (limited to 'embed')
-rw-r--r--embed/ephy-embed-prefs.c88
-rw-r--r--embed/ephy-embed-prefs.h1
2 files changed, 88 insertions, 1 deletions
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index cb64b3012..a7cf60eaa 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -134,6 +134,89 @@ webkit_pref_callback_user_stylesheet (GConfClient *client,
g_free (uri);
}
+static char *
+webkit_pref_get_internal_user_agent (void)
+{
+ char *user_agent;
+ char *webkit_user_agent;
+ char *vendor_user_agent;
+ 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",
+ G_KEY_FILE_NONE, NULL)) {
+ char *vendor;
+ char *vendor_sub;
+ char *vendor_comment;
+
+ vendor = g_key_file_get_string (branding_keyfile,
+ "User Agent", "Vendor", NULL);
+ vendor_sub = g_key_file_get_string (branding_keyfile,
+ "User Agent", "VendorSub", NULL);
+ vendor_comment = g_key_file_get_string (branding_keyfile,
+ "User Agent", "VendorComment", NULL);
+
+ if (vendor) {
+ vendor_user_agent = g_strconcat (vendor,
+ vendor_sub ? "/" : "",
+ vendor_sub ? vendor_sub : "",
+ vendor_comment ? " (" : "",
+ vendor_comment ? vendor_comment : "",
+ vendor_comment ? ")" : "",
+ NULL);
+ }
+
+ g_free (vendor);
+ g_free (vendor_sub);
+ g_free (vendor_comment);
+ }
+
+ g_key_file_free (branding_keyfile);
+
+ g_object_get (settings, "user-agent", &webkit_user_agent, NULL);
+
+ user_agent = g_strconcat (webkit_user_agent, " ",
+ vendor_user_agent ? vendor_user_agent : "",
+ vendor_user_agent ? " " : "",
+ "Epiphany/"VERSION,
+ NULL);
+
+ g_free (vendor_user_agent);
+ g_free (webkit_user_agent);
+
+ return user_agent;
+}
+
+static void
+webkit_pref_callback_user_agent (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer data)
+{
+ GConfValue *gcvalue;
+ const char *value = NULL;
+ static char *internal_user_agent = NULL;
+ char *webkit_pref = data;
+
+ gcvalue = gconf_entry_get_value (entry);
+
+ /* happens on initial notify if the key doesn't exist */
+ if (gcvalue != NULL &&
+ gcvalue->type == GCONF_VALUE_STRING) {
+ value = gconf_value_get_string (gcvalue);
+ }
+
+ if (value == NULL || value[0] == '\0') {
+ if (internal_user_agent == NULL)
+ internal_user_agent = webkit_pref_get_internal_user_agent ();
+
+ g_object_set (settings, webkit_pref, internal_user_agent, NULL);
+ } else
+ g_object_set (settings, webkit_pref, value, NULL);
+}
+
static void
webkit_pref_callback_font_size (GConfClient *client,
guint cnxn_id,
@@ -286,7 +369,10 @@ static const PrefData webkit_pref_entries[] =
webkit_pref_callback_boolean },
{ CONF_RENDERING_LANGUAGE,
"accept-language",
- webkit_pref_callback_accept_languages }
+ webkit_pref_callback_accept_languages },
+ { CONF_USER_AGENT,
+ "user-agent",
+ webkit_pref_callback_user_agent }
};
static void
diff --git a/embed/ephy-embed-prefs.h b/embed/ephy-embed-prefs.h
index ada4ac860..4865aa0ed 100644
--- a/embed/ephy-embed-prefs.h
+++ b/embed/ephy-embed-prefs.h
@@ -41,6 +41,7 @@
#define CONF_DISPLAY_SMOOTHSCROLL "/apps/epiphany/web/smooth_scroll"
#define CONF_WEB_INSPECTOR_ENABLED "/apps/epiphany/web/inspector_enabled"
#define CONF_CARET_BROWSING_ENABLED "/apps/epiphany/web/browse_with_caret"
+#define CONF_USER_AGENT "/apps/epiphany/general/user_agent"
/* These are defined gnome wide now */
#define CONF_NETWORK_PROXY_MODE "/system/proxy/mode"