1 /* See LICENSE file for copyright and license details.
3 * To understand surf, start reading main().
11 #include <gdk/gdkkeysyms.h>
13 #include <sys/types.h>
18 #include <webkit/webkit.h>
19 #include <glib/gstdio.h>
20 #include <JavaScriptCore/JavaScript.h>
22 #define LENGTH(x) (sizeof x / sizeof x[0])
23 #define CLEANMASK(mask) (mask & ~(GDK_MOD2_MASK))
25 typedef union Arg Arg;
32 typedef struct Client {
33 GtkWidget *win, *scroll, *vbox, *indicator;
36 WebKitDownload *download;
37 char *title, *linkhover;
38 const char *uri, *needle;
46 void (*func)(Client *c, const Arg *arg);
53 void (*func)(Client *c, const Arg *arg);
58 static Atom uriprop, findprop;
59 static Client *clients = NULL;
60 static GdkNativeWindow embed = 0;
61 static gboolean showxid = FALSE;
62 static int ignorexprop = 0;
63 static char winid[64];
64 static char *progname;
65 static gboolean loadimage = 1, plugin = 1, script = 1;
67 static char *buildpath(const char *path);
68 static void cleanup(void);
69 static void clipboard(Client *c, const Arg *arg);
70 static void context(WebKitWebView *v, GtkMenu *m, Client *c);
71 static char *copystr(char **str, const char *src);
72 static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c);
73 static gboolean decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c);
74 static gboolean decidewindow(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c);
75 static void destroyclient(Client *c);
76 static void destroywin(GtkWidget* w, Client *c);
77 static void die(char *str);
78 static void download(Client *c, const Arg *arg);
79 static void drawindicator(Client *c);
80 static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c);
81 static void find(Client *c, const Arg *arg);
82 static const char *getatom(Client *c, Atom a);
83 static const char *getcookies(SoupURI *uri);
84 static char *geturi(Client *c);
85 void gotheaders(SoupMessage *msg, gpointer user_data);
86 static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
87 static void itemclick(GtkMenuItem *mi, Client *c);
88 static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
89 static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
90 static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
91 static void loaduri(Client *c, const Arg *arg);
92 static void navigate(Client *c, const Arg *arg);
93 static Client *newclient(void);
94 static void newwindow(Client *c, const Arg *arg);
95 static void newrequest(SoupSession *s, SoupMessage *msg, gpointer v);
96 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
97 static void print(Client *c, const Arg *arg);
98 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
99 static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
100 static void reload(Client *c, const Arg *arg);
101 static void resize(GtkWidget *w, GtkAllocation *a, Client *c);
102 static void scroll(Client *c, const Arg *arg);
103 static void setatom(Client *c, Atom a, const char *v);
104 static void setcookie(SoupCookie *c);
105 static void setup(void);
106 static void sigchld(int unused);
107 static void source(Client *c, const Arg *arg);
108 static void spawn(Client *c, const Arg *arg);
109 static void stop(Client *c, const Arg *arg);
110 static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
111 static void update(Client *c);
112 static void updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c);
113 static void updatewinid(Client *c);
114 static void usage(void);
115 static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c);
116 static void zoom(Client *c, const Arg *arg);
118 /* configuration, allows nested code to access above variables */
122 buildpath(const char *path) {
126 /* creating directory */
128 apath = g_strdup(path);
130 apath = g_strconcat(g_get_home_dir(), "/", path, NULL);
131 if((p = strrchr(apath, '/'))) {
133 g_mkdir_with_parents(apath, 0755);
136 /* creating file (gives error when apath ends with "/") */
137 if((f = g_fopen(apath, "a")))
145 destroyclient(clients);
153 clipboard(Client *c, const Arg *arg) {
154 gboolean paste = *(gboolean *)arg;
157 gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pasteuri, c);
159 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), c->linkhover ? c->linkhover : geturi(c), -1);
163 context(WebKitWebView *v, GtkMenu *m, Client *c) {
165 GtkContainer *parent;
167 gtk_widget_hide_all(GTK_WIDGET(m));
168 gtk_widget_show(GTK_WIDGET(m));
169 for(i = 0; i < LENGTH(items); i++) {
170 parent = GTK_CONTAINER(gtk_widget_get_parent(c->items[i]));
172 gtk_container_remove(parent, c->items[i]);
173 gtk_menu_shell_append(GTK_MENU_SHELL(m), c->items[i]);
174 gtk_widget_show(c->items[i]);
179 copystr(char **str, const char *src) {
191 createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c) {
192 Client *n = newclient();
197 decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c) {
198 if(!webkit_web_view_can_show_mime_type(v, m)) {
199 webkit_web_policy_decision_download(p);
206 decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c) {
209 if(webkit_web_navigation_action_get_reason(n) == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
210 webkit_web_policy_decision_ignore(p);
211 arg.v = (void *)webkit_network_request_get_uri(r);
212 newwindow(NULL, &arg);
219 destroyclient(Client *c) {
223 gtk_widget_destroy(c->indicator);
224 gtk_widget_destroy(GTK_WIDGET(c->view));
225 gtk_widget_destroy(c->scroll);
226 gtk_widget_destroy(c->vbox);
227 gtk_widget_destroy(c->win);
228 for(i = 0; i < LENGTH(items); i++)
229 gtk_widget_destroy(c->items[i]);
232 for(p = clients; p && p->next != c; p = p->next);
243 destroywin(GtkWidget* w, Client *c) {
254 download(Client *c, const Arg *arg) {
256 WebKitNetworkRequest *r;
260 uri = (char *)arg->v;
262 uri = c->linkhover ? c->linkhover : geturi(c);
263 r = webkit_network_request_new(uri);
264 dl = webkit_download_new(r);
265 initdownload(c->view, dl, c);
266 webkit_download_start(c->download);
270 drawindicator(Client *c) {
277 uri = getatom(c, uriprop);
279 width = c->progress * w->allocation.width / 100;
280 gc = gdk_gc_new(w->window);
281 gdk_color_parse(strstr(uri, "https://") == uri ?
282 progress_trust : progress, &fg);
283 gdk_gc_set_rgb_fg_color(gc, &fg);
284 gdk_draw_rectangle(w->window,
285 w->style->bg_gc[GTK_WIDGET_STATE(w)],
286 TRUE, 0, 0, w->allocation.width, w->allocation.height);
287 gdk_draw_rectangle(w->window, gc, TRUE, 0, 0, width,
288 w->allocation.height);
293 exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c) {
299 find(Client *c, const Arg *arg) {
302 s = getatom(c, findprop);
303 gboolean forward = *(gboolean *)arg;
304 webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE);
308 getcookies(SoupURI *uri) {
310 SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, TRUE);
311 c = soup_cookie_jar_get_cookies(j, uri, TRUE);
317 getatom(Client *c, Atom a) {
318 static char buf[BUFSIZ];
321 unsigned long ldummy;
322 unsigned char *p = NULL;
324 XGetWindowProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window),
325 a, 0L, BUFSIZ, False, XA_STRING,
326 &adummy, &idummy, &ldummy, &ldummy, &p);
328 strncpy(buf, (char *)p, LENGTH(buf)-1);
339 if(!(uri = (char *)webkit_web_view_get_uri(c->view)))
345 gotheaders(SoupMessage *msg, gpointer v) {
349 uri = soup_message_get_uri(msg);
350 for(p = l = soup_cookies_from_response(msg); p;
351 p = g_slist_next(p)) {
352 setcookie((SoupCookie *)p->data);
354 soup_cookies_free(l);
358 initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
359 const char *filename;
361 WebKitWebBackForwardList *h;
362 WebKitWebHistoryItem *i;
365 filename = webkit_download_get_suggested_filename(o);
366 if(!strcmp("", filename))
367 filename = "index.html";
368 uri = g_strconcat("file://", dldir, "/", filename, NULL);
369 webkit_download_set_destination_uri(c->download, uri);
371 h = webkit_web_view_get_back_forward_list(c->view);
372 i = webkit_web_history_item_new_with_data(webkit_download_get_uri(c->download), filename);
373 webkit_web_back_forward_list_add_item(h, i);
374 g_signal_connect(c->download, "notify::progress", G_CALLBACK(updatedownload), c);
375 g_signal_connect(c->download, "notify::status", G_CALLBACK(updatedownload), c);
377 c->title = copystr(&c->title, filename);
383 itemclick(GtkMenuItem *mi, Client *c) {
387 label = gtk_menu_item_get_label(mi);
388 for(i = 0; i < LENGTH(items); i++)
389 if(!strcmp(items[i].label, label))
390 items[i].func(c, &(items[i].arg));
394 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
396 gboolean processed = FALSE;
399 for(i = 0; i < LENGTH(keys); i++) {
400 if(gdk_keyval_to_lower(ev->keyval) == keys[i].keyval
401 && CLEANMASK(ev->state) == keys[i].mod
403 keys[i].func(c, &(keys[i].arg));
411 linkhover(WebKitWebView *v, const char* t, const char* l, Client *c) {
413 c->linkhover = copystr(&c->linkhover, l);
414 else if(c->linkhover) {
422 loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
423 switch(webkit_web_view_get_load_status (c->view)) {
424 case WEBKIT_LOAD_COMMITTED:
427 setatom(c, uriprop, geturi(c));
429 case WEBKIT_LOAD_FINISHED:
439 loaduri(Client *c, const Arg *arg) {
441 const char *uri = (char *)arg->v;
442 Arg a = { .b = FALSE };
444 if(strcmp(uri, "") == 0)
446 u = g_strrstr(uri, "://") ? g_strdup(uri)
447 : g_strdup_printf("http://%s", uri);
448 /* prevents endless loop */
449 if(c->uri && strcmp(u, c->uri) == 0) {
453 webkit_web_view_load_uri(c->view, u);
455 c->title = copystr(&c->title, u);
462 navigate(Client *c, const Arg *arg) {
463 int steps = *(int *)arg;
464 webkit_web_view_go_back_or_forward(c->view, steps);
471 WebKitWebSettings *settings;
472 GdkGeometry hints = { 1, 1 };
475 if(!(c = calloc(1, sizeof(Client))))
476 die("Cannot malloc!\n");
479 c->win = gtk_plug_new(embed);
482 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
483 /* TA: 20091214: Despite what the GNOME docs say, the ICCCM
484 * is always correct, so we should still call this function.
485 * But when doing so, we *must* differentiate between a
486 * WM_CLASS and a resource on the window. By convention, the
487 * window class (WM_CLASS) is capped, while the resource is in
488 * lowercase. Both these values come as a pair.
490 gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf");
492 /* TA: 20091214: And set the role here as well -- so that
493 * sessions can pick this up.
495 gtk_window_set_role(GTK_WINDOW(c->win), "Surf");
497 gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
498 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
499 g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
500 g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c);
502 if(!(c->items = calloc(1, sizeof(GtkWidget *) * LENGTH(items))))
503 die("Cannot malloc!\n");
506 for(i = 0; i < LENGTH(items); i++) {
507 c->items[i] = gtk_menu_item_new_with_label(items[i].label);
508 g_signal_connect(G_OBJECT(c->items[i]), "activate",
509 G_CALLBACK(itemclick), c);
513 c->vbox = gtk_vbox_new(FALSE, 0);
515 /* Scrolled Window */
516 c->scroll = gtk_scrolled_window_new(NULL, NULL);
517 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll),
518 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
521 c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
522 g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
523 g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
524 g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(createwindow), c);
525 g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c);
526 g_signal_connect(G_OBJECT(c->view), "mime-type-policy-decision-requested", G_CALLBACK(decidedownload), c);
527 g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
528 g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c);
529 g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(context), c);
530 g_signal_connect(G_OBJECT(c->view), "notify::load-status", G_CALLBACK(loadstatuschange), c);
531 g_signal_connect(G_OBJECT(c->view), "notify::progress", G_CALLBACK(progresschange), c);
534 c->indicator = gtk_drawing_area_new();
535 gtk_widget_set_size_request(c->indicator, 0, 2);
536 g_signal_connect (G_OBJECT (c->indicator), "expose_event",
537 G_CALLBACK (exposeindicator), c);
540 gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
541 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
542 gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
543 gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
546 gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START);
547 gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
548 gtk_widget_grab_focus(GTK_WIDGET(c->view));
549 gtk_widget_show(c->vbox);
550 gtk_widget_show(c->indicator);
551 gtk_widget_show(c->scroll);
552 gtk_widget_show(GTK_WIDGET(c->view));
553 gtk_widget_show(c->win);
554 gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE);
555 gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK);
556 gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
557 webkit_web_view_set_full_content_zoom(c->view, TRUE);
558 settings = webkit_web_view_get_settings(c->view);
559 if(!(ua = getenv("SURF_USERAGENT")))
561 g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
562 uri = g_strconcat("file://", stylefile, NULL);
563 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
564 g_object_set(G_OBJECT(settings), "auto-load-images", loadimage, NULL);
565 g_object_set(G_OBJECT(settings), "enable-plugins", plugin, NULL);
566 g_object_set(G_OBJECT(settings), "enable-scripts", script, NULL);
568 setatom(c, findprop, "");
569 setatom(c, uriprop, "");
571 webkit_web_view_set_transparent(c->view, TRUE);
578 gdk_display_sync(gtk_widget_get_display(c->win));
579 printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
586 newrequest(SoupSession *s, SoupMessage *msg, gpointer v) {
587 SoupMessageHeaders *h = msg->request_headers;
591 soup_message_headers_remove(h, "Cookie");
592 uri = soup_message_get_uri(msg);
593 if((c = getcookies(uri)))
594 soup_message_headers_append(h, "Cookie", c);
595 g_signal_connect_after(G_OBJECT(msg), "got-headers", G_CALLBACK(gotheaders), NULL);
599 newwindow(Client *c, const Arg *arg) {
601 const char *cmd[10], *uri;
602 const Arg a = { .v = (void *)cmd };
608 snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed);
620 uri = arg->v ? (char *)arg->v : c->linkhover;
628 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {
629 Arg arg = {.v = text };
631 loaduri((Client *) d, &arg);
635 print(Client *c, const Arg *arg) {
636 webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
640 processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
641 Client *c = (Client *)d;
645 if(((XEvent *)e)->type == PropertyNotify) {
646 ev = &((XEvent *)e)->xproperty;
649 else if(ev->state == PropertyNewValue) {
650 if(ev->atom == uriprop) {
651 arg.v = getatom(c, uriprop);
654 else if(ev->atom == findprop) {
658 return GDK_FILTER_REMOVE;
661 return GDK_FILTER_CONTINUE;
665 progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
666 c->progress = webkit_web_view_get_progress(c->view) * 100;
671 reload(Client *c, const Arg *arg) {
672 gboolean nocache = *(gboolean *)arg;
674 webkit_web_view_reload_bypass_cache(c->view);
676 webkit_web_view_reload(c->view);
680 resize(GtkWidget *w, GtkAllocation *a, Client *c) {
685 zoom = webkit_web_view_get_zoom_level(c->view);
686 if(a->width * a->height < 300 * 400 && zoom != 0.2)
687 webkit_web_view_set_zoom_level(c->view, 0.2);
689 webkit_web_view_set_zoom_level(c->view, 1.0);
693 scroll(Client *c, const Arg *arg) {
697 a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll));
698 v = gtk_adjustment_get_value(a);
699 v += gtk_adjustment_get_step_increment(a) * arg->i;
701 v = MIN(v, gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a));
702 gtk_adjustment_set_value(a, v);
706 setcookie(SoupCookie *c) {
708 SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, FALSE);
709 c = soup_cookie_copy(c);
710 if(c->expires == NULL && sessiontime) {
711 e = soup_date_new_from_time_t(time(NULL) + sessiontime);
712 soup_cookie_set_expires(c, e);
714 soup_cookie_jar_add_cookie(j, c);
719 setatom(Client *c, Atom a, const char *v) {
722 XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), a,
723 XA_STRING, 8, PropModeReplace, (unsigned char *)v,
734 /* clean up any zombies immediately */
736 gtk_init(NULL, NULL);
737 if (!g_thread_supported())
741 s = webkit_get_default_session();
742 uriprop = XInternAtom(dpy, "_SURF_URI", False);
743 findprop = XInternAtom(dpy, "_SURF_FIND", False);
746 cookiefile = buildpath(cookiefile);
747 dldir = buildpath(dldir);
748 scriptfile = buildpath(scriptfile);
749 stylefile = buildpath(stylefile);
751 /* request handler */
752 s = webkit_get_default_session();
753 soup_session_remove_feature_by_type(s, soup_cookie_get_type());
754 soup_session_remove_feature_by_type(s, soup_cookie_jar_get_type());
755 g_signal_connect_after(G_OBJECT(s), "request-started", G_CALLBACK(newrequest), NULL);
758 if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
759 new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
760 g_strdup_printf("http://%s", proxy);
762 puri = soup_uri_new(new_proxy);
763 g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
770 sigchld(int unused) {
771 if(signal(SIGCHLD, sigchld) == SIG_ERR)
772 die("Can't install SIGCHLD handler");
773 while(0 < waitpid(-1, NULL, WNOHANG));
777 source(Client *c, const Arg *arg) {
778 Arg a = { .b = FALSE };
781 s = webkit_web_view_get_view_source_mode(c->view);
782 webkit_web_view_set_view_source_mode(c->view, !s);
787 spawn(Client *c, const Arg *arg) {
790 close(ConnectionNumber(dpy));
792 execvp(((char **)arg->v)[0], (char **)arg->v);
793 fprintf(stderr, "surf: execvp %s", ((char **)arg->v)[0]);
800 stop(Client *c, const Arg *arg) {
802 webkit_download_cancel(c->download);
804 webkit_web_view_stop_loading(c->view);
809 titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) {
810 c->title = copystr(&c->title, t);
818 if(c->progress != 100)
819 t = g_strdup_printf("[%i%%] %s", c->progress, c->title);
820 else if(c->linkhover)
821 t = g_strdup(c->linkhover);
823 t = g_strdup(c->title);
825 gtk_window_set_title(GTK_WINDOW(c->win), t);
830 updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c) {
831 WebKitDownloadStatus status;
833 status = webkit_download_get_status(c->download);
834 if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
835 c->progress = (gint)(webkit_download_get_progress(c->download)*100);
843 updatewinid(Client *c) {
844 snprintf(winid, LENGTH(winid), "%u",
845 (int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
850 fputs("surf - simple browser\n", stderr);
851 die("usage: surf [-e xid] [-i] [-p] [-s] [-v] [-x] [uri]\n");
855 windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) {
856 JSStringRef jsscript;
858 JSValueRef exception = NULL;
861 if(g_file_get_contents(scriptfile, &script, NULL, &error)) {
862 jsscript = JSStringCreateWithUTF8CString(script);
863 JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), NULL, 0, &exception);
868 zoom(Client *c, const Arg *arg) {
870 if(arg->i < 0) /* zoom out */
871 webkit_web_view_zoom_out(c->view);
872 else if(arg->i > 0) /* zoom in */
873 webkit_web_view_zoom_in(c->view);
876 webkit_web_view_set_zoom_level(c->view, 1.0);
881 main(int argc, char *argv[]) {
886 /* command line args */
887 for(i = 1, arg.v = NULL; i < argc && argv[i][0] == '-' &&
888 argv[i][1] != '\0' && argv[i][2] == '\0'; i++) {
889 if(!strcmp(argv[i], "--")) {
896 embed = atoi(argv[i]);
913 die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
923 loaduri(clients, &arg);