From 38ee70f43987dada86ba928834cee55a53331a98 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 3 Mar 2013 09:32:13 +0100 Subject: Give the web frame to the functions that call javascript. --- src/hints.c | 6 ++---- src/hints.h | 2 +- src/main.c | 46 +++++++++++++++++++++++----------------------- 3 files changed, 26 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/hints.c b/src/hints.c index 97b18f3..85979ee 100644 --- a/src/hints.c +++ b/src/hints.c @@ -33,13 +33,11 @@ static void hints_observe_input(gboolean observe); static gboolean hints_changed_callback(GtkEditable *entry, gpointer data); static gboolean hints_keypress_callback(WebKitWebView* webview, GdkEventKey* event); -void hints_init(void) +void hints_init(WebKitWebFrame* frame) { char* value = NULL; char* error = NULL; - vp_eval_script( - webkit_web_view_get_main_frame(vp.gui.webview), HINTS_JS, HINT_FILE, &value, &error - ); + vp_eval_script(frame, HINTS_JS, HINT_FILE, &value, &error); g_free(value); g_free(error); } diff --git a/src/hints.h b/src/hints.h index 0955b08..aa5f65f 100644 --- a/src/hints.h +++ b/src/hints.h @@ -40,7 +40,7 @@ typedef enum { HINTS_PROCESS_YANK = (1 << 6), } HintsProcess; -void hints_init(void); +void hints_init(WebKitWebFrame* frame); void hints_create(const char* input, guint mode, const guint prefixLength); void hints_update(const gulong num); void hints_clear(void); diff --git a/src/main.c b/src/main.c index 8a6056f..4906bd9 100644 --- a/src/main.c +++ b/src/main.c @@ -66,7 +66,7 @@ static void vp_request_start_cb(WebKitWebView* webview, WebKitWebFrame* frame, /* functions */ static gboolean vp_process_input(const char* input); -static void vp_run_user_script(void); +static void vp_run_user_script(WebKitWebFrame* frame); static char* vp_jsref_to_string(JSContextRef context, JSValueRef ref); static void vp_print_version(void); static void vp_init(void); @@ -109,26 +109,28 @@ static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gp break; case WEBKIT_LOAD_COMMITTED: - /* set the status */ - if (g_str_has_prefix(uri, "https://")) { - WebKitWebFrame* frame = webkit_web_view_get_main_frame(vp.gui.webview); - WebKitWebDataSource* src = webkit_web_frame_get_data_source(frame); - WebKitNetworkRequest* request = webkit_web_data_source_get_request(src); - SoupMessage* msg = webkit_network_request_get_message(request); - SoupMessageFlags flags = soup_message_get_flags(msg); - vp_set_status( - (flags & SOUP_MESSAGE_CERTIFICATE_TRUSTED) ? VP_STATUS_SSL_VALID : VP_STATUS_SSL_INVALID - ); - } else { - vp_set_status(VP_STATUS_NORMAL); + { + WebKitWebFrame* frame = webkit_web_view_get_main_frame(vp.gui.webview); + /* set the status */ + if (g_str_has_prefix(uri, "https://")) { + WebKitWebDataSource* src = webkit_web_frame_get_data_source(frame); + WebKitNetworkRequest* request = webkit_web_data_source_get_request(src); + SoupMessage* msg = webkit_network_request_get_message(request); + SoupMessageFlags flags = soup_message_get_flags(msg); + vp_set_status( + (flags & SOUP_MESSAGE_CERTIFICATE_TRUSTED) ? VP_STATUS_SSL_VALID : VP_STATUS_SSL_INVALID + ); + } else { + vp_set_status(VP_STATUS_NORMAL); + } + + /* inject the hinting javascript */ + hints_init(frame); + + /* run user script file */ + vp_run_user_script(frame); } - /* inject the hinting javascript */ - hints_init(); - - /* run user script file */ - vp_run_user_script(); - /* status bar is updated by vp_set_mode */ vp_set_mode(VP_MODE_NORMAL , FALSE); vp_update_urlbar(uri); @@ -597,7 +599,7 @@ void vp_echo(const MessageType type, gboolean hide, const char *error, ...) } } -static void vp_run_user_script(void) +static void vp_run_user_script(WebKitWebFrame* frame) { char* js = NULL; GError* error = NULL; @@ -608,9 +610,7 @@ static void vp_run_user_script(void) char* value = NULL; char* error = NULL; - vp_eval_script( - webkit_web_view_get_main_frame(vp.gui.webview), js, core.files[FILES_SCRIPT], &value, &error - ); + vp_eval_script(frame, js, core.files[FILES_SCRIPT], &value, &error); if (error) { fprintf(stderr, "%s", error); g_free(error); -- cgit v1.2.3