X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=ee4bfeeef7c12014740c9dd04e25ed15864e2a73;hb=344efec3fb932a9c5baae582fe70c72a0bc4a747;hp=6f71657570e9cefeb02c0ef4fbc7e94f40906ccb;hpb=c2da2bae5dbca73f26fe77bb8080e2a90d3cbb1d;p=surf.git diff --git a/surf.c b/surf.c index 6f71657..ee4bfee 100644 --- a/surf.c +++ b/surf.c @@ -85,16 +85,17 @@ static GdkNativeWindow embed = 0; static gboolean showxid = FALSE; static char winid[64]; static gboolean usingproxy = 0; -static char togglestat[8]; +static char togglestat[9]; static char pagestat[3]; static GTlsDatabase *tlsdb; static int policysel = 0; static char *stylefile = NULL; +static SoupCache *diskcache = NULL; static void addaccelgroup(Client *c); static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, WebKitNetworkRequest *req, - WebKitNetworkResponse *resp, gpointer d); + WebKitNetworkResponse *resp, Client *c); static char *buildpath(const char *path); static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl); @@ -137,6 +138,8 @@ static void getpagestat(Client *c); static char *geturi(Client *c); static gchar *getstyle(const char *uri); +static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri); + static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c); static void inspector(Client *c, const Arg *arg); @@ -208,11 +211,30 @@ addaccelgroup(Client *c) { static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, WebKitNetworkRequest *req, WebKitNetworkResponse *resp, - gpointer d) { + Client *c) { const gchar *uri = webkit_network_request_get_uri(req); + int i, isascii = 1; if(g_str_has_suffix(uri, "/favicon.ico")) webkit_network_request_set_uri(req, "about:blank"); + + if(!g_str_has_prefix(uri, "http://") \ + && !g_str_has_prefix(uri, "https://") \ + && !g_str_has_prefix(uri, "about:") \ + && !g_str_has_prefix(uri, "file://") \ + && !g_str_has_prefix(uri, "data:") \ + && !g_str_has_prefix(uri, "blob:") \ + && strlen(uri) > 0) { + + for(i = 0; i < strlen(uri); i++) { + if(!g_ascii_isprint(uri[i])) { + isascii = 0; + break; + } + } + if(isascii) + handleplumb(c, w, uri); + } } static char * @@ -270,6 +292,10 @@ buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl) { static void cleanup(void) { + if (diskcache) { + soup_cache_flush(diskcache); + soup_cache_dump(diskcache); + } while(clients) destroyclient(clients); g_free(cookiefile); @@ -556,6 +582,15 @@ getstyle(const char *uri) { return g_strdup(""); } +static void +handleplumb(Client *c, WebKitWebView *w, const gchar *uri) { + Arg arg; + + webkit_web_view_stop_loading(w); + arg = (Arg)PLUMB((char *)uri); + spawn(c, &arg); +} + static gboolean initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) { Arg arg; @@ -677,6 +712,10 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { case WEBKIT_LOAD_FINISHED: c->progress = 100; updatetitle(c); + if (diskcache) { + soup_cache_flush(diskcache); + soup_cache_dump(diskcache); + } break; default: break; @@ -946,7 +985,7 @@ newclient(void) { static void newwindow(Client *c, const Arg *arg, gboolean noembed) { guint i = 0; - const char *cmd[16], *uri; + const char *cmd[18], *uri; const Arg a = { .v = (void *)cmd }; char tmp[64]; @@ -957,9 +996,11 @@ newwindow(Client *c, const Arg *arg, gboolean noembed) { cmd[i++] = "-b"; if(embed && !noembed) { cmd[i++] = "-e"; - snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed); + snprintf(tmp, LENGTH(tmp), "%u", (int)embed); cmd[i++] = tmp; } + if(!allowgeolocation) + cmd[i++] = "-g"; if(!loadimages) cmd[i++] = "-i"; if(kioskmode) @@ -970,6 +1011,8 @@ newwindow(Client *c, const Arg *arg, gboolean noembed) { cmd[i++] = "-s"; if(showxid) cmd[i++] = "-x"; + if(enablediskcache) + cmd[i++] = "-D"; cmd[i++] = "-c"; cmd[i++] = cookiefile; cmd[i++] = "--"; @@ -1147,6 +1190,7 @@ setup(void) { /* dirs and files */ cookiefile = buildpath(cookiefile); scriptfile = buildpath(scriptfile); + cachefolder = buildpath(cachefolder); styledir = buildpath(styledir); if(stylefile == NULL && enablestyles) { for(i = 0; i < LENGTH(styles); i++) { @@ -1173,6 +1217,14 @@ setup(void) { SOUP_SESSION_FEATURE(cookiejar_new(cookiefile, FALSE, cookiepolicy_get()))); + /* disk cache */ + if(enablediskcache) { + diskcache = soup_cache_new(cachefolder, SOUP_CACHE_SINGLE_USER); + soup_cache_set_max_size(diskcache, diskcachebytes); + soup_cache_load(diskcache); + soup_session_add_feature(s, SOUP_SESSION_FEATURE(diskcache)); + } + /* ssl */ tlsdb = g_tls_file_database_new(cafile, &error); @@ -1361,6 +1413,8 @@ gettogglestat(Client *c){ togglestat[p++] = allowgeolocation? 'G': 'g'; + togglestat[p++] = enablediskcache? 'D': 'd'; + g_object_get(G_OBJECT(settings), "auto-load-images", &value, NULL); togglestat[p++] = value? 'I': 'i'; @@ -1477,6 +1531,12 @@ main(int argc, char *argv[]) { case 'c': cookiefile = EARGF(usage()); break; + case 'd': + enablediskcache = 0; + break; + case 'D': + enablediskcache = 1; + break; case 'e': embed = strtol(EARGF(usage()), NULL, 0); break;