[epiphany/mcatanzaro/user-agent] Simplify user agent construction
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/user-agent] Simplify user agent construction
- Date: Sun, 23 Jun 2019 17:05:48 +0000 (UTC)
commit 73960cb8d5f536d2c2106b45213a9e3693289615
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Sun Jun 23 11:12:08 2019 -0500
Simplify user agent construction
embed/ephy-embed-prefs.c | 13 ++-----------
lib/ephy-user-agent.c | 15 ++++++++++-----
lib/ephy-user-agent.h | 2 +-
lib/safe-browsing/ephy-gsb-service.c | 2 +-
lib/sync/ephy-sync-service.c | 2 +-
5 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index dcae90dd1..a3158fcd8 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -142,17 +142,8 @@ webkit_pref_callback_user_agent (GSettings *settings,
const char *key,
gpointer data)
{
- EphyEmbedShell *shell = ephy_embed_shell_get_default ();
- char *user_agent;
-
- if (ephy_embed_shell_get_mode (shell) == EPHY_EMBED_SHELL_MODE_APPLICATION)
- user_agent = g_strdup_printf ("%s (Web App)", ephy_user_agent_get_internal ());
- else
- user_agent = g_strdup (ephy_user_agent_get_internal ());
-
- webkit_settings_set_user_agent (webkit_settings, user_agent);
-
- g_free (user_agent);
+ webkit_settings_set_user_agent (webkit_settings,
+ ephy_user_agent_get ());
}
static void
diff --git a/lib/ephy-user-agent.c b/lib/ephy-user-agent.c
index 7d598f733..d30114053 100644
--- a/lib/ephy-user-agent.c
+++ b/lib/ephy-user-agent.c
@@ -21,16 +21,18 @@
#include "config.h"
#include "ephy-user-agent.h"
+#include "ephy-file-helpers.h"
#include "ephy-settings.h"
#include <webkit2/webkit2.h>
const char *
-ephy_user_agent_get_internal (void)
+ephy_user_agent_get (void)
{
- WebKitSettings *settings;
static char *user_agent = NULL;
- gboolean mobile = FALSE;
+ WebKitSettings *settings;
+ gboolean mobile;
+ gboolean web_app;
if (user_agent)
return user_agent;
@@ -43,10 +45,13 @@ ephy_user_agent_get_internal (void)
}
mobile = g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_MOBILE_USER_AGENT);
+ web_app = ephy_profile_dir_is_web_application ();
+
settings = webkit_settings_new ();
- user_agent = g_strdup_printf ("%s%s Epiphany/605.1.15",
+ user_agent = g_strdup_printf ("%s%s Epiphany/605.1.15%s",
webkit_settings_get_user_agent (settings),
- mobile ? " Mobile" : "");
+ mobile ? " Mobile" : "",
+ web_app ? " (Web App)" : "");
g_object_unref (settings);
return user_agent;
diff --git a/lib/ephy-user-agent.h b/lib/ephy-user-agent.h
index 4f02b7a47..353bbbb49 100644
--- a/lib/ephy-user-agent.h
+++ b/lib/ephy-user-agent.h
@@ -24,6 +24,6 @@
G_BEGIN_DECLS
-const char *ephy_user_agent_get_internal (void);
+const char *ephy_user_agent_get (void);
G_END_DECLS
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index d31fbc154..8a89f26cb 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -436,7 +436,7 @@ static void
ephy_gsb_service_init (EphyGSBService *self)
{
self->session = soup_session_new ();
- g_object_set (self->session, "user-agent", ephy_user_agent_get_internal (), NULL);
+ g_object_set (self->session, "user-agent", ephy_user_agent_get (), NULL);
}
static void
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 24c97ac19..276f5cb7c 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -1962,7 +1962,7 @@ ephy_sync_service_constructed (GObject *object)
if (self->sync_periodically) {
g_object_set (self->session,
- "user-agent", ephy_user_agent_get_internal (),
+ "user-agent", ephy_user_agent_get (),
NULL);
g_signal_connect (EPHY_SETTINGS_SYNC, "changed::"EPHY_PREFS_SYNC_FREQUENCY,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]