summaryrefslogtreecommitdiff
path: root/browser.c
diff options
context:
space:
mode:
authorPeter Hofmann <scm@uninformativ.de>2014-12-14 14:15:04 +0100
committerPeter Hofmann <scm@uninformativ.de>2014-12-14 14:30:56 +0100
commitc18cc3dc6aee850c7aa7d47ac29f6d602ee30b21 (patch)
tree95a0907fd132bd211e128a753f1833e938b88369 /browser.c
parentdae6061a900777aff7c4bfbddf2cef191743cfce (diff)
downloadlariza-c18cc3dc6aee850c7aa7d47ac29f6d602ee30b21.tar.gz
Quickfix for crashes when downloads start
Every new window added download_handle_start() as a signal handler to the global WebKitWebContext. This is wrong anway, because the signal handler sets the destination path; this should not be done multiple times. The actual crash happened when a window was closed and *then* a download started. The window's signal handler still existed with a pointer to the window's "struct Client". This struct, however, is now free'd and invalid. Hence the crash. To get rid of the crashes, only add the signal handler once. Sad thing is, this makes the "status" level bar useless: It would only work for the very first window ever created -- if it still existed. If that window has been closed as well, we would still crash. Thus, remove "status" completely. We'll have to find a new way to announce the start of a download. Closes #10.
Diffstat (limited to 'browser.c')
-rw-r--r--browser.c42
1 files changed, 10 insertions, 32 deletions
diff --git a/browser.c b/browser.c
index b73f317..4a1c5e2 100644
--- a/browser.c
+++ b/browser.c
@@ -26,7 +26,6 @@ static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
WebKitPolicyDecisionType, gpointer);
static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
-static gboolean download_reset_indicator(gpointer);
static void downloadmanager_cancel(GtkToolButton *, gpointer data);
static void downloadmanager_setup(void);
static gchar *ensure_uri_scheme(const gchar *);
@@ -49,7 +48,6 @@ struct Client
GtkWidget *location;
GtkWidget *progress;
GtkWidget *scroll;
- GtkWidget *status;
GtkWidget *top_box;
GtkWidget *vbox;
GtkWidget *web_view;
@@ -70,13 +68,12 @@ static gboolean cooperative_alone = TRUE;
static gboolean cooperative_instances = TRUE;
static int cooperative_pipe_fp = 0;
static gchar *download_dir = "/tmp";
-static gint downloads_indicated = 0;
static Window embed = 0;
static gchar *fifo_suffix = "main";
static gdouble global_zoom = 1.0;
static gchar *home_uri = "about:blank";
+static gboolean initial_wc_setup_done = FALSE;
static GHashTable *keywords = NULL;
-static gboolean language_is_set = FALSE;
static gchar *search_text = NULL;
static gboolean tabbed_automagic = TRUE;
static gchar *user_agent = NULL;
@@ -168,8 +165,6 @@ client_new(const gchar *uri)
G_CALLBACK(client_destroy_request), c);
g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
G_CALLBACK(decide_policy), NULL);
- g_signal_connect(G_OBJECT(wc), "download-started",
- G_CALLBACK(download_handle_start), c);
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
@@ -179,10 +174,15 @@ client_new(const gchar *uri)
g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
G_CALLBACK(hover_web_view), c);
- if (!language_is_set && accepted_language[0] != NULL)
+ if (!initial_wc_setup_done)
{
- webkit_web_context_set_preferred_languages(wc, accepted_language);
- language_is_set = TRUE;
+ if (accepted_language[0] != NULL)
+ webkit_web_context_set_preferred_languages(wc, accepted_language);
+
+ g_signal_connect(G_OBJECT(wc), "download-started",
+ G_CALLBACK(download_handle_start), NULL);
+
+ initial_wc_setup_done = TRUE;
}
if (user_agent != NULL)
@@ -203,13 +203,8 @@ client_new(const gchar *uri)
gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
gtk_widget_set_size_request(c->progress, 100, -1);
- c->status = gtk_level_bar_new();
- gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
- gtk_widget_set_size_request(c->status, 20, -1);
-
c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 2);
- gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -373,7 +368,6 @@ download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
gboolean
download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
{
- struct Client *c = (struct Client *)data;
gchar *path, *path2 = NULL, *uri;
GtkToolItem *tb;
int suffix = 1;
@@ -399,10 +393,6 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer da
webkit_download_set_destination(download, uri);
g_free(uri);
- gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 1);
- downloads_indicated++;
- g_timeout_add(500, download_reset_indicator, c);
-
tb = gtk_tool_button_new(NULL, NULL);
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "gtk-delete");
gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
@@ -424,18 +414,6 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer da
return FALSE;
}
-gboolean
-download_reset_indicator(gpointer data)
-{
- struct Client *c = (struct Client *)data;
-
- downloads_indicated--;
- if (downloads_indicated == 0)
- gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
-
- return FALSE;
-}
-
void
downloadmanager_cancel(GtkToolButton *tb, gpointer data)
{