diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/callbacks.c | 32 | ||||
-rw-r--r-- | src/callbacks.h | 6 | ||||
-rw-r--r-- | src/events.c | 3 | ||||
-rw-r--r-- | src/events.h | 1 | ||||
-rw-r--r-- | src/uzbl-core.c | 72 | ||||
-rw-r--r-- | src/uzbl-core.h | 9 |
6 files changed, 119 insertions, 4 deletions
diff --git a/src/callbacks.c b/src/callbacks.c index 9130f5f..6ec48ea 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -27,6 +27,25 @@ set_proxy_url() { } void +set_authentication_handler() { + /* Check if WEBKIT_TYPE_SOUP_AUTH_DIALOG feature is set */ + GSList *flist = soup_session_get_features (uzbl.net.soup_session, (GType) WEBKIT_TYPE_SOUP_AUTH_DIALOG); + guint feature_is_set = g_slist_length(flist); + g_slist_free(flist); + + if (uzbl.behave.authentication_handler == NULL || *uzbl.behave.authentication_handler == NULL) { + if (!feature_is_set) + soup_session_add_feature_by_type + (uzbl.net.soup_session, (GType) WEBKIT_TYPE_SOUP_AUTH_DIALOG); + } else { + if (feature_is_set) + soup_session_remove_feature_by_type + (uzbl.net.soup_session, (GType) WEBKIT_TYPE_SOUP_AUTH_DIALOG); + } + return; +} + +void set_icon() { if(file_exists(uzbl.gui.icon)) { if (uzbl.gui.main_window) @@ -559,6 +578,19 @@ button_release_cb (GtkWidget* window, GdkEventButton* event) { } gboolean +motion_notify_cb(GtkWidget* window, GdkEventMotion* event, gpointer user_data) { + (void) window; + (void) event; + (void) user_data; + + gchar *details; + details = g_strdup_printf("%.0lf %.0lf %u", event->x, event->y, event->state); + send_event(PTR_MOVE, details, NULL); + + return FALSE; +} + +gboolean navigation_decision_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data) { (void) web_view; (void) frame; diff --git a/src/callbacks.h b/src/callbacks.h index 882ffa4..43a9192 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -13,6 +13,9 @@ void set_proxy_url(); void +set_authentication_handler(); + +void set_icon(); void @@ -167,6 +170,9 @@ gboolean key_release_cb (GtkWidget* window, GdkEventKey* event); gboolean +motion_notify_cb(GtkWidget* window, GdkEventMotion* event, gpointer user_data); + +gboolean navigation_decision_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data); diff --git a/src/events.c b/src/events.c index acb554c..371c8b8 100644 --- a/src/events.c +++ b/src/events.c @@ -43,7 +43,8 @@ const char *event_table[LAST_EVENT] = { "FILE_INCLUDED" , "PLUG_CREATED" , "COMMAND_ERROR" , - "BUILTINS" + "BUILTINS" , + "PTR_MOVE" }; void diff --git a/src/events.h b/src/events.h index 7b8f58b..b02a43c 100644 --- a/src/events.h +++ b/src/events.h @@ -14,6 +14,7 @@ enum event_type { LINK_UNHOVER, FORM_ACTIVE, ROOT_ACTIVE, FOCUS_LOST, FOCUS_GAINED, FILE_INCLUDED, PLUG_CREATED, COMMAND_ERROR, BUILTINS, + PTR_MOVE, /* must be last entry */ LAST_EVENT diff --git a/src/uzbl-core.c b/src/uzbl-core.c index da61093..9168597 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -101,6 +101,7 @@ const struct var_name_to_ptr_t { { "forward_keys", PTR_V_INT(uzbl.behave.forward_keys, 1, NULL)}, { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, NULL)}, + { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)}, { "new_window", PTR_V_STR(uzbl.behave.new_window, 1, NULL)}, { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)}, @@ -2041,6 +2042,7 @@ create_browser () { "signal::key-release-event", (GCallback)key_release_cb, NULL, "signal::button-press-event", (GCallback)button_press_cb, NULL, "signal::button-release-event", (GCallback)button_release_cb, NULL, + "signal::motion-notify-event", (GCallback)motion_notify_cb, NULL, "signal::title-changed", (GCallback)title_change_cb, NULL, "signal::selection-changed", (GCallback)selection_changed_cb, NULL, "signal::load-progress-changed", (GCallback)progress_change_cb, NULL, @@ -2317,6 +2319,63 @@ settings_init () { init_connect_socket(); g_signal_connect_after(n->soup_session, "request-started", G_CALLBACK(handle_cookies), NULL); + g_signal_connect(n->soup_session, "authenticate", G_CALLBACK(handle_authentication), NULL); +} + +void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) { + + (void) user_data; + + if(uzbl.behave.authentication_handler && *uzbl.behave.authentication_handler != NULL) { + gchar *info, *host, *realm; + gchar *p; + + soup_session_pause_message(session, msg); + + /* Sanitize strings */ + info = g_strdup(soup_auth_get_info(auth)); + host = g_strdup(soup_auth_get_host(auth)); + realm = g_strdup(soup_auth_get_realm(auth)); + for (p = info; *p; p++) if (*p == '\'') *p = '\"'; + for (p = host; *p; p++) if (*p == '\'') *p = '\"'; + for (p = realm; *p; p++) if (*p == '\'') *p = '\"'; + + GString *s = g_string_new (""); + g_string_printf(s, "'%s' '%s' '%s' '%s'", + info, host, realm, retrying?"TRUE":"FALSE"); + + run_handler(uzbl.behave.authentication_handler, s->str); + + if (uzbl.comm.sync_stdout && strcmp (uzbl.comm.sync_stdout, "") != 0) { + char *username, *password; + int number_of_endls=0; + + username = uzbl.comm.sync_stdout; + + for (p = uzbl.comm.sync_stdout; *p; p++) { + if (*p == '\n') { + *p = '\0'; + if (++number_of_endls == 1) + password = p + 1; + } + } + + /* If stdout was correct (contains exactly two lines of text) do + * authenticate. */ + if (number_of_endls == 2) + soup_auth_authenticate(auth, username, password); + } + + if (uzbl.comm.sync_stdout) + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); + + soup_session_unpause_message(session, msg); + + g_string_free(s, TRUE); + g_free(info); + g_free(host); + g_free(realm); + } } void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data){ @@ -2467,9 +2526,9 @@ initialize(int argc, char *argv[]) { } event_buffer_timeout(10); - uzbl.info.webkit_major = WEBKIT_MAJOR_VERSION; - uzbl.info.webkit_minor = WEBKIT_MINOR_VERSION; - uzbl.info.webkit_micro = WEBKIT_MICRO_VERSION; + uzbl.info.webkit_major = webkit_major_version(); + uzbl.info.webkit_minor = webkit_minor_version(); + uzbl.info.webkit_micro = webkit_micro_version(); uzbl.info.arch = ARCH; uzbl.info.commit = COMMIT; @@ -2483,6 +2542,13 @@ initialize(int argc, char *argv[]) { void load_uri_imp(gchar *uri) { GString* newuri; + + /* Strip leading whitespaces */ + while (*uri) { + if (!isspace(*uri)) break; + uri++; + } + if (g_strstr_len (uri, 11, "javascript:") != NULL) { eval_js(uzbl.gui.web_view, uri, NULL); return; diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 70a383c..e05fcdb 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -28,6 +28,7 @@ #include <stdio.h> #include <string.h> +#include <ctype.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> @@ -123,6 +124,7 @@ typedef struct { gchar* socket_dir; gchar* download_handler; gchar* cookie_handler; + gchar* authentication_handler; gchar* new_window; gchar* default_font_family; gchar* monospace_font_family; @@ -390,6 +392,13 @@ run_external_js (WebKitWebView * web_view, GArray *argv, GString *result); void eval_js(WebKitWebView * web_view, gchar *script, GString *result); +void +handle_authentication (SoupSession *session, + SoupMessage *msg, + SoupAuth *auth, + gboolean retrying, + gpointer user_data); + void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data); |