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