aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorXan Lopez <xan@src.gnome.org>2007-12-30 00:59:00 +0800
committerXan Lopez <xan@src.gnome.org>2007-12-30 00:59:00 +0800
commiteeecbfedf3b0a9c1bdf3f17981dc885603d268af (patch)
tree234bcc4502a23b530fdb57805e1ca330716396e9 /embed
parent845fb8717fa53f67893f5f4b17bbdb711e11da2f (diff)
downloadgsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.tar
gsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.tar.gz
gsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.tar.bz2
gsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.tar.lz
gsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.tar.xz
gsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.tar.zst
gsoc2013-epiphany-eeecbfedf3b0a9c1bdf3f17981dc885603d268af.zip
Mozilla implementation of the embed history interfaces.
svn path=/trunk/; revision=7833
Diffstat (limited to 'embed')
-rw-r--r--embed/Makefile.am4
-rw-r--r--embed/mozilla/Makefile.am2
-rw-r--r--embed/mozilla/mozilla-embed.cpp109
-rw-r--r--embed/mozilla/mozilla-history-item.cpp69
-rw-r--r--embed/mozilla/mozilla-history-item.h39
5 files changed, 219 insertions, 4 deletions
diff --git a/embed/Makefile.am b/embed/Makefile.am
index 3deefb9bd..22c8b56be 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -17,8 +17,7 @@ NOINST_H_FILES = \
ephy-embed-dialog.h \
ephy-embed-find.h \
ephy-encodings.h \
- ephy-favicon-cache.h \
- ephy-history-item.h
+ ephy-favicon-cache.h
INST_H_FILES = \
ephy-adblock.h \
@@ -36,6 +35,7 @@ INST_H_FILES = \
ephy-embed-shell.h \
ephy-embed-utils.h \
ephy-history.h \
+ ephy-history-item.h \
ephy-password-manager.h \
ephy-permission-manager.h
diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am
index fe12e84dd..cf2259316 100644
--- a/embed/mozilla/Makefile.am
+++ b/embed/mozilla/Makefile.am
@@ -59,6 +59,8 @@ libephymozillaembed_la_SOURCES = \
mozilla-embed-persist.h \
mozilla-embed-single.cpp \
mozilla-embed-single.h \
+ mozilla-history-item.cpp \
+ mozilla-history-item.h \
mozilla-notifiers.cpp \
mozilla-notifiers.h
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index 40cc20ff9..ba1b589d8 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -41,12 +41,12 @@
#include "ephy-command-manager.h"
#include "ephy-debug.h"
+#include "mozilla-embed.h"
#include "ephy-embed-container.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
#include "mozilla-embed-event.h"
-
-#include "mozilla-embed.h"
+#include "mozilla-history-item.h"
static void mozilla_embed_class_init (MozillaEmbedClass *klass);
static void mozilla_embed_init (MozillaEmbed *gs);
@@ -877,6 +877,106 @@ impl_has_modified_forms (EphyEmbed *embed)
return NS_SUCCEEDED (rv) ? modified : FALSE;
}
+static EphyHistoryItem*
+mozilla_get_nth_history_item (MozillaEmbed *embed,
+ gboolean is_relative,
+ int absolute_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);
+}
+
+static GList*
+mozilla_construct_history_list (MozillaEmbed *embed, int start, int end)
+{
+ GList *list = NULL;
+ EphyHistoryItem *item;
+
+ while (start != end)
+ {
+ item = mozilla_get_nth_history_item (embed, FALSE, start);
+ list = g_list_prepend (list, item);
+
+ if (start < end)
+ start++;
+ else
+ start--;
+ }
+
+ return g_list_reverse (list);
+}
+
+static GList*
+impl_get_backward_history (EphyEmbed *embed)
+{
+ MozillaEmbed *membed = MOZILLA_EMBED (embed);
+ int start = impl_shistory_get_pos (embed) + -1;
+
+ return mozilla_construct_history_list (membed, start, -1);
+}
+
+static GList*
+impl_get_forward_history (EphyEmbed *embed)
+{
+ MozillaEmbed *membed = MOZILLA_EMBED (embed);
+ int start = impl_shistory_get_pos (embed) + 1;
+ int end = impl_shistory_n_items (embed);
+
+ return mozilla_construct_history_list (membed, start, end);
+}
+
+static EphyHistoryItem*
+impl_get_next_history_item (EphyEmbed *embed)
+{
+ return mozilla_get_nth_history_item (MOZILLA_EMBED (embed),
+ TRUE,
+ +1);
+}
+
+static EphyHistoryItem*
+impl_get_previous_history_item (EphyEmbed *embed)
+{
+ return mozilla_get_nth_history_item (MOZILLA_EMBED (embed),
+ TRUE,
+ -1);
+}
+
+static void
+impl_go_to_history_item (EphyEmbed *embed, EphyHistoryItem *item)
+{
+ int index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item),
+ HISTORY_ITEM_INDEX_KEY));
+
+ MOZILLA_EMBED (embed)->priv->browser->GoToHistoryIndex (index);
+}
+
static void
mozilla_embed_location_changed_cb (GtkMozEmbed *embed,
MozillaEmbed *membed)
@@ -1388,6 +1488,11 @@ ephy_embed_iface_init (EphyEmbedIface *iface)
iface->print_preview_navigate = impl_print_preview_navigate;
iface->has_modified_forms = impl_has_modified_forms;
iface->get_security_level = impl_get_security_level;
+ iface->get_backward_history = impl_get_backward_history;
+ iface->get_forward_history = impl_get_forward_history;
+ iface->get_next_history_item = impl_get_next_history_item;
+ iface->get_previous_history_item = impl_get_previous_history_item;
+ iface->go_to_history_item = impl_go_to_history_item;
}
static void
diff --git a/embed/mozilla/mozilla-history-item.cpp b/embed/mozilla/mozilla-history-item.cpp
new file mode 100644
index 000000000..b3c364e25
--- /dev/null
+++ b/embed/mozilla/mozilla-history-item.cpp
@@ -0,0 +1,69 @@
+#include "mozilla-history-item.h"
+#include "ephy-history-item.h"
+
+static void mozilla_history_item_finalize (GObject *object);
+
+static const char*
+impl_get_url (EphyHistoryItem *item)
+{
+ return MOZILLA_HISTORY_ITEM (item)->url;
+}
+
+static const char*
+impl_get_title (EphyHistoryItem *item)
+{
+ return MOZILLA_HISTORY_ITEM (item)->title;
+}
+
+static void
+mozilla_history_item_iface_init (EphyHistoryItemIface *iface)
+{
+ iface->get_url = impl_get_url;
+ iface->get_title = impl_get_title;
+}
+
+G_DEFINE_TYPE_WITH_CODE (MozillaHistoryItem, mozilla_history_item, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (EPHY_TYPE_HISTORY_ITEM,
+ mozilla_history_item_iface_init))
+
+static void
+mozilla_history_item_class_init (MozillaHistoryItemClass *klass)
+{
+ GObjectClass *gobject_class = (GObjectClass *)klass;
+
+ gobject_class->finalize = mozilla_history_item_finalize;
+}
+
+static void
+mozilla_history_item_init (MozillaHistoryItem *self)
+{
+}
+
+static void
+mozilla_history_item_finalize (GObject *object)
+{
+ MozillaHistoryItem *self = (MozillaHistoryItem *)object;
+
+ g_free (self->url);
+ g_free (self->title);
+
+ G_OBJECT_CLASS (mozilla_history_item_parent_class)->finalize (object);
+}
+
+MozillaHistoryItem*
+mozilla_history_item_new (const char *url, const char *title, int index)
+{
+ MozillaHistoryItem *item;
+
+ g_return_val_if_fail (url != NULL, NULL);
+ g_return_val_if_fail (title != NULL, NULL);
+
+ item = (MozillaHistoryItem*) g_object_new (MOZILLA_TYPE_HISTORY_ITEM, NULL);
+
+ item->url = g_strdup (url);
+ item->title = g_strdup (title);
+
+ g_object_set_data (G_OBJECT (item), HISTORY_ITEM_INDEX_KEY, GINT_TO_POINTER (index));
+
+ return item;
+}
diff --git a/embed/mozilla/mozilla-history-item.h b/embed/mozilla/mozilla-history-item.h
new file mode 100644
index 000000000..270fb6f53
--- /dev/null
+++ b/embed/mozilla/mozilla-history-item.h
@@ -0,0 +1,39 @@
+#ifndef __MOZILLA_HISTORY_ITEM_H__
+#define __MOZILLA_HISTORY_ITEM_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MOZILLA_TYPE_HISTORY_ITEM (mozilla_history_item_get_type())
+#define MOZILLA_HISTORY_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOZILLA_TYPE_HISTORY_ITEM, MozillaHistoryItem))
+#define MOZILLA_HISTORY_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOZILLA_TYPE_HISTORY_ITEM, MozillaHistoryItemClass))
+#define MOZILLA_IS_HISTORY_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOZILLA_TYPE_HISTORY_ITEM))
+#define MOZILLA_IS_HISTORY_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZILLA_TYPE_HISTORY_ITEM))
+#define MOZILLA_HISTORY_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZILLA_TYPE_HISTORY_ITEM, MozillaHistoryItemClass))
+
+#define HISTORY_ITEM_INDEX_KEY "NTh"
+
+typedef struct _MozillaHistoryItem MozillaHistoryItem;
+typedef struct _MozillaHistoryItemClass MozillaHistoryItemClass;
+
+struct _MozillaHistoryItemClass
+{
+ GObjectClass parent_class;
+};
+
+struct _MozillaHistoryItem
+{
+ GObject parent_instance;
+
+ char *url;
+ char *title;
+};
+
+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;
+
+G_END_DECLS
+
+#endif /* __MOZILLA_HISTORY_ITEM_H__ */