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>
33 #define LENGTH(x) (sizeof(x) / sizeof(x[0]))
34 #define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
35 #define SETB(p, s) [p] = { { .b = s }, }
36 #define SETI(p, s) [p] = { { .i = s }, }
37 #define SETV(p, s) [p] = { { .v = s }, }
38 #define SETF(p, s) [p] = { { .f = s }, }
39 #define FSETB(p, s) [p] = { { .b = s }, 1 }
40 #define FSETI(p, s) [p] = { { .i = s }, 1 }
41 #define FSETV(p, s) [p] = { { .v = s }, 1 }
42 #define FSETF(p, s) [p] = { { .f = s }, 1 }
43 #define CSETB(p, s) [p] = (Parameter){ { .b = s }, 1 }
44 #define CSETI(p, s) [p] = (Parameter){ { .i = s }, 1 }
45 #define CSETV(p, s) [p] = (Parameter){ { .v = s }, 1 }
46 #define CSETF(p, s) [p] = (Parameter){ { .f = s }, 1 }
48 enum { AtomFind, AtomGo, AtomUri, AtomLast };
51 OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
52 OnLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
53 OnImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
54 OnMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
55 OnEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
56 OnBar = WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR,
57 OnSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
58 OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
103 typedef struct Client {
106 WebKitWebInspector *inspector;
107 WebKitFindController *finder;
108 WebKitHitTestResult *mousepos;
109 GTlsCertificateFlags tlserr;
111 int progress, fullscreen, https, insecure;
112 const char *title, *overtitle, *targeturi;
120 void (*func)(Client *c, const Arg *a);
128 void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
130 unsigned int stopevent;
135 Parameter config[ParameterLast];
146 static void usage(void);
147 static void die(const char *errstr, ...);
148 static void setup(void);
149 static void sigchld(int unused);
150 static void sighup(int unused);
151 static char *buildfile(const char *path);
152 static char *buildpath(const char *path);
153 static const char *getuserhomedir(const char *user);
154 static const char *getcurrentuserhomedir(void);
155 static Client *newclient(Client *c);
156 static void loaduri(Client *c, const Arg *a);
157 static const char *geturi(Client *c);
158 static void setatom(Client *c, int a, const char *v);
159 static const char *getatom(Client *c, int a);
160 static void updatetitle(Client *c);
161 static void gettogglestats(Client *c);
162 static void getpagestats(Client *c);
163 static WebKitCookieAcceptPolicy cookiepolicy_get(void);
164 static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
165 static void seturiparameters(Client *c, const char *uri);
166 static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
167 static const char *getcert(const char *uri);
168 static void setcert(Client *c, const char *file);
169 static const char *getstyle(const char *uri);
170 static void setstyle(Client *c, const char *file);
171 static void runscript(Client *c);
172 static void evalscript(Client *c, const char *jsstr, ...);
173 static void updatewinid(Client *c);
174 static void handleplumb(Client *c, const char *uri);
175 static void newwindow(Client *c, const Arg *a, int noembed);
176 static void spawn(Client *c, 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 void showview(WebKitWebView *v, Client *c);
190 static GtkWidget *createwindow(Client *c);
191 static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
192 GTlsCertificate *cert,
193 GTlsCertificateFlags err, Client *c);
194 static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
195 static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
196 static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
197 static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
198 guint modifiers, Client *c);
199 static gboolean permissionrequested(WebKitWebView *v,
200 WebKitPermissionRequest *r, Client *c);
201 static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
202 WebKitPolicyDecisionType dt, Client *c);
203 static void decidenavigation(WebKitPolicyDecision *d, Client *c);
204 static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
205 static void decideresource(WebKitPolicyDecision *d, Client *c);
206 static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
208 static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
210 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
211 static void download(Client *c, WebKitURIResponse *r);
212 static void closeview(WebKitWebView *v, Client *c);
213 static void destroywin(GtkWidget* w, Client *c);
216 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
217 static void reload(Client *c, const Arg *a);
218 static void print(Client *c, const Arg *a);
219 static void clipboard(Client *c, const Arg *a);
220 static void zoom(Client *c, const Arg *a);
221 static void scroll(Client *c, const Arg *a);
222 static void navigate(Client *c, const Arg *a);
223 static void stop(Client *c, const Arg *a);
224 static void toggle(Client *c, const Arg *a);
225 static void togglefullscreen(Client *c, const Arg *a);
226 static void togglecookiepolicy(Client *c, const Arg *a);
227 static void toggleinspector(Client *c, const Arg *a);
228 static void find(Client *c, const Arg *a);
231 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
232 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
233 static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
235 static char winid[64];
236 static char togglestats[11];
237 static char pagestats[2];
238 static Atom atoms[AtomLast];
241 static int cookiepolicy;
243 static Client *clients;
244 static GdkDevice *gdkkb;
245 static char *stylefile;
246 static const char *useragent;
247 static Parameter *curconfig;
250 /* configuration, allows nested code to access above variables */
256 die("usage: %s [-bBdDfFgGiIkKmMnNpPsStTvx] [-a cookiepolicies ] "
257 "[-c cookiefile] [-C stylefile] [-e xid] [-r scriptfile] "
258 "[-u useragent] [-z zoomlevel] [uri]\n", basename(argv0));
262 die(const char *errstr, ...)
266 va_start(ap, errstr);
267 vfprintf(stderr, errstr, ap);
278 /* clean up any zombies immediately */
280 if (signal(SIGHUP, sighup) == SIG_ERR)
281 die("Can't install SIGHUP handler");
283 if (!(dpy = XOpenDisplay(NULL)))
284 die("Can't open default display");
287 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
288 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
289 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
291 gtk_init(NULL, NULL);
293 gdpy = gdk_display_get_default();
295 curconfig = defconfig;
298 cookiefile = buildfile(cookiefile);
299 scriptfile = buildfile(scriptfile);
300 cachedir = buildpath(cachedir);
301 certdir = buildpath(certdir);
303 gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
305 for (i = 0; i < LENGTH(certs); ++i) {
306 if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
307 certs[i].file = g_strconcat(certdir, "/", certs[i].file,
310 fprintf(stderr, "Could not compile regex: %s\n",
312 certs[i].regex = NULL;
317 styledir = buildpath(styledir);
318 for (i = 0; i < LENGTH(styles); ++i) {
319 if (!regcomp(&(styles[i].re), styles[i].regex,
321 styles[i].file = g_strconcat(styledir, "/",
322 styles[i].file, NULL);
324 fprintf(stderr, "Could not compile regex: %s\n",
326 styles[i].regex = NULL;
331 stylefile = buildfile(stylefile);
334 for (i = 0; i < LENGTH(uriparams); ++i) {
335 if (!regcomp(&(uriparams[i].re), uriparams[i].uri,
337 /* copy default parameters if they are not already set
338 * or if they are forced */
339 for (j = 0; j < ParameterLast; ++j) {
340 if (!uriparams[i].config[j].force ||
342 uriparams[i].config[j] = defconfig[j];
345 fprintf(stderr, "Could not compile regex: %s\n",
347 uriparams[i].uri = NULL;
355 if (signal(SIGCHLD, sigchld) == SIG_ERR)
356 die("Can't install SIGCHLD handler");
357 while (waitpid(-1, NULL, WNOHANG) > 0)
367 for (c = clients; c; c = c->next)
372 buildfile(const char *path)
374 char *dname, *bname, *bpath, *fpath;
377 dname = g_path_get_dirname(path);
378 bname = g_path_get_basename(path);
380 bpath = buildpath(dname);
383 fpath = g_build_filename(bpath, bname, NULL);
387 if (!(f = fopen(fpath, "a")))
388 die("Could not open file: %s\n", fpath);
390 g_chmod(fpath, 0600); /* always */
397 getuserhomedir(const char *user)
399 struct passwd *pw = getpwnam(user);
402 die("Can't get user %s login information.\n", user);
408 getcurrentuserhomedir(void)
414 homedir = getenv("HOME");
418 user = getenv("USER");
420 return getuserhomedir(user);
422 pw = getpwuid(getuid());
424 die("Can't get current user home directory\n");
430 buildpath(const char *path)
432 char *apath, *name, *p, *fpath;
435 if (path[0] == '~') {
436 if (path[1] == '/' || path[1] == '\0') {
437 p = (char *)&path[1];
438 homedir = getcurrentuserhomedir();
440 if ((p = strchr(path, '/')))
441 name = g_strndup(&path[1], --p - path);
443 name = g_strdup(&path[1]);
445 homedir = getuserhomedir(name);
448 apath = g_build_filename(homedir, p, NULL);
450 apath = g_strdup(path);
453 /* creating directory */
454 if (g_mkdir_with_parents(apath, 0700) < 0)
455 die("Could not access directory: %s\n", apath);
457 fpath = realpath(apath, NULL);
464 newclient(Client *rc)
468 if (!(c = calloc(1, sizeof(Client))))
469 die("Cannot malloc!\n");
475 c->view = newview(c, rc ? rc->view : NULL);
481 loaduri(Client *c, const Arg *a)
485 const char *uri = a->v;
487 if (g_strcmp0(uri, "") == 0)
490 if (g_str_has_prefix(uri, "http://") ||
491 g_str_has_prefix(uri, "https://") ||
492 g_str_has_prefix(uri, "file://") ||
493 g_str_has_prefix(uri, "about:")) {
495 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
496 url = g_strdup_printf("file://%s", path);
499 url = g_strdup_printf("http://%s", uri);
502 setatom(c, AtomUri, url);
504 if (strcmp(url, geturi(c)) == 0) {
507 webkit_web_view_load_uri(c->view, url);
519 if (!(uri = webkit_web_view_get_uri(c->view)))
525 setatom(Client *c, int a, const char *v)
528 XChangeProperty(dpy, c->xid,
529 atoms[a], XA_STRING, 8, PropModeReplace,
530 (unsigned char *)v, strlen(v) + 1);
534 getatom(Client *c, int a)
536 static char buf[BUFSIZ];
539 unsigned long ldummy;
540 unsigned char *p = NULL;
542 XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
543 &adummy, &idummy, &ldummy, &ldummy, &p);
545 strncpy(buf, (char *)p, LENGTH(buf) - 1);
554 updatetitle(Client *c)
557 const char *name = c->overtitle ? c->overtitle :
558 c->title ? c->title : "";
560 if (curconfig[ShowIndicators].val.b) {
564 if (c->progress != 100)
565 title = g_strdup_printf("[%i%%] %s:%s | %s",
566 c->progress, togglestats, pagestats, name);
568 title = g_strdup_printf("%s:%s | %s",
569 togglestats, pagestats, name);
571 gtk_window_set_title(GTK_WINDOW(c->win), title);
574 gtk_window_set_title(GTK_WINDOW(c->win), name);
579 gettogglestats(Client *c)
581 togglestats[0] = cookiepolicy_set(cookiepolicy_get());
582 togglestats[1] = curconfig[CaretBrowsing].val.b ? 'C' : 'c';
583 togglestats[2] = curconfig[Geolocation].val.b ? 'G' : 'g';
584 togglestats[3] = curconfig[DiskCache].val.b ? 'D' : 'd';
585 togglestats[4] = curconfig[LoadImages].val.b ? 'I' : 'i';
586 togglestats[5] = curconfig[JavaScript].val.b ? 'S' : 's';
587 togglestats[6] = curconfig[Plugins].val.b ? 'V' : 'v';
588 togglestats[7] = curconfig[Style].val.b ? 'M' : 'm';
589 togglestats[8] = curconfig[FrameFlattening].val.b ? 'F' : 'f';
590 togglestats[9] = curconfig[StrictTLS].val.b ? 'T' : 't';
591 togglestats[10] = '\0';
595 getpagestats(Client *c)
598 pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
604 WebKitCookieAcceptPolicy
605 cookiepolicy_get(void)
607 switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
609 return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
611 return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
612 default: /* fallthrough */
614 return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
619 cookiepolicy_set(const WebKitCookieAcceptPolicy p)
622 case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
624 case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
626 default: /* fallthrough */
627 case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
633 seturiparameters(Client *c, const char *uri)
637 for (i = 0; i < LENGTH(uriparams); ++i) {
638 if (uriparams[i].uri &&
639 !regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
640 curconfig = uriparams[i].config;
645 for (i = 0; i < ParameterLast; ++i)
646 setparameter(c, 0, i, &curconfig[i].val);
650 setparameter(Client *c, int refresh, ParamName p, const Arg *a)
652 GdkRGBA bgcolor = { 0 };
653 WebKitSettings *s = webkit_web_view_get_settings(c->view);
656 case AcceleratedCanvas:
657 webkit_settings_set_enable_accelerated_2d_canvas(s, a->b);
660 webkit_settings_set_enable_caret_browsing(s, a->b);
665 setcert(c, geturi(c));
666 return; /* do not update */
668 webkit_cookie_manager_set_accept_policy(
669 webkit_web_context_get_cookie_manager(
670 webkit_web_view_get_context(c->view)),
675 webkit_web_context_set_cache_model(
676 webkit_web_view_get_context(c->view), a->b ?
677 WEBKIT_CACHE_MODEL_WEB_BROWSER :
678 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
679 return; /* do not update */
681 webkit_settings_set_enable_dns_prefetching(s, a->b);
682 return; /* do not update */
684 webkit_settings_set_default_font_size(s, a->i);
685 return; /* do not update */
686 case FrameFlattening:
687 webkit_settings_set_enable_frame_flattening(s, a->b);
694 webkit_web_view_set_background_color(c->view, &bgcolor);
695 return; /* do not update */
697 webkit_settings_set_enable_developer_extras(s, a->b);
698 return; /* do not update */
700 webkit_settings_set_enable_javascript(s, a->b);
703 return; /* do nothing */
705 webkit_settings_set_auto_load_images(s, a->b);
707 case MediaManualPlay:
708 webkit_settings_set_media_playback_requires_user_gesture(s, a->b);
711 webkit_settings_set_enable_plugins(s, a->b);
713 case PreferredLanguages:
714 return; /* do nothing */
715 case RunInFullscreen:
716 return; /* do nothing */
718 /* Disabled until we write some WebKitWebExtension for
719 * manipulating the DOM directly.
720 enablescrollbars = !enablescrollbars;
721 evalscript(c, "document.documentElement.style.overflow = '%s'",
722 enablescrollbars ? "auto" : "hidden");
724 return; /* do not update */
728 webkit_settings_set_enable_site_specific_quirks(s, a->b);
731 webkit_web_context_set_spell_checking_enabled(
732 webkit_web_view_get_context(c->view), a->b);
733 return; /* do not update */
735 return; /* do nothing */
737 webkit_web_context_set_tls_errors_policy(
738 webkit_web_view_get_context(c->view), a->b ?
739 WEBKIT_TLS_ERRORS_POLICY_FAIL :
740 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
744 setstyle(c, getstyle(geturi(c)));
746 webkit_user_content_manager_remove_all_style_sheets(
747 webkit_web_view_get_user_content_manager(c->view));
751 webkit_web_view_set_zoom_level(c->view, a->f);
752 return; /* do not update */
754 return; /* do nothing */
763 getcert(const char *uri)
767 for (i = 0; i < LENGTH(certs); ++i) {
768 if (certs[i].regex &&
769 !regexec(&(certs[i].re), uri, 0, NULL, 0))
770 return certs[i].file;
777 setcert(Client *c, const char *uri)
779 const char *file = getcert(uri);
781 GTlsCertificate *cert;
786 if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
787 fprintf(stderr, "Could not read certificate file: %s\n", file);
791 uri = strstr(uri, "://") + sizeof("://") - 1;
792 host = strndup(uri, strstr(uri, "/") - uri);
794 webkit_web_context_allow_tls_certificate_for_host(
795 webkit_web_view_get_context(c->view), cert, host);
796 g_object_unref(cert);
802 getstyle(const char *uri)
809 for (i = 0; i < LENGTH(styles); ++i) {
810 if (styles[i].regex &&
811 !regexec(&(styles[i].re), uri, 0, NULL, 0))
812 return styles[i].file;
819 setstyle(Client *c, const char *file)
823 if (!g_file_get_contents(file, &style, NULL, NULL)) {
824 fprintf(stderr, "Could not read style file: %s\n", file);
828 webkit_user_content_manager_add_style_sheet(
829 webkit_web_view_get_user_content_manager(c->view),
830 webkit_user_style_sheet_new(style,
831 WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
832 WEBKIT_USER_STYLE_LEVEL_USER,
844 if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
845 evalscript(c, script);
850 evalscript(Client *c, const char *jsstr, ...)
856 script = g_strdup_vprintf(jsstr, ap);
859 webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
864 updatewinid(Client *c)
866 snprintf(winid, LENGTH(winid), "%lu", c->xid);
870 handleplumb(Client *c, const char *uri)
872 Arg a = (Arg)PLUMB(uri);
877 newwindow(Client *c, const Arg *a, int noembed)
881 const char *cmd[28], *uri;
882 const Arg arg = { .v = cmd };
886 cmd[i++] = curconfig[CookiePolicies].val.v;
887 cmd[i++] = curconfig[ScrollBars].val.b ? "-B" : "-b";
888 if (cookiefile && g_strcmp0(cookiefile, "")) {
890 cmd[i++] = cookiefile;
892 if (stylefile && g_strcmp0(stylefile, "")) {
894 cmd[i++] = stylefile;
896 cmd[i++] = curconfig[DiskCache].val.b ? "-D" : "-d";
897 if (embed && !noembed) {
899 snprintf(tmp, LENGTH(tmp), "%lu", embed);
902 cmd[i++] = curconfig[RunInFullscreen].val.b ? "-F" : "-f" ;
903 cmd[i++] = curconfig[Geolocation].val.b ? "-G" : "-g" ;
904 cmd[i++] = curconfig[LoadImages].val.b ? "-I" : "-i" ;
905 cmd[i++] = curconfig[KioskMode].val.b ? "-K" : "-k" ;
906 cmd[i++] = curconfig[Style].val.b ? "-M" : "-m" ;
907 cmd[i++] = curconfig[Inspector].val.b ? "-N" : "-n" ;
908 cmd[i++] = curconfig[Plugins].val.b ? "-P" : "-p" ;
909 if (scriptfile && g_strcmp0(scriptfile, "")) {
911 cmd[i++] = scriptfile;
913 cmd[i++] = curconfig[JavaScript].val.b ? "-S" : "-s";
914 cmd[i++] = curconfig[StrictTLS].val.b ? "-T" : "-t";
915 if (fulluseragent && g_strcmp0(fulluseragent, "")) {
917 cmd[i++] = fulluseragent;
921 /* do not keep zoom level */
931 spawn(Client *c, const Arg *a)
935 close(ConnectionNumber(dpy));
937 execvp(((char **)a->v)[0], (char **)a->v);
938 fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
945 destroyclient(Client *c)
949 webkit_web_view_stop_loading(c->view);
950 /* Not needed, has already been called
951 gtk_widget_destroy(c->win);
954 for (p = clients; p && p->next != c; p = p->next)
967 destroyclient(clients);
976 newview(Client *c, WebKitWebView *rv)
979 WebKitSettings *settings;
980 WebKitUserContentManager *contentmanager;
981 WebKitWebContext *context;
986 webkit_web_view_new_with_related_view(rv));
988 settings = webkit_settings_new_with_settings(
989 "auto-load-images", curconfig[LoadImages].val.b,
990 "default-font-size", curconfig[FontSize].val.i,
991 "enable-caret-browsing", curconfig[CaretBrowsing].val.b,
992 "enable-developer-extras", curconfig[Inspector].val.b,
993 "enable-dns-prefetching", curconfig[DNSPrefetch].val.b,
994 "enable-frame-flattening", curconfig[FrameFlattening].val.b,
995 "enable-html5-database", curconfig[DiskCache].val.b,
996 "enable-html5-local-storage", curconfig[DiskCache].val.b,
997 "enable-javascript", curconfig[JavaScript].val.b,
998 "enable-plugins", curconfig[Plugins].val.b,
999 "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.b,
1000 "enable-site-specific-quirks", curconfig[SiteQuirks].val.b,
1001 "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.b,
1003 /* For mor interesting settings, have a look at
1004 * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
1006 if (strcmp(fulluseragent, "")) {
1007 webkit_settings_set_user_agent(settings, fulluseragent);
1008 } else if (surfuseragent) {
1009 webkit_settings_set_user_agent_with_application_details(
1010 settings, "Surf", VERSION);
1012 useragent = webkit_settings_get_user_agent(settings);
1014 contentmanager = webkit_user_content_manager_new();
1016 context = webkit_web_context_new_with_website_data_manager(
1017 webkit_website_data_manager_new(
1018 "base-cache-directory", cachedir,
1019 "base-data-directory", cachedir,
1022 /* rendering process model, can be a shared unique one
1023 * or one for each view */
1024 webkit_web_context_set_process_model(context,
1025 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
1027 webkit_web_context_set_tls_errors_policy(context,
1028 curconfig[StrictTLS].val.b ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
1029 WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1031 webkit_web_context_set_cache_model(context,
1032 curconfig[DiskCache].val.b ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
1033 WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
1035 /* Currently only works with text file to be compatible with curl */
1036 webkit_cookie_manager_set_persistent_storage(
1037 webkit_web_context_get_cookie_manager(context), cookiefile,
1038 WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
1040 webkit_cookie_manager_set_accept_policy(
1041 webkit_web_context_get_cookie_manager(context),
1042 cookiepolicy_get());
1044 webkit_web_context_set_preferred_languages(context,
1045 curconfig[PreferredLanguages].val.v);
1046 webkit_web_context_set_spell_checking_languages(context,
1047 curconfig[SpellLanguages].val.v);
1048 webkit_web_context_set_spell_checking_enabled(context,
1049 curconfig[SpellChecking].val.b);
1051 g_signal_connect(G_OBJECT(context), "download-started",
1052 G_CALLBACK(downloadstarted), c);
1053 g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
1054 G_CALLBACK(initwebextensions), c);
1056 v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
1057 "settings", settings,
1058 "user-content-manager", contentmanager,
1059 "web-context", context,
1063 g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
1064 G_CALLBACK(progresschanged), c);
1065 g_signal_connect(G_OBJECT(v), "notify::title",
1066 G_CALLBACK(titlechanged), c);
1067 g_signal_connect(G_OBJECT(v), "button-release-event",
1068 G_CALLBACK(buttonreleased), c);
1069 g_signal_connect(G_OBJECT(v), "close",
1070 G_CALLBACK(closeview), c);
1071 g_signal_connect(G_OBJECT(v), "create",
1072 G_CALLBACK(createview), c);
1073 g_signal_connect(G_OBJECT(v), "decide-policy",
1074 G_CALLBACK(decidepolicy), c);
1075 g_signal_connect(G_OBJECT(v), "insecure-content-detected",
1076 G_CALLBACK(insecurecontent), c);
1077 g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
1078 G_CALLBACK(loadfailedtls), c);
1079 g_signal_connect(G_OBJECT(v), "load-changed",
1080 G_CALLBACK(loadchanged), c);
1081 g_signal_connect(G_OBJECT(v), "mouse-target-changed",
1082 G_CALLBACK(mousetargetchanged), c);
1083 g_signal_connect(G_OBJECT(v), "permission-request",
1084 G_CALLBACK(permissionrequested), c);
1085 g_signal_connect(G_OBJECT(v), "ready-to-show",
1086 G_CALLBACK(showview), c);
1092 initwebextensions(WebKitWebContext *wc, Client *c)
1094 webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
1098 createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
1102 switch (webkit_navigation_action_get_navigation_type(a)) {
1103 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1105 * popup windows of type “other” are almost always triggered
1106 * by user gesture, so inverse the logic here
1108 /* instead of this, compare destination uri to mouse-over uri for validating window */
1109 if (webkit_navigation_action_is_user_gesture(a))
1111 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1112 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1113 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1114 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1115 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1122 return GTK_WIDGET(n->view);
1126 buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
1128 WebKitHitTestResultContext element;
1131 element = webkit_hit_test_result_get_context(c->mousepos);
1133 for (i = 0; i < LENGTH(buttons); ++i) {
1134 if (element & buttons[i].target &&
1135 e->button.button == buttons[i].button &&
1136 CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
1138 buttons[i].func(c, &buttons[i].arg, c->mousepos);
1139 return buttons[i].stopevent;
1147 processx(GdkXEvent *e, GdkEvent *event, gpointer d)
1149 Client *c = (Client *)d;
1153 if (((XEvent *)e)->type == PropertyNotify) {
1154 ev = &((XEvent *)e)->xproperty;
1155 if (ev->state == PropertyNewValue) {
1156 if (ev->atom == atoms[AtomFind]) {
1159 return GDK_FILTER_REMOVE;
1160 } else if (ev->atom == atoms[AtomGo]) {
1161 a.v = getatom(c, AtomGo);
1164 return GDK_FILTER_REMOVE;
1168 return GDK_FILTER_CONTINUE;
1172 winevent(GtkWidget *w, GdkEvent *e, Client *c)
1177 case GDK_ENTER_NOTIFY:
1178 c->overtitle = c->targeturi;
1182 if (!curconfig[KioskMode].val.b) {
1183 for (i = 0; i < LENGTH(keys); ++i) {
1184 if (gdk_keyval_to_lower(e->key.keyval) ==
1186 CLEANMASK(e->key.state) == keys[i].mod &&
1189 keys[i].func(c, &(keys[i].arg));
1194 case GDK_LEAVE_NOTIFY:
1195 c->overtitle = NULL;
1198 case GDK_WINDOW_STATE:
1199 if (e->window_state.changed_mask ==
1200 GDK_WINDOW_STATE_FULLSCREEN)
1201 c->fullscreen = e->window_state.new_window_state &
1202 GDK_WINDOW_STATE_FULLSCREEN;
1212 showview(WebKitWebView *v, Client *c)
1214 GdkRGBA bgcolor = { 0 };
1217 c->finder = webkit_web_view_get_find_controller(c->view);
1218 c->inspector = webkit_web_view_get_inspector(c->view);
1220 c->win = createwindow(c);
1222 gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
1223 gtk_widget_show_all(c->win);
1224 gtk_widget_grab_focus(GTK_WIDGET(c->view));
1226 gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
1227 c->xid = gdk_x11_window_get_xid(gwin);
1230 gdk_display_sync(gtk_widget_get_display(c->win));
1234 if (curconfig[HideBackground].val.b)
1235 webkit_web_view_set_background_color(c->view, &bgcolor);
1237 if (!curconfig[KioskMode].val.b) {
1238 gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
1239 gdk_window_add_filter(gwin, processx, c);
1242 if (curconfig[RunInFullscreen].val.b)
1243 togglefullscreen(c, NULL);
1245 if (curconfig[ZoomLevel].val.f != 1.0)
1246 webkit_web_view_set_zoom_level(c->view,
1247 curconfig[ZoomLevel].val.f);
1249 setatom(c, AtomFind, "");
1250 setatom(c, AtomUri, "about:blank");
1254 createwindow(Client *c)
1260 w = gtk_plug_new(embed);
1262 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1264 wmstr = g_path_get_basename(argv0);
1265 gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
1268 wmstr = g_strdup_printf("%s[%lu]", "Surf",
1269 webkit_web_view_get_page_id(c->view));
1270 gtk_window_set_role(GTK_WINDOW(w), wmstr);
1273 gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
1276 g_signal_connect(G_OBJECT(w), "destroy",
1277 G_CALLBACK(destroywin), c);
1278 g_signal_connect(G_OBJECT(w), "enter-notify-event",
1279 G_CALLBACK(winevent), c);
1280 g_signal_connect(G_OBJECT(w), "key-press-event",
1281 G_CALLBACK(winevent), c);
1282 g_signal_connect(G_OBJECT(w), "leave-notify-event",
1283 G_CALLBACK(winevent), c);
1284 g_signal_connect(G_OBJECT(w), "window-state-event",
1285 G_CALLBACK(winevent), c);
1291 loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
1292 GTlsCertificateFlags err, Client *c)
1294 GString *errmsg = g_string_new(NULL);
1299 if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
1300 g_string_append(errmsg,
1301 "The signing certificate authority is not known.<br>");
1302 if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
1303 g_string_append(errmsg,
1304 "The certificate does not match the expected identity "
1305 "of the site that it was retrieved from.<br>");
1306 if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
1307 g_string_append(errmsg,
1308 "The certificate's activation time "
1309 "is still in the future.<br>");
1310 if (err & G_TLS_CERTIFICATE_EXPIRED)
1311 g_string_append(errmsg, "The certificate has expired.<br>");
1312 if (err & G_TLS_CERTIFICATE_REVOKED)
1313 g_string_append(errmsg,
1314 "The certificate has been revoked according to "
1315 "the GTlsConnection's certificate revocation list.<br>");
1316 if (err & G_TLS_CERTIFICATE_INSECURE)
1317 g_string_append(errmsg,
1318 "The certificate's algorithm is considered insecure.<br>");
1319 if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
1320 g_string_append(errmsg,
1321 "Some error occurred validating the certificate.<br>");
1323 g_object_get(cert, "certificate-pem", &pem, NULL);
1324 html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
1325 "<p><pre>%s</pre><p>", uri, errmsg->str, pem);
1327 g_string_free(errmsg, TRUE);
1329 webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
1336 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
1338 const char *title = geturi(c);
1341 case WEBKIT_LOAD_STARTED:
1342 curconfig = defconfig;
1343 setatom(c, AtomUri, title);
1345 c->https = c->insecure = 0;
1346 seturiparameters(c, geturi(c));
1348 case WEBKIT_LOAD_REDIRECTED:
1349 setatom(c, AtomUri, title);
1351 seturiparameters(c, geturi(c));
1353 case WEBKIT_LOAD_COMMITTED:
1354 c->https = webkit_web_view_get_tls_info(c->view, NULL,
1357 case WEBKIT_LOAD_FINISHED:
1358 /* Disabled until we write some WebKitWebExtension for
1359 * manipulating the DOM directly.
1360 evalscript(c, "document.documentElement.style.overflow = '%s'",
1361 enablescrollbars ? "auto" : "hidden");
1370 progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
1372 c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
1378 titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
1380 c->title = webkit_web_view_get_title(c->view);
1385 mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
1388 WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
1390 /* Keep the hit test to know where is the pointer on the next click */
1394 c->targeturi = webkit_hit_test_result_get_link_uri(h);
1395 else if (hc & OnImg)
1396 c->targeturi = webkit_hit_test_result_get_image_uri(h);
1397 else if (hc & OnMedia)
1398 c->targeturi = webkit_hit_test_result_get_media_uri(h);
1400 c->targeturi = NULL;
1402 c->overtitle = c->targeturi;
1407 permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
1409 if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
1410 if (curconfig[Geolocation].val.b)
1411 webkit_permission_request_allow(r);
1413 webkit_permission_request_deny(r);
1421 decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
1422 WebKitPolicyDecisionType dt, Client *c)
1425 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
1426 decidenavigation(d, c);
1428 case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
1429 decidenewwindow(d, c);
1431 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
1432 decideresource(d, c);
1435 webkit_policy_decision_ignore(d);
1442 decidenavigation(WebKitPolicyDecision *d, Client *c)
1444 WebKitNavigationAction *a =
1445 webkit_navigation_policy_decision_get_navigation_action(
1446 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1448 switch (webkit_navigation_action_get_navigation_type(a)) {
1449 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1450 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1451 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1452 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1453 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
1454 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1456 /* Do not navigate to links with a "_blank" target (popup) */
1457 if (webkit_navigation_policy_decision_get_frame_name(
1458 WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
1459 webkit_policy_decision_ignore(d);
1461 /* Filter out navigation to different domain ? */
1462 /* get action→urirequest, copy and load in new window+view
1463 * on Ctrl+Click ? */
1464 webkit_policy_decision_use(d);
1471 decidenewwindow(WebKitPolicyDecision *d, Client *c)
1474 WebKitNavigationAction *a =
1475 webkit_navigation_policy_decision_get_navigation_action(
1476 WEBKIT_NAVIGATION_POLICY_DECISION(d));
1479 switch (webkit_navigation_action_get_navigation_type(a)) {
1480 case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
1481 case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
1482 case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
1483 case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
1484 case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
1485 /* Filter domains here */
1486 /* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
1487 * test for link clicked but no button ? */
1488 arg.v = webkit_uri_request_get_uri(
1489 webkit_navigation_action_get_request(a));
1490 newwindow(c, &arg, 0);
1492 case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
1497 webkit_policy_decision_ignore(d);
1501 decideresource(WebKitPolicyDecision *d, Client *c)
1504 WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
1505 WebKitURIResponse *res =
1506 webkit_response_policy_decision_get_response(r);
1507 const gchar *uri = webkit_uri_response_get_uri(res);
1509 if (g_str_has_suffix(uri, "/favicon.ico")) {
1510 webkit_policy_decision_ignore(d);
1514 if (!g_str_has_prefix(uri, "http://")
1515 && !g_str_has_prefix(uri, "https://")
1516 && !g_str_has_prefix(uri, "about:")
1517 && !g_str_has_prefix(uri, "file://")
1518 && !g_str_has_prefix(uri, "data:")
1519 && !g_str_has_prefix(uri, "blob:")
1520 && strlen(uri) > 0) {
1521 for (i = 0; i < strlen(uri); i++) {
1522 if (!g_ascii_isprint(uri[i])) {
1528 handleplumb(c, uri);
1529 webkit_policy_decision_ignore(d);
1534 if (webkit_response_policy_decision_is_mime_type_supported(r)) {
1535 webkit_policy_decision_use(d);
1537 webkit_policy_decision_ignore(d);
1543 insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
1549 downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
1551 g_signal_connect(G_OBJECT(d), "notify::response",
1552 G_CALLBACK(responsereceived), c);
1556 responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
1558 download(c, webkit_download_get_response(d));
1559 webkit_download_cancel(d);
1563 download(Client *c, WebKitURIResponse *r)
1565 Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
1570 closeview(WebKitWebView *v, Client *c)
1572 gtk_widget_destroy(c->win);
1576 destroywin(GtkWidget* w, Client *c)
1584 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
1586 Arg a = {.v = text };
1588 loaduri((Client *) d, &a);
1592 reload(Client *c, const Arg *a)
1595 webkit_web_view_reload_bypass_cache(c->view);
1597 webkit_web_view_reload(c->view);
1601 print(Client *c, const Arg *a)
1603 webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
1604 GTK_WINDOW(c->win));
1608 clipboard(Client *c, const Arg *a)
1610 if (a->b) { /* load clipboard uri */
1611 gtk_clipboard_request_text(gtk_clipboard_get(
1612 GDK_SELECTION_PRIMARY),
1614 } else { /* copy uri */
1615 gtk_clipboard_set_text(gtk_clipboard_get(
1616 GDK_SELECTION_PRIMARY), c->targeturi
1617 ? c->targeturi : geturi(c), -1);
1622 zoom(Client *c, const Arg *a)
1625 webkit_web_view_set_zoom_level(c->view,
1626 curconfig[ZoomLevel].val.f + 0.1);
1628 webkit_web_view_set_zoom_level(c->view,
1629 curconfig[ZoomLevel].val.f - 0.1);
1631 webkit_web_view_set_zoom_level(c->view, 1.0);
1633 curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
1637 scroll(Client *c, const Arg *a)
1639 GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
1641 gdk_event_set_device(ev, gdkkb);
1642 ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
1643 ev->key.state = GDK_CONTROL_MASK;
1644 ev->key.time = GDK_CURRENT_TIME;
1648 ev->key.keyval = GDK_KEY_Down;
1651 ev->key.keyval = GDK_KEY_Page_Down;
1654 ev->key.keyval = GDK_KEY_Left;
1657 ev->key.keyval = GDK_KEY_Right;
1660 ev->key.keyval = GDK_KEY_Page_Up;
1663 ev->key.keyval = GDK_KEY_Up;
1671 navigate(Client *c, const Arg *a)
1674 webkit_web_view_go_back(c->view);
1676 webkit_web_view_go_forward(c->view);
1680 stop(Client *c, const Arg *a)
1682 webkit_web_view_stop_loading(c->view);
1686 toggle(Client *c, const Arg *a)
1688 curconfig[a->i].val.b ^= 1;
1689 setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
1693 togglefullscreen(Client *c, const Arg *a)
1695 /* toggling value is handled in winevent() */
1697 gtk_window_unfullscreen(GTK_WINDOW(c->win));
1699 gtk_window_fullscreen(GTK_WINDOW(c->win));
1703 togglecookiepolicy(Client *c, const Arg *a)
1706 cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
1708 setparameter(c, 0, CookiePolicies, NULL);
1712 toggleinspector(Client *c, const Arg *a)
1714 if (webkit_web_inspector_is_attached(c->inspector))
1715 webkit_web_inspector_close(c->inspector);
1716 else if (curconfig[Inspector].val.b)
1717 webkit_web_inspector_show(c->inspector);
1721 find(Client *c, const Arg *a)
1727 webkit_find_controller_search_next(c->finder);
1729 webkit_find_controller_search_previous(c->finder);
1731 s = getatom(c, AtomFind);
1732 f = webkit_find_controller_get_search_text(c->finder);
1734 if (g_strcmp0(f, s) == 0) /* reset search */
1735 webkit_find_controller_search(c->finder, "", findopts,
1738 webkit_find_controller_search(c->finder, s, findopts,
1741 if (strcmp(s, "") == 0)
1742 webkit_find_controller_search_finish(c->finder);
1747 clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
1753 clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
1757 arg.v = webkit_hit_test_result_get_link_uri(h);
1758 newwindow(c, &arg, a->b);
1762 clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
1766 arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
1771 main(int argc, char *argv[])
1776 memset(&arg, 0, sizeof(arg));
1778 /* command line args */
1781 defconfig CSETV(CookiePolicies, EARGF(usage()));
1784 defconfig CSETB(ScrollBars, 0);
1787 defconfig CSETB(ScrollBars, 1);
1790 cookiefile = EARGF(usage());
1793 stylefile = EARGF(usage());
1796 defconfig CSETB(DiskCache, 0);
1799 defconfig CSETB(DiskCache, 1);
1802 embed = strtol(EARGF(usage()), NULL, 0);
1805 defconfig CSETB(RunInFullscreen, 0);
1808 defconfig CSETB(RunInFullscreen, 1);
1811 defconfig CSETB(Geolocation, 0);
1814 defconfig CSETB(Geolocation, 1);
1817 defconfig CSETB(LoadImages, 0);
1820 defconfig CSETB(LoadImages, 1);
1823 defconfig CSETB(KioskMode, 0);
1826 defconfig CSETB(KioskMode, 1);
1829 defconfig CSETB(Style, 0);
1832 defconfig CSETB(Style, 1);
1835 defconfig CSETB(Inspector, 0);
1838 defconfig CSETB(Inspector, 1);
1841 defconfig CSETB(Plugins, 0);
1844 defconfig CSETB(Plugins, 1);
1847 scriptfile = EARGF(usage());
1850 defconfig CSETB(JavaScript, 0);
1853 defconfig CSETB(JavaScript, 1);
1856 defconfig CSETB(StrictTLS, 0);
1859 defconfig CSETB(StrictTLS, 1);
1862 fulluseragent = EARGF(usage());
1865 die("surf-"VERSION", ©2009-2017 surf engineers, "
1866 "see LICENSE for details\n");
1871 defconfig CSETF(ZoomLevel, strtof(EARGF(usage()), NULL));
1879 arg.v = "about:blank";
1882 c = newclient(NULL);