aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/mozilla-history-item.cpp
diff options
context:
space:
mode:
authorXan Lopez <xan@src.gnome.org>2007-12-30 07:39:23 +0800
committerXan Lopez <xan@src.gnome.org>2007-12-30 07:39:23 +0800
commit2a776b7f4ea30e814b2703a50633143b5b0ebc95 (patch)
tree5bbcfc00e1a574c903b56dc4c2bce782bfe28d4a /embed/mozilla/mozilla-history-item.cpp
parent8fdb4086efaad93d0c9349520081a9608853fca0 (diff)
downloadgsoc2013-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/mozilla-history-item.cpp')
-rw-r--r--embed/mozilla/mozilla-history-item.cpp91
1 files changed, 78 insertions, 13 deletions
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;