diff options
author | marco <marco@conformal.com> | 2011-11-02 08:20:12 -0500 |
---|---|---|
committer | marco <marco@conformal.com> | 2011-11-02 08:20:12 -0500 |
commit | aa8c440c973effa08af9cef45ef101498ccc0324 (patch) | |
tree | b9ebfea484528165b3ab2fbfaadd1f671217bac8 | |
parent | 78e12066a6d888515f8579180e524476aa3766c5 (diff) | |
download | xombrero-aa8c440c973effa08af9cef45ef101498ccc0324.tar.gz |
Make the inspector not crash on exit
Turns out that someone else frees resources so don't do that and let gtk handle it all by itself.
-rw-r--r-- | inspector.c | 90 | ||||
-rw-r--r-- | xxxterm.c | 19 | ||||
-rw-r--r-- | xxxterm.h | 20 |
3 files changed, 105 insertions, 24 deletions
diff --git a/inspector.c b/inspector.c index 25e155d..6b8f114 100644 --- a/inspector.c +++ b/inspector.c @@ -30,6 +30,11 @@ inspector_close_window(WebKitWebInspector *inspector, struct tab *t) { DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); + if (t->inspector_window) { + gtk_widget_hide(t->inspector_window); + return (TRUE); /* handled */ + } + return (FALSE); /* NOT handled */ } @@ -41,27 +46,31 @@ inspector_detach_window(WebKitWebInspector *inspector, struct tab *t) return (FALSE); /* NOT handled */ } -void -inspector_finished(WebKitWebInspector *inspector, struct tab *t) +gboolean +inspector_delete(GtkWidget *inspector_window, GdkEvent *e, struct tab *t) { - DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); + inspector_close_window(t->inspector, t); + + return (TRUE); /* handled */ } WebKitWebView* inspector_inspect_web_view_cb(WebKitWebInspector *inspector, WebKitWebView* wv, struct tab *t) { - GtkWidget *inspector_window; - GtkWidget *inspector_view; - DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); - inspector_window = create_window("inspector"); - inspector_view = webkit_web_view_new(); - gtk_container_add(GTK_CONTAINER(inspector_window), inspector_view); - gtk_widget_show_all(inspector_window); + if (t->inspector_window) + goto done; - return WEBKIT_WEB_VIEW(inspector_view); + t->inspector_window = create_window("inspector"); + t->inspector_view = webkit_web_view_new(); + gtk_container_add(GTK_CONTAINER(t->inspector_window), t->inspector_view); + + g_signal_connect(t->inspector_window, + "delete-event", G_CALLBACK(inspector_delete), t); +done: + return WEBKIT_WEB_VIEW(t->inspector_view); } gboolean @@ -69,19 +78,51 @@ inspector_show_window(WebKitWebInspector *inspector, struct tab *t) { DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); + if (t->inspector_window) { + g_signal_emit_by_name(inspector, "attach-window", t); + gtk_widget_show_all(t->inspector_window); + gtk_window_present(GTK_WINDOW(t->inspector_window)); + return (TRUE); /* handled */ + } + return (FALSE); /* NOT handled */ } void +inspector_finished(WebKitWebInspector *inspector, struct tab *t) +{ + DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); + + if (t->inspector_window) { + g_signal_handlers_disconnect_by_func( + t->inspector, inspector_attach_window, t); + g_signal_handlers_disconnect_by_func( + t->inspector, inspector_close_window, t); + g_signal_handlers_disconnect_by_func( + t->inspector, inspector_detach_window, t); + g_signal_handlers_disconnect_by_func( + t->inspector, inspector_finished, t); + g_signal_handlers_disconnect_by_func( + t->inspector, inspector_inspect_web_view_cb, t); + g_signal_handlers_disconnect_by_func( + t->inspector, inspector_show_window, t); + + gtk_widget_hide(t->inspector_window); + + /* XXX it seems that the window is disposed automatically */ + t->inspector_window = NULL; + t->inspector_view = NULL; + } +} + +void setup_inspector(struct tab *t) { - WebKitWebInspector *inspector; DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); - inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(t->wv)); - - g_object_connect(G_OBJECT(inspector), + t->inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(t->wv)); + g_object_connect(G_OBJECT(t->inspector), "signal::attach-window", G_CALLBACK(inspector_attach_window), t, "signal::close-window", G_CALLBACK(inspector_close_window), t, "signal::detach-window", G_CALLBACK(inspector_detach_window), t, @@ -89,4 +130,23 @@ setup_inspector(struct tab *t) "signal::inspect-web-view", G_CALLBACK(inspector_inspect_web_view_cb), t, "signal::show-window", G_CALLBACK(inspector_show_window), t, (char *)NULL); + +} + +int +inspector_cmd(struct tab *t, struct karg *args) +{ + DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id); + + if (t == NULL) + return (1); + + if (args->i & XT_INS_SHOW) + webkit_web_inspector_show(t->inspector); + else if (args->i & XT_INS_HIDE) + webkit_web_inspector_close(t->inspector); + else if (args->i & XT_INS_CLOSE) + inspector_finished(t->inspector, t); + + return (XT_CB_PASSTHROUGH); } diff --git a/xxxterm.c b/xxxterm.c index a48b997..fdfd7fd 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -113,12 +113,6 @@ TAILQ_HEAD(command_list, command_entry); /* starts from 1 to catch atoi() failures when calling xtp_handle_dl() */ int next_download_id = 1; -struct karg { - int i; - char *s; - int precount; -}; - /* defines */ #define XT_NAME ("XXXTerm") #define XT_DIR (".xxxterm") @@ -137,8 +131,6 @@ struct karg { #define XT_SAVE_SESSION_ID ("SESSION_NAME=") #define XT_SEARCH_FILE ("search_history") #define XT_COMMAND_FILE ("command_history") -#define XT_CB_HANDLED (TRUE) -#define XT_CB_PASSTHROUGH (FALSE) #define XT_DOCTYPE "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n" #define XT_HTML_TAG "<html xmlns='http://www.w3.org/1999/xhtml'>\n" #define XT_DLMAN_REFRESH "10" @@ -6080,6 +6072,11 @@ struct cmd { /* external javascript */ { "script", 0, script_cmd, XT_EJS_SHOW, XT_USERARG }, + + /* inspector */ + { "inspector", 0, inspector_cmd, XT_INS_SHOW, 0 }, + { "show", 1, inspector_cmd, XT_INS_SHOW, 0 }, + { "hide", 1, inspector_cmd, XT_INS_HIDE, 0 }, }; struct { @@ -9113,6 +9110,11 @@ delete_tab(struct tab *t) if (t->search_id) g_source_remove(t->search_id); + /* inspector */ + bzero(&a, sizeof a); + a.i = XT_INS_CLOSE; + inspector_cmd(t, &a); + if (browser_mode == XT_BM_KIOSK) { gtk_widget_destroy(t->uri_entry); gtk_widget_destroy(t->stop); @@ -9137,6 +9139,7 @@ delete_tab(struct tab *t) /* recreate session */ if (session_autosave) { + bzero(&a, sizeof a); a.s = NULL; save_tabs(NULL, &a); } diff --git a/xxxterm.h b/xxxterm.h index fea2414..ad49fc7 100644 --- a/xxxterm.h +++ b/xxxterm.h @@ -68,7 +68,7 @@ void arc4random_buf(void *, size_t); #include <gnutls/x509.h> /* comment if you don't want to use threads */ -#define USE_THREADS +//#define USE_THREADS #ifdef USE_THREADS #include <gcrypt.h> @@ -223,12 +223,30 @@ struct tab { /* marks */ double mark[XT_NOMARKS]; + + /* inspector */ + WebKitWebInspector *inspector; + GtkWidget *inspector_window; + GtkWidget *inspector_view; }; TAILQ_HEAD(tab_list, tab); +struct karg { + int i; + char *s; + int precount; +}; + +/* utility */ +#define XT_CB_HANDLED (TRUE) +#define XT_CB_PASSTHROUGH (FALSE) GtkWidget *create_window(const gchar *); /* inspector */ +#define XT_INS_SHOW (1<<0) +#define XT_INS_HIDE (1<<1) +#define XT_INS_CLOSE (1<<2) WebKitWebView* inspector_inspect_web_view_cb(WebKitWebInspector *, WebKitWebView*, struct tab *); void setup_inspector(struct tab *); +int inspector_cmd(struct tab *, struct karg *); |