diff options
author | Xan Lopez <xan@src.gnome.org> | 2007-12-30 07:39:23 +0800 |
---|---|---|
committer | Xan Lopez <xan@src.gnome.org> | 2007-12-30 07:39:23 +0800 |
commit | 2a776b7f4ea30e814b2703a50633143b5b0ebc95 (patch) | |
tree | 5bbcfc00e1a574c903b56dc4c2bce782bfe28d4a /embed/mozilla | |
parent | 8fdb4086efaad93d0c9349520081a9608853fca0 (diff) | |
download | gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.tar gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.tar.gz gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.tar.bz2 gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.tar.lz gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.tar.xz gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.tar.zst gsoc2013-epiphany-2a776b7f4ea30e814b2703a50633143b5b0ebc95.zip |
Make MozillaHistoryItem create url and title on demand.
Adapt code to the API change.
svn path=/trunk/; revision=7835
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 35 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.h | 9 | ||||
-rw-r--r-- | embed/mozilla/mozilla-history-item.cpp | 91 | ||||
-rw-r--r-- | embed/mozilla/mozilla-history-item.h | 7 |
4 files changed, 101 insertions, 41 deletions
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 |