c3df8e2fac1a4d534eb1ff07cb2f2798da283e27
[surf.git] / surf.c
1 /* See LICENSE file for copyright and license details.
2  *
3  * To understand surf, start reading main().
4  */
5 #include <X11/X.h>
6 #include <X11/Xatom.h>
7 #include <gtk/gtk.h>
8 #include <gdk/gdkx.h>
9 #include <gdk/gdk.h>
10 #include <gdk/gdkkeysyms.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <getopt.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <webkit/webkit.h>
17 #include <glib/gstdio.h>
18
19 #define LENGTH(x) (sizeof x / sizeof x[0])
20 #define CLEANMASK(mask)         (mask & ~(GDK_MOD2_MASK))
21
22 Display *dpy;
23 Atom urlprop;
24 typedef union Arg Arg;
25 union Arg {
26         const gboolean b;
27         const gint i;
28         const void *v;
29 } ;
30
31 typedef struct Client {
32         GtkWidget *win, *scroll, *vbox, *urlbar, *searchbar, *indicator;
33         WebKitWebView *view;
34         WebKitDownload *download;
35         gchar *title;
36         gint progress;
37         struct Client *next;
38 } Client;
39
40 typedef struct Cookie {
41         char *name;
42         char *value;
43         char *domain;
44         char *path;
45         struct Cookie *next;
46 } Cookie;
47
48 typedef enum {
49     BROWSER = 0x0001,
50     SEARCHBAR = 0x0010,
51     URLBAR = 0x0100,
52     ALWAYS = ~0,
53 } KeyFocus;
54
55 typedef struct {
56         guint mod;
57         guint keyval;
58         void (*func)(Client *c, const Arg *arg);
59         const Arg arg;
60         KeyFocus focus;
61 } Key;
62
63 SoupCookieJar *cookiejar;
64 SoupSession *session;
65 Client *clients = NULL;
66 Cookie *cookies = NULL;
67 gboolean embed = FALSE;
68 gboolean showxid = FALSE;
69 gboolean ignore_once = FALSE;
70 extern char *optarg;
71 extern gint optind;
72
73 static void cleanup(void);
74 static void clipboard(Client *c, const Arg *arg);
75 static void destroyclient(Client *c);
76 static void destroywin(GtkWidget* w, Client *c);
77 static void die(char *str);
78 static void download(WebKitDownload *o, GParamSpec *pspec, Client *c);
79 static void drawindicator(Client *c);
80 static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c);
81 static gboolean initdownload(WebKitWebView *view, WebKitDownload *o, Client *c);
82 static gchar *geturi(Client *c);
83 static void hidesearch(Client *c, const Arg *arg);
84 static void hideurl(Client *c, const Arg *arg);
85 static gboolean keypress(GtkWidget* w, GdkEventKey *ev, Client *c);
86 static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, Client *c);
87 static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, Client *c);
88 static void loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c);
89 static void loadfile(Client *c, const gchar *f);
90 static void loaduri(Client *c, const Arg *arg);
91 static void navigate(Client *c, const Arg *arg);
92 static Client *newclient();
93 static WebKitWebView *newwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c);
94 static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
95 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
96 static void print(Client *c, const Arg *arg);
97 static void proccookies(SoupMessage *m, Client *c);
98 static void progresschange(WebKitWebView *view, gint p, Client *c);
99 static void request(SoupSession *s, SoupMessage *m, Client *c);
100 static void reload(Client *c, const Arg *arg);
101 static void rereadcookies();
102 static void setcookie(char *name, char *val, char *dom, char *path, long exp);
103 static void setup();
104 static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
105                 const gchar* title, Client *c);
106 static void searchtext(Client *c, const Arg *arg);
107 static void source(Client *c, const Arg *arg);
108 static void showsearch(Client *c, const Arg *arg);
109 static void showurl(Client *c, const Arg *arg);
110 static void stop(Client *c, const Arg *arg);
111 static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, Client *c);
112 static void usage();
113 static void update(Client *c, const gchar *title);
114 static void zoom(Client *c, const Arg *arg);
115
116 #include "config.h"
117
118 void
119 cleanup(void) {
120         while(clients)
121                 destroyclient(clients);
122 }
123
124 void
125 clipboard(Client *c, const Arg *arg) {
126         gboolean paste = *(gboolean *)arg;
127         if(paste)
128                 gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pasteurl, c);
129         else
130                 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), webkit_web_view_get_uri(c->view), -1);
131 }
132
133 void
134 destroyclient(Client *c) {
135         Client *p;
136
137         gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
138         gtk_widget_destroy(c->scroll);
139         gtk_widget_destroy(c->urlbar);
140         gtk_widget_destroy(c->searchbar);
141         gtk_widget_destroy(c->vbox);
142         gtk_widget_destroy(c->win);
143         for(p = clients; p && p->next != c; p = p->next);
144         if(p)
145                 p->next = c->next;
146         else
147                 clients = c->next;
148         free(c);
149         if(clients == NULL)
150                 gtk_main_quit();
151 }
152
153 void
154 destroywin(GtkWidget* w, Client *c) {
155         destroyclient(c);
156 }
157
158 void
159 die(char *str) {
160         fputs(str, stderr);
161         exit(EXIT_FAILURE);
162 }
163
164 void
165 drawindicator(Client *c) {
166         gint width;
167         gchar *uri;
168         GtkWidget *w;
169         GdkGC *gc;
170         GdkColor fg;
171
172         uri = geturi(c);
173         w = c->indicator;
174         width = c->progress * w->allocation.width / 100;
175         gc = gdk_gc_new(w->window);
176         gdk_color_parse(strstr(uri, "https://") == uri ?
177                         progress_trust : progress, &fg);
178         gdk_gc_set_rgb_fg_color(gc, &fg);
179         gdk_draw_rectangle(w->window,
180                         w->style->bg_gc[GTK_WIDGET_STATE(w)],
181                         TRUE, 0, 0, w->allocation.width, w->allocation.height);
182         gdk_draw_rectangle(w->window, gc, TRUE, 0, 0, width,
183                         w->allocation.height);
184         g_object_unref(gc);/*g_free(gc);*/
185 }
186
187 gboolean
188 exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c) {
189         drawindicator(c);
190         return TRUE;
191 }
192
193 void
194 download(WebKitDownload *o, GParamSpec *pspec, Client *c) {
195         WebKitDownloadStatus status;
196
197         status = webkit_download_get_status(c->download);
198         if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
199                 c->progress = (gint)(webkit_download_get_progress(c->download)*100);
200         }
201         update(c, NULL);
202 }
203
204 gboolean
205 initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
206         const gchar *home, *filename;
207         gchar *uri, *path, *html;
208
209         stop(c, NULL);
210         c->download = o;
211         home = g_get_home_dir();
212         filename = webkit_download_get_suggested_filename(o);
213         path = g_build_filename(home, ".surf", "dl", 
214                         filename, NULL);
215         uri = g_strconcat("file://", path, NULL);
216         webkit_download_set_destination_uri(c->download, uri);
217         c->progress = 0;
218         g_free(uri);
219         html = g_strdup_printf("Download <b>%s</b>...", filename);
220         webkit_web_view_load_html_string(c->view, html,
221                         webkit_download_get_uri(c->download));
222         g_signal_connect(c->download, "notify::progress", G_CALLBACK(download), c);
223         g_signal_connect(c->download, "notify::status", G_CALLBACK(download), c);
224         webkit_download_start(c->download);
225         update(c, filename);
226         g_free(html);
227         return TRUE;
228 }
229
230 gchar *
231 geturi(Client *c) {
232         gchar *uri;
233
234         if(!(uri = (gchar *)webkit_web_view_get_uri(c->view)))
235                 uri = g_strdup("about:blank");
236         return uri;
237 }
238
239 void
240 hidesearch(Client *c, const Arg *arg) {
241         gtk_widget_hide(c->searchbar);
242         gtk_widget_grab_focus(GTK_WIDGET(c->view));
243 }
244
245 void
246 hideurl(Client *c, const Arg *arg) {
247         gtk_widget_hide(c->urlbar);
248         gtk_widget_grab_focus(GTK_WIDGET(c->view));
249 }
250
251 gboolean
252 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
253         guint i, focus;
254         gboolean processed = FALSE;
255
256         if(ev->type != GDK_KEY_PRESS)
257                 return FALSE;
258         if(GTK_WIDGET_HAS_FOCUS(c->searchbar))
259                 focus = SEARCHBAR;
260         else if(GTK_WIDGET_HAS_FOCUS(c->urlbar))
261                 focus = URLBAR;
262         else
263                 focus = BROWSER;
264         for(i = 0; i < LENGTH(keys); i++) {
265                 if(focus & keys[i].focus && ev->keyval == keys[i].keyval &&
266                                 CLEANMASK(ev->state) == keys[i].mod
267                                 && keys[i].func) {
268                         keys[i].func(c, &(keys[i].arg));
269                         processed = TRUE;
270                 }
271         }
272         return processed;
273 }
274
275 void
276 linkhover(WebKitWebView* page, const gchar* t, const gchar* l, Client *c) {
277         if(l)
278                 gtk_window_set_title(GTK_WINDOW(c->win), l);
279         else
280                 update(c, NULL);
281 }
282
283 void
284 loadcommit(WebKitWebView *view, WebKitWebFrame *f, Client *c) {
285         gchar *uri;
286
287         ignore_once = TRUE;
288         uri = geturi(c);
289         XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), urlprop,
290                         XA_STRING, 8, PropModeReplace, (unsigned char *)uri,
291                         strlen(uri) + 1);
292 }
293
294 void
295 loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c) {
296         c->progress = 0;
297         update(c, NULL);
298 }
299
300 void
301 loadfile(Client *c, const gchar *f) {
302         GIOChannel *chan = NULL;
303         GError *e = NULL;
304         GString *code;
305         gchar *line, *uri;
306         Arg arg;
307
308         if(strcmp(f, "-") == 0) {
309                 chan = g_io_channel_unix_new(STDIN_FILENO);
310                 if (chan) {
311                         code = g_string_new("");
312                         while(g_io_channel_read_line(chan, &line, NULL, NULL,
313                                                 &e) == G_IO_STATUS_NORMAL) {
314                                 g_string_append(code, line);
315                                 g_free(line);
316                         }
317                         webkit_web_view_load_html_string(c->view, code->str,
318                                         "file://.");
319                         g_io_channel_shutdown(chan, FALSE, NULL);
320                         g_string_free(code, TRUE);
321                 }
322                 arg.v = uri = g_strdup("stdin");
323         }
324         else {
325                 arg.v = uri = g_strdup_printf("file://%s", f);
326                 loaduri(c, &arg);
327         }
328         update(c, uri);
329         g_free(uri);
330 }
331
332 void
333 loaduri(Client *c, const Arg *arg) {
334         gchar *u;
335         const gchar *uri = (gchar *)arg->v;
336         if(!uri)
337                 uri = gtk_entry_get_text(GTK_ENTRY(c->urlbar));
338         u = g_strrstr(uri, "://") ? g_strdup(uri)
339                 : g_strdup_printf("http://%s", uri);
340         webkit_web_view_load_uri(c->view, u);
341         c->progress = 0;
342         update(c, u);
343         g_free(u);
344 }
345
346 void
347 navigate(Client *c, const Arg *arg) {
348         gint steps = *(gint *)arg;
349         webkit_web_view_go_back_or_forward(c->view, steps);
350 }
351
352 Client *
353 newclient(void) {
354         Client *c;
355         if(!(c = calloc(1, sizeof(Client))))
356                 die("Cannot malloc!\n");
357         /* Window */
358         if(embed) {
359                 c->win = gtk_plug_new(0);
360         }
361         else {
362                 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
363                 gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf");
364         }
365         gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
366         g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
367         g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
368
369         /* VBox */
370         c->vbox = gtk_vbox_new(FALSE, 0);
371
372         /* scrolled window */
373         c->scroll = gtk_scrolled_window_new(NULL, NULL);
374         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll),
375                         GTK_POLICY_NEVER, GTK_POLICY_NEVER);
376
377         /* webview */
378         c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
379         g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
380         g_signal_connect(G_OBJECT(c->view), "load-progress-changed", G_CALLBACK(progresschange), c);
381         g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c);
382         g_signal_connect(G_OBJECT(c->view), "load-started", G_CALLBACK(loadstart), c);
383         g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
384         g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
385         g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
386         g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
387
388         /* urlbar */
389         c->urlbar = gtk_entry_new();
390         gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
391
392         /* searchbar */
393         c->searchbar = gtk_entry_new();
394         gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
395
396         /* indicator */
397         c->indicator = gtk_drawing_area_new();
398         gtk_widget_set_size_request(c->indicator, 0, 2);
399         g_signal_connect (G_OBJECT (c->indicator), "expose_event",
400                         G_CALLBACK (exposeindicator), c);
401
402         /* downloadbar */
403
404         /* Arranging */
405         gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
406         gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
407         gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
408         gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar);
409         gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
410         gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
411
412         /* Setup */
413         gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
414         gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);
415         gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START);
416         gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
417         gtk_widget_grab_focus(GTK_WIDGET(c->view));
418         gtk_widget_hide_all(c->searchbar);
419         gtk_widget_hide_all(c->urlbar);
420         gtk_widget_show(c->vbox);
421         gtk_widget_show(c->indicator);
422         gtk_widget_show(c->scroll);
423         gtk_widget_show(GTK_WIDGET(c->view));
424         gtk_widget_show(c->win);
425         gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK);
426         gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
427         webkit_web_view_set_full_content_zoom(c->view, TRUE);
428         c->download = NULL;
429         c->title = NULL;
430         c->next = clients;
431         clients = c;
432         if(showxid) {
433                 gdk_display_sync(gtk_widget_get_display(c->win));
434                 printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
435                 fflush(NULL);
436         }
437         return c;
438 }
439
440 WebKitWebView *
441 newwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c) {
442         Client *n = newclient();
443         return n->view;
444 }
445
446  
447 void
448 pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d) {
449         Arg arg = {.v = text };
450         if(text != NULL)
451                 loaduri((Client *) d, &arg);
452 }
453
454 GdkFilterReturn
455 processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
456         Client *c = (Client *)d;
457         XPropertyEvent *ev;
458         Atom adummy;
459         gint idummy;
460         unsigned long ldummy;
461         unsigned char *buf = NULL;
462         Arg arg;
463
464         if(((XEvent *)e)->type == PropertyNotify) {
465                 ev = &((XEvent *)e)->xproperty;
466                 if(ev->atom == urlprop && ev->state == PropertyNewValue) {
467                         if(ignore_once)
468                                ignore_once = FALSE;
469                         else {
470                                 XGetWindowProperty(dpy, ev->window, urlprop, 0L, BUFSIZ, False, XA_STRING,
471                                         &adummy, &idummy, &ldummy, &ldummy, &buf);
472                                 arg.v = buf;
473                                 loaduri(c, &arg);
474                                 XFree(buf);
475                         }
476                         return GDK_FILTER_REMOVE;
477                 }
478         }
479         return GDK_FILTER_CONTINUE;
480 }
481
482 void
483 print(Client *c, const Arg *arg) {
484         webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
485 }
486
487 void
488 proccookies(SoupMessage *m, Client *c) {
489         GSList *l;
490         SoupCookie *co;
491         long t;
492
493         rereadcookies();
494         for (l = soup_cookies_from_response(m); l; l = l->next){
495                 co = (SoupCookie *)l->data;
496                 t = co->expires ?  soup_date_to_time_t(co->expires) : 0;
497                 setcookie(co->name, co->value, co->domain, co->value, t);
498         }
499         g_slist_free(l);
500 }
501
502 void
503 progresschange(WebKitWebView* view, gint p, Client *c) {
504         c->progress = p;
505         update(c, NULL);
506 }
507
508 void
509 request(SoupSession *s, SoupMessage *m, Client *c) {
510         soup_message_add_header_handler(m, "got-headers", "Set-Cookie",
511                         G_CALLBACK(proccookies), c);
512 }
513
514 void
515 reload(Client *c, const Arg *arg) {
516         gboolean nocache = *(gboolean *)arg;
517         if(nocache)
518                  webkit_web_view_reload_bypass_cache(c->view);
519         else
520                  webkit_web_view_reload(c->view);
521 }
522
523 void
524 rereadcookies() {
525         const gchar *filename, *home;
526
527         home = g_get_home_dir();
528         filename = g_build_filename(home, ".surf", "cookies", NULL);
529 }
530
531 void
532 setcookie(char *name, char *val, char *dom, char *path, long exp) {
533
534 }
535
536 void
537 setup() {
538         dpy = GDK_DISPLAY();
539         session = webkit_get_default_session();
540         urlprop = XInternAtom(dpy, "_SURF_URL", False);
541 }
542
543 void
544 showsearch(Client *c, const Arg *arg) {
545         hideurl(c, NULL);
546         gtk_widget_show(c->searchbar);
547         gtk_widget_grab_focus(c->searchbar);
548 }
549
550 void
551 source(Client *c, const Arg *arg) {
552         Arg a = { .b = FALSE };
553         /*gboolean s;
554
555         s = webkit_web_view_get_view_source_mode(c->view);
556         webkit_web_view_set_view_source_mode(c->view, c->source);*/
557         reload(c, &a);
558 }
559
560 void
561 searchtext(Client *c, const Arg *arg) {
562         gboolean forward = *(gboolean *)arg;
563         webkit_web_view_search_text(c->view,
564                         gtk_entry_get_text(GTK_ENTRY(c->searchbar)),
565                         FALSE,
566                         forward,
567                         TRUE);
568 }
569
570 void
571 showurl(Client *c, const Arg *arg) {
572         gchar *uri;
573
574         hidesearch(c, NULL);
575         uri = geturi(c);
576         gtk_entry_set_text(GTK_ENTRY(c->urlbar), uri);
577         gtk_widget_show(c->urlbar);
578         gtk_widget_grab_focus(c->urlbar);
579 }
580
581 void
582 stop(Client *c, const Arg *arg) {
583         if(c->download)
584                 webkit_download_cancel(c->download);
585         else
586                 webkit_web_view_stop_loading(c->view);
587         c->download = NULL;
588 }
589
590 void
591 titlechange(WebKitWebView *v, WebKitWebFrame *f, const gchar *t, Client *c) {
592         update(c, t);
593 }
594
595 void
596 usage() {
597         fputs("surf - simple browser\n", stderr);
598         die("usage: surf [-e] [-x] [uri]\n");
599 }
600
601 void
602 update(Client *c, const char *title) {
603         gchar *t;
604
605         if(title) {
606                 if(c->title)
607                         g_free(c->title);
608                 c->title = g_strdup(title);
609         }
610         if(c->progress == 100)
611                 t = g_strdup(c->title);
612         else
613                 t = g_strdup_printf("%s [%i%%]", c->title, c->progress);
614         drawindicator(c);
615         gtk_window_set_title(GTK_WINDOW(c->win), t);
616         g_free(t);
617
618 }
619
620 void
621 zoom(Client *c, const Arg *arg) {
622         if(arg->i < 0)          /* zoom out */
623                 webkit_web_view_zoom_out(c->view);
624         else if(arg->i > 0)     /* zoom in */
625                 webkit_web_view_zoom_in(c->view);
626         else                    /* reset */
627                 webkit_web_view_set_zoom_level(c->view, 1.0);
628 }
629
630 int main(int argc, char *argv[]) {
631         SoupSession *s;
632         Client *c;
633         gint o;
634         const gchar *home, *filename;
635         Arg arg;
636
637         gtk_init(NULL, NULL);
638         if (!g_thread_supported())
639                 g_thread_init(NULL);
640         setup();
641         while((o = getopt(argc, argv, "vhxeu:f:")) != -1)
642                 switch(o) {
643                 case 'x':
644                         showxid = TRUE;
645                         break;
646                 case 'e':
647                         showxid = TRUE;
648                         embed = TRUE;
649                         break;
650                 case 'v':
651                         die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
652                         break;
653                 default:
654                         usage();
655                 }
656         if(optind + 1 == argc) {
657                 c = newclient();
658                 arg.v = argv[optind];
659                 if(strchr("./", argv[optind][0]) || strcmp("-", argv[optind]) == 0)
660                         loadfile(c, argv[optind]);
661                 else
662                         loaduri(c, &arg);
663
664         }
665         else if(optind != argc)
666                 usage();
667         if(!clients)
668                 newclient();
669
670         /* make dirs */
671         home = g_get_home_dir();
672         filename = g_build_filename(home, ".surf", "dl", NULL);
673         g_mkdir_with_parents(filename, 0755);
674
675         /* cookie persistance */
676         s = webkit_get_default_session();
677         filename = g_build_filename(home, ".surf", "cookies.jar", NULL);
678         cookiejar = soup_cookie_jar_text_new(filename, FALSE);
679         soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
680
681         gtk_main();
682         cleanup();
683         return EXIT_SUCCESS;
684 }