1 /* See LICENSE file for copyright and license details.
3 * To understand surf, start reading main().
20 #include <gdk/gdkkeysyms.h>
22 #include <glib/gstdio.h>
26 #include <JavaScriptCore/JavaScript.h>
27 #include <webkit2/webkit2.h>
29 #include <X11/Xatom.h>
34 #define LENGTH(x) (sizeof(x) / sizeof(x[0]))
35 #define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
38 enum { AtomFind, AtomGo, AtomUri, AtomLast };
41 OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
42 OnLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
43 OnImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
44 OnMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
45 OnEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
46 OnBar = WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR,
47 OnSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
48 OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
99 typedef struct Client {
102 WebKitWebInspector *inspector;
103 WebKitFindController *finder;
104 WebKitHitTestResult *mousepos;
105 GTlsCertificate *cert, *failedcert;
106 GTlsCertificateFlags tlserr;
108 unsigned long pageid;
109 int progress, fullscreen, https, insecure, errorpage;
110 const char *title, *overtitle, *targeturi;
118 void (*func)(Client *c, const Arg *a);
126 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
128 unsigned int stopevent;
133 Parameter config[ParameterLast];
144 static void usage(void);
145 static void die(const char *errstr, ...);
146 static void setup(void);
147 static void sigchld(int unused);
148 static void sighup(int unused);
149 static char *buildfile(const char *path);
150 static char *buildpath(const char *path);
151 static char *untildepath(const char *path);
152 static const char *getuserhomedir(const char *user);
153 static const char *getcurrentuserhomedir(void);
154 static Client *newclient(Client *c);
155 static void loaduri(Client *c, const Arg *a);
156 static const char *geturi(Client *c);
157 static void setatom(Client *c, int a, const char *v);
158 static const char *getatom(Client *c, int a);
159 static void updatetitle(Client *c);
160 static void gettogglestats(Client *c);
161 static void getpagestats(Client *c);
162 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
163 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
164 static void seturiparameters(Client *c, const char *uri, ParamName *params);
165 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
166 static const char *getcert(const char *uri);
167 static void setcert(Client *c, const char *file);
168 static const char *getstyle(const char *uri);
169 static void setstyle(Client *c, const char *file);
170 static void runscript(Client *c);
171 static void evalscript(Client *c, const char *jsstr, ...);
172 static void updatewinid(Client *c);
173 static void handleplumb(Client *c, const char *uri);
174 static void newwindow(Client *c, const Arg *a, int noembed);
175 static void spawn(Client *c, const Arg *a);
176 static void msgext(Client *c, char type, const Arg *a);
177 static void destroyclient(Client *c);
178 static void cleanup(void);
181 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
182 static void initwebextensions(WebKitWebContext *wc, Client *c);
183 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
185 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
186 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
188 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
189 static gboolean readpipe(GIOChannel *s, GIOCondition ioc, gpointer unused);
190 static void showview(WebKitWebView *v, Client *c);
191 static GtkWidget *createwindow(Client *c);
192 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
193 GTlsCertificate *cert,
194 GTlsCertificateFlags err, Client *c);
195 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
196 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
197 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
198 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
199 guint modifiers, Client *c);
200 static gboolean permissionrequested(WebKitWebView *v,
201 WebKitPermissionRequest *r, Client *c);
202 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
203 WebKitPolicyDecisionType dt, Client *c);
204 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
205 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
206 static void decideresource(WebKitPolicyDecision *d, Client *c);
207 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
209 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
211 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
212 static void download(Client *c, WebKitURIResponse *r);
213 static void webprocessterminated(WebKitWebView *v,
214 WebKitWebProcessTerminationReason r,
216 static void closeview(WebKitWebView *v, Client *c);
217 static void destroywin(GtkWidget* w, Client *c);
220 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
221 static void reload(Client *c, const Arg *a);
222 static void print(Client *c, const Arg *a);
223 static void showcert(Client *c, const Arg *a);
224 static void clipboard(Client *c, const Arg *a);
225 static void zoom(Client *c, const Arg *a);
226 static void scrollv(Client *c, const Arg *a);
227 static void scrollh(Client *c, const Arg *a);
228 static void navigate(Client *c, const Arg *a);
229 static void stop(Client *c, const Arg *a);
230 static void toggle(Client *c, const Arg *a);
231 static void togglefullscreen(Client *c, const Arg *a);
232 static void togglecookiepolicy(Client *c, const Arg *a);
233 static void toggleinspector(Client *c, const Arg *a);
234 static void find(Client *c, const Arg *a);
237 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
238 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
239 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
241 static char winid[64];
242 static char togglestats[12];
243 static char pagestats[2];
244 static Atom atoms[AtomLast];
247 static int cookiepolicy;
249 static Client *clients;
250 static GdkDevice *gdkkb;
251 static char *stylefile;
252 static const char *useragent;
253 static Parameter *curconfig;
254 static int modparams[ParameterLast];
255 static int pipein[2], pipeout[2];
258 static ParamName loadtransient[] = {
272 static ParamName loadcommitted[] = {
298 static ParamName loadfinished[] = {
302 /* configuration, allows nested code to access above variables */
308 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
309 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
310 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
314 die(const char *errstr, ...)
318 va_start(ap, errstr);
319 vfprintf(stderr, errstr, ap);
331 /* clean up any zombies immediately */
333 if (signal(SIGHUP, sighup) == SIG_ERR)
334 die("Can't install SIGHUP handler");
336 if (!(dpy = XOpenDisplay(NULL)))
337 die("Can't open default display");
340 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
341 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
342 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
344 gtk_init(NULL, NULL);
346 gdpy = gdk_display_get_default();
348 curconfig = defconfig;
351 cookiefile = buildfile(cookiefile);
352 scriptfile = buildfile(scriptfile);
353 cachedir = buildpath(cachedir);
354 certdir = buildpath(certdir);
356 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
358 if (pipe(pipeout) < 0 || pipe(pipein) < 0) {
359 fputs("Unable to create pipes\n", stderr);
361 gchanin = g_io_channel_unix_new(pipein[0]);
362 g_io_channel_set_encoding(gchanin, NULL, NULL);
363 g_io_channel_set_close_on_unref(gchanin, TRUE);
364 g_io_add_watch(gchanin, G_IO_IN, readpipe, NULL);
368 for (i = 0; i < LENGTH(certs); ++i) {
369 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
370 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
373 fprintf(stderr, "Could not compile regex: %s\n",
375 certs[i].regex = NULL;
380 styledir = buildpath(styledir);
381 for (i = 0; i < LENGTH(styles); ++i) {
382 if (!regcomp(&(styles[i].re), styles[i].regex,
384 styles[i].file = g_strconcat(styledir, "/",
385 styles[i].file, NULL);
387 fprintf(stderr, "Could not compile regex: %s\n",
389 styles[i].regex = NULL;
394 stylefile = buildfile(stylefile);
397 for (i = 0; i < LENGTH(uriparams); ++i) {
398 if (regcomp(&(uriparams[i].re), uriparams[i].uri,
400 fprintf(stderr, "Could not compile regex: %s\n",
402 uriparams[i].uri = NULL;
406 /* copy default parameters with higher priority */
407 for (j = 0; j < ParameterLast; ++j) {
408 if (defconfig[j].prio >= uriparams[i].config[j].prio)
409 uriparams[i].config[j] = defconfig[j];
417 if (signal(SIGCHLD, sigchld) == SIG_ERR)
418 die("Can't install SIGCHLD handler");
419 while (waitpid(-1, NULL, WNOHANG) > 0)
429 for (c = clients; c; c = c->next)
434 buildfile(const char *path)
436 char *dname, *bname, *bpath, *fpath;
439 dname = g_path_get_dirname(path);
440 bname = g_path_get_basename(path);
442 bpath = buildpath(dname);
445 fpath = g_build_filename(bpath, bname, NULL);
449 if (!(f = fopen(fpath, "a")))
450 die("Could not open file: %s\n", fpath);
452 g_chmod(fpath, 0600); /* always */
459 getuserhomedir(const char *user)
461 struct passwd *pw = getpwnam(user);
464 die("Can't get user %s login information.\n", user);
470 getcurrentuserhomedir(void)
476 homedir = getenv("HOME");
480 user = getenv("USER");
482 return getuserhomedir(user);
484 pw = getpwuid(getuid());
486 die("Can't get current user home directory\n");
492 buildpath(const char *path)
497 apath = untildepath(path);
499 apath = g_strdup(path);
501 /* creating directory */
502 if (g_mkdir_with_parents(apath, 0700) < 0)
503 die("Could not access directory: %s\n", apath);
505 fpath = realpath(apath, NULL);
512 untildepath(const char *path)
514 char *apath, *name, *p;
517 if (path[1] == '/' || path[1] == '\0') {
518 p = (char *)&path[1];
519 homedir = getcurrentuserhomedir();
521 if ((p = strchr(path, '/')))
522 name = g_strndup(&path[1], p - (path + 1));
524 name = g_strdup(&path[1]);
526 homedir = getuserhomedir(name);
529 apath = g_build_filename(homedir, p, NULL);
534 newclient(Client *rc)
538 if (!(c = calloc(1, sizeof(Client))))
539 die("Cannot malloc!\n");
545 c->view = newview(c, rc ? rc->view : NULL);
551 loaduri(Client *c, const Arg *a)
554 char *url, *path, *apath;
555 const char *uri = a->v;
557 if (g_strcmp0(uri, "") == 0)
560 if (g_str_has_prefix(uri, "http://") ||
561 g_str_has_prefix(uri, "https://") ||
562 g_str_has_prefix(uri, "file://") ||
563 g_str_has_prefix(uri, "about:")) {
567 apath = untildepath(uri);
570 if (!stat(apath, &st) && (path = realpath(apath, NULL))) {
571 url = g_strdup_printf("file://%s", path);
574 url = g_strdup_printf("http://%s", uri);
580 setatom(c, AtomUri, url);
582 if (strcmp(url, geturi(c)) == 0) {
585 webkit_web_view_load_uri(c->view, url);
597 if (!(uri = webkit_web_view_get_uri(c->view)))
603 setatom(Client *c, int a, const char *v)
605 XChangeProperty(dpy, c->xid,
606 atoms[a], XA_STRING, 8, PropModeReplace,
607 (unsigned char *)v, strlen(v) + 1);
612 getatom(Client *c, int a)
614 static char buf[BUFSIZ];
617 unsigned long ldummy;
618 unsigned char *p = NULL;
621 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
622 &adummy, &idummy, &ldummy, &ldummy, &p);
624 strncpy(buf, (char *)p, LENGTH(buf) - 1);
633 updatetitle(Client *c)
636 const char *name = c->overtitle ? c->overtitle :
637 c->title ? c->title : "";
639 if (curconfig[ShowIndicators].val.i) {
643 if (c->progress != 100)
644 title = g_strdup_printf("[%i%%] %s:%s | %s",
645 c->progress, togglestats, pagestats, name);
647 title = g_strdup_printf("%s:%s | %s",
648 togglestats, pagestats, name);
650 gtk_window_set_title(GTK_WINDOW(c->win), title);
653 gtk_window_set_title(GTK_WINDOW(c->win), name);
658 gettogglestats(Client *c)
660 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
661 togglestats[1] = curconfig[CaretBrowsing].val.i ? 'C' : 'c';
662 togglestats[2] = curconfig[Geolocation].val.i ? 'G' : 'g';
663 togglestats[3] = curconfig[DiskCache].val.i ? 'D' : 'd';
664 togglestats[4] = curconfig[LoadImages].val.i ? 'I' : 'i';
665 togglestats[5] = curconfig[JavaScript].val.i ? 'S' : 's';
666 togglestats[6] = curconfig[Plugins].val.i ? 'V' : 'v';
667 togglestats[7] = curconfig[Style].val.i ? 'M' : 'm';
668 togglestats[8] = curconfig[FrameFlattening].val.i ? 'F' : 'f';
669 togglestats[9] = curconfig[Certificate].val.i ? 'X' : 'x';
670 togglestats[10] = curconfig[StrictTLS].val.i ? 'T' : 't';
671 togglestats[11] = '\0';
675 getpagestats(Client *c)
678 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
684 WebKitCookieAcceptPolicy
685 cookiepolicy_get(void)
687 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
689 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
691 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
692 default: /* fallthrough */
694 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
699 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
702 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
704 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
706 default: /* fallthrough */
707 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
713 seturiparameters(Client *c, const char *uri, ParamName *params)
715 Parameter *config, *uriconfig = NULL;
718 for (i = 0; i < LENGTH(uriparams); ++i) {
719 if (uriparams[i].uri &&
720 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
721 uriconfig = uriparams[i].config;
726 curconfig = uriconfig ? uriconfig : defconfig;
728 for (i = 0; (p = params[i]) != ParameterLast; ++i) {
730 default: /* FALLTHROUGH */
731 if (!(defconfig[p].prio < curconfig[p].prio ||
732 defconfig[p].prio < modparams[p]))
737 setparameter(c, 0, p, &curconfig[p].val);
743 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
745 GdkRGBA bgcolor = { 0 };
746 WebKitSettings *s = webkit_web_view_get_settings(c->view);
748 modparams[p] = curconfig[p].prio;
751 case AcceleratedCanvas:
752 webkit_settings_set_enable_accelerated_2d_canvas(s, a->i);
754 case AccessMicrophone:
755 return; /* do nothing */
757 return; /* do nothing */
759 webkit_settings_set_enable_caret_browsing(s, a->i);
764 setcert(c, geturi(c));
765 return; /* do not update */
767 webkit_cookie_manager_set_accept_policy(
768 webkit_web_context_get_cookie_manager(
769 webkit_web_view_get_context(c->view)),
774 webkit_web_context_set_cache_model(
775 webkit_web_view_get_context(c->view), a->i ?
776 WEBKIT_CACHE_MODEL_WEB_BROWSER :
777 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
778 return; /* do not update */
780 webkit_settings_set_default_charset(s, a->v);
781 return; /* do not update */
783 webkit_settings_set_enable_dns_prefetching(s, a->i);
784 return; /* do not update */
785 case FileURLsCrossAccess:
786 webkit_settings_set_allow_file_access_from_file_urls(s, a->i);
787 webkit_settings_set_allow_universal_access_from_file_urls(s, a->i);
788 return; /* do not update */
790 webkit_settings_set_default_font_size(s, a->i);
791 return; /* do not update */
792 case FrameFlattening:
793 webkit_settings_set_enable_frame_flattening(s, a->i);
800 webkit_web_view_set_background_color(c->view, &bgcolor);
801 return; /* do not update */
803 webkit_settings_set_enable_developer_extras(s, a->i);
804 return; /* do not update */
806 webkit_settings_set_enable_java(s, a->i);
807 return; /* do not update */
809 webkit_settings_set_enable_javascript(s, a->i);
812 return; /* do nothing */
814 webkit_settings_set_auto_load_images(s, a->i);
816 case MediaManualPlay:
817 webkit_settings_set_media_playback_requires_user_gesture(s, a->i);
820 webkit_settings_set_enable_plugins(s, a->i);
822 case PreferredLanguages:
823 return; /* do nothing */
824 case RunInFullscreen:
825 return; /* do nothing */
827 /* Disabled until we write some WebKitWebExtension for
828 * manipulating the DOM directly.
829 enablescrollbars = !enablescrollbars;
830 evalscript(c, "document.documentElement.style.overflow = '%s'",
831 enablescrollbars ? "auto" : "hidden");
833 return; /* do not update */
836 case SmoothScrolling:
837 webkit_settings_set_enable_smooth_scrolling(s, a->i);
838 return; /* do not update */
840 webkit_settings_set_enable_site_specific_quirks(s, a->i);
843 webkit_web_context_set_spell_checking_enabled(
844 webkit_web_view_get_context(c->view), a->i);
845 return; /* do not update */
847 return; /* do nothing */
849 webkit_web_context_set_tls_errors_policy(
850 webkit_web_view_get_context(c->view), a->i ?
851 WEBKIT_TLS_ERRORS_POLICY_FAIL :
852 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
855 webkit_user_content_manager_remove_all_style_sheets(
856 webkit_web_view_get_user_content_manager(c->view));
858 setstyle(c, getstyle(geturi(c)));
862 webkit_settings_set_enable_webgl(s, a->i);
865 webkit_web_view_set_zoom_level(c->view, a->f);
866 return; /* do not update */
868 return; /* do nothing */
877 getcert(const char *uri)
881 for (i = 0; i < LENGTH(certs); ++i) {
882 if (certs[i].regex &&
883 !regexec(&(certs[i].re), uri, 0, NULL, 0))
884 return certs[i].file;
891 setcert(Client *c, const char *uri)
893 const char *file = getcert(uri);
895 GTlsCertificate *cert;
900 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
901 fprintf(stderr, "Could not read certificate file: %s\n", file);
905 if ((uri = strstr(uri, "https://"))) {
906 uri += sizeof("https://") - 1;
907 host = g_strndup(uri, strchr(uri, '/') - uri);
908 webkit_web_context_allow_tls_certificate_for_host(
909 webkit_web_view_get_context(c->view), cert, host);
913 g_object_unref(cert);
918 getstyle(const char *uri)
925 for (i = 0; i < LENGTH(styles); ++i) {
926 if (styles[i].regex &&
927 !regexec(&(styles[i].re), uri, 0, NULL, 0))
928 return styles[i].file;
935 setstyle(Client *c, const char *file)
939 if (!g_file_get_contents(file, &style, NULL, NULL)) {
940 fprintf(stderr, "Could not read style file: %s\n", file);
944 webkit_user_content_manager_add_style_sheet(
945 webkit_web_view_get_user_content_manager(c->view),
946 webkit_user_style_sheet_new(style,
947 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
948 WEBKIT_USER_STYLE_LEVEL_USER,
960 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
961 evalscript(c, "%s", script);
966 evalscript(Client *c, const char *jsstr, ...)
972 script = g_strdup_vprintf(jsstr, ap);
975 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
980 updatewinid(Client *c)
982 snprintf(winid, LENGTH(winid), "%lu", c->xid);
986 handleplumb(Client *c, const char *uri)
988 Arg a = (Arg)PLUMB(uri);
993 newwindow(Client *c, const Arg *a, int noembed)
997 const char *cmd[29], *uri;
998 const Arg arg = { .v = cmd };
1002 cmd[i++] = curconfig[CookiePolicies].val.v;
1003 cmd[i++] = curconfig[ScrollBars].val.i ? "-B" : "-b";
1004 if (cookiefile && g_strcmp0(cookiefile, "")) {
1006 cmd[i++] = cookiefile;
1008 if (stylefile && g_strcmp0(stylefile, "")) {
1010 cmd[i++] = stylefile;
1012 cmd[i++] = curconfig[DiskCache].val.i ? "-D" : "-d";
1013 if (embed && !noembed) {
1015 snprintf(tmp, LENGTH(tmp), "%lu", embed);
1018 cmd[i++] = curconfig[RunInFullscreen].val.i ? "-F" : "-f" ;
1019 cmd[i++] = curconfig[Geolocation].val.i ? "-G" : "-g" ;
1020 cmd[i++] = curconfig[LoadImages].val.i ? "-I" : "-i" ;
1021 cmd[i++] = curconfig[KioskMode].val.i ? "-K" : "-k" ;
1022 cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ;
1023 cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ;
1024 cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ;
1025 if (scriptfile && g_strcmp0(scriptfile, "")) {
1027 cmd[i++] = scriptfile;
1029 cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
1030 cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
1031 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
1033 cmd[i++] = fulluseragent;
1037 cmd[i++] = curconfig[Certificate].val.i ? "-X" : "-x" ;
1038 /* do not keep zoom level */
1048 spawn(Client *c, const Arg *a)
1052 close(ConnectionNumber(dpy));
1056 execvp(((char **)a->v)[0], (char **)a->v);
1057 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
1064 destroyclient(Client *c)
1068 webkit_web_view_stop_loading(c->view);
1069 /* Not needed, has already been called
1070 gtk_widget_destroy(c->win);
1073 for (p = clients; p && p->next != c; p = p->next)
1086 destroyclient(clients);
1098 newview(Client *c, WebKitWebView *rv)
1101 WebKitSettings *settings;
1102 WebKitWebContext *context;
1103 WebKitCookieManager *cookiemanager;
1104 WebKitUserContentManager *contentmanager;
1108 v = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(rv));
1110 settings = webkit_settings_new_with_settings(
1111 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1112 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i,
1113 "auto-load-images", curconfig[LoadImages].val.i,
1114 "default-charset", curconfig[DefaultCharset].val.v,
1115 "default-font-size", curconfig[FontSize].val.i,
1116 "enable-caret-browsing", curconfig[CaretBrowsing].val.i,
1117 "enable-developer-extras", curconfig[Inspector].val.i,
1118 "enable-dns-prefetching", curconfig[DNSPrefetch].val.i,
1119 "enable-frame-flattening", curconfig[FrameFlattening].val.i,
1120 "enable-html5-database", curconfig[DiskCache].val.i,
1121 "enable-html5-local-storage", curconfig[DiskCache].val.i,
1122 "enable-java", curconfig[Java].val.i,
1123 "enable-javascript", curconfig[JavaScript].val.i,
1124 "enable-plugins", curconfig[Plugins].val.i,
1125 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.i,
1126 "enable-site-specific-quirks", curconfig[SiteQuirks].val.i,
1127 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.i,
1128 "enable-webgl", curconfig[WebGL].val.i,
1129 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.i,
1131 /* For more interesting settings, have a look at
1132 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1134 if (strcmp(fulluseragent, "")) {
1135 webkit_settings_set_user_agent(settings, fulluseragent);
1136 } else if (surfuseragent) {
1137 webkit_settings_set_user_agent_with_application_details(
1138 settings, "Surf", VERSION);
1140 useragent = webkit_settings_get_user_agent(settings);
1142 contentmanager = webkit_user_content_manager_new();
1144 context = webkit_web_context_new_with_website_data_manager(
1145 webkit_website_data_manager_new(
1146 "base-cache-directory", cachedir,
1147 "base-data-directory", cachedir,
1150 cookiemanager = webkit_web_context_get_cookie_manager(context);
1152 /* rendering process model, can be a shared unique one
1153 * or one for each view */
1154 webkit_web_context_set_process_model(context,
1155 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1157 webkit_web_context_set_tls_errors_policy(context,
1158 curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1159 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1161 webkit_web_context_set_cache_model(context,
1162 curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1163 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1165 /* Currently only works with text file to be compatible with curl */
1166 webkit_cookie_manager_set_persistent_storage(cookiemanager,
1167 cookiefile, WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1169 webkit_cookie_manager_set_accept_policy(cookiemanager,
1170 cookiepolicy_get());
1172 webkit_web_context_set_preferred_languages(context,
1173 curconfig[PreferredLanguages].val.v);
1174 webkit_web_context_set_spell_checking_languages(context,
1175 curconfig[SpellLanguages].val.v);
1176 webkit_web_context_set_spell_checking_enabled(context,
1177 curconfig[SpellChecking].val.i);
1179 g_signal_connect(G_OBJECT(context), "download-started",
1180 G_CALLBACK(downloadstarted), c);
1181 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1182 G_CALLBACK(initwebextensions), c);
1184 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1185 "settings", settings,
1186 "user-content-manager", contentmanager,
1187 "web-context", context,
1191 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1192 G_CALLBACK(progresschanged), c);
1193 g_signal_connect(G_OBJECT(v), "notify::title",
1194 G_CALLBACK(titlechanged), c);
1195 g_signal_connect(G_OBJECT(v), "button-release-event",
1196 G_CALLBACK(buttonreleased), c);
1197 g_signal_connect(G_OBJECT(v), "close",
1198 G_CALLBACK(closeview), c);
1199 g_signal_connect(G_OBJECT(v), "create",
1200 G_CALLBACK(createview), c);
1201 g_signal_connect(G_OBJECT(v), "decide-policy",
1202 G_CALLBACK(decidepolicy), c);
1203 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1204 G_CALLBACK(insecurecontent), c);
1205 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1206 G_CALLBACK(loadfailedtls), c);
1207 g_signal_connect(G_OBJECT(v), "load-changed",
1208 G_CALLBACK(loadchanged), c);
1209 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1210 G_CALLBACK(mousetargetchanged), c);
1211 g_signal_connect(G_OBJECT(v), "permission-request",
1212 G_CALLBACK(permissionrequested), c);
1213 g_signal_connect(G_OBJECT(v), "ready-to-show",
1214 G_CALLBACK(showview), c);
1215 g_signal_connect(G_OBJECT(v), "web-process-terminated",
1216 G_CALLBACK(webprocessterminated), c);
1222 readpipe(GIOChannel *s, GIOCondition ioc, gpointer unused)
1226 GError *gerr = NULL;
1228 if (g_io_channel_read_chars(s, msg, sizeof(msg), &msgsz, &gerr) !=
1229 G_IO_STATUS_NORMAL) {
1230 fprintf(stderr, "surf: error reading pipe: %s\n",
1248 initwebextensions(WebKitWebContext *wc, Client *c)
1252 if (!pipeout[0] || !pipein[1])
1255 gv = g_variant_new("(ii)", pipeout[0], pipein[1]);
1257 webkit_web_context_set_web_extensions_initialization_user_data(wc, gv);
1258 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1262 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1266 switch (webkit_navigation_action_get_navigation_type(a)) {
1267 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1269 * popup windows of type “other” are almost always triggered
1270 * by user gesture, so inverse the logic here
1272 /* instead of this, compare destination uri to mouse-over uri for validating window */
1273 if (webkit_navigation_action_is_user_gesture(a))
1275 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1276 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1277 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1278 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1279 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1286 return GTK_WIDGET(n->view);
1290 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1292 WebKitHitTestResultContext element;
1295 element = webkit_hit_test_result_get_context(c->mousepos);
1297 for (i = 0; i < LENGTH(buttons); ++i) {
1298 if (element & buttons[i].target &&
1299 e->button.button == buttons[i].button &&
1300 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1302 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1303 return buttons[i].stopevent;
1311 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1313 Client *c = (Client *)d;
1317 if (((XEvent *)e)->type == PropertyNotify) {
1318 ev = &((XEvent *)e)->xproperty;
1319 if (ev->state == PropertyNewValue) {
1320 if (ev->atom == atoms[AtomFind]) {
1323 return GDK_FILTER_REMOVE;
1324 } else if (ev->atom == atoms[AtomGo]) {
1325 a.v = getatom(c, AtomGo);
1328 return GDK_FILTER_REMOVE;
1332 return GDK_FILTER_CONTINUE;
1336 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1341 case GDK_ENTER_NOTIFY:
1342 c->overtitle = c->targeturi;
1346 if (!curconfig[KioskMode].val.i) {
1347 for (i = 0; i < LENGTH(keys); ++i) {
1348 if (gdk_keyval_to_lower(e->key.keyval) ==
1350 CLEANMASK(e->key.state) == keys[i].mod &&
1353 keys[i].func(c, &(keys[i].arg));
1358 case GDK_LEAVE_NOTIFY:
1359 c->overtitle = NULL;
1362 case GDK_WINDOW_STATE:
1363 if (e->window_state.changed_mask ==
1364 GDK_WINDOW_STATE_FULLSCREEN)
1365 c->fullscreen = e->window_state.new_window_state &
1366 GDK_WINDOW_STATE_FULLSCREEN;
1376 showview(WebKitWebView *v, Client *c)
1378 GdkRGBA bgcolor = { 0 };
1381 c->finder = webkit_web_view_get_find_controller(c->view);
1382 c->inspector = webkit_web_view_get_inspector(c->view);
1384 c->pageid = webkit_web_view_get_page_id(c->view);
1385 c->win = createwindow(c);
1387 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1388 gtk_widget_show_all(c->win);
1389 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1391 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1392 c->xid = gdk_x11_window_get_xid(gwin);
1395 gdk_display_sync(gtk_widget_get_display(c->win));
1400 if (curconfig[HideBackground].val.i)
1401 webkit_web_view_set_background_color(c->view, &bgcolor);
1403 if (!curconfig[KioskMode].val.i) {
1404 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1405 gdk_window_add_filter(gwin, processx, c);
1408 if (curconfig[RunInFullscreen].val.i)
1409 togglefullscreen(c, NULL);
1411 if (curconfig[ZoomLevel].val.f != 1.0)
1412 webkit_web_view_set_zoom_level(c->view,
1413 curconfig[ZoomLevel].val.f);
1415 setatom(c, AtomFind, "");
1416 setatom(c, AtomUri, "about:blank");
1420 createwindow(Client *c)
1426 w = gtk_plug_new(embed);
1428 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1430 wmstr = g_path_get_basename(argv0);
1431 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1434 wmstr = g_strdup_printf("%s[%lu]", "Surf", c->pageid);
1435 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1438 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1441 g_signal_connect(G_OBJECT(w), "destroy",
1442 G_CALLBACK(destroywin), c);
1443 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1444 G_CALLBACK(winevent), c);
1445 g_signal_connect(G_OBJECT(w), "key-press-event",
1446 G_CALLBACK(winevent), c);
1447 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1448 G_CALLBACK(winevent), c);
1449 g_signal_connect(G_OBJECT(w), "window-state-event",
1450 G_CALLBACK(winevent), c);
1456 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1457 GTlsCertificateFlags err, Client *c)
1459 GString *errmsg = g_string_new(NULL);
1462 c->failedcert = g_object_ref(cert);
1466 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1467 g_string_append(errmsg,
1468 "The signing certificate authority is not known.<br>");
1469 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1470 g_string_append(errmsg,
1471 "The certificate does not match the expected identity "
1472 "of the site that it was retrieved from.<br>");
1473 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1474 g_string_append(errmsg,
1475 "The certificate's activation time "
1476 "is still in the future.<br>");
1477 if (err & G_TLS_CERTIFICATE_EXPIRED)
1478 g_string_append(errmsg, "The certificate has expired.<br>");
1479 if (err & G_TLS_CERTIFICATE_REVOKED)
1480 g_string_append(errmsg,
1481 "The certificate has been revoked according to "
1482 "the GTlsConnection's certificate revocation list.<br>");
1483 if (err & G_TLS_CERTIFICATE_INSECURE)
1484 g_string_append(errmsg,
1485 "The certificate's algorithm is considered insecure.<br>");
1486 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1487 g_string_append(errmsg,
1488 "Some error occurred validating the certificate.<br>");
1490 g_object_get(cert, "certificate-pem", &pem, NULL);
1491 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1492 "<p>You can inspect the following certificate "
1493 "with Ctrl-t (default keybinding).</p>"
1494 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1496 g_string_free(errmsg, TRUE);
1498 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1505 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1507 const char *uri = geturi(c);
1510 case WEBKIT_LOAD_STARTED:
1511 setatom(c, AtomUri, uri);
1513 c->https = c->insecure = 0;
1514 seturiparameters(c, uri, loadtransient);
1518 g_clear_object(&c->failedcert);
1520 case WEBKIT_LOAD_REDIRECTED:
1521 setatom(c, AtomUri, uri);
1523 seturiparameters(c, uri, loadtransient);
1525 case WEBKIT_LOAD_COMMITTED:
1526 seturiparameters(c, uri, loadcommitted);
1527 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1530 case WEBKIT_LOAD_FINISHED:
1531 seturiparameters(c, uri, loadfinished);
1532 /* Disabled until we write some WebKitWebExtension for
1533 * manipulating the DOM directly.
1534 evalscript(c, "document.documentElement.style.overflow = '%s'",
1535 enablescrollbars ? "auto" : "hidden");
1544 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1546 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1552 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1554 c->title = webkit_web_view_get_title(c->view);
1559 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1562 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1564 /* Keep the hit test to know where is the pointer on the next click */
1568 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1569 else if (hc & OnImg)
1570 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1571 else if (hc & OnMedia)
1572 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1574 c->targeturi = NULL;
1576 c->overtitle = c->targeturi;
1581 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1583 ParamName param = ParameterLast;
1585 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1586 param = Geolocation;
1587 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1588 if (webkit_user_media_permission_is_for_audio_device(
1589 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1590 param = AccessMicrophone;
1591 else if (webkit_user_media_permission_is_for_video_device(
1592 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1593 param = AccessWebcam;
1598 if (curconfig[param].val.i)
1599 webkit_permission_request_allow(r);
1601 webkit_permission_request_deny(r);
1607 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1608 WebKitPolicyDecisionType dt, Client *c)
1611 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1612 decidenavigation(d, c);
1614 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1615 decidenewwindow(d, c);
1617 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1618 decideresource(d, c);
1621 webkit_policy_decision_ignore(d);
1628 decidenavigation(WebKitPolicyDecision *d, Client *c)
1630 WebKitNavigationAction *a =
1631 webkit_navigation_policy_decision_get_navigation_action(
1632 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1634 switch (webkit_navigation_action_get_navigation_type(a)) {
1635 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1636 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1637 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1638 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1639 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1640 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1642 /* Do not navigate to links with a "_blank" target (popup) */
1643 if (webkit_navigation_policy_decision_get_frame_name(
1644 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1645 webkit_policy_decision_ignore(d);
1647 /* Filter out navigation to different domain ? */
1648 /* get action→urirequest, copy and load in new window+view
1649 * on Ctrl+Click ? */
1650 webkit_policy_decision_use(d);
1657 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1660 WebKitNavigationAction *a =
1661 webkit_navigation_policy_decision_get_navigation_action(
1662 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1665 switch (webkit_navigation_action_get_navigation_type(a)) {
1666 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1667 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1668 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1669 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1670 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1671 /* Filter domains here */
1672 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1673 * test for link clicked but no button ? */
1674 arg.v = webkit_uri_request_get_uri(
1675 webkit_navigation_action_get_request(a));
1676 newwindow(c, &arg, 0);
1678 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1683 webkit_policy_decision_ignore(d);
1687 decideresource(WebKitPolicyDecision *d, Client *c)
1690 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1691 WebKitURIResponse *res =
1692 webkit_response_policy_decision_get_response(r);
1693 const gchar *uri = webkit_uri_response_get_uri(res);
1695 if (g_str_has_suffix(uri, "/favicon.ico")) {
1696 webkit_policy_decision_ignore(d);
1700 if (!g_str_has_prefix(uri, "http://")
1701 && !g_str_has_prefix(uri, "https://")
1702 && !g_str_has_prefix(uri, "about:")
1703 && !g_str_has_prefix(uri, "file://")
1704 && !g_str_has_prefix(uri, "data:")
1705 && !g_str_has_prefix(uri, "blob:")
1706 && strlen(uri) > 0) {
1707 for (i = 0; i < strlen(uri); i++) {
1708 if (!g_ascii_isprint(uri[i])) {
1714 handleplumb(c, uri);
1715 webkit_policy_decision_ignore(d);
1720 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1721 webkit_policy_decision_use(d);
1723 webkit_policy_decision_ignore(d);
1729 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1735 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1737 g_signal_connect(G_OBJECT(d), "notify::response",
1738 G_CALLBACK(responsereceived), c);
1742 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1744 download(c, webkit_download_get_response(d));
1745 webkit_download_cancel(d);
1749 download(Client *c, WebKitURIResponse *r)
1751 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1756 webprocessterminated(WebKitWebView *v, WebKitWebProcessTerminationReason r,
1759 fprintf(stderr, "web process terminated: %s\n",
1760 r == WEBKIT_WEB_PROCESS_CRASHED ? "crashed" : "no memory");
1765 closeview(WebKitWebView *v, Client *c)
1767 gtk_widget_destroy(c->win);
1771 destroywin(GtkWidget* w, Client *c)
1779 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1781 Arg a = {.v = text };
1783 loaduri((Client *) d, &a);
1787 reload(Client *c, const Arg *a)
1790 webkit_web_view_reload_bypass_cache(c->view);
1792 webkit_web_view_reload(c->view);
1796 print(Client *c, const Arg *a)
1798 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1799 GTK_WINDOW(c->win));
1803 showcert(Client *c, const Arg *a)
1805 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1806 GcrCertificate *gcrt;
1809 GcrCertificateWidget *wcert;
1814 g_object_get(cert, "certificate", &crt, NULL);
1815 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1816 g_byte_array_unref(crt);
1818 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1819 wcert = gcr_certificate_widget_new(gcrt);
1820 g_object_unref(gcrt);
1822 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1823 gtk_widget_show_all(win);
1827 clipboard(Client *c, const Arg *a)
1829 if (a->i) { /* load clipboard uri */
1830 gtk_clipboard_request_text(gtk_clipboard_get(
1831 GDK_SELECTION_PRIMARY),
1833 } else { /* copy uri */
1834 gtk_clipboard_set_text(gtk_clipboard_get(
1835 GDK_SELECTION_PRIMARY), c->targeturi
1836 ? c->targeturi : geturi(c), -1);
1841 zoom(Client *c, const Arg *a)
1844 webkit_web_view_set_zoom_level(c->view,
1845 curconfig[ZoomLevel].val.f + 0.1);
1847 webkit_web_view_set_zoom_level(c->view,
1848 curconfig[ZoomLevel].val.f - 0.1);
1850 webkit_web_view_set_zoom_level(c->view, 1.0);
1852 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1856 msgext(Client *c, char type, const Arg *a)
1858 char msg[MSGBUFSZ] = { c->pageid, type, a->i, '\0' };
1861 if (write(pipeout[1], msg, sizeof(msg)) < 0)
1862 fprintf(stderr, "surf: error sending: %s\n", msg);
1867 scrollv(Client *c, const Arg *a)
1873 scrollh(Client *c, const Arg *a)
1879 navigate(Client *c, const Arg *a)
1882 webkit_web_view_go_back(c->view);
1884 webkit_web_view_go_forward(c->view);
1888 stop(Client *c, const Arg *a)
1890 webkit_web_view_stop_loading(c->view);
1894 toggle(Client *c, const Arg *a)
1896 curconfig[a->i].val.i ^= 1;
1897 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1901 togglefullscreen(Client *c, const Arg *a)
1903 /* toggling value is handled in winevent() */
1905 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1907 gtk_window_fullscreen(GTK_WINDOW(c->win));
1911 togglecookiepolicy(Client *c, const Arg *a)
1914 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1916 setparameter(c, 0, CookiePolicies, NULL);
1920 toggleinspector(Client *c, const Arg *a)
1922 if (webkit_web_inspector_is_attached(c->inspector))
1923 webkit_web_inspector_close(c->inspector);
1924 else if (curconfig[Inspector].val.i)
1925 webkit_web_inspector_show(c->inspector);
1929 find(Client *c, const Arg *a)
1935 webkit_find_controller_search_next(c->finder);
1937 webkit_find_controller_search_previous(c->finder);
1939 s = getatom(c, AtomFind);
1940 f = webkit_find_controller_get_search_text(c->finder);
1942 if (g_strcmp0(f, s) == 0) /* reset search */
1943 webkit_find_controller_search(c->finder, "", findopts,
1946 webkit_find_controller_search(c->finder, s, findopts,
1949 if (strcmp(s, "") == 0)
1950 webkit_find_controller_search_finish(c->finder);
1955 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1961 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1965 arg.v = webkit_hit_test_result_get_link_uri(h);
1966 newwindow(c, &arg, a->i);
1970 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1974 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1979 main(int argc, char *argv[])
1984 memset(&arg, 0, sizeof(arg));
1986 /* command line args */
1989 defconfig[CookiePolicies].val.v = EARGF(usage());
1990 defconfig[CookiePolicies].prio = 2;
1993 defconfig[ScrollBars].val.i = 0;
1994 defconfig[ScrollBars].prio = 2;
1997 defconfig[ScrollBars].val.i = 1;
1998 defconfig[ScrollBars].prio = 2;
2001 cookiefile = EARGF(usage());
2004 stylefile = EARGF(usage());
2007 defconfig[DiskCache].val.i = 0;
2008 defconfig[DiskCache].prio = 2;
2011 defconfig[DiskCache].val.i = 1;
2012 defconfig[DiskCache].prio = 2;
2015 embed = strtol(EARGF(usage()), NULL, 0);
2018 defconfig[RunInFullscreen].val.i = 0;
2019 defconfig[RunInFullscreen].prio = 2;
2022 defconfig[RunInFullscreen].val.i = 1;
2023 defconfig[RunInFullscreen].prio = 2;
2026 defconfig[Geolocation].val.i = 0;
2027 defconfig[Geolocation].prio = 2;
2030 defconfig[Geolocation].val.i = 1;
2031 defconfig[Geolocation].prio = 2;
2034 defconfig[LoadImages].val.i = 0;
2035 defconfig[LoadImages].prio = 2;
2038 defconfig[LoadImages].val.i = 1;
2039 defconfig[LoadImages].prio = 2;
2042 defconfig[KioskMode].val.i = 0;
2043 defconfig[KioskMode].prio = 2;
2046 defconfig[KioskMode].val.i = 1;
2047 defconfig[KioskMode].prio = 2;
2050 defconfig[Style].val.i = 0;
2051 defconfig[Style].prio = 2;
2054 defconfig[Style].val.i = 1;
2055 defconfig[Style].prio = 2;
2058 defconfig[Inspector].val.i = 0;
2059 defconfig[Inspector].prio = 2;
2062 defconfig[Inspector].val.i = 1;
2063 defconfig[Inspector].prio = 2;
2066 defconfig[Plugins].val.i = 0;
2067 defconfig[Plugins].prio = 2;
2070 defconfig[Plugins].val.i = 1;
2071 defconfig[Plugins].prio = 2;
2074 scriptfile = EARGF(usage());
2077 defconfig[JavaScript].val.i = 0;
2078 defconfig[JavaScript].prio = 2;
2081 defconfig[JavaScript].val.i = 1;
2082 defconfig[JavaScript].prio = 2;
2085 defconfig[StrictTLS].val.i = 0;
2086 defconfig[StrictTLS].prio = 2;
2089 defconfig[StrictTLS].val.i = 1;
2090 defconfig[StrictTLS].prio = 2;
2093 fulluseragent = EARGF(usage());
2096 die("surf-"VERSION", see LICENSE for © details\n");
2101 defconfig[Certificate].val.i = 0;
2102 defconfig[Certificate].prio = 2;
2105 defconfig[Certificate].val.i = 1;
2106 defconfig[Certificate].prio = 2;
2109 defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
2110 defconfig[ZoomLevel].prio = 2;
2118 arg.v = "about:blank";
2121 c = newclient(NULL);