[epiphany] Add the "mobile-user-agent" setting



commit 3a3d32efb169a5a371aaff74fe4ce052e7507f82
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri May 31 17:29:22 2019 +0200

    Add the "mobile-user-agent" setting
    
    This allows to use a mobile user agent.

 data/org.gnome.epiphany.gschema.xml | 5 +++++
 embed/ephy-embed-prefs.c            | 5 +++++
 lib/ephy-prefs.h                    | 2 ++
 lib/ephy-user-agent.c               | 6 +++++-
 4 files changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 758668cbc..0392949a2 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -184,6 +184,11 @@
                        <summary>User agent</summary>
                        <description>String that will be used as user agent, to identify the browser to the 
web servers.</description>
                </key>
+               <key type="b" name="mobile-user-agent">
+                       <default>false</default>
+                       <summary>Mobile user agent</summary>
+                       <description>Whether to present a mobile user agent. If the user agent is overridden, 
this will have no effect.</description>
+               </key>
                <key type="b" name="do-not-track">
                        <default>true</default>
                        <summary>Do Not Track</summary>
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index 1a0fb5d72..dcae90dd1 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -471,6 +471,11 @@ static const PrefData webkit_pref_entries[] =
     EPHY_PREFS_WEB_USER_AGENT,
     "user-agent",
     webkit_pref_callback_user_agent },
+  { EPHY_PREFS_WEB_SCHEMA,
+    EPHY_PREFS_WEB_MOBILE_USER_AGENT,
+    "mobile-user-agent",
+    /* No need for a specific callback, we just want to update the user agent. */
+    webkit_pref_callback_user_agent },
   { EPHY_PREFS_WEB_SCHEMA,
     EPHY_PREFS_WEB_COOKIES_POLICY,
     "accept-policy",
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 34cadfcf1..b23098051 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -111,6 +111,7 @@ static const char * const ephy_prefs_state_schema[] = {
 #define EPHY_PREFS_WEB_ENABLE_WEBAUDIO              "enable-webaudio"
 #define EPHY_PREFS_WEB_ENABLE_SMOOTH_SCROLLING      "enable-smooth-scrolling"
 #define EPHY_PREFS_WEB_USER_AGENT                   "user-agent"
+#define EPHY_PREFS_WEB_MOBILE_USER_AGENT            "mobile-user-agent"
 #define EPHY_PREFS_WEB_COOKIES_POLICY               "cookies-policy"
 #define EPHY_PREFS_WEB_DEFAULT_ENCODING             "default-encoding"
 #define EPHY_PREFS_WEB_DO_NOT_TRACK                 "do-not-track"
@@ -142,6 +143,7 @@ static const char * const ephy_prefs_web_schema[] = {
   EPHY_PREFS_WEB_ENABLE_WEBAUDIO,
   EPHY_PREFS_WEB_ENABLE_SMOOTH_SCROLLING,
   EPHY_PREFS_WEB_USER_AGENT,
+  EPHY_PREFS_WEB_MOBILE_USER_AGENT,
   EPHY_PREFS_WEB_COOKIES_POLICY,
   EPHY_PREFS_WEB_DEFAULT_ENCODING,
   EPHY_PREFS_WEB_DO_NOT_TRACK,
diff --git a/lib/ephy-user-agent.c b/lib/ephy-user-agent.c
index 7bcf6f50d..7d598f733 100644
--- a/lib/ephy-user-agent.c
+++ b/lib/ephy-user-agent.c
@@ -30,6 +30,7 @@ ephy_user_agent_get_internal (void)
 {
   WebKitSettings *settings;
   static char *user_agent = NULL;
+  gboolean mobile = FALSE;
 
   if (user_agent)
     return user_agent;
@@ -41,8 +42,11 @@ ephy_user_agent_get_internal (void)
     g_free (user_agent);
   }
 
+  mobile = g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_MOBILE_USER_AGENT);
   settings = webkit_settings_new ();
-  user_agent = g_strdup_printf ("%s Epiphany/605.1.15", webkit_settings_get_user_agent (settings));
+  user_agent = g_strdup_printf ("%s%s Epiphany/605.1.15",
+                                webkit_settings_get_user_agent (settings),
+                                mobile ? " Mobile" : "");
   g_object_unref (settings);
 
   return user_agent;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]