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))
36 #define SETB(p, s) [p] = { { .b = s }, }
37 #define SETI(p, s) [p] = { { .i = s }, }
38 #define SETV(p, s) [p] = { { .v = s }, }
39 #define SETF(p, s) [p] = { { .f = s }, }
40 #define FSETB(p, s) [p] = { { .b = s }, 1 }
41 #define FSETI(p, s) [p] = { { .i = s }, 1 }
42 #define FSETV(p, s) [p] = { { .v = s }, 1 }
43 #define FSETF(p, s) [p] = { { .f = s }, 1 }
44 #define CSETB(p, s) [p] = (Parameter){ { .b = s }, 1 }
45 #define CSETI(p, s) [p] = (Parameter){ { .i = s }, 1 }
46 #define CSETV(p, s) [p] = (Parameter){ { .v = s }, 1 }
47 #define CSETF(p, s) [p] = (Parameter){ { .f = s }, 1 }
49 enum { AtomFind, AtomGo, AtomUri, AtomLast };
52 OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
53 OnLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
54 OnImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
55 OnMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
56 OnEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
57 OnBar = WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR,
58 OnSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
59 OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
110 typedef struct Client {
113 WebKitWebInspector *inspector;
114 WebKitFindController *finder;
115 WebKitHitTestResult *mousepos;
116 GTlsCertificate *cert, *failedcert;
117 GTlsCertificateFlags tlserr;
119 int progress, fullscreen, https, insecure, errorpage;
120 const char *title, *overtitle, *targeturi;
128 void (*func)(Client *c, const Arg *a);
136 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
138 unsigned int stopevent;
143 Parameter config[ParameterLast];
154 static void usage(void);
155 static void die(const char *errstr, ...);
156 static void setup(void);
157 static void sigchld(int unused);
158 static void sighup(int unused);
159 static char *buildfile(const char *path);
160 static char *buildpath(const char *path);
161 static const char *getuserhomedir(const char *user);
162 static const char *getcurrentuserhomedir(void);
163 static Client *newclient(Client *c);
164 static void loaduri(Client *c, const Arg *a);
165 static const char *geturi(Client *c);
166 static void setatom(Client *c, int a, const char *v);
167 static const char *getatom(Client *c, int a);
168 static void updatetitle(Client *c);
169 static void gettogglestats(Client *c);
170 static void getpagestats(Client *c);
171 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
172 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
173 static void seturiparameters(Client *c, const char *uri);
174 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
175 static const char *getcert(const char *uri);
176 static void setcert(Client *c, const char *file);
177 static const char *getstyle(const char *uri);
178 static void setstyle(Client *c, const char *file);
179 static void runscript(Client *c);
180 static void evalscript(Client *c, const char *jsstr, ...);
181 static void updatewinid(Client *c);
182 static void handleplumb(Client *c, const char *uri);
183 static void newwindow(Client *c, const Arg *a, int noembed);
184 static void spawn(Client *c, const Arg *a);
185 static void destroyclient(Client *c);
186 static void cleanup(void);
189 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
190 static void initwebextensions(WebKitWebContext *wc, Client *c);
191 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
193 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
194 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
196 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
197 static void showview(WebKitWebView *v, Client *c);
198 static GtkWidget *createwindow(Client *c);
199 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
200 GTlsCertificate *cert,
201 GTlsCertificateFlags err, Client *c);
202 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
203 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
204 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
205 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
206 guint modifiers, Client *c);
207 static gboolean permissionrequested(WebKitWebView *v,
208 WebKitPermissionRequest *r, Client *c);
209 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
210 WebKitPolicyDecisionType dt, Client *c);
211 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
212 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
213 static void decideresource(WebKitPolicyDecision *d, Client *c);
214 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
216 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
218 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
219 static void download(Client *c, WebKitURIResponse *r);
220 static void closeview(WebKitWebView *v, Client *c);
221 static void destroywin(GtkWidget* w, Client *c);
224 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
225 static void reload(Client *c, const Arg *a);
226 static void print(Client *c, const Arg *a);
227 static void showcert(Client *c, const Arg *a);
228 static void clipboard(Client *c, const Arg *a);
229 static void zoom(Client *c, const Arg *a);
230 static void scroll(Client *c, const Arg *a);
231 static void navigate(Client *c, const Arg *a);
232 static void stop(Client *c, const Arg *a);
233 static void toggle(Client *c, const Arg *a);
234 static void togglefullscreen(Client *c, const Arg *a);
235 static void togglecookiepolicy(Client *c, const Arg *a);
236 static void toggleinspector(Client *c, const Arg *a);
237 static void find(Client *c, const Arg *a);
240 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
241 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
242 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
244 static char winid[64];
245 static char togglestats[12];
246 static char pagestats[2];
247 static Atom atoms[AtomLast];
250 static int cookiepolicy;
252 static Client *clients;
253 static GdkDevice *gdkkb;
254 static char *stylefile;
255 static const char *useragent;
256 static Parameter *curconfig;
259 /* configuration, allows nested code to access above variables */
265 die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
266 "[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
267 "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
271 die(const char *errstr, ...)
275 va_start(ap, errstr);
276 vfprintf(stderr, errstr, ap);
287 /* clean up any zombies immediately */
289 if (signal(SIGHUP, sighup) == SIG_ERR)
290 die("Can't install SIGHUP handler");
292 if (!(dpy = XOpenDisplay(NULL)))
293 die("Can't open default display");
296 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
297 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
298 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
300 gtk_init(NULL, NULL);
302 gdpy = gdk_display_get_default();
304 curconfig = defconfig;
307 cookiefile = buildfile(cookiefile);
308 scriptfile = buildfile(scriptfile);
309 cachedir = buildpath(cachedir);
310 certdir = buildpath(certdir);
312 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
314 for (i = 0; i < LENGTH(certs); ++i) {
315 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
316 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
319 fprintf(stderr, "Could not compile regex: %s\n",
321 certs[i].regex = NULL;
326 styledir = buildpath(styledir);
327 for (i = 0; i < LENGTH(styles); ++i) {
328 if (!regcomp(&(styles[i].re), styles[i].regex,
330 styles[i].file = g_strconcat(styledir, "/",
331 styles[i].file, NULL);
333 fprintf(stderr, "Could not compile regex: %s\n",
335 styles[i].regex = NULL;
340 stylefile = buildfile(stylefile);
343 for (i = 0; i < LENGTH(uriparams); ++i) {
344 if (!regcomp(&(uriparams[i].re), uriparams[i].uri,
346 /* copy default parameters if they are not already set
347 * or if they are forced */
348 for (j = 0; j < ParameterLast; ++j) {
349 if (!uriparams[i].config[j].force ||
351 uriparams[i].config[j] = defconfig[j];
354 fprintf(stderr, "Could not compile regex: %s\n",
356 uriparams[i].uri = NULL;
364 if (signal(SIGCHLD, sigchld) == SIG_ERR)
365 die("Can't install SIGCHLD handler");
366 while (waitpid(-1, NULL, WNOHANG) > 0)
376 for (c = clients; c; c = c->next)
381 buildfile(const char *path)
383 char *dname, *bname, *bpath, *fpath;
386 dname = g_path_get_dirname(path);
387 bname = g_path_get_basename(path);
389 bpath = buildpath(dname);
392 fpath = g_build_filename(bpath, bname, NULL);
396 if (!(f = fopen(fpath, "a")))
397 die("Could not open file: %s\n", fpath);
399 g_chmod(fpath, 0600); /* always */
406 getuserhomedir(const char *user)
408 struct passwd *pw = getpwnam(user);
411 die("Can't get user %s login information.\n", user);
417 getcurrentuserhomedir(void)
423 homedir = getenv("HOME");
427 user = getenv("USER");
429 return getuserhomedir(user);
431 pw = getpwuid(getuid());
433 die("Can't get current user home directory\n");
439 buildpath(const char *path)
441 char *apath, *name, *p, *fpath;
444 if (path[0] == '~') {
445 if (path[1] == '/' || path[1] == '\0') {
446 p = (char *)&path[1];
447 homedir = getcurrentuserhomedir();
449 if ((p = strchr(path, '/')))
450 name = g_strndup(&path[1], --p - path);
452 name = g_strdup(&path[1]);
454 homedir = getuserhomedir(name);
457 apath = g_build_filename(homedir, p, NULL);
459 apath = g_strdup(path);
462 /* creating directory */
463 if (g_mkdir_with_parents(apath, 0700) < 0)
464 die("Could not access directory: %s\n", apath);
466 fpath = realpath(apath, NULL);
473 newclient(Client *rc)
477 if (!(c = calloc(1, sizeof(Client))))
478 die("Cannot malloc!\n");
484 c->view = newview(c, rc ? rc->view : NULL);
490 loaduri(Client *c, const Arg *a)
494 const char *uri = a->v;
496 if (g_strcmp0(uri, "") == 0)
499 if (g_str_has_prefix(uri, "http://") ||
500 g_str_has_prefix(uri, "https://") ||
501 g_str_has_prefix(uri, "file://") ||
502 g_str_has_prefix(uri, "about:")) {
504 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
505 url = g_strdup_printf("file://%s", path);
508 url = g_strdup_printf("http://%s", uri);
511 setatom(c, AtomUri, url);
513 if (strcmp(url, geturi(c)) == 0) {
516 webkit_web_view_load_uri(c->view, url);
528 if (!(uri = webkit_web_view_get_uri(c->view)))
534 setatom(Client *c, int a, const char *v)
536 XChangeProperty(dpy, c->xid,
537 atoms[a], XA_STRING, 8, PropModeReplace,
538 (unsigned char *)v, strlen(v) + 1);
543 getatom(Client *c, int a)
545 static char buf[BUFSIZ];
548 unsigned long ldummy;
549 unsigned char *p = NULL;
552 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
553 &adummy, &idummy, &ldummy, &ldummy, &p);
555 strncpy(buf, (char *)p, LENGTH(buf) - 1);
564 updatetitle(Client *c)
567 const char *name = c->overtitle ? c->overtitle :
568 c->title ? c->title : "";
570 if (curconfig[ShowIndicators].val.b) {
574 if (c->progress != 100)
575 title = g_strdup_printf("[%i%%] %s:%s | %s",
576 c->progress, togglestats, pagestats, name);
578 title = g_strdup_printf("%s:%s | %s",
579 togglestats, pagestats, name);
581 gtk_window_set_title(GTK_WINDOW(c->win), title);
584 gtk_window_set_title(GTK_WINDOW(c->win), name);
589 gettogglestats(Client *c)
591 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
592 togglestats[1] = curconfig[CaretBrowsing].val.b ? 'C' : 'c';
593 togglestats[2] = curconfig[Geolocation].val.b ? 'G' : 'g';
594 togglestats[3] = curconfig[DiskCache].val.b ? 'D' : 'd';
595 togglestats[4] = curconfig[LoadImages].val.b ? 'I' : 'i';
596 togglestats[5] = curconfig[JavaScript].val.b ? 'S' : 's';
597 togglestats[6] = curconfig[Plugins].val.b ? 'V' : 'v';
598 togglestats[7] = curconfig[Style].val.b ? 'M' : 'm';
599 togglestats[8] = curconfig[FrameFlattening].val.b ? 'F' : 'f';
600 togglestats[9] = curconfig[Certificate].val.b ? 'X' : 'x';
601 togglestats[10] = curconfig[StrictTLS].val.b ? 'T' : 't';
602 togglestats[11] = '\0';
606 getpagestats(Client *c)
609 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
615 WebKitCookieAcceptPolicy
616 cookiepolicy_get(void)
618 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
620 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
622 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
623 default: /* fallthrough */
625 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
630 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
633 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
635 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
637 default: /* fallthrough */
638 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
644 seturiparameters(Client *c, const char *uri)
646 Parameter *config, *newconfig = NULL;
649 for (i = 0; i < LENGTH(uriparams); ++i) {
650 if (uriparams[i].uri &&
651 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
652 newconfig = uriparams[i].config;
658 newconfig = defconfig;
660 for (i = 0; i < ParameterLast; ++i) {
665 config = defconfig[i].force ? defconfig :
666 newconfig[i].force ? newconfig :
670 if (newconfig == curconfig || defconfig[i].force)
672 config = newconfig[i].force ? newconfig :
673 curconfig[i].force ? defconfig :
678 setparameter(c, 0, i, &config[i].val);
681 curconfig = newconfig;
685 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
687 GdkRGBA bgcolor = { 0 };
688 WebKitSettings *s = webkit_web_view_get_settings(c->view);
691 case AcceleratedCanvas:
692 webkit_settings_set_enable_accelerated_2d_canvas(s, a->b);
694 case AccessMicrophone:
695 return; /* do nothing */
697 return; /* do nothing */
699 webkit_settings_set_enable_caret_browsing(s, a->b);
704 setcert(c, geturi(c));
705 return; /* do not update */
707 webkit_cookie_manager_set_accept_policy(
708 webkit_web_context_get_cookie_manager(
709 webkit_web_view_get_context(c->view)),
714 webkit_web_context_set_cache_model(
715 webkit_web_view_get_context(c->view), a->b ?
716 WEBKIT_CACHE_MODEL_WEB_BROWSER :
717 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
718 return; /* do not update */
720 webkit_settings_set_default_charset(s, a->v);
721 return; /* do not update */
723 webkit_settings_set_enable_dns_prefetching(s, a->b);
724 return; /* do not update */
725 case FileURLsCrossAccess:
726 webkit_settings_set_allow_file_access_from_file_urls(s, a->b);
727 webkit_settings_set_allow_universal_access_from_file_urls(s, a->b);
728 return; /* do not update */
730 webkit_settings_set_default_font_size(s, a->i);
731 return; /* do not update */
732 case FrameFlattening:
733 webkit_settings_set_enable_frame_flattening(s, a->b);
740 webkit_web_view_set_background_color(c->view, &bgcolor);
741 return; /* do not update */
743 webkit_settings_set_enable_developer_extras(s, a->b);
744 return; /* do not update */
746 webkit_settings_set_enable_java(s, a->b);
747 return; /* do not update */
749 webkit_settings_set_enable_javascript(s, a->b);
752 return; /* do nothing */
754 webkit_settings_set_auto_load_images(s, a->b);
756 case MediaManualPlay:
757 webkit_settings_set_media_playback_requires_user_gesture(s, a->b);
760 webkit_settings_set_enable_plugins(s, a->b);
762 case PreferredLanguages:
763 return; /* do nothing */
764 case RunInFullscreen:
765 return; /* do nothing */
767 /* Disabled until we write some WebKitWebExtension for
768 * manipulating the DOM directly.
769 enablescrollbars = !enablescrollbars;
770 evalscript(c, "document.documentElement.style.overflow = '%s'",
771 enablescrollbars ? "auto" : "hidden");
773 return; /* do not update */
776 case SmoothScrolling:
777 webkit_settings_set_enable_smooth_scrolling(s, a->b);
778 return; /* do not update */
780 webkit_settings_set_enable_site_specific_quirks(s, a->b);
783 webkit_web_context_set_spell_checking_enabled(
784 webkit_web_view_get_context(c->view), a->b);
785 return; /* do not update */
787 return; /* do nothing */
789 webkit_web_context_set_tls_errors_policy(
790 webkit_web_view_get_context(c->view), a->b ?
791 WEBKIT_TLS_ERRORS_POLICY_FAIL :
792 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
795 webkit_user_content_manager_remove_all_style_sheets(
796 webkit_web_view_get_user_content_manager(c->view));
798 setstyle(c, getstyle(geturi(c)));
802 webkit_web_view_set_zoom_level(c->view, a->f);
803 return; /* do not update */
805 return; /* do nothing */
814 getcert(const char *uri)
818 for (i = 0; i < LENGTH(certs); ++i) {
819 if (certs[i].regex &&
820 !regexec(&(certs[i].re), uri, 0, NULL, 0))
821 return certs[i].file;
828 setcert(Client *c, const char *uri)
830 const char *file = getcert(uri);
832 GTlsCertificate *cert;
837 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
838 fprintf(stderr, "Could not read certificate file: %s\n", file);
842 if ((uri = strstr(uri, "https://"))) {
843 uri += sizeof("https://") - 1;
844 host = g_strndup(uri, strchr(uri, '/') - uri);
845 webkit_web_context_allow_tls_certificate_for_host(
846 webkit_web_view_get_context(c->view), cert, host);
850 g_object_unref(cert);
855 getstyle(const char *uri)
862 for (i = 0; i < LENGTH(styles); ++i) {
863 if (styles[i].regex &&
864 !regexec(&(styles[i].re), uri, 0, NULL, 0))
865 return styles[i].file;
872 setstyle(Client *c, const char *file)
876 if (!g_file_get_contents(file, &style, NULL, NULL)) {
877 fprintf(stderr, "Could not read style file: %s\n", file);
881 webkit_user_content_manager_add_style_sheet(
882 webkit_web_view_get_user_content_manager(c->view),
883 webkit_user_style_sheet_new(style,
884 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
885 WEBKIT_USER_STYLE_LEVEL_USER,
897 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
898 evalscript(c, script);
903 evalscript(Client *c, const char *jsstr, ...)
909 script = g_strdup_vprintf(jsstr, ap);
912 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
917 updatewinid(Client *c)
919 snprintf(winid, LENGTH(winid), "%lu", c->xid);
923 handleplumb(Client *c, const char *uri)
925 Arg a = (Arg)PLUMB(uri);
930 newwindow(Client *c, const Arg *a, int noembed)
934 const char *cmd[29], *uri;
935 const Arg arg = { .v = cmd };
939 cmd[i++] = curconfig[CookiePolicies].val.v;
940 cmd[i++] = curconfig[ScrollBars].val.b ? "-B" : "-b";
941 if (cookiefile && g_strcmp0(cookiefile, "")) {
943 cmd[i++] = cookiefile;
945 if (stylefile && g_strcmp0(stylefile, "")) {
947 cmd[i++] = stylefile;
949 cmd[i++] = curconfig[DiskCache].val.b ? "-D" : "-d";
950 if (embed && !noembed) {
952 snprintf(tmp, LENGTH(tmp), "%lu", embed);
955 cmd[i++] = curconfig[RunInFullscreen].val.b ? "-F" : "-f" ;
956 cmd[i++] = curconfig[Geolocation].val.b ? "-G" : "-g" ;
957 cmd[i++] = curconfig[LoadImages].val.b ? "-I" : "-i" ;
958 cmd[i++] = curconfig[KioskMode].val.b ? "-K" : "-k" ;
959 cmd[i++] = curconfig[Style].val.b ? "-M" : "-m" ;
960 cmd[i++] = curconfig[Inspector].val.b ? "-N" : "-n" ;
961 cmd[i++] = curconfig[Plugins].val.b ? "-P" : "-p" ;
962 if (scriptfile && g_strcmp0(scriptfile, "")) {
964 cmd[i++] = scriptfile;
966 cmd[i++] = curconfig[JavaScript].val.b ? "-S" : "-s";
967 cmd[i++] = curconfig[StrictTLS].val.b ? "-T" : "-t";
968 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
970 cmd[i++] = fulluseragent;
974 cmd[i++] = curconfig[Certificate].val.b ? "-X" : "-x" ;
975 /* do not keep zoom level */
985 spawn(Client *c, const Arg *a)
989 close(ConnectionNumber(dpy));
991 execvp(((char **)a->v)[0], (char **)a->v);
992 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
999 destroyclient(Client *c)
1003 webkit_web_view_stop_loading(c->view);
1004 /* Not needed, has already been called
1005 gtk_widget_destroy(c->win);
1008 for (p = clients; p && p->next != c; p = p->next)
1021 destroyclient(clients);
1030 newview(Client *c, WebKitWebView *rv)
1033 WebKitSettings *settings;
1034 WebKitUserContentManager *contentmanager;
1035 WebKitWebContext *context;
1039 v = WEBKIT_WEB_VIEW(
1040 webkit_web_view_new_with_related_view(rv));
1042 settings = webkit_settings_new_with_settings(
1043 "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.b,
1044 "allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.b,
1045 "auto-load-images", curconfig[LoadImages].val.b,
1046 "default-charset", curconfig[DefaultCharset].val.v,
1047 "default-font-size", curconfig[FontSize].val.i,
1048 "enable-caret-browsing", curconfig[CaretBrowsing].val.b,
1049 "enable-developer-extras", curconfig[Inspector].val.b,
1050 "enable-dns-prefetching", curconfig[DNSPrefetch].val.b,
1051 "enable-frame-flattening", curconfig[FrameFlattening].val.b,
1052 "enable-html5-database", curconfig[DiskCache].val.b,
1053 "enable-html5-local-storage", curconfig[DiskCache].val.b,
1054 "enable-java", curconfig[Java].val.b,
1055 "enable-javascript", curconfig[JavaScript].val.b,
1056 "enable-plugins", curconfig[Plugins].val.b,
1057 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.b,
1058 "enable-site-specific-quirks", curconfig[SiteQuirks].val.b,
1059 "enable-smooth-scrolling", curconfig[SmoothScrolling].val.b,
1060 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.b,
1062 /* For more interesting settings, have a look at
1063 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1065 if (strcmp(fulluseragent, "")) {
1066 webkit_settings_set_user_agent(settings, fulluseragent);
1067 } else if (surfuseragent) {
1068 webkit_settings_set_user_agent_with_application_details(
1069 settings, "Surf", VERSION);
1071 useragent = webkit_settings_get_user_agent(settings);
1073 contentmanager = webkit_user_content_manager_new();
1075 context = webkit_web_context_new_with_website_data_manager(
1076 webkit_website_data_manager_new(
1077 "base-cache-directory", cachedir,
1078 "base-data-directory", cachedir,
1081 /* rendering process model, can be a shared unique one
1082 * or one for each view */
1083 webkit_web_context_set_process_model(context,
1084 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1086 webkit_web_context_set_tls_errors_policy(context,
1087 curconfig[StrictTLS].val.b ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1088 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1090 webkit_web_context_set_cache_model(context,
1091 curconfig[DiskCache].val.b ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1092 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1094 /* Currently only works with text file to be compatible with curl */
1095 webkit_cookie_manager_set_persistent_storage(
1096 webkit_web_context_get_cookie_manager(context), cookiefile,
1097 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1099 webkit_cookie_manager_set_accept_policy(
1100 webkit_web_context_get_cookie_manager(context),
1101 cookiepolicy_get());
1103 webkit_web_context_set_preferred_languages(context,
1104 curconfig[PreferredLanguages].val.v);
1105 webkit_web_context_set_spell_checking_languages(context,
1106 curconfig[SpellLanguages].val.v);
1107 webkit_web_context_set_spell_checking_enabled(context,
1108 curconfig[SpellChecking].val.b);
1110 g_signal_connect(G_OBJECT(context), "download-started",
1111 G_CALLBACK(downloadstarted), c);
1112 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1113 G_CALLBACK(initwebextensions), c);
1115 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1116 "settings", settings,
1117 "user-content-manager", contentmanager,
1118 "web-context", context,
1122 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1123 G_CALLBACK(progresschanged), c);
1124 g_signal_connect(G_OBJECT(v), "notify::title",
1125 G_CALLBACK(titlechanged), c);
1126 g_signal_connect(G_OBJECT(v), "button-release-event",
1127 G_CALLBACK(buttonreleased), c);
1128 g_signal_connect(G_OBJECT(v), "close",
1129 G_CALLBACK(closeview), c);
1130 g_signal_connect(G_OBJECT(v), "create",
1131 G_CALLBACK(createview), c);
1132 g_signal_connect(G_OBJECT(v), "decide-policy",
1133 G_CALLBACK(decidepolicy), c);
1134 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1135 G_CALLBACK(insecurecontent), c);
1136 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1137 G_CALLBACK(loadfailedtls), c);
1138 g_signal_connect(G_OBJECT(v), "load-changed",
1139 G_CALLBACK(loadchanged), c);
1140 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1141 G_CALLBACK(mousetargetchanged), c);
1142 g_signal_connect(G_OBJECT(v), "permission-request",
1143 G_CALLBACK(permissionrequested), c);
1144 g_signal_connect(G_OBJECT(v), "ready-to-show",
1145 G_CALLBACK(showview), c);
1151 initwebextensions(WebKitWebContext *wc, Client *c)
1153 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1157 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1161 switch (webkit_navigation_action_get_navigation_type(a)) {
1162 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1164 * popup windows of type “other” are almost always triggered
1165 * by user gesture, so inverse the logic here
1167 /* instead of this, compare destination uri to mouse-over uri for validating window */
1168 if (webkit_navigation_action_is_user_gesture(a))
1170 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1171 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1172 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1173 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1174 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1181 return GTK_WIDGET(n->view);
1185 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1187 WebKitHitTestResultContext element;
1190 element = webkit_hit_test_result_get_context(c->mousepos);
1192 for (i = 0; i < LENGTH(buttons); ++i) {
1193 if (element & buttons[i].target &&
1194 e->button.button == buttons[i].button &&
1195 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1197 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1198 return buttons[i].stopevent;
1206 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1208 Client *c = (Client *)d;
1212 if (((XEvent *)e)->type == PropertyNotify) {
1213 ev = &((XEvent *)e)->xproperty;
1214 if (ev->state == PropertyNewValue) {
1215 if (ev->atom == atoms[AtomFind]) {
1218 return GDK_FILTER_REMOVE;
1219 } else if (ev->atom == atoms[AtomGo]) {
1220 a.v = getatom(c, AtomGo);
1223 return GDK_FILTER_REMOVE;
1227 return GDK_FILTER_CONTINUE;
1231 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1236 case GDK_ENTER_NOTIFY:
1237 c->overtitle = c->targeturi;
1241 if (!curconfig[KioskMode].val.b) {
1242 for (i = 0; i < LENGTH(keys); ++i) {
1243 if (gdk_keyval_to_lower(e->key.keyval) ==
1245 CLEANMASK(e->key.state) == keys[i].mod &&
1248 keys[i].func(c, &(keys[i].arg));
1253 case GDK_LEAVE_NOTIFY:
1254 c->overtitle = NULL;
1257 case GDK_WINDOW_STATE:
1258 if (e->window_state.changed_mask ==
1259 GDK_WINDOW_STATE_FULLSCREEN)
1260 c->fullscreen = e->window_state.new_window_state &
1261 GDK_WINDOW_STATE_FULLSCREEN;
1271 showview(WebKitWebView *v, Client *c)
1273 GdkRGBA bgcolor = { 0 };
1276 c->finder = webkit_web_view_get_find_controller(c->view);
1277 c->inspector = webkit_web_view_get_inspector(c->view);
1279 c->win = createwindow(c);
1281 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1282 gtk_widget_show_all(c->win);
1283 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1285 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1286 c->xid = gdk_x11_window_get_xid(gwin);
1289 gdk_display_sync(gtk_widget_get_display(c->win));
1293 if (curconfig[HideBackground].val.b)
1294 webkit_web_view_set_background_color(c->view, &bgcolor);
1296 if (!curconfig[KioskMode].val.b) {
1297 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1298 gdk_window_add_filter(gwin, processx, c);
1301 if (curconfig[RunInFullscreen].val.b)
1302 togglefullscreen(c, NULL);
1304 if (curconfig[ZoomLevel].val.f != 1.0)
1305 webkit_web_view_set_zoom_level(c->view,
1306 curconfig[ZoomLevel].val.f);
1308 setatom(c, AtomFind, "");
1309 setatom(c, AtomUri, "about:blank");
1313 createwindow(Client *c)
1319 w = gtk_plug_new(embed);
1321 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1323 wmstr = g_path_get_basename(argv0);
1324 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1327 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1328 webkit_web_view_get_page_id(c->view));
1329 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1332 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1335 g_signal_connect(G_OBJECT(w), "destroy",
1336 G_CALLBACK(destroywin), c);
1337 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1338 G_CALLBACK(winevent), c);
1339 g_signal_connect(G_OBJECT(w), "key-press-event",
1340 G_CALLBACK(winevent), c);
1341 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1342 G_CALLBACK(winevent), c);
1343 g_signal_connect(G_OBJECT(w), "window-state-event",
1344 G_CALLBACK(winevent), c);
1350 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1351 GTlsCertificateFlags err, Client *c)
1353 GString *errmsg = g_string_new(NULL);
1356 c->failedcert = g_object_ref(cert);
1360 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1361 g_string_append(errmsg,
1362 "The signing certificate authority is not known.<br>");
1363 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1364 g_string_append(errmsg,
1365 "The certificate does not match the expected identity "
1366 "of the site that it was retrieved from.<br>");
1367 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1368 g_string_append(errmsg,
1369 "The certificate's activation time "
1370 "is still in the future.<br>");
1371 if (err & G_TLS_CERTIFICATE_EXPIRED)
1372 g_string_append(errmsg, "The certificate has expired.<br>");
1373 if (err & G_TLS_CERTIFICATE_REVOKED)
1374 g_string_append(errmsg,
1375 "The certificate has been revoked according to "
1376 "the GTlsConnection's certificate revocation list.<br>");
1377 if (err & G_TLS_CERTIFICATE_INSECURE)
1378 g_string_append(errmsg,
1379 "The certificate's algorithm is considered insecure.<br>");
1380 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1381 g_string_append(errmsg,
1382 "Some error occurred validating the certificate.<br>");
1384 g_object_get(cert, "certificate-pem", &pem, NULL);
1385 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1386 "<p>You can inspect the following certificate "
1387 "with Ctrl-t (default keybinding).</p>"
1388 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1390 g_string_free(errmsg, TRUE);
1392 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1399 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1401 const char *uri = geturi(c);
1404 case WEBKIT_LOAD_STARTED:
1405 setatom(c, AtomUri, uri);
1407 c->https = c->insecure = 0;
1408 seturiparameters(c, uri);
1412 g_clear_object(&c->failedcert);
1414 case WEBKIT_LOAD_REDIRECTED:
1415 setatom(c, AtomUri, uri);
1417 seturiparameters(c, uri);
1419 case WEBKIT_LOAD_COMMITTED:
1420 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1423 case WEBKIT_LOAD_FINISHED:
1424 /* Disabled until we write some WebKitWebExtension for
1425 * manipulating the DOM directly.
1426 evalscript(c, "document.documentElement.style.overflow = '%s'",
1427 enablescrollbars ? "auto" : "hidden");
1436 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1438 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1444 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1446 c->title = webkit_web_view_get_title(c->view);
1451 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1454 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1456 /* Keep the hit test to know where is the pointer on the next click */
1460 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1461 else if (hc & OnImg)
1462 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1463 else if (hc & OnMedia)
1464 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1466 c->targeturi = NULL;
1468 c->overtitle = c->targeturi;
1473 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1475 ParamName param = ParameterLast;
1477 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1478 param = Geolocation;
1479 } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
1480 if (webkit_user_media_permission_is_for_audio_device(
1481 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1482 param = AccessMicrophone;
1483 else if (webkit_user_media_permission_is_for_video_device(
1484 WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
1485 param = AccessWebcam;
1490 if (curconfig[param].val.b)
1491 webkit_permission_request_allow(r);
1493 webkit_permission_request_deny(r);
1499 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1500 WebKitPolicyDecisionType dt, Client *c)
1503 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1504 decidenavigation(d, c);
1506 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1507 decidenewwindow(d, c);
1509 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1510 decideresource(d, c);
1513 webkit_policy_decision_ignore(d);
1520 decidenavigation(WebKitPolicyDecision *d, Client *c)
1522 WebKitNavigationAction *a =
1523 webkit_navigation_policy_decision_get_navigation_action(
1524 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1526 switch (webkit_navigation_action_get_navigation_type(a)) {
1527 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1528 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1529 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1530 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1531 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1532 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1534 /* Do not navigate to links with a "_blank" target (popup) */
1535 if (webkit_navigation_policy_decision_get_frame_name(
1536 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1537 webkit_policy_decision_ignore(d);
1539 /* Filter out navigation to different domain ? */
1540 /* get action→urirequest, copy and load in new window+view
1541 * on Ctrl+Click ? */
1542 webkit_policy_decision_use(d);
1549 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1552 WebKitNavigationAction *a =
1553 webkit_navigation_policy_decision_get_navigation_action(
1554 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1557 switch (webkit_navigation_action_get_navigation_type(a)) {
1558 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1559 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1560 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1561 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1562 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1563 /* Filter domains here */
1564 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1565 * test for link clicked but no button ? */
1566 arg.v = webkit_uri_request_get_uri(
1567 webkit_navigation_action_get_request(a));
1568 newwindow(c, &arg, 0);
1570 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1575 webkit_policy_decision_ignore(d);
1579 decideresource(WebKitPolicyDecision *d, Client *c)
1582 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1583 WebKitURIResponse *res =
1584 webkit_response_policy_decision_get_response(r);
1585 const gchar *uri = webkit_uri_response_get_uri(res);
1587 if (g_str_has_suffix(uri, "/favicon.ico")) {
1588 webkit_policy_decision_ignore(d);
1592 if (!g_str_has_prefix(uri, "http://")
1593 && !g_str_has_prefix(uri, "https://")
1594 && !g_str_has_prefix(uri, "about:")
1595 && !g_str_has_prefix(uri, "file://")
1596 && !g_str_has_prefix(uri, "data:")
1597 && !g_str_has_prefix(uri, "blob:")
1598 && strlen(uri) > 0) {
1599 for (i = 0; i < strlen(uri); i++) {
1600 if (!g_ascii_isprint(uri[i])) {
1606 handleplumb(c, uri);
1607 webkit_policy_decision_ignore(d);
1612 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1613 webkit_policy_decision_use(d);
1615 webkit_policy_decision_ignore(d);
1621 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1627 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1629 g_signal_connect(G_OBJECT(d), "notify::response",
1630 G_CALLBACK(responsereceived), c);
1634 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1636 download(c, webkit_download_get_response(d));
1637 webkit_download_cancel(d);
1641 download(Client *c, WebKitURIResponse *r)
1643 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1648 closeview(WebKitWebView *v, Client *c)
1650 gtk_widget_destroy(c->win);
1654 destroywin(GtkWidget* w, Client *c)
1662 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1664 Arg a = {.v = text };
1666 loaduri((Client *) d, &a);
1670 reload(Client *c, const Arg *a)
1673 webkit_web_view_reload_bypass_cache(c->view);
1675 webkit_web_view_reload(c->view);
1679 print(Client *c, const Arg *a)
1681 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1682 GTK_WINDOW(c->win));
1686 showcert(Client *c, const Arg *a)
1688 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1689 GcrCertificate *gcrt;
1692 GcrCertificateWidget *wcert;
1697 g_object_get(cert, "certificate", &crt, NULL);
1698 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1699 g_byte_array_unref(crt);
1701 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1702 wcert = gcr_certificate_widget_new(gcrt);
1703 g_object_unref(gcrt);
1705 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1706 gtk_widget_show_all(win);
1710 clipboard(Client *c, const Arg *a)
1712 if (a->b) { /* load clipboard uri */
1713 gtk_clipboard_request_text(gtk_clipboard_get(
1714 GDK_SELECTION_PRIMARY),
1716 } else { /* copy uri */
1717 gtk_clipboard_set_text(gtk_clipboard_get(
1718 GDK_SELECTION_PRIMARY), c->targeturi
1719 ? c->targeturi : geturi(c), -1);
1724 zoom(Client *c, const Arg *a)
1727 webkit_web_view_set_zoom_level(c->view,
1728 curconfig[ZoomLevel].val.f + 0.1);
1730 webkit_web_view_set_zoom_level(c->view,
1731 curconfig[ZoomLevel].val.f - 0.1);
1733 webkit_web_view_set_zoom_level(c->view, 1.0);
1735 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1739 scroll(Client *c, const Arg *a)
1741 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1743 gdk_event_set_device(ev, gdkkb);
1744 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1745 ev->key.state = GDK_CONTROL_MASK;
1746 ev->key.time = GDK_CURRENT_TIME;
1750 ev->key.keyval = GDK_KEY_Down;
1753 ev->key.keyval = GDK_KEY_Page_Down;
1756 ev->key.keyval = GDK_KEY_Left;
1759 ev->key.keyval = GDK_KEY_Right;
1762 ev->key.keyval = GDK_KEY_Page_Up;
1765 ev->key.keyval = GDK_KEY_Up;
1773 navigate(Client *c, const Arg *a)
1776 webkit_web_view_go_back(c->view);
1778 webkit_web_view_go_forward(c->view);
1782 stop(Client *c, const Arg *a)
1784 webkit_web_view_stop_loading(c->view);
1788 toggle(Client *c, const Arg *a)
1790 curconfig[a->i].val.b ^= 1;
1791 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1795 togglefullscreen(Client *c, const Arg *a)
1797 /* toggling value is handled in winevent() */
1799 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1801 gtk_window_fullscreen(GTK_WINDOW(c->win));
1805 togglecookiepolicy(Client *c, const Arg *a)
1808 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1810 setparameter(c, 0, CookiePolicies, NULL);
1814 toggleinspector(Client *c, const Arg *a)
1816 if (webkit_web_inspector_is_attached(c->inspector))
1817 webkit_web_inspector_close(c->inspector);
1818 else if (curconfig[Inspector].val.b)
1819 webkit_web_inspector_show(c->inspector);
1823 find(Client *c, const Arg *a)
1829 webkit_find_controller_search_next(c->finder);
1831 webkit_find_controller_search_previous(c->finder);
1833 s = getatom(c, AtomFind);
1834 f = webkit_find_controller_get_search_text(c->finder);
1836 if (g_strcmp0(f, s) == 0) /* reset search */
1837 webkit_find_controller_search(c->finder, "", findopts,
1840 webkit_find_controller_search(c->finder, s, findopts,
1843 if (strcmp(s, "") == 0)
1844 webkit_find_controller_search_finish(c->finder);
1849 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1855 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1859 arg.v = webkit_hit_test_result_get_link_uri(h);
1860 newwindow(c, &arg, a->b);
1864 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1868 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1873 main(int argc, char *argv[])
1878 memset(&arg, 0, sizeof(arg));
1880 /* command line args */
1883 defconfig CSETV(CookiePolicies, EARGF(usage()));
1886 defconfig CSETB(ScrollBars, 0);
1889 defconfig CSETB(ScrollBars, 1);
1892 cookiefile = EARGF(usage());
1895 stylefile = EARGF(usage());
1898 defconfig CSETB(DiskCache, 0);
1901 defconfig CSETB(DiskCache, 1);
1904 embed = strtol(EARGF(usage()), NULL, 0);
1907 defconfig CSETB(RunInFullscreen, 0);
1910 defconfig CSETB(RunInFullscreen, 1);
1913 defconfig CSETB(Geolocation, 0);
1916 defconfig CSETB(Geolocation, 1);
1919 defconfig CSETB(LoadImages, 0);
1922 defconfig CSETB(LoadImages, 1);
1925 defconfig CSETB(KioskMode, 0);
1928 defconfig CSETB(KioskMode, 1);
1931 defconfig CSETB(Style, 0);
1934 defconfig CSETB(Style, 1);
1937 defconfig CSETB(Inspector, 0);
1940 defconfig CSETB(Inspector, 1);
1943 defconfig CSETB(Plugins, 0);
1946 defconfig CSETB(Plugins, 1);
1949 scriptfile = EARGF(usage());
1952 defconfig CSETB(JavaScript, 0);
1955 defconfig CSETB(JavaScript, 1);
1958 defconfig CSETB(StrictTLS, 0);
1961 defconfig CSETB(StrictTLS, 1);
1964 fulluseragent = EARGF(usage());
1967 die("surf-"VERSION", see LICENSE for © details\n");
1972 defconfig CSETB(Certificate, 0);
1975 defconfig CSETB(Certificate, 1);
1978 defconfig CSETF(ZoomLevel, strtof(EARGF(usage()), NULL));
1986 arg.v = "about:blank";
1989 c = newclient(NULL);