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