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,
104 typedef struct Client {
107 WebKitWebInspector *inspector;
108 WebKitFindController *finder;
109 WebKitHitTestResult *mousepos;
110 GTlsCertificate *cert, *failedcert;
111 GTlsCertificateFlags tlserr;
113 int progress, fullscreen, https, insecure, errorpage;
114 const char *title, *overtitle, *targeturi;
122 void (*func)(Client *c, const Arg *a);
130 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
132 unsigned int stopevent;
137 Parameter config[ParameterLast];
148 static void usage(void);
149 static void die(const char *errstr, ...);
150 static void setup(void);
151 static void sigchld(int unused);
152 static void sighup(int unused);
153 static char *buildfile(const char *path);
154 static char *buildpath(const char *path);
155 static const char *getuserhomedir(const char *user);
156 static const char *getcurrentuserhomedir(void);
157 static Client *newclient(Client *c);
158 static void loaduri(Client *c, const Arg *a);
159 static const char *geturi(Client *c);
160 static void setatom(Client *c, int a, const char *v);
161 static const char *getatom(Client *c, int a);
162 static void updatetitle(Client *c);
163 static void gettogglestats(Client *c);
164 static void getpagestats(Client *c);
165 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
166 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
167 static void seturiparameters(Client *c, const char *uri);
168 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
169 static const char *getcert(const char *uri);
170 static void setcert(Client *c, const char *file);
171 static const char *getstyle(const char *uri);
172 static void setstyle(Client *c, const char *file);
173 static void runscript(Client *c);
174 static void evalscript(Client *c, const char *jsstr, ...);
175 static void updatewinid(Client *c);
176 static void handleplumb(Client *c, const char *uri);
177 static void newwindow(Client *c, const Arg *a, int noembed);
178 static void spawn(Client *c, const Arg *a);
179 static void destroyclient(Client *c);
180 static void cleanup(void);
183 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
184 static void initwebextensions(WebKitWebContext *wc, Client *c);
185 static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
187 static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
188 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
190 static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
191 static void showview(WebKitWebView *v, Client *c);
192 static GtkWidget *createwindow(Client *c);
193 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
194 GTlsCertificate *cert,
195 GTlsCertificateFlags err, Client *c);
196 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
197 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
198 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
199 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
200 guint modifiers, Client *c);
201 static gboolean permissionrequested(WebKitWebView *v,
202 WebKitPermissionRequest *r, Client *c);
203 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
204 WebKitPolicyDecisionType dt, Client *c);
205 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
206 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
207 static void decideresource(WebKitPolicyDecision *d, Client *c);
208 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
210 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
212 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
213 static void download(Client *c, WebKitURIResponse *r);
214 static void closeview(WebKitWebView *v, Client *c);
215 static void destroywin(GtkWidget* w, Client *c);
218 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
219 static void reload(Client *c, const Arg *a);
220 static void print(Client *c, const Arg *a);
221 static void showcert(Client *c, const Arg *a);
222 static void clipboard(Client *c, const Arg *a);
223 static void zoom(Client *c, const Arg *a);
224 static void scroll(Client *c, const Arg *a);
225 static void navigate(Client *c, const Arg *a);
226 static void stop(Client *c, const Arg *a);
227 static void toggle(Client *c, const Arg *a);
228 static void togglefullscreen(Client *c, const Arg *a);
229 static void togglecookiepolicy(Client *c, const Arg *a);
230 static void toggleinspector(Client *c, const Arg *a);
231 static void find(Client *c, const Arg *a);
234 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
235 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
236 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
238 static char winid[64];
239 static char togglestats[12];
240 static char pagestats[2];
241 static Atom atoms[AtomLast];
244 static int cookiepolicy;
246 static Client *clients;
247 static GdkDevice *gdkkb;
248 static char *stylefile;
249 static const char *useragent;
250 static Parameter *curconfig;
253 /* configuration, allows nested code to access above variables */
259 die("usage: %s [-bBdDfFgGiIkKmMnNpPsStTvx] [-a cookiepolicies ] "
260 "[-c cookiefile] [-C stylefile] [-e xid] [-r scriptfile] "
261 "[-u useragent] [-z zoomlevel] [uri]\n", basename(argv0));
265 die(const char *errstr, ...)
269 va_start(ap, errstr);
270 vfprintf(stderr, errstr, ap);
281 /* clean up any zombies immediately */
283 if (signal(SIGHUP, sighup) == SIG_ERR)
284 die("Can't install SIGHUP handler");
286 if (!(dpy = XOpenDisplay(NULL)))
287 die("Can't open default display");
290 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
291 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
292 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
294 gtk_init(NULL, NULL);
296 gdpy = gdk_display_get_default();
298 curconfig = defconfig;
301 cookiefile = buildfile(cookiefile);
302 scriptfile = buildfile(scriptfile);
303 cachedir = buildpath(cachedir);
304 certdir = buildpath(certdir);
306 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
308 for (i = 0; i < LENGTH(certs); ++i) {
309 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
310 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
313 fprintf(stderr, "Could not compile regex: %s\n",
315 certs[i].regex = NULL;
320 styledir = buildpath(styledir);
321 for (i = 0; i < LENGTH(styles); ++i) {
322 if (!regcomp(&(styles[i].re), styles[i].regex,
324 styles[i].file = g_strconcat(styledir, "/",
325 styles[i].file, NULL);
327 fprintf(stderr, "Could not compile regex: %s\n",
329 styles[i].regex = NULL;
334 stylefile = buildfile(stylefile);
337 for (i = 0; i < LENGTH(uriparams); ++i) {
338 if (!regcomp(&(uriparams[i].re), uriparams[i].uri,
340 /* copy default parameters if they are not already set
341 * or if they are forced */
342 for (j = 0; j < ParameterLast; ++j) {
343 if (!uriparams[i].config[j].force ||
345 uriparams[i].config[j] = defconfig[j];
348 fprintf(stderr, "Could not compile regex: %s\n",
350 uriparams[i].uri = NULL;
358 if (signal(SIGCHLD, sigchld) == SIG_ERR)
359 die("Can't install SIGCHLD handler");
360 while (waitpid(-1, NULL, WNOHANG) > 0)
370 for (c = clients; c; c = c->next)
375 buildfile(const char *path)
377 char *dname, *bname, *bpath, *fpath;
380 dname = g_path_get_dirname(path);
381 bname = g_path_get_basename(path);
383 bpath = buildpath(dname);
386 fpath = g_build_filename(bpath, bname, NULL);
390 if (!(f = fopen(fpath, "a")))
391 die("Could not open file: %s\n", fpath);
393 g_chmod(fpath, 0600); /* always */
400 getuserhomedir(const char *user)
402 struct passwd *pw = getpwnam(user);
405 die("Can't get user %s login information.\n", user);
411 getcurrentuserhomedir(void)
417 homedir = getenv("HOME");
421 user = getenv("USER");
423 return getuserhomedir(user);
425 pw = getpwuid(getuid());
427 die("Can't get current user home directory\n");
433 buildpath(const char *path)
435 char *apath, *name, *p, *fpath;
438 if (path[0] == '~') {
439 if (path[1] == '/' || path[1] == '\0') {
440 p = (char *)&path[1];
441 homedir = getcurrentuserhomedir();
443 if ((p = strchr(path, '/')))
444 name = g_strndup(&path[1], --p - path);
446 name = g_strdup(&path[1]);
448 homedir = getuserhomedir(name);
451 apath = g_build_filename(homedir, p, NULL);
453 apath = g_strdup(path);
456 /* creating directory */
457 if (g_mkdir_with_parents(apath, 0700) < 0)
458 die("Could not access directory: %s\n", apath);
460 fpath = realpath(apath, NULL);
467 newclient(Client *rc)
471 if (!(c = calloc(1, sizeof(Client))))
472 die("Cannot malloc!\n");
478 c->view = newview(c, rc ? rc->view : NULL);
484 loaduri(Client *c, const Arg *a)
488 const char *uri = a->v;
490 if (g_strcmp0(uri, "") == 0)
493 if (g_str_has_prefix(uri, "http://") ||
494 g_str_has_prefix(uri, "https://") ||
495 g_str_has_prefix(uri, "file://") ||
496 g_str_has_prefix(uri, "about:")) {
498 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
499 url = g_strdup_printf("file://%s", path);
502 url = g_strdup_printf("http://%s", uri);
505 setatom(c, AtomUri, url);
507 if (strcmp(url, geturi(c)) == 0) {
510 webkit_web_view_load_uri(c->view, url);
522 if (!(uri = webkit_web_view_get_uri(c->view)))
528 setatom(Client *c, int a, const char *v)
531 XChangeProperty(dpy, c->xid,
532 atoms[a], XA_STRING, 8, PropModeReplace,
533 (unsigned char *)v, strlen(v) + 1);
537 getatom(Client *c, int a)
539 static char buf[BUFSIZ];
542 unsigned long ldummy;
543 unsigned char *p = NULL;
545 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
546 &adummy, &idummy, &ldummy, &ldummy, &p);
548 strncpy(buf, (char *)p, LENGTH(buf) - 1);
557 updatetitle(Client *c)
560 const char *name = c->overtitle ? c->overtitle :
561 c->title ? c->title : "";
563 if (curconfig[ShowIndicators].val.b) {
567 if (c->progress != 100)
568 title = g_strdup_printf("[%i%%] %s:%s | %s",
569 c->progress, togglestats, pagestats, name);
571 title = g_strdup_printf("%s:%s | %s",
572 togglestats, pagestats, name);
574 gtk_window_set_title(GTK_WINDOW(c->win), title);
577 gtk_window_set_title(GTK_WINDOW(c->win), name);
582 gettogglestats(Client *c)
584 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
585 togglestats[1] = curconfig[CaretBrowsing].val.b ? 'C' : 'c';
586 togglestats[2] = curconfig[Geolocation].val.b ? 'G' : 'g';
587 togglestats[3] = curconfig[DiskCache].val.b ? 'D' : 'd';
588 togglestats[4] = curconfig[LoadImages].val.b ? 'I' : 'i';
589 togglestats[5] = curconfig[JavaScript].val.b ? 'S' : 's';
590 togglestats[6] = curconfig[Plugins].val.b ? 'V' : 'v';
591 togglestats[7] = curconfig[Style].val.b ? 'M' : 'm';
592 togglestats[8] = curconfig[FrameFlattening].val.b ? 'F' : 'f';
593 togglestats[9] = curconfig[Certificate].val.b ? 'X' : 'x';
594 togglestats[10] = curconfig[StrictTLS].val.b ? 'T' : 't';
595 togglestats[11] = '\0';
599 getpagestats(Client *c)
602 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
608 WebKitCookieAcceptPolicy
609 cookiepolicy_get(void)
611 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
613 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
615 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
616 default: /* fallthrough */
618 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
623 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
626 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
628 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
630 default: /* fallthrough */
631 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
637 seturiparameters(Client *c, const char *uri)
641 for (i = 0; i < LENGTH(uriparams); ++i) {
642 if (uriparams[i].uri &&
643 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
644 curconfig = uriparams[i].config;
649 for (i = 0; i < ParameterLast; ++i)
650 setparameter(c, 0, i, &curconfig[i].val);
654 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
656 GdkRGBA bgcolor = { 0 };
657 WebKitSettings *s = webkit_web_view_get_settings(c->view);
660 case AcceleratedCanvas:
661 webkit_settings_set_enable_accelerated_2d_canvas(s, a->b);
664 webkit_settings_set_enable_caret_browsing(s, a->b);
669 setcert(c, geturi(c));
670 return; /* do not update */
672 webkit_cookie_manager_set_accept_policy(
673 webkit_web_context_get_cookie_manager(
674 webkit_web_view_get_context(c->view)),
679 webkit_web_context_set_cache_model(
680 webkit_web_view_get_context(c->view), a->b ?
681 WEBKIT_CACHE_MODEL_WEB_BROWSER :
682 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
683 return; /* do not update */
685 webkit_settings_set_enable_dns_prefetching(s, a->b);
686 return; /* do not update */
688 webkit_settings_set_default_font_size(s, a->i);
689 return; /* do not update */
690 case FrameFlattening:
691 webkit_settings_set_enable_frame_flattening(s, a->b);
698 webkit_web_view_set_background_color(c->view, &bgcolor);
699 return; /* do not update */
701 webkit_settings_set_enable_developer_extras(s, a->b);
702 return; /* do not update */
704 webkit_settings_set_enable_javascript(s, a->b);
707 return; /* do nothing */
709 webkit_settings_set_auto_load_images(s, a->b);
711 case MediaManualPlay:
712 webkit_settings_set_media_playback_requires_user_gesture(s, a->b);
715 webkit_settings_set_enable_plugins(s, a->b);
717 case PreferredLanguages:
718 return; /* do nothing */
719 case RunInFullscreen:
720 return; /* do nothing */
722 /* Disabled until we write some WebKitWebExtension for
723 * manipulating the DOM directly.
724 enablescrollbars = !enablescrollbars;
725 evalscript(c, "document.documentElement.style.overflow = '%s'",
726 enablescrollbars ? "auto" : "hidden");
728 return; /* do not update */
732 webkit_settings_set_enable_site_specific_quirks(s, a->b);
735 webkit_web_context_set_spell_checking_enabled(
736 webkit_web_view_get_context(c->view), a->b);
737 return; /* do not update */
739 return; /* do nothing */
741 webkit_web_context_set_tls_errors_policy(
742 webkit_web_view_get_context(c->view), a->b ?
743 WEBKIT_TLS_ERRORS_POLICY_FAIL :
744 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
748 setstyle(c, getstyle(geturi(c)));
750 webkit_user_content_manager_remove_all_style_sheets(
751 webkit_web_view_get_user_content_manager(c->view));
755 webkit_web_view_set_zoom_level(c->view, a->f);
756 return; /* do not update */
758 return; /* do nothing */
767 getcert(const char *uri)
771 for (i = 0; i < LENGTH(certs); ++i) {
772 if (certs[i].regex &&
773 !regexec(&(certs[i].re), uri, 0, NULL, 0))
774 return certs[i].file;
781 setcert(Client *c, const char *uri)
783 const char *file = getcert(uri);
785 GTlsCertificate *cert;
790 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
791 fprintf(stderr, "Could not read certificate file: %s\n", file);
795 if ((uri = strstr(uri, "https://"))) {
796 uri += sizeof("https://") - 1;
797 host = g_strndup(uri, strchr(uri, '/') - uri);
798 webkit_web_context_allow_tls_certificate_for_host(
799 webkit_web_view_get_context(c->view), cert, host);
803 g_object_unref(cert);
808 getstyle(const char *uri)
815 for (i = 0; i < LENGTH(styles); ++i) {
816 if (styles[i].regex &&
817 !regexec(&(styles[i].re), uri, 0, NULL, 0))
818 return styles[i].file;
825 setstyle(Client *c, const char *file)
829 if (!g_file_get_contents(file, &style, NULL, NULL)) {
830 fprintf(stderr, "Could not read style file: %s\n", file);
834 webkit_user_content_manager_add_style_sheet(
835 webkit_web_view_get_user_content_manager(c->view),
836 webkit_user_style_sheet_new(style,
837 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
838 WEBKIT_USER_STYLE_LEVEL_USER,
850 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
851 evalscript(c, script);
856 evalscript(Client *c, const char *jsstr, ...)
862 script = g_strdup_vprintf(jsstr, ap);
865 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
870 updatewinid(Client *c)
872 snprintf(winid, LENGTH(winid), "%lu", c->xid);
876 handleplumb(Client *c, const char *uri)
878 Arg a = (Arg)PLUMB(uri);
883 newwindow(Client *c, const Arg *a, int noembed)
887 const char *cmd[29], *uri;
888 const Arg arg = { .v = cmd };
892 cmd[i++] = curconfig[CookiePolicies].val.v;
893 cmd[i++] = curconfig[ScrollBars].val.b ? "-B" : "-b";
894 if (cookiefile && g_strcmp0(cookiefile, "")) {
896 cmd[i++] = cookiefile;
898 if (stylefile && g_strcmp0(stylefile, "")) {
900 cmd[i++] = stylefile;
902 cmd[i++] = curconfig[DiskCache].val.b ? "-D" : "-d";
903 if (embed && !noembed) {
905 snprintf(tmp, LENGTH(tmp), "%lu", embed);
908 cmd[i++] = curconfig[RunInFullscreen].val.b ? "-F" : "-f" ;
909 cmd[i++] = curconfig[Geolocation].val.b ? "-G" : "-g" ;
910 cmd[i++] = curconfig[LoadImages].val.b ? "-I" : "-i" ;
911 cmd[i++] = curconfig[KioskMode].val.b ? "-K" : "-k" ;
912 cmd[i++] = curconfig[Style].val.b ? "-M" : "-m" ;
913 cmd[i++] = curconfig[Inspector].val.b ? "-N" : "-n" ;
914 cmd[i++] = curconfig[Plugins].val.b ? "-P" : "-p" ;
915 if (scriptfile && g_strcmp0(scriptfile, "")) {
917 cmd[i++] = scriptfile;
919 cmd[i++] = curconfig[JavaScript].val.b ? "-S" : "-s";
920 cmd[i++] = curconfig[StrictTLS].val.b ? "-T" : "-t";
921 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
923 cmd[i++] = fulluseragent;
927 cmd[i++] = curconfig[Certificate].val.b ? "-X" : "-x" ;
928 /* do not keep zoom level */
938 spawn(Client *c, const Arg *a)
942 close(ConnectionNumber(dpy));
944 execvp(((char **)a->v)[0], (char **)a->v);
945 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
952 destroyclient(Client *c)
956 webkit_web_view_stop_loading(c->view);
957 /* Not needed, has already been called
958 gtk_widget_destroy(c->win);
961 for (p = clients; p && p->next != c; p = p->next)
974 destroyclient(clients);
983 newview(Client *c, WebKitWebView *rv)
986 WebKitSettings *settings;
987 WebKitUserContentManager *contentmanager;
988 WebKitWebContext *context;
993 webkit_web_view_new_with_related_view(rv));
995 settings = webkit_settings_new_with_settings(
996 "auto-load-images", curconfig[LoadImages].val.b,
997 "default-font-size", curconfig[FontSize].val.i,
998 "enable-caret-browsing", curconfig[CaretBrowsing].val.b,
999 "enable-developer-extras", curconfig[Inspector].val.b,
1000 "enable-dns-prefetching", curconfig[DNSPrefetch].val.b,
1001 "enable-frame-flattening", curconfig[FrameFlattening].val.b,
1002 "enable-html5-database", curconfig[DiskCache].val.b,
1003 "enable-html5-local-storage", curconfig[DiskCache].val.b,
1004 "enable-javascript", curconfig[JavaScript].val.b,
1005 "enable-plugins", curconfig[Plugins].val.b,
1006 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.b,
1007 "enable-site-specific-quirks", curconfig[SiteQuirks].val.b,
1008 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.b,
1010 /* For more interesting settings, have a look at
1011 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1013 if (strcmp(fulluseragent, "")) {
1014 webkit_settings_set_user_agent(settings, fulluseragent);
1015 } else if (surfuseragent) {
1016 webkit_settings_set_user_agent_with_application_details(
1017 settings, "Surf", VERSION);
1019 useragent = webkit_settings_get_user_agent(settings);
1021 contentmanager = webkit_user_content_manager_new();
1023 context = webkit_web_context_new_with_website_data_manager(
1024 webkit_website_data_manager_new(
1025 "base-cache-directory", cachedir,
1026 "base-data-directory", cachedir,
1029 /* rendering process model, can be a shared unique one
1030 * or one for each view */
1031 webkit_web_context_set_process_model(context,
1032 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1034 webkit_web_context_set_tls_errors_policy(context,
1035 curconfig[StrictTLS].val.b ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1036 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1038 webkit_web_context_set_cache_model(context,
1039 curconfig[DiskCache].val.b ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1040 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1042 /* Currently only works with text file to be compatible with curl */
1043 webkit_cookie_manager_set_persistent_storage(
1044 webkit_web_context_get_cookie_manager(context), cookiefile,
1045 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1047 webkit_cookie_manager_set_accept_policy(
1048 webkit_web_context_get_cookie_manager(context),
1049 cookiepolicy_get());
1051 webkit_web_context_set_preferred_languages(context,
1052 curconfig[PreferredLanguages].val.v);
1053 webkit_web_context_set_spell_checking_languages(context,
1054 curconfig[SpellLanguages].val.v);
1055 webkit_web_context_set_spell_checking_enabled(context,
1056 curconfig[SpellChecking].val.b);
1058 g_signal_connect(G_OBJECT(context), "download-started",
1059 G_CALLBACK(downloadstarted), c);
1060 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1061 G_CALLBACK(initwebextensions), c);
1063 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1064 "settings", settings,
1065 "user-content-manager", contentmanager,
1066 "web-context", context,
1070 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1071 G_CALLBACK(progresschanged), c);
1072 g_signal_connect(G_OBJECT(v), "notify::title",
1073 G_CALLBACK(titlechanged), c);
1074 g_signal_connect(G_OBJECT(v), "button-release-event",
1075 G_CALLBACK(buttonreleased), c);
1076 g_signal_connect(G_OBJECT(v), "close",
1077 G_CALLBACK(closeview), c);
1078 g_signal_connect(G_OBJECT(v), "create",
1079 G_CALLBACK(createview), c);
1080 g_signal_connect(G_OBJECT(v), "decide-policy",
1081 G_CALLBACK(decidepolicy), c);
1082 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1083 G_CALLBACK(insecurecontent), c);
1084 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1085 G_CALLBACK(loadfailedtls), c);
1086 g_signal_connect(G_OBJECT(v), "load-changed",
1087 G_CALLBACK(loadchanged), c);
1088 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1089 G_CALLBACK(mousetargetchanged), c);
1090 g_signal_connect(G_OBJECT(v), "permission-request",
1091 G_CALLBACK(permissionrequested), c);
1092 g_signal_connect(G_OBJECT(v), "ready-to-show",
1093 G_CALLBACK(showview), c);
1099 initwebextensions(WebKitWebContext *wc, Client *c)
1101 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1105 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1109 switch (webkit_navigation_action_get_navigation_type(a)) {
1110 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1112 * popup windows of type “other” are almost always triggered
1113 * by user gesture, so inverse the logic here
1115 /* instead of this, compare destination uri to mouse-over uri for validating window */
1116 if (webkit_navigation_action_is_user_gesture(a))
1118 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1119 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1120 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1121 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1122 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1129 return GTK_WIDGET(n->view);
1133 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1135 WebKitHitTestResultContext element;
1138 element = webkit_hit_test_result_get_context(c->mousepos);
1140 for (i = 0; i < LENGTH(buttons); ++i) {
1141 if (element & buttons[i].target &&
1142 e->button.button == buttons[i].button &&
1143 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1145 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1146 return buttons[i].stopevent;
1154 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1156 Client *c = (Client *)d;
1160 if (((XEvent *)e)->type == PropertyNotify) {
1161 ev = &((XEvent *)e)->xproperty;
1162 if (ev->state == PropertyNewValue) {
1163 if (ev->atom == atoms[AtomFind]) {
1166 return GDK_FILTER_REMOVE;
1167 } else if (ev->atom == atoms[AtomGo]) {
1168 a.v = getatom(c, AtomGo);
1171 return GDK_FILTER_REMOVE;
1175 return GDK_FILTER_CONTINUE;
1179 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1184 case GDK_ENTER_NOTIFY:
1185 c->overtitle = c->targeturi;
1189 if (!curconfig[KioskMode].val.b) {
1190 for (i = 0; i < LENGTH(keys); ++i) {
1191 if (gdk_keyval_to_lower(e->key.keyval) ==
1193 CLEANMASK(e->key.state) == keys[i].mod &&
1196 keys[i].func(c, &(keys[i].arg));
1201 case GDK_LEAVE_NOTIFY:
1202 c->overtitle = NULL;
1205 case GDK_WINDOW_STATE:
1206 if (e->window_state.changed_mask ==
1207 GDK_WINDOW_STATE_FULLSCREEN)
1208 c->fullscreen = e->window_state.new_window_state &
1209 GDK_WINDOW_STATE_FULLSCREEN;
1219 showview(WebKitWebView *v, Client *c)
1221 GdkRGBA bgcolor = { 0 };
1224 c->finder = webkit_web_view_get_find_controller(c->view);
1225 c->inspector = webkit_web_view_get_inspector(c->view);
1227 c->win = createwindow(c);
1229 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1230 gtk_widget_show_all(c->win);
1231 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1233 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1234 c->xid = gdk_x11_window_get_xid(gwin);
1237 gdk_display_sync(gtk_widget_get_display(c->win));
1241 if (curconfig[HideBackground].val.b)
1242 webkit_web_view_set_background_color(c->view, &bgcolor);
1244 if (!curconfig[KioskMode].val.b) {
1245 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1246 gdk_window_add_filter(gwin, processx, c);
1249 if (curconfig[RunInFullscreen].val.b)
1250 togglefullscreen(c, NULL);
1252 if (curconfig[ZoomLevel].val.f != 1.0)
1253 webkit_web_view_set_zoom_level(c->view,
1254 curconfig[ZoomLevel].val.f);
1256 setatom(c, AtomFind, "");
1257 setatom(c, AtomUri, "about:blank");
1261 createwindow(Client *c)
1267 w = gtk_plug_new(embed);
1269 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1271 wmstr = g_path_get_basename(argv0);
1272 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1275 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1276 webkit_web_view_get_page_id(c->view));
1277 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1280 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1283 g_signal_connect(G_OBJECT(w), "destroy",
1284 G_CALLBACK(destroywin), c);
1285 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1286 G_CALLBACK(winevent), c);
1287 g_signal_connect(G_OBJECT(w), "key-press-event",
1288 G_CALLBACK(winevent), c);
1289 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1290 G_CALLBACK(winevent), c);
1291 g_signal_connect(G_OBJECT(w), "window-state-event",
1292 G_CALLBACK(winevent), c);
1298 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1299 GTlsCertificateFlags err, Client *c)
1301 GString *errmsg = g_string_new(NULL);
1304 c->failedcert = g_object_ref(cert);
1308 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1309 g_string_append(errmsg,
1310 "The signing certificate authority is not known.<br>");
1311 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1312 g_string_append(errmsg,
1313 "The certificate does not match the expected identity "
1314 "of the site that it was retrieved from.<br>");
1315 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1316 g_string_append(errmsg,
1317 "The certificate's activation time "
1318 "is still in the future.<br>");
1319 if (err & G_TLS_CERTIFICATE_EXPIRED)
1320 g_string_append(errmsg, "The certificate has expired.<br>");
1321 if (err & G_TLS_CERTIFICATE_REVOKED)
1322 g_string_append(errmsg,
1323 "The certificate has been revoked according to "
1324 "the GTlsConnection's certificate revocation list.<br>");
1325 if (err & G_TLS_CERTIFICATE_INSECURE)
1326 g_string_append(errmsg,
1327 "The certificate's algorithm is considered insecure.<br>");
1328 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1329 g_string_append(errmsg,
1330 "Some error occurred validating the certificate.<br>");
1332 g_object_get(cert, "certificate-pem", &pem, NULL);
1333 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1334 "<p>You can inspect the following certificate "
1335 "with Ctrl+Shift+x (default keybinding).</p>"
1336 "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
1338 g_string_free(errmsg, TRUE);
1340 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1347 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1349 const char *title = geturi(c);
1352 case WEBKIT_LOAD_STARTED:
1353 curconfig = defconfig;
1354 setatom(c, AtomUri, title);
1356 c->https = c->insecure = 0;
1357 seturiparameters(c, geturi(c));
1361 g_clear_object(&c->failedcert);
1363 case WEBKIT_LOAD_REDIRECTED:
1364 setatom(c, AtomUri, title);
1366 seturiparameters(c, geturi(c));
1368 case WEBKIT_LOAD_COMMITTED:
1369 c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
1372 case WEBKIT_LOAD_FINISHED:
1373 /* Disabled until we write some WebKitWebExtension for
1374 * manipulating the DOM directly.
1375 evalscript(c, "document.documentElement.style.overflow = '%s'",
1376 enablescrollbars ? "auto" : "hidden");
1385 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1387 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1393 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1395 c->title = webkit_web_view_get_title(c->view);
1400 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1403 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1405 /* Keep the hit test to know where is the pointer on the next click */
1409 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1410 else if (hc & OnImg)
1411 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1412 else if (hc & OnMedia)
1413 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1415 c->targeturi = NULL;
1417 c->overtitle = c->targeturi;
1422 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1424 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1425 if (curconfig[Geolocation].val.b)
1426 webkit_permission_request_allow(r);
1428 webkit_permission_request_deny(r);
1436 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1437 WebKitPolicyDecisionType dt, Client *c)
1440 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1441 decidenavigation(d, c);
1443 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1444 decidenewwindow(d, c);
1446 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1447 decideresource(d, c);
1450 webkit_policy_decision_ignore(d);
1457 decidenavigation(WebKitPolicyDecision *d, Client *c)
1459 WebKitNavigationAction *a =
1460 webkit_navigation_policy_decision_get_navigation_action(
1461 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1463 switch (webkit_navigation_action_get_navigation_type(a)) {
1464 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1465 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1466 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1467 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1468 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1469 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1471 /* Do not navigate to links with a "_blank" target (popup) */
1472 if (webkit_navigation_policy_decision_get_frame_name(
1473 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1474 webkit_policy_decision_ignore(d);
1476 /* Filter out navigation to different domain ? */
1477 /* get action→urirequest, copy and load in new window+view
1478 * on Ctrl+Click ? */
1479 webkit_policy_decision_use(d);
1486 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1489 WebKitNavigationAction *a =
1490 webkit_navigation_policy_decision_get_navigation_action(
1491 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1494 switch (webkit_navigation_action_get_navigation_type(a)) {
1495 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1496 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1497 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1498 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1499 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1500 /* Filter domains here */
1501 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1502 * test for link clicked but no button ? */
1503 arg.v = webkit_uri_request_get_uri(
1504 webkit_navigation_action_get_request(a));
1505 newwindow(c, &arg, 0);
1507 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1512 webkit_policy_decision_ignore(d);
1516 decideresource(WebKitPolicyDecision *d, Client *c)
1519 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1520 WebKitURIResponse *res =
1521 webkit_response_policy_decision_get_response(r);
1522 const gchar *uri = webkit_uri_response_get_uri(res);
1524 if (g_str_has_suffix(uri, "/favicon.ico")) {
1525 webkit_policy_decision_ignore(d);
1529 if (!g_str_has_prefix(uri, "http://")
1530 && !g_str_has_prefix(uri, "https://")
1531 && !g_str_has_prefix(uri, "about:")
1532 && !g_str_has_prefix(uri, "file://")
1533 && !g_str_has_prefix(uri, "data:")
1534 && !g_str_has_prefix(uri, "blob:")
1535 && strlen(uri) > 0) {
1536 for (i = 0; i < strlen(uri); i++) {
1537 if (!g_ascii_isprint(uri[i])) {
1543 handleplumb(c, uri);
1544 webkit_policy_decision_ignore(d);
1549 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1550 webkit_policy_decision_use(d);
1552 webkit_policy_decision_ignore(d);
1558 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1564 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1566 g_signal_connect(G_OBJECT(d), "notify::response",
1567 G_CALLBACK(responsereceived), c);
1571 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1573 download(c, webkit_download_get_response(d));
1574 webkit_download_cancel(d);
1578 download(Client *c, WebKitURIResponse *r)
1580 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1585 closeview(WebKitWebView *v, Client *c)
1587 gtk_widget_destroy(c->win);
1591 destroywin(GtkWidget* w, Client *c)
1599 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1601 Arg a = {.v = text };
1603 loaduri((Client *) d, &a);
1607 reload(Client *c, const Arg *a)
1610 webkit_web_view_reload_bypass_cache(c->view);
1612 webkit_web_view_reload(c->view);
1616 print(Client *c, const Arg *a)
1618 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1619 GTK_WINDOW(c->win));
1623 showcert(Client *c, const Arg *a)
1625 GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
1626 GcrCertificate *gcrt;
1629 GcrCertificateWidget *wcert;
1634 g_object_get(cert, "certificate", &crt, NULL);
1635 gcrt = gcr_simple_certificate_new(crt->data, crt->len);
1636 g_byte_array_unref(crt);
1638 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1639 wcert = gcr_certificate_widget_new(gcrt);
1640 g_object_unref(gcrt);
1642 gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
1643 gtk_widget_show_all(win);
1647 clipboard(Client *c, const Arg *a)
1649 if (a->b) { /* load clipboard uri */
1650 gtk_clipboard_request_text(gtk_clipboard_get(
1651 GDK_SELECTION_PRIMARY),
1653 } else { /* copy uri */
1654 gtk_clipboard_set_text(gtk_clipboard_get(
1655 GDK_SELECTION_PRIMARY), c->targeturi
1656 ? c->targeturi : geturi(c), -1);
1661 zoom(Client *c, const Arg *a)
1664 webkit_web_view_set_zoom_level(c->view,
1665 curconfig[ZoomLevel].val.f + 0.1);
1667 webkit_web_view_set_zoom_level(c->view,
1668 curconfig[ZoomLevel].val.f - 0.1);
1670 webkit_web_view_set_zoom_level(c->view, 1.0);
1672 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1676 scroll(Client *c, const Arg *a)
1678 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1680 gdk_event_set_device(ev, gdkkb);
1681 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1682 ev->key.state = GDK_CONTROL_MASK;
1683 ev->key.time = GDK_CURRENT_TIME;
1687 ev->key.keyval = GDK_KEY_Down;
1690 ev->key.keyval = GDK_KEY_Page_Down;
1693 ev->key.keyval = GDK_KEY_Left;
1696 ev->key.keyval = GDK_KEY_Right;
1699 ev->key.keyval = GDK_KEY_Page_Up;
1702 ev->key.keyval = GDK_KEY_Up;
1710 navigate(Client *c, const Arg *a)
1713 webkit_web_view_go_back(c->view);
1715 webkit_web_view_go_forward(c->view);
1719 stop(Client *c, const Arg *a)
1721 webkit_web_view_stop_loading(c->view);
1725 toggle(Client *c, const Arg *a)
1727 curconfig[a->i].val.b ^= 1;
1728 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1732 togglefullscreen(Client *c, const Arg *a)
1734 /* toggling value is handled in winevent() */
1736 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1738 gtk_window_fullscreen(GTK_WINDOW(c->win));
1742 togglecookiepolicy(Client *c, const Arg *a)
1745 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1747 setparameter(c, 0, CookiePolicies, NULL);
1751 toggleinspector(Client *c, const Arg *a)
1753 if (webkit_web_inspector_is_attached(c->inspector))
1754 webkit_web_inspector_close(c->inspector);
1755 else if (curconfig[Inspector].val.b)
1756 webkit_web_inspector_show(c->inspector);
1760 find(Client *c, const Arg *a)
1766 webkit_find_controller_search_next(c->finder);
1768 webkit_find_controller_search_previous(c->finder);
1770 s = getatom(c, AtomFind);
1771 f = webkit_find_controller_get_search_text(c->finder);
1773 if (g_strcmp0(f, s) == 0) /* reset search */
1774 webkit_find_controller_search(c->finder, "", findopts,
1777 webkit_find_controller_search(c->finder, s, findopts,
1780 if (strcmp(s, "") == 0)
1781 webkit_find_controller_search_finish(c->finder);
1786 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1792 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1796 arg.v = webkit_hit_test_result_get_link_uri(h);
1797 newwindow(c, &arg, a->b);
1801 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1805 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1810 main(int argc, char *argv[])
1815 memset(&arg, 0, sizeof(arg));
1817 /* command line args */
1820 defconfig CSETV(CookiePolicies, EARGF(usage()));
1823 defconfig CSETB(ScrollBars, 0);
1826 defconfig CSETB(ScrollBars, 1);
1829 cookiefile = EARGF(usage());
1832 stylefile = EARGF(usage());
1835 defconfig CSETB(DiskCache, 0);
1838 defconfig CSETB(DiskCache, 1);
1841 embed = strtol(EARGF(usage()), NULL, 0);
1844 defconfig CSETB(RunInFullscreen, 0);
1847 defconfig CSETB(RunInFullscreen, 1);
1850 defconfig CSETB(Geolocation, 0);
1853 defconfig CSETB(Geolocation, 1);
1856 defconfig CSETB(LoadImages, 0);
1859 defconfig CSETB(LoadImages, 1);
1862 defconfig CSETB(KioskMode, 0);
1865 defconfig CSETB(KioskMode, 1);
1868 defconfig CSETB(Style, 0);
1871 defconfig CSETB(Style, 1);
1874 defconfig CSETB(Inspector, 0);
1877 defconfig CSETB(Inspector, 1);
1880 defconfig CSETB(Plugins, 0);
1883 defconfig CSETB(Plugins, 1);
1886 scriptfile = EARGF(usage());
1889 defconfig CSETB(JavaScript, 0);
1892 defconfig CSETB(JavaScript, 1);
1895 defconfig CSETB(StrictTLS, 0);
1898 defconfig CSETB(StrictTLS, 1);
1901 fulluseragent = EARGF(usage());
1904 die("surf-"VERSION", ©2009-2017 surf engineers, "
1905 "see LICENSE for details\n");
1910 defconfig CSETB(Certificate, 0);
1913 defconfig CSETB(Certificate, 1);
1916 defconfig CSETF(ZoomLevel, strtof(EARGF(usage()), NULL));
1924 arg.v = "about:blank";
1927 c = newclient(NULL);