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))
37 enum { AtomFind, AtomGo, AtomUri, AtomLast };
40 OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
41 OnLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
42 OnImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
43 OnMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
44 OnEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
45 OnBar = WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR,
46 OnSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
47 OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
97 typedef struct Client {
100 WebKitWebInspector *inspector;
101 WebKitFindController *finder;
102 WebKitHitTestResult *mousepos;
103 GTlsCertificate *cert, *failedcert;
104 GTlsCertificateFlags tlserr;
106 int progress, fullscreen, https, insecure, errorpage;
107 const char *title, *overtitle, *targeturi;
115 void (*func)(Client *c, const Arg *a);
123 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
125 unsigned int stopevent;
130 Parameter config[ParameterLast];
141 static void usage(void);
142 static void die(const char *errstr, ...);
143 static void setup(void);
144 static void sigchld(int unused);
145 static void sighup(int unused);
146 static char *buildfile(const char *path);
147 static char *buildpath(const char *path);
148 static const char *getuserhomedir(const char *user);
149 static const char *getcurrentuserhomedir(void);
150 static Client *newclient(Client *c);
151 static void loaduri(Client *c, const Arg *a);
152 static const char *geturi(Client *c);
153 static void setatom(Client *c, int a, const char *v);
154 static const char *getatom(Client *c, int a);
155 static void updatetitle(Client *c);
156 static void gettogglestats(Client *c);
157 static void getpagestats(Client *c);
158 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
159 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
160 static void seturiparameters(Client *c, const char *uri, ParamName *params);
161 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
162 static const char *getcert(const char *uri);
163 static void setcert(Client *c, const char *file);
164 static const char *getstyle(const char *uri);
165 static void setstyle(Client *c, const char *file);
166 static void runscript(Client *c);
167 static void evalscript(Client *c, const char *jsstr, ...);
168 static void updatewinid(Client *c);
169 static void handleplumb(Client *c, const char *uri);
170 static void newwindow(Client *c, const Arg *a, int noembed);
171 static void spawn(Client *c, const Arg *a);
172 static void destroyclient(Client *c);
173 static void cleanup(void);
176 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
177 static void initwebextensions(WebKitWebContext *wc, Client *c);
178 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
180 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
181 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
183 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
184 static void showview(WebKitWebView *v, Client *c);
185 static GtkWidget *createwindow(Client *c);
186 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
187 GTlsCertificate *cert,
188 GTlsCertificateFlags err, Client *c);
189 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
190 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
191 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
192 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
193 guint modifiers, Client *c);
194 static gboolean permissionrequested(WebKitWebView *v,
195 WebKitPermissionRequest *r, Client *c);
196 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
197 WebKitPolicyDecisionType dt, Client *c);
198 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
199 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
200 static void decideresource(WebKitPolicyDecision *d, Client *c);
201 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
203 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
205 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
206 static void download(Client *c, WebKitURIResponse *r);
207 static void closeview(WebKitWebView *v, Client *c);
208 static void destroywin(GtkWidget* w, Client *c);
211 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
212 static void reload(Client *c, const Arg *a);
213 static void print(Client *c, const Arg *a);
214 static void showcert(Client *c, const Arg *a);
215 static void clipboard(Client *c, const Arg *a);
216 static void zoom(Client *c, const Arg *a);
217 static void scroll(Client *c, const Arg *a);
218 static void navigate(Client *c, const Arg *a);
219 static void stop(Client *c, const Arg *a);
220 static void toggle(Client *c, const Arg *a);
221 static void togglefullscreen(Client *c, const Arg *a);
222 static void togglecookiepolicy(Client *c, const Arg *a);
223 static void toggleinspector(Client *c, const Arg *a);
224 static void find(Client *c, const Arg *a);
227 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
228 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
229 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
231 static char winid[64];
232 static char togglestats[12];
233 static char pagestats[2];
234 static Atom atoms[AtomLast];
237 static int cookiepolicy;
239 static Client *clients;
240 static GdkDevice *gdkkb;
241 static char *stylefile;
242 static const char *useragent;
243 static Parameter *curconfig;
246 static ParamName loadtransient[] = {
260 static ParamName loadcommitted[] = {
286 static ParamName loadfinished[] = {
290 /* configuration, allows nested code to access above variables */
296 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
297 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
298 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
302 die(const char *errstr, ...)
306 va_start(ap, errstr);
307 vfprintf(stderr, errstr, ap);
318 /* clean up any zombies immediately */
320 if (signal(SIGHUP, sighup) == SIG_ERR)
321 die("Can't install SIGHUP handler");
323 if (!(dpy = XOpenDisplay(NULL)))
324 die("Can't open default display");
327 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
328 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
329 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
331 gtk_init(NULL, NULL);
333 gdpy = gdk_display_get_default();
335 curconfig = defconfig;
338 cookiefile = buildfile(cookiefile);
339 scriptfile = buildfile(scriptfile);
340 cachedir = buildpath(cachedir);
341 certdir = buildpath(certdir);
343 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
345 for (i = 0; i < LENGTH(certs); ++i) {
346 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
347 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
350 fprintf(stderr, "Could not compile regex: %s\n",
352 certs[i].regex = NULL;
357 styledir = buildpath(styledir);
358 for (i = 0; i < LENGTH(styles); ++i) {
359 if (!regcomp(&(styles[i].re), styles[i].regex,
361 styles[i].file = g_strconcat(styledir, "/",
362 styles[i].file, NULL);
364 fprintf(stderr, "Could not compile regex: %s\n",
366 styles[i].regex = NULL;
371 stylefile = buildfile(stylefile);
374 for (i = 0; i < LENGTH(uriparams); ++i) {
375 if (regcomp(&(uriparams[i].re), uriparams[i].uri,
377 fprintf(stderr, "Could not compile regex: %s\n",
379 uriparams[i].uri = NULL;
383 /* copy default parameters with higher priority */
384 for (j = 0; j < ParameterLast; ++j) {
385 if (defconfig[j].prio >= uriparams[i].config[j].prio)
386 uriparams[i].config[j] = defconfig[j];
394 if (signal(SIGCHLD, sigchld) == SIG_ERR)
395 die("Can't install SIGCHLD handler");
396 while (waitpid(-1, NULL, WNOHANG) > 0)
406 for (c = clients; c; c = c->next)
411 buildfile(const char *path)
413 char *dname, *bname, *bpath, *fpath;
416 dname = g_path_get_dirname(path);
417 bname = g_path_get_basename(path);
419 bpath = buildpath(dname);
422 fpath = g_build_filename(bpath, bname, NULL);
426 if (!(f = fopen(fpath, "a")))
427 die("Could not open file: %s\n", fpath);
429 g_chmod(fpath, 0600); /* always */
436 getuserhomedir(const char *user)
438 struct passwd *pw = getpwnam(user);
441 die("Can't get user %s login information.\n", user);
447 getcurrentuserhomedir(void)
453 homedir = getenv("HOME");
457 user = getenv("USER");
459 return getuserhomedir(user);
461 pw = getpwuid(getuid());
463 die("Can't get current user home directory\n");
469 buildpath(const char *path)
471 char *apath, *name, *p, *fpath;
474 if (path[0] == '~') {
475 if (path[1] == '/' || path[1] == '\0') {
476 p = (char *)&path[1];
477 homedir = getcurrentuserhomedir();
479 if ((p = strchr(path, '/')))
480 name = g_strndup(&path[1], --p - path);
482 name = g_strdup(&path[1]);
484 homedir = getuserhomedir(name);
487 apath = g_build_filename(homedir, p, NULL);
489 apath = g_strdup(path);
492 /* creating directory */
493 if (g_mkdir_with_parents(apath, 0700) < 0)
494 die("Could not access directory: %s\n", apath);
496 fpath = realpath(apath, NULL);
503 newclient(Client *rc)
507 if (!(c = calloc(1, sizeof(Client))))
508 die("Cannot malloc!\n");
514 c->view = newview(c, rc ? rc->view : NULL);
520 loaduri(Client *c, const Arg *a)
524 const char *uri = a->v;
526 if (g_strcmp0(uri, "") == 0)
529 if (g_str_has_prefix(uri, "http://") ||
530 g_str_has_prefix(uri, "https://") ||
531 g_str_has_prefix(uri, "file://") ||
532 g_str_has_prefix(uri, "about:")) {
534 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
535 url = g_strdup_printf("file://%s", path);
538 url = g_strdup_printf("http://%s", uri);
541 setatom(c, AtomUri, url);
543 if (strcmp(url, geturi(c)) == 0) {
546 webkit_web_view_load_uri(c->view, url);
558 if (!(uri = webkit_web_view_get_uri(c->view)))
564 setatom(Client *c, int a, const char *v)
566 XChangeProperty(dpy, c->xid,
567 atoms[a], XA_STRING, 8, PropModeReplace,
568 (unsigned char *)v, strlen(v) + 1);
573 getatom(Client *c, int a)
575 static char buf[BUFSIZ];
578 unsigned long ldummy;
579 unsigned char *p = NULL;
582 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
583 &adummy, &idummy, &ldummy, &ldummy, &p);
585 strncpy(buf, (char *)p, LENGTH(buf) - 1);
594 updatetitle(Client *c)
597 const char *name = c->overtitle ? c->overtitle :
598 c->title ? c->title : "";
600 if (curconfig[ShowIndicators].val.i) {
604 if (c->progress != 100)
605 title = g_strdup_printf("[%i%%] %s:%s | %s",
606 c->progress, togglestats, pagestats, name);
608 title = g_strdup_printf("%s:%s | %s",
609 togglestats, pagestats, name);
611 gtk_window_set_title(GTK_WINDOW(c->win), title);
614 gtk_window_set_title(GTK_WINDOW(c->win), name);
619 gettogglestats(Client *c)
621 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
622 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
623 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
624 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
625 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
626 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
627 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
628 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
629 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
630 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
631 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
632 togglestats[11] = '\0';
636 getpagestats(Client *c)
639 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
645 WebKitCookieAcceptPolicy
646 cookiepolicy_get(void)
648 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
650 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
652 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
653 default: /* fallthrough */
655 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
660 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
663 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
665 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
667 default: /* fallthrough */
668 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
674 seturiparameters(Client *c, const char *uri, ParamName *params)
676 Parameter *config, *newconfig = NULL;
679 for (i = 0; i < LENGTH(uriparams); ++i) {
680 if (uriparams[i].uri &&
681 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
682 newconfig = uriparams[i].config;
688 newconfig = defconfig;
690 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
695 config = (newconfig[p].prio > defconfig[p].prio) ?
696 newconfig : defconfig;
699 if (newconfig[p].prio > defconfig[p].prio)
701 else if (curconfig[p].prio > defconfig[p].prio)
707 setparameter(c, 0, p, &config[p].val);
710 curconfig = newconfig;
714 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
716 GdkRGBA bgcolor = { 0 };
717 WebKitSettings *s = webkit_web_view_get_settings(c->view);
720 case AcceleratedCanvas:
721 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
723 case AccessMicrophone:
724 return; /* do nothing */
726 return; /* do nothing */
728 webkit_settings_set_enable_caret_browsing(s, a->i);
733 setcert(c, geturi(c));
734 return; /* do not update */
736 webkit_cookie_manager_set_accept_policy(
737 webkit_web_context_get_cookie_manager(
738 webkit_web_view_get_context(c->view)),
743 webkit_web_context_set_cache_model(
744 webkit_web_view_get_context(c->view), a->i ?
745 WEBKIT_CACHE_MODEL_WEB_BROWSER :
746 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
747 return; /* do not update */
749 webkit_settings_set_default_charset(s, a->v);
750 return; /* do not update */
752 webkit_settings_set_enable_dns_prefetching(s, a->i);
753 return; /* do not update */
754 case FileURLsCrossAccess:
755 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
756 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
757 return; /* do not update */
759 webkit_settings_set_default_font_size(s, a->i);
760 return; /* do not update */
761 case FrameFlattening:
762 webkit_settings_set_enable_frame_flattening(s, a->i);
769 webkit_web_view_set_background_color(c->view, &bgcolor);
770 return; /* do not update */
772 webkit_settings_set_enable_developer_extras(s, a->i);
773 return; /* do not update */
775 webkit_settings_set_enable_java(s, a->i);
776 return; /* do not update */
778 webkit_settings_set_enable_javascript(s, a->i);
781 return; /* do nothing */
783 webkit_settings_set_auto_load_images(s, a->i);
785 case MediaManualPlay:
786 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
789 webkit_settings_set_enable_plugins(s, a->i);
791 case PreferredLanguages:
792 return; /* do nothing */
793 case RunInFullscreen:
794 return; /* do nothing */
796 /* Disabled until we write some WebKitWebExtension for
797 * manipulating the DOM directly.
798 enablescrollbars = !enablescrollbars;
799 evalscript(c, "document.documentElement.style.overflow = '%s'",
800 enablescrollbars ? "auto" : "hidden");
802 return; /* do not update */
805 case SmoothScrolling:
806 webkit_settings_set_enable_smooth_scrolling(s, a->i);
807 return; /* do not update */
809 webkit_settings_set_enable_site_specific_quirks(s, a->i);
812 webkit_web_context_set_spell_checking_enabled(
813 webkit_web_view_get_context(c->view), a->i);
814 return; /* do not update */
816 return; /* do nothing */
818 webkit_web_context_set_tls_errors_policy(
819 webkit_web_view_get_context(c->view), a->i ?
820 WEBKIT_TLS_ERRORS_POLICY_FAIL :
821 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
824 webkit_user_content_manager_remove_all_style_sheets(
825 webkit_web_view_get_user_content_manager(c->view));
827 setstyle(c, getstyle(geturi(c)));
831 webkit_web_view_set_zoom_level(c->view, a->f);
832 return; /* do not update */
834 return; /* do nothing */
843 getcert(const char *uri)
847 for (i = 0; i < LENGTH(certs); ++i) {
848 if (certs[i].regex &&
849 !regexec(&(certs[i].re), uri, 0, NULL, 0))
850 return certs[i].file;
857 setcert(Client *c, const char *uri)
859 const char *file = getcert(uri);
861 GTlsCertificate *cert;
866 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
867 fprintf(stderr, "Could not read certificate file: %s\n", file);
871 if ((uri = strstr(uri, "https://"))) {
872 uri += sizeof("https://") - 1;
873 host = g_strndup(uri, strchr(uri, '/') - uri);
874 webkit_web_context_allow_tls_certificate_for_host(
875 webkit_web_view_get_context(c->view), cert, host);
879 g_object_unref(cert);
884 getstyle(const char *uri)
891 for (i = 0; i < LENGTH(styles); ++i) {
892 if (styles[i].regex &&
893 !regexec(&(styles[i].re), uri, 0, NULL, 0))
894 return styles[i].file;
901 setstyle(Client *c, const char *file)
905 if (!g_file_get_contents(file, &style, NULL, NULL)) {
906 fprintf(stderr, "Could not read style file: %s\n", file);
910 webkit_user_content_manager_add_style_sheet(
911 webkit_web_view_get_user_content_manager(c->view),
912 webkit_user_style_sheet_new(style,
913 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
914 WEBKIT_USER_STYLE_LEVEL_USER,
926 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
927 evalscript(c, script);
932 evalscript(Client *c, const char *jsstr, ...)
938 script = g_strdup_vprintf(jsstr, ap);
941 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
946 updatewinid(Client *c)
948 snprintf(winid, LENGTH(winid), "%lu", c->xid);
952 handleplumb(Client *c, const char *uri)
954 Arg a = (Arg)PLUMB(uri);
959 newwindow(Client *c, const Arg *a, int noembed)
963 const char *cmd[29], *uri;
964 const Arg arg = { .v = cmd };
968 cmd[i++] = curconfig[CookiePolicies].val.v;
969 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
970 if (cookiefile && g_strcmp0(cookiefile, "")) {
972 cmd[i++] = cookiefile;
974 if (stylefile && g_strcmp0(stylefile, "")) {
976 cmd[i++] = stylefile;
978 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
979 if (embed && !noembed) {
981 snprintf(tmp, LENGTH(tmp), "%lu", embed);
984 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
985 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
986 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
987 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
988 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
989 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
990 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
991 if (scriptfile && g_strcmp0(scriptfile, "")) {
993 cmd[i++] = scriptfile;
995 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
996 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
997 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
999 cmd[i++] = fulluseragent;
1003 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1004 /* do not keep zoom level */
1014 spawn(Client *c, const Arg *a)
1018 close(ConnectionNumber(dpy));
1020 execvp(((char **)a->v)[0], (char **)a->v);
1021 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1028 destroyclient(Client *c)
1032 webkit_web_view_stop_loading(c->view);
1033 /* Not needed, has already been called
1034 gtk_widget_destroy(c->win);
1037 for (p = clients; p && p->next != c; p = p->next)
1050 destroyclient(clients);
1059 newview(Client *c, WebKitWebView *rv)
1062 WebKitSettings *settings;
1063 WebKitUserContentManager *contentmanager;
1064 WebKitWebContext *context;
1068 v = WEBKIT_WEB_VIEW(
1069 webkit_web_view_new_with_related_view(rv));
1071 settings = webkit_settings_new_with_settings(
1072 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1073 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1074 "auto-load-images", curconfig[LoadImages].val.i,
1075 "default-charset", curconfig[DefaultCharset].val.v,
1076 "default-font-size", curconfig[FontSize].val.i,
1077 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1078 "enable-developer-extras", curconfig[Inspector].val.i,
1079 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1080 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1081 "enable-html5-database", curconfig[DiskCache].val.i,
1082 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1083 "enable-java", curconfig[Java].val.i,
1084 "enable-javascript", curconfig[JavaScript].val.i,
1085 "enable-plugins", curconfig[Plugins].val.i,
1086 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1087 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1088 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1089 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1091 /* For more interesting settings, have a look at
1092 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1094 if (strcmp(fulluseragent, "")) {
1095 webkit_settings_set_user_agent(settings, fulluseragent);
1096 } else if (surfuseragent) {
1097 webkit_settings_set_user_agent_with_application_details(
1098 settings, "Surf", VERSION);
1100 useragent = webkit_settings_get_user_agent(settings);
1102 contentmanager = webkit_user_content_manager_new();
1104 context = webkit_web_context_new_with_website_data_manager(
1105 webkit_website_data_manager_new(
1106 "base-cache-directory", cachedir,
1107 "base-data-directory", cachedir,
1110 /* rendering process model, can be a shared unique one
1111 * or one for each view */
1112 webkit_web_context_set_process_model(context,
1113 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1115 webkit_web_context_set_tls_errors_policy(context,
1116 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1117 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1119 webkit_web_context_set_cache_model(context,
1120 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1121 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1123 /* Currently only works with text file to be compatible with curl */
1124 webkit_cookie_manager_set_persistent_storage(
1125 webkit_web_context_get_cookie_manager(context), cookiefile,
1126 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1128 webkit_cookie_manager_set_accept_policy(
1129 webkit_web_context_get_cookie_manager(context),
1130 cookiepolicy_get());
1132 webkit_web_context_set_preferred_languages(context,
1133 curconfig[PreferredLanguages].val.v);
1134 webkit_web_context_set_spell_checking_languages(context,
1135 curconfig[SpellLanguages].val.v);
1136 webkit_web_context_set_spell_checking_enabled(context,
1137 curconfig[SpellChecking].val.i);
1139 g_signal_connect(G_OBJECT(context), "download-started",
1140 G_CALLBACK(downloadstarted), c);
1141 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1142 G_CALLBACK(initwebextensions), c);
1144 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1145 "settings", settings,
1146 "user-content-manager", contentmanager,
1147 "web-context", context,
1151 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1152 G_CALLBACK(progresschanged), c);
1153 g_signal_connect(G_OBJECT(v), "notify::title",
1154 G_CALLBACK(titlechanged), c);
1155 g_signal_connect(G_OBJECT(v), "button-release-event",
1156 G_CALLBACK(buttonreleased), c);
1157 g_signal_connect(G_OBJECT(v), "close",
1158 G_CALLBACK(closeview), c);
1159 g_signal_connect(G_OBJECT(v), "create",
1160 G_CALLBACK(createview), c);
1161 g_signal_connect(G_OBJECT(v), "decide-policy",
1162 G_CALLBACK(decidepolicy), c);
1163 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1164 G_CALLBACK(insecurecontent), c);
1165 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1166 G_CALLBACK(loadfailedtls), c);
1167 g_signal_connect(G_OBJECT(v), "load-changed",
1168 G_CALLBACK(loadchanged), c);
1169 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1170 G_CALLBACK(mousetargetchanged), c);
1171 g_signal_connect(G_OBJECT(v), "permission-request",
1172 G_CALLBACK(permissionrequested), c);
1173 g_signal_connect(G_OBJECT(v), "ready-to-show",
1174 G_CALLBACK(showview), c);
1180 initwebextensions(WebKitWebContext *wc, Client *c)
1182 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1186 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1190 switch (webkit_navigation_action_get_navigation_type(a)) {
1191 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1193 * popup windows of type “other” are almost always triggered
1194 * by user gesture, so inverse the logic here
1196 /* instead of this, compare destination uri to mouse-over uri for validating window */
1197 if (webkit_navigation_action_is_user_gesture(a))
1199 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1200 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1201 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1202 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1203 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1210 return GTK_WIDGET(n->view);
1214 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1216 WebKitHitTestResultContext element;
1219 element = webkit_hit_test_result_get_context(c->mousepos);
1221 for (i = 0; i < LENGTH(buttons); ++i) {
1222 if (element & buttons[i].target &&
1223 e->button.button == buttons[i].button &&
1224 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1226 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1227 return buttons[i].stopevent;
1235 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1237 Client *c = (Client *)d;
1241 if (((XEvent *)e)->type == PropertyNotify) {
1242 ev = &((XEvent *)e)->xproperty;
1243 if (ev->state == PropertyNewValue) {
1244 if (ev->atom == atoms[AtomFind]) {
1247 return GDK_FILTER_REMOVE;
1248 } else if (ev->atom == atoms[AtomGo]) {
1249 a.v = getatom(c, AtomGo);
1252 return GDK_FILTER_REMOVE;
1256 return GDK_FILTER_CONTINUE;
1260 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1265 case GDK_ENTER_NOTIFY:
1266 c->overtitle = c->targeturi;
1270 if (!curconfig[KioskMode].val.i) {
1271 for (i = 0; i < LENGTH(keys); ++i) {
1272 if (gdk_keyval_to_lower(e->key.keyval) ==
1274 CLEANMASK(e->key.state) == keys[i].mod &&
1277 keys[i].func(c, &(keys[i].arg));
1282 case GDK_LEAVE_NOTIFY:
1283 c->overtitle = NULL;
1286 case GDK_WINDOW_STATE:
1287 if (e->window_state.changed_mask ==
1288 GDK_WINDOW_STATE_FULLSCREEN)
1289 c->fullscreen = e->window_state.new_window_state &
1290 GDK_WINDOW_STATE_FULLSCREEN;
1300 showview(WebKitWebView *v, Client *c)
1302 GdkRGBA bgcolor = { 0 };
1305 c->finder = webkit_web_view_get_find_controller(c->view);
1306 c->inspector = webkit_web_view_get_inspector(c->view);
1308 c->win = createwindow(c);
1310 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1311 gtk_widget_show_all(c->win);
1312 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1314 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1315 c->xid = gdk_x11_window_get_xid(gwin);
1318 gdk_display_sync(gtk_widget_get_display(c->win));
1322 if (curconfig[HideBackground].val.i)
1323 webkit_web_view_set_background_color(c->view, &bgcolor);
1325 if (!curconfig[KioskMode].val.i) {
1326 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1327 gdk_window_add_filter(gwin, processx, c);
1330 if (curconfig[RunInFullscreen].val.i)
1331 togglefullscreen(c, NULL);
1333 if (curconfig[ZoomLevel].val.f != 1.0)
1334 webkit_web_view_set_zoom_level(c->view,
1335 curconfig[ZoomLevel].val.f);
1337 setatom(c, AtomFind, "");
1338 setatom(c, AtomUri, "about:blank");
1342 createwindow(Client *c)
1348 w = gtk_plug_new(embed);
1350 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1352 wmstr = g_path_get_basename(argv0);
1353 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1356 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1357 webkit_web_view_get_page_id(c->view));
1358 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1361 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1364 g_signal_connect(G_OBJECT(w), "destroy",
1365 G_CALLBACK(destroywin), c);
1366 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1367 G_CALLBACK(winevent), c);
1368 g_signal_connect(G_OBJECT(w), "key-press-event",
1369 G_CALLBACK(winevent), c);
1370 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1371 G_CALLBACK(winevent), c);
1372 g_signal_connect(G_OBJECT(w), "window-state-event",
1373 G_CALLBACK(winevent), c);
1379 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1380 GTlsCertificateFlags err, Client *c)
1382 GString *errmsg = g_string_new(NULL);
1385 c->failedcert = g_object_ref(cert);
1389 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1390 g_string_append(errmsg,
1391 "The signing certificate authority is not known.<br>");
1392 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1393 g_string_append(errmsg,
1394 "The certificate does not match the expected identity "
1395 "of the site that it was retrieved from.<br>");
1396 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1397 g_string_append(errmsg,
1398 "The certificate's activation time "
1399 "is still in the future.<br>");
1400 if (err & G_TLS_CERTIFICATE_EXPIRED)
1401 g_string_append(errmsg, "The certificate has expired.<br>");
1402 if (err & G_TLS_CERTIFICATE_REVOKED)
1403 g_string_append(errmsg,
1404 "The certificate has been revoked according to "
1405 "the GTlsConnection's certificate revocation list.<br>");
1406 if (err & G_TLS_CERTIFICATE_INSECURE)
1407 g_string_append(errmsg,
1408 "The certificate's algorithm is considered insecure.<br>");
1409 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1410 g_string_append(errmsg,
1411 "Some error occurred validating the certificate.<br>");
1413 g_object_get(cert, "certificate-pem", &pem, NULL);
1414 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1415 "<p>You can inspect the following certificate "
1416 "with Ctrl-t (default keybinding).</p>"
1417 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1419 g_string_free(errmsg, TRUE);
1421 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1428 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1430 const char *uri = geturi(c);
1433 case WEBKIT_LOAD_STARTED:
1434 setatom(c, AtomUri, uri);
1436 c->https = c->insecure = 0;
1437 seturiparameters(c, uri, loadtransient);
1441 g_clear_object(&c->failedcert);
1443 case WEBKIT_LOAD_REDIRECTED:
1444 setatom(c, AtomUri, uri);
1446 seturiparameters(c, uri, loadtransient);
1448 case WEBKIT_LOAD_COMMITTED:
1449 seturiparameters(c, uri, loadcommitted);
1450 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1453 case WEBKIT_LOAD_FINISHED:
1454 seturiparameters(c, uri, loadfinished);
1455 /* Disabled until we write some WebKitWebExtension for
1456 * manipulating the DOM directly.
1457 evalscript(c, "document.documentElement.style.overflow = '%s'",
1458 enablescrollbars ? "auto" : "hidden");
1467 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1469 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1475 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1477 c->title = webkit_web_view_get_title(c->view);
1482 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1485 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1487 /* Keep the hit test to know where is the pointer on the next click */
1491 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1492 else if (hc & OnImg)
1493 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1494 else if (hc & OnMedia)
1495 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1497 c->targeturi = NULL;
1499 c->overtitle = c->targeturi;
1504 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1506 ParamName param = ParameterLast;
1508 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1509 param = Geolocation;
1510 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1511 if (webkit_user_media_permission_is_for_audio_device(
1512 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1513 param = AccessMicrophone;
1514 else if (webkit_user_media_permission_is_for_video_device(
1515 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1516 param = AccessWebcam;
1521 if (curconfig[param].val.i)
1522 webkit_permission_request_allow(r);
1524 webkit_permission_request_deny(r);
1530 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1531 WebKitPolicyDecisionType dt, Client *c)
1534 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1535 decidenavigation(d, c);
1537 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1538 decidenewwindow(d, c);
1540 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1541 decideresource(d, c);
1544 webkit_policy_decision_ignore(d);
1551 decidenavigation(WebKitPolicyDecision *d, Client *c)
1553 WebKitNavigationAction *a =
1554 webkit_navigation_policy_decision_get_navigation_action(
1555 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1557 switch (webkit_navigation_action_get_navigation_type(a)) {
1558 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1559 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1560 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1561 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1562 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1563 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1565 /* Do not navigate to links with a "_blank" target (popup) */
1566 if (webkit_navigation_policy_decision_get_frame_name(
1567 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1568 webkit_policy_decision_ignore(d);
1570 /* Filter out navigation to different domain ? */
1571 /* get action→urirequest, copy and load in new window+view
1572 * on Ctrl+Click ? */
1573 webkit_policy_decision_use(d);
1580 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1583 WebKitNavigationAction *a =
1584 webkit_navigation_policy_decision_get_navigation_action(
1585 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1588 switch (webkit_navigation_action_get_navigation_type(a)) {
1589 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1590 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1591 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1592 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1593 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1594 /* Filter domains here */
1595 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1596 * test for link clicked but no button ? */
1597 arg.v = webkit_uri_request_get_uri(
1598 webkit_navigation_action_get_request(a));
1599 newwindow(c, &arg, 0);
1601 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1606 webkit_policy_decision_ignore(d);
1610 decideresource(WebKitPolicyDecision *d, Client *c)
1613 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1614 WebKitURIResponse *res =
1615 webkit_response_policy_decision_get_response(r);
1616 const gchar *uri = webkit_uri_response_get_uri(res);
1618 if (g_str_has_suffix(uri, "/favicon.ico")) {
1619 webkit_policy_decision_ignore(d);
1623 if (!g_str_has_prefix(uri, "http://")
1624 && !g_str_has_prefix(uri, "https://")
1625 && !g_str_has_prefix(uri, "about:")
1626 && !g_str_has_prefix(uri, "file://")
1627 && !g_str_has_prefix(uri, "data:")
1628 && !g_str_has_prefix(uri, "blob:")
1629 && strlen(uri) > 0) {
1630 for (i = 0; i < strlen(uri); i++) {
1631 if (!g_ascii_isprint(uri[i])) {
1637 handleplumb(c, uri);
1638 webkit_policy_decision_ignore(d);
1643 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1644 webkit_policy_decision_use(d);
1646 webkit_policy_decision_ignore(d);
1652 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1658 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1660 g_signal_connect(G_OBJECT(d), "notify::response",
1661 G_CALLBACK(responsereceived), c);
1665 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1667 download(c, webkit_download_get_response(d));
1668 webkit_download_cancel(d);
1672 download(Client *c, WebKitURIResponse *r)
1674 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1679 closeview(WebKitWebView *v, Client *c)
1681 gtk_widget_destroy(c->win);
1685 destroywin(GtkWidget* w, Client *c)
1693 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1695 Arg a = {.v = text };
1697 loaduri((Client *) d, &a);
1701 reload(Client *c, const Arg *a)
1704 webkit_web_view_reload_bypass_cache(c->view);
1706 webkit_web_view_reload(c->view);
1710 print(Client *c, const Arg *a)
1712 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1713 GTK_WINDOW(c->win));
1717 showcert(Client *c, const Arg *a)
1719 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1720 GcrCertificate *gcrt;
1723 GcrCertificateWidget *wcert;
1728 g_object_get(cert, "certificate", &crt, NULL);
1729 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1730 g_byte_array_unref(crt);
1732 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1733 wcert = gcr_certificate_widget_new(gcrt);
1734 g_object_unref(gcrt);
1736 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1737 gtk_widget_show_all(win);
1741 clipboard(Client *c, const Arg *a)
1743 if (a->i) { /* load clipboard uri */
1744 gtk_clipboard_request_text(gtk_clipboard_get(
1745 GDK_SELECTION_PRIMARY),
1747 } else { /* copy uri */
1748 gtk_clipboard_set_text(gtk_clipboard_get(
1749 GDK_SELECTION_PRIMARY), c->targeturi
1750 ? c->targeturi : geturi(c), -1);
1755 zoom(Client *c, const Arg *a)
1758 webkit_web_view_set_zoom_level(c->view,
1759 curconfig[ZoomLevel].val.f + 0.1);
1761 webkit_web_view_set_zoom_level(c->view,
1762 curconfig[ZoomLevel].val.f - 0.1);
1764 webkit_web_view_set_zoom_level(c->view, 1.0);
1766 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1770 scroll(Client *c, const Arg *a)
1772 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1774 gdk_event_set_device(ev, gdkkb);
1775 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1776 ev->key.state = GDK_CONTROL_MASK;
1777 ev->key.time = GDK_CURRENT_TIME;
1781 ev->key.keyval = GDK_KEY_Down;
1784 ev->key.keyval = GDK_KEY_Page_Down;
1787 ev->key.keyval = GDK_KEY_Left;
1790 ev->key.keyval = GDK_KEY_Right;
1793 ev->key.keyval = GDK_KEY_Page_Up;
1796 ev->key.keyval = GDK_KEY_Up;
1804 navigate(Client *c, const Arg *a)
1807 webkit_web_view_go_back(c->view);
1809 webkit_web_view_go_forward(c->view);
1813 stop(Client *c, const Arg *a)
1815 webkit_web_view_stop_loading(c->view);
1819 toggle(Client *c, const Arg *a)
1821 curconfig[a->i].val.i ^= 1;
1822 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1826 togglefullscreen(Client *c, const Arg *a)
1828 /* toggling value is handled in winevent() */
1830 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1832 gtk_window_fullscreen(GTK_WINDOW(c->win));
1836 togglecookiepolicy(Client *c, const Arg *a)
1839 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1841 setparameter(c, 0, CookiePolicies, NULL);
1845 toggleinspector(Client *c, const Arg *a)
1847 if (webkit_web_inspector_is_attached(c->inspector))
1848 webkit_web_inspector_close(c->inspector);
1849 else if (curconfig[Inspector].val.i)
1850 webkit_web_inspector_show(c->inspector);
1854 find(Client *c, const Arg *a)
1860 webkit_find_controller_search_next(c->finder);
1862 webkit_find_controller_search_previous(c->finder);
1864 s = getatom(c, AtomFind);
1865 f = webkit_find_controller_get_search_text(c->finder);
1867 if (g_strcmp0(f, s) == 0) /* reset search */
1868 webkit_find_controller_search(c->finder, "", findopts,
1871 webkit_find_controller_search(c->finder, s, findopts,
1874 if (strcmp(s, "") == 0)
1875 webkit_find_controller_search_finish(c->finder);
1880 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1886 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1890 arg.v = webkit_hit_test_result_get_link_uri(h);
1891 newwindow(c, &arg, a->i);
1895 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1899 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1904 main(int argc, char *argv[])
1909 memset(&arg, 0, sizeof(arg));
1911 /* command line args */
1914 defconfig[CookiePolicies].val.v = EARGF(usage());
1915 defconfig[CookiePolicies].prio = 2;
1918 defconfig[ScrollBars].val.i = 0;
1919 defconfig[ScrollBars].prio = 2;
1922 defconfig[ScrollBars].val.i = 1;
1923 defconfig[ScrollBars].prio = 2;
1926 cookiefile = EARGF(usage());
1929 stylefile = EARGF(usage());
1932 defconfig[DiskCache].val.i = 0;
1933 defconfig[DiskCache].prio = 2;
1936 defconfig[DiskCache].val.i = 1;
1937 defconfig[DiskCache].prio = 2;
1940 embed = strtol(EARGF(usage()), NULL, 0);
1943 defconfig[RunInFullscreen].val.i = 0;
1944 defconfig[RunInFullscreen].prio = 2;
1947 defconfig[RunInFullscreen].val.i = 1;
1948 defconfig[RunInFullscreen].prio = 2;
1951 defconfig[Geolocation].val.i = 0;
1952 defconfig[Geolocation].prio = 2;
1955 defconfig[Geolocation].val.i = 1;
1956 defconfig[Geolocation].prio = 2;
1959 defconfig[LoadImages].val.i = 0;
1960 defconfig[LoadImages].prio = 2;
1963 defconfig[LoadImages].val.i = 1;
1964 defconfig[LoadImages].prio = 2;
1967 defconfig[KioskMode].val.i = 0;
1968 defconfig[KioskMode].prio = 2;
1971 defconfig[KioskMode].val.i = 1;
1972 defconfig[KioskMode].prio = 2;
1975 defconfig[Style].val.i = 0;
1976 defconfig[Style].prio = 2;
1979 defconfig[Style].val.i = 1;
1980 defconfig[Style].prio = 2;
1983 defconfig[Inspector].val.i = 0;
1984 defconfig[Inspector].prio = 2;
1987 defconfig[Inspector].val.i = 1;
1988 defconfig[Inspector].prio = 2;
1991 defconfig[Plugins].val.i = 0;
1992 defconfig[Plugins].prio = 2;
1995 defconfig[Plugins].val.i = 1;
1996 defconfig[Plugins].prio = 2;
1999 scriptfile = EARGF(usage());
2002 defconfig[JavaScript].val.i = 0;
2003 defconfig[JavaScript].prio = 2;
2006 defconfig[JavaScript].val.i = 1;
2007 defconfig[JavaScript].prio = 2;
2010 defconfig[StrictTLS].val.i = 0;
2011 defconfig[StrictTLS].prio = 2;
2014 defconfig[StrictTLS].val.i = 1;
2015 defconfig[StrictTLS].prio = 2;
2018 fulluseragent = EARGF(usage());
2021 die("surf-"VERSION", see LICENSE for © details\n");
2026 defconfig[Certificate].val.i = 0;
2027 defconfig[Certificate].prio = 2;
2030 defconfig[Certificate].val.i = 1;
2031 defconfig[Certificate].prio = 2;
2034 defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
2035 defconfig[ZoomLevel].prio = 2;
2043 arg.v = "about:blank";
2046 c = newclient(NULL);