X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=surf.c;h=eab314af5cd7f38795d0619ee5fe973dea8d5e95;hp=61448fb58f5615c6236a4d7f38ba9b61e982fdf1;hb=c60523a702fbc77899457243f1a85e4990adfb97;hpb=a8bf2068276e27dcbd2919cb72d926b9f4f3882e diff --git a/surf.c b/surf.c index 61448fb..eab314a 100644 --- a/surf.c +++ b/surf.c @@ -79,6 +79,7 @@ typedef enum { SpellLanguages, StrictTLS, Style, + WebGL, ZoomLevel, ParameterLast } ParamName; @@ -145,6 +146,7 @@ static void sigchld(int unused); static void sighup(int unused); static char *buildfile(const char *path); static char *buildpath(const char *path); +static char *untildepath(const char *path); static const char *getuserhomedir(const char *user); static const char *getcurrentuserhomedir(void); static Client *newclient(Client *c); @@ -204,6 +206,9 @@ static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c); static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c); static void download(Client *c, WebKitURIResponse *r); +static void webprocessterminated(WebKitWebView *v, + WebKitWebProcessTerminationReason r, + Client *c); static void closeview(WebKitWebView *v, Client *c); static void destroywin(GtkWidget* w, Client *c); @@ -241,6 +246,7 @@ static GdkDevice *gdkkb; static char *stylefile; static const char *useragent; static Parameter *curconfig; +static int modparams[ParameterLast]; char *argv0; static ParamName loadtransient[] = { @@ -468,26 +474,12 @@ getcurrentuserhomedir(void) char * buildpath(const char *path) { - char *apath, *name, *p, *fpath; - const char *homedir; - - if (path[0] == '~') { - if (path[1] == '/' || path[1] == '\0') { - p = (char *)&path[1]; - homedir = getcurrentuserhomedir(); - } else { - if ((p = strchr(path, '/'))) - name = g_strndup(&path[1], --p - path); - else - name = g_strdup(&path[1]); + char *apath, *fpath; - homedir = getuserhomedir(name); - g_free(name); - } - apath = g_build_filename(homedir, p, NULL); - } else { + if (path[0] == '~') + apath = untildepath(path); + else apath = g_strdup(path); - } /* creating directory */ if (g_mkdir_with_parents(apath, 0700) < 0) @@ -499,6 +491,28 @@ buildpath(const char *path) return fpath; } +char * +untildepath(const char *path) +{ + char *apath, *name, *p; + const char *homedir; + + if (path[1] == '/' || path[1] == '\0') { + p = (char *)&path[1]; + homedir = getcurrentuserhomedir(); + } else { + if ((p = strchr(path, '/'))) + name = g_strndup(&path[1], p - (path + 1)); + else + name = g_strdup(&path[1]); + + homedir = getuserhomedir(name); + g_free(name); + } + apath = g_build_filename(homedir, p, NULL); + return apath; +} + Client * newclient(Client *rc) { @@ -520,7 +534,7 @@ void loaduri(Client *c, const Arg *a) { struct stat st; - char *url, *path; + char *url, *path, *apath; const char *uri = a->v; if (g_strcmp0(uri, "") == 0) @@ -531,11 +545,19 @@ loaduri(Client *c, const Arg *a) g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) { url = g_strdup(uri); - } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) { - url = g_strdup_printf("file://%s", path); - free(path); } else { - url = g_strdup_printf("http://%s", uri); + 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 = g_strdup_printf("http://%s", uri); + } + if (apath != uri) + free(apath); } setatom(c, AtomUri, url); @@ -673,41 +695,31 @@ cookiepolicy_set(const WebKitCookieAcceptPolicy p) void seturiparameters(Client *c, const char *uri, ParamName *params) { - Parameter *config, *newconfig = NULL; + Parameter *config, *uriconfig = NULL; int i, p; for (i = 0; i < LENGTH(uriparams); ++i) { if (uriparams[i].uri && !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) { - newconfig = uriparams[i].config; + uriconfig = uriparams[i].config; break; } } - if (!newconfig) - newconfig = defconfig; + curconfig = uriconfig ? uriconfig : defconfig; for (i = 0; (p = params[i]) != ParameterLast; ++i) { switch(p) { + default: /* FALLTHROUGH */ + if (!(defconfig[p].prio < curconfig[p].prio || + defconfig[p].prio < modparams[p])) + continue; case Certificate: case CookiePolicies: case Style: - config = (newconfig[p].prio > defconfig[p].prio) ? - newconfig : defconfig; - break; - default: - if (newconfig[p].prio > defconfig[p].prio) - config = newconfig; - else if (curconfig[p].prio > defconfig[p].prio) - config = defconfig; - else - continue; + setparameter(c, 0, p, &curconfig[p].val); } - - setparameter(c, 0, p, &config[p].val); } - - curconfig = newconfig; } void @@ -716,6 +728,8 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) GdkRGBA bgcolor = { 0 }; WebKitSettings *s = webkit_web_view_get_settings(c->view); + modparams[p] = curconfig[p].prio; + switch (p) { case AcceleratedCanvas: webkit_settings_set_enable_accelerated_2d_canvas(s, a->i); @@ -827,6 +841,9 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) setstyle(c, getstyle(geturi(c))); refresh = 0; break; + case WebGL: + webkit_settings_set_enable_webgl(s, a->i); + break; case ZoomLevel: webkit_web_view_set_zoom_level(c->view, a->f); return; /* do not update */ @@ -924,7 +941,7 @@ runscript(Client *c) gsize l; if (g_file_get_contents(scriptfile, &script, &l, NULL) && l) - evalscript(c, script); + evalscript(c, "%s", script); g_free(script); } @@ -1086,6 +1103,7 @@ newview(Client *c, WebKitWebView *rv) "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i, "enable-site-specific-quirks", curconfig[SiteQuirks].val.i, "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i, + "enable-webgl", curconfig[WebGL].val.i, "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i, NULL); /* For more interesting settings, have a look at @@ -1172,6 +1190,8 @@ newview(Client *c, WebKitWebView *rv) G_CALLBACK(permissionrequested), c); g_signal_connect(G_OBJECT(v), "ready-to-show", G_CALLBACK(showview), c); + g_signal_connect(G_OBJECT(v), "web-process-terminated", + G_CALLBACK(webprocessterminated), c); return v; } @@ -1317,6 +1337,7 @@ showview(WebKitWebView *v, Client *c) if (showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); puts(winid); + fflush(stdout); } if (curconfig[HideBackground].val.i) @@ -1675,6 +1696,15 @@ download(Client *c, WebKitURIResponse *r) spawn(c, &a); } +void +webprocessterminated(WebKitWebView *v, WebKitWebProcessTerminationReason r, + Client *c) +{ + fprintf(stderr, "web process terminated: %s\n", + r == WEBKIT_WEB_PROCESS_CRASHED ? "crashed" : "no memory"); + closeview(v, c); +} + void closeview(WebKitWebView *v, Client *c) {