aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--embed/ephy-history-item.c6
-rw-r--r--embed/ephy-history-item.h8
-rw-r--r--embed/mozilla/mozilla-embed.cpp35
-rw-r--r--embed/mozilla/mozilla-embed.h9
-rw-r--r--embed/mozilla/mozilla-history-item.cpp91
-rw-r--r--embed/mozilla/mozilla-history-item.h7
-rw-r--r--src/ephy-navigation-action.c11
7 files changed, 116 insertions, 51 deletions
diff --git a/embed/ephy-history-item.c b/embed/ephy-history-item.c
index 83703943c..f5089b294 100644
--- a/embed/ephy-history-item.c
+++ b/embed/ephy-history-item.c
@@ -18,6 +18,8 @@
*
*/
+#include "config.h"
+
#include "ephy-history-item.h"
GType
@@ -41,14 +43,14 @@ ephy_history_item_get_type (void)
return type;
}
-const char*
+char*
ephy_history_item_get_url (EphyHistoryItem *item)
{
EphyHistoryItemIface *iface = EPHY_HISTORY_ITEM_GET_IFACE (item);
return iface->get_url (item);
}
-const char*
+char*
ephy_history_item_get_title (EphyHistoryItem *item)
{
EphyHistoryItemIface *iface = EPHY_HISTORY_ITEM_GET_IFACE (item);
diff --git a/embed/ephy-history-item.h b/embed/ephy-history-item.h
index 153dcb745..7ec7871d5 100644
--- a/embed/ephy-history-item.h
+++ b/embed/ephy-history-item.h
@@ -40,13 +40,13 @@ struct _EphyHistoryItemIface
{
GTypeInterface base_iface;
- const char * (* get_url) (EphyHistoryItem *item);
- const char * (* get_title) (EphyHistoryItem *item);
+ char * (* get_url) (EphyHistoryItem *item);
+ char * (* get_title) (EphyHistoryItem *item);
};
GType ephy_history_item_get_type (void);
-const char* ephy_history_item_get_url (EphyHistoryItem *item);
-const char* ephy_history_item_get_title (EphyHistoryItem *item);
+char* ephy_history_item_get_url (EphyHistoryItem *item);
+char* ephy_history_item_get_title (EphyHistoryItem *item);
G_END_DECLS
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index ad52392fb..b9badb6b2 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -880,37 +880,14 @@ impl_has_modified_forms (EphyEmbed *embed)
static EphyHistoryItem*
mozilla_get_nth_history_item (MozillaEmbed *embed,
gboolean is_relative,
- int absolute_nth)
+ int nth)
{
- char *url = NULL, *title = NULL;
- nsresult rv;
- nsCString nsUrl;
- PRUnichar *nsTitle;
- int nth = absolute_nth;
- MozillaEmbedPrivate *mpriv = embed->priv;
-
if (is_relative)
{
nth += impl_shistory_get_pos (EPHY_EMBED (embed));
}
- rv = mpriv->browser->GetSHUrlAtIndex(nth, nsUrl);
-
- if (NS_SUCCEEDED (rv) && nsUrl.Length())
- url = g_strdup(nsUrl.get());
-
- rv = mpriv->browser->GetSHTitleAtIndex(nth, &nsTitle);
-
- if (NS_SUCCEEDED (rv) && nsTitle)
- {
- nsCString cTitle;
- NS_UTF16ToCString (nsString(nsTitle),
- NS_CSTRING_ENCODING_UTF8, cTitle);
- title = g_strdup (cTitle.get());
- nsMemory::Free (nsTitle);
- }
-
- return (EphyHistoryItem*)mozilla_history_item_new (url, title, absolute_nth);
+ return (EphyHistoryItem*)mozilla_history_item_new (embed, nth);
}
static GList*
@@ -1572,3 +1549,11 @@ _mozilla_embed_new_xul_dialog (void)
return GTK_MOZ_EMBED (embed);
}
+
+EphyBrowser*
+_mozilla_embed_get_browser (MozillaEmbed *embed)
+{
+ g_return_val_if_fail (MOZILLA_IS_EMBED (embed), NULL);
+
+ return embed->priv->browser;
+}
diff --git a/embed/mozilla/mozilla-embed.h b/embed/mozilla/mozilla-embed.h
index 21ddaf466..28fcecb41 100644
--- a/embed/mozilla/mozilla-embed.h
+++ b/embed/mozilla/mozilla-embed.h
@@ -29,6 +29,13 @@
#include "ephy-embed.h"
#include "ephy-base-embed.h"
+#ifdef __cplusplus
+#include "EphyBrowser.h"
+#else
+/* can't include C++ headers from outside embed/mozilla */
+typedef struct _EphyBrowser EphyBrowser;
+#endif
+
G_BEGIN_DECLS
#define MOZILLA_TYPE_EMBED (mozilla_embed_get_type ())
@@ -65,6 +72,8 @@ GtkMozEmbed *_mozilla_embed_new_xul_dialog (void);
EphyEmbedChrome _mozilla_embed_translate_chrome (GtkMozEmbedChromeFlags flags);
+EphyBrowser *_mozilla_embed_get_browser (MozillaEmbed *embed);
+
G_END_DECLS
#endif
diff --git a/embed/mozilla/mozilla-history-item.cpp b/embed/mozilla/mozilla-history-item.cpp
index 570b2fbe0..b312fd912 100644
--- a/embed/mozilla/mozilla-history-item.cpp
+++ b/embed/mozilla/mozilla-history-item.cpp
@@ -1,18 +1,83 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright © 2007 Xan Lopez
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mozilla-config.h"
+#include "config.h"
+
#include "mozilla-history-item.h"
#include "ephy-history-item.h"
+#include "EphyBrowser.h"
+
+#include <nsStringAPI.h>
+#include <nsMemory.h>
static void mozilla_history_item_finalize (GObject *object);
-static const char*
+static char*
impl_get_url (EphyHistoryItem *item)
{
- return MOZILLA_HISTORY_ITEM (item)->url;
+ char *url = NULL;
+ nsresult rv;
+ nsCString nsUrl;
+ MozillaHistoryItem *mitem = MOZILLA_HISTORY_ITEM (item);
+
+ if (!mitem->embed)
+ return NULL;
+
+ EphyBrowser *browser = (EphyBrowser*)_mozilla_embed_get_browser (mitem->embed);
+
+ rv = browser->GetSHUrlAtIndex(mitem->nth, nsUrl);
+
+ if (NS_SUCCEEDED (rv) && nsUrl.Length()) {
+ url = g_strdup(nsUrl.get());
+ }
+
+ return url;
}
-static const char*
+static char*
impl_get_title (EphyHistoryItem *item)
{
- return MOZILLA_HISTORY_ITEM (item)->title;
+ char *title = NULL;
+ nsresult rv;
+ PRUnichar *nsTitle;
+
+ MozillaHistoryItem *mitem = MOZILLA_HISTORY_ITEM (item);
+
+ if (!mitem->embed)
+ return NULL;
+
+ EphyBrowser *browser = (EphyBrowser*)_mozilla_embed_get_browser (mitem->embed);
+
+ rv = browser->GetSHTitleAtIndex(mitem->nth, &nsTitle);
+
+ if (NS_SUCCEEDED (rv) && nsTitle)
+ {
+ nsCString cTitle;
+ NS_UTF16ToCString (nsString(nsTitle),
+ NS_CSTRING_ENCODING_UTF8, cTitle);
+ title = g_strdup (cTitle.get());
+ nsMemory::Free (nsTitle);
+ }
+
+ return title;
}
static void
@@ -42,26 +107,26 @@ mozilla_history_item_init (MozillaHistoryItem *self)
static void
mozilla_history_item_finalize (GObject *object)
{
- MozillaHistoryItem *self = (MozillaHistoryItem *)object;
+ MozillaHistoryItem *item = MOZILLA_HISTORY_ITEM (object);
+ MozillaEmbed **ptr = &item->embed;
- g_free (self->url);
- g_free (self->title);
+ g_object_remove_weak_pointer (G_OBJECT (item->embed),
+ (gpointer*)ptr);
G_OBJECT_CLASS (mozilla_history_item_parent_class)->finalize (object);
}
MozillaHistoryItem*
-mozilla_history_item_new (const char *url, const char *title, int index)
+mozilla_history_item_new (MozillaEmbed *embed, int index)
{
MozillaHistoryItem *item;
-
- g_return_val_if_fail (url != NULL, NULL);
- g_return_val_if_fail (title != NULL, NULL);
+ MozillaEmbed **ptr;
item = (MozillaHistoryItem*) g_object_new (MOZILLA_TYPE_HISTORY_ITEM, NULL);
+ item->embed = embed;
+ ptr = &item->embed;
- item->url = g_strdup (url);
- item->title = g_strdup (title);
+ g_object_add_weak_pointer (G_OBJECT (embed), (gpointer*)ptr);
item->nth = index;
return item;
diff --git a/embed/mozilla/mozilla-history-item.h b/embed/mozilla/mozilla-history-item.h
index de764a665..0e26f155e 100644
--- a/embed/mozilla/mozilla-history-item.h
+++ b/embed/mozilla/mozilla-history-item.h
@@ -4,6 +4,8 @@
#include <glib.h>
#include <glib-object.h>
+#include "mozilla-embed.h"
+
G_BEGIN_DECLS
#define MOZILLA_TYPE_HISTORY_ITEM (mozilla_history_item_get_type())
@@ -25,13 +27,12 @@ struct _MozillaHistoryItem
{
GObject parent_instance;
- char *url;
- char *title;
+ MozillaEmbed *embed;
int nth;
};
GType mozilla_history_item_get_type (void) G_GNUC_CONST;
-MozillaHistoryItem *mozilla_history_item_new (const char *url, const char *title, int index) G_GNUC_MALLOC;
+MozillaHistoryItem *mozilla_history_item_new (MozillaEmbed *embed, int index) G_GNUC_MALLOC;
G_END_DECLS
diff --git a/src/ephy-navigation-action.c b/src/ephy-navigation-action.c
index 415294710..e977a4e2a 100644
--- a/src/ephy-navigation-action.c
+++ b/src/ephy-navigation-action.c
@@ -170,11 +170,13 @@ select_menu_item_cb (GtkWidget *menuitem,
char *url;
GtkWidget *statusbar;
EphyHistoryItem *item;
+ char *freeme = NULL;
item = (EphyHistoryItem*)g_object_get_data (G_OBJECT (menuitem), HISTORY_ITEM_DATA_KEY);
if (item)
{
url = ephy_history_item_get_url (item);
+ freeme = url;
}
else
{
@@ -185,6 +187,8 @@ select_menu_item_cb (GtkWidget *menuitem,
statusbar = ephy_window_get_statusbar (action->priv->window);
gtk_statusbar_push (GTK_STATUSBAR (statusbar), action->priv->statusbar_cid, url);
+
+ g_free (freeme);
}
static void
@@ -239,7 +243,7 @@ build_back_or_forward_menu (EphyNavigationAction *action)
{
GtkWidget *item;
EphyHistoryItem *hitem;
- const char *title, *url;
+ char *title, *url;
hitem = (EphyHistoryItem*)list->data;
url = ephy_history_item_get_url (hitem);
@@ -247,12 +251,11 @@ build_back_or_forward_menu (EphyNavigationAction *action)
item = new_history_menu_item (title ? title : url, url);
+ g_free (title);
+
g_object_set_data_full (G_OBJECT (item), HISTORY_ITEM_DATA_KEY, hitem,
(GDestroyNotify) g_object_unref);
- g_object_set_data_full (G_OBJECT (item), URL_DATA_KEY, g_strdup (url),
- (GDestroyNotify) g_free);
-
g_signal_connect (item, "activate",
G_CALLBACK (activate_back_or_forward_menu_item_cb),
action);