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 /* copy default parameters if they are not already set
378 * or if they are forced */
379 for (j = 0; j < ParameterLast; ++j) {
380 if (!uriparams[i].config[j].force ||
382 uriparams[i].config[j] = defconfig[j];
385 fprintf(stderr, "Could not compile regex: %s\n",
387 uriparams[i].uri = NULL;
395 if (signal(SIGCHLD, sigchld) == SIG_ERR)
396 die("Can't install SIGCHLD handler");
397 while (waitpid(-1, NULL, WNOHANG) > 0)
407 for (c = clients; c; c = c->next)
412 buildfile(const char *path)
414 char *dname, *bname, *bpath, *fpath;
417 dname = g_path_get_dirname(path);
418 bname = g_path_get_basename(path);
420 bpath = buildpath(dname);
423 fpath = g_build_filename(bpath, bname, NULL);
427 if (!(f = fopen(fpath, "a")))
428 die("Could not open file: %s\n", fpath);
430 g_chmod(fpath, 0600); /* always */
437 getuserhomedir(const char *user)
439 struct passwd *pw = getpwnam(user);
442 die("Can't get user %s login information.\n", user);
448 getcurrentuserhomedir(void)
454 homedir = getenv("HOME");
458 user = getenv("USER");
460 return getuserhomedir(user);
462 pw = getpwuid(getuid());
464 die("Can't get current user home directory\n");
470 buildpath(const char *path)
472 char *apath, *name, *p, *fpath;
475 if (path[0] == '~') {
476 if (path[1] == '/' || path[1] == '\0') {
477 p = (char *)&path[1];
478 homedir = getcurrentuserhomedir();
480 if ((p = strchr(path, '/')))
481 name = g_strndup(&path[1], --p - path);
483 name = g_strdup(&path[1]);
485 homedir = getuserhomedir(name);
488 apath = g_build_filename(homedir, p, NULL);
490 apath = g_strdup(path);
493 /* creating directory */
494 if (g_mkdir_with_parents(apath, 0700) < 0)
495 die("Could not access directory: %s\n", apath);
497 fpath = realpath(apath, NULL);
504 newclient(Client *rc)
508 if (!(c = calloc(1, sizeof(Client))))
509 die("Cannot malloc!\n");
515 c->view = newview(c, rc ? rc->view : NULL);
521 loaduri(Client *c, const Arg *a)
525 const char *uri = a->v;
527 if (g_strcmp0(uri, "") == 0)
530 if (g_str_has_prefix(uri, "http://") ||
531 g_str_has_prefix(uri, "https://") ||
532 g_str_has_prefix(uri, "file://") ||
533 g_str_has_prefix(uri, "about:")) {
535 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
536 url = g_strdup_printf("file://%s", path);
539 url = g_strdup_printf("http://%s", uri);
542 setatom(c, AtomUri, url);
544 if (strcmp(url, geturi(c)) == 0) {
547 webkit_web_view_load_uri(c->view, url);
559 if (!(uri = webkit_web_view_get_uri(c->view)))
565 setatom(Client *c, int a, const char *v)
567 XChangeProperty(dpy, c->xid,
568 atoms[a], XA_STRING, 8, PropModeReplace,
569 (unsigned char *)v, strlen(v) + 1);
574 getatom(Client *c, int a)
576 static char buf[BUFSIZ];
579 unsigned long ldummy;
580 unsigned char *p = NULL;
583 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
584 &adummy, &idummy, &ldummy, &ldummy, &p);
586 strncpy(buf, (char *)p, LENGTH(buf) - 1);
595 updatetitle(Client *c)
598 const char *name = c->overtitle ? c->overtitle :
599 c->title ? c->title : "";
601 if (curconfig[ShowIndicators].val.i) {
605 if (c->progress != 100)
606 title = g_strdup_printf("[%i%%] %s:%s | %s",
607 c->progress, togglestats, pagestats, name);
609 title = g_strdup_printf("%s:%s | %s",
610 togglestats, pagestats, name);
612 gtk_window_set_title(GTK_WINDOW(c->win), title);
615 gtk_window_set_title(GTK_WINDOW(c->win), name);
620 gettogglestats(Client *c)
622 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
623 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
624 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
625 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
626 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
627 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
628 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
629 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
630 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
631 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
632 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
633 togglestats[11] = '\0';
637 getpagestats(Client *c)
640 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
646 WebKitCookieAcceptPolicy
647 cookiepolicy_get(void)
649 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
651 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
653 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
654 default: /* fallthrough */
656 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
661 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
664 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
666 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
668 default: /* fallthrough */
669 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
675 seturiparameters(Client *c, const char *uri, ParamName *params)
677 Parameter *config, *newconfig = NULL;
680 for (i = 0; i < LENGTH(uriparams); ++i) {
681 if (uriparams[i].uri &&
682 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
683 newconfig = uriparams[i].config;
689 newconfig = defconfig;
691 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
696 config = defconfig[p].force ? defconfig :
697 newconfig[p].force ? newconfig :
701 if (defconfig[p].force)
703 config = newconfig[p].force ? newconfig :
704 curconfig[p].force ? defconfig :
709 setparameter(c, 0, p, &config[p].val);
712 curconfig = newconfig;
716 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
718 GdkRGBA bgcolor = { 0 };
719 WebKitSettings *s = webkit_web_view_get_settings(c->view);
722 case AcceleratedCanvas:
723 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
725 case AccessMicrophone:
726 return; /* do nothing */
728 return; /* do nothing */
730 webkit_settings_set_enable_caret_browsing(s, a->i);
735 setcert(c, geturi(c));
736 return; /* do not update */
738 webkit_cookie_manager_set_accept_policy(
739 webkit_web_context_get_cookie_manager(
740 webkit_web_view_get_context(c->view)),
745 webkit_web_context_set_cache_model(
746 webkit_web_view_get_context(c->view), a->i ?
747 WEBKIT_CACHE_MODEL_WEB_BROWSER :
748 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
749 return; /* do not update */
751 webkit_settings_set_default_charset(s, a->v);
752 return; /* do not update */
754 webkit_settings_set_enable_dns_prefetching(s, a->i);
755 return; /* do not update */
756 case FileURLsCrossAccess:
757 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
758 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
759 return; /* do not update */
761 webkit_settings_set_default_font_size(s, a->i);
762 return; /* do not update */
763 case FrameFlattening:
764 webkit_settings_set_enable_frame_flattening(s, a->i);
771 webkit_web_view_set_background_color(c->view, &bgcolor);
772 return; /* do not update */
774 webkit_settings_set_enable_developer_extras(s, a->i);
775 return; /* do not update */
777 webkit_settings_set_enable_java(s, a->i);
778 return; /* do not update */
780 webkit_settings_set_enable_javascript(s, a->i);
783 return; /* do nothing */
785 webkit_settings_set_auto_load_images(s, a->i);
787 case MediaManualPlay:
788 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
791 webkit_settings_set_enable_plugins(s, a->i);
793 case PreferredLanguages:
794 return; /* do nothing */
795 case RunInFullscreen:
796 return; /* do nothing */
798 /* Disabled until we write some WebKitWebExtension for
799 * manipulating the DOM directly.
800 enablescrollbars = !enablescrollbars;
801 evalscript(c, "document.documentElement.style.overflow = '%s'",
802 enablescrollbars ? "auto" : "hidden");
804 return; /* do not update */
807 case SmoothScrolling:
808 webkit_settings_set_enable_smooth_scrolling(s, a->i);
809 return; /* do not update */
811 webkit_settings_set_enable_site_specific_quirks(s, a->i);
814 webkit_web_context_set_spell_checking_enabled(
815 webkit_web_view_get_context(c->view), a->i);
816 return; /* do not update */
818 return; /* do nothing */
820 webkit_web_context_set_tls_errors_policy(
821 webkit_web_view_get_context(c->view), a->i ?
822 WEBKIT_TLS_ERRORS_POLICY_FAIL :
823 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
826 webkit_user_content_manager_remove_all_style_sheets(
827 webkit_web_view_get_user_content_manager(c->view));
829 setstyle(c, getstyle(geturi(c)));
833 webkit_web_view_set_zoom_level(c->view, a->f);
834 return; /* do not update */
836 return; /* do nothing */
845 getcert(const char *uri)
849 for (i = 0; i < LENGTH(certs); ++i) {
850 if (certs[i].regex &&
851 !regexec(&(certs[i].re), uri, 0, NULL, 0))
852 return certs[i].file;
859 setcert(Client *c, const char *uri)
861 const char *file = getcert(uri);
863 GTlsCertificate *cert;
868 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
869 fprintf(stderr, "Could not read certificate file: %s\n", file);
873 if ((uri = strstr(uri, "https://"))) {
874 uri += sizeof("https://") - 1;
875 host = g_strndup(uri, strchr(uri, '/') - uri);
876 webkit_web_context_allow_tls_certificate_for_host(
877 webkit_web_view_get_context(c->view), cert, host);
881 g_object_unref(cert);
886 getstyle(const char *uri)
893 for (i = 0; i < LENGTH(styles); ++i) {
894 if (styles[i].regex &&
895 !regexec(&(styles[i].re), uri, 0, NULL, 0))
896 return styles[i].file;
903 setstyle(Client *c, const char *file)
907 if (!g_file_get_contents(file, &style, NULL, NULL)) {
908 fprintf(stderr, "Could not read style file: %s\n", file);
912 webkit_user_content_manager_add_style_sheet(
913 webkit_web_view_get_user_content_manager(c->view),
914 webkit_user_style_sheet_new(style,
915 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
916 WEBKIT_USER_STYLE_LEVEL_USER,
928 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
929 evalscript(c, script);
934 evalscript(Client *c, const char *jsstr, ...)
940 script = g_strdup_vprintf(jsstr, ap);
943 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
948 updatewinid(Client *c)
950 snprintf(winid, LENGTH(winid), "%lu", c->xid);
954 handleplumb(Client *c, const char *uri)
956 Arg a = (Arg)PLUMB(uri);
961 newwindow(Client *c, const Arg *a, int noembed)
965 const char *cmd[29], *uri;
966 const Arg arg = { .v = cmd };
970 cmd[i++] = curconfig[CookiePolicies].val.v;
971 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
972 if (cookiefile && g_strcmp0(cookiefile, "")) {
974 cmd[i++] = cookiefile;
976 if (stylefile && g_strcmp0(stylefile, "")) {
978 cmd[i++] = stylefile;
980 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
981 if (embed && !noembed) {
983 snprintf(tmp, LENGTH(tmp), "%lu", embed);
986 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
987 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
988 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
989 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
990 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
991 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
992 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
993 if (scriptfile && g_strcmp0(scriptfile, "")) {
995 cmd[i++] = scriptfile;
997 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
998 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
999 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
1001 cmd[i++] = fulluseragent;
1005 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1006 /* do not keep zoom level */
1016 spawn(Client *c, const Arg *a)
1020 close(ConnectionNumber(dpy));
1022 execvp(((char **)a->v)[0], (char **)a->v);
1023 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1030 destroyclient(Client *c)
1034 webkit_web_view_stop_loading(c->view);
1035 /* Not needed, has already been called
1036 gtk_widget_destroy(c->win);
1039 for (p = clients; p && p->next != c; p = p->next)
1052 destroyclient(clients);
1061 newview(Client *c, WebKitWebView *rv)
1064 WebKitSettings *settings;
1065 WebKitUserContentManager *contentmanager;
1066 WebKitWebContext *context;
1070 v = WEBKIT_WEB_VIEW(
1071 webkit_web_view_new_with_related_view(rv));
1073 settings = webkit_settings_new_with_settings(
1074 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1075 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1076 "auto-load-images", curconfig[LoadImages].val.i,
1077 "default-charset", curconfig[DefaultCharset].val.v,
1078 "default-font-size", curconfig[FontSize].val.i,
1079 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1080 "enable-developer-extras", curconfig[Inspector].val.i,
1081 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1082 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1083 "enable-html5-database", curconfig[DiskCache].val.i,
1084 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1085 "enable-java", curconfig[Java].val.i,
1086 "enable-javascript", curconfig[JavaScript].val.i,
1087 "enable-plugins", curconfig[Plugins].val.i,
1088 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1089 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1090 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1091 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1093 /* For more interesting settings, have a look at
1094 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1096 if (strcmp(fulluseragent, "")) {
1097 webkit_settings_set_user_agent(settings, fulluseragent);
1098 } else if (surfuseragent) {
1099 webkit_settings_set_user_agent_with_application_details(
1100 settings, "Surf", VERSION);
1102 useragent = webkit_settings_get_user_agent(settings);
1104 contentmanager = webkit_user_content_manager_new();
1106 context = webkit_web_context_new_with_website_data_manager(
1107 webkit_website_data_manager_new(
1108 "base-cache-directory", cachedir,
1109 "base-data-directory", cachedir,
1112 /* rendering process model, can be a shared unique one
1113 * or one for each view */
1114 webkit_web_context_set_process_model(context,
1115 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1117 webkit_web_context_set_tls_errors_policy(context,
1118 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1119 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1121 webkit_web_context_set_cache_model(context,
1122 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1123 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1125 /* Currently only works with text file to be compatible with curl */
1126 webkit_cookie_manager_set_persistent_storage(
1127 webkit_web_context_get_cookie_manager(context), cookiefile,
1128 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1130 webkit_cookie_manager_set_accept_policy(
1131 webkit_web_context_get_cookie_manager(context),
1132 cookiepolicy_get());
1134 webkit_web_context_set_preferred_languages(context,
1135 curconfig[PreferredLanguages].val.v);
1136 webkit_web_context_set_spell_checking_languages(context,
1137 curconfig[SpellLanguages].val.v);
1138 webkit_web_context_set_spell_checking_enabled(context,
1139 curconfig[SpellChecking].val.i);
1141 g_signal_connect(G_OBJECT(context), "download-started",
1142 G_CALLBACK(downloadstarted), c);
1143 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1144 G_CALLBACK(initwebextensions), c);
1146 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1147 "settings", settings,
1148 "user-content-manager", contentmanager,
1149 "web-context", context,
1153 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1154 G_CALLBACK(progresschanged), c);
1155 g_signal_connect(G_OBJECT(v), "notify::title",
1156 G_CALLBACK(titlechanged), c);
1157 g_signal_connect(G_OBJECT(v), "button-release-event",
1158 G_CALLBACK(buttonreleased), c);
1159 g_signal_connect(G_OBJECT(v), "close",
1160 G_CALLBACK(closeview), c);
1161 g_signal_connect(G_OBJECT(v), "create",
1162 G_CALLBACK(createview), c);
1163 g_signal_connect(G_OBJECT(v), "decide-policy",
1164 G_CALLBACK(decidepolicy), c);
1165 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1166 G_CALLBACK(insecurecontent), c);
1167 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1168 G_CALLBACK(loadfailedtls), c);
1169 g_signal_connect(G_OBJECT(v), "load-changed",
1170 G_CALLBACK(loadchanged), c);
1171 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1172 G_CALLBACK(mousetargetchanged), c);
1173 g_signal_connect(G_OBJECT(v), "permission-request",
1174 G_CALLBACK(permissionrequested), c);
1175 g_signal_connect(G_OBJECT(v), "ready-to-show",
1176 G_CALLBACK(showview), c);
1182 initwebextensions(WebKitWebContext *wc, Client *c)
1184 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1188 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1192 switch (webkit_navigation_action_get_navigation_type(a)) {
1193 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1195 * popup windows of type “other” are almost always triggered
1196 * by user gesture, so inverse the logic here
1198 /* instead of this, compare destination uri to mouse-over uri for validating window */
1199 if (webkit_navigation_action_is_user_gesture(a))
1201 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1202 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1203 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1204 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1205 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1212 return GTK_WIDGET(n->view);
1216 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1218 WebKitHitTestResultContext element;
1221 element = webkit_hit_test_result_get_context(c->mousepos);
1223 for (i = 0; i < LENGTH(buttons); ++i) {
1224 if (element & buttons[i].target &&
1225 e->button.button == buttons[i].button &&
1226 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1228 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1229 return buttons[i].stopevent;
1237 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1239 Client *c = (Client *)d;
1243 if (((XEvent *)e)->type == PropertyNotify) {
1244 ev = &((XEvent *)e)->xproperty;
1245 if (ev->state == PropertyNewValue) {
1246 if (ev->atom == atoms[AtomFind]) {
1249 return GDK_FILTER_REMOVE;
1250 } else if (ev->atom == atoms[AtomGo]) {
1251 a.v = getatom(c, AtomGo);
1254 return GDK_FILTER_REMOVE;
1258 return GDK_FILTER_CONTINUE;
1262 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1267 case GDK_ENTER_NOTIFY:
1268 c->overtitle = c->targeturi;
1272 if (!curconfig[KioskMode].val.i) {
1273 for (i = 0; i < LENGTH(keys); ++i) {
1274 if (gdk_keyval_to_lower(e->key.keyval) ==
1276 CLEANMASK(e->key.state) == keys[i].mod &&
1279 keys[i].func(c, &(keys[i].arg));
1284 case GDK_LEAVE_NOTIFY:
1285 c->overtitle = NULL;
1288 case GDK_WINDOW_STATE:
1289 if (e->window_state.changed_mask ==
1290 GDK_WINDOW_STATE_FULLSCREEN)
1291 c->fullscreen = e->window_state.new_window_state &
1292 GDK_WINDOW_STATE_FULLSCREEN;
1302 showview(WebKitWebView *v, Client *c)
1304 GdkRGBA bgcolor = { 0 };
1307 c->finder = webkit_web_view_get_find_controller(c->view);
1308 c->inspector = webkit_web_view_get_inspector(c->view);
1310 c->win = createwindow(c);
1312 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1313 gtk_widget_show_all(c->win);
1314 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1316 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1317 c->xid = gdk_x11_window_get_xid(gwin);
1320 gdk_display_sync(gtk_widget_get_display(c->win));
1324 if (curconfig[HideBackground].val.i)
1325 webkit_web_view_set_background_color(c->view, &bgcolor);
1327 if (!curconfig[KioskMode].val.i) {
1328 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1329 gdk_window_add_filter(gwin, processx, c);
1332 if (curconfig[RunInFullscreen].val.i)
1333 togglefullscreen(c, NULL);
1335 if (curconfig[ZoomLevel].val.f != 1.0)
1336 webkit_web_view_set_zoom_level(c->view,
1337 curconfig[ZoomLevel].val.f);
1339 setatom(c, AtomFind, "");
1340 setatom(c, AtomUri, "about:blank");
1344 createwindow(Client *c)
1350 w = gtk_plug_new(embed);
1352 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1354 wmstr = g_path_get_basename(argv0);
1355 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1358 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1359 webkit_web_view_get_page_id(c->view));
1360 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1363 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1366 g_signal_connect(G_OBJECT(w), "destroy",
1367 G_CALLBACK(destroywin), c);
1368 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1369 G_CALLBACK(winevent), c);
1370 g_signal_connect(G_OBJECT(w), "key-press-event",
1371 G_CALLBACK(winevent), c);
1372 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1373 G_CALLBACK(winevent), c);
1374 g_signal_connect(G_OBJECT(w), "window-state-event",
1375 G_CALLBACK(winevent), c);
1381 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1382 GTlsCertificateFlags err, Client *c)
1384 GString *errmsg = g_string_new(NULL);
1387 c->failedcert = g_object_ref(cert);
1391 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1392 g_string_append(errmsg,
1393 "The signing certificate authority is not known.<br>");
1394 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1395 g_string_append(errmsg,
1396 "The certificate does not match the expected identity "
1397 "of the site that it was retrieved from.<br>");
1398 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1399 g_string_append(errmsg,
1400 "The certificate's activation time "
1401 "is still in the future.<br>");
1402 if (err & G_TLS_CERTIFICATE_EXPIRED)
1403 g_string_append(errmsg, "The certificate has expired.<br>");
1404 if (err & G_TLS_CERTIFICATE_REVOKED)
1405 g_string_append(errmsg,
1406 "The certificate has been revoked according to "
1407 "the GTlsConnection's certificate revocation list.<br>");
1408 if (err & G_TLS_CERTIFICATE_INSECURE)
1409 g_string_append(errmsg,
1410 "The certificate's algorithm is considered insecure.<br>");
1411 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1412 g_string_append(errmsg,
1413 "Some error occurred validating the certificate.<br>");
1415 g_object_get(cert, "certificate-pem", &pem, NULL);
1416 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1417 "<p>You can inspect the following certificate "
1418 "with Ctrl-t (default keybinding).</p>"
1419 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1421 g_string_free(errmsg, TRUE);
1423 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1430 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1432 const char *uri = geturi(c);
1435 case WEBKIT_LOAD_STARTED:
1436 setatom(c, AtomUri, uri);
1438 c->https = c->insecure = 0;
1439 seturiparameters(c, uri, loadtransient);
1443 g_clear_object(&c->failedcert);
1445 case WEBKIT_LOAD_REDIRECTED:
1446 setatom(c, AtomUri, uri);
1448 seturiparameters(c, uri, loadtransient);
1450 case WEBKIT_LOAD_COMMITTED:
1451 seturiparameters(c, uri, loadcommitted);
1452 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1455 case WEBKIT_LOAD_FINISHED:
1456 seturiparameters(c, uri, loadfinished);
1457 /* Disabled until we write some WebKitWebExtension for
1458 * manipulating the DOM directly.
1459 evalscript(c, "document.documentElement.style.overflow = '%s'",
1460 enablescrollbars ? "auto" : "hidden");
1469 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1471 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1477 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1479 c->title = webkit_web_view_get_title(c->view);
1484 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1487 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1489 /* Keep the hit test to know where is the pointer on the next click */
1493 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1494 else if (hc & OnImg)
1495 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1496 else if (hc & OnMedia)
1497 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1499 c->targeturi = NULL;
1501 c->overtitle = c->targeturi;
1506 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1508 ParamName param = ParameterLast;
1510 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1511 param = Geolocation;
1512 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1513 if (webkit_user_media_permission_is_for_audio_device(
1514 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1515 param = AccessMicrophone;
1516 else if (webkit_user_media_permission_is_for_video_device(
1517 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1518 param = AccessWebcam;
1523 if (curconfig[param].val.i)
1524 webkit_permission_request_allow(r);
1526 webkit_permission_request_deny(r);
1532 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1533 WebKitPolicyDecisionType dt, Client *c)
1536 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1537 decidenavigation(d, c);
1539 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1540 decidenewwindow(d, c);
1542 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1543 decideresource(d, c);
1546 webkit_policy_decision_ignore(d);
1553 decidenavigation(WebKitPolicyDecision *d, Client *c)
1555 WebKitNavigationAction *a =
1556 webkit_navigation_policy_decision_get_navigation_action(
1557 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1559 switch (webkit_navigation_action_get_navigation_type(a)) {
1560 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1561 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1562 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1563 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1564 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1565 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1567 /* Do not navigate to links with a "_blank" target (popup) */
1568 if (webkit_navigation_policy_decision_get_frame_name(
1569 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1570 webkit_policy_decision_ignore(d);
1572 /* Filter out navigation to different domain ? */
1573 /* get action→urirequest, copy and load in new window+view
1574 * on Ctrl+Click ? */
1575 webkit_policy_decision_use(d);
1582 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1585 WebKitNavigationAction *a =
1586 webkit_navigation_policy_decision_get_navigation_action(
1587 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1590 switch (webkit_navigation_action_get_navigation_type(a)) {
1591 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1592 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1593 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1594 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1595 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1596 /* Filter domains here */
1597 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1598 * test for link clicked but no button ? */
1599 arg.v = webkit_uri_request_get_uri(
1600 webkit_navigation_action_get_request(a));
1601 newwindow(c, &arg, 0);
1603 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1608 webkit_policy_decision_ignore(d);
1612 decideresource(WebKitPolicyDecision *d, Client *c)
1615 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1616 WebKitURIResponse *res =
1617 webkit_response_policy_decision_get_response(r);
1618 const gchar *uri = webkit_uri_response_get_uri(res);
1620 if (g_str_has_suffix(uri, "/favicon.ico")) {
1621 webkit_policy_decision_ignore(d);
1625 if (!g_str_has_prefix(uri, "http://")
1626 && !g_str_has_prefix(uri, "https://")
1627 && !g_str_has_prefix(uri, "about:")
1628 && !g_str_has_prefix(uri, "file://")
1629 && !g_str_has_prefix(uri, "data:")
1630 && !g_str_has_prefix(uri, "blob:")
1631 && strlen(uri) > 0) {
1632 for (i = 0; i < strlen(uri); i++) {
1633 if (!g_ascii_isprint(uri[i])) {
1639 handleplumb(c, uri);
1640 webkit_policy_decision_ignore(d);
1645 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1646 webkit_policy_decision_use(d);
1648 webkit_policy_decision_ignore(d);
1654 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1660 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1662 g_signal_connect(G_OBJECT(d), "notify::response",
1663 G_CALLBACK(responsereceived), c);
1667 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1669 download(c, webkit_download_get_response(d));
1670 webkit_download_cancel(d);
1674 download(Client *c, WebKitURIResponse *r)
1676 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1681 closeview(WebKitWebView *v, Client *c)
1683 gtk_widget_destroy(c->win);
1687 destroywin(GtkWidget* w, Client *c)
1695 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1697 Arg a = {.v = text };
1699 loaduri((Client *) d, &a);
1703 reload(Client *c, const Arg *a)
1706 webkit_web_view_reload_bypass_cache(c->view);
1708 webkit_web_view_reload(c->view);
1712 print(Client *c, const Arg *a)
1714 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1715 GTK_WINDOW(c->win));
1719 showcert(Client *c, const Arg *a)
1721 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1722 GcrCertificate *gcrt;
1725 GcrCertificateWidget *wcert;
1730 g_object_get(cert, "certificate", &crt, NULL);
1731 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1732 g_byte_array_unref(crt);
1734 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1735 wcert = gcr_certificate_widget_new(gcrt);
1736 g_object_unref(gcrt);
1738 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1739 gtk_widget_show_all(win);
1743 clipboard(Client *c, const Arg *a)
1745 if (a->i) { /* load clipboard uri */
1746 gtk_clipboard_request_text(gtk_clipboard_get(
1747 GDK_SELECTION_PRIMARY),
1749 } else { /* copy uri */
1750 gtk_clipboard_set_text(gtk_clipboard_get(
1751 GDK_SELECTION_PRIMARY), c->targeturi
1752 ? c->targeturi : geturi(c), -1);
1757 zoom(Client *c, const Arg *a)
1760 webkit_web_view_set_zoom_level(c->view,
1761 curconfig[ZoomLevel].val.f + 0.1);
1763 webkit_web_view_set_zoom_level(c->view,
1764 curconfig[ZoomLevel].val.f - 0.1);
1766 webkit_web_view_set_zoom_level(c->view, 1.0);
1768 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1772 scroll(Client *c, const Arg *a)
1774 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1776 gdk_event_set_device(ev, gdkkb);
1777 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1778 ev->key.state = GDK_CONTROL_MASK;
1779 ev->key.time = GDK_CURRENT_TIME;
1783 ev->key.keyval = GDK_KEY_Down;
1786 ev->key.keyval = GDK_KEY_Page_Down;
1789 ev->key.keyval = GDK_KEY_Left;
1792 ev->key.keyval = GDK_KEY_Right;
1795 ev->key.keyval = GDK_KEY_Page_Up;
1798 ev->key.keyval = GDK_KEY_Up;
1806 navigate(Client *c, const Arg *a)
1809 webkit_web_view_go_back(c->view);
1811 webkit_web_view_go_forward(c->view);
1815 stop(Client *c, const Arg *a)
1817 webkit_web_view_stop_loading(c->view);
1821 toggle(Client *c, const Arg *a)
1823 curconfig[a->i].val.i ^= 1;
1824 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1828 togglefullscreen(Client *c, const Arg *a)
1830 /* toggling value is handled in winevent() */
1832 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1834 gtk_window_fullscreen(GTK_WINDOW(c->win));
1838 togglecookiepolicy(Client *c, const Arg *a)
1841 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1843 setparameter(c, 0, CookiePolicies, NULL);
1847 toggleinspector(Client *c, const Arg *a)
1849 if (webkit_web_inspector_is_attached(c->inspector))
1850 webkit_web_inspector_close(c->inspector);
1851 else if (curconfig[Inspector].val.i)
1852 webkit_web_inspector_show(c->inspector);
1856 find(Client *c, const Arg *a)
1862 webkit_find_controller_search_next(c->finder);
1864 webkit_find_controller_search_previous(c->finder);
1866 s = getatom(c, AtomFind);
1867 f = webkit_find_controller_get_search_text(c->finder);
1869 if (g_strcmp0(f, s) == 0) /* reset search */
1870 webkit_find_controller_search(c->finder, "", findopts,
1873 webkit_find_controller_search(c->finder, s, findopts,
1876 if (strcmp(s, "") == 0)
1877 webkit_find_controller_search_finish(c->finder);
1882 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1888 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1892 arg.v = webkit_hit_test_result_get_link_uri(h);
1893 newwindow(c, &arg, a->i);
1897 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1901 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1906 main(int argc, char *argv[])
1911 memset(&arg, 0, sizeof(arg));
1913 /* command line args */
1916 defconfig[CookiePolicies].val.v = EARGF(usage());
1917 defconfig[CookiePolicies].force = 1;
1920 defconfig[ScrollBars].val.i = 0;
1921 defconfig[ScrollBars].force = 1;
1924 defconfig[ScrollBars].val.i = 1;
1925 defconfig[ScrollBars].force = 1;
1928 cookiefile = EARGF(usage());
1931 stylefile = EARGF(usage());
1934 defconfig[DiskCache].val.i = 0;
1935 defconfig[DiskCache].force = 1;
1938 defconfig[DiskCache].val.i = 1;
1939 defconfig[DiskCache].force = 1;
1942 embed = strtol(EARGF(usage()), NULL, 0);
1945 defconfig[RunInFullscreen].val.i = 0;
1946 defconfig[RunInFullscreen].force = 1;
1949 defconfig[RunInFullscreen].val.i = 1;
1950 defconfig[RunInFullscreen].force = 1;
1953 defconfig[Geolocation].val.i = 0;
1954 defconfig[Geolocation].force = 1;
1957 defconfig[Geolocation].val.i = 1;
1958 defconfig[Geolocation].force = 1;
1961 defconfig[LoadImages].val.i = 0;
1962 defconfig[LoadImages].force = 1;
1965 defconfig[LoadImages].val.i = 1;
1966 defconfig[LoadImages].force = 1;
1969 defconfig[KioskMode].val.i = 0;
1970 defconfig[KioskMode].force = 1;
1973 defconfig[KioskMode].val.i = 1;
1974 defconfig[KioskMode].force = 1;
1977 defconfig[Style].val.i = 0;
1978 defconfig[Style].force = 1;
1981 defconfig[Style].val.i = 1;
1982 defconfig[Style].force = 1;
1985 defconfig[Inspector].val.i = 0;
1986 defconfig[Inspector].force = 1;
1989 defconfig[Inspector].val.i = 1;
1990 defconfig[Inspector].force = 1;
1993 defconfig[Plugins].val.i = 0;
1994 defconfig[Plugins].force = 1;
1997 defconfig[Plugins].val.i = 1;
1998 defconfig[Plugins].force = 1;
2001 scriptfile = EARGF(usage());
2004 defconfig[JavaScript].val.i = 0;
2005 defconfig[JavaScript].force = 1;
2008 defconfig[JavaScript].val.i = 1;
2009 defconfig[JavaScript].force = 1;
2012 defconfig[StrictTLS].val.i = 0;
2013 defconfig[StrictTLS].force = 1;
2016 defconfig[StrictTLS].val.i = 1;
2017 defconfig[StrictTLS].force = 1;
2020 fulluseragent = EARGF(usage());
2023 die("surf-"VERSION", see LICENSE for © details\n");
2028 defconfig[Certificate].val.i = 0;
2029 defconfig[Certificate].force = 1;
2032 defconfig[Certificate].val.i = 1;
2033 defconfig[Certificate].force = 1;
2036 defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
2037 defconfig[ZoomLevel].force = 1;
2045 arg.v = "about:blank";
2048 c = newclient(NULL);