diff options
-rw-r--r-- | embed/ephy-embed.c | 159 | ||||
-rw-r--r-- | embed/ephy-embed.h | 12 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 346 | ||||
-rw-r--r-- | src/ephy-tab.c | 358 |
4 files changed, 400 insertions, 475 deletions
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 3f052e413..458849a2c 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -424,61 +424,68 @@ ephy_embed_base_init (gpointer g_class) 1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); - g_object_interface_install_property (g_class, - g_param_spec_enum ("security-level", - "Security Level", - "The embed's security level", - EPHY_TYPE_EMBED_SECURITY_LEVEL, - EPHY_EMBED_STATE_IS_UNKNOWN, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_enum ("document-type", - "Document Type", - "The embed's documen type", - EPHY_TYPE_EMBED_DOCUMENT_TYPE, - EPHY_EMBED_DOCUMENT_HTML, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_float ("zoom", - "Zoom", - "The embed's zoom", - ZOOM_MINIMAL, - ZOOM_MAXIMAL, - 1.0, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_int ("load-progress", - "Load progress", - "The embed's load progress in percent", - 0, - 100, - 0, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_boolean ("load-status", - "Load status", - "The embed's load status", - FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_flags ("navigation", - "Navigation flags", - "The embed's navigation flags", - EPHY_TYPE_EMBED_NAVIGATION_FLAGS, - 0, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_string ("address", - "Address", - "The embed's address", - "", - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_interface_install_property (g_class, - g_param_spec_string ("typed-address", - "Typed Address", - "The typed address", - "", - G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_enum ("security-level", + "Security Level", + "The embed's security level", + EPHY_TYPE_EMBED_SECURITY_LEVEL, + EPHY_EMBED_STATE_IS_UNKNOWN, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_enum ("document-type", + "Document Type", + "The embed's documen type", + EPHY_TYPE_EMBED_DOCUMENT_TYPE, + EPHY_EMBED_DOCUMENT_HTML, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_float ("zoom", + "Zoom", + "The embed's zoom", + ZOOM_MINIMAL, + ZOOM_MAXIMAL, + 1.0, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_int ("load-progress", + "Load progress", + "The embed's load progress in percent", + 0, + 100, + 0, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_boolean ("load-status", + "Load status", + "The embed's load status", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_flags ("navigation", + "Navigation flags", + "The embed's navigation flags", + EPHY_TYPE_EMBED_NAVIGATION_FLAGS, + 0, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_string ("address", + "Address", + "The embed's address", + "", + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_string ("typed-address", + "Typed Address", + "The typed address", + "", + G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_string ("title", + "Title", + "The embed's title", + _("Blank page"), + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + initialized = TRUE; } @@ -694,7 +701,7 @@ ephy_embed_get_link_message (EphyEmbed *embed) * Note that Epiphany does not display JavaScript statusbar messages. * * Return value: a message from JavaScript meant to be displayed in the - * statusbar + * statusbar **/ char * ephy_embed_get_js_status (EphyEmbed *embed) @@ -1104,20 +1111,6 @@ ephy_embed_get_load_percent (EphyEmbed *embed) } /** - * ephy_embed_set_load_percent: - * @embed: an #EphyEmbed - * @percent: a percentage, from 0 to 100. - * - * Sets the load percentage. - **/ -void -ephy_embed_set_load_percent (EphyEmbed *embed, int percent) -{ - EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - return iface->set_load_percent (embed, percent); -} - -/** * ephy_embed_get_load_status: * @embed: an #EphyEmbed * @@ -1134,13 +1127,6 @@ ephy_embed_get_load_status (EphyEmbed *embed) return iface->get_load_status (embed); } -void -ephy_embed_set_load_status (EphyEmbed *embed, gboolean status) -{ - EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - return iface->set_load_status (embed, status); -} - /** * ephy_embed_get_navigation_flags: * @embed: an #EphyEmbed @@ -1156,13 +1142,6 @@ ephy_embed_get_navigation_flags (EphyEmbed *embed) return iface->get_navigation_flags (embed); } -void -ephy_embed_update_navigation_flags (EphyEmbed *embed) -{ - EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - return iface->update_navigation_flags (embed); -} - /** * ephy_embed_get_typed_address: * @embed: an #EphyEmbed @@ -1195,8 +1174,8 @@ ephy_embed_get_typed_address (EphyEmbed *embed) **/ void ephy_embed_set_typed_address (EphyEmbed *embed, - const char *address, - EphyEmbedAddressExpire expire) + const char *address, + EphyEmbedAddressExpire expire) { EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); return iface->set_typed_address (embed, address, expire); @@ -1217,11 +1196,3 @@ ephy_embed_get_address (EphyEmbed *embed) return iface->get_address (embed); } -void -ephy_embed_set_address (EphyEmbed *embed, - char *address) -{ - EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - return iface->set_address (embed, address); -} - diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index b56bfe964..7dffe063d 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -244,17 +244,13 @@ struct _EphyEmbedIface void (* close) (EphyEmbed *embed); EphyEmbedDocumentType (* get_document_type) (EphyEmbed *embed); int (* get_load_percent) (EphyEmbed *embed); - void (* set_load_percent) (EphyEmbed *embed, int percent); gboolean (* get_load_status) (EphyEmbed *embed); - void (* set_load_status) (EphyEmbed *embed, gboolean percent); - void (* update_navigation_flags) (EphyEmbed *embed); EphyEmbedNavigationFlags (* get_navigation_flags) (EphyEmbed *embed); const char * (* get_typed_address) (EphyEmbed *embed); void (* set_typed_address) (EphyEmbed *embed, const char *address, EphyEmbedAddressExpire expire); - const char * (* get_address) (EphyEmbed *embed); - void (* set_address) (EphyEmbed *embed, char *address); + const char * (* get_address) (EphyEmbed *embed); }; GType ephy_embed_net_state_get_type (void); @@ -352,15 +348,12 @@ EphyEmbedDocumentType ephy_embed_get_document_type (EphyEmbed *embed); /* Progress */ int ephy_embed_get_load_percent (EphyEmbed *embed); -void ephy_embed_set_load_percent (EphyEmbed *embed, int percent); /* FIXME: remove me */ /* Load status */ gboolean ephy_embed_get_load_status (EphyEmbed *embed); -void ephy_embed_set_load_status (EphyEmbed *embed, gboolean status); /* FIXME: remove me */ /* Navigation flags */ -void ephy_embed_update_navigation_flags (EphyEmbed *embed); /* FIXME: remove me */ EphyEmbedNavigationFlags ephy_embed_get_navigation_flags (EphyEmbed *embed); /* Typed address */ @@ -369,8 +362,7 @@ void ephy_embed_set_typed_address (EphyEmbed *embed, const char *address, EphyEmbedAddressExpire expire); /* Address */ -const char * ephy_embed_get_address (EphyEmbed *embed); -void ephy_embed_set_address (EphyEmbed *embed, char *address); /* FIXME: remove me */ +const char * ephy_embed_get_address (EphyEmbed *embed); /* Encoding */ char *ephy_embed_get_encoding (EphyEmbed *embed); diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index d0601b170..2031ae9df 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -33,6 +33,10 @@ #include <nsIWebProgressListener.h> #include <nsMemory.h> +#include <glib/gi18n.h> +#include <libgnomevfs/gnome-vfs.h> +#include <libgnomevfs/gnome-vfs-uri.h> + #include "EphyBrowser.h" #include "EphyUtils.h" #include "EventContext.h" @@ -83,6 +87,10 @@ static void mozilla_embed_document_type_cb (EphyEmbed *embed, static void mozilla_embed_zoom_change_cb (EphyEmbed *embed, float zoom, MozillaEmbed *membed); +static void mozilla_embed_title_change_cb (EphyEmbed *embed, + MozillaEmbed *membed); +static void mozilla_embed_set_title (MozillaEmbed *embed, + char *title); static void impl_set_typed_address (EphyEmbed *embed, const char *address, EphyEmbedAddressExpire expire); @@ -99,6 +107,8 @@ typedef enum MOZILLA_EMBED_LOAD_STOPPED } MozillaEmbedLoadState; +#define MAX_TITLE_LENGTH 512 /* characters */ + struct MozillaEmbedPrivate { EphyBrowser *browser; @@ -113,12 +123,18 @@ struct MozillaEmbedPrivate float zoom; /* Flags */ + guint is_blank : 1; guint is_loading : 1; guint is_setting_zoom : 1; gint8 load_percent; char *address; char *typed_address; + char *title; + char *loading_title; + int cur_requests; + int total_requests; + char *status_message; }; #define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1" @@ -132,6 +148,7 @@ enum PROP_LOAD_STATUS, PROP_NAVIGATION, PROP_SECURITY, + PROP_TITLE, PROP_TYPED_ADDRESS, PROP_ZOOM }; @@ -258,6 +275,9 @@ mozilla_embed_get_property (GObject *object, case PROP_NAVIGATION: g_value_set_flags (value, priv->nav_flags); break; + case PROP_TITLE: + g_value_set_string (value, priv->title); + break; case PROP_TYPED_ADDRESS: g_value_set_string (value, priv->typed_address); break; @@ -320,6 +340,9 @@ mozilla_embed_class_init (MozillaEmbedClass *klass) g_object_class_override_property (object_class, PROP_LOAD_PROGRESS, "load-progress"); g_object_class_override_property (object_class, PROP_LOAD_STATUS, "load-status"); g_object_class_override_property (object_class, PROP_NAVIGATION, "navigation"); + g_object_class_override_property (object_class, PROP_ADDRESS, "address"); + g_object_class_override_property (object_class, PROP_TYPED_ADDRESS, "typed-address"); + g_object_class_override_property (object_class, PROP_TITLE, "title"); g_type_class_add_private (object_class, sizeof(MozillaEmbedPrivate)); } @@ -358,6 +381,9 @@ mozilla_embed_init (MozillaEmbed *embed) g_signal_connect_object (embed, "ge_zoom_change", G_CALLBACK (mozilla_embed_zoom_change_cb), embed, (GConnectFlags) 0); + g_signal_connect_object (embed, "title", + G_CALLBACK (mozilla_embed_title_change_cb), + embed, (GConnectFlags) 0); priv->document_type = EPHY_EMBED_DOCUMENT_HTML; priv->security_level = EPHY_EMBED_STATE_IS_UNKNOWN; @@ -366,7 +392,13 @@ mozilla_embed_init (MozillaEmbed *embed) priv->load_percent = 0; priv->is_loading = FALSE; priv->typed_address = NULL; + priv->address = NULL; priv->address_expire = EPHY_EMBED_ADDRESS_EXPIRE_NOW; + priv->title = NULL; + priv->loading_title = NULL; + priv->is_blank = TRUE; + priv->total_requests = 0; + priv->cur_requests = 0; } gpointer @@ -403,6 +435,8 @@ mozilla_embed_finalize (GObject *object) g_free (embed->priv->address); g_free (embed->priv->typed_address); + g_free (embed->priv->title); + g_free (embed->priv->loading_title); G_OBJECT_CLASS (mozilla_embed_parent_class)->finalize (object); @@ -957,9 +991,9 @@ impl_get_load_percent (EphyEmbed *embed) } static void -impl_set_load_percent (EphyEmbed *embed, int percent) +mozilla_embed_set_load_percent (MozillaEmbed *embed, int percent) { - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (embed)->priv; + MozillaEmbedPrivate *mpriv = embed->priv; if (percent != mpriv->load_percent) { @@ -978,9 +1012,9 @@ impl_get_load_status (EphyEmbed *embed) } static void -impl_set_load_status (EphyEmbed *embed, gboolean status) +mozilla_embed_set_load_status (MozillaEmbed *embed, gboolean status) { - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (embed)->priv; + MozillaEmbedPrivate *mpriv = embed->priv; guint is_loading; is_loading = status != FALSE; @@ -994,22 +1028,23 @@ impl_set_load_status (EphyEmbed *embed, gboolean status) } static void -impl_update_navigation_flags (EphyEmbed *embed) +mozilla_embed_update_navigation_flags (MozillaEmbed *membed) { - MozillaEmbedPrivate *priv = MOZILLA_EMBED (embed)->priv; + MozillaEmbedPrivate *priv = membed->priv; + EphyEmbed *embed = EPHY_EMBED (membed); guint flags = 0; - if (ephy_embed_can_go_up (embed)) + if (impl_can_go_up (embed)) { flags |= EPHY_EMBED_NAV_UP; } - if (ephy_embed_can_go_back (embed)) + if (impl_can_go_back (embed)) { flags |= EPHY_EMBED_NAV_BACK; } - if (ephy_embed_can_go_forward (embed)) + if (impl_can_go_forward (embed)) { flags |= EPHY_EMBED_NAV_FORWARD; } @@ -1067,18 +1102,16 @@ impl_get_address (EphyEmbed *embed) } static void -impl_set_address (EphyEmbed *embed, char *address) +mozilla_embed_set_address (MozillaEmbed *embed, char *address) { - MozillaEmbedPrivate *priv = MOZILLA_EMBED (embed)->priv; + MozillaEmbedPrivate *priv = embed->priv; GObject *object = G_OBJECT (embed); g_free (priv->address); priv->address = address; -#if 0 priv->is_blank = address == NULL || strcmp (address, "about:blank") == 0; -#endif if (priv->is_loading && priv->address_expire == EPHY_EMBED_ADDRESS_EXPIRE_NOW && @@ -1217,6 +1250,187 @@ update_load_state (MozillaEmbed *membed, gint state) } static void +update_net_state_message (MozillaEmbed *embed, const char *uri, EphyEmbedNetState flags) +{ + GnomeVFSURI *vfs_uri = NULL; + const char *msg = NULL; + const char *host = NULL; + + if (uri != NULL) + { + vfs_uri = gnome_vfs_uri_new (uri); + } + + if (vfs_uri != NULL) + { + host = gnome_vfs_uri_get_host_name (vfs_uri); + } + + if (host == NULL || host[0] == '\0') goto out; + + /* IS_REQUEST and IS_NETWORK can be both set */ + if (flags & EPHY_EMBED_STATE_IS_REQUEST) + { + if (flags & EPHY_EMBED_STATE_REDIRECTING) + { + msg = _("Redirecting to “%s”…"); + } + else if (flags & EPHY_EMBED_STATE_TRANSFERRING) + { + msg = _("Transferring data from “%s”…"); + } + else if (flags & EPHY_EMBED_STATE_NEGOTIATING) + { + msg = _("Waiting for authorization from “%s”…"); + } + } + + if (flags & EPHY_EMBED_STATE_IS_NETWORK) + { + if (flags & EPHY_EMBED_STATE_START) + { + msg = _("Loading “%s”…"); + } + } + + if ((flags & EPHY_EMBED_STATE_IS_NETWORK) && + (flags & EPHY_EMBED_STATE_STOP)) + { + g_free (embed->priv->status_message); + embed->priv->status_message = NULL; + g_object_notify (G_OBJECT (embed), "message"); + + } + else if (msg != NULL) + { + g_free (embed->priv->status_message); + g_free (embed->priv->loading_title); + embed->priv->status_message = g_strdup_printf (msg, host); + embed->priv->loading_title = g_strdup_printf (msg, host); + g_object_notify (G_OBJECT (embed), "message"); + g_object_notify (G_OBJECT (embed), "title"); + } + +out: + if (vfs_uri != NULL) + { + gnome_vfs_uri_unref (vfs_uri); + } +} + +static int +build_load_percent (int requests_done, int requests_total) +{ + int percent= 0; + + if (requests_total > 0) + { + percent = (requests_done * 100) / requests_total; + + /* Mozilla sometimes report more done requests than + total requests. Their progress widget clamp the value */ + percent = CLAMP (percent, 0, 100); + } + + return percent; +} + +static void +build_progress_from_requests (MozillaEmbed *embed, EphyEmbedNetState state) +{ + int load_percent; + + if (state & EPHY_EMBED_STATE_IS_REQUEST) + { + if (state & EPHY_EMBED_STATE_START) + { + embed->priv->total_requests ++; + } + else if (state & EPHY_EMBED_STATE_STOP) + { + embed->priv->cur_requests ++; + } + + load_percent = build_load_percent (embed->priv->cur_requests, + embed->priv->total_requests); + + mozilla_embed_set_load_percent (embed, load_percent); + } +} + +static void +ensure_page_info (MozillaEmbed *embed, const char *address) +{ + MozillaEmbedPrivate *priv = embed->priv; + + if ((priv->address == NULL || priv->address[0] == '\0') && + priv->address_expire == EPHY_EMBED_ADDRESS_EXPIRE_NOW) + { + mozilla_embed_set_address (embed, g_strdup (address)); + } + + /* FIXME huh?? */ + if (priv->title == NULL || priv->title[0] == '\0') + { + mozilla_embed_set_title (embed, NULL); + } +} + +static void +update_embed_from_net_state (MozillaEmbed *embed, + const char *uri, + EphyEmbedNetState state) +{ + MozillaEmbedPrivate *priv = embed->priv; + + update_net_state_message (embed, uri, state); + + if (state & EPHY_EMBED_STATE_IS_NETWORK) + { + if (state & EPHY_EMBED_STATE_START) + { + GObject *object = G_OBJECT (embed); + + g_object_freeze_notify (object); + + priv->total_requests = 0; + priv->cur_requests = 0; + + mozilla_embed_set_load_percent (embed, 0); + mozilla_embed_set_load_status (embed, TRUE); + + ensure_page_info (embed, uri); + + g_object_notify (object, "title"); + + g_object_thaw_notify (object); + } + else if (state & EPHY_EMBED_STATE_STOP) + { + GObject *object = G_OBJECT (embed); + + g_object_freeze_notify (object); + + mozilla_embed_set_load_percent (embed, 100); + mozilla_embed_set_load_status (embed, FALSE); + + g_free (priv->loading_title); + priv->loading_title = NULL; + + priv->address_expire = EPHY_EMBED_ADDRESS_EXPIRE_NOW; + + g_object_notify (object, "title"); + + g_object_thaw_notify (object); + } + + mozilla_embed_update_navigation_flags (embed); + } + + build_progress_from_requests (embed, state); +} + +static void mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, const char *aURI, gint state, guint status, MozillaEmbed *membed) @@ -1252,6 +1466,7 @@ mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, const char *aURI, } update_load_state (membed, state); + update_embed_from_net_state (membed, aURI, (EphyEmbedNetState)state); g_signal_emit_by_name (membed, "ge_net_state", aURI, /* FIXME: (gulong) */ estate); } @@ -1478,6 +1693,107 @@ mozilla_embed_zoom_change_cb (EphyEmbed *embed, } } +static char * +get_title_from_address (const char *address) +{ + GnomeVFSURI *uri; + char *title; + + if (address == NULL) return NULL; + + uri = gnome_vfs_uri_new (address); + if (uri == NULL) return g_strdup (address); + + title = gnome_vfs_uri_to_string (uri, + (GnomeVFSURIHideOptions) + (GNOME_VFS_URI_HIDE_USER_NAME | + GNOME_VFS_URI_HIDE_PASSWORD | + GNOME_VFS_URI_HIDE_HOST_PORT | + GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD | + GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER)); + gnome_vfs_uri_unref (uri); + + return title; +} + +static void +mozilla_embed_set_loading_title (MozillaEmbed *embed, + const char *title, + gboolean is_address) +{ + MozillaEmbedPrivate *priv = embed->priv; + char *freeme = NULL; + + g_free (priv->loading_title); + priv->loading_title = NULL; + + if (is_address) + { + title = freeme = get_title_from_address (title); + } + + if (title != NULL && title[0] != '\0') + { + /* translators: %s here is the address of the web page */ + priv->loading_title = g_strdup_printf (_("Loading “%s”…"), title); + } + else + { + priv->loading_title = g_strdup (_("Loading…")); + } + + g_free (freeme); +} + +static void +mozilla_embed_set_title (MozillaEmbed *embed, + char *title) +{ + MozillaEmbedPrivate *priv = embed->priv; + + if (!priv->is_blank && (title == NULL || g_strstrip (title)[0] == '\0')) + { + + g_free (title); + title = get_title_from_address (priv->address); + + /* Fallback */ + if (title == NULL || title[0] == '\0') + { + g_free (title); + title = NULL; + priv->is_blank = TRUE; + } + } + else if (priv->is_blank && title != NULL) + { + g_free (title); + title = NULL; + } + + g_free (priv->title); + priv->title = ephy_string_shorten (title, MAX_TITLE_LENGTH); + + g_object_notify (G_OBJECT (embed), "title"); +} + +static void +mozilla_embed_title_change_cb (EphyEmbed *embed, + MozillaEmbed *membed) +{ + GObject *object = G_OBJECT (embed); + char *title; + + title = gtk_moz_embed_get_title (GTK_MOZ_EMBED (embed)); + + g_object_freeze_notify (object); + + mozilla_embed_set_title (membed, title); + mozilla_embed_set_loading_title (membed, title, FALSE); + + g_object_thaw_notify (object); +} + static EphyEmbedSecurityLevel mozilla_embed_security_level (PRUint32 state) { @@ -1551,15 +1867,11 @@ ephy_embed_iface_init (EphyEmbedIface *iface) iface->has_modified_forms = impl_has_modified_forms; iface->get_document_type = impl_get_document_type; iface->get_load_percent = impl_get_load_percent; - iface->set_load_percent = impl_set_load_percent; iface->get_load_status = impl_get_load_status; - iface->set_load_status = impl_set_load_status; - iface->update_navigation_flags = impl_update_navigation_flags; iface->get_navigation_flags = impl_get_navigation_flags; iface->get_typed_address = impl_get_typed_address; iface->set_typed_address = impl_set_typed_address; iface->get_address = impl_get_address; - iface->set_address = impl_set_address; } static void diff --git a/src/ephy-tab.c b/src/ephy-tab.c index bcd109e20..58637ab5b 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -75,7 +75,6 @@ #define MAX_HIDDEN_POPUPS 5 #define RELOAD_DELAY 250 /* ms */ #define RELOAD_DELAY_MAX_TICKS 40 /* RELOAD_DELAY * RELOAD_DELAY_MAX_TICKS = 10 s */ -#define MAX_TITLE_LENGTH 512 /* characters */ struct _EphyTabPrivate { @@ -83,21 +82,14 @@ struct _EphyTabPrivate char *status_message; char *link_message; - char *title; - char *loading_title; char *icon_address; GdkPixbuf *icon; - int cur_requests; - int total_requests; int width; int height; GSList *hidden_popups; GSList *shown_popups; guint idle_resize_handler; - /* Flags */ - guint is_blank : 1; - /* File watch */ GnomeVFSMonitorHandle *monitor; guint reload_scheduled_id; @@ -117,7 +109,6 @@ enum PROP_MESSAGE, PROP_HIDDEN_POPUP_COUNT, PROP_POPUPS_ALLOWED, - PROP_TITLE }; typedef struct @@ -140,9 +131,6 @@ static guint n_tabs = 0; /* internal functions, accessible only from this file */ static void ephy_tab_set_link_message (EphyTab *tab, char *message); -static void ephy_tab_set_title (EphyTab *tab, - EphyEmbed *embed, - char *new_title); static guint popup_blocker_n_hidden (EphyTab *tab); static gboolean ephy_tab_get_popups_allowed (EphyTab *tab); static void ephy_tab_set_popups_allowed (EphyTab *tab, @@ -210,7 +198,6 @@ ephy_tab_set_property (GObject *object, case PROP_ICON: case PROP_MESSAGE: case PROP_HIDDEN_POPUP_COUNT: - case PROP_TITLE: /* read only */ break; } @@ -243,9 +230,6 @@ ephy_tab_get_property (GObject *object, g_value_set_boolean (value, ephy_tab_get_popups_allowed (tab)); break; - case PROP_TITLE: - g_value_set_string (value, priv->title); - break; } } @@ -380,14 +364,6 @@ ephy_tab_class_init (EphyTabClass *class) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_class_install_property (object_class, - PROP_TITLE, - g_param_spec_string ("title", - "Title", - "The tab's title", - _("Blank page"), - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_type_class_add_private (object_class, sizeof (EphyTabPrivate)); } @@ -709,8 +685,6 @@ ephy_tab_finalize (GObject *object) priv->icon = NULL; } - g_free (priv->title); - g_free (priv->loading_title); g_free (priv->icon_address); g_free (priv->link_message); g_free (priv->status_message); @@ -762,58 +736,6 @@ let_me_resize_hack (EphyTab *tab) return FALSE; } - -static char * -get_title_from_address (const char *address) -{ - GnomeVFSURI *uri; - char *title; - - if (address == NULL) return NULL; - - uri = gnome_vfs_uri_new (address); - if (uri == NULL) return g_strdup (address); - - title = gnome_vfs_uri_to_string (uri, - GNOME_VFS_URI_HIDE_USER_NAME | - GNOME_VFS_URI_HIDE_PASSWORD | - GNOME_VFS_URI_HIDE_HOST_PORT | - GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD | - GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER); - gnome_vfs_uri_unref (uri); - - return title; -} - -static void -ephy_tab_set_loading_title (EphyTab *tab, - const char *title, - gboolean is_address) -{ - EphyTabPrivate *priv = tab->priv; - char *freeme = NULL; - - g_free (priv->loading_title); - priv->loading_title = NULL; - - if (is_address) - { - title = freeme = get_title_from_address (title); - } - - if (title != NULL && title[0] != '\0') - { - /* translators: %s here is the address of the web page */ - priv->loading_title = g_strdup_printf (_("Loading “%s”…"), title); - } - else - { - priv->loading_title = g_strdup (_("Loading…")); - } - - g_free (freeme); -} - /* Public functions */ /** @@ -1319,14 +1241,15 @@ ephy_tab_open_uri_cb (EphyEmbed *embed, */ if (priv->is_blank) { - ephy_tab_set_address (tab, g_strdup (uri)); - ephy_tab_set_loading_title (tab, uri, TRUE); + ephy_embed_set_address (embed, g_strdup (uri)); + ephy_embed_set_loading_title (embed, uri, TRUE); } /* allow load to proceed */ return FALSE; } +#if 0 static void ephy_tab_address_cb (EphyEmbed *embed, const char *address, @@ -1367,6 +1290,7 @@ ephy_tab_address_cb (EphyEmbed *embed, g_object_thaw_notify (object); } +#endif static void ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) @@ -1376,204 +1300,6 @@ ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) } static void -ephy_tab_title_cb (EphyEmbed *embed, - EphyTab *tab) -{ - EphyTabPrivate *priv = tab->priv; - GObject *object = G_OBJECT (tab); - - g_object_freeze_notify (object); - - ephy_tab_set_title (tab, embed, ephy_embed_get_title (embed)); - - ephy_tab_set_loading_title (tab, priv->title, FALSE); - - g_object_thaw_notify (object); -} - -static int -build_load_percent (int requests_done, int requests_total) -{ - int percent= 0; - - if (requests_total > 0) - { - percent = (requests_done * 100) / requests_total; - - /* Mozilla sometimes report more done requests than - total requests. Their progress widget clamp the value */ - percent = CLAMP (percent, 0, 100); - } - - return percent; -} - -static void -update_net_state_message (EphyTab *tab, const char *uri, EphyEmbedNetState flags) -{ - GnomeVFSURI *vfs_uri = NULL; - const char *msg = NULL; - const char *host = NULL; - - if (uri != NULL) - { - vfs_uri = gnome_vfs_uri_new (uri); - } - - if (vfs_uri != NULL) - { - host = gnome_vfs_uri_get_host_name (vfs_uri); - } - - if (host == NULL || host[0] == '\0') goto out; - - /* IS_REQUEST and IS_NETWORK can be both set */ - if (flags & EPHY_EMBED_STATE_IS_REQUEST) - { - if (flags & EPHY_EMBED_STATE_REDIRECTING) - { - msg = _("Redirecting to “%s”…"); - } - else if (flags & EPHY_EMBED_STATE_TRANSFERRING) - { - msg = _("Transferring data from “%s”…"); - } - else if (flags & EPHY_EMBED_STATE_NEGOTIATING) - { - msg = _("Waiting for authorization from “%s”…"); - } - } - - if (flags & EPHY_EMBED_STATE_IS_NETWORK) - { - if (flags & EPHY_EMBED_STATE_START) - { - msg = _("Loading “%s”…"); - } - } - - if ((flags & EPHY_EMBED_STATE_IS_NETWORK) && - (flags & EPHY_EMBED_STATE_STOP)) - { - g_free (tab->priv->status_message); - tab->priv->status_message = NULL; - g_object_notify (G_OBJECT (tab), "message"); - - } - else if (msg != NULL) - { - g_free (tab->priv->status_message); - g_free (tab->priv->loading_title); - tab->priv->status_message = g_strdup_printf (msg, host); - tab->priv->loading_title = g_strdup_printf (msg, host); - g_object_notify (G_OBJECT (tab), "message"); - g_object_notify (G_OBJECT (tab), "title"); - } - -out: - if (vfs_uri != NULL) - { - gnome_vfs_uri_unref (vfs_uri); - } -} - -static void -build_progress_from_requests (EphyTab *tab, EphyEmbedNetState state) -{ - int load_percent; - - if (state & EPHY_EMBED_STATE_IS_REQUEST) - { - if (state & EPHY_EMBED_STATE_START) - { - tab->priv->total_requests ++; - } - else if (state & EPHY_EMBED_STATE_STOP) - { - tab->priv->cur_requests ++; - } - - load_percent = build_load_percent (tab->priv->cur_requests, - tab->priv->total_requests); - - ephy_embed_set_load_percent (ephy_tab_get_embed (tab), load_percent); - } -} - -static void -ensure_page_info (EphyTab *tab, EphyEmbed *embed, const char *address) -{ - EphyTabPrivate *priv = tab->priv; - - if ((priv->address == NULL || priv->address[0] == '\0') && - priv->address_expire == EPHY_TAB_ADDRESS_EXPIRE_NOW) - { - ephy_tab_set_address (tab, g_strdup (address)); - } - - /* FIXME huh?? */ - if (tab->priv->title == NULL || tab->priv->title[0] == '\0') - { - ephy_tab_set_title (tab, embed, NULL); - } -} - -static void -ephy_tab_net_state_cb (EphyEmbed *embed, - const char *uri, - EphyEmbedNetState state, - EphyTab *tab) -{ - EphyTabPrivate *priv = tab->priv; - - update_net_state_message (tab, uri, state); - - if (state & EPHY_EMBED_STATE_IS_NETWORK) - { - if (state & EPHY_EMBED_STATE_START) - { - GObject *object = G_OBJECT (tab); - - g_object_freeze_notify (object); - - priv->total_requests = 0; - priv->cur_requests = 0; - - ephy_embed_set_load_percent (embed, 0); - ephy_embed_set_load_status (embed, TRUE); - ephy_embed_update_navigation_flags (embed); - - ensure_page_info (tab, embed, uri); - - g_object_notify (object, "title"); - - g_object_thaw_notify (object); - } - else if (state & EPHY_EMBED_STATE_STOP) - { - GObject *object = G_OBJECT (tab); - - g_object_freeze_notify (object); - - ephy_embed_set_load_percent (ephy_tab_get_embed (tab), 100); - ephy_embed_set_load_status (embed, FALSE); - ephy_embed_update_navigation_flags (embed); - - g_free (priv->loading_title); - priv->loading_title = NULL; - - priv->address_expire = EPHY_TAB_ADDRESS_EXPIRE_NOW; - - g_object_notify (object, "title"); - - g_object_thaw_notify (object); - } - } - - build_progress_from_requests (tab, state); -} - -static void ephy_tab_new_window_cb (EphyEmbed *embed, EphyEmbed *new_embed, EphyTab *tab) @@ -1809,17 +1535,10 @@ ephy_tab_init (EphyTab *tab) g_array_index (tabs_id_array, gpointer, id) = tab; } - tab->priv->total_requests = 0; - tab->priv->cur_requests = 0; tab->priv->width = -1; tab->priv->height = -1; - priv->title = NULL; - priv->is_blank = TRUE; priv->icon_address = NULL; priv->icon = NULL; - priv->address = NULL; - priv->title = NULL; - priv->loading_title = NULL; priv->reload_delay_ticks = 0; embed = ephy_embed_factory_new_object (EPHY_TYPE_EMBED); @@ -1837,12 +1556,6 @@ ephy_tab_init (EphyTab *tab) g_signal_connect_object (embed, "ge_location", G_CALLBACK (ephy_tab_address_cb), tab, 0); - g_signal_connect_object (embed, "title", - G_CALLBACK (ephy_tab_title_cb), - tab, 0); - g_signal_connect_object (embed, "ge_net_state", - G_CALLBACK (ephy_tab_net_state_cb), - tab, 0); g_signal_connect_object (embed, "ge_new_window", G_CALLBACK (ephy_tab_new_window_cb), tab, 0); @@ -1902,39 +1615,6 @@ ephy_tab_get_status_message (EphyTab *tab) } } -static void -ephy_tab_set_title (EphyTab *tab, - EphyEmbed *embed, - char *title) -{ - EphyTabPrivate *priv = tab->priv; - - if (!priv->is_blank && (title == NULL || g_strstrip (title)[0] == '\0')) - { - - g_free (title); - title = get_title_from_address (priv->address); - - /* Fallback */ - if (title == NULL || title[0] == '\0') - { - g_free (title); - title = NULL; - priv->is_blank = TRUE; - } - } - else if (priv->is_blank && title != NULL) - { - g_free (title); - title = NULL; - } - - g_free (priv->title); - priv->title = ephy_string_shorten (title, MAX_TITLE_LENGTH); - - g_object_notify (G_OBJECT (tab), "title"); -} - /** * ephy_tab_get_title_composite: * @tab: an #EphyTab @@ -1976,36 +1656,6 @@ ephy_tab_get_title_composite (EphyTab *tab) return title != NULL ? title : ""; } -/** - * ephy_tab_get_title: - * @tab: an #EphyTab - * - * Returns the title of the web page loaded in @tab. - * - * Return value: @tab's loaded web page's title. Will never be %NULL. - **/ -const char * -ephy_tab_get_title (EphyTab *tab) -{ - EphyTabPrivate *priv; - const char *title = ""; - - g_return_val_if_fail (EPHY_IS_TAB (tab), NULL); - - priv = tab->priv; - - if (priv->is_blank) - { - title = _("Blank page"); - } - else - { - title = priv->title; - } - - return title != NULL ? title : ""; -} - /* private */ guint _ephy_tab_get_id (EphyTab *tab) |