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,
98 typedef struct Client {
101 WebKitWebInspector *inspector;
102 WebKitFindController *finder;
103 WebKitHitTestResult *mousepos;
104 GTlsCertificate *cert, *failedcert;
105 GTlsCertificateFlags tlserr;
107 int progress, fullscreen, https, insecure, errorpage;
108 const char *title, *overtitle, *targeturi;
116 void (*func)(Client *c, const Arg *a);
124 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
126 unsigned int stopevent;
131 Parameter config[ParameterLast];
142 static void usage(void);
143 static void die(const char *errstr, ...);
144 static void setup(void);
145 static void sigchld(int unused);
146 static void sighup(int unused);
147 static char *buildfile(const char *path);
148 static char *buildpath(const char *path);
149 static const char *getuserhomedir(const char *user);
150 static const char *getcurrentuserhomedir(void);
151 static Client *newclient(Client *c);
152 static void loaduri(Client *c, const Arg *a);
153 static const char *geturi(Client *c);
154 static void setatom(Client *c, int a, const char *v);
155 static const char *getatom(Client *c, int a);
156 static void updatetitle(Client *c);
157 static void gettogglestats(Client *c);
158 static void getpagestats(Client *c);
159 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
160 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
161 static void seturiparameters(Client *c, const char *uri, ParamName *params);
162 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
163 static const char *getcert(const char *uri);
164 static void setcert(Client *c, const char *file);
165 static const char *getstyle(const char *uri);
166 static void setstyle(Client *c, const char *file);
167 static void runscript(Client *c);
168 static void evalscript(Client *c, const char *jsstr, ...);
169 static void updatewinid(Client *c);
170 static void handleplumb(Client *c, const char *uri);
171 static void newwindow(Client *c, const Arg *a, int noembed);
172 static void spawn(Client *c, const Arg *a);
173 static void destroyclient(Client *c);
174 static void cleanup(void);
177 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
178 static void initwebextensions(WebKitWebContext *wc, Client *c);
179 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
181 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
182 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
184 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
185 static void showview(WebKitWebView *v, Client *c);
186 static GtkWidget *createwindow(Client *c);
187 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
188 GTlsCertificate *cert,
189 GTlsCertificateFlags err, Client *c);
190 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
191 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
192 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
193 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
194 guint modifiers, Client *c);
195 static gboolean permissionrequested(WebKitWebView *v,
196 WebKitPermissionRequest *r, Client *c);
197 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
198 WebKitPolicyDecisionType dt, Client *c);
199 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
200 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
201 static void decideresource(WebKitPolicyDecision *d, Client *c);
202 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
204 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
206 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
207 static void download(Client *c, WebKitURIResponse *r);
208 static void closeview(WebKitWebView *v, Client *c);
209 static void destroywin(GtkWidget* w, Client *c);
212 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
213 static void reload(Client *c, const Arg *a);
214 static void print(Client *c, const Arg *a);
215 static void showcert(Client *c, const Arg *a);
216 static void clipboard(Client *c, const Arg *a);
217 static void zoom(Client *c, const Arg *a);
218 static void scroll(Client *c, const Arg *a);
219 static void navigate(Client *c, const Arg *a);
220 static void stop(Client *c, const Arg *a);
221 static void toggle(Client *c, const Arg *a);
222 static void togglefullscreen(Client *c, const Arg *a);
223 static void togglecookiepolicy(Client *c, const Arg *a);
224 static void toggleinspector(Client *c, const Arg *a);
225 static void find(Client *c, const Arg *a);
228 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
229 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
230 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
232 static char winid[64];
233 static char togglestats[12];
234 static char pagestats[2];
235 static Atom atoms[AtomLast];
238 static int cookiepolicy;
240 static Client *clients;
241 static GdkDevice *gdkkb;
242 static char *stylefile;
243 static const char *useragent;
244 static Parameter *curconfig;
245 static int modparams[ParameterLast];
248 static ParamName loadtransient[] = {
262 static ParamName loadcommitted[] = {
288 static ParamName loadfinished[] = {
292 /* configuration, allows nested code to access above variables */
298 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
299 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
300 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
304 die(const char *errstr, ...)
308 va_start(ap, errstr);
309 vfprintf(stderr, errstr, ap);
320 /* clean up any zombies immediately */
322 if (signal(SIGHUP, sighup) == SIG_ERR)
323 die("Can't install SIGHUP handler");
325 if (!(dpy = XOpenDisplay(NULL)))
326 die("Can't open default display");
329 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
330 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
331 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
333 gtk_init(NULL, NULL);
335 gdpy = gdk_display_get_default();
337 curconfig = defconfig;
340 cookiefile = buildfile(cookiefile);
341 scriptfile = buildfile(scriptfile);
342 cachedir = buildpath(cachedir);
343 certdir = buildpath(certdir);
345 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
347 for (i = 0; i < LENGTH(certs); ++i) {
348 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
349 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
352 fprintf(stderr, "Could not compile regex: %s\n",
354 certs[i].regex = NULL;
359 styledir = buildpath(styledir);
360 for (i = 0; i < LENGTH(styles); ++i) {
361 if (!regcomp(&(styles[i].re), styles[i].regex,
363 styles[i].file = g_strconcat(styledir, "/",
364 styles[i].file, NULL);
366 fprintf(stderr, "Could not compile regex: %s\n",
368 styles[i].regex = NULL;
373 stylefile = buildfile(stylefile);
376 for (i = 0; i < LENGTH(uriparams); ++i) {
377 if (regcomp(&(uriparams[i].re), uriparams[i].uri,
379 fprintf(stderr, "Could not compile regex: %s\n",
381 uriparams[i].uri = NULL;
385 /* copy default parameters with higher priority */
386 for (j = 0; j < ParameterLast; ++j) {
387 if (defconfig[j].prio >= uriparams[i].config[j].prio)
388 uriparams[i].config[j] = defconfig[j];
396 if (signal(SIGCHLD, sigchld) == SIG_ERR)
397 die("Can't install SIGCHLD handler");
398 while (waitpid(-1, NULL, WNOHANG) > 0)
408 for (c = clients; c; c = c->next)
413 buildfile(const char *path)
415 char *dname, *bname, *bpath, *fpath;
418 dname = g_path_get_dirname(path);
419 bname = g_path_get_basename(path);
421 bpath = buildpath(dname);
424 fpath = g_build_filename(bpath, bname, NULL);
428 if (!(f = fopen(fpath, "a")))
429 die("Could not open file: %s\n", fpath);
431 g_chmod(fpath, 0600); /* always */
438 getuserhomedir(const char *user)
440 struct passwd *pw = getpwnam(user);
443 die("Can't get user %s login information.\n", user);
449 getcurrentuserhomedir(void)
455 homedir = getenv("HOME");
459 user = getenv("USER");
461 return getuserhomedir(user);
463 pw = getpwuid(getuid());
465 die("Can't get current user home directory\n");
471 buildpath(const char *path)
473 char *apath, *name, *p, *fpath;
476 if (path[0] == '~') {
477 if (path[1] == '/' || path[1] == '\0') {
478 p = (char *)&path[1];
479 homedir = getcurrentuserhomedir();
481 if ((p = strchr(path, '/')))
482 name = g_strndup(&path[1], --p - path);
484 name = g_strdup(&path[1]);
486 homedir = getuserhomedir(name);
489 apath = g_build_filename(homedir, p, NULL);
491 apath = g_strdup(path);
494 /* creating directory */
495 if (g_mkdir_with_parents(apath, 0700) < 0)
496 die("Could not access directory: %s\n", apath);
498 fpath = realpath(apath, NULL);
505 newclient(Client *rc)
509 if (!(c = calloc(1, sizeof(Client))))
510 die("Cannot malloc!\n");
516 c->view = newview(c, rc ? rc->view : NULL);
522 loaduri(Client *c, const Arg *a)
526 const char *uri = a->v;
528 if (g_strcmp0(uri, "") == 0)
531 if (g_str_has_prefix(uri, "http://") ||
532 g_str_has_prefix(uri, "https://") ||
533 g_str_has_prefix(uri, "file://") ||
534 g_str_has_prefix(uri, "about:")) {
536 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
537 url = g_strdup_printf("file://%s", path);
540 url = g_strdup_printf("http://%s", uri);
543 setatom(c, AtomUri, url);
545 if (strcmp(url, geturi(c)) == 0) {
548 webkit_web_view_load_uri(c->view, url);
560 if (!(uri = webkit_web_view_get_uri(c->view)))
566 setatom(Client *c, int a, const char *v)
568 XChangeProperty(dpy, c->xid,
569 atoms[a], XA_STRING, 8, PropModeReplace,
570 (unsigned char *)v, strlen(v) + 1);
575 getatom(Client *c, int a)
577 static char buf[BUFSIZ];
580 unsigned long ldummy;
581 unsigned char *p = NULL;
584 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
585 &adummy, &idummy, &ldummy, &ldummy, &p);
587 strncpy(buf, (char *)p, LENGTH(buf) - 1);
596 updatetitle(Client *c)
599 const char *name = c->overtitle ? c->overtitle :
600 c->title ? c->title : "";
602 if (curconfig[ShowIndicators].val.i) {
606 if (c->progress != 100)
607 title = g_strdup_printf("[%i%%] %s:%s | %s",
608 c->progress, togglestats, pagestats, name);
610 title = g_strdup_printf("%s:%s | %s",
611 togglestats, pagestats, name);
613 gtk_window_set_title(GTK_WINDOW(c->win), title);
616 gtk_window_set_title(GTK_WINDOW(c->win), name);
621 gettogglestats(Client *c)
623 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
624 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
625 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
626 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
627 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
628 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
629 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
630 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
631 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
632 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
633 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
634 togglestats[11] = '\0';
638 getpagestats(Client *c)
641 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
647 WebKitCookieAcceptPolicy
648 cookiepolicy_get(void)
650 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
652 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
654 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
655 default: /* fallthrough */
657 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
662 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
665 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
667 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
669 default: /* fallthrough */
670 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
676 seturiparameters(Client *c, const char *uri, ParamName *params)
678 Parameter *config, *uriconfig = NULL;
681 for (i = 0; i < LENGTH(uriparams); ++i) {
682 if (uriparams[i].uri &&
683 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
684 uriconfig = uriparams[i].config;
689 curconfig = uriconfig ? uriconfig : defconfig;
691 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
693 default: /* FALLTHROUGH */
694 if (!(defconfig[p].prio < curconfig[p].prio ||
695 defconfig[p].prio < modparams[p]))
700 setparameter(c, 0, p, &curconfig[p].val);
706 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
708 GdkRGBA bgcolor = { 0 };
709 WebKitSettings *s = webkit_web_view_get_settings(c->view);
711 modparams[p] = curconfig[p].prio;
714 case AcceleratedCanvas:
715 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
717 case AccessMicrophone:
718 return; /* do nothing */
720 return; /* do nothing */
722 webkit_settings_set_enable_caret_browsing(s, a->i);
727 setcert(c, geturi(c));
728 return; /* do not update */
730 webkit_cookie_manager_set_accept_policy(
731 webkit_web_context_get_cookie_manager(
732 webkit_web_view_get_context(c->view)),
737 webkit_web_context_set_cache_model(
738 webkit_web_view_get_context(c->view), a->i ?
739 WEBKIT_CACHE_MODEL_WEB_BROWSER :
740 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
741 return; /* do not update */
743 webkit_settings_set_default_charset(s, a->v);
744 return; /* do not update */
746 webkit_settings_set_enable_dns_prefetching(s, a->i);
747 return; /* do not update */
748 case FileURLsCrossAccess:
749 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
750 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
751 return; /* do not update */
753 webkit_settings_set_default_font_size(s, a->i);
754 return; /* do not update */
755 case FrameFlattening:
756 webkit_settings_set_enable_frame_flattening(s, a->i);
763 webkit_web_view_set_background_color(c->view, &bgcolor);
764 return; /* do not update */
766 webkit_settings_set_enable_developer_extras(s, a->i);
767 return; /* do not update */
769 webkit_settings_set_enable_java(s, a->i);
770 return; /* do not update */
772 webkit_settings_set_enable_javascript(s, a->i);
775 return; /* do nothing */
777 webkit_settings_set_auto_load_images(s, a->i);
779 case MediaManualPlay:
780 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
783 webkit_settings_set_enable_plugins(s, a->i);
785 case PreferredLanguages:
786 return; /* do nothing */
787 case RunInFullscreen:
788 return; /* do nothing */
790 /* Disabled until we write some WebKitWebExtension for
791 * manipulating the DOM directly.
792 enablescrollbars = !enablescrollbars;
793 evalscript(c, "document.documentElement.style.overflow = '%s'",
794 enablescrollbars ? "auto" : "hidden");
796 return; /* do not update */
799 case SmoothScrolling:
800 webkit_settings_set_enable_smooth_scrolling(s, a->i);
801 return; /* do not update */
803 webkit_settings_set_enable_site_specific_quirks(s, a->i);
806 webkit_web_context_set_spell_checking_enabled(
807 webkit_web_view_get_context(c->view), a->i);
808 return; /* do not update */
810 return; /* do nothing */
812 webkit_web_context_set_tls_errors_policy(
813 webkit_web_view_get_context(c->view), a->i ?
814 WEBKIT_TLS_ERRORS_POLICY_FAIL :
815 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
818 webkit_user_content_manager_remove_all_style_sheets(
819 webkit_web_view_get_user_content_manager(c->view));
821 setstyle(c, getstyle(geturi(c)));
825 webkit_settings_set_enable_webgl(s, a->i);
828 webkit_web_view_set_zoom_level(c->view, a->f);
829 return; /* do not update */
831 return; /* do nothing */
840 getcert(const char *uri)
844 for (i = 0; i < LENGTH(certs); ++i) {
845 if (certs[i].regex &&
846 !regexec(&(certs[i].re), uri, 0, NULL, 0))
847 return certs[i].file;
854 setcert(Client *c, const char *uri)
856 const char *file = getcert(uri);
858 GTlsCertificate *cert;
863 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
864 fprintf(stderr, "Could not read certificate file: %s\n", file);
868 if ((uri = strstr(uri, "https://"))) {
869 uri += sizeof("https://") - 1;
870 host = g_strndup(uri, strchr(uri, '/') - uri);
871 webkit_web_context_allow_tls_certificate_for_host(
872 webkit_web_view_get_context(c->view), cert, host);
876 g_object_unref(cert);
881 getstyle(const char *uri)
888 for (i = 0; i < LENGTH(styles); ++i) {
889 if (styles[i].regex &&
890 !regexec(&(styles[i].re), uri, 0, NULL, 0))
891 return styles[i].file;
898 setstyle(Client *c, const char *file)
902 if (!g_file_get_contents(file, &style, NULL, NULL)) {
903 fprintf(stderr, "Could not read style file: %s\n", file);
907 webkit_user_content_manager_add_style_sheet(
908 webkit_web_view_get_user_content_manager(c->view),
909 webkit_user_style_sheet_new(style,
910 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
911 WEBKIT_USER_STYLE_LEVEL_USER,
923 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
924 evalscript(c, "%s", script);
929 evalscript(Client *c, const char *jsstr, ...)
935 script = g_strdup_vprintf(jsstr, ap);
938 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
943 updatewinid(Client *c)
945 snprintf(winid, LENGTH(winid), "%lu", c->xid);
949 handleplumb(Client *c, const char *uri)
951 Arg a = (Arg)PLUMB(uri);
956 newwindow(Client *c, const Arg *a, int noembed)
960 const char *cmd[29], *uri;
961 const Arg arg = { .v = cmd };
965 cmd[i++] = curconfig[CookiePolicies].val.v;
966 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
967 if (cookiefile && g_strcmp0(cookiefile, "")) {
969 cmd[i++] = cookiefile;
971 if (stylefile && g_strcmp0(stylefile, "")) {
973 cmd[i++] = stylefile;
975 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
976 if (embed && !noembed) {
978 snprintf(tmp, LENGTH(tmp), "%lu", embed);
981 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
982 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
983 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
984 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
985 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
986 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
987 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
988 if (scriptfile && g_strcmp0(scriptfile, "")) {
990 cmd[i++] = scriptfile;
992 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
993 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
994 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
996 cmd[i++] = fulluseragent;
1000 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1001 /* do not keep zoom level */
1011 spawn(Client *c, const Arg *a)
1015 close(ConnectionNumber(dpy));
1017 execvp(((char **)a->v)[0], (char **)a->v);
1018 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1025 destroyclient(Client *c)
1029 webkit_web_view_stop_loading(c->view);
1030 /* Not needed, has already been called
1031 gtk_widget_destroy(c->win);
1034 for (p = clients; p && p->next != c; p = p->next)
1047 destroyclient(clients);
1056 newview(Client *c, WebKitWebView *rv)
1059 WebKitSettings *settings;
1060 WebKitUserContentManager *contentmanager;
1061 WebKitWebContext *context;
1065 v = WEBKIT_WEB_VIEW(
1066 webkit_web_view_new_with_related_view(rv));
1068 settings = webkit_settings_new_with_settings(
1069 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1070 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1071 "auto-load-images", curconfig[LoadImages].val.i,
1072 "default-charset", curconfig[DefaultCharset].val.v,
1073 "default-font-size", curconfig[FontSize].val.i,
1074 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1075 "enable-developer-extras", curconfig[Inspector].val.i,
1076 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1077 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1078 "enable-html5-database", curconfig[DiskCache].val.i,
1079 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1080 "enable-java", curconfig[Java].val.i,
1081 "enable-javascript", curconfig[JavaScript].val.i,
1082 "enable-plugins", curconfig[Plugins].val.i,
1083 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1084 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1085 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1086 "enable-webgl", curconfig[WebGL].val.i,
1087 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1089 /* For more interesting settings, have a look at
1090 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1092 if (strcmp(fulluseragent, "")) {
1093 webkit_settings_set_user_agent(settings, fulluseragent);
1094 } else if (surfuseragent) {
1095 webkit_settings_set_user_agent_with_application_details(
1096 settings, "Surf", VERSION);
1098 useragent = webkit_settings_get_user_agent(settings);
1100 contentmanager = webkit_user_content_manager_new();
1102 context = webkit_web_context_new_with_website_data_manager(
1103 webkit_website_data_manager_new(
1104 "base-cache-directory", cachedir,
1105 "base-data-directory", cachedir,
1108 /* rendering process model, can be a shared unique one
1109 * or one for each view */
1110 webkit_web_context_set_process_model(context,
1111 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1113 webkit_web_context_set_tls_errors_policy(context,
1114 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1115 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1117 webkit_web_context_set_cache_model(context,
1118 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1119 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1121 /* Currently only works with text file to be compatible with curl */
1122 webkit_cookie_manager_set_persistent_storage(
1123 webkit_web_context_get_cookie_manager(context), cookiefile,
1124 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1126 webkit_cookie_manager_set_accept_policy(
1127 webkit_web_context_get_cookie_manager(context),
1128 cookiepolicy_get());
1130 webkit_web_context_set_preferred_languages(context,
1131 curconfig[PreferredLanguages].val.v);
1132 webkit_web_context_set_spell_checking_languages(context,
1133 curconfig[SpellLanguages].val.v);
1134 webkit_web_context_set_spell_checking_enabled(context,
1135 curconfig[SpellChecking].val.i);
1137 g_signal_connect(G_OBJECT(context), "download-started",
1138 G_CALLBACK(downloadstarted), c);
1139 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1140 G_CALLBACK(initwebextensions), c);
1142 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1143 "settings", settings,
1144 "user-content-manager", contentmanager,
1145 "web-context", context,
1149 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1150 G_CALLBACK(progresschanged), c);
1151 g_signal_connect(G_OBJECT(v), "notify::title",
1152 G_CALLBACK(titlechanged), c);
1153 g_signal_connect(G_OBJECT(v), "button-release-event",
1154 G_CALLBACK(buttonreleased), c);
1155 g_signal_connect(G_OBJECT(v), "close",
1156 G_CALLBACK(closeview), c);
1157 g_signal_connect(G_OBJECT(v), "create",
1158 G_CALLBACK(createview), c);
1159 g_signal_connect(G_OBJECT(v), "decide-policy",
1160 G_CALLBACK(decidepolicy), c);
1161 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1162 G_CALLBACK(insecurecontent), c);
1163 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1164 G_CALLBACK(loadfailedtls), c);
1165 g_signal_connect(G_OBJECT(v), "load-changed",
1166 G_CALLBACK(loadchanged), c);
1167 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1168 G_CALLBACK(mousetargetchanged), c);
1169 g_signal_connect(G_OBJECT(v), "permission-request",
1170 G_CALLBACK(permissionrequested), c);
1171 g_signal_connect(G_OBJECT(v), "ready-to-show",
1172 G_CALLBACK(showview), c);
1178 initwebextensions(WebKitWebContext *wc, Client *c)
1180 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1184 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1188 switch (webkit_navigation_action_get_navigation_type(a)) {
1189 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1191 * popup windows of type “other” are almost always triggered
1192 * by user gesture, so inverse the logic here
1194 /* instead of this, compare destination uri to mouse-over uri for validating window */
1195 if (webkit_navigation_action_is_user_gesture(a))
1197 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1198 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1199 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1200 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1201 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1208 return GTK_WIDGET(n->view);
1212 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1214 WebKitHitTestResultContext element;
1217 element = webkit_hit_test_result_get_context(c->mousepos);
1219 for (i = 0; i < LENGTH(buttons); ++i) {
1220 if (element & buttons[i].target &&
1221 e->button.button == buttons[i].button &&
1222 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1224 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1225 return buttons[i].stopevent;
1233 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1235 Client *c = (Client *)d;
1239 if (((XEvent *)e)->type == PropertyNotify) {
1240 ev = &((XEvent *)e)->xproperty;
1241 if (ev->state == PropertyNewValue) {
1242 if (ev->atom == atoms[AtomFind]) {
1245 return GDK_FILTER_REMOVE;
1246 } else if (ev->atom == atoms[AtomGo]) {
1247 a.v = getatom(c, AtomGo);
1250 return GDK_FILTER_REMOVE;
1254 return GDK_FILTER_CONTINUE;
1258 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1263 case GDK_ENTER_NOTIFY:
1264 c->overtitle = c->targeturi;
1268 if (!curconfig[KioskMode].val.i) {
1269 for (i = 0; i < LENGTH(keys); ++i) {
1270 if (gdk_keyval_to_lower(e->key.keyval) ==
1272 CLEANMASK(e->key.state) == keys[i].mod &&
1275 keys[i].func(c, &(keys[i].arg));
1280 case GDK_LEAVE_NOTIFY:
1281 c->overtitle = NULL;
1284 case GDK_WINDOW_STATE:
1285 if (e->window_state.changed_mask ==
1286 GDK_WINDOW_STATE_FULLSCREEN)
1287 c->fullscreen = e->window_state.new_window_state &
1288 GDK_WINDOW_STATE_FULLSCREEN;
1298 showview(WebKitWebView *v, Client *c)
1300 GdkRGBA bgcolor = { 0 };
1303 c->finder = webkit_web_view_get_find_controller(c->view);
1304 c->inspector = webkit_web_view_get_inspector(c->view);
1306 c->win = createwindow(c);
1308 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1309 gtk_widget_show_all(c->win);
1310 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1312 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1313 c->xid = gdk_x11_window_get_xid(gwin);
1316 gdk_display_sync(gtk_widget_get_display(c->win));
1320 if (curconfig[HideBackground].val.i)
1321 webkit_web_view_set_background_color(c->view, &bgcolor);
1323 if (!curconfig[KioskMode].val.i) {
1324 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1325 gdk_window_add_filter(gwin, processx, c);
1328 if (curconfig[RunInFullscreen].val.i)
1329 togglefullscreen(c, NULL);
1331 if (curconfig[ZoomLevel].val.f != 1.0)
1332 webkit_web_view_set_zoom_level(c->view,
1333 curconfig[ZoomLevel].val.f);
1335 setatom(c, AtomFind, "");
1336 setatom(c, AtomUri, "about:blank");
1340 createwindow(Client *c)
1346 w = gtk_plug_new(embed);
1348 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1350 wmstr = g_path_get_basename(argv0);
1351 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1354 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1355 webkit_web_view_get_page_id(c->view));
1356 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1359 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1362 g_signal_connect(G_OBJECT(w), "destroy",
1363 G_CALLBACK(destroywin), c);
1364 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1365 G_CALLBACK(winevent), c);
1366 g_signal_connect(G_OBJECT(w), "key-press-event",
1367 G_CALLBACK(winevent), c);
1368 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1369 G_CALLBACK(winevent), c);
1370 g_signal_connect(G_OBJECT(w), "window-state-event",
1371 G_CALLBACK(winevent), c);
1377 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1378 GTlsCertificateFlags err, Client *c)
1380 GString *errmsg = g_string_new(NULL);
1383 c->failedcert = g_object_ref(cert);
1387 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1388 g_string_append(errmsg,
1389 "The signing certificate authority is not known.<br>");
1390 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1391 g_string_append(errmsg,
1392 "The certificate does not match the expected identity "
1393 "of the site that it was retrieved from.<br>");
1394 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1395 g_string_append(errmsg,
1396 "The certificate's activation time "
1397 "is still in the future.<br>");
1398 if (err & G_TLS_CERTIFICATE_EXPIRED)
1399 g_string_append(errmsg, "The certificate has expired.<br>");
1400 if (err & G_TLS_CERTIFICATE_REVOKED)
1401 g_string_append(errmsg,
1402 "The certificate has been revoked according to "
1403 "the GTlsConnection's certificate revocation list.<br>");
1404 if (err & G_TLS_CERTIFICATE_INSECURE)
1405 g_string_append(errmsg,
1406 "The certificate's algorithm is considered insecure.<br>");
1407 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1408 g_string_append(errmsg,
1409 "Some error occurred validating the certificate.<br>");
1411 g_object_get(cert, "certificate-pem", &pem, NULL);
1412 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1413 "<p>You can inspect the following certificate "
1414 "with Ctrl-t (default keybinding).</p>"
1415 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1417 g_string_free(errmsg, TRUE);
1419 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1426 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1428 const char *uri = geturi(c);
1431 case WEBKIT_LOAD_STARTED:
1432 setatom(c, AtomUri, uri);
1434 c->https = c->insecure = 0;
1435 seturiparameters(c, uri, loadtransient);
1439 g_clear_object(&c->failedcert);
1441 case WEBKIT_LOAD_REDIRECTED:
1442 setatom(c, AtomUri, uri);
1444 seturiparameters(c, uri, loadtransient);
1446 case WEBKIT_LOAD_COMMITTED:
1447 seturiparameters(c, uri, loadcommitted);
1448 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1451 case WEBKIT_LOAD_FINISHED:
1452 seturiparameters(c, uri, loadfinished);
1453 /* Disabled until we write some WebKitWebExtension for
1454 * manipulating the DOM directly.
1455 evalscript(c, "document.documentElement.style.overflow = '%s'",
1456 enablescrollbars ? "auto" : "hidden");
1465 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1467 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1473 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1475 c->title = webkit_web_view_get_title(c->view);
1480 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1483 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1485 /* Keep the hit test to know where is the pointer on the next click */
1489 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1490 else if (hc & OnImg)
1491 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1492 else if (hc & OnMedia)
1493 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1495 c->targeturi = NULL;
1497 c->overtitle = c->targeturi;
1502 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1504 ParamName param = ParameterLast;
1506 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1507 param = Geolocation;
1508 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1509 if (webkit_user_media_permission_is_for_audio_device(
1510 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1511 param = AccessMicrophone;
1512 else if (webkit_user_media_permission_is_for_video_device(
1513 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1514 param = AccessWebcam;
1519 if (curconfig[param].val.i)
1520 webkit_permission_request_allow(r);
1522 webkit_permission_request_deny(r);
1528 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1529 WebKitPolicyDecisionType dt, Client *c)
1532 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1533 decidenavigation(d, c);
1535 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1536 decidenewwindow(d, c);
1538 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1539 decideresource(d, c);
1542 webkit_policy_decision_ignore(d);
1549 decidenavigation(WebKitPolicyDecision *d, Client *c)
1551 WebKitNavigationAction *a =
1552 webkit_navigation_policy_decision_get_navigation_action(
1553 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1555 switch (webkit_navigation_action_get_navigation_type(a)) {
1556 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1557 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1558 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1559 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1560 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1561 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1563 /* Do not navigate to links with a "_blank" target (popup) */
1564 if (webkit_navigation_policy_decision_get_frame_name(
1565 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1566 webkit_policy_decision_ignore(d);
1568 /* Filter out navigation to different domain ? */
1569 /* get action→urirequest, copy and load in new window+view
1570 * on Ctrl+Click ? */
1571 webkit_policy_decision_use(d);
1578 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1581 WebKitNavigationAction *a =
1582 webkit_navigation_policy_decision_get_navigation_action(
1583 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1586 switch (webkit_navigation_action_get_navigation_type(a)) {
1587 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1588 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1589 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1590 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1591 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1592 /* Filter domains here */
1593 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1594 * test for link clicked but no button ? */
1595 arg.v = webkit_uri_request_get_uri(
1596 webkit_navigation_action_get_request(a));
1597 newwindow(c, &arg, 0);
1599 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1604 webkit_policy_decision_ignore(d);
1608 decideresource(WebKitPolicyDecision *d, Client *c)
1611 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1612 WebKitURIResponse *res =
1613 webkit_response_policy_decision_get_response(r);
1614 const gchar *uri = webkit_uri_response_get_uri(res);
1616 if (g_str_has_suffix(uri, "/favicon.ico")) {
1617 webkit_policy_decision_ignore(d);
1621 if (!g_str_has_prefix(uri, "http://")
1622 && !g_str_has_prefix(uri, "https://")
1623 && !g_str_has_prefix(uri, "about:")
1624 && !g_str_has_prefix(uri, "file://")
1625 && !g_str_has_prefix(uri, "data:")
1626 && !g_str_has_prefix(uri, "blob:")
1627 && strlen(uri) > 0) {
1628 for (i = 0; i < strlen(uri); i++) {
1629 if (!g_ascii_isprint(uri[i])) {
1635 handleplumb(c, uri);
1636 webkit_policy_decision_ignore(d);
1641 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1642 webkit_policy_decision_use(d);
1644 webkit_policy_decision_ignore(d);
1650 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1656 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1658 g_signal_connect(G_OBJECT(d), "notify::response",
1659 G_CALLBACK(responsereceived), c);
1663 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1665 download(c, webkit_download_get_response(d));
1666 webkit_download_cancel(d);
1670 download(Client *c, WebKitURIResponse *r)
1672 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1677 closeview(WebKitWebView *v, Client *c)
1679 gtk_widget_destroy(c->win);
1683 destroywin(GtkWidget* w, Client *c)
1691 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1693 Arg a = {.v = text };
1695 loaduri((Client *) d, &a);
1699 reload(Client *c, const Arg *a)
1702 webkit_web_view_reload_bypass_cache(c->view);
1704 webkit_web_view_reload(c->view);
1708 print(Client *c, const Arg *a)
1710 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1711 GTK_WINDOW(c->win));
1715 showcert(Client *c, const Arg *a)
1717 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1718 GcrCertificate *gcrt;
1721 GcrCertificateWidget *wcert;
1726 g_object_get(cert, "certificate", &crt, NULL);
1727 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1728 g_byte_array_unref(crt);
1730 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1731 wcert = gcr_certificate_widget_new(gcrt);
1732 g_object_unref(gcrt);
1734 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1735 gtk_widget_show_all(win);
1739 clipboard(Client *c, const Arg *a)
1741 if (a->i) { /* load clipboard uri */
1742 gtk_clipboard_request_text(gtk_clipboard_get(
1743 GDK_SELECTION_PRIMARY),
1745 } else { /* copy uri */
1746 gtk_clipboard_set_text(gtk_clipboard_get(
1747 GDK_SELECTION_PRIMARY), c->targeturi
1748 ? c->targeturi : geturi(c), -1);
1753 zoom(Client *c, const Arg *a)
1756 webkit_web_view_set_zoom_level(c->view,
1757 curconfig[ZoomLevel].val.f + 0.1);
1759 webkit_web_view_set_zoom_level(c->view,
1760 curconfig[ZoomLevel].val.f - 0.1);
1762 webkit_web_view_set_zoom_level(c->view, 1.0);
1764 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1768 scroll(Client *c, const Arg *a)
1770 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1772 gdk_event_set_device(ev, gdkkb);
1773 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1774 ev->key.state = GDK_CONTROL_MASK;
1775 ev->key.time = GDK_CURRENT_TIME;
1779 ev->key.keyval = GDK_KEY_Down;
1782 ev->key.keyval = GDK_KEY_Page_Down;
1785 ev->key.keyval = GDK_KEY_Left;
1788 ev->key.keyval = GDK_KEY_Right;
1791 ev->key.keyval = GDK_KEY_Page_Up;
1794 ev->key.keyval = GDK_KEY_Up;
1802 navigate(Client *c, const Arg *a)
1805 webkit_web_view_go_back(c->view);
1807 webkit_web_view_go_forward(c->view);
1811 stop(Client *c, const Arg *a)
1813 webkit_web_view_stop_loading(c->view);
1817 toggle(Client *c, const Arg *a)
1819 curconfig[a->i].val.i ^= 1;
1820 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1824 togglefullscreen(Client *c, const Arg *a)
1826 /* toggling value is handled in winevent() */
1828 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1830 gtk_window_fullscreen(GTK_WINDOW(c->win));
1834 togglecookiepolicy(Client *c, const Arg *a)
1837 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1839 setparameter(c, 0, CookiePolicies, NULL);
1843 toggleinspector(Client *c, const Arg *a)
1845 if (webkit_web_inspector_is_attached(c->inspector))
1846 webkit_web_inspector_close(c->inspector);
1847 else if (curconfig[Inspector].val.i)
1848 webkit_web_inspector_show(c->inspector);
1852 find(Client *c, const Arg *a)
1858 webkit_find_controller_search_next(c->finder);
1860 webkit_find_controller_search_previous(c->finder);
1862 s = getatom(c, AtomFind);
1863 f = webkit_find_controller_get_search_text(c->finder);
1865 if (g_strcmp0(f, s) == 0) /* reset search */
1866 webkit_find_controller_search(c->finder, "", findopts,
1869 webkit_find_controller_search(c->finder, s, findopts,
1872 if (strcmp(s, "") == 0)
1873 webkit_find_controller_search_finish(c->finder);
1878 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1884 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1888 arg.v = webkit_hit_test_result_get_link_uri(h);
1889 newwindow(c, &arg, a->i);
1893 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1897 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1902 main(int argc, char *argv[])
1907 memset(&arg, 0, sizeof(arg));
1909 /* command line args */
1912 defconfig[CookiePolicies].val.v = EARGF(usage());
1913 defconfig[CookiePolicies].prio = 2;
1916 defconfig[ScrollBars].val.i = 0;
1917 defconfig[ScrollBars].prio = 2;
1920 defconfig[ScrollBars].val.i = 1;
1921 defconfig[ScrollBars].prio = 2;
1924 cookiefile = EARGF(usage());
1927 stylefile = EARGF(usage());
1930 defconfig[DiskCache].val.i = 0;
1931 defconfig[DiskCache].prio = 2;
1934 defconfig[DiskCache].val.i = 1;
1935 defconfig[DiskCache].prio = 2;
1938 embed = strtol(EARGF(usage()), NULL, 0);
1941 defconfig[RunInFullscreen].val.i = 0;
1942 defconfig[RunInFullscreen].prio = 2;
1945 defconfig[RunInFullscreen].val.i = 1;
1946 defconfig[RunInFullscreen].prio = 2;
1949 defconfig[Geolocation].val.i = 0;
1950 defconfig[Geolocation].prio = 2;
1953 defconfig[Geolocation].val.i = 1;
1954 defconfig[Geolocation].prio = 2;
1957 defconfig[LoadImages].val.i = 0;
1958 defconfig[LoadImages].prio = 2;
1961 defconfig[LoadImages].val.i = 1;
1962 defconfig[LoadImages].prio = 2;
1965 defconfig[KioskMode].val.i = 0;
1966 defconfig[KioskMode].prio = 2;
1969 defconfig[KioskMode].val.i = 1;
1970 defconfig[KioskMode].prio = 2;
1973 defconfig[Style].val.i = 0;
1974 defconfig[Style].prio = 2;
1977 defconfig[Style].val.i = 1;
1978 defconfig[Style].prio = 2;
1981 defconfig[Inspector].val.i = 0;
1982 defconfig[Inspector].prio = 2;
1985 defconfig[Inspector].val.i = 1;
1986 defconfig[Inspector].prio = 2;
1989 defconfig[Plugins].val.i = 0;
1990 defconfig[Plugins].prio = 2;
1993 defconfig[Plugins].val.i = 1;
1994 defconfig[Plugins].prio = 2;
1997 scriptfile = EARGF(usage());
2000 defconfig[JavaScript].val.i = 0;
2001 defconfig[JavaScript].prio = 2;
2004 defconfig[JavaScript].val.i = 1;
2005 defconfig[JavaScript].prio = 2;
2008 defconfig[StrictTLS].val.i = 0;
2009 defconfig[StrictTLS].prio = 2;
2012 defconfig[StrictTLS].val.i = 1;
2013 defconfig[StrictTLS].prio = 2;
2016 fulluseragent = EARGF(usage());
2019 die("surf-"VERSION", see LICENSE for © details\n");
2024 defconfig[Certificate].val.i = 0;
2025 defconfig[Certificate].prio = 2;
2028 defconfig[Certificate].val.i = 1;
2029 defconfig[Certificate].prio = 2;
2032 defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
2033 defconfig[ZoomLevel].prio = 2;
2041 arg.v = "about:blank";
2044 c = newclient(NULL);