Adapt user agent handling

Now we can only append Surf version to the default WebKit user agent
instead of setting the whole string (while this remains possible to do).
This commit is contained in:
Quentin Rameau 2015-11-20 17:12:00 +01:00
parent e6cefa584e
commit 5bca222339
2 changed files with 11 additions and 7 deletions

View file

@ -1,7 +1,6 @@
/* modifier 0 means no modifier */ /* modifier 0 means no modifier */
static char *useragent = "Mozilla/5.0 (X11; U; Unix; en-US) " static int surfuseragent = 1; /* Append Surf version to default WebKit user agent */
"AppleWebKit/537.15 (KHTML, like Gecko) " static char *fulluseragent = ""; /* Or override the whole user agent string */
"Chrome/24.0.1295.0 Safari/537.15 Surf/"VERSION;
static char *scriptfile = "~/.surf/script.js"; static char *scriptfile = "~/.surf/script.js";
static char *styledir = "~/.surf/styles/"; static char *styledir = "~/.surf/styles/";
static char *cachedir = "~/.surf/cache/"; static char *cachedir = "~/.surf/cache/";

13
surf.c
View file

@ -112,6 +112,7 @@ static char pagestats[2];
static GTlsDatabase *tlsdb; static GTlsDatabase *tlsdb;
static int cookiepolicy; static int cookiepolicy;
static char *stylefile = NULL; static char *stylefile = NULL;
static const char *useragent;
static void addaccelgroup(Client *c); static void addaccelgroup(Client *c);
static char *buildfile(const char *path); static char *buildfile(const char *path);
@ -899,7 +900,6 @@ newview(Client *c, WebKitWebView *rv)
WebKitSettings *settings; WebKitSettings *settings;
WebKitUserContentManager *contentmanager; WebKitUserContentManager *contentmanager;
WebKitWebContext *context; WebKitWebContext *context;
char *ua;
/* Webview */ /* Webview */
if (rv) { if (rv) {
@ -918,12 +918,17 @@ newview(Client *c, WebKitWebView *rv)
"enable-javascript", enablescripts, "enable-javascript", enablescripts,
"enable-plugins", enableplugins, "enable-plugins", enableplugins,
NULL); NULL);
if (!(ua = getenv("SURF_USERAGENT")))
ua = useragent;
webkit_settings_set_user_agent(settings, ua);
/* Have a look at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html /* Have a look at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html
* for more interesting settings */ * for more interesting settings */
if (strcmp(fulluseragent, "")) {
webkit_settings_set_user_agent(settings, fulluseragent);
} else if (surfuseragent) {
webkit_settings_set_user_agent_with_application_details(
settings, "Surf", VERSION);
}
useragent = webkit_settings_get_user_agent(settings);
contentmanager = webkit_user_content_manager_new(); contentmanager = webkit_user_content_manager_new();
context = webkit_web_context_new_with_website_data_manager( context = webkit_web_context_new_with_website_data_manager(