GNOME Bugzilla – Bug 767123
Include User-Agent component for installed web apps runtime
Last modified: 2016-06-09 12:08:49 UTC
Please consider including an extra component to Epiphany’s User-Agent when Epiphany is used as an installable web application runtime.
The motivation for including an extra component is letting websites owners get a little feedback about the popularity of their Epiphany web app. This can in turn help them help Epiphany by promoting installable web apps to their users. It also allows web apps to provide a more targeted experience to web app users (hide cookie disclaimers, slightly different stylesheet, and the like).
Suggested User-Agent for installed apps:
Mozilla/5.0 […] Epiphany/3.20.0 (WebApp)
Normal User-Agent for reference:
Mozilla/5.0 […] Epiphany/3.20.0
This would be a good first task for someone who wants to start contributing to Epiphany. The place to start would be webkit_pref_callback_user_agent() in embed/ephy-embed-prefs.c. To decide if we're in application mode, use ephy_embed_shell_get_default() to get the singleton instance of the EphyEmbedShell class, then ephy_embed_shell_get_mode().
We have to decide whether to append (WebApp) to the user agent even if the user has overridden the user agent with the gsetting. I think either way would be reasonable.
Created attachment 329014 [details] [review]
Suggested patch based on clear instructions.
Review of attachment 329014 [details] [review]:
Thanks. A couple string handling mistakes here, though:
@@ +204,3 @@
+ if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) ==
+ user_agent = g_strdup_printf ("%s (WebappShell)", user_agent);
You're leaking the previous value of user_agent here; got to free it before assigning to it again. Unfortunately you'll need to add yet another variable to use for the left hand side of this assignment. :/
@@ +208,3 @@
+ webkit_settings_set_user_agent (webkit_settings, user_agent);
+ g_free (user_agent);
+ g_free (internal_user_agent);
You don't want to free internal_user_agent here. Notice that webkit_pref_get_internal_user_agent returns a const char *, indicating that you're not supposed to free it. You probably got away with it because webkit_pref_get_internal_user_agent is probably only called once, but the function is written to return the original result if called multiple times, so now it's going to return freed memory on subsequent uses.
Created attachment 329100 [details] [review]
Patch, take three
Everything should be in order now. Sorry for having submitted 3:00 am-code. I should have waited till morning. :)
OK, looks good. I pushed a follow-up to simplify the code a bit more.
I forgot to mention this here in the bug: the final user-agent for web apps looks like this:
Mozilla/5.0 […] Epiphany/3.21.2 (WebappShell)
I've been thinking of changing it to (WebAppShell) or (WebApp) or (Web App) as I don't really like webapp as one word.
I have no good arguments for or against any particular component name. I didn’t capitalize the A because I came across some other examples of “Webapp” being used in User-Agents as one word. Similar solutions have used “(WAC)”, referring to a Web Application Container specification that seem to have died out. It doesn’t really matter as long as it stays consistent over time and doesn’t change. Choose something you’re happy with now rather than keep one you dislike and decide to change it later.
The following fix has been pushed:
8b18787 embed-prefs: Tweak the web app user agent
Created attachment 329453 [details] [review]
embed-prefs: Tweak the web app user agent