2009-06-05 18:16:10 +00:00
|
|
|
/* See LICENSE file for copyright and license details.
|
|
|
|
*
|
|
|
|
* To understand surf, start reading main().
|
|
|
|
*/
|
2015-11-21 18:22:11 +00:00
|
|
|
#include <sys/file.h>
|
2009-10-15 14:31:49 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2017-04-29 12:56:02 +00:00
|
|
|
#include <glib.h>
|
2015-11-21 18:22:11 +00:00
|
|
|
#include <libgen.h>
|
2012-11-25 21:31:46 +00:00
|
|
|
#include <limits.h>
|
2015-11-21 18:22:11 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
2009-06-05 11:22:40 +00:00
|
|
|
#include <stdio.h>
|
2015-11-21 18:22:11 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gdk/gdkx.h>
|
2009-06-07 10:50:18 +00:00
|
|
|
#include <glib/gstdio.h>
|
2015-11-21 18:22:11 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gtk/gtkx.h>
|
2017-04-29 12:49:04 +00:00
|
|
|
#include <gcr/gcr.h>
|
2009-09-16 08:06:21 +00:00
|
|
|
#include <JavaScriptCore/JavaScript.h>
|
2015-11-21 18:22:11 +00:00
|
|
|
#include <webkit2/webkit2.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xatom.h>
|
2009-06-05 11:22:40 +00:00
|
|
|
|
2012-10-31 20:13:50 +00:00
|
|
|
#include "arg.h"
|
|
|
|
|
2015-10-18 20:52:16 +00:00
|
|
|
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
2014-02-07 01:17:43 +00:00
|
|
|
#define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
|
2015-11-29 23:39:52 +00:00
|
|
|
#define SETB(p, s) [p] = { { .b = s }, }
|
|
|
|
#define SETI(p, s) [p] = { { .i = s }, }
|
|
|
|
#define SETV(p, s) [p] = { { .v = s }, }
|
|
|
|
#define SETF(p, s) [p] = { { .f = s }, }
|
|
|
|
#define FSETB(p, s) [p] = { { .b = s }, 1 }
|
|
|
|
#define FSETI(p, s) [p] = { { .i = s }, 1 }
|
|
|
|
#define FSETV(p, s) [p] = { { .v = s }, 1 }
|
|
|
|
#define FSETF(p, s) [p] = { { .f = s }, 1 }
|
|
|
|
#define CSETB(p, s) [p] = (Parameter){ { .b = s }, 1 }
|
|
|
|
#define CSETI(p, s) [p] = (Parameter){ { .i = s }, 1 }
|
|
|
|
#define CSETV(p, s) [p] = (Parameter){ { .v = s }, 1 }
|
|
|
|
#define CSETF(p, s) [p] = (Parameter){ { .f = s }, 1 }
|
2009-06-05 11:22:40 +00:00
|
|
|
|
2010-05-28 11:20:17 +00:00
|
|
|
enum { AtomFind, AtomGo, AtomUri, AtomLast };
|
2015-11-18 16:53:33 +00:00
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
enum {
|
|
|
|
OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
|
|
|
|
OnLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
|
|
|
|
OnImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
|
|
|
|
OnMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
|
|
|
|
OnEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
|
|
|
|
OnBar = WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR,
|
|
|
|
OnSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
|
|
|
|
OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
|
|
|
|
};
|
|
|
|
|
2015-11-29 16:16:48 +00:00
|
|
|
typedef enum {
|
2016-07-05 15:26:54 +00:00
|
|
|
AcceleratedCanvas,
|
2017-05-18 09:20:07 +00:00
|
|
|
AccessMicrophone,
|
|
|
|
AccessWebcam,
|
2015-11-21 18:14:08 +00:00
|
|
|
CaretBrowsing,
|
2017-04-28 10:58:36 +00:00
|
|
|
Certificate,
|
2015-11-29 16:16:48 +00:00
|
|
|
CookiePolicies,
|
|
|
|
DiskCache,
|
2017-05-11 13:23:22 +00:00
|
|
|
DefaultCharset,
|
2015-11-29 16:16:48 +00:00
|
|
|
DNSPrefetch,
|
2017-05-18 11:46:49 +00:00
|
|
|
FileURLsCrossAccess,
|
2015-11-29 16:16:48 +00:00
|
|
|
FontSize,
|
2015-11-21 18:14:08 +00:00
|
|
|
FrameFlattening,
|
|
|
|
Geolocation,
|
2015-11-29 16:16:48 +00:00
|
|
|
HideBackground,
|
|
|
|
Inspector,
|
2017-05-11 13:27:27 +00:00
|
|
|
Java,
|
2015-11-21 18:14:08 +00:00
|
|
|
JavaScript,
|
2015-11-29 16:16:48 +00:00
|
|
|
KioskMode,
|
2015-11-21 18:14:08 +00:00
|
|
|
LoadImages,
|
2016-07-05 15:26:54 +00:00
|
|
|
MediaManualPlay,
|
2015-11-21 18:14:08 +00:00
|
|
|
Plugins,
|
2015-11-29 16:16:48 +00:00
|
|
|
PreferredLanguages,
|
|
|
|
RunInFullscreen,
|
2015-11-21 18:14:08 +00:00
|
|
|
ScrollBars,
|
2015-11-29 16:16:48 +00:00
|
|
|
ShowIndicators,
|
2016-07-05 15:26:54 +00:00
|
|
|
SiteQuirks,
|
2017-05-11 13:33:42 +00:00
|
|
|
SmoothScrolling,
|
2015-11-29 16:16:48 +00:00
|
|
|
SpellChecking,
|
|
|
|
SpellLanguages,
|
2017-04-19 15:45:20 +00:00
|
|
|
StrictTLS,
|
2015-11-29 16:16:48 +00:00
|
|
|
Style,
|
|
|
|
ZoomLevel,
|
2017-05-18 23:10:30 +00:00
|
|
|
ParameterLast
|
2015-11-29 16:16:48 +00:00
|
|
|
} ParamName;
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
typedef union {
|
2015-11-22 01:03:26 +00:00
|
|
|
int b;
|
|
|
|
int i;
|
2015-11-29 16:16:48 +00:00
|
|
|
float f;
|
2009-09-06 11:40:41 +00:00
|
|
|
const void *v;
|
2015-11-21 18:14:08 +00:00
|
|
|
} Arg;
|
2009-09-06 11:40:41 +00:00
|
|
|
|
2015-11-29 16:16:48 +00:00
|
|
|
typedef struct {
|
|
|
|
Arg val;
|
|
|
|
int force;
|
|
|
|
} Parameter;
|
|
|
|
|
2009-06-05 18:16:10 +00:00
|
|
|
typedef struct Client {
|
2015-11-18 14:23:42 +00:00
|
|
|
GtkWidget *win;
|
2009-06-05 18:16:10 +00:00
|
|
|
WebKitWebView *view;
|
2013-01-26 14:53:33 +00:00
|
|
|
WebKitWebInspector *inspector;
|
2015-11-20 00:12:28 +00:00
|
|
|
WebKitFindController *finder;
|
2015-11-18 16:59:50 +00:00
|
|
|
WebKitHitTestResult *mousepos;
|
2017-04-29 12:56:02 +00:00
|
|
|
GTlsCertificate *cert, *failedcert;
|
2016-07-08 16:27:07 +00:00
|
|
|
GTlsCertificateFlags tlserr;
|
2015-11-21 18:14:08 +00:00
|
|
|
Window xid;
|
2017-04-29 12:56:02 +00:00
|
|
|
int progress, fullscreen, https, insecure, errorpage;
|
2015-11-22 15:45:22 +00:00
|
|
|
const char *title, *overtitle, *targeturi;
|
2013-09-10 12:45:18 +00:00
|
|
|
const char *needle;
|
2009-06-05 18:16:10 +00:00
|
|
|
struct Client *next;
|
|
|
|
} Client;
|
2009-09-06 11:15:53 +00:00
|
|
|
|
2009-09-06 11:40:41 +00:00
|
|
|
typedef struct {
|
|
|
|
guint mod;
|
|
|
|
guint keyval;
|
2015-11-21 18:14:08 +00:00
|
|
|
void (*func)(Client *c, const Arg *a);
|
2009-09-06 11:40:41 +00:00
|
|
|
const Arg arg;
|
|
|
|
} Key;
|
|
|
|
|
2015-01-28 20:01:55 +00:00
|
|
|
typedef struct {
|
2015-11-19 12:19:27 +00:00
|
|
|
unsigned int target;
|
2015-01-28 20:01:55 +00:00
|
|
|
unsigned int mask;
|
|
|
|
guint button;
|
2015-11-19 12:19:27 +00:00
|
|
|
void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
|
2015-01-28 20:01:55 +00:00
|
|
|
const Arg arg;
|
2015-11-19 12:19:27 +00:00
|
|
|
unsigned int stopevent;
|
2015-01-28 20:01:55 +00:00
|
|
|
} Button;
|
|
|
|
|
2015-11-29 16:16:48 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *uri;
|
|
|
|
Parameter config[ParameterLast];
|
|
|
|
regex_t re;
|
|
|
|
} UriParameters;
|
|
|
|
|
2015-01-17 06:19:48 +00:00
|
|
|
typedef struct {
|
|
|
|
char *regex;
|
2017-04-27 13:01:54 +00:00
|
|
|
char *file;
|
2015-01-17 06:19:48 +00:00
|
|
|
regex_t re;
|
2017-04-27 13:01:54 +00:00
|
|
|
} SiteSpecific;
|
2015-01-17 06:19:48 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
/* Surf */
|
|
|
|
static void usage(void);
|
|
|
|
static void die(const char *errstr, ...);
|
|
|
|
static void setup(void);
|
|
|
|
static void sigchld(int unused);
|
2016-01-09 19:18:53 +00:00
|
|
|
static void sighup(int unused);
|
2015-10-13 19:39:01 +00:00
|
|
|
static char *buildfile(const char *path);
|
2009-10-16 14:33:18 +00:00
|
|
|
static char *buildpath(const char *path);
|
2016-06-03 13:14:53 +00:00
|
|
|
static const char *getuserhomedir(const char *user);
|
|
|
|
static const char *getcurrentuserhomedir(void);
|
2015-11-21 18:14:08 +00:00
|
|
|
static Client *newclient(Client *c);
|
|
|
|
static void loaduri(Client *c, const Arg *a);
|
2015-11-22 00:52:13 +00:00
|
|
|
static const char *geturi(Client *c);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void setatom(Client *c, int a, const char *v);
|
|
|
|
static const char *getatom(Client *c, int a);
|
|
|
|
static void updatetitle(Client *c);
|
|
|
|
static void gettogglestats(Client *c);
|
|
|
|
static void getpagestats(Client *c);
|
2015-11-18 13:48:49 +00:00
|
|
|
static WebKitCookieAcceptPolicy cookiepolicy_get(void);
|
|
|
|
static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
|
2017-05-18 23:10:30 +00:00
|
|
|
static void seturiparameters(Client *c, const char *uri, ParamName *params);
|
2015-11-29 16:42:42 +00:00
|
|
|
static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
|
2017-04-28 10:58:36 +00:00
|
|
|
static const char *getcert(const char *uri);
|
|
|
|
static void setcert(Client *c, const char *file);
|
2015-11-22 00:52:13 +00:00
|
|
|
static const char *getstyle(const char *uri);
|
2017-04-27 13:41:16 +00:00
|
|
|
static void setstyle(Client *c, const char *file);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void runscript(Client *c);
|
|
|
|
static void evalscript(Client *c, const char *jsstr, ...);
|
|
|
|
static void updatewinid(Client *c);
|
2015-11-22 00:52:13 +00:00
|
|
|
static void handleplumb(Client *c, const char *uri);
|
2015-11-22 01:03:26 +00:00
|
|
|
static void newwindow(Client *c, const Arg *a, int noembed);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void spawn(Client *c, const Arg *a);
|
|
|
|
static void destroyclient(Client *c);
|
|
|
|
static void cleanup(void);
|
2013-01-26 14:53:33 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
/* GTK/WebKit */
|
|
|
|
static WebKitWebView *newview(Client *c, WebKitWebView *rv);
|
2015-11-23 21:12:00 +00:00
|
|
|
static void initwebextensions(WebKitWebContext *wc, Client *c);
|
2015-11-18 17:16:06 +00:00
|
|
|
static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
|
2015-11-22 00:42:34 +00:00
|
|
|
Client *c);
|
2015-11-22 01:10:18 +00:00
|
|
|
static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
|
2015-11-21 18:14:08 +00:00
|
|
|
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
|
|
|
|
gpointer d);
|
|
|
|
static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
|
|
|
|
static void showview(WebKitWebView *v, Client *c);
|
|
|
|
static GtkWidget *createwindow(Client *c);
|
2017-04-29 12:49:04 +00:00
|
|
|
static gboolean loadfailedtls(WebKitWebView *v, gchar *uri,
|
|
|
|
GTlsCertificate *cert,
|
|
|
|
GTlsCertificateFlags err, Client *c);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c);
|
|
|
|
static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c);
|
|
|
|
static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c);
|
|
|
|
static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
|
2015-11-22 00:42:34 +00:00
|
|
|
guint modifiers, Client *c);
|
2015-11-21 18:14:08 +00:00
|
|
|
static gboolean permissionrequested(WebKitWebView *v,
|
2015-11-22 00:42:34 +00:00
|
|
|
WebKitPermissionRequest *r, Client *c);
|
2015-11-18 17:30:28 +00:00
|
|
|
static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
|
2015-11-22 00:42:34 +00:00
|
|
|
WebKitPolicyDecisionType dt, Client *c);
|
2015-11-18 17:30:28 +00:00
|
|
|
static void decidenavigation(WebKitPolicyDecision *d, Client *c);
|
|
|
|
static void decidenewwindow(WebKitPolicyDecision *d, Client *c);
|
|
|
|
static void decideresource(WebKitPolicyDecision *d, Client *c);
|
2016-07-08 16:27:07 +00:00
|
|
|
static void insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e,
|
|
|
|
Client *c);
|
2015-11-18 18:05:59 +00:00
|
|
|
static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
|
2015-11-22 00:42:34 +00:00
|
|
|
Client *c);
|
2015-11-18 18:05:59 +00:00
|
|
|
static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
|
|
|
|
static void download(Client *c, WebKitURIResponse *r);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void closeview(WebKitWebView *v, Client *c);
|
|
|
|
static void destroywin(GtkWidget* w, Client *c);
|
2013-01-26 14:53:33 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
/* Hotkeys */
|
2009-10-16 14:33:18 +00:00
|
|
|
static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
|
2015-11-22 00:42:34 +00:00
|
|
|
static void reload(Client *c, const Arg *a);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void print(Client *c, const Arg *a);
|
2017-04-29 12:56:02 +00:00
|
|
|
static void showcert(Client *c, const Arg *a);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void clipboard(Client *c, const Arg *a);
|
|
|
|
static void zoom(Client *c, const Arg *a);
|
2016-03-02 13:29:21 +00:00
|
|
|
static void scroll(Client *c, const Arg *a);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void navigate(Client *c, const Arg *a);
|
2015-11-22 00:42:34 +00:00
|
|
|
static void stop(Client *c, const Arg *a);
|
2015-11-20 14:48:04 +00:00
|
|
|
static void toggle(Client *c, const Arg *a);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void togglefullscreen(Client *c, const Arg *a);
|
2015-11-22 00:42:34 +00:00
|
|
|
static void togglecookiepolicy(Client *c, const Arg *a);
|
2015-11-21 18:14:08 +00:00
|
|
|
static void toggleinspector(Client *c, const Arg *a);
|
|
|
|
static void find(Client *c, const Arg *a);
|
|
|
|
|
|
|
|
/* Buttons */
|
|
|
|
static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
|
|
|
|
static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
|
2015-11-21 18:53:29 +00:00
|
|
|
static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
static char winid[64];
|
2017-04-29 15:21:12 +00:00
|
|
|
static char togglestats[12];
|
2015-11-21 18:14:08 +00:00
|
|
|
static char pagestats[2];
|
|
|
|
static Atom atoms[AtomLast];
|
|
|
|
static Window embed;
|
2015-11-22 01:03:26 +00:00
|
|
|
static int showxid;
|
2015-11-21 18:14:08 +00:00
|
|
|
static int cookiepolicy;
|
|
|
|
static Display *dpy;
|
|
|
|
static Client *clients;
|
2016-03-02 13:29:21 +00:00
|
|
|
static GdkDevice *gdkkb;
|
2015-11-21 18:14:08 +00:00
|
|
|
static char *stylefile;
|
|
|
|
static const char *useragent;
|
2015-11-29 16:42:42 +00:00
|
|
|
static Parameter *curconfig;
|
2015-11-21 18:14:08 +00:00
|
|
|
char *argv0;
|
2009-09-06 11:40:41 +00:00
|
|
|
|
2017-05-18 23:10:30 +00:00
|
|
|
static ParamName loadtransient[] = {
|
|
|
|
Certificate,
|
|
|
|
CookiePolicies,
|
|
|
|
DiskCache,
|
|
|
|
DNSPrefetch,
|
|
|
|
FileURLsCrossAccess,
|
|
|
|
JavaScript,
|
|
|
|
LoadImages,
|
|
|
|
PreferredLanguages,
|
|
|
|
ShowIndicators,
|
|
|
|
StrictTLS,
|
|
|
|
ParameterLast
|
|
|
|
};
|
|
|
|
|
|
|
|
static ParamName loadcommitted[] = {
|
|
|
|
AcceleratedCanvas,
|
|
|
|
// AccessMicrophone,
|
|
|
|
// AccessWebcam,
|
|
|
|
CaretBrowsing,
|
|
|
|
DefaultCharset,
|
|
|
|
FontSize,
|
|
|
|
FrameFlattening,
|
|
|
|
Geolocation,
|
|
|
|
HideBackground,
|
|
|
|
Inspector,
|
|
|
|
Java,
|
|
|
|
// KioskMode,
|
|
|
|
MediaManualPlay,
|
|
|
|
Plugins,
|
|
|
|
RunInFullscreen,
|
|
|
|
ScrollBars,
|
|
|
|
SiteQuirks,
|
|
|
|
SmoothScrolling,
|
|
|
|
SpellChecking,
|
|
|
|
SpellLanguages,
|
|
|
|
Style,
|
|
|
|
ZoomLevel,
|
|
|
|
ParameterLast
|
|
|
|
};
|
|
|
|
|
|
|
|
static ParamName loadfinished[] = {
|
|
|
|
ParameterLast
|
|
|
|
};
|
|
|
|
|
2009-09-21 17:28:39 +00:00
|
|
|
/* configuration, allows nested code to access above variables */
|
2009-09-06 11:40:41 +00:00
|
|
|
#include "config.h"
|
2009-06-06 18:26:04 +00:00
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
usage(void)
|
|
|
|
{
|
2017-05-04 08:22:29 +00:00
|
|
|
die("usage: surf [-bBdDfFgGiIkKmMnNpPsStTvwxX]\n"
|
|
|
|
"[-a cookiepolicies ] [-c cookiefile] [-C stylefile] [-e xid]\n"
|
|
|
|
"[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
die(const char *errstr, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, errstr);
|
|
|
|
vfprintf(stderr, errstr, ap);
|
|
|
|
va_end(ap);
|
2015-11-22 11:17:05 +00:00
|
|
|
exit(1);
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setup(void)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2016-07-05 11:35:44 +00:00
|
|
|
GdkDisplay *gdpy;
|
2015-11-29 16:42:42 +00:00
|
|
|
int i, j;
|
2013-03-15 17:37:12 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
/* clean up any zombies immediately */
|
|
|
|
sigchld(0);
|
2016-01-09 19:18:53 +00:00
|
|
|
if (signal(SIGHUP, sighup) == SIG_ERR)
|
|
|
|
die("Can't install SIGHUP handler");
|
|
|
|
|
2017-02-12 17:50:31 +00:00
|
|
|
if (!(dpy = XOpenDisplay(NULL)))
|
|
|
|
die("Can't open default display");
|
2015-11-29 16:42:42 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
/* atoms */
|
|
|
|
atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
|
|
|
|
atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
|
|
|
|
atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
|
|
|
|
|
2017-02-12 17:50:31 +00:00
|
|
|
gtk_init(NULL, NULL);
|
|
|
|
|
|
|
|
gdpy = gdk_display_get_default();
|
|
|
|
|
|
|
|
curconfig = defconfig;
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
/* dirs and files */
|
|
|
|
cookiefile = buildfile(cookiefile);
|
|
|
|
scriptfile = buildfile(scriptfile);
|
|
|
|
cachedir = buildpath(cachedir);
|
2017-04-28 10:58:36 +00:00
|
|
|
certdir = buildpath(certdir);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2016-07-05 10:33:23 +00:00
|
|
|
gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
|
2016-03-02 13:29:21 +00:00
|
|
|
|
2017-04-28 10:58:36 +00:00
|
|
|
for (i = 0; i < LENGTH(certs); ++i) {
|
2017-04-28 11:09:39 +00:00
|
|
|
if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
|
|
|
|
certs[i].file = g_strconcat(certdir, "/", certs[i].file,
|
|
|
|
NULL);
|
|
|
|
} else {
|
2017-04-28 10:58:36 +00:00
|
|
|
fprintf(stderr, "Could not compile regex: %s\n",
|
|
|
|
certs[i].regex);
|
|
|
|
certs[i].regex = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
if (!stylefile) {
|
2015-11-21 18:14:08 +00:00
|
|
|
styledir = buildpath(styledir);
|
2015-11-22 00:42:34 +00:00
|
|
|
for (i = 0; i < LENGTH(styles); ++i) {
|
2017-04-28 11:09:39 +00:00
|
|
|
if (!regcomp(&(styles[i].re), styles[i].regex,
|
2015-11-21 18:14:08 +00:00
|
|
|
REG_EXTENDED)) {
|
2017-04-28 11:09:39 +00:00
|
|
|
styles[i].file = g_strconcat(styledir, "/",
|
|
|
|
styles[i].file, NULL);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Could not compile regex: %s\n",
|
2015-11-21 18:14:08 +00:00
|
|
|
styles[i].regex);
|
|
|
|
styles[i].regex = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(styledir);
|
|
|
|
} else {
|
|
|
|
stylefile = buildfile(stylefile);
|
2013-03-15 15:12:15 +00:00
|
|
|
}
|
2015-11-29 16:42:42 +00:00
|
|
|
|
|
|
|
for (i = 0; i < LENGTH(uriparams); ++i) {
|
|
|
|
if (!regcomp(&(uriparams[i].re), uriparams[i].uri,
|
|
|
|
REG_EXTENDED)) {
|
|
|
|
/* copy default parameters if they are not already set
|
|
|
|
* or if they are forced */
|
|
|
|
for (j = 0; j < ParameterLast; ++j) {
|
|
|
|
if (!uriparams[i].config[j].force ||
|
|
|
|
defconfig[j].force)
|
|
|
|
uriparams[i].config[j] = defconfig[j];
|
|
|
|
}
|
|
|
|
} else {
|
2017-04-28 11:09:39 +00:00
|
|
|
fprintf(stderr, "Could not compile regex: %s\n",
|
2015-11-29 16:42:42 +00:00
|
|
|
uriparams[i].uri);
|
|
|
|
uriparams[i].uri = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sigchld(int unused)
|
|
|
|
{
|
|
|
|
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
|
|
|
die("Can't install SIGCHLD handler");
|
2015-11-22 11:22:23 +00:00
|
|
|
while (waitpid(-1, NULL, WNOHANG) > 0)
|
|
|
|
;
|
2013-03-15 15:12:15 +00:00
|
|
|
}
|
|
|
|
|
2016-01-09 19:18:53 +00:00
|
|
|
void
|
|
|
|
sighup(int unused)
|
|
|
|
{
|
|
|
|
Arg a = { .b = 0 };
|
|
|
|
Client *c;
|
|
|
|
|
|
|
|
for (c = clients; c; c = c->next)
|
|
|
|
reload(c, &a);
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
char *
|
|
|
|
buildfile(const char *path)
|
|
|
|
{
|
2015-10-13 19:39:01 +00:00
|
|
|
char *dname, *bname, *bpath, *fpath;
|
2009-10-13 19:52:43 +00:00
|
|
|
FILE *f;
|
|
|
|
|
2015-10-13 19:39:01 +00:00
|
|
|
dname = g_path_get_dirname(path);
|
|
|
|
bname = g_path_get_basename(path);
|
|
|
|
|
|
|
|
bpath = buildpath(dname);
|
|
|
|
g_free(dname);
|
|
|
|
|
|
|
|
fpath = g_build_filename(bpath, bname, NULL);
|
2015-11-04 14:42:42 +00:00
|
|
|
g_free(bpath);
|
2015-10-13 19:39:01 +00:00
|
|
|
g_free(bname);
|
|
|
|
|
2015-10-18 20:52:16 +00:00
|
|
|
if (!(f = fopen(fpath, "a")))
|
2015-10-13 19:39:01 +00:00
|
|
|
die("Could not open file: %s\n", fpath);
|
|
|
|
|
|
|
|
g_chmod(fpath, 0600); /* always */
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return fpath;
|
|
|
|
}
|
|
|
|
|
2016-05-29 09:56:51 +00:00
|
|
|
static const char*
|
2016-06-03 13:14:53 +00:00
|
|
|
getuserhomedir(const char *user)
|
|
|
|
{
|
2016-05-29 09:56:51 +00:00
|
|
|
struct passwd *pw = getpwnam(user);
|
2016-06-03 13:14:53 +00:00
|
|
|
|
|
|
|
if (!pw)
|
|
|
|
die("Can't get user %s login information.\n", user);
|
|
|
|
|
2016-05-29 09:56:51 +00:00
|
|
|
return pw->pw_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
2016-06-03 13:14:53 +00:00
|
|
|
getcurrentuserhomedir(void)
|
|
|
|
{
|
2016-05-29 09:56:51 +00:00
|
|
|
const char *homedir;
|
|
|
|
const char *user;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
homedir = getenv("HOME");
|
2016-06-03 13:14:53 +00:00
|
|
|
if (homedir)
|
2016-05-29 09:56:51 +00:00
|
|
|
return homedir;
|
|
|
|
|
|
|
|
user = getenv("USER");
|
2016-06-03 13:14:53 +00:00
|
|
|
if (user)
|
|
|
|
return getuserhomedir(user);
|
2016-05-29 09:56:51 +00:00
|
|
|
|
|
|
|
pw = getpwuid(getuid());
|
2016-06-03 13:14:53 +00:00
|
|
|
if (!pw)
|
2016-05-29 09:56:51 +00:00
|
|
|
die("Can't get current user home directory\n");
|
2016-06-03 13:14:53 +00:00
|
|
|
|
2016-05-29 09:56:51 +00:00
|
|
|
return pw->pw_dir;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
char *
|
|
|
|
buildpath(const char *path)
|
|
|
|
{
|
2015-10-13 19:39:01 +00:00
|
|
|
char *apath, *name, *p, *fpath;
|
2016-06-03 13:14:53 +00:00
|
|
|
const char *homedir;
|
2015-10-13 19:39:01 +00:00
|
|
|
|
2015-10-18 20:52:16 +00:00
|
|
|
if (path[0] == '~') {
|
|
|
|
if (path[1] == '/' || path[1] == '\0') {
|
2015-10-13 19:39:01 +00:00
|
|
|
p = (char *)&path[1];
|
2016-06-03 13:14:53 +00:00
|
|
|
homedir = getcurrentuserhomedir();
|
2012-10-31 20:13:50 +00:00
|
|
|
} else {
|
2015-10-18 20:52:16 +00:00
|
|
|
if ((p = strchr(path, '/')))
|
2015-10-13 19:39:01 +00:00
|
|
|
name = g_strndup(&path[1], --p - path);
|
|
|
|
else
|
|
|
|
name = g_strdup(&path[1]);
|
|
|
|
|
2016-06-03 13:14:53 +00:00
|
|
|
homedir = getuserhomedir(name);
|
2015-10-13 19:39:01 +00:00
|
|
|
g_free(name);
|
2012-10-31 20:13:50 +00:00
|
|
|
}
|
2016-05-29 09:56:51 +00:00
|
|
|
apath = g_build_filename(homedir, p, NULL);
|
2012-10-31 20:13:50 +00:00
|
|
|
} else {
|
2015-10-13 19:39:01 +00:00
|
|
|
apath = g_strdup(path);
|
2012-10-31 20:13:50 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 19:39:01 +00:00
|
|
|
/* creating directory */
|
2015-10-18 20:52:16 +00:00
|
|
|
if (g_mkdir_with_parents(apath, 0700) < 0)
|
2015-10-13 19:39:01 +00:00
|
|
|
die("Could not access directory: %s\n", apath);
|
|
|
|
|
|
|
|
fpath = realpath(apath, NULL);
|
|
|
|
g_free(apath);
|
2012-10-31 20:13:50 +00:00
|
|
|
|
2015-10-13 19:39:01 +00:00
|
|
|
return fpath;
|
2009-10-13 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
Client *
|
|
|
|
newclient(Client *rc)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
Client *c;
|
2015-11-19 12:19:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
if (!(c = calloc(1, sizeof(Client))))
|
|
|
|
die("Cannot malloc!\n");
|
2015-11-19 12:19:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
c->next = clients;
|
|
|
|
clients = c;
|
|
|
|
|
2015-11-22 12:24:24 +00:00
|
|
|
c->progress = 100;
|
|
|
|
c->view = newview(c, rc ? rc->view : NULL);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
return c;
|
2012-10-13 05:16:08 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
loaduri(Client *c, const Arg *a)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *url, *path;
|
2015-11-22 00:42:34 +00:00
|
|
|
const char *uri = a->v;
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
if (g_strcmp0(uri, "") == 0)
|
|
|
|
return;
|
|
|
|
|
2016-04-16 04:19:13 +00:00
|
|
|
if (g_str_has_prefix(uri, "http://") ||
|
|
|
|
g_str_has_prefix(uri, "https://") ||
|
|
|
|
g_str_has_prefix(uri, "file://") ||
|
|
|
|
g_str_has_prefix(uri, "about:")) {
|
2015-11-21 18:14:08 +00:00
|
|
|
url = g_strdup(uri);
|
|
|
|
} else if (!stat(uri, &st) && (path = realpath(uri, NULL))) {
|
|
|
|
url = g_strdup_printf("file://%s", path);
|
|
|
|
free(path);
|
|
|
|
} else {
|
|
|
|
url = g_strdup_printf("http://%s", uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
setatom(c, AtomUri, url);
|
|
|
|
|
|
|
|
if (strcmp(url, geturi(c)) == 0) {
|
|
|
|
reload(c, a);
|
|
|
|
} else {
|
|
|
|
webkit_web_view_load_uri(c->view, url);
|
|
|
|
updatetitle(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(url);
|
|
|
|
}
|
|
|
|
|
2015-11-22 00:52:13 +00:00
|
|
|
const char *
|
2015-11-21 18:14:08 +00:00
|
|
|
geturi(Client *c)
|
|
|
|
{
|
2015-11-22 01:22:38 +00:00
|
|
|
const char *uri;
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-22 01:22:38 +00:00
|
|
|
if (!(uri = webkit_web_view_get_uri(c->view)))
|
2015-11-21 18:14:08 +00:00
|
|
|
uri = "about:blank";
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setatom(Client *c, int a, const char *v)
|
|
|
|
{
|
|
|
|
XChangeProperty(dpy, c->xid,
|
2015-11-22 01:25:07 +00:00
|
|
|
atoms[a], XA_STRING, 8, PropModeReplace,
|
|
|
|
(unsigned char *)v, strlen(v) + 1);
|
2017-05-11 22:28:24 +00:00
|
|
|
XSync(dpy, False);
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
getatom(Client *c, int a)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZ];
|
|
|
|
Atom adummy;
|
|
|
|
int idummy;
|
|
|
|
unsigned long ldummy;
|
|
|
|
unsigned char *p = NULL;
|
|
|
|
|
2017-05-11 22:28:24 +00:00
|
|
|
XSync(dpy, False);
|
2015-11-22 00:42:34 +00:00
|
|
|
XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
|
|
|
|
&adummy, &idummy, &ldummy, &ldummy, &p);
|
2015-11-21 18:14:08 +00:00
|
|
|
if (p)
|
2015-11-22 00:42:34 +00:00
|
|
|
strncpy(buf, (char *)p, LENGTH(buf) - 1);
|
2015-11-21 18:14:08 +00:00
|
|
|
else
|
|
|
|
buf[0] = '\0';
|
|
|
|
XFree(p);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
updatetitle(Client *c)
|
|
|
|
{
|
|
|
|
char *title;
|
2015-11-22 15:45:22 +00:00
|
|
|
const char *name = c->overtitle ? c->overtitle :
|
2015-11-22 12:24:24 +00:00
|
|
|
c->title ? c->title : "";
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
if (curconfig[ShowIndicators].val.b) {
|
2015-11-21 18:14:08 +00:00
|
|
|
gettogglestats(c);
|
|
|
|
getpagestats(c);
|
|
|
|
|
2015-11-22 12:24:24 +00:00
|
|
|
if (c->progress != 100)
|
2015-11-21 18:14:08 +00:00
|
|
|
title = g_strdup_printf("[%i%%] %s:%s | %s",
|
2015-11-22 12:24:24 +00:00
|
|
|
c->progress, togglestats, pagestats, name);
|
|
|
|
else
|
2015-11-21 18:14:08 +00:00
|
|
|
title = g_strdup_printf("%s:%s | %s",
|
2015-11-22 12:24:24 +00:00
|
|
|
togglestats, pagestats, name);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(c->win), title);
|
|
|
|
g_free(title);
|
|
|
|
} else {
|
2015-11-22 12:24:24 +00:00
|
|
|
gtk_window_set_title(GTK_WINDOW(c->win), name);
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gettogglestats(Client *c)
|
|
|
|
{
|
|
|
|
togglestats[0] = cookiepolicy_set(cookiepolicy_get());
|
2015-11-29 16:42:42 +00:00
|
|
|
togglestats[1] = curconfig[CaretBrowsing].val.b ? 'C' : 'c';
|
|
|
|
togglestats[2] = curconfig[Geolocation].val.b ? 'G' : 'g';
|
|
|
|
togglestats[3] = curconfig[DiskCache].val.b ? 'D' : 'd';
|
|
|
|
togglestats[4] = curconfig[LoadImages].val.b ? 'I' : 'i';
|
|
|
|
togglestats[5] = curconfig[JavaScript].val.b ? 'S' : 's';
|
|
|
|
togglestats[6] = curconfig[Plugins].val.b ? 'V' : 'v';
|
|
|
|
togglestats[7] = curconfig[Style].val.b ? 'M' : 'm';
|
|
|
|
togglestats[8] = curconfig[FrameFlattening].val.b ? 'F' : 'f';
|
2017-04-29 15:21:12 +00:00
|
|
|
togglestats[9] = curconfig[Certificate].val.b ? 'X' : 'x';
|
|
|
|
togglestats[10] = curconfig[StrictTLS].val.b ? 'T' : 't';
|
|
|
|
togglestats[11] = '\0';
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
getpagestats(Client *c)
|
|
|
|
{
|
2016-07-08 16:27:07 +00:00
|
|
|
if (c->https)
|
|
|
|
pagestats[0] = (c->tlserr || c->insecure) ? 'U' : 'T';
|
|
|
|
else
|
|
|
|
pagestats[0] = '-';
|
2015-11-21 18:14:08 +00:00
|
|
|
pagestats[1] = '\0';
|
2009-06-05 11:22:40 +00:00
|
|
|
}
|
2009-06-06 14:30:11 +00:00
|
|
|
|
2015-11-18 13:48:49 +00:00
|
|
|
WebKitCookieAcceptPolicy
|
2015-10-20 13:04:52 +00:00
|
|
|
cookiepolicy_get(void)
|
|
|
|
{
|
2015-11-29 16:42:42 +00:00
|
|
|
switch (((char *)curconfig[CookiePolicies].val.v)[cookiepolicy]) {
|
2014-01-30 19:36:06 +00:00
|
|
|
case 'a':
|
2015-11-18 13:48:49 +00:00
|
|
|
return WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
|
2014-01-30 19:36:06 +00:00
|
|
|
case '@':
|
2015-11-18 13:48:49 +00:00
|
|
|
return WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
|
2015-11-22 12:33:28 +00:00
|
|
|
default: /* fallthrough */
|
2014-01-30 19:36:06 +00:00
|
|
|
case 'A':
|
2015-11-22 12:33:28 +00:00
|
|
|
return WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
|
2014-01-30 19:36:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
char
|
2015-11-22 00:42:34 +00:00
|
|
|
cookiepolicy_set(const WebKitCookieAcceptPolicy p)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-22 00:42:34 +00:00
|
|
|
switch (p) {
|
2015-11-18 13:48:49 +00:00
|
|
|
case WEBKIT_COOKIE_POLICY_ACCEPT_NEVER:
|
2014-01-30 19:36:06 +00:00
|
|
|
return 'a';
|
2015-11-18 13:48:49 +00:00
|
|
|
case WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY:
|
2014-01-30 19:36:06 +00:00
|
|
|
return '@';
|
2015-11-22 12:33:28 +00:00
|
|
|
default: /* fallthrough */
|
2015-11-18 13:48:49 +00:00
|
|
|
case WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS:
|
2015-11-22 12:33:28 +00:00
|
|
|
return 'A';
|
2014-01-30 19:36:06 +00:00
|
|
|
}
|
2015-11-29 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-18 23:10:30 +00:00
|
|
|
seturiparameters(Client *c, const char *uri, ParamName *params)
|
2015-11-29 16:42:42 +00:00
|
|
|
{
|
2017-05-18 10:33:28 +00:00
|
|
|
Parameter *config, *newconfig = NULL;
|
2017-05-18 23:10:30 +00:00
|
|
|
int i, p;
|
2015-11-29 16:42:42 +00:00
|
|
|
|
|
|
|
for (i = 0; i < LENGTH(uriparams); ++i) {
|
|
|
|
if (uriparams[i].uri &&
|
|
|
|
!regexec(&(uriparams[i].re), uri, 0, NULL, 0)) {
|
2017-05-09 12:45:24 +00:00
|
|
|
newconfig = uriparams[i].config;
|
2015-11-29 16:42:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 12:45:24 +00:00
|
|
|
if (!newconfig)
|
|
|
|
newconfig = defconfig;
|
|
|
|
|
2017-05-18 23:10:30 +00:00
|
|
|
for (i = 0; (p = params[i]) != ParameterLast; ++i) {
|
|
|
|
switch(p) {
|
2017-05-18 10:33:28 +00:00
|
|
|
case Certificate:
|
|
|
|
case CookiePolicies:
|
|
|
|
case Style:
|
2017-05-18 23:10:30 +00:00
|
|
|
config = defconfig[p].force ? defconfig :
|
|
|
|
newconfig[p].force ? newconfig :
|
2017-05-18 10:33:28 +00:00
|
|
|
defconfig;
|
|
|
|
break;
|
|
|
|
default:
|
2017-05-18 23:10:30 +00:00
|
|
|
if (defconfig[p].force)
|
2017-05-18 10:33:28 +00:00
|
|
|
continue;
|
2017-05-18 23:10:30 +00:00
|
|
|
config = newconfig[p].force ? newconfig :
|
|
|
|
curconfig[p].force ? defconfig :
|
2017-05-18 10:33:28 +00:00
|
|
|
NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config)
|
2017-05-18 23:10:30 +00:00
|
|
|
setparameter(c, 0, p, &config[p].val);
|
2017-05-09 12:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
curconfig = newconfig;
|
2015-11-29 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setparameter(Client *c, int refresh, ParamName p, const Arg *a)
|
|
|
|
{
|
2016-01-09 11:57:39 +00:00
|
|
|
GdkRGBA bgcolor = { 0 };
|
2015-11-29 16:42:42 +00:00
|
|
|
WebKitSettings *s = webkit_web_view_get_settings(c->view);
|
|
|
|
|
|
|
|
switch (p) {
|
2016-07-05 15:26:54 +00:00
|
|
|
case AcceleratedCanvas:
|
|
|
|
webkit_settings_set_enable_accelerated_2d_canvas(s, a->b);
|
|
|
|
break;
|
2017-05-18 09:20:07 +00:00
|
|
|
case AccessMicrophone:
|
|
|
|
return; /* do nothing */
|
|
|
|
case AccessWebcam:
|
|
|
|
return; /* do nothing */
|
2015-11-29 16:42:42 +00:00
|
|
|
case CaretBrowsing:
|
|
|
|
webkit_settings_set_enable_caret_browsing(s, a->b);
|
|
|
|
refresh = 0;
|
|
|
|
break;
|
2017-04-28 10:58:36 +00:00
|
|
|
case Certificate:
|
|
|
|
if (a->b)
|
|
|
|
setcert(c, geturi(c));
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case CookiePolicies:
|
|
|
|
webkit_cookie_manager_set_accept_policy(
|
|
|
|
webkit_web_context_get_cookie_manager(
|
|
|
|
webkit_web_view_get_context(c->view)),
|
|
|
|
cookiepolicy_get());
|
|
|
|
refresh = 0;
|
|
|
|
break;
|
|
|
|
case DiskCache:
|
|
|
|
webkit_web_context_set_cache_model(
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_web_view_get_context(c->view), a->b ?
|
2015-11-29 16:42:42 +00:00
|
|
|
WEBKIT_CACHE_MODEL_WEB_BROWSER :
|
|
|
|
WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
|
2016-01-09 11:57:39 +00:00
|
|
|
return; /* do not update */
|
2017-05-11 13:23:22 +00:00
|
|
|
case DefaultCharset:
|
|
|
|
webkit_settings_set_default_charset(s, a->v);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case DNSPrefetch:
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_settings_set_enable_dns_prefetching(s, a->b);
|
|
|
|
return; /* do not update */
|
2017-05-18 11:46:49 +00:00
|
|
|
case FileURLsCrossAccess:
|
|
|
|
webkit_settings_set_allow_file_access_from_file_urls(s, a->b);
|
|
|
|
webkit_settings_set_allow_universal_access_from_file_urls(s, a->b);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case FontSize:
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_settings_set_default_font_size(s, a->i);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case FrameFlattening:
|
|
|
|
webkit_settings_set_enable_frame_flattening(s, a->b);
|
|
|
|
break;
|
|
|
|
case Geolocation:
|
2016-01-09 11:57:39 +00:00
|
|
|
refresh = 0;
|
2015-11-29 16:42:42 +00:00
|
|
|
break;
|
|
|
|
case HideBackground:
|
2016-01-09 11:57:39 +00:00
|
|
|
if (a->b)
|
|
|
|
webkit_web_view_set_background_color(c->view, &bgcolor);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case Inspector:
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_settings_set_enable_developer_extras(s, a->b);
|
|
|
|
return; /* do not update */
|
2017-05-11 13:27:27 +00:00
|
|
|
case Java:
|
|
|
|
webkit_settings_set_enable_java(s, a->b);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case JavaScript:
|
|
|
|
webkit_settings_set_enable_javascript(s, a->b);
|
|
|
|
break;
|
|
|
|
case KioskMode:
|
|
|
|
return; /* do nothing */
|
|
|
|
case LoadImages:
|
|
|
|
webkit_settings_set_auto_load_images(s, a->b);
|
|
|
|
break;
|
2016-07-05 15:26:54 +00:00
|
|
|
case MediaManualPlay:
|
|
|
|
webkit_settings_set_media_playback_requires_user_gesture(s, a->b);
|
|
|
|
break;
|
2015-11-29 16:42:42 +00:00
|
|
|
case Plugins:
|
|
|
|
webkit_settings_set_enable_plugins(s, a->b);
|
|
|
|
break;
|
|
|
|
case PreferredLanguages:
|
|
|
|
return; /* do nothing */
|
|
|
|
case RunInFullscreen:
|
|
|
|
return; /* do nothing */
|
|
|
|
case ScrollBars:
|
|
|
|
/* Disabled until we write some WebKitWebExtension for
|
|
|
|
* manipulating the DOM directly.
|
|
|
|
enablescrollbars = !enablescrollbars;
|
|
|
|
evalscript(c, "document.documentElement.style.overflow = '%s'",
|
|
|
|
enablescrollbars ? "auto" : "hidden");
|
|
|
|
*/
|
2016-01-09 11:57:39 +00:00
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case ShowIndicators:
|
2016-01-09 11:57:39 +00:00
|
|
|
break;
|
2017-05-11 13:33:42 +00:00
|
|
|
case SmoothScrolling:
|
|
|
|
webkit_settings_set_enable_smooth_scrolling(s, a->b);
|
|
|
|
return; /* do not update */
|
2016-07-05 15:26:54 +00:00
|
|
|
case SiteQuirks:
|
|
|
|
webkit_settings_set_enable_site_specific_quirks(s, a->b);
|
|
|
|
break;
|
2015-11-29 16:42:42 +00:00
|
|
|
case SpellChecking:
|
|
|
|
webkit_web_context_set_spell_checking_enabled(
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_web_view_get_context(c->view), a->b);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
case SpellLanguages:
|
|
|
|
return; /* do nothing */
|
2017-04-19 15:45:20 +00:00
|
|
|
case StrictTLS:
|
2015-11-29 16:42:42 +00:00
|
|
|
webkit_web_context_set_tls_errors_policy(
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_web_view_get_context(c->view), a->b ?
|
|
|
|
WEBKIT_TLS_ERRORS_POLICY_FAIL :
|
2015-11-29 16:42:42 +00:00
|
|
|
WEBKIT_TLS_ERRORS_POLICY_IGNORE);
|
2017-04-19 16:35:16 +00:00
|
|
|
break;
|
2015-11-29 16:42:42 +00:00
|
|
|
case Style:
|
2017-05-18 14:42:59 +00:00
|
|
|
webkit_user_content_manager_remove_all_style_sheets(
|
|
|
|
webkit_web_view_get_user_content_manager(c->view));
|
2016-01-09 11:57:39 +00:00
|
|
|
if (a->b)
|
2015-11-29 16:42:42 +00:00
|
|
|
setstyle(c, getstyle(geturi(c)));
|
|
|
|
refresh = 0;
|
|
|
|
break;
|
|
|
|
case ZoomLevel:
|
2016-01-09 11:57:39 +00:00
|
|
|
webkit_web_view_set_zoom_level(c->view, a->f);
|
|
|
|
return; /* do not update */
|
2015-11-29 16:42:42 +00:00
|
|
|
default:
|
|
|
|
return; /* do nothing */
|
|
|
|
}
|
2014-01-30 19:36:06 +00:00
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
updatetitle(c);
|
|
|
|
if (refresh)
|
|
|
|
reload(c, a);
|
2014-01-30 19:36:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 10:58:36 +00:00
|
|
|
const char *
|
|
|
|
getcert(const char *uri)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < LENGTH(certs); ++i) {
|
|
|
|
if (certs[i].regex &&
|
|
|
|
!regexec(&(certs[i].re), uri, 0, NULL, 0))
|
|
|
|
return certs[i].file;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setcert(Client *c, const char *uri)
|
|
|
|
{
|
|
|
|
const char *file = getcert(uri);
|
|
|
|
char *host;
|
|
|
|
GTlsCertificate *cert;
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(cert = g_tls_certificate_new_from_file(file, NULL))) {
|
|
|
|
fprintf(stderr, "Could not read certificate file: %s\n", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-29 20:16:03 +00:00
|
|
|
if ((uri = strstr(uri, "https://"))) {
|
|
|
|
uri += sizeof("https://") - 1;
|
|
|
|
host = g_strndup(uri, strchr(uri, '/') - uri);
|
|
|
|
webkit_web_context_allow_tls_certificate_for_host(
|
|
|
|
webkit_web_view_get_context(c->view), cert, host);
|
|
|
|
g_free(host);
|
|
|
|
}
|
2017-04-28 10:58:36 +00:00
|
|
|
|
2017-04-29 12:34:02 +00:00
|
|
|
g_object_unref(cert);
|
2017-04-28 10:58:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-22 00:52:13 +00:00
|
|
|
const char *
|
2015-11-21 18:14:08 +00:00
|
|
|
getstyle(const char *uri)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
if (stylefile)
|
2015-11-21 18:14:08 +00:00
|
|
|
return stylefile;
|
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
for (i = 0; i < LENGTH(styles); ++i) {
|
|
|
|
if (styles[i].regex &&
|
|
|
|
!regexec(&(styles[i].re), uri, 0, NULL, 0))
|
2017-04-27 13:01:54 +00:00
|
|
|
return styles[i].file;
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2017-04-27 13:41:16 +00:00
|
|
|
setstyle(Client *c, const char *file)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
gchar *style;
|
2015-11-19 16:14:29 +00:00
|
|
|
|
2017-04-27 13:41:16 +00:00
|
|
|
if (!g_file_get_contents(file, &style, NULL, NULL)) {
|
|
|
|
fprintf(stderr, "Could not read style file: %s\n", file);
|
2015-11-21 18:14:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-19 16:14:29 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
webkit_user_content_manager_add_style_sheet(
|
|
|
|
webkit_web_view_get_user_content_manager(c->view),
|
|
|
|
webkit_user_style_sheet_new(style,
|
|
|
|
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
|
|
|
|
WEBKIT_USER_STYLE_LEVEL_USER,
|
|
|
|
NULL, NULL));
|
|
|
|
|
|
|
|
g_free(style);
|
2011-11-03 13:09:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-19 16:14:29 +00:00
|
|
|
runscript(Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-19 16:14:29 +00:00
|
|
|
gchar *script;
|
|
|
|
gsize l;
|
2011-11-03 13:09:19 +00:00
|
|
|
|
2015-11-19 16:14:29 +00:00
|
|
|
if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
|
|
|
|
evalscript(c, script);
|
|
|
|
g_free(script);
|
2010-05-09 17:37:46 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
evalscript(Client *c, const char *jsstr, ...)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
va_list ap;
|
|
|
|
gchar *script;
|
2015-11-18 17:16:06 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
va_start(ap, jsstr);
|
|
|
|
script = g_strdup_vprintf(jsstr, ap);
|
|
|
|
va_end(ap);
|
2015-11-18 17:16:06 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
|
|
|
|
g_free(script);
|
2009-06-05 11:22:40 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
updatewinid(Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
snprintf(winid, LENGTH(winid), "%lu", c->xid);
|
2009-10-27 07:11:44 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 17:30:28 +00:00
|
|
|
void
|
2015-11-22 00:52:13 +00:00
|
|
|
handleplumb(Client *c, const char *uri)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-22 00:42:34 +00:00
|
|
|
Arg a = (Arg)PLUMB(uri);
|
|
|
|
spawn(c, &a);
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
2015-01-17 06:19:48 +00:00
|
|
|
|
2015-10-31 11:34:57 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
newwindow(Client *c, const Arg *a, int noembed)
|
2015-11-18 18:05:59 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
int i = 0;
|
|
|
|
char tmp[64];
|
2017-04-29 15:21:12 +00:00
|
|
|
const char *cmd[29], *uri;
|
2015-11-21 18:14:08 +00:00
|
|
|
const Arg arg = { .v = cmd };
|
2010-05-26 13:33:01 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
cmd[i++] = argv0;
|
|
|
|
cmd[i++] = "-a";
|
2015-11-29 16:42:42 +00:00
|
|
|
cmd[i++] = curconfig[CookiePolicies].val.v;
|
|
|
|
cmd[i++] = curconfig[ScrollBars].val.b ? "-B" : "-b";
|
2015-11-21 18:14:08 +00:00
|
|
|
if (cookiefile && g_strcmp0(cookiefile, "")) {
|
|
|
|
cmd[i++] = "-c";
|
|
|
|
cmd[i++] = cookiefile;
|
2015-11-03 14:42:30 +00:00
|
|
|
}
|
2017-04-23 16:11:54 +00:00
|
|
|
if (stylefile && g_strcmp0(stylefile, "")) {
|
|
|
|
cmd[i++] = "-C";
|
|
|
|
cmd[i++] = stylefile;
|
|
|
|
}
|
2015-11-29 16:42:42 +00:00
|
|
|
cmd[i++] = curconfig[DiskCache].val.b ? "-D" : "-d";
|
2015-11-21 18:14:08 +00:00
|
|
|
if (embed && !noembed) {
|
|
|
|
cmd[i++] = "-e";
|
|
|
|
snprintf(tmp, LENGTH(tmp), "%lu", embed);
|
|
|
|
cmd[i++] = tmp;
|
2009-06-08 14:34:46 +00:00
|
|
|
}
|
2015-11-29 16:42:42 +00:00
|
|
|
cmd[i++] = curconfig[RunInFullscreen].val.b ? "-F" : "-f" ;
|
|
|
|
cmd[i++] = curconfig[Geolocation].val.b ? "-G" : "-g" ;
|
|
|
|
cmd[i++] = curconfig[LoadImages].val.b ? "-I" : "-i" ;
|
|
|
|
cmd[i++] = curconfig[KioskMode].val.b ? "-K" : "-k" ;
|
|
|
|
cmd[i++] = curconfig[Style].val.b ? "-M" : "-m" ;
|
|
|
|
cmd[i++] = curconfig[Inspector].val.b ? "-N" : "-n" ;
|
|
|
|
cmd[i++] = curconfig[Plugins].val.b ? "-P" : "-p" ;
|
2015-11-21 18:14:08 +00:00
|
|
|
if (scriptfile && g_strcmp0(scriptfile, "")) {
|
|
|
|
cmd[i++] = "-r";
|
|
|
|
cmd[i++] = scriptfile;
|
2010-03-08 08:24:55 +00:00
|
|
|
}
|
2015-11-29 16:42:42 +00:00
|
|
|
cmd[i++] = curconfig[JavaScript].val.b ? "-S" : "-s";
|
2017-04-23 16:18:23 +00:00
|
|
|
cmd[i++] = curconfig[StrictTLS].val.b ? "-T" : "-t";
|
2015-11-21 18:14:08 +00:00
|
|
|
if (fulluseragent && g_strcmp0(fulluseragent, "")) {
|
|
|
|
cmd[i++] = "-u";
|
|
|
|
cmd[i++] = fulluseragent;
|
2010-01-29 08:44:14 +00:00
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
if (showxid)
|
2017-04-29 15:23:37 +00:00
|
|
|
cmd[i++] = "-w";
|
2017-04-29 15:21:12 +00:00
|
|
|
cmd[i++] = curconfig[Certificate].val.b ? "-X" : "-x" ;
|
2015-11-21 18:14:08 +00:00
|
|
|
/* do not keep zoom level */
|
|
|
|
cmd[i++] = "--";
|
|
|
|
if ((uri = a->v))
|
|
|
|
cmd[i++] = uri;
|
|
|
|
cmd[i] = NULL;
|
|
|
|
|
|
|
|
spawn(c, &arg);
|
2009-09-06 11:40:41 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 15:19:24 +00:00
|
|
|
void
|
2015-11-22 00:42:34 +00:00
|
|
|
spawn(Client *c, const Arg *a)
|
2015-11-20 15:19:24 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
if (fork() == 0) {
|
|
|
|
if (dpy)
|
|
|
|
close(ConnectionNumber(dpy));
|
|
|
|
setsid();
|
2015-11-22 00:42:34 +00:00
|
|
|
execvp(((char **)a->v)[0], (char **)a->v);
|
2015-11-22 12:44:31 +00:00
|
|
|
fprintf(stderr, "%s: execvp %s", argv0, ((char **)a->v)[0]);
|
2015-11-21 18:14:08 +00:00
|
|
|
perror(" failed");
|
2015-11-22 12:44:31 +00:00
|
|
|
exit(1);
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
2015-11-20 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
destroyclient(Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
Client *p;
|
2014-02-05 20:14:16 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
webkit_web_view_stop_loading(c->view);
|
|
|
|
/* Not needed, has already been called
|
|
|
|
gtk_widget_destroy(c->win);
|
|
|
|
*/
|
2015-11-18 15:53:37 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
for (p = clients; p && p->next != c; p = p->next)
|
|
|
|
;
|
|
|
|
if (p)
|
|
|
|
p->next = c->next;
|
|
|
|
else
|
|
|
|
clients = c->next;
|
|
|
|
free(c);
|
|
|
|
}
|
2015-11-18 15:53:37 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
cleanup(void)
|
|
|
|
{
|
|
|
|
while (clients)
|
|
|
|
destroyclient(clients);
|
|
|
|
g_free(cookiefile);
|
|
|
|
g_free(scriptfile);
|
|
|
|
g_free(stylefile);
|
|
|
|
g_free(cachedir);
|
2017-02-12 17:50:31 +00:00
|
|
|
XCloseDisplay(dpy);
|
2015-11-18 15:53:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebKitWebView *
|
|
|
|
newview(Client *c, WebKitWebView *rv)
|
|
|
|
{
|
|
|
|
WebKitWebView *v;
|
|
|
|
WebKitSettings *settings;
|
2015-11-18 16:17:49 +00:00
|
|
|
WebKitUserContentManager *contentmanager;
|
|
|
|
WebKitWebContext *context;
|
2015-11-18 15:53:37 +00:00
|
|
|
|
2009-10-28 18:27:11 +00:00
|
|
|
/* Webview */
|
2015-11-18 15:53:37 +00:00
|
|
|
if (rv) {
|
|
|
|
v = WEBKIT_WEB_VIEW(
|
|
|
|
webkit_web_view_new_with_related_view(rv));
|
|
|
|
} else {
|
2015-11-18 16:17:49 +00:00
|
|
|
settings = webkit_settings_new_with_settings(
|
2017-05-18 11:46:49 +00:00
|
|
|
"allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.b,
|
|
|
|
"allow-universal-access-from-file-urls", curconfig[FileURLsCrossAccess].val.b,
|
2015-11-29 16:42:42 +00:00
|
|
|
"auto-load-images", curconfig[LoadImages].val.b,
|
2017-05-11 13:23:22 +00:00
|
|
|
"default-charset", curconfig[DefaultCharset].val.v,
|
2017-03-06 10:00:04 +00:00
|
|
|
"default-font-size", curconfig[FontSize].val.i,
|
2015-11-29 16:42:42 +00:00
|
|
|
"enable-caret-browsing", curconfig[CaretBrowsing].val.b,
|
|
|
|
"enable-developer-extras", curconfig[Inspector].val.b,
|
|
|
|
"enable-dns-prefetching", curconfig[DNSPrefetch].val.b,
|
|
|
|
"enable-frame-flattening", curconfig[FrameFlattening].val.b,
|
|
|
|
"enable-html5-database", curconfig[DiskCache].val.b,
|
|
|
|
"enable-html5-local-storage", curconfig[DiskCache].val.b,
|
2017-05-11 13:27:27 +00:00
|
|
|
"enable-java", curconfig[Java].val.b,
|
2015-11-29 16:42:42 +00:00
|
|
|
"enable-javascript", curconfig[JavaScript].val.b,
|
|
|
|
"enable-plugins", curconfig[Plugins].val.b,
|
2016-07-05 15:26:54 +00:00
|
|
|
"enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.b,
|
|
|
|
"enable-site-specific-quirks", curconfig[SiteQuirks].val.b,
|
2017-05-11 13:33:42 +00:00
|
|
|
"enable-smooth-scrolling", curconfig[SmoothScrolling].val.b,
|
2016-07-05 15:26:54 +00:00
|
|
|
"media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.b,
|
2015-11-29 16:42:42 +00:00
|
|
|
NULL);
|
2017-04-29 20:07:08 +00:00
|
|
|
/* For more interesting settings, have a look at
|
2015-11-22 00:42:34 +00:00
|
|
|
* http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
|
2015-11-18 16:17:49 +00:00
|
|
|
|
2015-11-20 16:12:00 +00:00
|
|
|
if (strcmp(fulluseragent, "")) {
|
|
|
|
webkit_settings_set_user_agent(settings, fulluseragent);
|
|
|
|
} else if (surfuseragent) {
|
|
|
|
webkit_settings_set_user_agent_with_application_details(
|
|
|
|
settings, "Surf", VERSION);
|
|
|
|
}
|
|
|
|
useragent = webkit_settings_get_user_agent(settings);
|
|
|
|
|
2015-11-18 16:17:49 +00:00
|
|
|
contentmanager = webkit_user_content_manager_new();
|
|
|
|
|
|
|
|
context = webkit_web_context_new_with_website_data_manager(
|
2015-11-22 00:42:34 +00:00
|
|
|
webkit_website_data_manager_new(
|
|
|
|
"base-cache-directory", cachedir,
|
|
|
|
"base-data-directory", cachedir,
|
|
|
|
NULL));
|
2015-11-18 16:17:49 +00:00
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
/* rendering process model, can be a shared unique one
|
|
|
|
* or one for each view */
|
2015-11-18 16:17:49 +00:00
|
|
|
webkit_web_context_set_process_model(context,
|
|
|
|
WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
|
2017-04-19 15:45:20 +00:00
|
|
|
/* TLS */
|
2015-11-29 16:42:42 +00:00
|
|
|
webkit_web_context_set_tls_errors_policy(context,
|
2017-04-19 15:45:20 +00:00
|
|
|
curconfig[StrictTLS].val.b ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
|
2015-11-22 00:42:34 +00:00
|
|
|
WEBKIT_TLS_ERRORS_POLICY_IGNORE);
|
2015-11-18 16:17:49 +00:00
|
|
|
/* disk cache */
|
2015-11-29 16:42:42 +00:00
|
|
|
webkit_web_context_set_cache_model(context,
|
|
|
|
curconfig[DiskCache].val.b ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
|
2015-11-22 00:42:34 +00:00
|
|
|
WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
|
2015-11-18 16:17:49 +00:00
|
|
|
|
|
|
|
/* Currently only works with text file to be compatible with curl */
|
|
|
|
webkit_cookie_manager_set_persistent_storage(
|
|
|
|
webkit_web_context_get_cookie_manager(context), cookiefile,
|
|
|
|
WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
|
|
|
|
/* cookie policy */
|
|
|
|
webkit_cookie_manager_set_accept_policy(
|
|
|
|
webkit_web_context_get_cookie_manager(context),
|
|
|
|
cookiepolicy_get());
|
2015-11-22 18:13:48 +00:00
|
|
|
/* languages */
|
|
|
|
webkit_web_context_set_preferred_languages(context,
|
2015-11-29 16:42:42 +00:00
|
|
|
curconfig[PreferredLanguages].val.v);
|
2015-11-22 18:13:48 +00:00
|
|
|
webkit_web_context_set_spell_checking_languages(context,
|
2015-11-29 16:42:42 +00:00
|
|
|
curconfig[SpellLanguages].val.v);
|
2015-11-22 18:13:48 +00:00
|
|
|
webkit_web_context_set_spell_checking_enabled(context,
|
2015-11-29 16:42:42 +00:00
|
|
|
curconfig[SpellChecking].val.b);
|
2015-11-18 16:17:49 +00:00
|
|
|
|
2015-11-18 18:05:59 +00:00
|
|
|
g_signal_connect(G_OBJECT(context), "download-started",
|
2015-11-22 00:42:34 +00:00
|
|
|
G_CALLBACK(downloadstarted), c);
|
2015-11-23 21:12:00 +00:00
|
|
|
g_signal_connect(G_OBJECT(context), "initialize-web-extensions",
|
|
|
|
G_CALLBACK(initwebextensions), c);
|
2015-11-18 18:05:59 +00:00
|
|
|
|
2015-11-18 16:17:49 +00:00
|
|
|
v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
|
|
|
|
"settings", settings,
|
|
|
|
"user-content-manager", contentmanager,
|
|
|
|
"web-context", context,
|
|
|
|
NULL);
|
2015-11-18 15:53:37 +00:00
|
|
|
}
|
2013-02-21 14:59:07 +00:00
|
|
|
|
2015-11-22 12:51:05 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "notify::estimated-load-progress",
|
|
|
|
G_CALLBACK(progresschanged), c);
|
2015-11-22 00:42:34 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "notify::title",
|
2015-11-18 16:42:51 +00:00
|
|
|
G_CALLBACK(titlechanged), c);
|
2015-11-22 12:51:05 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "button-release-event",
|
|
|
|
G_CALLBACK(buttonreleased), c);
|
|
|
|
g_signal_connect(G_OBJECT(v), "close",
|
|
|
|
G_CALLBACK(closeview), c);
|
2015-11-22 00:42:34 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "create",
|
2015-11-18 17:16:06 +00:00
|
|
|
G_CALLBACK(createview), c);
|
2015-11-22 00:42:34 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "decide-policy",
|
2015-11-18 17:30:28 +00:00
|
|
|
G_CALLBACK(decidepolicy), c);
|
2016-07-08 16:27:07 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "insecure-content-detected",
|
|
|
|
G_CALLBACK(insecurecontent), c);
|
2017-04-29 12:49:04 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "load-failed-with-tls-errors",
|
|
|
|
G_CALLBACK(loadfailedtls), c);
|
2015-11-22 00:42:34 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "load-changed",
|
2015-11-18 17:39:45 +00:00
|
|
|
G_CALLBACK(loadchanged), c);
|
2015-11-22 12:51:05 +00:00
|
|
|
g_signal_connect(G_OBJECT(v), "mouse-target-changed",
|
|
|
|
G_CALLBACK(mousetargetchanged), c);
|
|
|
|
g_signal_connect(G_OBJECT(v), "permission-request",
|
|
|
|
G_CALLBACK(permissionrequested), c);
|
|
|
|
g_signal_connect(G_OBJECT(v), "ready-to-show",
|
|
|
|
G_CALLBACK(showview), c);
|
2009-06-05 11:22:40 +00:00
|
|
|
|
2015-11-18 15:53:37 +00:00
|
|
|
return v;
|
2015-11-18 15:13:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-23 21:12:00 +00:00
|
|
|
void
|
|
|
|
initwebextensions(WebKitWebContext *wc, Client *c)
|
|
|
|
{
|
|
|
|
webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR);
|
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
GtkWidget *
|
|
|
|
createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c)
|
2015-11-18 15:13:27 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
Client *n;
|
2015-11-18 15:13:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
switch (webkit_navigation_action_get_navigation_type(a)) {
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
|
|
|
|
/*
|
|
|
|
* popup windows of type “other” are almost always triggered
|
|
|
|
* by user gesture, so inverse the logic here
|
|
|
|
*/
|
|
|
|
/* instead of this, compare destination uri to mouse-over uri for validating window */
|
2015-11-22 00:42:34 +00:00
|
|
|
if (webkit_navigation_action_is_user_gesture(a))
|
2015-11-21 18:14:08 +00:00
|
|
|
return NULL;
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
|
|
|
|
n = newclient(c);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-11-18 15:13:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
return GTK_WIDGET(n->view);
|
|
|
|
}
|
2015-11-19 23:44:29 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
gboolean
|
2015-11-22 01:10:18 +00:00
|
|
|
buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
|
2015-11-21 18:14:08 +00:00
|
|
|
{
|
|
|
|
WebKitHitTestResultContext element;
|
|
|
|
int i;
|
2015-11-20 00:12:28 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
element = webkit_hit_test_result_get_context(c->mousepos);
|
2015-11-18 15:13:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
for (i = 0; i < LENGTH(buttons); ++i) {
|
|
|
|
if (element & buttons[i].target &&
|
2015-11-22 01:10:18 +00:00
|
|
|
e->button.button == buttons[i].button &&
|
|
|
|
CLEANMASK(e->button.state) == CLEANMASK(buttons[i].mask) &&
|
2015-11-21 18:14:08 +00:00
|
|
|
buttons[i].func) {
|
|
|
|
buttons[i].func(c, &buttons[i].arg, c->mousepos);
|
|
|
|
return buttons[i].stopevent;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 15:13:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-11-18 15:13:27 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
GdkFilterReturn
|
|
|
|
processx(GdkXEvent *e, GdkEvent *event, gpointer d)
|
|
|
|
{
|
|
|
|
Client *c = (Client *)d;
|
|
|
|
XPropertyEvent *ev;
|
2015-11-22 00:42:34 +00:00
|
|
|
Arg a;
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
if (((XEvent *)e)->type == PropertyNotify) {
|
|
|
|
ev = &((XEvent *)e)->xproperty;
|
|
|
|
if (ev->state == PropertyNewValue) {
|
|
|
|
if (ev->atom == atoms[AtomFind]) {
|
|
|
|
find(c, NULL);
|
|
|
|
|
|
|
|
return GDK_FILTER_REMOVE;
|
|
|
|
} else if (ev->atom == atoms[AtomGo]) {
|
2015-11-22 00:42:34 +00:00
|
|
|
a.v = getatom(c, AtomGo);
|
|
|
|
loaduri(c, &a);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
return GDK_FILTER_REMOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
winevent(GtkWidget *w, GdkEvent *e, Client *c)
|
|
|
|
{
|
2015-11-22 16:44:40 +00:00
|
|
|
int i;
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
switch (e->type) {
|
2015-11-22 15:45:22 +00:00
|
|
|
case GDK_ENTER_NOTIFY:
|
|
|
|
c->overtitle = c->targeturi;
|
|
|
|
updatetitle(c);
|
|
|
|
break;
|
2015-11-22 16:44:40 +00:00
|
|
|
case GDK_KEY_PRESS:
|
2015-11-29 16:42:42 +00:00
|
|
|
if (!curconfig[KioskMode].val.b) {
|
2015-11-22 16:44:40 +00:00
|
|
|
for (i = 0; i < LENGTH(keys); ++i) {
|
|
|
|
if (gdk_keyval_to_lower(e->key.keyval) ==
|
|
|
|
keys[i].keyval &&
|
|
|
|
CLEANMASK(e->key.state) == keys[i].mod &&
|
|
|
|
keys[i].func) {
|
|
|
|
updatewinid(c);
|
|
|
|
keys[i].func(c, &(keys[i].arg));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
case GDK_LEAVE_NOTIFY:
|
2015-11-22 15:45:22 +00:00
|
|
|
c->overtitle = NULL;
|
2015-11-21 18:14:08 +00:00
|
|
|
updatetitle(c);
|
|
|
|
break;
|
2015-11-22 15:45:22 +00:00
|
|
|
case GDK_WINDOW_STATE:
|
2015-11-21 18:14:08 +00:00
|
|
|
if (e->window_state.changed_mask ==
|
2015-11-22 15:45:22 +00:00
|
|
|
GDK_WINDOW_STATE_FULLSCREEN)
|
2015-11-21 18:14:08 +00:00
|
|
|
c->fullscreen = e->window_state.new_window_state &
|
2015-11-22 00:42:34 +00:00
|
|
|
GDK_WINDOW_STATE_FULLSCREEN;
|
2015-11-22 15:45:22 +00:00
|
|
|
break;
|
2015-11-21 18:14:08 +00:00
|
|
|
default:
|
2015-11-22 15:45:22 +00:00
|
|
|
break;
|
2009-09-07 22:00:43 +00:00
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-22 15:45:22 +00:00
|
|
|
return FALSE;
|
2009-06-05 11:22:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
showview(WebKitWebView *v, Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
GdkRGBA bgcolor = { 0 };
|
|
|
|
GdkWindow *gwin;
|
2009-10-15 14:31:49 +00:00
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
c->finder = webkit_web_view_get_find_controller(c->view);
|
2016-01-09 12:42:50 +00:00
|
|
|
c->inspector = webkit_web_view_get_inspector(c->view);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
c->win = createwindow(c);
|
2015-11-20 16:39:45 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(c->win), GTK_WIDGET(c->view));
|
2015-11-22 00:42:34 +00:00
|
|
|
gtk_widget_show_all(c->win);
|
2015-11-21 18:14:08 +00:00
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(c->view));
|
2015-11-22 00:42:34 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
gwin = gtk_widget_get_window(GTK_WIDGET(c->win));
|
|
|
|
c->xid = gdk_x11_window_get_xid(gwin);
|
2015-11-22 00:42:34 +00:00
|
|
|
updatewinid(c);
|
|
|
|
if (showxid) {
|
|
|
|
gdk_display_sync(gtk_widget_get_display(c->win));
|
|
|
|
puts(winid);
|
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
if (curconfig[HideBackground].val.b)
|
2015-11-22 00:42:34 +00:00
|
|
|
webkit_web_view_set_background_color(c->view, &bgcolor);
|
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
if (!curconfig[KioskMode].val.b) {
|
2015-11-22 00:42:34 +00:00
|
|
|
gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
|
|
|
|
gdk_window_add_filter(gwin, processx, c);
|
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
if (curconfig[RunInFullscreen].val.b)
|
2015-11-21 18:14:08 +00:00
|
|
|
togglefullscreen(c, NULL);
|
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
if (curconfig[ZoomLevel].val.f != 1.0)
|
|
|
|
webkit_web_view_set_zoom_level(c->view,
|
|
|
|
curconfig[ZoomLevel].val.f);
|
2015-11-22 00:42:34 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
setatom(c, AtomFind, "");
|
|
|
|
setatom(c, AtomUri, "about:blank");
|
2009-10-15 14:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 13:38:23 +00:00
|
|
|
GtkWidget *
|
|
|
|
createwindow(Client *c)
|
|
|
|
{
|
2015-11-22 10:53:19 +00:00
|
|
|
char *wmstr;
|
2015-11-19 13:38:23 +00:00
|
|
|
GtkWidget *w;
|
|
|
|
|
|
|
|
if (embed) {
|
|
|
|
w = gtk_plug_new(embed);
|
|
|
|
} else {
|
|
|
|
w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
2015-11-22 10:53:19 +00:00
|
|
|
wmstr = g_path_get_basename(argv0);
|
|
|
|
gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
|
|
|
|
g_free(wmstr);
|
2015-11-19 13:38:23 +00:00
|
|
|
|
2015-11-22 10:53:19 +00:00
|
|
|
wmstr = g_strdup_printf("%s[%lu]", "Surf",
|
|
|
|
webkit_web_view_get_page_id(c->view));
|
|
|
|
gtk_window_set_role(GTK_WINDOW(w), wmstr);
|
|
|
|
g_free(wmstr);
|
2015-11-19 13:38:23 +00:00
|
|
|
|
2017-04-19 14:05:39 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
|
2015-11-19 13:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(w), "destroy",
|
2015-11-22 00:42:34 +00:00
|
|
|
G_CALLBACK(destroywin), c);
|
2015-11-22 15:45:22 +00:00
|
|
|
g_signal_connect(G_OBJECT(w), "enter-notify-event",
|
|
|
|
G_CALLBACK(winevent), c);
|
2015-11-22 16:44:40 +00:00
|
|
|
g_signal_connect(G_OBJECT(w), "key-press-event",
|
|
|
|
G_CALLBACK(winevent), c);
|
2015-11-19 22:42:19 +00:00
|
|
|
g_signal_connect(G_OBJECT(w), "leave-notify-event",
|
2015-11-22 00:42:34 +00:00
|
|
|
G_CALLBACK(winevent), c);
|
2015-11-19 23:00:59 +00:00
|
|
|
g_signal_connect(G_OBJECT(w), "window-state-event",
|
2015-11-22 00:42:34 +00:00
|
|
|
G_CALLBACK(winevent), c);
|
2015-11-19 13:38:23 +00:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2017-04-29 12:49:04 +00:00
|
|
|
gboolean
|
|
|
|
loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
|
|
|
|
GTlsCertificateFlags err, Client *c)
|
|
|
|
{
|
|
|
|
GString *errmsg = g_string_new(NULL);
|
|
|
|
gchar *html, *pem;
|
|
|
|
|
2017-04-29 12:56:02 +00:00
|
|
|
c->failedcert = g_object_ref(cert);
|
2017-04-29 12:49:04 +00:00
|
|
|
c->tlserr = err;
|
2017-04-29 12:56:02 +00:00
|
|
|
c->errorpage = 1;
|
2017-04-29 12:49:04 +00:00
|
|
|
|
|
|
|
if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
|
|
|
|
g_string_append(errmsg,
|
|
|
|
"The signing certificate authority is not known.<br>");
|
|
|
|
if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
|
|
|
|
g_string_append(errmsg,
|
|
|
|
"The certificate does not match the expected identity "
|
|
|
|
"of the site that it was retrieved from.<br>");
|
|
|
|
if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
|
|
|
|
g_string_append(errmsg,
|
|
|
|
"The certificate's activation time "
|
|
|
|
"is still in the future.<br>");
|
|
|
|
if (err & G_TLS_CERTIFICATE_EXPIRED)
|
|
|
|
g_string_append(errmsg, "The certificate has expired.<br>");
|
|
|
|
if (err & G_TLS_CERTIFICATE_REVOKED)
|
|
|
|
g_string_append(errmsg,
|
|
|
|
"The certificate has been revoked according to "
|
|
|
|
"the GTlsConnection's certificate revocation list.<br>");
|
|
|
|
if (err & G_TLS_CERTIFICATE_INSECURE)
|
|
|
|
g_string_append(errmsg,
|
|
|
|
"The certificate's algorithm is considered insecure.<br>");
|
|
|
|
if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
|
|
|
|
g_string_append(errmsg,
|
|
|
|
"Some error occurred validating the certificate.<br>");
|
|
|
|
|
|
|
|
g_object_get(cert, "certificate-pem", &pem, NULL);
|
|
|
|
html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
|
2017-04-29 12:56:02 +00:00
|
|
|
"<p>You can inspect the following certificate "
|
2017-05-02 15:10:32 +00:00
|
|
|
"with Ctrl-t (default keybinding).</p>"
|
2017-04-29 12:56:02 +00:00
|
|
|
"<p><pre>%s</pre></p>", uri, errmsg->str, pem);
|
2017-04-29 12:49:04 +00:00
|
|
|
g_free(pem);
|
|
|
|
g_string_free(errmsg, TRUE);
|
|
|
|
|
|
|
|
webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
|
|
|
|
g_free(html);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2017-05-11 22:03:57 +00:00
|
|
|
const char *uri = geturi(c);
|
2015-12-01 11:31:42 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
switch (e) {
|
|
|
|
case WEBKIT_LOAD_STARTED:
|
2017-05-11 22:03:57 +00:00
|
|
|
setatom(c, AtomUri, uri);
|
|
|
|
c->title = uri;
|
2016-07-08 16:27:07 +00:00
|
|
|
c->https = c->insecure = 0;
|
2017-05-18 23:10:30 +00:00
|
|
|
seturiparameters(c, uri, loadtransient);
|
2017-04-29 12:56:02 +00:00
|
|
|
if (c->errorpage)
|
|
|
|
c->errorpage = 0;
|
|
|
|
else
|
|
|
|
g_clear_object(&c->failedcert);
|
2015-11-21 18:14:08 +00:00
|
|
|
break;
|
|
|
|
case WEBKIT_LOAD_REDIRECTED:
|
2017-05-11 22:03:57 +00:00
|
|
|
setatom(c, AtomUri, uri);
|
|
|
|
c->title = uri;
|
2017-05-18 23:10:30 +00:00
|
|
|
seturiparameters(c, uri, loadtransient);
|
2015-11-21 18:14:08 +00:00
|
|
|
break;
|
|
|
|
case WEBKIT_LOAD_COMMITTED:
|
2017-05-18 23:10:30 +00:00
|
|
|
seturiparameters(c, uri, loadcommitted);
|
2017-04-29 12:56:02 +00:00
|
|
|
c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
|
2016-07-08 16:27:07 +00:00
|
|
|
&c->tlserr);
|
2015-11-21 18:14:08 +00:00
|
|
|
break;
|
|
|
|
case WEBKIT_LOAD_FINISHED:
|
2017-05-18 23:10:30 +00:00
|
|
|
seturiparameters(c, uri, loadfinished);
|
2015-11-21 18:14:08 +00:00
|
|
|
/* Disabled until we write some WebKitWebExtension for
|
|
|
|
* manipulating the DOM directly.
|
|
|
|
evalscript(c, "document.documentElement.style.overflow = '%s'",
|
|
|
|
enablescrollbars ? "auto" : "hidden");
|
|
|
|
*/
|
|
|
|
runscript(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updatetitle(c);
|
2009-06-09 20:08:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
|
2015-11-22 00:42:34 +00:00
|
|
|
100;
|
2015-11-21 18:14:08 +00:00
|
|
|
updatetitle(c);
|
2009-10-28 19:43:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
c->title = webkit_web_view_get_title(c->view);
|
|
|
|
updatetitle(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
|
|
|
|
Client *c)
|
|
|
|
{
|
2015-11-22 00:42:34 +00:00
|
|
|
WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
/* Keep the hit test to know where is the pointer on the next click */
|
|
|
|
c->mousepos = h;
|
|
|
|
|
|
|
|
if (hc & OnLink)
|
|
|
|
c->targeturi = webkit_hit_test_result_get_link_uri(h);
|
|
|
|
else if (hc & OnImg)
|
|
|
|
c->targeturi = webkit_hit_test_result_get_image_uri(h);
|
|
|
|
else if (hc & OnMedia)
|
|
|
|
c->targeturi = webkit_hit_test_result_get_media_uri(h);
|
|
|
|
else
|
|
|
|
c->targeturi = NULL;
|
2015-11-22 15:45:22 +00:00
|
|
|
|
|
|
|
c->overtitle = c->targeturi;
|
2015-11-21 18:14:08 +00:00
|
|
|
updatetitle(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
|
|
|
|
{
|
2017-05-18 09:20:07 +00:00
|
|
|
ParamName param = ParameterLast;
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
|
2017-05-18 09:20:07 +00:00
|
|
|
param = Geolocation;
|
|
|
|
} else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
|
|
|
|
if (webkit_user_media_permission_is_for_audio_device(
|
|
|
|
WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
|
|
|
|
param = AccessMicrophone;
|
|
|
|
else if (webkit_user_media_permission_is_for_video_device(
|
|
|
|
WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
|
|
|
|
param = AccessWebcam;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 09:20:07 +00:00
|
|
|
if (curconfig[param].val.b)
|
|
|
|
webkit_permission_request_allow(r);
|
|
|
|
else
|
|
|
|
webkit_permission_request_deny(r);
|
|
|
|
|
|
|
|
return TRUE;
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d,
|
|
|
|
WebKitPolicyDecisionType dt, Client *c)
|
|
|
|
{
|
|
|
|
switch (dt) {
|
|
|
|
case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
|
|
|
|
decidenavigation(d, c);
|
|
|
|
break;
|
|
|
|
case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
|
|
|
|
decidenewwindow(d, c);
|
|
|
|
break;
|
|
|
|
case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
|
|
|
|
decideresource(d, c);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
webkit_policy_decision_ignore(d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
decidenavigation(WebKitPolicyDecision *d, Client *c)
|
|
|
|
{
|
2015-11-22 00:42:34 +00:00
|
|
|
WebKitNavigationAction *a =
|
|
|
|
webkit_navigation_policy_decision_get_navigation_action(
|
2015-11-21 18:14:08 +00:00
|
|
|
WEBKIT_NAVIGATION_POLICY_DECISION(d));
|
|
|
|
|
|
|
|
switch (webkit_navigation_action_get_navigation_type(a)) {
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
|
2015-11-22 00:42:34 +00:00
|
|
|
case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: /* fallthrough */
|
2015-11-21 18:14:08 +00:00
|
|
|
case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
|
|
|
|
default:
|
|
|
|
/* Do not navigate to links with a "_blank" target (popup) */
|
|
|
|
if (webkit_navigation_policy_decision_get_frame_name(
|
|
|
|
WEBKIT_NAVIGATION_POLICY_DECISION(d))) {
|
|
|
|
webkit_policy_decision_ignore(d);
|
|
|
|
} else {
|
|
|
|
/* Filter out navigation to different domain ? */
|
|
|
|
/* get action→urirequest, copy and load in new window+view
|
|
|
|
* on Ctrl+Click ? */
|
|
|
|
webkit_policy_decision_use(d);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
decidenewwindow(WebKitPolicyDecision *d, Client *c)
|
|
|
|
{
|
2009-09-06 11:40:41 +00:00
|
|
|
Arg arg;
|
2015-11-22 00:42:34 +00:00
|
|
|
WebKitNavigationAction *a =
|
|
|
|
webkit_navigation_policy_decision_get_navigation_action(
|
2015-11-21 18:14:08 +00:00
|
|
|
WEBKIT_NAVIGATION_POLICY_DECISION(d));
|
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
switch (webkit_navigation_action_get_navigation_type(a)) {
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED:
|
|
|
|
/* Filter domains here */
|
|
|
|
/* If the value of “mouse-button” is not 0, then the navigation was triggered by a mouse event.
|
|
|
|
* test for link clicked but no button ? */
|
|
|
|
arg.v = webkit_uri_request_get_uri(
|
2015-11-22 00:42:34 +00:00
|
|
|
webkit_navigation_action_get_request(a));
|
2015-11-21 18:14:08 +00:00
|
|
|
newwindow(c, &arg, 0);
|
|
|
|
break;
|
|
|
|
case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
webkit_policy_decision_ignore(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
decideresource(WebKitPolicyDecision *d, Client *c)
|
|
|
|
{
|
|
|
|
int i, isascii = 1;
|
|
|
|
WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d);
|
2015-11-22 00:42:34 +00:00
|
|
|
WebKitURIResponse *res =
|
|
|
|
webkit_response_policy_decision_get_response(r);
|
|
|
|
const gchar *uri = webkit_uri_response_get_uri(res);
|
2015-11-21 18:14:08 +00:00
|
|
|
|
2015-11-22 14:19:10 +00:00
|
|
|
if (g_str_has_suffix(uri, "/favicon.ico")) {
|
|
|
|
webkit_policy_decision_ignore(d);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-21 18:14:08 +00:00
|
|
|
|
|
|
|
if (!g_str_has_prefix(uri, "http://")
|
|
|
|
&& !g_str_has_prefix(uri, "https://")
|
|
|
|
&& !g_str_has_prefix(uri, "about:")
|
|
|
|
&& !g_str_has_prefix(uri, "file://")
|
|
|
|
&& !g_str_has_prefix(uri, "data:")
|
|
|
|
&& !g_str_has_prefix(uri, "blob:")
|
|
|
|
&& strlen(uri) > 0) {
|
|
|
|
for (i = 0; i < strlen(uri); i++) {
|
|
|
|
if (!g_ascii_isprint(uri[i])) {
|
|
|
|
isascii = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isascii) {
|
|
|
|
handleplumb(c, uri);
|
|
|
|
webkit_policy_decision_ignore(d);
|
2015-11-22 14:19:10 +00:00
|
|
|
return;
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (webkit_response_policy_decision_is_mime_type_supported(r)) {
|
|
|
|
webkit_policy_decision_use(d);
|
|
|
|
} else {
|
|
|
|
webkit_policy_decision_ignore(d);
|
|
|
|
download(c, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:27:07 +00:00
|
|
|
void
|
|
|
|
insecurecontent(WebKitWebView *v, WebKitInsecureContentEvent e, Client *c)
|
|
|
|
{
|
|
|
|
c->insecure = 1;
|
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
|
|
|
|
{
|
|
|
|
g_signal_connect(G_OBJECT(d), "notify::response",
|
2015-11-22 00:42:34 +00:00
|
|
|
G_CALLBACK(responsereceived), c);
|
2015-11-21 18:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
|
|
|
|
{
|
|
|
|
download(c, webkit_download_get_response(d));
|
|
|
|
webkit_download_cancel(d);
|
|
|
|
}
|
2013-03-14 18:14:44 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
download(Client *c, WebKitURIResponse *r)
|
|
|
|
{
|
2015-11-22 00:42:34 +00:00
|
|
|
Arg a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
|
2015-11-21 18:14:08 +00:00
|
|
|
spawn(c, &a);
|
2009-06-06 18:34:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
closeview(WebKitWebView *v, Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
gtk_widget_destroy(c->win);
|
2009-06-09 08:29:47 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
destroywin(GtkWidget* w, Client *c)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
destroyclient(c);
|
2015-11-22 00:42:34 +00:00
|
|
|
if (!clients)
|
2015-11-21 18:14:08 +00:00
|
|
|
gtk_main_quit();
|
|
|
|
}
|
2015-01-28 20:01:55 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
|
|
|
|
{
|
2015-11-22 00:42:34 +00:00
|
|
|
Arg a = {.v = text };
|
2015-11-22 12:15:39 +00:00
|
|
|
if (text)
|
2015-11-22 00:42:34 +00:00
|
|
|
loaduri((Client *) d, &a);
|
2015-01-28 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-22 00:42:34 +00:00
|
|
|
reload(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-22 01:03:26 +00:00
|
|
|
if (a->b)
|
2015-10-18 20:52:15 +00:00
|
|
|
webkit_web_view_reload_bypass_cache(c->view);
|
2015-10-20 13:04:52 +00:00
|
|
|
else
|
2015-10-18 20:52:15 +00:00
|
|
|
webkit_web_view_reload(c->view);
|
2009-09-06 11:40:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
print(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
webkit_print_operation_run_dialog(webkit_print_operation_new(c->view),
|
2015-11-22 00:42:34 +00:00
|
|
|
GTK_WINDOW(c->win));
|
2012-05-31 09:46:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-29 12:56:02 +00:00
|
|
|
void
|
|
|
|
showcert(Client *c, const Arg *a)
|
|
|
|
{
|
|
|
|
GTlsCertificate *cert = c->failedcert ? c->failedcert : c->cert;
|
|
|
|
GcrCertificate *gcrt;
|
|
|
|
GByteArray *crt;
|
|
|
|
GtkWidget *win;
|
|
|
|
GcrCertificateWidget *wcert;
|
|
|
|
|
|
|
|
if (!cert)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_get(cert, "certificate", &crt, NULL);
|
|
|
|
gcrt = gcr_simple_certificate_new(crt->data, crt->len);
|
|
|
|
g_byte_array_unref(crt);
|
|
|
|
|
|
|
|
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
wcert = gcr_certificate_widget_new(gcrt);
|
|
|
|
g_object_unref(gcrt);
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(wcert));
|
|
|
|
gtk_widget_show_all(win);
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
clipboard(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
if (a->b) { /* load clipboard uri */
|
|
|
|
gtk_clipboard_request_text(gtk_clipboard_get(
|
|
|
|
GDK_SELECTION_PRIMARY),
|
|
|
|
pasteuri, c);
|
|
|
|
} else { /* copy uri */
|
|
|
|
gtk_clipboard_set_text(gtk_clipboard_get(
|
|
|
|
GDK_SELECTION_PRIMARY), c->targeturi
|
|
|
|
? c->targeturi : geturi(c), -1);
|
|
|
|
}
|
2009-10-15 14:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
zoom(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
if (a->i > 0)
|
2015-11-29 16:42:42 +00:00
|
|
|
webkit_web_view_set_zoom_level(c->view,
|
|
|
|
curconfig[ZoomLevel].val.f + 0.1);
|
2015-11-21 18:14:08 +00:00
|
|
|
else if (a->i < 0)
|
2015-11-29 16:42:42 +00:00
|
|
|
webkit_web_view_set_zoom_level(c->view,
|
|
|
|
curconfig[ZoomLevel].val.f - 0.1);
|
2015-11-21 18:14:08 +00:00
|
|
|
else
|
|
|
|
webkit_web_view_set_zoom_level(c->view, 1.0);
|
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
curconfig[ZoomLevel].val.f = webkit_web_view_get_zoom_level(c->view);
|
2009-10-20 21:46:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2016-03-02 13:29:21 +00:00
|
|
|
scroll(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2016-03-02 13:29:21 +00:00
|
|
|
GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
|
2009-06-06 18:34:55 +00:00
|
|
|
|
2016-03-02 13:29:21 +00:00
|
|
|
gdk_event_set_device(ev, gdkkb);
|
|
|
|
ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
|
|
|
|
ev->key.state = GDK_CONTROL_MASK;
|
|
|
|
ev->key.time = GDK_CURRENT_TIME;
|
|
|
|
|
|
|
|
switch (a->i) {
|
|
|
|
case 'd':
|
|
|
|
ev->key.keyval = GDK_KEY_Down;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
ev->key.keyval = GDK_KEY_Page_Down;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
ev->key.keyval = GDK_KEY_Left;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
ev->key.keyval = GDK_KEY_Right;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
ev->key.keyval = GDK_KEY_Page_Up;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
ev->key.keyval = GDK_KEY_Up;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_event_put(ev);
|
2009-10-28 19:43:30 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
navigate(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
if (a->i < 0)
|
|
|
|
webkit_web_view_go_back(c->view);
|
|
|
|
else if (a->i > 0)
|
|
|
|
webkit_web_view_go_forward(c->view);
|
2009-10-15 14:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-22 00:42:34 +00:00
|
|
|
stop(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2010-05-17 08:58:08 +00:00
|
|
|
webkit_web_view_stop_loading(c->view);
|
2009-06-06 18:34:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-20 14:48:04 +00:00
|
|
|
toggle(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-29 16:42:42 +00:00
|
|
|
curconfig[a->i].val.b ^= 1;
|
|
|
|
setparameter(c, 1, (ParamName)a->i, &curconfig[a->i].val);
|
2012-11-15 13:52:22 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
void
|
|
|
|
togglefullscreen(Client *c, const Arg *a)
|
|
|
|
{
|
|
|
|
/* toggling value is handled in winevent() */
|
|
|
|
if (c->fullscreen)
|
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(c->win));
|
|
|
|
else
|
|
|
|
gtk_window_fullscreen(GTK_WINDOW(c->win));
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-22 00:42:34 +00:00
|
|
|
togglecookiepolicy(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-18 13:48:49 +00:00
|
|
|
++cookiepolicy;
|
2015-11-29 16:42:42 +00:00
|
|
|
cookiepolicy %= strlen(curconfig[CookiePolicies].val.v);
|
2014-01-30 19:36:06 +00:00
|
|
|
|
2015-11-29 16:42:42 +00:00
|
|
|
setparameter(c, 0, CookiePolicies, NULL);
|
2013-02-16 23:37:43 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
toggleinspector(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2016-01-09 12:42:50 +00:00
|
|
|
if (webkit_web_inspector_is_attached(c->inspector))
|
|
|
|
webkit_web_inspector_close(c->inspector);
|
|
|
|
else if (curconfig[Inspector].val.b)
|
|
|
|
webkit_web_inspector_show(c->inspector);
|
2012-11-15 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
find(Client *c, const Arg *a)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
const char *s, *f;
|
2012-11-15 14:26:48 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
if (a && a->i) {
|
|
|
|
if (a->i > 0)
|
|
|
|
webkit_find_controller_search_next(c->finder);
|
|
|
|
else
|
|
|
|
webkit_find_controller_search_previous(c->finder);
|
|
|
|
} else {
|
|
|
|
s = getatom(c, AtomFind);
|
|
|
|
f = webkit_find_controller_get_search_text(c->finder);
|
2009-06-08 14:34:46 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
if (g_strcmp0(f, s) == 0) /* reset search */
|
2015-11-22 00:42:34 +00:00
|
|
|
webkit_find_controller_search(c->finder, "", findopts,
|
|
|
|
G_MAXUINT);
|
2012-11-15 14:26:48 +00:00
|
|
|
|
2015-11-22 00:42:34 +00:00
|
|
|
webkit_find_controller_search(c->finder, s, findopts,
|
|
|
|
G_MAXUINT);
|
2013-04-14 12:26:44 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
if (strcmp(s, "") == 0)
|
|
|
|
webkit_find_controller_search_finish(c->finder);
|
2012-10-28 13:06:17 +00:00
|
|
|
}
|
2009-10-27 07:11:44 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h)
|
2015-10-20 13:04:52 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
navigate(c, a);
|
2009-10-28 19:43:30 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:04:52 +00:00
|
|
|
void
|
2015-11-21 18:14:08 +00:00
|
|
|
clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
|
2015-11-20 00:03:32 +00:00
|
|
|
{
|
2015-11-21 18:14:08 +00:00
|
|
|
Arg arg;
|
2015-11-20 00:03:32 +00:00
|
|
|
|
2015-11-21 18:14:08 +00:00
|
|
|
arg.v = webkit_hit_test_result_get_link_uri(h);
|
|
|
|
newwindow(c, &arg, a->b);
|
2009-09-06 11:40:41 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 18:53:29 +00:00
|
|
|
void
|
|
|
|
clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
|
|
|
|
{
|
|
|
|
Arg arg;
|
|
|
|
|
2015-11-24 22:18:06 +00:00
|
|
|
arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
|
|
|
|
spawn(c, &arg);
|
2015-11-21 18:53:29 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 19:56:56 +00:00
|
|
|
int
|
2015-10-20 13:04:52 +00:00
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2009-09-06 11:40:41 +00:00
|
|
|
Arg arg;
|
2014-02-05 20:14:16 +00:00
|
|
|
Client *c;
|
2009-06-05 11:22:40 +00:00
|
|
|
|
2012-11-08 21:05:40 +00:00
|
|
|
memset(&arg, 0, sizeof(arg));
|
|
|
|
|
2009-09-16 23:09:00 +00:00
|
|
|
/* command line args */
|
2012-10-31 20:13:50 +00:00
|
|
|
ARGBEGIN {
|
2014-01-30 19:47:03 +00:00
|
|
|
case 'a':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETV(CookiePolicies, EARGF(usage()));
|
2014-01-30 19:47:03 +00:00
|
|
|
break;
|
2013-02-21 14:59:07 +00:00
|
|
|
case 'b':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(ScrollBars, 0);
|
2013-02-21 14:59:07 +00:00
|
|
|
break;
|
2013-05-21 19:30:00 +00:00
|
|
|
case 'B':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(ScrollBars, 1);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
2012-10-31 20:13:50 +00:00
|
|
|
case 'c':
|
|
|
|
cookiefile = EARGF(usage());
|
|
|
|
break;
|
2017-04-19 16:14:56 +00:00
|
|
|
case 'C':
|
|
|
|
stylefile = EARGF(usage());
|
|
|
|
break;
|
2015-01-17 19:50:21 +00:00
|
|
|
case 'd':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(DiskCache, 0);
|
2015-01-17 19:50:21 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(DiskCache, 1);
|
2015-01-17 19:50:21 +00:00
|
|
|
break;
|
2012-10-31 20:13:50 +00:00
|
|
|
case 'e':
|
|
|
|
embed = strtol(EARGF(usage()), NULL, 0);
|
|
|
|
break;
|
2013-08-25 17:50:40 +00:00
|
|
|
case 'f':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(RunInFullscreen, 0);
|
2013-08-25 17:50:40 +00:00
|
|
|
break;
|
2013-08-31 18:00:41 +00:00
|
|
|
case 'F':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(RunInFullscreen, 1);
|
2013-08-31 18:00:41 +00:00
|
|
|
break;
|
2013-04-28 19:26:56 +00:00
|
|
|
case 'g':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Geolocation, 0);
|
2013-04-28 19:26:56 +00:00
|
|
|
break;
|
2013-05-21 19:30:00 +00:00
|
|
|
case 'G':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Geolocation, 1);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
2012-10-31 20:13:50 +00:00
|
|
|
case 'i':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(LoadImages, 0);
|
2012-10-31 20:13:50 +00:00
|
|
|
break;
|
2013-05-21 19:30:00 +00:00
|
|
|
case 'I':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(LoadImages, 1);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
2013-03-11 20:26:22 +00:00
|
|
|
case 'k':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(KioskMode, 0);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
|
|
|
case 'K':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(KioskMode, 1);
|
2013-03-11 20:26:22 +00:00
|
|
|
break;
|
2015-01-17 06:19:48 +00:00
|
|
|
case 'm':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Style, 0);
|
2015-01-17 06:19:48 +00:00
|
|
|
break;
|
|
|
|
case 'M':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Style, 1);
|
2015-01-17 06:19:48 +00:00
|
|
|
break;
|
2013-01-26 14:53:33 +00:00
|
|
|
case 'n':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Inspector, 0);
|
2013-01-26 14:53:33 +00:00
|
|
|
break;
|
2013-05-21 19:30:00 +00:00
|
|
|
case 'N':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Inspector, 1);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
2012-10-31 20:13:50 +00:00
|
|
|
case 'p':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Plugins, 0);
|
2012-10-31 20:13:50 +00:00
|
|
|
break;
|
2013-05-21 19:30:00 +00:00
|
|
|
case 'P':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(Plugins, 1);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
2012-10-31 20:13:50 +00:00
|
|
|
case 'r':
|
|
|
|
scriptfile = EARGF(usage());
|
|
|
|
break;
|
|
|
|
case 's':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(JavaScript, 0);
|
2012-10-31 20:13:50 +00:00
|
|
|
break;
|
2013-05-21 19:30:00 +00:00
|
|
|
case 'S':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETB(JavaScript, 1);
|
2013-05-21 19:30:00 +00:00
|
|
|
break;
|
2017-04-23 16:18:23 +00:00
|
|
|
case 't':
|
|
|
|
defconfig CSETB(StrictTLS, 0);
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
defconfig CSETB(StrictTLS, 1);
|
|
|
|
break;
|
2012-10-31 20:25:14 +00:00
|
|
|
case 'u':
|
2015-11-23 21:13:32 +00:00
|
|
|
fulluseragent = EARGF(usage());
|
2012-10-31 20:25:14 +00:00
|
|
|
break;
|
2013-01-26 14:53:33 +00:00
|
|
|
case 'v':
|
2017-05-02 16:53:01 +00:00
|
|
|
die("surf-"VERSION", see LICENSE for © details\n");
|
2017-04-29 15:23:37 +00:00
|
|
|
case 'w':
|
2015-11-22 01:03:26 +00:00
|
|
|
showxid = 1;
|
2012-10-31 20:13:50 +00:00
|
|
|
break;
|
2017-04-29 15:21:12 +00:00
|
|
|
case 'x':
|
|
|
|
defconfig CSETB(Certificate, 0);
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
defconfig CSETB(Certificate, 1);
|
|
|
|
break;
|
2013-10-19 16:55:53 +00:00
|
|
|
case 'z':
|
2015-11-29 23:39:52 +00:00
|
|
|
defconfig CSETF(ZoomLevel, strtof(EARGF(usage()), NULL));
|
2013-10-19 16:55:53 +00:00
|
|
|
break;
|
2012-10-31 20:13:50 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
2015-10-18 20:52:16 +00:00
|
|
|
if (argc > 0)
|
2012-10-31 20:13:50 +00:00
|
|
|
arg.v = argv[0];
|
2015-11-22 12:24:24 +00:00
|
|
|
else
|
|
|
|
arg.v = "about:blank";
|
2012-10-31 20:13:50 +00:00
|
|
|
|
2009-09-13 14:15:28 +00:00
|
|
|
setup();
|
2015-11-18 15:53:37 +00:00
|
|
|
c = newclient(NULL);
|
|
|
|
showview(NULL, c);
|
2015-11-22 00:42:34 +00:00
|
|
|
|
2015-11-22 12:24:24 +00:00
|
|
|
loaduri(c, &arg);
|
|
|
|
updatetitle(c);
|
2012-11-08 21:05:40 +00:00
|
|
|
|
2009-06-05 11:22:40 +00:00
|
|
|
gtk_main();
|
|
|
|
cleanup();
|
2012-10-31 20:13:50 +00:00
|
|
|
|
2015-11-22 11:17:05 +00:00
|
|
|
return 0;
|
2009-06-05 11:22:40 +00:00
|
|
|
}
|