gint progress;
struct Client *next;
} Client;
+
+typedef struct Cookie {
+ char *name;
+ char *value;
+ char *domain;
+ char *path;
+ struct Cookie *next;
+} Cookie;
+
SoupCookieJar *cookiejar;
+SoupSession *session;
Client *clients = NULL;
+Cookie *cookies = NULL;
gboolean embed = FALSE;
gboolean showxid = FALSE;
gboolean ignore_once = FALSE;
extern int optind;
static void cleanup(void);
+static void proccookies(SoupMessage *m, Client *c);
static void destroyclient(Client *c);
static void destroywin(GtkWidget* w, Client *c);
static void die(char *str);
static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
static void progresschange(WebKitWebView *view, gint p, Client *c);
+static void request(SoupSession *s, SoupMessage *m, Client *c);
+static void setcookie(char *name, char *val, char *dom, char *path, long exp);
static void setup(void);
static void showsearch(Client *c);
static void showurl(Client *c);
static void stop(Client *c);
-static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, Client *c);
+static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
+ const gchar* title, Client *c);
static void usage();
static void updatetitle(Client *c, const gchar *title);
destroyclient(clients);
}
+void
+proccookies(SoupMessage *m, Client *c) {
+ GSList *l;
+ SoupCookie *co;
+ long t;
+
+ for (l = soup_cookies_from_response(m); l; l = l->next){
+ co = (SoupCookie *)l->data;
+ t = co->expires ? soup_date_to_time_t(co->expires) : 0;
+ setcookie(co->name, co->value, co->domain, co->value, t);
+ }
+ g_slist_free(l);
+}
+
void
destroyclient(Client *c) {
Client *p;
}
if(ev->state & GDK_CONTROL_MASK) {
switch(ev->keyval) {
+ case GDK_P:
+ webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
+ return TRUE;
case GDK_p:
gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pasteurl, c);
- return TRUE;
case GDK_y:
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), webkit_web_view_get_uri(c->view), -1);
return TRUE;
case GDK_r:
+ webkit_web_view_reload(c->view);
+ return TRUE;
case GDK_R:
- if((ev->state & GDK_SHIFT_MASK))
- webkit_web_view_reload_bypass_cache(c->view);
- else
- webkit_web_view_reload(c->view);
+ webkit_web_view_reload_bypass_cache(c->view);
return TRUE;
case GDK_b:
return TRUE;
!(ev->state & GDK_SHIFT_MASK),
TRUE);
return TRUE;
- case GDK_Left:
+ case GDK_h:
webkit_web_view_go_back(c->view);
return TRUE;
- case GDK_Right:
+ case GDK_l:
webkit_web_view_go_forward(c->view);
return TRUE;
}
void
loaduri(Client *c, const gchar *uri) {
gchar *u;
- u = g_strrstr(uri, ":") ? g_strdup(uri)
+ u = g_strrstr(uri, "://") ? g_strdup(uri)
: g_strdup_printf("http://%s", uri);
webkit_web_view_load_uri(c->view, u);
c->progress = 0;
g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
+ g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
/* urlbar */
c->urlbar = gtk_entry_new();
int idummy;
unsigned long ldummy;
unsigned char *buf = NULL;
+
if(((XEvent *)e)->type == PropertyNotify) {
ev = &((XEvent *)e)->xproperty;
if(ev->atom == urlprop && ev->state == PropertyNewValue) {
updatetitle(c, NULL);
}
-void setup(void) {
+void
+request(SoupSession *s, SoupMessage *m, Client *c) {
+ soup_message_add_header_handler(m, "got-headers", "Set-Cookie",
+ G_CALLBACK(proccookies), c);
+}
+
+void
+setcookie(char *name, char *val, char *dom, char *path, long exp) {
+ printf("%s %s %s %s %li\n", name, val, dom, path, exp);
+}
+
+void
+setup(void) {
dpy = GDK_DISPLAY();
+ session = webkit_get_default_session();
urlprop = XInternAtom(dpy, "_SURF_URL", False);
}
void
usage() {
fputs("surf - simple browser\n", stderr);
- die("usage: surf [-e] [-x] [-u uri] [-f file]\n");
+ die("usage: surf [-e] [-x] [uri]\n");
}
void
showxid = TRUE;
embed = TRUE;
break;
- case 'u':
- c = newclient();
- loaduri(c, optarg);
- break;
- case 'f':
- c = newclient();
- loadfile(c, optarg);
- break;
case 'v':
die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
break;
default:
usage();
}
- if(optind != argc)
+ if(optind + 1 == argc) {
+ c = newclient();
+ if(strchr("./", argv[optind][0]) || strcmp("-", argv[optind]) == 0)
+ loadfile(c, argv[optind]);
+ else
+ loaduri(c, argv[optind]);
+
+ }
+ else if(optind != argc)
usage();
if(!clients)
newclient();