+ if (!(c = calloc(1, sizeof(Client))))
+ die("Cannot malloc!\n");
+
+ c->next = clients;
+ clients = c;
+
+ c->progress = 100;
+ c->view = newview(c, rc ? rc->view : NULL);
+
+ return c;
+}
+
+void
+loaduri(Client *c, const Arg *a)
+{
+ struct stat st;
+ char *url, *path, *apath;
+ const char *uri = a->v;
+
+ if (g_strcmp0(uri, "") == 0)
+ return;
+
+ if (g_str_has_prefix(uri, "http://") ||
+ g_str_has_prefix(uri, "https://") ||
+ g_str_has_prefix(uri, "file://") ||
+ g_str_has_prefix(uri, "about:")) {
+ url = g_strdup(uri);
+ } else {
+ if (uri[0] == '~')
+ apath = untildepath(uri);
+ else
+ apath = (char *)uri;
+ if (!stat(apath, &st) && (path = realpath(apath, NULL))) {
+ url = g_strdup_printf("file://%s", path);
+ free(path);
+ } else {
+ url = parseuri(uri);
+ }
+ if (apath != uri)
+ free(apath);
+ }
+
+ setatom(c, AtomUri, url);
+
+ if (strcmp(url, geturi(c)) == 0) {
+ reload(c, a);
+ } else {
+ webkit_web_view_load_uri(c->view, url);
+ updatetitle(c);
+ }
+
+ g_free(url);
+}
+
+const char *
+geturi(Client *c)
+{
+ const char *uri;
+
+ if (!(uri = webkit_web_view_get_uri(c->view)))
+ uri = "about:blank";
+ return uri;
+}
+
+void
+setatom(Client *c, int a, const char *v)
+{
+ XChangeProperty(dpy, c->xid,
+ atoms[a], XA_STRING, 8, PropModeReplace,
+ (unsigned char *)v, strlen(v) + 1);
+ XSync(dpy, False);
+}
+
+const char *
+getatom(Client *c, int a)
+{
+ static char buf[BUFSIZ];
+ Atom adummy;
+ int idummy;
+ unsigned long ldummy;
+ unsigned char *p = NULL;
+
+ XSync(dpy, False);
+ XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
+ &adummy, &idummy, &ldummy, &ldummy, &p);
+ if (p)
+ strncpy(buf, (char *)p, LENGTH(buf) - 1);
+ else
+ buf[0] = '\0';
+ XFree(p);
+
+ return buf;
+}
+
+void
+updatetitle(Client *c)
+{
+ char *title;
+ const char *name = c->overtitle ? c->overtitle :
+ c->title ? c->title : "";
+
+ if (curconfig[ShowIndicators].val.i) {
+ gettogglestats(c);
+ getpagestats(c);
+
+ if (c->progress != 100)
+ title = g_strdup_printf("[%i%%] %s:%s | %s",
+ c->progress, togglestats, pagestats, name);
+ else
+ title = g_strdup_printf("%s:%s | %s",
+ togglestats, pagestats, name);
+
+ gtk_window_set_title(GTK_WINDOW(c->win), title);
+ g_free(title);
+ } else {
+ gtk_window_set_title(GTK_WINDOW(c->win), name);
+ }
+}
+
+void
+gettogglestats(Client *c)
+{
+ togglestats[0] = cookiepolicy_set(cookiepolicy_get());
+ togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
+ togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
+ togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
+ togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
+ togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
+ togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
+ togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
+ togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
+ togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
+ togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
+ togglestats[11] = '\0';
+}
+
+void
+getpagestats(Client *c)
+{
+ if (c->https)
+ pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
+ else
+ pagestats[0] = '-';
+ pagestats[1] = '\0';
+}
+
+WebKitCookieAcceptPolicy
+cookiepolicy_get(void)
+{
+ switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {