#include <sys/file.h>
#include <libgen.h>
#include <stdarg.h>
+#include <regex.h>
+#include <pwd.h>
+#include <string.h>
#include "arg.h"
char *argv0;
#define LENGTH(x) (sizeof x / sizeof x[0])
-#define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
+#define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
#define COOKIEJAR_TYPE (cookiejar_get_type ())
#define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar))
enum { AtomFind, AtomGo, AtomUri, AtomLast };
+enum {
+ ClkDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
+ ClkLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
+ ClkImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE,
+ ClkMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA,
+ ClkSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION,
+ ClkEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE,
+ ClkAny = ClkDoc | ClkLink | ClkImg | ClkMedia | ClkSel | ClkEdit,
+};
typedef union Arg Arg;
union Arg {
WebKitWebView *view;
WebKitWebInspector *inspector;
char *title, *linkhover;
- const char *uri, *needle;
+ const char *needle;
gint progress;
struct Client *next;
gboolean zoomed, fullscreen, isinspecting, sslfailed;
const Arg arg;
} Key;
+typedef struct {
+ unsigned int click;
+ unsigned int mask;
+ guint button;
+ void (*func)(Client *c, const Arg *arg);
+ const Arg arg;
+} Button;
+
typedef struct {
SoupCookieJarText parent_instance;
int lock;
G_DEFINE_TYPE(CookieJar, cookiejar, SOUP_TYPE_COOKIE_JAR_TEXT)
+typedef struct {
+ char *regex;
+ char *style;
+ regex_t re;
+} SiteStyle;
+
static Display *dpy;
static Atom atoms[AtomLast];
static Client *clients = NULL;
static gboolean showxid = FALSE;
static char winid[64];
static gboolean usingproxy = 0;
-static char togglestat[7];
+static char togglestat[9];
static char pagestat[3];
+static GTlsDatabase *tlsdb;
+static int policysel = 0;
+static char *stylefile = NULL;
+static SoupCache *diskcache = NULL;
static void addaccelgroup(Client *c);
static void beforerequest(WebKitWebView *w, WebKitWebFrame *f,
WebKitWebResource *r, WebKitNetworkRequest *req,
- WebKitNetworkResponse *resp, gpointer d);
+ WebKitNetworkResponse *resp, Client *c);
+static char *buildfile(const char *path);
static char *buildpath(const char *path);
-static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e,
- GList *gl);
+static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c);
static void cleanup(void);
static void clipboard(Client *c, const Arg *arg);
+/* Cookiejar implementation */
static void cookiejar_changed(SoupCookieJar *self, SoupCookie *old_cookie,
SoupCookie *new_cookie);
static void cookiejar_finalize(GObject *self);
-static SoupCookieJar *cookiejar_new(const char *filename, gboolean read_only);
+static SoupCookieJarAcceptPolicy cookiepolicy_get(void);
+static SoupCookieJar *cookiejar_new(const char *filename, gboolean read_only,
+ SoupCookieJarAcceptPolicy policy);
static void cookiejar_set_property(GObject *self, guint prop_id,
const GValue *value, GParamSpec *pspec);
+static char cookiepolicy_set(const SoupCookieJarAcceptPolicy p);
static char *copystr(char **str, const char *src);
static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f,
static void gettogglestat(Client *c);
static void getpagestat(Client *c);
static char *geturi(Client *c);
+static gchar *getstyle(const char *uri);
+
+static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
+
static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
static void inspector(Client *c, const Arg *arg);
static Client *newclient(void);
static void newwindow(Client *c, const Arg *arg, gboolean noembed);
static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
-static void populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c);
-static void popupactivate(GtkMenuItem *menu, Client *);
+static gboolean contextmenu(WebKitWebView *view, GtkWidget *menu,
+ WebKitHitTestResult *target, gboolean keyboard, Client *c);
+static void menuactivate(GtkMenuItem *item, Client *c);
static void print(Client *c, const Arg *arg);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
gpointer d);
static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
+static void linkopen(Client *c, const Arg *arg);
+static void linkopenembed(Client *c, const Arg *arg);
static void reload(Client *c, const Arg *arg);
static void scroll_h(Client *c, const Arg *arg);
static void scroll_v(Client *c, const Arg *arg);
static void source(Client *c, const Arg *arg);
static void spawn(Client *c, const Arg *arg);
static void stop(Client *c, const Arg *arg);
-static void titlechange(WebKitWebView *v, WebKitWebFrame *frame,
- const char *title, Client *c);
+static void titlechange(WebKitWebView *view, GParamSpec *pspec, Client *c);
+static void titlechangeleave(void *a, void *b, Client *c);
static void toggle(Client *c, const Arg *arg);
+static void togglecookiepolicy(Client *c, const Arg *arg);
static void togglegeolocation(Client *c, const Arg *arg);
static void togglescrollbars(Client *c, const Arg *arg);
static void togglestyle(Client *c, const Arg *arg);
static void
beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r,
WebKitNetworkRequest *req, WebKitNetworkResponse *resp,
- gpointer d) {
+ Client *c) {
const gchar *uri = webkit_network_request_get_uri(req);
+ int i, isascii = 1;
if(g_str_has_suffix(uri, "/favicon.ico"))
webkit_network_request_set_uri(req, "about:blank");
+
+ 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, w, uri);
+ }
}
static char *
-buildpath(const char *path) {
- char *apath, *p;
+buildfile(const char *path) {
+ char *dname, *bname, *bpath, *fpath;
FILE *f;
- /* creating directory */
- if(path[0] == '/') {
- apath = g_strdup(path);
- } else if(path[0] == '~') {
- if(path[1] == '/') {
- apath = g_strconcat(g_get_home_dir(), &path[1], NULL);
+ 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);
+ g_free(bname);
+
+ if(!(f = fopen(fpath, "a")))
+ die("Could not open file: %s\n", fpath);
+
+ g_chmod(fpath, 0600); /* always */
+ fclose(f);
+
+ return fpath;
+}
+
+static char *
+buildpath(const char *path) {
+ struct passwd *pw;
+ char *apath, *name, *p, *fpath;
+
+ if(path[0] == '~') {
+ if(path[1] == '/' || path[1] == '\0') {
+ p = (char *)&path[1];
+ pw = getpwuid(getuid());
} else {
- apath = g_strconcat(g_get_home_dir(), "/",
- &path[1], NULL);
+ if((p = strchr(path, '/')))
+ name = g_strndup(&path[1], --p - path);
+ else
+ name = g_strdup(&path[1]);
+
+ if(!(pw = getpwnam(name))) {
+ die("Can't get user %s home directory: %s.\n",
+ name, path);
+ }
+ g_free(name);
}
+ apath = g_build_filename(pw->pw_dir, p, NULL);
} else {
- apath = g_strconcat(g_get_current_dir(), "/", path, NULL);
+ apath = g_strdup(path);
}
- if((p = strrchr(apath, '/'))) {
- *p = '\0';
- g_mkdir_with_parents(apath, 0700);
- g_chmod(apath, 0700); /* in case it existed */
- *p = '/';
- }
- /* creating file (gives error when apath ends with "/") */
- if((f = fopen(apath, "a"))) {
- g_chmod(apath, 0600); /* always */
- fclose(f);
- }
+ /* creating directory */
+ if(g_mkdir_with_parents(apath, 0700) < 0)
+ die("Could not access directory: %s\n", apath);
- return apath;
+ fpath = realpath(apath, NULL);
+ g_free(apath);
+
+ return fpath;
}
static gboolean
-buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl) {
+buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c) {
WebKitHitTestResultContext context;
WebKitHitTestResult *result = webkit_web_view_get_hit_test_result(web,
e);
Arg arg;
+ unsigned int i;
g_object_get(result, "context", &context, NULL);
- if(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
- if(e->button == 2) {
- g_object_get(result, "link-uri", &arg.v, NULL);
- newwindow(NULL, &arg, e->state & GDK_CONTROL_MASK);
+ g_object_get(result, "link-uri", &arg.v, NULL);
+ for(i = 0; i < LENGTH(buttons); i++) {
+ if(context & buttons[i].click && e->button == buttons[i].button &&
+ CLEANMASK(e->state) == CLEANMASK(buttons[i].mask) && buttons[i].func) {
+ buttons[i].func(c, buttons[i].click == ClkLink && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
return true;
}
}
static void
cleanup(void) {
+ if(diskcache) {
+ soup_cache_flush(diskcache);
+ soup_cache_dump(diskcache);
+ }
while(clients)
destroyclient(clients);
g_free(cookiefile);
}
static SoupCookieJar *
-cookiejar_new(const char *filename, gboolean read_only) {
+cookiejar_new(const char *filename, gboolean read_only,
+ SoupCookieJarAcceptPolicy policy) {
return g_object_new(COOKIEJAR_TYPE,
SOUP_COOKIE_JAR_TEXT_FILENAME, filename,
- SOUP_COOKIE_JAR_READ_ONLY, read_only, NULL);
+ SOUP_COOKIE_JAR_READ_ONLY, read_only,
+ SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL);
}
static void
flock(COOKIEJAR(self)->lock, LOCK_UN);
}
+static SoupCookieJarAcceptPolicy
+cookiepolicy_get(void) {
+ switch(cookiepolicies[policysel]) {
+ case 'a':
+ return SOUP_COOKIE_JAR_ACCEPT_NEVER;
+ case '@':
+ return SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
+ case 'A':
+ default:
+ break;
+ }
+
+ return SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
+}
+
+static char
+cookiepolicy_set(const SoupCookieJarAcceptPolicy ep) {
+ switch(ep) {
+ case SOUP_COOKIE_JAR_ACCEPT_NEVER:
+ return 'a';
+ case SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY:
+ return '@';
+ case SOUP_COOKIE_JAR_ACCEPT_ALWAYS:
+ default:
+ break;
+ }
+
+ return 'A';
+}
+
static void
evalscript(JSContextRef js, char *script, char* scriptname) {
JSStringRef jsscript, jsscriptname;
return uri;
}
+static gchar *
+getstyle(const char *uri) {
+ int i;
+
+ if(stylefile != NULL)
+ return g_strconcat("file://", stylefile, NULL);
+
+ for(i = 0; i < LENGTH(styles); i++) {
+ if(styles[i].regex && !regexec(&(styles[i].re), uri, 0,
+ NULL, 0)) {
+ return g_strconcat("file://", styles[i].style, NULL);
+ }
+ }
+ return g_strdup("");
+}
+
+static void
+handleplumb(Client *c, WebKitWebView *w, const gchar *uri) {
+ Arg arg;
+
+ webkit_web_view_stop_loading(w);
+ arg = (Arg)PLUMB((char *)uri);
+ spawn(c, &arg);
+}
+
static gboolean
initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
Arg arg;
WebKitWebFrame *frame;
WebKitWebDataSource *src;
WebKitNetworkRequest *request;
+ WebKitWebSettings *set = webkit_web_view_get_settings(c->view);
SoupMessage *msg;
char *uri;
src = webkit_web_frame_get_data_source(frame);
request = webkit_web_data_source_get_request(src);
msg = webkit_network_request_get_message(request);
- c->sslfailed = soup_message_get_flags(msg)
- ^ SOUP_MESSAGE_CERTIFICATE_TRUSTED;
+ c->sslfailed = !(soup_message_get_flags(msg)
+ & SOUP_MESSAGE_CERTIFICATE_TRUSTED);
}
setatom(c, AtomUri, uri);
+
+ if(enablestyles) {
+ g_object_set(G_OBJECT(set), "user-stylesheet-uri",
+ getstyle(uri), NULL);
+ }
break;
case WEBKIT_LOAD_FINISHED:
c->progress = 100;
updatetitle(c);
+ if(diskcache) {
+ soup_cache_flush(diskcache);
+ soup_cache_dump(diskcache);
+ }
break;
default:
break;
static void
loaduri(Client *c, const Arg *arg) {
- char *u, *rp;
+ char *u = NULL, *rp;
const char *uri = (char *)arg->v;
Arg a = { .b = FALSE };
struct stat st;
: g_strdup_printf("http://%s", uri);
}
+ setatom(c, AtomUri, uri);
+
/* prevents endless loop */
- if(c->uri && strcmp(u, c->uri) == 0) {
+ if(strcmp(u, geturi(c)) == 0) {
reload(c, &a);
} else {
webkit_web_view_load_uri(c->view, u);
c->progress = 0;
c->title = copystr(&c->title, u);
- g_free(u);
updatetitle(c);
}
+ g_free(u);
}
static void
GdkGeometry hints = { 1, 1 };
GdkScreen *screen;
gdouble dpi;
- char *uri, *ua;
+ char *ua;
if(!(c = calloc(1, sizeof(Client))))
die("Cannot malloc!\n");
+ c->title = NULL;
+ c->progress = 100;
+
/* Window */
if(embed) {
c->win = gtk_plug_new(embed);
g_signal_connect(G_OBJECT(c->win),
"destroy",
G_CALLBACK(destroywin), c);
+ g_signal_connect(G_OBJECT(c->win),
+ "leave_notify_event",
+ G_CALLBACK(titlechangeleave), c);
if(!kioskmode)
addaccelgroup(c);
c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
g_signal_connect(G_OBJECT(c->view),
- "title-changed",
+ "notify::title",
G_CALLBACK(titlechange), c);
g_signal_connect(G_OBJECT(c->view),
"hovering-over-link",
"button-release-event",
G_CALLBACK(buttonrelease), c);
g_signal_connect(G_OBJECT(c->view),
- "populate-popup",
- G_CALLBACK(populatepopup), c);
+ "context-menu",
+ G_CALLBACK(contextmenu), c);
g_signal_connect(G_OBJECT(c->view),
"resource-request-starting",
G_CALLBACK(beforerequest), c);
if(!(ua = getenv("SURF_USERAGENT")))
ua = useragent;
g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
- uri = g_strconcat("file://", stylefile, NULL);
- g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
+ if (enablestyles) {
+ g_object_set(G_OBJECT(settings), "user-stylesheet-uri",
+ getstyle("about:blank"), NULL);
+ }
g_object_set(G_OBJECT(settings), "auto-load-images", loadimages,
NULL);
g_object_set(G_OBJECT(settings), "enable-plugins", enableplugins,
kioskmode ^ 1, NULL);
g_object_set(G_OBJECT(settings), "default-font-size",
defaultfontsize, NULL);
+ g_object_set(G_OBJECT(settings), "resizable-text-areas",
+ 1, NULL);
/*
* While stupid, CSS specifies that a pixel represents 1/96 of an inch.
webkit_web_view_set_zoom_level(c->view, dpi/96);
}
}
+ /* This might conflict with _zoomto96dpi_. */
+ if(zoomlevel != 1.0)
+ webkit_web_view_set_zoom_level(c->view, zoomlevel);
if(enableinspector) {
c->inspector = WEBKIT_WEB_INSPECTOR(
fullscreen(c, NULL);
}
- g_free(uri);
-
setatom(c, AtomFind, "");
setatom(c, AtomUri, "about:blank");
if(hidebackground)
webkit_web_view_set_transparent(c->view, TRUE);
- c->title = NULL;
c->next = clients;
clients = c;
static void
newwindow(Client *c, const Arg *arg, gboolean noembed) {
guint i = 0;
- const char *cmd[14], *uri;
+ const char *cmd[18], *uri;
const Arg a = { .v = (void *)cmd };
char tmp[64];
cmd[i++] = argv0;
+ cmd[i++] = "-a";
+ cmd[i++] = cookiepolicies;
if(!enablescrollbars)
cmd[i++] = "-b";
if(embed && !noembed) {
cmd[i++] = "-e";
- snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed);
+ snprintf(tmp, LENGTH(tmp), "%u", (int)embed);
cmd[i++] = tmp;
}
+ if(!allowgeolocation)
+ cmd[i++] = "-g";
if(!loadimages)
cmd[i++] = "-i";
if(kioskmode)
cmd[i++] = "-s";
if(showxid)
cmd[i++] = "-x";
+ if(enablediskcache)
+ cmd[i++] = "-D";
cmd[i++] = "-c";
cmd[i++] = cookiefile;
cmd[i++] = "--";
spawn(NULL, &a);
}
-static void
-populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c) {
- GList *items = gtk_container_get_children(GTK_CONTAINER(menu));
+static gboolean
+contextmenu(WebKitWebView *view, GtkWidget *menu, WebKitHitTestResult *target,
+ gboolean keyboard, Client *c) {
+ GList *items = gtk_container_get_children(GTK_CONTAINER(GTK_MENU(menu)));
for(GList *l = items; l; l = l->next) {
- g_signal_connect(l->data, "activate", G_CALLBACK(popupactivate), c);
+ g_signal_connect(l->data, "activate", G_CALLBACK(menuactivate), c);
}
g_list_free(items);
+ return FALSE;
}
static void
-popupactivate(GtkMenuItem *menu, Client *c) {
+menuactivate(GtkMenuItem *item, Client *c) {
/*
* context-menu-action-2000 open link
* context-menu-action-1 open link in window
* context-menu-action-2 download linked file
* context-menu-action-3 copy link location
+ * context-menu-action-7 copy image address
* context-menu-action-13 reload
* context-menu-action-10 back
* context-menu-action-11 forward
*/
GtkAction *a = NULL;
- const char *name;
- GtkClipboard *prisel;
+ const char *name, *uri;
+ GtkClipboard *prisel, *clpbrd;
- a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(menu));
+ a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(item));
if(a == NULL)
return;
if(!g_strcmp0(name, "context-menu-action-3")) {
prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gtk_clipboard_set_text(prisel, c->linkhover, -1);
+ } else if(!g_strcmp0(name, "context-menu-action-7")) {
+ prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+ clpbrd = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+ uri = gtk_clipboard_wait_for_text(clpbrd);
+ if(uri)
+ gtk_clipboard_set_text(prisel, uri, -1);
}
}
updatetitle(c);
}
+static void
+linkopen(Client *c, const Arg *arg) {
+ newwindow(NULL, arg, 1);
+}
+
+static void
+linkopenembed(Client *c, const Arg *arg) {
+ newwindow(NULL, arg, 0);
+}
+
static void
reload(Client *c, const Arg *arg) {
gboolean nocache = *(gboolean *)arg;
gdouble v;
v = gtk_adjustment_get_value(a);
- switch (arg->i){
+ switch(arg->i) {
case +10000:
case -10000:
v += gtk_adjustment_get_page_increment(a) *
static void
setup(void) {
+ int i;
char *proxy;
char *new_proxy;
SoupURI *puri;
SoupSession *s;
+ GError *error = NULL;
/* clean up any zombies immediately */
sigchld(0);
atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
/* dirs and files */
- cookiefile = buildpath(cookiefile);
- scriptfile = buildpath(scriptfile);
- stylefile = buildpath(stylefile);
+ cookiefile = buildfile(cookiefile);
+ scriptfile = buildfile(scriptfile);
+ cachefolder = buildpath(cachefolder);
+ styledir = buildpath(styledir);
+ if(stylefile == NULL) {
+ for(i = 0; i < LENGTH(styles); i++) {
+ if(regcomp(&(styles[i].re), styles[i].regex,
+ REG_EXTENDED)) {
+ fprintf(stderr,
+ "Could not compile regex: %s\n",
+ styles[i].regex);
+ styles[i].regex = NULL;
+ }
+ styles[i].style = buildfile(
+ g_strconcat(styledir, "/",
+ styles[i].style, NULL));
+ }
+ } else {
+ stylefile = buildfile(stylefile);
+ }
/* request handler */
s = webkit_get_default_session();
/* cookie jar */
soup_session_add_feature(s,
- SOUP_SESSION_FEATURE(cookiejar_new(cookiefile,
- FALSE)));
+ SOUP_SESSION_FEATURE(cookiejar_new(cookiefile, FALSE,
+ cookiepolicy_get())));
+
+ /* disk cache */
+ if(enablediskcache) {
+ diskcache = soup_cache_new(cachefolder, SOUP_CACHE_SINGLE_USER);
+ soup_cache_set_max_size(diskcache, diskcachebytes);
+ soup_cache_load(diskcache);
+ soup_session_add_feature(s, SOUP_SESSION_FEATURE(diskcache));
+ }
/* ssl */
- g_object_set(G_OBJECT(s), "ssl-ca-file", cafile, NULL);
+ tlsdb = g_tls_file_database_new(cafile, &error);
+
+ if(error) {
+ g_warning("Error loading SSL database %s: %s", cafile, error->message);
+ g_error_free(error);
+ }
+ g_object_set(G_OBJECT(s), "tls-database", tlsdb, NULL);
g_object_set(G_OBJECT(s), "ssl-strict", strictssl, NULL);
/* proxy */
if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
- new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
- g_strdup_printf("http://%s", proxy);
+ new_proxy = g_strrstr(proxy, "http://")
+ || g_strrstr(proxy, "socks://")
+ || g_strrstr(proxy, "socks4://")
+ || g_strrstr(proxy, "socks5://")
+ ? g_strdup(proxy)
+ : g_strdup_printf("http://%s", proxy);
puri = soup_uri_new(new_proxy);
g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
soup_uri_free(puri);
}
static void
-titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) {
- c->title = copystr(&c->title, t);
+titlechange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
+ const gchar *t = webkit_web_view_get_title(view);
+ if (t) {
+ c->title = copystr(&c->title, t);
+ updatetitle(c);
+ }
+}
+
+static void
+titlechangeleave(void *a, void *b, Client *c) {
+ c->linkhover = NULL;
updatetitle(c);
}
reload(c, &a);
}
+static void
+togglecookiepolicy(Client *c, const Arg *arg) {
+ SoupCookieJar *jar;
+ SoupCookieJarAcceptPolicy policy;
+
+ jar = SOUP_COOKIE_JAR(
+ soup_session_get_feature(
+ webkit_get_default_session(),
+ SOUP_TYPE_COOKIE_JAR));
+ g_object_get(G_OBJECT(jar), "accept-policy", &policy, NULL);
+
+ policysel++;
+ if(policysel >= strlen(cookiepolicies))
+ policysel = 0;
+
+ g_object_set(G_OBJECT(jar), "accept-policy",
+ cookiepolicy_get(), NULL);
+
+ updatetitle(c);
+ /* Do not reload. */
+}
+
+static void
+togglegeolocation(Client *c, const Arg *arg) {
+ Arg a = { .b = FALSE };
+
+ allowgeolocation ^= 1;
+
+ reload(c, &a);
+}
+
static void
twitch(Client *c, const Arg *arg) {
GtkAdjustment *a;
gtk_adjustment_set_value(a, v);
}
-static void
-togglegeolocation(Client *c, const Arg *arg) {
- Arg a = { .b = FALSE };
-
- allowgeolocation ^= 1;
-
- reload(c, &a);
-}
-
static void
togglescrollbars(Client *c, const Arg *arg) {
GtkPolicyType vspolicy;
static void
togglestyle(Client *c, const Arg *arg) {
- WebKitWebSettings *settings;
+ WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
char *uri;
- settings = webkit_web_view_get_settings(c->view);
- g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL);
- uri = uri[0] ? g_strdup("") : g_strconcat("file://", stylefile, NULL);
+ enablestyles = !enablestyles;
+ uri = enablestyles ? getstyle(geturi(c)) : g_strdup("");
g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
updatetitle(c);
static void
gettogglestat(Client *c){
gboolean value;
- char *uri;
+ int p = 0;
WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
+ togglestat[p++] = cookiepolicy_set(cookiepolicy_get());
+
g_object_get(G_OBJECT(settings), "enable-caret-browsing",
&value, NULL);
- togglestat[0] = value? 'C': 'c';
+ togglestat[p++] = value? 'C': 'c';
- togglestat[1] = allowgeolocation? 'G': 'g';
+ togglestat[p++] = allowgeolocation? 'G': 'g';
+
+ togglestat[p++] = enablediskcache? 'D': 'd';
g_object_get(G_OBJECT(settings), "auto-load-images", &value, NULL);
- togglestat[2] = value? 'I': 'i';
+ togglestat[p++] = value? 'I': 'i';
g_object_get(G_OBJECT(settings), "enable-scripts", &value, NULL);
- togglestat[3] = value? 'S': 's';
+ togglestat[p++] = value? 'S': 's';
g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL);
- togglestat[4] = value? 'V': 'v';
+ togglestat[p++] = value? 'V': 'v';
- g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL);
- togglestat[5] = uri[0] ? 'M': 'm';
+ togglestat[p++] = enablestyles ? 'M': 'm';
- togglestat[6] = '\0';
+ togglestat[p] = '\0';
}
static void
pagestat, c->linkhover);
} else if(c->progress != 100) {
t = g_strdup_printf("[%i%%] %s:%s | %s", c->progress,
- togglestat, pagestat, c->title);
+ togglestat, pagestat,
+ (c->title == NULL)? "" : c->title);
} else {
t = g_strdup_printf("%s:%s | %s", togglestat, pagestat,
- c->title);
+ (c->title == NULL)? "" : c->title);
}
gtk_window_set_title(GTK_WINDOW(c->win), t);
g_free(t);
} else {
- gtk_window_set_title(GTK_WINDOW(c->win), c->title);
+ gtk_window_set_title(GTK_WINDOW(c->win),
+ (c->title == NULL)? "" : c->title);
}
}
static void
usage(void) {
- die("usage: %s [-biknpsvx] [-c cookiefile] [-e xid] [-r scriptfile]"
- " [-t stylefile] [-u useragent] [uri]\n", basename(argv0));
+ die("usage: %s [-bBfFgGiIkKnNpPsSvx]"
+ " [-a cookiepolicies ] "
+ " [-c cookiefile] [-e xid] [-r scriptfile]"
+ " [-t stylefile] [-u useragent] [-z zoomlevel]"
+ " [uri]\n", basename(argv0));
}
static void
int
main(int argc, char *argv[]) {
Arg arg;
+ Client *c;
memset(&arg, 0, sizeof(arg));
/* command line args */
ARGBEGIN {
+ case 'a':
+ cookiepolicies = EARGF(usage());
+ break;
case 'b':
enablescrollbars = 0;
break;
case 'c':
cookiefile = EARGF(usage());
break;
+ case 'd':
+ enablediskcache = 0;
+ break;
+ case 'D':
+ enablediskcache = 1;
+ break;
case 'e':
embed = strtol(EARGF(usage()), NULL, 0);
break;
case 'f':
runinfullscreen = 1;
break;
+ case 'F':
+ runinfullscreen = 0;
+ break;
case 'g':
allowgeolocation = 0;
break;
case 'K':
kioskmode = 1;
break;
+ case 'm':
+ enablestyles = 0;
+ break;
+ case 'M':
+ enablestyles = 1;
+ break;
case 'n':
enableinspector = 0;
break;
useragent = EARGF(usage());
break;
case 'v':
- die("surf-"VERSION", ©2009-2012 surf engineers, "
+ die("surf-"VERSION", ©2009-2014 surf engineers, "
"see LICENSE for details\n");
case 'x':
showxid = TRUE;
break;
+ case 'z':
+ zoomlevel = strtof(EARGF(usage()), NULL);
+ break;
default:
usage();
} ARGEND;
arg.v = argv[0];
setup();
- newclient();
- if(arg.v)
+ c = newclient();
+ if(arg.v) {
loaduri(clients, &arg);
+ } else {
+ updatetitle(c);
+ }
gtk_main();
cleanup();