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 closeview(WebKitWebView *v, Client *c);
210 static void destroywin(GtkWidget* w, Client *c);
213 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
214 static void reload(Client *c, const Arg *a);
215 static void print(Client *c, const Arg *a);
216 static void showcert(Client *c, const Arg *a);
217 static void clipboard(Client *c, const Arg *a);
218 static void zoom(Client *c, const Arg *a);
219 static void scroll(Client *c, const Arg *a);
220 static void navigate(Client *c, const Arg *a);
221 static void stop(Client *c, const Arg *a);
222 static void toggle(Client *c, const Arg *a);
223 static void togglefullscreen(Client *c, const Arg *a);
224 static void togglecookiepolicy(Client *c, const Arg *a);
225 static void toggleinspector(Client *c, const Arg *a);
226 static void find(Client *c, const Arg *a);
229 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
230 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
231 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
233 static char winid[64];
234 static char togglestats[12];
235 static char pagestats[2];
236 static Atom atoms[AtomLast];
239 static int cookiepolicy;
241 static Client *clients;
242 static GdkDevice *gdkkb;
243 static char *stylefile;
244 static const char *useragent;
245 static Parameter *curconfig;
246 static int modparams[ParameterLast];
249 static ParamName loadtransient[] = {
263 static ParamName loadcommitted[] = {
289 static ParamName loadfinished[] = {
293 /* configuration, allows nested code to access above variables */
299 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
300 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
301 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
305 die(const char *errstr, ...)
309 va_start(ap, errstr);
310 vfprintf(stderr, errstr, ap);
321 /* clean up any zombies immediately */
323 if (signal(SIGHUP, sighup) == SIG_ERR)
324 die("Can't install SIGHUP handler");
326 if (!(dpy = XOpenDisplay(NULL)))
327 die("Can't open default display");
330 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
331 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
332 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
334 gtk_init(NULL, NULL);
336 gdpy = gdk_display_get_default();
338 curconfig = defconfig;
341 cookiefile = buildfile(cookiefile);
342 scriptfile = buildfile(scriptfile);
343 cachedir = buildpath(cachedir);
344 certdir = buildpath(certdir);
346 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
348 for (i = 0; i < LENGTH(certs); ++i) {
349 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
350 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
353 fprintf(stderr, "Could not compile regex: %s\n",
355 certs[i].regex = NULL;
360 styledir = buildpath(styledir);
361 for (i = 0; i < LENGTH(styles); ++i) {
362 if (!regcomp(&(styles[i].re), styles[i].regex,
364 styles[i].file = g_strconcat(styledir, "/",
365 styles[i].file, NULL);
367 fprintf(stderr, "Could not compile regex: %s\n",
369 styles[i].regex = NULL;
374 stylefile = buildfile(stylefile);
377 for (i = 0; i < LENGTH(uriparams); ++i) {
378 if (regcomp(&(uriparams[i].re), uriparams[i].uri,
380 fprintf(stderr, "Could not compile regex: %s\n",
382 uriparams[i].uri = NULL;
386 /* copy default parameters with higher priority */
387 for (j = 0; j < ParameterLast; ++j) {
388 if (defconfig[j].prio >= uriparams[i].config[j].prio)
389 uriparams[i].config[j] = defconfig[j];
397 if (signal(SIGCHLD, sigchld) == SIG_ERR)
398 die("Can't install SIGCHLD handler");
399 while (waitpid(-1, NULL, WNOHANG) > 0)
409 for (c = clients; c; c = c->next)
414 buildfile(const char *path)
416 char *dname, *bname, *bpath, *fpath;
419 dname = g_path_get_dirname(path);
420 bname = g_path_get_basename(path);
422 bpath = buildpath(dname);
425 fpath = g_build_filename(bpath, bname, NULL);
429 if (!(f = fopen(fpath, "a")))
430 die("Could not open file: %s\n", fpath);
432 g_chmod(fpath, 0600); /* always */
439 getuserhomedir(const char *user)
441 struct passwd *pw = getpwnam(user);
444 die("Can't get user %s login information.\n", user);
450 getcurrentuserhomedir(void)
456 homedir = getenv("HOME");
460 user = getenv("USER");
462 return getuserhomedir(user);
464 pw = getpwuid(getuid());
466 die("Can't get current user home directory\n");
472 buildpath(const char *path)
477 apath = untildepath(path);
479 apath = g_strdup(path);
481 /* creating directory */
482 if (g_mkdir_with_parents(apath, 0700) < 0)
483 die("Could not access directory: %s\n", apath);
485 fpath = realpath(apath, NULL);
492 untildepath(const char *path)
494 char *apath, *name, *p;
497 if (path[1] == '/' || path[1] == '\0') {
498 p = (char *)&path[1];
499 homedir = getcurrentuserhomedir();
501 if ((p = strchr(path, '/')))
502 name = g_strndup(&path[1], p - (path + 1));
504 name = g_strdup(&path[1]);
506 homedir = getuserhomedir(name);
509 apath = g_build_filename(homedir, p, NULL);
514 newclient(Client *rc)
518 if (!(c = calloc(1, sizeof(Client))))
519 die("Cannot malloc!\n");
525 c->view = newview(c, rc ? rc->view : NULL);
531 loaduri(Client *c, const Arg *a)
534 char *url, *path, *apath;
535 const char *uri = a->v;
537 if (g_strcmp0(uri, "") == 0)
540 if (g_str_has_prefix(uri, "http://") ||
541 g_str_has_prefix(uri, "https://") ||
542 g_str_has_prefix(uri, "file://") ||
543 g_str_has_prefix(uri, "about:")) {
547 apath = untildepath(uri);
550 if (!stat(apath, &st) && (path = realpath(apath, NULL))) {
551 url = g_strdup_printf("file://%s", path);
554 url = g_strdup_printf("http://%s", uri);
560 setatom(c, AtomUri, url);
562 if (strcmp(url, geturi(c)) == 0) {
565 webkit_web_view_load_uri(c->view, url);
577 if (!(uri = webkit_web_view_get_uri(c->view)))
583 setatom(Client *c, int a, const char *v)
585 XChangeProperty(dpy, c->xid,
586 atoms[a], XA_STRING, 8, PropModeReplace,
587 (unsigned char *)v, strlen(v) + 1);
592 getatom(Client *c, int a)
594 static char buf[BUFSIZ];
597 unsigned long ldummy;
598 unsigned char *p = NULL;
601 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
602 &adummy, &idummy, &ldummy, &ldummy, &p);
604 strncpy(buf, (char *)p, LENGTH(buf) - 1);
613 updatetitle(Client *c)
616 const char *name = c->overtitle ? c->overtitle :
617 c->title ? c->title : "";
619 if (curconfig[ShowIndicators].val.i) {
623 if (c->progress != 100)
624 title = g_strdup_printf("[%i%%] %s:%s | %s",
625 c->progress, togglestats, pagestats, name);
627 title = g_strdup_printf("%s:%s | %s",
628 togglestats, pagestats, name);
630 gtk_window_set_title(GTK_WINDOW(c->win), title);
633 gtk_window_set_title(GTK_WINDOW(c->win), name);
638 gettogglestats(Client *c)
640 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
641 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
642 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
643 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
644 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
645 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
646 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
647 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
648 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
649 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
650 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
651 togglestats[11] = '\0';
655 getpagestats(Client *c)
658 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
664 WebKitCookieAcceptPolicy
665 cookiepolicy_get(void)
667 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
669 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
671 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
672 default: /* fallthrough */
674 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
679 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
682 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
684 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
686 default: /* fallthrough */
687 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
693 seturiparameters(Client *c, const char *uri, ParamName *params)
695 Parameter *config, *uriconfig = NULL;
698 for (i = 0; i < LENGTH(uriparams); ++i) {
699 if (uriparams[i].uri &&
700 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
701 uriconfig = uriparams[i].config;
706 curconfig = uriconfig ? uriconfig : defconfig;
708 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
710 default: /* FALLTHROUGH */
711 if (!(defconfig[p].prio < curconfig[p].prio ||
712 defconfig[p].prio < modparams[p]))
717 setparameter(c, 0, p, &curconfig[p].val);
723 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
725 GdkRGBA bgcolor = { 0 };
726 WebKitSettings *s = webkit_web_view_get_settings(c->view);
728 modparams[p] = curconfig[p].prio;
731 case AcceleratedCanvas:
732 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
734 case AccessMicrophone:
735 return; /* do nothing */
737 return; /* do nothing */
739 webkit_settings_set_enable_caret_browsing(s, a->i);
744 setcert(c, geturi(c));
745 return; /* do not update */
747 webkit_cookie_manager_set_accept_policy(
748 webkit_web_context_get_cookie_manager(
749 webkit_web_view_get_context(c->view)),
754 webkit_web_context_set_cache_model(
755 webkit_web_view_get_context(c->view), a->i ?
756 WEBKIT_CACHE_MODEL_WEB_BROWSER :
757 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
758 return; /* do not update */
760 webkit_settings_set_default_charset(s, a->v);
761 return; /* do not update */
763 webkit_settings_set_enable_dns_prefetching(s, a->i);
764 return; /* do not update */
765 case FileURLsCrossAccess:
766 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
767 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
768 return; /* do not update */
770 webkit_settings_set_default_font_size(s, a->i);
771 return; /* do not update */
772 case FrameFlattening:
773 webkit_settings_set_enable_frame_flattening(s, a->i);
780 webkit_web_view_set_background_color(c->view, &bgcolor);
781 return; /* do not update */
783 webkit_settings_set_enable_developer_extras(s, a->i);
784 return; /* do not update */
786 webkit_settings_set_enable_java(s, a->i);
787 return; /* do not update */
789 webkit_settings_set_enable_javascript(s, a->i);
792 return; /* do nothing */
794 webkit_settings_set_auto_load_images(s, a->i);
796 case MediaManualPlay:
797 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
800 webkit_settings_set_enable_plugins(s, a->i);
802 case PreferredLanguages:
803 return; /* do nothing */
804 case RunInFullscreen:
805 return; /* do nothing */
807 /* Disabled until we write some WebKitWebExtension for
808 * manipulating the DOM directly.
809 enablescrollbars = !enablescrollbars;
810 evalscript(c, "document.documentElement.style.overflow = '%s'",
811 enablescrollbars ? "auto" : "hidden");
813 return; /* do not update */
816 case SmoothScrolling:
817 webkit_settings_set_enable_smooth_scrolling(s, a->i);
818 return; /* do not update */
820 webkit_settings_set_enable_site_specific_quirks(s, a->i);
823 webkit_web_context_set_spell_checking_enabled(
824 webkit_web_view_get_context(c->view), a->i);
825 return; /* do not update */
827 return; /* do nothing */
829 webkit_web_context_set_tls_errors_policy(
830 webkit_web_view_get_context(c->view), a->i ?
831 WEBKIT_TLS_ERRORS_POLICY_FAIL :
832 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
835 webkit_user_content_manager_remove_all_style_sheets(
836 webkit_web_view_get_user_content_manager(c->view));
838 setstyle(c, getstyle(geturi(c)));
842 webkit_settings_set_enable_webgl(s, a->i);
845 webkit_web_view_set_zoom_level(c->view, a->f);
846 return; /* do not update */
848 return; /* do nothing */
857 getcert(const char *uri)
861 for (i = 0; i < LENGTH(certs); ++i) {
862 if (certs[i].regex &&
863 !regexec(&(certs[i].re), uri, 0, NULL, 0))
864 return certs[i].file;
871 setcert(Client *c, const char *uri)
873 const char *file = getcert(uri);
875 GTlsCertificate *cert;
880 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
881 fprintf(stderr, "Could not read certificate file: %s\n", file);
885 if ((uri = strstr(uri, "https://"))) {
886 uri += sizeof("https://") - 1;
887 host = g_strndup(uri, strchr(uri, '/') - uri);
888 webkit_web_context_allow_tls_certificate_for_host(
889 webkit_web_view_get_context(c->view), cert, host);
893 g_object_unref(cert);
898 getstyle(const char *uri)
905 for (i = 0; i < LENGTH(styles); ++i) {
906 if (styles[i].regex &&
907 !regexec(&(styles[i].re), uri, 0, NULL, 0))
908 return styles[i].file;
915 setstyle(Client *c, const char *file)
919 if (!g_file_get_contents(file, &style, NULL, NULL)) {
920 fprintf(stderr, "Could not read style file: %s\n", file);
924 webkit_user_content_manager_add_style_sheet(
925 webkit_web_view_get_user_content_manager(c->view),
926 webkit_user_style_sheet_new(style,
927 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
928 WEBKIT_USER_STYLE_LEVEL_USER,
940 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
941 evalscript(c, "%s", script);
946 evalscript(Client *c, const char *jsstr, ...)
952 script = g_strdup_vprintf(jsstr, ap);
955 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
960 updatewinid(Client *c)
962 snprintf(winid, LENGTH(winid), "%lu", c->xid);
966 handleplumb(Client *c, const char *uri)
968 Arg a = (Arg)PLUMB(uri);
973 newwindow(Client *c, const Arg *a, int noembed)
977 const char *cmd[29], *uri;
978 const Arg arg = { .v = cmd };
982 cmd[i++] = curconfig[CookiePolicies].val.v;
983 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
984 if (cookiefile && g_strcmp0(cookiefile, "")) {
986 cmd[i++] = cookiefile;
988 if (stylefile && g_strcmp0(stylefile, "")) {
990 cmd[i++] = stylefile;
992 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
993 if (embed && !noembed) {
995 snprintf(tmp, LENGTH(tmp), "%lu", embed);
998 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
999 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
1000 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
1001 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
1002 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
1003 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
1004 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
1005 if (scriptfile && g_strcmp0(scriptfile, "")) {
1007 cmd[i++] = scriptfile;
1009 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
1010 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
1011 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
1013 cmd[i++] = fulluseragent;
1017 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1018 /* do not keep zoom level */
1028 spawn(Client *c, const Arg *a)
1032 close(ConnectionNumber(dpy));
1034 execvp(((char **)a->v)[0], (char **)a->v);
1035 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1042 destroyclient(Client *c)
1046 webkit_web_view_stop_loading(c->view);
1047 /* Not needed, has already been called
1048 gtk_widget_destroy(c->win);
1051 for (p = clients; p && p->next != c; p = p->next)
1064 destroyclient(clients);
1073 newview(Client *c, WebKitWebView *rv)
1076 WebKitSettings *settings;
1077 WebKitUserContentManager *contentmanager;
1078 WebKitWebContext *context;
1082 v = WEBKIT_WEB_VIEW(
1083 webkit_web_view_new_with_related_view(rv));
1085 settings = webkit_settings_new_with_settings(
1086 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1087 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1088 "auto-load-images", curconfig[LoadImages].val.i,
1089 "default-charset", curconfig[DefaultCharset].val.v,
1090 "default-font-size", curconfig[FontSize].val.i,
1091 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1092 "enable-developer-extras", curconfig[Inspector].val.i,
1093 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1094 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1095 "enable-html5-database", curconfig[DiskCache].val.i,
1096 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1097 "enable-java", curconfig[Java].val.i,
1098 "enable-javascript", curconfig[JavaScript].val.i,
1099 "enable-plugins", curconfig[Plugins].val.i,
1100 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1101 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1102 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1103 "enable-webgl", curconfig[WebGL].val.i,
1104 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1106 /* For more interesting settings, have a look at
1107 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1109 if (strcmp(fulluseragent, "")) {
1110 webkit_settings_set_user_agent(settings, fulluseragent);
1111 } else if (surfuseragent) {
1112 webkit_settings_set_user_agent_with_application_details(
1113 settings, "Surf", VERSION);
1115 useragent = webkit_settings_get_user_agent(settings);
1117 contentmanager = webkit_user_content_manager_new();
1119 context = webkit_web_context_new_with_website_data_manager(
1120 webkit_website_data_manager_new(
1121 "base-cache-directory", cachedir,
1122 "base-data-directory", cachedir,
1125 /* rendering process model, can be a shared unique one
1126 * or one for each view */
1127 webkit_web_context_set_process_model(context,
1128 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1130 webkit_web_context_set_tls_errors_policy(context,
1131 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1132 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1134 webkit_web_context_set_cache_model(context,
1135 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1136 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1138 /* Currently only works with text file to be compatible with curl */
1139 webkit_cookie_manager_set_persistent_storage(
1140 webkit_web_context_get_cookie_manager(context), cookiefile,
1141 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1143 webkit_cookie_manager_set_accept_policy(
1144 webkit_web_context_get_cookie_manager(context),
1145 cookiepolicy_get());
1147 webkit_web_context_set_preferred_languages(context,
1148 curconfig[PreferredLanguages].val.v);
1149 webkit_web_context_set_spell_checking_languages(context,
1150 curconfig[SpellLanguages].val.v);
1151 webkit_web_context_set_spell_checking_enabled(context,
1152 curconfig[SpellChecking].val.i);
1154 g_signal_connect(G_OBJECT(context), "download-started",
1155 G_CALLBACK(downloadstarted), c);
1156 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1157 G_CALLBACK(initwebextensions), c);
1159 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1160 "settings", settings,
1161 "user-content-manager", contentmanager,
1162 "web-context", context,
1166 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1167 G_CALLBACK(progresschanged), c);
1168 g_signal_connect(G_OBJECT(v), "notify::title",
1169 G_CALLBACK(titlechanged), c);
1170 g_signal_connect(G_OBJECT(v), "button-release-event",
1171 G_CALLBACK(buttonreleased), c);
1172 g_signal_connect(G_OBJECT(v), "close",
1173 G_CALLBACK(closeview), c);
1174 g_signal_connect(G_OBJECT(v), "create",
1175 G_CALLBACK(createview), c);
1176 g_signal_connect(G_OBJECT(v), "decide-policy",
1177 G_CALLBACK(decidepolicy), c);
1178 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1179 G_CALLBACK(insecurecontent), c);
1180 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1181 G_CALLBACK(loadfailedtls), c);
1182 g_signal_connect(G_OBJECT(v), "load-changed",
1183 G_CALLBACK(loadchanged), c);
1184 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1185 G_CALLBACK(mousetargetchanged), c);
1186 g_signal_connect(G_OBJECT(v), "permission-request",
1187 G_CALLBACK(permissionrequested), c);
1188 g_signal_connect(G_OBJECT(v), "ready-to-show",
1189 G_CALLBACK(showview), c);
1195 initwebextensions(WebKitWebContext *wc, Client *c)
1197 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1201 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1205 switch (webkit_navigation_action_get_navigation_type(a)) {
1206 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1208 * popup windows of type “other” are almost always triggered
1209 * by user gesture, so inverse the logic here
1211 /* instead of this, compare destination uri to mouse-over uri for validating window */
1212 if (webkit_navigation_action_is_user_gesture(a))
1214 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1215 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1216 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1217 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1218 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1225 return GTK_WIDGET(n->view);
1229 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1231 WebKitHitTestResultContext element;
1234 element = webkit_hit_test_result_get_context(c->mousepos);
1236 for (i = 0; i < LENGTH(buttons); ++i) {
1237 if (element & buttons[i].target &&
1238 e->button.button == buttons[i].button &&
1239 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1241 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1242 return buttons[i].stopevent;
1250 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1252 Client *c = (Client *)d;
1256 if (((XEvent *)e)->type == PropertyNotify) {
1257 ev = &((XEvent *)e)->xproperty;
1258 if (ev->state == PropertyNewValue) {
1259 if (ev->atom == atoms[AtomFind]) {
1262 return GDK_FILTER_REMOVE;
1263 } else if (ev->atom == atoms[AtomGo]) {
1264 a.v = getatom(c, AtomGo);
1267 return GDK_FILTER_REMOVE;
1271 return GDK_FILTER_CONTINUE;
1275 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1280 case GDK_ENTER_NOTIFY:
1281 c->overtitle = c->targeturi;
1285 if (!curconfig[KioskMode].val.i) {
1286 for (i = 0; i < LENGTH(keys); ++i) {
1287 if (gdk_keyval_to_lower(e->key.keyval) ==
1289 CLEANMASK(e->key.state) == keys[i].mod &&
1292 keys[i].func(c, &(keys[i].arg));
1297 case GDK_LEAVE_NOTIFY:
1298 c->overtitle = NULL;
1301 case GDK_WINDOW_STATE:
1302 if (e->window_state.changed_mask ==
1303 GDK_WINDOW_STATE_FULLSCREEN)
1304 c->fullscreen = e->window_state.new_window_state &
1305 GDK_WINDOW_STATE_FULLSCREEN;
1315 showview(WebKitWebView *v, Client *c)
1317 GdkRGBA bgcolor = { 0 };
1320 c->finder = webkit_web_view_get_find_controller(c->view);
1321 c->inspector = webkit_web_view_get_inspector(c->view);
1323 c->win = createwindow(c);
1325 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1326 gtk_widget_show_all(c->win);
1327 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1329 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1330 c->xid = gdk_x11_window_get_xid(gwin);
1333 gdk_display_sync(gtk_widget_get_display(c->win));
1338 if (curconfig[HideBackground].val.i)
1339 webkit_web_view_set_background_color(c->view, &bgcolor);
1341 if (!curconfig[KioskMode].val.i) {
1342 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1343 gdk_window_add_filter(gwin, processx, c);
1346 if (curconfig[RunInFullscreen].val.i)
1347 togglefullscreen(c, NULL);
1349 if (curconfig[ZoomLevel].val.f != 1.0)
1350 webkit_web_view_set_zoom_level(c->view,
1351 curconfig[ZoomLevel].val.f);
1353 setatom(c, AtomFind, "");
1354 setatom(c, AtomUri, "about:blank");
1358 createwindow(Client *c)
1364 w = gtk_plug_new(embed);
1366 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1368 wmstr = g_path_get_basename(argv0);
1369 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1372 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1373 webkit_web_view_get_page_id(c->view));
1374 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1377 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1380 g_signal_connect(G_OBJECT(w), "destroy",
1381 G_CALLBACK(destroywin), c);
1382 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1383 G_CALLBACK(winevent), c);
1384 g_signal_connect(G_OBJECT(w), "key-press-event",
1385 G_CALLBACK(winevent), c);
1386 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1387 G_CALLBACK(winevent), c);
1388 g_signal_connect(G_OBJECT(w), "window-state-event",
1389 G_CALLBACK(winevent), c);
1395 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1396 GTlsCertificateFlags err, Client *c)
1398 GString *errmsg = g_string_new(NULL);
1401 c->failedcert = g_object_ref(cert);
1405 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1406 g_string_append(errmsg,
1407 "The signing certificate authority is not known.<br>");
1408 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1409 g_string_append(errmsg,
1410 "The certificate does not match the expected identity "
1411 "of the site that it was retrieved from.<br>");
1412 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1413 g_string_append(errmsg,
1414 "The certificate's activation time "
1415 "is still in the future.<br>");
1416 if (err & G_TLS_CERTIFICATE_EXPIRED)
1417 g_string_append(errmsg, "The certificate has expired.<br>");
1418 if (err & G_TLS_CERTIFICATE_REVOKED)
1419 g_string_append(errmsg,
1420 "The certificate has been revoked according to "
1421 "the GTlsConnection's certificate revocation list.<br>");
1422 if (err & G_TLS_CERTIFICATE_INSECURE)
1423 g_string_append(errmsg,
1424 "The certificate's algorithm is considered insecure.<br>");
1425 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1426 g_string_append(errmsg,
1427 "Some error occurred validating the certificate.<br>");
1429 g_object_get(cert, "certificate-pem", &pem, NULL);
1430 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1431 "<p>You can inspect the following certificate "
1432 "with Ctrl-t (default keybinding).</p>"
1433 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1435 g_string_free(errmsg, TRUE);
1437 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1444 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1446 const char *uri = geturi(c);
1449 case WEBKIT_LOAD_STARTED:
1450 setatom(c, AtomUri, uri);
1452 c->https = c->insecure = 0;
1453 seturiparameters(c, uri, loadtransient);
1457 g_clear_object(&c->failedcert);
1459 case WEBKIT_LOAD_REDIRECTED:
1460 setatom(c, AtomUri, uri);
1462 seturiparameters(c, uri, loadtransient);
1464 case WEBKIT_LOAD_COMMITTED:
1465 seturiparameters(c, uri, loadcommitted);
1466 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1469 case WEBKIT_LOAD_FINISHED:
1470 seturiparameters(c, uri, loadfinished);
1471 /* Disabled until we write some WebKitWebExtension for
1472 * manipulating the DOM directly.
1473 evalscript(c, "document.documentElement.style.overflow = '%s'",
1474 enablescrollbars ? "auto" : "hidden");
1483 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1485 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1491 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1493 c->title = webkit_web_view_get_title(c->view);
1498 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1501 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1503 /* Keep the hit test to know where is the pointer on the next click */
1507 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1508 else if (hc & OnImg)
1509 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1510 else if (hc & OnMedia)
1511 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1513 c->targeturi = NULL;
1515 c->overtitle = c->targeturi;
1520 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1522 ParamName param = ParameterLast;
1524 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1525 param = Geolocation;
1526 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1527 if (webkit_user_media_permission_is_for_audio_device(
1528 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1529 param = AccessMicrophone;
1530 else if (webkit_user_media_permission_is_for_video_device(
1531 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1532 param = AccessWebcam;
1537 if (curconfig[param].val.i)
1538 webkit_permission_request_allow(r);
1540 webkit_permission_request_deny(r);
1546 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1547 WebKitPolicyDecisionType dt, Client *c)
1550 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1551 decidenavigation(d, c);
1553 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1554 decidenewwindow(d, c);
1556 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1557 decideresource(d, c);
1560 webkit_policy_decision_ignore(d);
1567 decidenavigation(WebKitPolicyDecision *d, Client *c)
1569 WebKitNavigationAction *a =
1570 webkit_navigation_policy_decision_get_navigation_action(
1571 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1573 switch (webkit_navigation_action_get_navigation_type(a)) {
1574 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1575 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1576 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1577 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1578 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1579 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1581 /* Do not navigate to links with a "_blank" target (popup) */
1582 if (webkit_navigation_policy_decision_get_frame_name(
1583 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1584 webkit_policy_decision_ignore(d);
1586 /* Filter out navigation to different domain ? */
1587 /* get action→urirequest, copy and load in new window+view
1588 * on Ctrl+Click ? */
1589 webkit_policy_decision_use(d);
1596 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1599 WebKitNavigationAction *a =
1600 webkit_navigation_policy_decision_get_navigation_action(
1601 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1604 switch (webkit_navigation_action_get_navigation_type(a)) {
1605 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1606 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1607 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1608 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1609 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1610 /* Filter domains here */
1611 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1612 * test for link clicked but no button ? */
1613 arg.v = webkit_uri_request_get_uri(
1614 webkit_navigation_action_get_request(a));
1615 newwindow(c, &arg, 0);
1617 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1622 webkit_policy_decision_ignore(d);
1626 decideresource(WebKitPolicyDecision *d, Client *c)
1629 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1630 WebKitURIResponse *res =
1631 webkit_response_policy_decision_get_response(r);
1632 const gchar *uri = webkit_uri_response_get_uri(res);
1634 if (g_str_has_suffix(uri, "/favicon.ico")) {
1635 webkit_policy_decision_ignore(d);
1639 if (!g_str_has_prefix(uri, "http://")
1640 && !g_str_has_prefix(uri, "https://")
1641 && !g_str_has_prefix(uri, "about:")
1642 && !g_str_has_prefix(uri, "file://")
1643 && !g_str_has_prefix(uri, "data:")
1644 && !g_str_has_prefix(uri, "blob:")
1645 && strlen(uri) > 0) {
1646 for (i = 0; i < strlen(uri); i++) {
1647 if (!g_ascii_isprint(uri[i])) {
1653 handleplumb(c, uri);
1654 webkit_policy_decision_ignore(d);
1659 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1660 webkit_policy_decision_use(d);
1662 webkit_policy_decision_ignore(d);
1668 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1674 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1676 g_signal_connect(G_OBJECT(d), "notify::response",
1677 G_CALLBACK(responsereceived), c);
1681 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1683 download(c, webkit_download_get_response(d));
1684 webkit_download_cancel(d);
1688 download(Client *c, WebKitURIResponse *r)
1690 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1695 closeview(WebKitWebView *v, Client *c)
1697 gtk_widget_destroy(c->win);
1701 destroywin(GtkWidget* w, Client *c)
1709 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1711 Arg a = {.v = text };
1713 loaduri((Client *) d, &a);
1717 reload(Client *c, const Arg *a)
1720 webkit_web_view_reload_bypass_cache(c->view);
1722 webkit_web_view_reload(c->view);
1726 print(Client *c, const Arg *a)
1728 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1729 GTK_WINDOW(c->win));
1733 showcert(Client *c, const Arg *a)
1735 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1736 GcrCertificate *gcrt;
1739 GcrCertificateWidget *wcert;
1744 g_object_get(cert, "certificate", &crt, NULL);
1745 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1746 g_byte_array_unref(crt);
1748 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1749 wcert = gcr_certificate_widget_new(gcrt);
1750 g_object_unref(gcrt);
1752 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1753 gtk_widget_show_all(win);
1757 clipboard(Client *c, const Arg *a)
1759 if (a->i) { /* load clipboard uri */
1760 gtk_clipboard_request_text(gtk_clipboard_get(
1761 GDK_SELECTION_PRIMARY),
1763 } else { /* copy uri */
1764 gtk_clipboard_set_text(gtk_clipboard_get(
1765 GDK_SELECTION_PRIMARY), c->targeturi
1766 ? c->targeturi : geturi(c), -1);
1771 zoom(Client *c, const Arg *a)
1774 webkit_web_view_set_zoom_level(c->view,
1775 curconfig[ZoomLevel].val.f + 0.1);
1777 webkit_web_view_set_zoom_level(c->view,
1778 curconfig[ZoomLevel].val.f - 0.1);
1780 webkit_web_view_set_zoom_level(c->view, 1.0);
1782 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1786 scroll(Client *c, const Arg *a)
1788 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1790 gdk_event_set_device(ev, gdkkb);
1791 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1792 ev->key.state = GDK_CONTROL_MASK;
1793 ev->key.time = GDK_CURRENT_TIME;
1797 ev->key.keyval = GDK_KEY_Down;
1800 ev->key.keyval = GDK_KEY_Page_Down;
1803 ev->key.keyval = GDK_KEY_Left;
1806 ev->key.keyval = GDK_KEY_Right;
1809 ev->key.keyval = GDK_KEY_Page_Up;
1812 ev->key.keyval = GDK_KEY_Up;
1820 navigate(Client *c, const Arg *a)
1823 webkit_web_view_go_back(c->view);
1825 webkit_web_view_go_forward(c->view);
1829 stop(Client *c, const Arg *a)
1831 webkit_web_view_stop_loading(c->view);
1835 toggle(Client *c, const Arg *a)
1837 curconfig[a->i].val.i ^= 1;
1838 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1842 togglefullscreen(Client *c, const Arg *a)
1844 /* toggling value is handled in winevent() */
1846 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1848 gtk_window_fullscreen(GTK_WINDOW(c->win));
1852 togglecookiepolicy(Client *c, const Arg *a)
1855 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1857 setparameter(c, 0, CookiePolicies, NULL);
1861 toggleinspector(Client *c, const Arg *a)
1863 if (webkit_web_inspector_is_attached(c->inspector))
1864 webkit_web_inspector_close(c->inspector);
1865 else if (curconfig[Inspector].val.i)
1866 webkit_web_inspector_show(c->inspector);
1870 find(Client *c, const Arg *a)
1876 webkit_find_controller_search_next(c->finder);
1878 webkit_find_controller_search_previous(c->finder);
1880 s = getatom(c, AtomFind);
1881 f = webkit_find_controller_get_search_text(c->finder);
1883 if (g_strcmp0(f, s) == 0) /* reset search */
1884 webkit_find_controller_search(c->finder, "", findopts,
1887 webkit_find_controller_search(c->finder, s, findopts,
1890 if (strcmp(s, "") == 0)
1891 webkit_find_controller_search_finish(c->finder);
1896 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1902 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1906 arg.v = webkit_hit_test_result_get_link_uri(h);
1907 newwindow(c, &arg, a->i);
1911 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1915 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1920 main(int argc, char *argv[])
1925 memset(&arg, 0, sizeof(arg));
1927 /* command line args */
1930 defconfig[CookiePolicies].val.v = EARGF(usage());
1931 defconfig[CookiePolicies].prio = 2;
1934 defconfig[ScrollBars].val.i = 0;
1935 defconfig[ScrollBars].prio = 2;
1938 defconfig[ScrollBars].val.i = 1;
1939 defconfig[ScrollBars].prio = 2;
1942 cookiefile = EARGF(usage());
1945 stylefile = EARGF(usage());
1948 defconfig[DiskCache].val.i = 0;
1949 defconfig[DiskCache].prio = 2;
1952 defconfig[DiskCache].val.i = 1;
1953 defconfig[DiskCache].prio = 2;
1956 embed = strtol(EARGF(usage()), NULL, 0);
1959 defconfig[RunInFullscreen].val.i = 0;
1960 defconfig[RunInFullscreen].prio = 2;
1963 defconfig[RunInFullscreen].val.i = 1;
1964 defconfig[RunInFullscreen].prio = 2;
1967 defconfig[Geolocation].val.i = 0;
1968 defconfig[Geolocation].prio = 2;
1971 defconfig[Geolocation].val.i = 1;
1972 defconfig[Geolocation].prio = 2;
1975 defconfig[LoadImages].val.i = 0;
1976 defconfig[LoadImages].prio = 2;
1979 defconfig[LoadImages].val.i = 1;
1980 defconfig[LoadImages].prio = 2;
1983 defconfig[KioskMode].val.i = 0;
1984 defconfig[KioskMode].prio = 2;
1987 defconfig[KioskMode].val.i = 1;
1988 defconfig[KioskMode].prio = 2;
1991 defconfig[Style].val.i = 0;
1992 defconfig[Style].prio = 2;
1995 defconfig[Style].val.i = 1;
1996 defconfig[Style].prio = 2;
1999 defconfig[Inspector].val.i = 0;
2000 defconfig[Inspector].prio = 2;
2003 defconfig[Inspector].val.i = 1;
2004 defconfig[Inspector].prio = 2;
2007 defconfig[Plugins].val.i = 0;
2008 defconfig[Plugins].prio = 2;
2011 defconfig[Plugins].val.i = 1;
2012 defconfig[Plugins].prio = 2;
2015 scriptfile = EARGF(usage());
2018 defconfig[JavaScript].val.i = 0;
2019 defconfig[JavaScript].prio = 2;
2022 defconfig[JavaScript].val.i = 1;
2023 defconfig[JavaScript].prio = 2;
2026 defconfig[StrictTLS].val.i = 0;
2027 defconfig[StrictTLS].prio = 2;
2030 defconfig[StrictTLS].val.i = 1;
2031 defconfig[StrictTLS].prio = 2;
2034 fulluseragent = EARGF(usage());
2037 die("surf-"VERSION", see LICENSE for © details\n");
2042 defconfig[Certificate].val.i = 0;
2043 defconfig[Certificate].prio = 2;
2046 defconfig[Certificate].val.i = 1;
2047 defconfig[Certificate].prio = 2;
2050 defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
2051 defconfig[ZoomLevel].prio = 2;
2059 arg.v = "about:blank";
2062 c = newclient(NULL);