1 /* See LICENSE file for copyright and license details.
3 * To understand surf, start reading main().
21 #include <gdk/gdkkeysyms.h>
23 #include <glib/gstdio.h>
27 #include <JavaScriptCore/JavaScript.h>
28 #include <webkit2/webkit2.h>
30 #include <X11/Xatom.h>
34 #define LENGTH(x) (sizeof(x) / sizeof(x[0]))
35 #define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
36 #define SETB(p, s) [p] = { { .b = s }, }
37 #define SETI(p, s) [p] = { { .i = s }, }
38 #define SETV(p, s) [p] = { { .v = s }, }
39 #define SETF(p, s) [p] = { { .f = s }, }
40 #define FSETB(p, s) [p] = { { .b = s }, 1 }
41 #define FSETI(p, s) [p] = { { .i = s }, 1 }
42 #define FSETV(p, s) [p] = { { .v = s }, 1 }
43 #define FSETF(p, s) [p] = { { .f = s }, 1 }
44 #define CSETB(p, s) [p] = (Parameter){ { .b = s }, 1 }
45 #define CSETI(p, s) [p] = (Parameter){ { .i = s }, 1 }
46 #define CSETV(p, s) [p] = (Parameter){ { .v = s }, 1 }
47 #define CSETF(p, s) [p] = (Parameter){ { .f = s }, 1 }
49 enum { AtomFind, AtomGo, AtomUri, AtomLast };
52 OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
53 OnLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
54 OnImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
55 OnMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
56 OnEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
57 OnBar = WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR,
58 OnSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
59 OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
109 typedef struct Client {
112 WebKitWebInspector *inspector;
113 WebKitFindController *finder;
114 WebKitHitTestResult *mousepos;
115 GTlsCertificate *cert, *failedcert;
116 GTlsCertificateFlags tlserr;
118 int progress, fullscreen, https, insecure, errorpage;
119 const char *title, *overtitle, *targeturi;
127 void (*func)(Client *c, const Arg *a);
135 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
137 unsigned int stopevent;
142 Parameter config[ParameterLast];
153 static void usage(void);
154 static void die(const char *errstr, ...);
155 static void setup(void);
156 static void sigchld(int unused);
157 static void sighup(int unused);
158 static char *buildfile(const char *path);
159 static char *buildpath(const char *path);
160 static const char *getuserhomedir(const char *user);
161 static const char *getcurrentuserhomedir(void);
162 static Client *newclient(Client *c);
163 static void loaduri(Client *c, const Arg *a);
164 static const char *geturi(Client *c);
165 static void setatom(Client *c, int a, const char *v);
166 static const char *getatom(Client *c, int a);
167 static void updatetitle(Client *c);
168 static void gettogglestats(Client *c);
169 static void getpagestats(Client *c);
170 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
171 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
172 static void seturiparameters(Client *c, const char *uri, ParamName *params);
173 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
174 static const char *getcert(const char *uri);
175 static void setcert(Client *c, const char *file);
176 static const char *getstyle(const char *uri);
177 static void setstyle(Client *c, const char *file);
178 static void runscript(Client *c);
179 static void evalscript(Client *c, const char *jsstr, ...);
180 static void updatewinid(Client *c);
181 static void handleplumb(Client *c, const char *uri);
182 static void newwindow(Client *c, const Arg *a, int noembed);
183 static void spawn(Client *c, const Arg *a);
184 static void destroyclient(Client *c);
185 static void cleanup(void);
188 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
189 static void initwebextensions(WebKitWebContext *wc, Client *c);
190 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
192 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
193 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
195 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
196 static void showview(WebKitWebView *v, Client *c);
197 static GtkWidget *createwindow(Client *c);
198 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
199 GTlsCertificate *cert,
200 GTlsCertificateFlags err, Client *c);
201 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
202 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
203 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
204 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
205 guint modifiers, Client *c);
206 static gboolean permissionrequested(WebKitWebView *v,
207 WebKitPermissionRequest *r, Client *c);
208 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
209 WebKitPolicyDecisionType dt, Client *c);
210 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
211 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
212 static void decideresource(WebKitPolicyDecision *d, Client *c);
213 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
215 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
217 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
218 static void download(Client *c, WebKitURIResponse *r);
219 static void closeview(WebKitWebView *v, Client *c);
220 static void destroywin(GtkWidget* w, Client *c);
223 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
224 static void reload(Client *c, const Arg *a);
225 static void print(Client *c, const Arg *a);
226 static void showcert(Client *c, const Arg *a);
227 static void clipboard(Client *c, const Arg *a);
228 static void zoom(Client *c, const Arg *a);
229 static void scroll(Client *c, const Arg *a);
230 static void navigate(Client *c, const Arg *a);
231 static void stop(Client *c, const Arg *a);
232 static void toggle(Client *c, const Arg *a);
233 static void togglefullscreen(Client *c, const Arg *a);
234 static void togglecookiepolicy(Client *c, const Arg *a);
235 static void toggleinspector(Client *c, const Arg *a);
236 static void find(Client *c, const Arg *a);
239 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
240 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
241 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
243 static char winid[64];
244 static char togglestats[12];
245 static char pagestats[2];
246 static Atom atoms[AtomLast];
249 static int cookiepolicy;
251 static Client *clients;
252 static GdkDevice *gdkkb;
253 static char *stylefile;
254 static const char *useragent;
255 static Parameter *curconfig;
258 static ParamName loadtransient[] = {
272 static ParamName loadcommitted[] = {
298 static ParamName loadfinished[] = {
302 /* configuration, allows nested code to access above variables */
308 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
309 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
310 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
314 die(const char *errstr, ...)
318 va_start(ap, errstr);
319 vfprintf(stderr, errstr, ap);
330 /* clean up any zombies immediately */
332 if (signal(SIGHUP, sighup) == SIG_ERR)
333 die("Can't install SIGHUP handler");
335 if (!(dpy = XOpenDisplay(NULL)))
336 die("Can't open default display");
339 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
340 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
341 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
343 gtk_init(NULL, NULL);
345 gdpy = gdk_display_get_default();
347 curconfig = defconfig;
350 cookiefile = buildfile(cookiefile);
351 scriptfile = buildfile(scriptfile);
352 cachedir = buildpath(cachedir);
353 certdir = buildpath(certdir);
355 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
357 for (i = 0; i < LENGTH(certs); ++i) {
358 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
359 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
362 fprintf(stderr, "Could not compile regex: %s\n",
364 certs[i].regex = NULL;
369 styledir = buildpath(styledir);
370 for (i = 0; i < LENGTH(styles); ++i) {
371 if (!regcomp(&(styles[i].re), styles[i].regex,
373 styles[i].file = g_strconcat(styledir, "/",
374 styles[i].file, NULL);
376 fprintf(stderr, "Could not compile regex: %s\n",
378 styles[i].regex = NULL;
383 stylefile = buildfile(stylefile);
386 for (i = 0; i < LENGTH(uriparams); ++i) {
387 if (!regcomp(&(uriparams[i].re), uriparams[i].uri,
389 /* copy default parameters if they are not already set
390 * or if they are forced */
391 for (j = 0; j < ParameterLast; ++j) {
392 if (!uriparams[i].config[j].force ||
394 uriparams[i].config[j] = defconfig[j];
397 fprintf(stderr, "Could not compile regex: %s\n",
399 uriparams[i].uri = NULL;
407 if (signal(SIGCHLD, sigchld) == SIG_ERR)
408 die("Can't install SIGCHLD handler");
409 while (waitpid(-1, NULL, WNOHANG) > 0)
419 for (c = clients; c; c = c->next)
424 buildfile(const char *path)
426 char *dname, *bname, *bpath, *fpath;
429 dname = g_path_get_dirname(path);
430 bname = g_path_get_basename(path);
432 bpath = buildpath(dname);
435 fpath = g_build_filename(bpath, bname, NULL);
439 if (!(f = fopen(fpath, "a")))
440 die("Could not open file: %s\n", fpath);
442 g_chmod(fpath, 0600); /* always */
449 getuserhomedir(const char *user)
451 struct passwd *pw = getpwnam(user);
454 die("Can't get user %s login information.\n", user);
460 getcurrentuserhomedir(void)
466 homedir = getenv("HOME");
470 user = getenv("USER");
472 return getuserhomedir(user);
474 pw = getpwuid(getuid());
476 die("Can't get current user home directory\n");
482 buildpath(const char *path)
484 char *apath, *name, *p, *fpath;
487 if (path[0] == '~') {
488 if (path[1] == '/' || path[1] == '\0') {
489 p = (char *)&path[1];
490 homedir = getcurrentuserhomedir();
492 if ((p = strchr(path, '/')))
493 name = g_strndup(&path[1], --p - path);
495 name = g_strdup(&path[1]);
497 homedir = getuserhomedir(name);
500 apath = g_build_filename(homedir, p, NULL);
502 apath = g_strdup(path);
505 /* creating directory */
506 if (g_mkdir_with_parents(apath, 0700) < 0)
507 die("Could not access directory: %s\n", apath);
509 fpath = realpath(apath, NULL);
516 newclient(Client *rc)
520 if (!(c = calloc(1, sizeof(Client))))
521 die("Cannot malloc!\n");
527 c->view = newview(c, rc ? rc->view : NULL);
533 loaduri(Client *c, const Arg *a)
537 const char *uri = a->v;
539 if (g_strcmp0(uri, "") == 0)
542 if (g_str_has_prefix(uri, "http://") ||
543 g_str_has_prefix(uri, "https://") ||
544 g_str_has_prefix(uri, "file://") ||
545 g_str_has_prefix(uri, "about:")) {
547 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
548 url = g_strdup_printf("file://%s", path);
551 url = g_strdup_printf("http://%s", uri);
554 setatom(c, AtomUri, url);
556 if (strcmp(url, geturi(c)) == 0) {
559 webkit_web_view_load_uri(c->view, url);
571 if (!(uri = webkit_web_view_get_uri(c->view)))
577 setatom(Client *c, int a, const char *v)
579 XChangeProperty(dpy, c->xid,
580 atoms[a], XA_STRING, 8, PropModeReplace,
581 (unsigned char *)v, strlen(v) + 1);
586 getatom(Client *c, int a)
588 static char buf[BUFSIZ];
591 unsigned long ldummy;
592 unsigned char *p = NULL;
595 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
596 &adummy, &idummy, &ldummy, &ldummy, &p);
598 strncpy(buf, (char *)p, LENGTH(buf) - 1);
607 updatetitle(Client *c)
610 const char *name = c->overtitle ? c->overtitle :
611 c->title ? c->title : "";
613 if (curconfig[ShowIndicators].val.i) {
617 if (c->progress != 100)
618 title = g_strdup_printf("[%i%%] %s:%s | %s",
619 c->progress, togglestats, pagestats, name);
621 title = g_strdup_printf("%s:%s | %s",
622 togglestats, pagestats, name);
624 gtk_window_set_title(GTK_WINDOW(c->win), title);
627 gtk_window_set_title(GTK_WINDOW(c->win), name);
632 gettogglestats(Client *c)
634 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
635 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
636 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
637 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
638 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
639 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
640 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
641 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
642 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
643 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
644 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
645 togglestats[11] = '\0';
649 getpagestats(Client *c)
652 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
658 WebKitCookieAcceptPolicy
659 cookiepolicy_get(void)
661 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
663 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
665 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
666 default: /* fallthrough */
668 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
673 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
676 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
678 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
680 default: /* fallthrough */
681 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
687 seturiparameters(Client *c, const char *uri, ParamName *params)
689 Parameter *config, *newconfig = NULL;
692 for (i = 0; i < LENGTH(uriparams); ++i) {
693 if (uriparams[i].uri &&
694 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
695 newconfig = uriparams[i].config;
701 newconfig = defconfig;
703 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
708 config = defconfig[p].force ? defconfig :
709 newconfig[p].force ? newconfig :
713 if (defconfig[p].force)
715 config = newconfig[p].force ? newconfig :
716 curconfig[p].force ? defconfig :
721 setparameter(c, 0, p, &config[p].val);
724 curconfig = newconfig;
728 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
730 GdkRGBA bgcolor = { 0 };
731 WebKitSettings *s = webkit_web_view_get_settings(c->view);
734 case AcceleratedCanvas:
735 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
737 case AccessMicrophone:
738 return; /* do nothing */
740 return; /* do nothing */
742 webkit_settings_set_enable_caret_browsing(s, a->i);
747 setcert(c, geturi(c));
748 return; /* do not update */
750 webkit_cookie_manager_set_accept_policy(
751 webkit_web_context_get_cookie_manager(
752 webkit_web_view_get_context(c->view)),
757 webkit_web_context_set_cache_model(
758 webkit_web_view_get_context(c->view), a->i ?
759 WEBKIT_CACHE_MODEL_WEB_BROWSER :
760 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
761 return; /* do not update */
763 webkit_settings_set_default_charset(s, a->v);
764 return; /* do not update */
766 webkit_settings_set_enable_dns_prefetching(s, a->i);
767 return; /* do not update */
768 case FileURLsCrossAccess:
769 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
770 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
771 return; /* do not update */
773 webkit_settings_set_default_font_size(s, a->i);
774 return; /* do not update */
775 case FrameFlattening:
776 webkit_settings_set_enable_frame_flattening(s, a->i);
783 webkit_web_view_set_background_color(c->view, &bgcolor);
784 return; /* do not update */
786 webkit_settings_set_enable_developer_extras(s, a->i);
787 return; /* do not update */
789 webkit_settings_set_enable_java(s, a->i);
790 return; /* do not update */
792 webkit_settings_set_enable_javascript(s, a->i);
795 return; /* do nothing */
797 webkit_settings_set_auto_load_images(s, a->i);
799 case MediaManualPlay:
800 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
803 webkit_settings_set_enable_plugins(s, a->i);
805 case PreferredLanguages:
806 return; /* do nothing */
807 case RunInFullscreen:
808 return; /* do nothing */
810 /* Disabled until we write some WebKitWebExtension for
811 * manipulating the DOM directly.
812 enablescrollbars = !enablescrollbars;
813 evalscript(c, "document.documentElement.style.overflow = '%s'",
814 enablescrollbars ? "auto" : "hidden");
816 return; /* do not update */
819 case SmoothScrolling:
820 webkit_settings_set_enable_smooth_scrolling(s, a->i);
821 return; /* do not update */
823 webkit_settings_set_enable_site_specific_quirks(s, a->i);
826 webkit_web_context_set_spell_checking_enabled(
827 webkit_web_view_get_context(c->view), a->i);
828 return; /* do not update */
830 return; /* do nothing */
832 webkit_web_context_set_tls_errors_policy(
833 webkit_web_view_get_context(c->view), a->i ?
834 WEBKIT_TLS_ERRORS_POLICY_FAIL :
835 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
838 webkit_user_content_manager_remove_all_style_sheets(
839 webkit_web_view_get_user_content_manager(c->view));
841 setstyle(c, getstyle(geturi(c)));
845 webkit_web_view_set_zoom_level(c->view, a->f);
846 return; /* do not update */
848 return; /* do nothing */
857 getcert(const char *uri)
861 for (i = 0; i < LENGTH(certs); ++i) {
862 if (certs[i].regex &&
863 !regexec(&(certs[i].re), uri, 0, NULL, 0))
864 return certs[i].file;
871 setcert(Client *c, const char *uri)
873 const char *file = getcert(uri);
875 GTlsCertificate *cert;
880 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
881 fprintf(stderr, "Could not read certificate file: %s\n", file);
885 if ((uri = strstr(uri, "https://"))) {
886 uri += sizeof("https://") - 1;
887 host = g_strndup(uri, strchr(uri, '/') - uri);
888 webkit_web_context_allow_tls_certificate_for_host(
889 webkit_web_view_get_context(c->view), cert, host);
893 g_object_unref(cert);
898 getstyle(const char *uri)
905 for (i = 0; i < LENGTH(styles); ++i) {
906 if (styles[i].regex &&
907 !regexec(&(styles[i].re), uri, 0, NULL, 0))
908 return styles[i].file;
915 setstyle(Client *c, const char *file)
919 if (!g_file_get_contents(file, &style, NULL, NULL)) {
920 fprintf(stderr, "Could not read style file: %s\n", file);
924 webkit_user_content_manager_add_style_sheet(
925 webkit_web_view_get_user_content_manager(c->view),
926 webkit_user_style_sheet_new(style,
927 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
928 WEBKIT_USER_STYLE_LEVEL_USER,
940 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
941 evalscript(c, script);
946 evalscript(Client *c, const char *jsstr, ...)
952 script = g_strdup_vprintf(jsstr, ap);
955 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
960 updatewinid(Client *c)
962 snprintf(winid, LENGTH(winid), "%lu", c->xid);
966 handleplumb(Client *c, const char *uri)
968 Arg a = (Arg)PLUMB(uri);
973 newwindow(Client *c, const Arg *a, int noembed)
977 const char *cmd[29], *uri;
978 const Arg arg = { .v = cmd };
982 cmd[i++] = curconfig[CookiePolicies].val.v;
983 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
984 if (cookiefile && g_strcmp0(cookiefile, "")) {
986 cmd[i++] = cookiefile;
988 if (stylefile && g_strcmp0(stylefile, "")) {
990 cmd[i++] = stylefile;
992 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
993 if (embed && !noembed) {
995 snprintf(tmp, LENGTH(tmp), "%lu", embed);
998 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
999 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
1000 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
1001 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
1002 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
1003 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
1004 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
1005 if (scriptfile && g_strcmp0(scriptfile, "")) {
1007 cmd[i++] = scriptfile;
1009 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
1010 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
1011 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
1013 cmd[i++] = fulluseragent;
1017 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1018 /* do not keep zoom level */
1028 spawn(Client *c, const Arg *a)
1032 close(ConnectionNumber(dpy));
1034 execvp(((char **)a->v)[0], (char **)a->v);
1035 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1042 destroyclient(Client *c)
1046 webkit_web_view_stop_loading(c->view);
1047 /* Not needed, has already been called
1048 gtk_widget_destroy(c->win);
1051 for (p = clients; p && p->next != c; p = p->next)
1064 destroyclient(clients);
1073 newview(Client *c, WebKitWebView *rv)
1076 WebKitSettings *settings;
1077 WebKitUserContentManager *contentmanager;
1078 WebKitWebContext *context;
1082 v = WEBKIT_WEB_VIEW(
1083 webkit_web_view_new_with_related_view(rv));
1085 settings = webkit_settings_new_with_settings(
1086 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1087 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1088 "auto-load-images", curconfig[LoadImages].val.i,
1089 "default-charset", curconfig[DefaultCharset].val.v,
1090 "default-font-size", curconfig[FontSize].val.i,
1091 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1092 "enable-developer-extras", curconfig[Inspector].val.i,
1093 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1094 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1095 "enable-html5-database", curconfig[DiskCache].val.i,
1096 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1097 "enable-java", curconfig[Java].val.i,
1098 "enable-javascript", curconfig[JavaScript].val.i,
1099 "enable-plugins", curconfig[Plugins].val.i,
1100 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1101 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1102 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1103 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1105 /* For more interesting settings, have a look at
1106 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1108 if (strcmp(fulluseragent, "")) {
1109 webkit_settings_set_user_agent(settings, fulluseragent);
1110 } else if (surfuseragent) {
1111 webkit_settings_set_user_agent_with_application_details(
1112 settings, "Surf", VERSION);
1114 useragent = webkit_settings_get_user_agent(settings);
1116 contentmanager = webkit_user_content_manager_new();
1118 context = webkit_web_context_new_with_website_data_manager(
1119 webkit_website_data_manager_new(
1120 "base-cache-directory", cachedir,
1121 "base-data-directory", cachedir,
1124 /* rendering process model, can be a shared unique one
1125 * or one for each view */
1126 webkit_web_context_set_process_model(context,
1127 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1129 webkit_web_context_set_tls_errors_policy(context,
1130 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1131 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1133 webkit_web_context_set_cache_model(context,
1134 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1135 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1137 /* Currently only works with text file to be compatible with curl */
1138 webkit_cookie_manager_set_persistent_storage(
1139 webkit_web_context_get_cookie_manager(context), cookiefile,
1140 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1142 webkit_cookie_manager_set_accept_policy(
1143 webkit_web_context_get_cookie_manager(context),
1144 cookiepolicy_get());
1146 webkit_web_context_set_preferred_languages(context,
1147 curconfig[PreferredLanguages].val.v);
1148 webkit_web_context_set_spell_checking_languages(context,
1149 curconfig[SpellLanguages].val.v);
1150 webkit_web_context_set_spell_checking_enabled(context,
1151 curconfig[SpellChecking].val.i);
1153 g_signal_connect(G_OBJECT(context), "download-started",
1154 G_CALLBACK(downloadstarted), c);
1155 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1156 G_CALLBACK(initwebextensions), c);
1158 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1159 "settings", settings,
1160 "user-content-manager", contentmanager,
1161 "web-context", context,
1165 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1166 G_CALLBACK(progresschanged), c);
1167 g_signal_connect(G_OBJECT(v), "notify::title",
1168 G_CALLBACK(titlechanged), c);
1169 g_signal_connect(G_OBJECT(v), "button-release-event",
1170 G_CALLBACK(buttonreleased), c);
1171 g_signal_connect(G_OBJECT(v), "close",
1172 G_CALLBACK(closeview), c);
1173 g_signal_connect(G_OBJECT(v), "create",
1174 G_CALLBACK(createview), c);
1175 g_signal_connect(G_OBJECT(v), "decide-policy",
1176 G_CALLBACK(decidepolicy), c);
1177 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1178 G_CALLBACK(insecurecontent), c);
1179 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1180 G_CALLBACK(loadfailedtls), c);
1181 g_signal_connect(G_OBJECT(v), "load-changed",
1182 G_CALLBACK(loadchanged), c);
1183 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1184 G_CALLBACK(mousetargetchanged), c);
1185 g_signal_connect(G_OBJECT(v), "permission-request",
1186 G_CALLBACK(permissionrequested), c);
1187 g_signal_connect(G_OBJECT(v), "ready-to-show",
1188 G_CALLBACK(showview), c);
1194 initwebextensions(WebKitWebContext *wc, Client *c)
1196 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1200 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1204 switch (webkit_navigation_action_get_navigation_type(a)) {
1205 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1207 * popup windows of type “other” are almost always triggered
1208 * by user gesture, so inverse the logic here
1210 /* instead of this, compare destination uri to mouse-over uri for validating window */
1211 if (webkit_navigation_action_is_user_gesture(a))
1213 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1214 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1215 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1216 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1217 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1224 return GTK_WIDGET(n->view);
1228 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1230 WebKitHitTestResultContext element;
1233 element = webkit_hit_test_result_get_context(c->mousepos);
1235 for (i = 0; i < LENGTH(buttons); ++i) {
1236 if (element & buttons[i].target &&
1237 e->button.button == buttons[i].button &&
1238 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1240 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1241 return buttons[i].stopevent;
1249 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1251 Client *c = (Client *)d;
1255 if (((XEvent *)e)->type == PropertyNotify) {
1256 ev = &((XEvent *)e)->xproperty;
1257 if (ev->state == PropertyNewValue) {
1258 if (ev->atom == atoms[AtomFind]) {
1261 return GDK_FILTER_REMOVE;
1262 } else if (ev->atom == atoms[AtomGo]) {
1263 a.v = getatom(c, AtomGo);
1266 return GDK_FILTER_REMOVE;
1270 return GDK_FILTER_CONTINUE;
1274 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1279 case GDK_ENTER_NOTIFY:
1280 c->overtitle = c->targeturi;
1284 if (!curconfig[KioskMode].val.i) {
1285 for (i = 0; i < LENGTH(keys); ++i) {
1286 if (gdk_keyval_to_lower(e->key.keyval) ==
1288 CLEANMASK(e->key.state) == keys[i].mod &&
1291 keys[i].func(c, &(keys[i].arg));
1296 case GDK_LEAVE_NOTIFY:
1297 c->overtitle = NULL;
1300 case GDK_WINDOW_STATE:
1301 if (e->window_state.changed_mask ==
1302 GDK_WINDOW_STATE_FULLSCREEN)
1303 c->fullscreen = e->window_state.new_window_state &
1304 GDK_WINDOW_STATE_FULLSCREEN;
1314 showview(WebKitWebView *v, Client *c)
1316 GdkRGBA bgcolor = { 0 };
1319 c->finder = webkit_web_view_get_find_controller(c->view);
1320 c->inspector = webkit_web_view_get_inspector(c->view);
1322 c->win = createwindow(c);
1324 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1325 gtk_widget_show_all(c->win);
1326 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1328 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1329 c->xid = gdk_x11_window_get_xid(gwin);
1332 gdk_display_sync(gtk_widget_get_display(c->win));
1336 if (curconfig[HideBackground].val.i)
1337 webkit_web_view_set_background_color(c->view, &bgcolor);
1339 if (!curconfig[KioskMode].val.i) {
1340 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1341 gdk_window_add_filter(gwin, processx, c);
1344 if (curconfig[RunInFullscreen].val.i)
1345 togglefullscreen(c, NULL);
1347 if (curconfig[ZoomLevel].val.f != 1.0)
1348 webkit_web_view_set_zoom_level(c->view,
1349 curconfig[ZoomLevel].val.f);
1351 setatom(c, AtomFind, "");
1352 setatom(c, AtomUri, "about:blank");
1356 createwindow(Client *c)
1362 w = gtk_plug_new(embed);
1364 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1366 wmstr = g_path_get_basename(argv0);
1367 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1370 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1371 webkit_web_view_get_page_id(c->view));
1372 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1375 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1378 g_signal_connect(G_OBJECT(w), "destroy",
1379 G_CALLBACK(destroywin), c);
1380 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1381 G_CALLBACK(winevent), c);
1382 g_signal_connect(G_OBJECT(w), "key-press-event",
1383 G_CALLBACK(winevent), c);
1384 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1385 G_CALLBACK(winevent), c);
1386 g_signal_connect(G_OBJECT(w), "window-state-event",
1387 G_CALLBACK(winevent), c);
1393 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1394 GTlsCertificateFlags err, Client *c)
1396 GString *errmsg = g_string_new(NULL);
1399 c->failedcert = g_object_ref(cert);
1403 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1404 g_string_append(errmsg,
1405 "The signing certificate authority is not known.<br>");
1406 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1407 g_string_append(errmsg,
1408 "The certificate does not match the expected identity "
1409 "of the site that it was retrieved from.<br>");
1410 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1411 g_string_append(errmsg,
1412 "The certificate's activation time "
1413 "is still in the future.<br>");
1414 if (err & G_TLS_CERTIFICATE_EXPIRED)
1415 g_string_append(errmsg, "The certificate has expired.<br>");
1416 if (err & G_TLS_CERTIFICATE_REVOKED)
1417 g_string_append(errmsg,
1418 "The certificate has been revoked according to "
1419 "the GTlsConnection's certificate revocation list.<br>");
1420 if (err & G_TLS_CERTIFICATE_INSECURE)
1421 g_string_append(errmsg,
1422 "The certificate's algorithm is considered insecure.<br>");
1423 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1424 g_string_append(errmsg,
1425 "Some error occurred validating the certificate.<br>");
1427 g_object_get(cert, "certificate-pem", &pem, NULL);
1428 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1429 "<p>You can inspect the following certificate "
1430 "with Ctrl-t (default keybinding).</p>"
1431 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1433 g_string_free(errmsg, TRUE);
1435 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1442 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1444 const char *uri = geturi(c);
1447 case WEBKIT_LOAD_STARTED:
1448 setatom(c, AtomUri, uri);
1450 c->https = c->insecure = 0;
1451 seturiparameters(c, uri, loadtransient);
1455 g_clear_object(&c->failedcert);
1457 case WEBKIT_LOAD_REDIRECTED:
1458 setatom(c, AtomUri, uri);
1460 seturiparameters(c, uri, loadtransient);
1462 case WEBKIT_LOAD_COMMITTED:
1463 seturiparameters(c, uri, loadcommitted);
1464 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1467 case WEBKIT_LOAD_FINISHED:
1468 seturiparameters(c, uri, loadfinished);
1469 /* Disabled until we write some WebKitWebExtension for
1470 * manipulating the DOM directly.
1471 evalscript(c, "document.documentElement.style.overflow = '%s'",
1472 enablescrollbars ? "auto" : "hidden");
1481 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1483 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1489 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1491 c->title = webkit_web_view_get_title(c->view);
1496 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1499 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1501 /* Keep the hit test to know where is the pointer on the next click */
1505 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1506 else if (hc & OnImg)
1507 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1508 else if (hc & OnMedia)
1509 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1511 c->targeturi = NULL;
1513 c->overtitle = c->targeturi;
1518 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1520 ParamName param = ParameterLast;
1522 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1523 param = Geolocation;
1524 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1525 if (webkit_user_media_permission_is_for_audio_device(
1526 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1527 param = AccessMicrophone;
1528 else if (webkit_user_media_permission_is_for_video_device(
1529 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1530 param = AccessWebcam;
1535 if (curconfig[param].val.i)
1536 webkit_permission_request_allow(r);
1538 webkit_permission_request_deny(r);
1544 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1545 WebKitPolicyDecisionType dt, Client *c)
1548 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1549 decidenavigation(d, c);
1551 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1552 decidenewwindow(d, c);
1554 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1555 decideresource(d, c);
1558 webkit_policy_decision_ignore(d);
1565 decidenavigation(WebKitPolicyDecision *d, Client *c)
1567 WebKitNavigationAction *a =
1568 webkit_navigation_policy_decision_get_navigation_action(
1569 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1571 switch (webkit_navigation_action_get_navigation_type(a)) {
1572 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1573 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1574 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1575 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1576 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1577 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1579 /* Do not navigate to links with a "_blank" target (popup) */
1580 if (webkit_navigation_policy_decision_get_frame_name(
1581 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1582 webkit_policy_decision_ignore(d);
1584 /* Filter out navigation to different domain ? */
1585 /* get action→urirequest, copy and load in new window+view
1586 * on Ctrl+Click ? */
1587 webkit_policy_decision_use(d);
1594 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1597 WebKitNavigationAction *a =
1598 webkit_navigation_policy_decision_get_navigation_action(
1599 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1602 switch (webkit_navigation_action_get_navigation_type(a)) {
1603 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1604 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1605 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1606 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1607 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1608 /* Filter domains here */
1609 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1610 * test for link clicked but no button ? */
1611 arg.v = webkit_uri_request_get_uri(
1612 webkit_navigation_action_get_request(a));
1613 newwindow(c, &arg, 0);
1615 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1620 webkit_policy_decision_ignore(d);
1624 decideresource(WebKitPolicyDecision *d, Client *c)
1627 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1628 WebKitURIResponse *res =
1629 webkit_response_policy_decision_get_response(r);
1630 const gchar *uri = webkit_uri_response_get_uri(res);
1632 if (g_str_has_suffix(uri, "/favicon.ico")) {
1633 webkit_policy_decision_ignore(d);
1637 if (!g_str_has_prefix(uri, "http://")
1638 && !g_str_has_prefix(uri, "https://")
1639 && !g_str_has_prefix(uri, "about:")
1640 && !g_str_has_prefix(uri, "file://")
1641 && !g_str_has_prefix(uri, "data:")
1642 && !g_str_has_prefix(uri, "blob:")
1643 && strlen(uri) > 0) {
1644 for (i = 0; i < strlen(uri); i++) {
1645 if (!g_ascii_isprint(uri[i])) {
1651 handleplumb(c, uri);
1652 webkit_policy_decision_ignore(d);
1657 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1658 webkit_policy_decision_use(d);
1660 webkit_policy_decision_ignore(d);
1666 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1672 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1674 g_signal_connect(G_OBJECT(d), "notify::response",
1675 G_CALLBACK(responsereceived), c);
1679 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1681 download(c, webkit_download_get_response(d));
1682 webkit_download_cancel(d);
1686 download(Client *c, WebKitURIResponse *r)
1688 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1693 closeview(WebKitWebView *v, Client *c)
1695 gtk_widget_destroy(c->win);
1699 destroywin(GtkWidget* w, Client *c)
1707 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1709 Arg a = {.v = text };
1711 loaduri((Client *) d, &a);
1715 reload(Client *c, const Arg *a)
1718 webkit_web_view_reload_bypass_cache(c->view);
1720 webkit_web_view_reload(c->view);
1724 print(Client *c, const Arg *a)
1726 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1727 GTK_WINDOW(c->win));
1731 showcert(Client *c, const Arg *a)
1733 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1734 GcrCertificate *gcrt;
1737 GcrCertificateWidget *wcert;
1742 g_object_get(cert, "certificate", &crt, NULL);
1743 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1744 g_byte_array_unref(crt);
1746 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1747 wcert = gcr_certificate_widget_new(gcrt);
1748 g_object_unref(gcrt);
1750 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1751 gtk_widget_show_all(win);
1755 clipboard(Client *c, const Arg *a)
1757 if (a->i) { /* load clipboard uri */
1758 gtk_clipboard_request_text(gtk_clipboard_get(
1759 GDK_SELECTION_PRIMARY),
1761 } else { /* copy uri */
1762 gtk_clipboard_set_text(gtk_clipboard_get(
1763 GDK_SELECTION_PRIMARY), c->targeturi
1764 ? c->targeturi : geturi(c), -1);
1769 zoom(Client *c, const Arg *a)
1772 webkit_web_view_set_zoom_level(c->view,
1773 curconfig[ZoomLevel].val.f + 0.1);
1775 webkit_web_view_set_zoom_level(c->view,
1776 curconfig[ZoomLevel].val.f - 0.1);
1778 webkit_web_view_set_zoom_level(c->view, 1.0);
1780 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1784 scroll(Client *c, const Arg *a)
1786 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1788 gdk_event_set_device(ev, gdkkb);
1789 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1790 ev->key.state = GDK_CONTROL_MASK;
1791 ev->key.time = GDK_CURRENT_TIME;
1795 ev->key.keyval = GDK_KEY_Down;
1798 ev->key.keyval = GDK_KEY_Page_Down;
1801 ev->key.keyval = GDK_KEY_Left;
1804 ev->key.keyval = GDK_KEY_Right;
1807 ev->key.keyval = GDK_KEY_Page_Up;
1810 ev->key.keyval = GDK_KEY_Up;
1818 navigate(Client *c, const Arg *a)
1821 webkit_web_view_go_back(c->view);
1823 webkit_web_view_go_forward(c->view);
1827 stop(Client *c, const Arg *a)
1829 webkit_web_view_stop_loading(c->view);
1833 toggle(Client *c, const Arg *a)
1835 curconfig[a->i].val.i ^= 1;
1836 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1840 togglefullscreen(Client *c, const Arg *a)
1842 /* toggling value is handled in winevent() */
1844 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1846 gtk_window_fullscreen(GTK_WINDOW(c->win));
1850 togglecookiepolicy(Client *c, const Arg *a)
1853 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1855 setparameter(c, 0, CookiePolicies, NULL);
1859 toggleinspector(Client *c, const Arg *a)
1861 if (webkit_web_inspector_is_attached(c->inspector))
1862 webkit_web_inspector_close(c->inspector);
1863 else if (curconfig[Inspector].val.i)
1864 webkit_web_inspector_show(c->inspector);
1868 find(Client *c, const Arg *a)
1874 webkit_find_controller_search_next(c->finder);
1876 webkit_find_controller_search_previous(c->finder);
1878 s = getatom(c, AtomFind);
1879 f = webkit_find_controller_get_search_text(c->finder);
1881 if (g_strcmp0(f, s) == 0) /* reset search */
1882 webkit_find_controller_search(c->finder, "", findopts,
1885 webkit_find_controller_search(c->finder, s, findopts,
1888 if (strcmp(s, "") == 0)
1889 webkit_find_controller_search_finish(c->finder);
1894 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1900 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1904 arg.v = webkit_hit_test_result_get_link_uri(h);
1905 newwindow(c, &arg, a->i);
1909 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1913 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1918 main(int argc, char *argv[])
1923 memset(&arg, 0, sizeof(arg));
1925 /* command line args */
1928 defconfig CSETV(CookiePolicies, EARGF(usage()));
1931 defconfig CSETB(ScrollBars, 0);
1934 defconfig CSETB(ScrollBars, 1);
1937 cookiefile = EARGF(usage());
1940 stylefile = EARGF(usage());
1943 defconfig CSETB(DiskCache, 0);
1946 defconfig CSETB(DiskCache, 1);
1949 embed = strtol(EARGF(usage()), NULL, 0);
1952 defconfig CSETB(RunInFullscreen, 0);
1955 defconfig CSETB(RunInFullscreen, 1);
1958 defconfig CSETB(Geolocation, 0);
1961 defconfig CSETB(Geolocation, 1);
1964 defconfig CSETB(LoadImages, 0);
1967 defconfig CSETB(LoadImages, 1);
1970 defconfig CSETB(KioskMode, 0);
1973 defconfig CSETB(KioskMode, 1);
1976 defconfig CSETB(Style, 0);
1979 defconfig CSETB(Style, 1);
1982 defconfig CSETB(Inspector, 0);
1985 defconfig CSETB(Inspector, 1);
1988 defconfig CSETB(Plugins, 0);
1991 defconfig CSETB(Plugins, 1);
1994 scriptfile = EARGF(usage());
1997 defconfig CSETB(JavaScript, 0);
2000 defconfig CSETB(JavaScript, 1);
2003 defconfig CSETB(StrictTLS, 0);
2006 defconfig CSETB(StrictTLS, 1);
2009 fulluseragent = EARGF(usage());
2012 die("surf-"VERSION", see LICENSE for © details\n");
2017 defconfig CSETB(Certificate, 0);
2020 defconfig CSETB(Certificate, 1);
2023 defconfig CSETF(ZoomLevel, strtof(EARGF(usage()), NULL));
2031 arg.v = "about:blank";
2034 c = newclient(NULL);