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 char *untildepath(const char *path);
150 static const char *getuserhomedir(const char *user);
151 static const char *getcurrentuserhomedir(void);
152 static Client *newclient(Client *c);
153 static void loaduri(Client *c, const Arg *a);
154 static const char *geturi(Client *c);
155 static void setatom(Client *c, int a, const char *v);
156 static const char *getatom(Client *c, int a);
157 static void updatetitle(Client *c);
158 static void gettogglestats(Client *c);
159 static void getpagestats(Client *c);
160 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
161 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
162 static void seturiparameters(Client *c, const char *uri, ParamName *params);
163 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
164 static const char *getcert(const char *uri);
165 static void setcert(Client *c, const char *file);
166 static const char *getstyle(const char *uri);
167 static void setstyle(Client *c, const char *file);
168 static void runscript(Client *c);
169 static void evalscript(Client *c, const char *jsstr, ...);
170 static void updatewinid(Client *c);
171 static void handleplumb(Client *c, const char *uri);
172 static void newwindow(Client *c, const Arg *a, int noembed);
173 static void spawn(Client *c, const Arg *a);
174 static void destroyclient(Client *c);
175 static void cleanup(void);
178 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
179 static void initwebextensions(WebKitWebContext *wc, Client *c);
180 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
182 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
183 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
185 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
186 static void showview(WebKitWebView *v, Client *c);
187 static GtkWidget *createwindow(Client *c);
188 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
189 GTlsCertificate *cert,
190 GTlsCertificateFlags err, Client *c);
191 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
192 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
193 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
194 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
195 guint modifiers, Client *c);
196 static gboolean permissionrequested(WebKitWebView *v,
197 WebKitPermissionRequest *r, Client *c);
198 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
199 WebKitPolicyDecisionType dt, Client *c);
200 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
201 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
202 static void decideresource(WebKitPolicyDecision *d, Client *c);
203 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
205 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
207 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
208 static void download(Client *c, WebKitURIResponse *r);
209 static void webprocessterminated(WebKitWebView *v,
210 WebKitWebProcessTerminationReason r,
212 static void closeview(WebKitWebView *v, Client *c);
213 static void destroywin(GtkWidget* w, Client *c);
216 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
217 static void reload(Client *c, const Arg *a);
218 static void print(Client *c, const Arg *a);
219 static void showcert(Client *c, const Arg *a);
220 static void clipboard(Client *c, const Arg *a);
221 static void zoom(Client *c, const Arg *a);
222 static void scroll(Client *c, const Arg *a);
223 static void navigate(Client *c, const Arg *a);
224 static void stop(Client *c, const Arg *a);
225 static void toggle(Client *c, const Arg *a);
226 static void togglefullscreen(Client *c, const Arg *a);
227 static void togglecookiepolicy(Client *c, const Arg *a);
228 static void toggleinspector(Client *c, const Arg *a);
229 static void find(Client *c, const Arg *a);
232 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
233 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
234 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
236 static char winid[64];
237 static char togglestats[12];
238 static char pagestats[2];
239 static Atom atoms[AtomLast];
242 static int cookiepolicy;
244 static Client *clients;
245 static GdkDevice *gdkkb;
246 static char *stylefile;
247 static const char *useragent;
248 static Parameter *curconfig;
249 static int modparams[ParameterLast];
252 static ParamName loadtransient[] = {
266 static ParamName loadcommitted[] = {
292 static ParamName loadfinished[] = {
296 /* configuration, allows nested code to access above variables */
302 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
303 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
304 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
308 die(const char *errstr, ...)
312 va_start(ap, errstr);
313 vfprintf(stderr, errstr, ap);
324 /* clean up any zombies immediately */
326 if (signal(SIGHUP, sighup) == SIG_ERR)
327 die("Can't install SIGHUP handler");
329 if (!(dpy = XOpenDisplay(NULL)))
330 die("Can't open default display");
333 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
334 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
335 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
337 gtk_init(NULL, NULL);
339 gdpy = gdk_display_get_default();
341 curconfig = defconfig;
344 cookiefile = buildfile(cookiefile);
345 scriptfile = buildfile(scriptfile);
346 cachedir = buildpath(cachedir);
347 certdir = buildpath(certdir);
349 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
351 for (i = 0; i < LENGTH(certs); ++i) {
352 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
353 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
356 fprintf(stderr, "Could not compile regex: %s\n",
358 certs[i].regex = NULL;
363 styledir = buildpath(styledir);
364 for (i = 0; i < LENGTH(styles); ++i) {
365 if (!regcomp(&(styles[i].re), styles[i].regex,
367 styles[i].file = g_strconcat(styledir, "/",
368 styles[i].file, NULL);
370 fprintf(stderr, "Could not compile regex: %s\n",
372 styles[i].regex = NULL;
377 stylefile = buildfile(stylefile);
380 for (i = 0; i < LENGTH(uriparams); ++i) {
381 if (regcomp(&(uriparams[i].re), uriparams[i].uri,
383 fprintf(stderr, "Could not compile regex: %s\n",
385 uriparams[i].uri = NULL;
389 /* copy default parameters with higher priority */
390 for (j = 0; j < ParameterLast; ++j) {
391 if (defconfig[j].prio >= uriparams[i].config[j].prio)
392 uriparams[i].config[j] = defconfig[j];
400 if (signal(SIGCHLD, sigchld) == SIG_ERR)
401 die("Can't install SIGCHLD handler");
402 while (waitpid(-1, NULL, WNOHANG) > 0)
412 for (c = clients; c; c = c->next)
417 buildfile(const char *path)
419 char *dname, *bname, *bpath, *fpath;
422 dname = g_path_get_dirname(path);
423 bname = g_path_get_basename(path);
425 bpath = buildpath(dname);
428 fpath = g_build_filename(bpath, bname, NULL);
432 if (!(f = fopen(fpath, "a")))
433 die("Could not open file: %s\n", fpath);
435 g_chmod(fpath, 0600); /* always */
442 getuserhomedir(const char *user)
444 struct passwd *pw = getpwnam(user);
447 die("Can't get user %s login information.\n", user);
453 getcurrentuserhomedir(void)
459 homedir = getenv("HOME");
463 user = getenv("USER");
465 return getuserhomedir(user);
467 pw = getpwuid(getuid());
469 die("Can't get current user home directory\n");
475 buildpath(const char *path)
480 apath = untildepath(path);
482 apath = g_strdup(path);
484 /* creating directory */
485 if (g_mkdir_with_parents(apath, 0700) < 0)
486 die("Could not access directory: %s\n", apath);
488 fpath = realpath(apath, NULL);
495 untildepath(const char *path)
497 char *apath, *name, *p;
500 if (path[1] == '/' || path[1] == '\0') {
501 p = (char *)&path[1];
502 homedir = getcurrentuserhomedir();
504 if ((p = strchr(path, '/')))
505 name = g_strndup(&path[1], p - (path + 1));
507 name = g_strdup(&path[1]);
509 homedir = getuserhomedir(name);
512 apath = g_build_filename(homedir, p, NULL);
517 newclient(Client *rc)
521 if (!(c = calloc(1, sizeof(Client))))
522 die("Cannot malloc!\n");
528 c->view = newview(c, rc ? rc->view : NULL);
534 loaduri(Client *c, const Arg *a)
537 char *url, *path, *apath;
538 const char *uri = a->v;
540 if (g_strcmp0(uri, "") == 0)
543 if (g_str_has_prefix(uri, "http://") ||
544 g_str_has_prefix(uri, "https://") ||
545 g_str_has_prefix(uri, "file://") ||
546 g_str_has_prefix(uri, "about:")) {
550 apath = untildepath(uri);
553 if (!stat(apath, &st) && (path = realpath(apath, NULL))) {
554 url = g_strdup_printf("file://%s", path);
557 url = g_strdup_printf("http://%s", uri);
563 setatom(c, AtomUri, url);
565 if (strcmp(url, geturi(c)) == 0) {
568 webkit_web_view_load_uri(c->view, url);
580 if (!(uri = webkit_web_view_get_uri(c->view)))
586 setatom(Client *c, int a, const char *v)
588 XChangeProperty(dpy, c->xid,
589 atoms[a], XA_STRING, 8, PropModeReplace,
590 (unsigned char *)v, strlen(v) + 1);
595 getatom(Client *c, int a)
597 static char buf[BUFSIZ];
600 unsigned long ldummy;
601 unsigned char *p = NULL;
604 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
605 &adummy, &idummy, &ldummy, &ldummy, &p);
607 strncpy(buf, (char *)p, LENGTH(buf) - 1);
616 updatetitle(Client *c)
619 const char *name = c->overtitle ? c->overtitle :
620 c->title ? c->title : "";
622 if (curconfig[ShowIndicators].val.i) {
626 if (c->progress != 100)
627 title = g_strdup_printf("[%i%%] %s:%s | %s",
628 c->progress, togglestats, pagestats, name);
630 title = g_strdup_printf("%s:%s | %s",
631 togglestats, pagestats, name);
633 gtk_window_set_title(GTK_WINDOW(c->win), title);
636 gtk_window_set_title(GTK_WINDOW(c->win), name);
641 gettogglestats(Client *c)
643 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
644 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
645 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
646 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
647 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
648 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
649 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
650 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
651 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
652 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
653 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
654 togglestats[11] = '\0';
658 getpagestats(Client *c)
661 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
667 WebKitCookieAcceptPolicy
668 cookiepolicy_get(void)
670 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
672 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
674 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
675 default: /* fallthrough */
677 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
682 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
685 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
687 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
689 default: /* fallthrough */
690 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
696 seturiparameters(Client *c, const char *uri, ParamName *params)
698 Parameter *config, *uriconfig = NULL;
701 for (i = 0; i < LENGTH(uriparams); ++i) {
702 if (uriparams[i].uri &&
703 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
704 uriconfig = uriparams[i].config;
709 curconfig = uriconfig ? uriconfig : defconfig;
711 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
713 default: /* FALLTHROUGH */
714 if (!(defconfig[p].prio < curconfig[p].prio ||
715 defconfig[p].prio < modparams[p]))
720 setparameter(c, 0, p, &curconfig[p].val);
726 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
728 GdkRGBA bgcolor = { 0 };
729 WebKitSettings *s = webkit_web_view_get_settings(c->view);
731 modparams[p] = curconfig[p].prio;
734 case AcceleratedCanvas:
735 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
737 case AccessMicrophone:
738 return; /* do nothing */
740 return; /* do nothing */
742 webkit_settings_set_enable_caret_browsing(s, a->i);
747 setcert(c, geturi(c));
748 return; /* do not update */
750 webkit_cookie_manager_set_accept_policy(
751 webkit_web_context_get_cookie_manager(
752 webkit_web_view_get_context(c->view)),
757 webkit_web_context_set_cache_model(
758 webkit_web_view_get_context(c->view), a->i ?
759 WEBKIT_CACHE_MODEL_WEB_BROWSER :
760 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
761 return; /* do not update */
763 webkit_settings_set_default_charset(s, a->v);
764 return; /* do not update */
766 webkit_settings_set_enable_dns_prefetching(s, a->i);
767 return; /* do not update */
768 case FileURLsCrossAccess:
769 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
770 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
771 return; /* do not update */
773 webkit_settings_set_default_font_size(s, a->i);
774 return; /* do not update */
775 case FrameFlattening:
776 webkit_settings_set_enable_frame_flattening(s, a->i);
783 webkit_web_view_set_background_color(c->view, &bgcolor);
784 return; /* do not update */
786 webkit_settings_set_enable_developer_extras(s, a->i);
787 return; /* do not update */
789 webkit_settings_set_enable_java(s, a->i);
790 return; /* do not update */
792 webkit_settings_set_enable_javascript(s, a->i);
795 return; /* do nothing */
797 webkit_settings_set_auto_load_images(s, a->i);
799 case MediaManualPlay:
800 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
803 webkit_settings_set_enable_plugins(s, a->i);
805 case PreferredLanguages:
806 return; /* do nothing */
807 case RunInFullscreen:
808 return; /* do nothing */
810 /* Disabled until we write some WebKitWebExtension for
811 * manipulating the DOM directly.
812 enablescrollbars = !enablescrollbars;
813 evalscript(c, "document.documentElement.style.overflow = '%s'",
814 enablescrollbars ? "auto" : "hidden");
816 return; /* do not update */
819 case SmoothScrolling:
820 webkit_settings_set_enable_smooth_scrolling(s, a->i);
821 return; /* do not update */
823 webkit_settings_set_enable_site_specific_quirks(s, a->i);
826 webkit_web_context_set_spell_checking_enabled(
827 webkit_web_view_get_context(c->view), a->i);
828 return; /* do not update */
830 return; /* do nothing */
832 webkit_web_context_set_tls_errors_policy(
833 webkit_web_view_get_context(c->view), a->i ?
834 WEBKIT_TLS_ERRORS_POLICY_FAIL :
835 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
838 webkit_user_content_manager_remove_all_style_sheets(
839 webkit_web_view_get_user_content_manager(c->view));
841 setstyle(c, getstyle(geturi(c)));
845 webkit_settings_set_enable_webgl(s, a->i);
848 webkit_web_view_set_zoom_level(c->view, a->f);
849 return; /* do not update */
851 return; /* do nothing */
860 getcert(const char *uri)
864 for (i = 0; i < LENGTH(certs); ++i) {
865 if (certs[i].regex &&
866 !regexec(&(certs[i].re), uri, 0, NULL, 0))
867 return certs[i].file;
874 setcert(Client *c, const char *uri)
876 const char *file = getcert(uri);
878 GTlsCertificate *cert;
883 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
884 fprintf(stderr, "Could not read certificate file: %s\n", file);
888 if ((uri = strstr(uri, "https://"))) {
889 uri += sizeof("https://") - 1;
890 host = g_strndup(uri, strchr(uri, '/') - uri);
891 webkit_web_context_allow_tls_certificate_for_host(
892 webkit_web_view_get_context(c->view), cert, host);
896 g_object_unref(cert);
901 getstyle(const char *uri)
908 for (i = 0; i < LENGTH(styles); ++i) {
909 if (styles[i].regex &&
910 !regexec(&(styles[i].re), uri, 0, NULL, 0))
911 return styles[i].file;
918 setstyle(Client *c, const char *file)
922 if (!g_file_get_contents(file, &style, NULL, NULL)) {
923 fprintf(stderr, "Could not read style file: %s\n", file);
927 webkit_user_content_manager_add_style_sheet(
928 webkit_web_view_get_user_content_manager(c->view),
929 webkit_user_style_sheet_new(style,
930 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
931 WEBKIT_USER_STYLE_LEVEL_USER,
943 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
944 evalscript(c, "%s", script);
949 evalscript(Client *c, const char *jsstr, ...)
955 script = g_strdup_vprintf(jsstr, ap);
958 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
963 updatewinid(Client *c)
965 snprintf(winid, LENGTH(winid), "%lu", c->xid);
969 handleplumb(Client *c, const char *uri)
971 Arg a = (Arg)PLUMB(uri);
976 newwindow(Client *c, const Arg *a, int noembed)
980 const char *cmd[29], *uri;
981 const Arg arg = { .v = cmd };
985 cmd[i++] = curconfig[CookiePolicies].val.v;
986 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
987 if (cookiefile && g_strcmp0(cookiefile, "")) {
989 cmd[i++] = cookiefile;
991 if (stylefile && g_strcmp0(stylefile, "")) {
993 cmd[i++] = stylefile;
995 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
996 if (embed && !noembed) {
998 snprintf(tmp, LENGTH(tmp), "%lu", embed);
1001 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
1002 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
1003 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
1004 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
1005 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
1006 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
1007 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
1008 if (scriptfile && g_strcmp0(scriptfile, "")) {
1010 cmd[i++] = scriptfile;
1012 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
1013 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
1014 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
1016 cmd[i++] = fulluseragent;
1020 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1021 /* do not keep zoom level */
1031 spawn(Client *c, const Arg *a)
1035 close(ConnectionNumber(dpy));
1037 execvp(((char **)a->v)[0], (char **)a->v);
1038 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1045 destroyclient(Client *c)
1049 webkit_web_view_stop_loading(c->view);
1050 /* Not needed, has already been called
1051 gtk_widget_destroy(c->win);
1054 for (p = clients; p && p->next != c; p = p->next)
1067 destroyclient(clients);
1076 newview(Client *c, WebKitWebView *rv)
1079 WebKitSettings *settings;
1080 WebKitUserContentManager *contentmanager;
1081 WebKitWebContext *context;
1085 v = WEBKIT_WEB_VIEW(
1086 webkit_web_view_new_with_related_view(rv));
1088 settings = webkit_settings_new_with_settings(
1089 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1090 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1091 "auto-load-images", curconfig[LoadImages].val.i,
1092 "default-charset", curconfig[DefaultCharset].val.v,
1093 "default-font-size", curconfig[FontSize].val.i,
1094 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1095 "enable-developer-extras", curconfig[Inspector].val.i,
1096 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1097 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1098 "enable-html5-database", curconfig[DiskCache].val.i,
1099 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1100 "enable-java", curconfig[Java].val.i,
1101 "enable-javascript", curconfig[JavaScript].val.i,
1102 "enable-plugins", curconfig[Plugins].val.i,
1103 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1104 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1105 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1106 "enable-webgl", curconfig[WebGL].val.i,
1107 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1109 /* For more interesting settings, have a look at
1110 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1112 if (strcmp(fulluseragent, "")) {
1113 webkit_settings_set_user_agent(settings, fulluseragent);
1114 } else if (surfuseragent) {
1115 webkit_settings_set_user_agent_with_application_details(
1116 settings, "Surf", VERSION);
1118 useragent = webkit_settings_get_user_agent(settings);
1120 contentmanager = webkit_user_content_manager_new();
1122 context = webkit_web_context_new_with_website_data_manager(
1123 webkit_website_data_manager_new(
1124 "base-cache-directory", cachedir,
1125 "base-data-directory", cachedir,
1128 /* rendering process model, can be a shared unique one
1129 * or one for each view */
1130 webkit_web_context_set_process_model(context,
1131 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1133 webkit_web_context_set_tls_errors_policy(context,
1134 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1135 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1137 webkit_web_context_set_cache_model(context,
1138 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1139 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1141 /* Currently only works with text file to be compatible with curl */
1142 webkit_cookie_manager_set_persistent_storage(
1143 webkit_web_context_get_cookie_manager(context), cookiefile,
1144 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1146 webkit_cookie_manager_set_accept_policy(
1147 webkit_web_context_get_cookie_manager(context),
1148 cookiepolicy_get());
1150 webkit_web_context_set_preferred_languages(context,
1151 curconfig[PreferredLanguages].val.v);
1152 webkit_web_context_set_spell_checking_languages(context,
1153 curconfig[SpellLanguages].val.v);
1154 webkit_web_context_set_spell_checking_enabled(context,
1155 curconfig[SpellChecking].val.i);
1157 g_signal_connect(G_OBJECT(context), "download-started",
1158 G_CALLBACK(downloadstarted), c);
1159 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1160 G_CALLBACK(initwebextensions), c);
1162 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1163 "settings", settings,
1164 "user-content-manager", contentmanager,
1165 "web-context", context,
1169 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1170 G_CALLBACK(progresschanged), c);
1171 g_signal_connect(G_OBJECT(v), "notify::title",
1172 G_CALLBACK(titlechanged), c);
1173 g_signal_connect(G_OBJECT(v), "button-release-event",
1174 G_CALLBACK(buttonreleased), c);
1175 g_signal_connect(G_OBJECT(v), "close",
1176 G_CALLBACK(closeview), c);
1177 g_signal_connect(G_OBJECT(v), "create",
1178 G_CALLBACK(createview), c);
1179 g_signal_connect(G_OBJECT(v), "decide-policy",
1180 G_CALLBACK(decidepolicy), c);
1181 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1182 G_CALLBACK(insecurecontent), c);
1183 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1184 G_CALLBACK(loadfailedtls), c);
1185 g_signal_connect(G_OBJECT(v), "load-changed",
1186 G_CALLBACK(loadchanged), c);
1187 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1188 G_CALLBACK(mousetargetchanged), c);
1189 g_signal_connect(G_OBJECT(v), "permission-request",
1190 G_CALLBACK(permissionrequested), c);
1191 g_signal_connect(G_OBJECT(v), "ready-to-show",
1192 G_CALLBACK(showview), c);
1193 g_signal_connect(G_OBJECT(v), "web-process-terminated",
1194 G_CALLBACK(webprocessterminated), c);
1200 initwebextensions(WebKitWebContext *wc, Client *c)
1202 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1206 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1210 switch (webkit_navigation_action_get_navigation_type(a)) {
1211 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1213 * popup windows of type “other” are almost always triggered
1214 * by user gesture, so inverse the logic here
1216 /* instead of this, compare destination uri to mouse-over uri for validating window */
1217 if (webkit_navigation_action_is_user_gesture(a))
1219 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1220 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1221 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1222 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1223 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1230 return GTK_WIDGET(n->view);
1234 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1236 WebKitHitTestResultContext element;
1239 element = webkit_hit_test_result_get_context(c->mousepos);
1241 for (i = 0; i < LENGTH(buttons); ++i) {
1242 if (element & buttons[i].target &&
1243 e->button.button == buttons[i].button &&
1244 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1246 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1247 return buttons[i].stopevent;
1255 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1257 Client *c = (Client *)d;
1261 if (((XEvent *)e)->type == PropertyNotify) {
1262 ev = &((XEvent *)e)->xproperty;
1263 if (ev->state == PropertyNewValue) {
1264 if (ev->atom == atoms[AtomFind]) {
1267 return GDK_FILTER_REMOVE;
1268 } else if (ev->atom == atoms[AtomGo]) {
1269 a.v = getatom(c, AtomGo);
1272 return GDK_FILTER_REMOVE;
1276 return GDK_FILTER_CONTINUE;
1280 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1285 case GDK_ENTER_NOTIFY:
1286 c->overtitle = c->targeturi;
1290 if (!curconfig[KioskMode].val.i) {
1291 for (i = 0; i < LENGTH(keys); ++i) {
1292 if (gdk_keyval_to_lower(e->key.keyval) ==
1294 CLEANMASK(e->key.state) == keys[i].mod &&
1297 keys[i].func(c, &(keys[i].arg));
1302 case GDK_LEAVE_NOTIFY:
1303 c->overtitle = NULL;
1306 case GDK_WINDOW_STATE:
1307 if (e->window_state.changed_mask ==
1308 GDK_WINDOW_STATE_FULLSCREEN)
1309 c->fullscreen = e->window_state.new_window_state &
1310 GDK_WINDOW_STATE_FULLSCREEN;
1320 showview(WebKitWebView *v, Client *c)
1322 GdkRGBA bgcolor = { 0 };
1325 c->finder = webkit_web_view_get_find_controller(c->view);
1326 c->inspector = webkit_web_view_get_inspector(c->view);
1328 c->win = createwindow(c);
1330 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1331 gtk_widget_show_all(c->win);
1332 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1334 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1335 c->xid = gdk_x11_window_get_xid(gwin);
1338 gdk_display_sync(gtk_widget_get_display(c->win));
1343 if (curconfig[HideBackground].val.i)
1344 webkit_web_view_set_background_color(c->view, &bgcolor);
1346 if (!curconfig[KioskMode].val.i) {
1347 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1348 gdk_window_add_filter(gwin, processx, c);
1351 if (curconfig[RunInFullscreen].val.i)
1352 togglefullscreen(c, NULL);
1354 if (curconfig[ZoomLevel].val.f != 1.0)
1355 webkit_web_view_set_zoom_level(c->view,
1356 curconfig[ZoomLevel].val.f);
1358 setatom(c, AtomFind, "");
1359 setatom(c, AtomUri, "about:blank");
1363 createwindow(Client *c)
1369 w = gtk_plug_new(embed);
1371 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1373 wmstr = g_path_get_basename(argv0);
1374 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1377 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1378 webkit_web_view_get_page_id(c->view));
1379 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1382 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1385 g_signal_connect(G_OBJECT(w), "destroy",
1386 G_CALLBACK(destroywin), c);
1387 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1388 G_CALLBACK(winevent), c);
1389 g_signal_connect(G_OBJECT(w), "key-press-event",
1390 G_CALLBACK(winevent), c);
1391 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1392 G_CALLBACK(winevent), c);
1393 g_signal_connect(G_OBJECT(w), "window-state-event",
1394 G_CALLBACK(winevent), c);
1400 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1401 GTlsCertificateFlags err, Client *c)
1403 GString *errmsg = g_string_new(NULL);
1406 c->failedcert = g_object_ref(cert);
1410 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1411 g_string_append(errmsg,
1412 "The signing certificate authority is not known.<br>");
1413 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1414 g_string_append(errmsg,
1415 "The certificate does not match the expected identity "
1416 "of the site that it was retrieved from.<br>");
1417 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1418 g_string_append(errmsg,
1419 "The certificate's activation time "
1420 "is still in the future.<br>");
1421 if (err & G_TLS_CERTIFICATE_EXPIRED)
1422 g_string_append(errmsg, "The certificate has expired.<br>");
1423 if (err & G_TLS_CERTIFICATE_REVOKED)
1424 g_string_append(errmsg,
1425 "The certificate has been revoked according to "
1426 "the GTlsConnection's certificate revocation list.<br>");
1427 if (err & G_TLS_CERTIFICATE_INSECURE)
1428 g_string_append(errmsg,
1429 "The certificate's algorithm is considered insecure.<br>");
1430 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1431 g_string_append(errmsg,
1432 "Some error occurred validating the certificate.<br>");
1434 g_object_get(cert, "certificate-pem", &pem, NULL);
1435 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1436 "<p>You can inspect the following certificate "
1437 "with Ctrl-t (default keybinding).</p>"
1438 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1440 g_string_free(errmsg, TRUE);
1442 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1449 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1451 const char *uri = geturi(c);
1454 case WEBKIT_LOAD_STARTED:
1455 setatom(c, AtomUri, uri);
1457 c->https = c->insecure = 0;
1458 seturiparameters(c, uri, loadtransient);
1462 g_clear_object(&c->failedcert);
1464 case WEBKIT_LOAD_REDIRECTED:
1465 setatom(c, AtomUri, uri);
1467 seturiparameters(c, uri, loadtransient);
1469 case WEBKIT_LOAD_COMMITTED:
1470 seturiparameters(c, uri, loadcommitted);
1471 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1474 case WEBKIT_LOAD_FINISHED:
1475 seturiparameters(c, uri, loadfinished);
1476 /* Disabled until we write some WebKitWebExtension for
1477 * manipulating the DOM directly.
1478 evalscript(c, "document.documentElement.style.overflow = '%s'",
1479 enablescrollbars ? "auto" : "hidden");
1488 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1490 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1496 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1498 c->title = webkit_web_view_get_title(c->view);
1503 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1506 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1508 /* Keep the hit test to know where is the pointer on the next click */
1512 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1513 else if (hc & OnImg)
1514 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1515 else if (hc & OnMedia)
1516 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1518 c->targeturi = NULL;
1520 c->overtitle = c->targeturi;
1525 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1527 ParamName param = ParameterLast;
1529 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1530 param = Geolocation;
1531 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1532 if (webkit_user_media_permission_is_for_audio_device(
1533 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1534 param = AccessMicrophone;
1535 else if (webkit_user_media_permission_is_for_video_device(
1536 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1537 param = AccessWebcam;
1542 if (curconfig[param].val.i)
1543 webkit_permission_request_allow(r);
1545 webkit_permission_request_deny(r);
1551 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1552 WebKitPolicyDecisionType dt, Client *c)
1555 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1556 decidenavigation(d, c);
1558 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1559 decidenewwindow(d, c);
1561 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1562 decideresource(d, c);
1565 webkit_policy_decision_ignore(d);
1572 decidenavigation(WebKitPolicyDecision *d, Client *c)
1574 WebKitNavigationAction *a =
1575 webkit_navigation_policy_decision_get_navigation_action(
1576 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1578 switch (webkit_navigation_action_get_navigation_type(a)) {
1579 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1580 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1581 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1582 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1583 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1584 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1586 /* Do not navigate to links with a "_blank" target (popup) */
1587 if (webkit_navigation_policy_decision_get_frame_name(
1588 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1589 webkit_policy_decision_ignore(d);
1591 /* Filter out navigation to different domain ? */
1592 /* get action→urirequest, copy and load in new window+view
1593 * on Ctrl+Click ? */
1594 webkit_policy_decision_use(d);
1601 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1604 WebKitNavigationAction *a =
1605 webkit_navigation_policy_decision_get_navigation_action(
1606 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1609 switch (webkit_navigation_action_get_navigation_type(a)) {
1610 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1611 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1612 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1613 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1614 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1615 /* Filter domains here */
1616 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1617 * test for link clicked but no button ? */
1618 arg.v = webkit_uri_request_get_uri(
1619 webkit_navigation_action_get_request(a));
1620 newwindow(c, &arg, 0);
1622 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1627 webkit_policy_decision_ignore(d);
1631 decideresource(WebKitPolicyDecision *d, Client *c)
1634 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1635 WebKitURIResponse *res =
1636 webkit_response_policy_decision_get_response(r);
1637 const gchar *uri = webkit_uri_response_get_uri(res);
1639 if (g_str_has_suffix(uri, "/favicon.ico")) {
1640 webkit_policy_decision_ignore(d);
1644 if (!g_str_has_prefix(uri, "http://")
1645 && !g_str_has_prefix(uri, "https://")
1646 && !g_str_has_prefix(uri, "about:")
1647 && !g_str_has_prefix(uri, "file://")
1648 && !g_str_has_prefix(uri, "data:")
1649 && !g_str_has_prefix(uri, "blob:")
1650 && strlen(uri) > 0) {
1651 for (i = 0; i < strlen(uri); i++) {
1652 if (!g_ascii_isprint(uri[i])) {
1658 handleplumb(c, uri);
1659 webkit_policy_decision_ignore(d);
1664 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1665 webkit_policy_decision_use(d);
1667 webkit_policy_decision_ignore(d);
1673 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1679 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1681 g_signal_connect(G_OBJECT(d), "notify::response",
1682 G_CALLBACK(responsereceived), c);
1686 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1688 download(c, webkit_download_get_response(d));
1689 webkit_download_cancel(d);
1693 download(Client *c, WebKitURIResponse *r)
1695 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1700 webprocessterminated(WebKitWebView *v, WebKitWebProcessTerminationReason r,
1703 fprintf(stderr, "web process terminated: %s\n",
1704 r == WEBKIT_WEB_PROCESS_CRASHED ? "crashed" : "no memory");
1709 closeview(WebKitWebView *v, Client *c)
1711 gtk_widget_destroy(c->win);
1715 destroywin(GtkWidget* w, Client *c)
1723 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1725 Arg a = {.v = text };
1727 loaduri((Client *) d, &a);
1731 reload(Client *c, const Arg *a)
1734 webkit_web_view_reload_bypass_cache(c->view);
1736 webkit_web_view_reload(c->view);
1740 print(Client *c, const Arg *a)
1742 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1743 GTK_WINDOW(c->win));
1747 showcert(Client *c, const Arg *a)
1749 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1750 GcrCertificate *gcrt;
1753 GcrCertificateWidget *wcert;
1758 g_object_get(cert, "certificate", &crt, NULL);
1759 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1760 g_byte_array_unref(crt);
1762 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1763 wcert = gcr_certificate_widget_new(gcrt);
1764 g_object_unref(gcrt);
1766 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1767 gtk_widget_show_all(win);
1771 clipboard(Client *c, const Arg *a)
1773 if (a->i) { /* load clipboard uri */
1774 gtk_clipboard_request_text(gtk_clipboard_get(
1775 GDK_SELECTION_PRIMARY),
1777 } else { /* copy uri */
1778 gtk_clipboard_set_text(gtk_clipboard_get(
1779 GDK_SELECTION_PRIMARY), c->targeturi
1780 ? c->targeturi : geturi(c), -1);
1785 zoom(Client *c, const Arg *a)
1788 webkit_web_view_set_zoom_level(c->view,
1789 curconfig[ZoomLevel].val.f + 0.1);
1791 webkit_web_view_set_zoom_level(c->view,
1792 curconfig[ZoomLevel].val.f - 0.1);
1794 webkit_web_view_set_zoom_level(c->view, 1.0);
1796 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1800 scroll(Client *c, const Arg *a)
1802 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1804 gdk_event_set_device(ev, gdkkb);
1805 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1806 ev->key.state = GDK_CONTROL_MASK;
1807 ev->key.time = GDK_CURRENT_TIME;
1811 ev->key.keyval = GDK_KEY_Down;
1814 ev->key.keyval = GDK_KEY_Page_Down;
1817 ev->key.keyval = GDK_KEY_Left;
1820 ev->key.keyval = GDK_KEY_Right;
1823 ev->key.keyval = GDK_KEY_Page_Up;
1826 ev->key.keyval = GDK_KEY_Up;
1834 navigate(Client *c, const Arg *a)
1837 webkit_web_view_go_back(c->view);
1839 webkit_web_view_go_forward(c->view);
1843 stop(Client *c, const Arg *a)
1845 webkit_web_view_stop_loading(c->view);
1849 toggle(Client *c, const Arg *a)
1851 curconfig[a->i].val.i ^= 1;
1852 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1856 togglefullscreen(Client *c, const Arg *a)
1858 /* toggling value is handled in winevent() */
1860 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1862 gtk_window_fullscreen(GTK_WINDOW(c->win));
1866 togglecookiepolicy(Client *c, const Arg *a)
1869 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1871 setparameter(c, 0, CookiePolicies, NULL);
1875 toggleinspector(Client *c, const Arg *a)
1877 if (webkit_web_inspector_is_attached(c->inspector))
1878 webkit_web_inspector_close(c->inspector);
1879 else if (curconfig[Inspector].val.i)
1880 webkit_web_inspector_show(c->inspector);
1884 find(Client *c, const Arg *a)
1890 webkit_find_controller_search_next(c->finder);
1892 webkit_find_controller_search_previous(c->finder);
1894 s = getatom(c, AtomFind);
1895 f = webkit_find_controller_get_search_text(c->finder);
1897 if (g_strcmp0(f, s) == 0) /* reset search */
1898 webkit_find_controller_search(c->finder, "", findopts,
1901 webkit_find_controller_search(c->finder, s, findopts,
1904 if (strcmp(s, "") == 0)
1905 webkit_find_controller_search_finish(c->finder);
1910 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1916 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1920 arg.v = webkit_hit_test_result_get_link_uri(h);
1921 newwindow(c, &arg, a->i);
1925 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1929 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1934 main(int argc, char *argv[])
1939 memset(&arg, 0, sizeof(arg));
1941 /* command line args */
1944 defconfig[CookiePolicies].val.v = EARGF(usage());
1945 defconfig[CookiePolicies].prio = 2;
1948 defconfig[ScrollBars].val.i = 0;
1949 defconfig[ScrollBars].prio = 2;
1952 defconfig[ScrollBars].val.i = 1;
1953 defconfig[ScrollBars].prio = 2;
1956 cookiefile = EARGF(usage());
1959 stylefile = EARGF(usage());
1962 defconfig[DiskCache].val.i = 0;
1963 defconfig[DiskCache].prio = 2;
1966 defconfig[DiskCache].val.i = 1;
1967 defconfig[DiskCache].prio = 2;
1970 embed = strtol(EARGF(usage()), NULL, 0);
1973 defconfig[RunInFullscreen].val.i = 0;
1974 defconfig[RunInFullscreen].prio = 2;
1977 defconfig[RunInFullscreen].val.i = 1;
1978 defconfig[RunInFullscreen].prio = 2;
1981 defconfig[Geolocation].val.i = 0;
1982 defconfig[Geolocation].prio = 2;
1985 defconfig[Geolocation].val.i = 1;
1986 defconfig[Geolocation].prio = 2;
1989 defconfig[LoadImages].val.i = 0;
1990 defconfig[LoadImages].prio = 2;
1993 defconfig[LoadImages].val.i = 1;
1994 defconfig[LoadImages].prio = 2;
1997 defconfig[KioskMode].val.i = 0;
1998 defconfig[KioskMode].prio = 2;
2001 defconfig[KioskMode].val.i = 1;
2002 defconfig[KioskMode].prio = 2;
2005 defconfig[Style].val.i = 0;
2006 defconfig[Style].prio = 2;
2009 defconfig[Style].val.i = 1;
2010 defconfig[Style].prio = 2;
2013 defconfig[Inspector].val.i = 0;
2014 defconfig[Inspector].prio = 2;
2017 defconfig[Inspector].val.i = 1;
2018 defconfig[Inspector].prio = 2;
2021 defconfig[Plugins].val.i = 0;
2022 defconfig[Plugins].prio = 2;
2025 defconfig[Plugins].val.i = 1;
2026 defconfig[Plugins].prio = 2;
2029 scriptfile = EARGF(usage());
2032 defconfig[JavaScript].val.i = 0;
2033 defconfig[JavaScript].prio = 2;
2036 defconfig[JavaScript].val.i = 1;
2037 defconfig[JavaScript].prio = 2;
2040 defconfig[StrictTLS].val.i = 0;
2041 defconfig[StrictTLS].prio = 2;
2044 defconfig[StrictTLS].val.i = 1;
2045 defconfig[StrictTLS].prio = 2;
2048 fulluseragent = EARGF(usage());
2051 die("surf-"VERSION", see LICENSE for © details\n");
2056 defconfig[Certificate].val.i = 0;
2057 defconfig[Certificate].prio = 2;
2060 defconfig[Certificate].val.i = 1;
2061 defconfig[Certificate].prio = 2;
2064 defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
2065 defconfig[ZoomLevel].prio = 2;
2073 arg.v = "about:blank";
2076 c = newclient(NULL);