Index: src/galeon-tab.c
===================================================================
RCS file: /cvs/gnome/galeon/src/galeon-tab.c,v
retrieving revision 1.98
diff -u -r1.98 galeon-tab.c
--- src/galeon-tab.c	6 Aug 2003 19:49:18 -0000	1.98
+++ src/galeon-tab.c	9 Aug 2003 22:36:57 -0000
@@ -139,6 +139,8 @@
 static void
 galeon_tab_zoom_changed_cb (GaleonEmbed *embed, gint zoom, 
 			    GaleonTab *tab);
+static void
+galeon_tab_destroy_brsr_cb (GaleonEmbed *embed, GaleonTab *tab);
 
 static void
 galeon_tab_popup_blocked_cb(GaleonEmbed *embed, const char *uri,
@@ -368,8 +370,8 @@
 	g_signal_connect (embed, "ge_visibility",
 			  GTK_SIGNAL_FUNC (galeon_tab_visibility_cb), 
 			  tab);
-	g_signal_connect_swapped (embed, "ge_destroy_brsr",
-			  GTK_SIGNAL_FUNC (galeon_tab_destroy), 
+	g_signal_connect (embed, "ge_destroy_brsr",
+			  GTK_SIGNAL_FUNC (galeon_tab_destroy_brsr_cb), 
 			  tab);
 	g_signal_connect (embed, "ge_open_uri",
 			  GTK_SIGNAL_FUNC (galeon_tab_open_uri_cb), 
@@ -414,6 +416,8 @@
 
 	g_idle_remove_by_data (tab->priv->embed);
 	
+	g_idle_remove_by_data (tab);
+
 	g_object_unref (G_OBJECT(tab->priv->tab_icon));
 
 	g_free (tab->priv->link_message);
@@ -939,6 +943,41 @@
 	galeon_window_update_control(window, PermissionControl);
 #endif
 }
+
+
+static gboolean
+galeon_tab_destroy_brsr_idle_cb (GaleonTab *tab)
+{
+	DEBUG_MSG (("galeon_tab_destroy_brsr_idle_cb\n"));
+
+	galeon_tab_destroy (tab);
+	return FALSE;
+}
+
+
+static void
+galeon_tab_destroy_brsr_cb (GaleonEmbed *embed, GaleonTab *tab)
+{
+	/* This is a dirty to hack to work around mozillas problems
+	 * with closing windows via javascript that dont have focus.
+	 * 
+	 * The problem is that if you have a tab loaded in the background
+	 * in the notebook, then mozilla won't emit the ge_destroy_brsr 
+	 * signal until it gets focus by someone clicking on the tab label.
+	 * At that point, the signal is emitted, we close the tab, remove
+	 * the label, and then the notebook crashes because widget for the
+	 * label has been destroyed.
+	 *
+	 * So lets work around the problem by adding an g_idle function
+	 * that destroys the tab when we know nothing is referencing it
+	 * in the stack.
+	 */
+	DEBUG_MSG (("galeon_tab_destroy_brsr_cb\n"));
+
+	g_idle_add_full (G_PRIORITY_HIGH_IDLE, 
+			 (GSourceFunc)galeon_tab_destroy_brsr_idle_cb, tab, 0);
+}
+
 
 void
 galeon_tab_destroy (GaleonTab *tab)
