? attachment.cgi?id=50646
? lib/egg/eggmarshalers.c
? lib/egg/eggmarshalers.h
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/epiphany/ChangeLog,v
retrieving revision 1.1908.2.166
diff -u -r1.1908.2.166 ChangeLog
--- ChangeLog	17 Aug 2005 13:45:39 -0000	1.1908.2.166
+++ ChangeLog	17 Aug 2005 14:35:12 -0000
@@ -1,3 +1,20 @@
+2005-08-17  Marco Pesenti Gritti  <mpg@redhat.com>
+
+	* NEWS
+	* configure.in:
+
+	Release 1.4.9
+
+	* embed/mozilla/EphyBrowser.cpp:
+	* embed/mozilla/EphyBrowser.h:
+	* embed/mozilla/Makefile.am:
+	* embed/mozilla/mozilla-embed.cpp:
+	* src/ephy-shell.c: (url_is_empty), (load_homepage),
+	(ephy_shell_new_tab):
+	* src/ephy-window.c: (ephy_window_load_url):
+
+	Back port focus fixes from 2.10 branch
+
 2005-08-17  Christian Persch  <chpe@cvs.gnome.org>
 
 	* lib/egg/egg-editable-toolbar.c: (new_pixbuf_from_widget),
Index: NEWS
===================================================================
RCS file: /cvs/gnome/epiphany/NEWS,v
retrieving revision 1.72.2.11
diff -u -r1.72.2.11 NEWS
--- NEWS	13 Feb 2005 17:14:03 -0000	1.72.2.11
+++ NEWS	17 Aug 2005 14:36:18 -0000
@@ -1,4 +1,17 @@
 ==============
+Epiphany 1.4.9
+==============
+
+Changes
+
+	* Fix several focus issues (some with security implications)
+	* Fix crash when updating tray icon
+	* Fix lock up with the move cursor showing
+	* Fix some leaks
+	* Fix getting the trust setting from New CA dialogue
+	* Don't activate the location entry if it's hidden
+
+==============
 Epiphany 1.4.8
 ==============
 
Index: configure.in
===================================================================
RCS file: /cvs/gnome/epiphany/Attic/configure.in,v
retrieving revision 1.195.2.33
diff -u -r1.195.2.33 configure.in
--- configure.in	13 Apr 2005 10:59:31 -0000	1.195.2.33
+++ configure.in	17 Aug 2005 14:36:20 -0000
@@ -402,6 +402,9 @@
   AC_DEFINE([ENABLE_FILEPICKER],[1],[Define to enable the native filepicker])
 fi
 
+dnl Broken everywhere
+AC_DEFINE([GTKMOZEMBED_BROKEN_FOCUS],[1],[Define if GtkMozEmbed has broken focus handling])
+
 dnl *******************************
 dnl Internationalization
 dnl ******************************* 
Index: embed/mozilla/EphyBrowser.cpp
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.cpp,v
retrieving revision 1.53.4.12
diff -u -r1.53.4.12 EphyBrowser.cpp
--- embed/mozilla/EphyBrowser.cpp	19 Nov 2004 20:15:59 -0000	1.53.4.12
+++ embed/mozilla/EphyBrowser.cpp	17 Aug 2005 14:36:24 -0000
@@ -351,6 +351,9 @@
 					 getter_AddRefs(mWebBrowser));
 	NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE);
 
+	mWebBrowserFocus = do_QueryInterface (mWebBrowser);
+	NS_ENSURE_TRUE (mWebBrowserFocus, NS_ERROR_FAILURE);
+
 	mWebBrowser->GetContentDOMWindow (getter_AddRefs (mDOMWindow));
 	NS_ENSURE_TRUE (mDOMWindow, NS_ERROR_FAILURE);
 
@@ -661,13 +664,9 @@
 	}
 
 	/* Use the focused document */
-	nsCOMPtr<nsIWebBrowserFocus> webBrowserFocus;
-	webBrowserFocus = do_QueryInterface (mWebBrowser);
-	NS_ENSURE_TRUE (webBrowserFocus, NS_ERROR_FAILURE);
-
 	nsresult rv;
 	nsCOMPtr<nsIDOMWindow> DOMWindow;
-	rv = webBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow));
+	rv = mWebBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow));
 	if (NS_SUCCEEDED (rv) && DOMWindow)
 	{
 		return DOMWindow->GetDocument (aDOMDocument);
@@ -1131,3 +1130,21 @@
 	return NS_OK;
 #endif
 }
+
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+nsresult
+EphyBrowser::FocusActivate ()
+{
+	NS_ENSURE_STATE (mWebBrowserFocus);
+
+	return mWebBrowserFocus->Activate();
+}
+
+nsresult
+EphyBrowser::FocusDeactivate ()
+{
+	NS_ENSURE_STATE (mWebBrowserFocus);
+
+	return mWebBrowserFocus->Deactivate();
+}
+#endif /* GTKMOZEMBED_BROKEN_FOCUS */
Index: embed/mozilla/EphyBrowser.h
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.h,v
retrieving revision 1.25.4.8
diff -u -r1.25.4.8 EphyBrowser.h
--- embed/mozilla/EphyBrowser.h	12 Dec 2004 22:22:19 -0000	1.25.4.8
+++ embed/mozilla/EphyBrowser.h	17 Aug 2005 14:36:24 -0000
@@ -35,6 +35,7 @@
 #include <nsIWebNavigation.h>
 #include <nsISHistory.h>
 #include <nsIWebBrowser.h>
+#include <nsIWebBrowserFocus.h>
 #include <nsIDOMDocument.h>
 #include <nsIDOMWindow.h>
 #include <nsIPrintSettings.h>
@@ -149,10 +150,16 @@
 	nsresult GetSecurityInfo (PRUint32 *aState, nsACString &aDescription);
 	nsresult ShowCertificate ();
 
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+	nsresult FocusActivate ();
+	nsresult FocusDeactivate ();
+#endif
+
 	nsCOMPtr<nsIWebBrowser> mWebBrowser;
 private:
 	GtkWidget *mEmbed;
 
+	nsCOMPtr<nsIWebBrowserFocus> mWebBrowserFocus;
 	nsCOMPtr<nsIDOMDocument> mTargetDocument;
 	nsCOMPtr<nsIDOMEventTarget> mEventTarget;
 	nsCOMPtr<nsIDOMWindow> mDOMWindow;
Index: embed/mozilla/Makefile.am
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/Makefile.am,v
retrieving revision 1.47.4.4
diff -u -r1.47.4.4 Makefile.am
--- embed/mozilla/Makefile.am	19 Nov 2004 20:15:25 -0000	1.47.4.4
+++ embed/mozilla/Makefile.am	17 Aug 2005 14:36:25 -0000
@@ -42,7 +42,7 @@
 
 if MAINTAINER_MODE
 INCLUDES += -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED \
-	-DGNOME_DISABLE_DEPRECATED -DBONOBO_DISABLE_DEPRECATED $(MOZILLA_WARN_CXXFLAGS)
+	-DBONOBO_DISABLE_DEPRECATED $(MOZILLA_WARN_CXXFLAGS)
 endif
 
 noinst_LTLIBRARIES = libephymozillaembed.la
Index: embed/mozilla/mozilla-embed.cpp
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/mozilla-embed.cpp,v
retrieving revision 1.83.4.7
diff -u -r1.83.4.7 mozilla-embed.cpp
--- embed/mozilla/mozilla-embed.cpp	28 Jan 2005 22:56:39 -0000	1.83.4.7
+++ embed/mozilla/mozilla-embed.cpp	17 Aug 2005 14:36:31 -0000
@@ -92,12 +92,20 @@
 {
 	EphyBrowser *browser;
 	MozillaEmbedLoadState load_state;
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+	guint focus_connected : 1;
+#endif /* GTKMOZEMBED_BROKEN_FOCUS */
 };
 
 #define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1"
 
 static GObjectClass *parent_class = NULL;
 
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+static guint fiesid = 0;
+static guint foesid = 0;
+#endif /* GTKMOZEMBED_BROKEN_FOCUS */
+
 static void
 impl_manager_do_command (EphyCommandManager *manager,
 			 const char *command) 
@@ -211,20 +219,98 @@
 					   wrap_around); 
 }
 
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+static gboolean
+child_focus_in_event_cb (GtkWidget *child,
+			 GdkEventFocus *event,
+			 MozillaEmbed *embed)
+{
+	embed->priv->browser->FocusActivate ();
+
+	return FALSE;
+}
+
+static gboolean
+child_focus_out_event_cb (GtkWidget *child,
+			  GdkEventFocus *event,
+			  MozillaEmbed *embed)
+{
+	embed->priv->browser->FocusDeactivate ();
+
+	return FALSE;
+}
+#endif /* GTKMOZEMBED_BROKEN_FOCUS */
+
 static void
 mozilla_embed_realize (GtkWidget *widget)
 {
 	MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (widget)->priv;
+	GtkBin *bin = GTK_BIN (widget);
 
-	(* GTK_WIDGET_CLASS(parent_class)->realize) (widget);
+	GTK_WIDGET_CLASS (parent_class)->realize (widget);
 
+	/* Initialise our helper class */
 	nsresult rv;
 	rv = mpriv->browser->Init (GTK_MOZ_EMBED (widget));
-
 	if (NS_FAILED (rv))
 	{
-               	g_warning ("EphyBrowser initialization failed for %p\n", widget);
+		g_warning ("EphyBrowser initialization failed for %p\n", widget);
+		return;
 	}
+
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+	/* HACK ALERT! This depends highly on undocumented interna of
+	 * GtkMozEmbed!
+	 *
+	 * GtkMozEmbed::realize installs focus-[in|out]-event handlers to
+	 * toplevel, and, on the first realize only, to the child.
+	 * GtkMozEmbed disconnects its focus-[in|out]-event handler
+	 * to the toplevel on unrealize, and leaves the ones to the child
+	 * in place. So we don't need to unblock the blocked handlers
+	 * and therefore need no ::unrealize handler.
+	*/
+
+	GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
+	gpointer data = ((GtkMozEmbed *) widget)->data;
+
+	guint n;
+
+	n = g_signal_handlers_block_matched (toplevel,
+					     (GSignalMatchType) (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
+					     fiesid, 0, NULL, NULL, data);
+	n += g_signal_handlers_block_matched (toplevel,
+					      (GSignalMatchType) (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
+					      foesid, 0, NULL, NULL, data);
+	if (n != 2)
+	{
+		g_warning ("Unexpected number (n=%d) of toplevel focus handlers found!\n", n);
+	}
+
+	if (mpriv->focus_connected) return;
+
+	GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+	g_return_if_fail (child != NULL);
+
+	n = g_signal_handlers_block_matched (child,
+					     (GSignalMatchType) (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
+					     fiesid, 0, NULL, NULL, widget);
+	n += g_signal_handlers_block_matched (child,
+					      (GSignalMatchType) (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
+					      foesid, 0, NULL, NULL, widget);
+	if (n != 2)
+	{
+		g_warning ("Unexpected number (n=%d) of child focus handlers found!\n", n);
+	}
+
+	g_signal_connect_object (child, "focus-in-event",
+				 G_CALLBACK (child_focus_in_event_cb), widget,
+				 G_CONNECT_AFTER);
+	g_signal_connect_object (child, "focus-out-event",
+				 G_CALLBACK (child_focus_out_event_cb), widget,
+				 G_CONNECT_AFTER);
+
+	mpriv->focus_connected = TRUE;
+#endif /* GTKMOZEMBED_BROKEN_FOCUS */
 }
 
 static GObject *
@@ -253,6 +339,11 @@
 	gtk_object_class->destroy = mozilla_embed_destroy;
 
 	widget_class->realize = mozilla_embed_realize;
+
+#ifdef GTKMOZEMBED_BROKEN_FOCUS
+	fiesid = g_signal_lookup ("focus-in-event", GTK_TYPE_WIDGET);
+	foesid = g_signal_lookup ("focus-out-event", GTK_TYPE_WIDGET);
+#endif /* GTKMOZEMBED_BROKEN_FOCUS */
 
 	g_type_class_add_private (object_class, sizeof(MozillaEmbedPrivate));
 }
Index: src/ephy-shell.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/ephy-shell.c,v
retrieving revision 1.91.4.3
diff -u -r1.91.4.3 ephy-shell.c
--- src/ephy-shell.c	25 Nov 2004 23:04:23 -0000	1.91.4.3
+++ src/ephy-shell.c	17 Aug 2005 14:36:35 -0000
@@ -504,10 +504,25 @@
 	return EPHY_SHELL (g_object_new (EPHY_TYPE_SHELL, NULL));
 }
 
-static void
+static gboolean
+url_is_empty (const char *location)
+{
+	gboolean is_empty = FALSE;
+
+        if (location == NULL || location[0] == '\0' ||
+            strcmp (location, "about:blank") == 0)
+        {
+                is_empty = TRUE;
+        }
+
+        return is_empty;
+}
+
+static gboolean
 load_homepage (EphyEmbed *embed)
 {
 	char *home;
+	gboolean is_empty;
 
 	home = eel_gconf_get_string(CONF_GENERAL_HOMEPAGE);
 
@@ -518,9 +533,13 @@
 		home = g_strdup ("about:blank");
 	}
 
+	is_empty = url_is_empty (home);
+
 	ephy_embed_load_url (embed, home);
 
 	g_free (home);
+
+	return is_empty;
 }
 
 /**
@@ -550,6 +569,7 @@
 	EphyEmbed *previous_embed = NULL;
 	GtkWidget *nb;
 	int position = -1;
+	gboolean is_empty = FALSE;
 	Toolbar *toolbar;
 
 	if (flags & EPHY_NEW_TAB_IN_NEW_WINDOW) in_new_window = TRUE;
@@ -594,17 +614,39 @@
 	{
 		ephy_tab_set_location (tab, "", TAB_ADDRESS_EXPIRE_NEXT);
 		toolbar_activate_location (toolbar);
-		load_homepage (embed);
+		is_empty = load_homepage (embed);
 	}
 	else if (flags & EPHY_NEW_TAB_OPEN_PAGE)
 	{
 		g_assert (url != NULL);
 		ephy_embed_load_url (embed, url);
+		is_empty = url_is_empty (url);
 	}
 
 	if (flags & EPHY_NEW_TAB_FULLSCREEN_MODE)
 	{
 		gtk_window_fullscreen (GTK_WINDOW (window));
+	}
+
+	/* Make sure the initial focus is somewhere sensible and not, for
+	 * example, on the reload button.
+	 */
+	if (in_new_window || jump_to)
+	{
+		/* If the location entry is blank, focus that, except if the
+		 * page was a copy */
+		if (is_empty)
+		{
+			/* empty page, focus location entry */
+			toolbar = EPHY_TOOLBAR (ephy_window_get_toolbar (window));
+			toolbar_activate_location (toolbar);
+		}
+		else if (embed != NULL)
+		{
+			/* non-empty page, focus the page. but make sure the widget is realised first! */
+			gtk_widget_realize (GTK_WIDGET (embed));
+			ephy_embed_activate (embed);
+		}
 	}
 
 	return tab;
Index: src/ephy-window.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/ephy-window.c,v
retrieving revision 1.206.4.27
diff -u -r1.206.4.27 ephy-window.c
--- src/ephy-window.c	4 Apr 2005 21:03:36 -0000	1.206.4.27
+++ src/ephy-window.c	17 Aug 2005 14:36:46 -0000
@@ -2687,7 +2687,15 @@
         g_return_if_fail (url != NULL);
 
         ephy_embed_load_url (embed, url);
-	ephy_embed_activate (embed);
+
+	if (url == NULL || url[0] == '\0' || strcmp (url, "about:blank") == 0)
+	{
+		toolbar_activate_location (window->priv->toolbar);
+	}
+	else
+	{
+		ephy_embed_activate (embed);
+	}
 }
 
 /**
