summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/webkit/webkitwebhistoryitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/gtk/webkit/webkitwebhistoryitem.cpp')
-rw-r--r--WebKit/gtk/webkit/webkitwebhistoryitem.cpp141
1 files changed, 91 insertions, 50 deletions
diff --git a/WebKit/gtk/webkit/webkitwebhistoryitem.cpp b/WebKit/gtk/webkit/webkitwebhistoryitem.cpp
index 8cdaa90..42e6a9b 100644
--- a/WebKit/gtk/webkit/webkitwebhistoryitem.cpp
+++ b/WebKit/gtk/webkit/webkitwebhistoryitem.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Jan Michael C. Alonzo
+ * Copyright (C) 2008, 2009 Jan Michael C. Alonzo
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -17,7 +17,6 @@
* Boston, MA 02110-1301, USA.
*/
-
#include "config.h"
#include "webkitwebhistoryitem.h"
@@ -53,12 +52,14 @@ using namespace WebKit;
extern "C" {
struct _WebKitWebHistoryItemPrivate {
- WTF::RefPtr<WebCore::HistoryItem> historyItem;
+ WebCore::HistoryItem* historyItem;
WebCore::CString title;
WebCore::CString alternateTitle;
WebCore::CString uri;
WebCore::CString originalUri;
+
+ gboolean disposed;
};
#define WEBKIT_WEB_HISTORY_ITEM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_HISTORY_ITEM, WebKitWebHistoryItemPrivate))
@@ -81,7 +82,7 @@ static void webkit_web_history_item_get_property(GObject* object, guint prop_id,
static GHashTable* webkit_history_items()
{
- static GHashTable* historyItems = g_hash_table_new(g_direct_hash, g_direct_equal);
+ static GHashTable* historyItems = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
return historyItems;
}
@@ -94,27 +95,24 @@ static void webkit_history_item_add(WebKitWebHistoryItem* webHistoryItem, WebCor
g_hash_table_insert(table, historyItem, g_object_ref(webHistoryItem));
}
-static void webkit_history_item_remove(WebCore::HistoryItem* historyItem)
-{
- GHashTable* table = webkit_history_items();
- WebKitWebHistoryItem* webHistoryItem = (WebKitWebHistoryItem*) g_hash_table_lookup(table, historyItem);
-
- g_return_if_fail(webHistoryItem != NULL);
-
- g_hash_table_remove(table, historyItem);
- g_object_unref(webHistoryItem);
-}
-
static void webkit_web_history_item_dispose(GObject* object)
{
WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object);
+ WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
+ WebCore::HistoryItem* item = core(webHistoryItem);
- webkit_history_item_remove(core(webHistoryItem));
+ if (!priv->disposed) {
+ GHashTable* table = webkit_history_items();
- /* destroy table if empty */
- GHashTable* table = webkit_history_items();
- if (!g_hash_table_size(table))
- g_hash_table_destroy(table);
+ g_hash_table_remove(table, item);
+ item->deref();
+
+ /* destroy table if empty */
+ if (!g_hash_table_size(table))
+ g_hash_table_destroy(table);
+
+ priv->disposed = true;
+ }
G_OBJECT_CLASS(webkit_web_history_item_parent_class)->dispose(object);
}
@@ -270,21 +268,9 @@ static void webkit_web_history_item_get_property(GObject* object, guint prop_id,
}
/* Helper function to create a new WebHistoryItem instance when needed */
-WebKitWebHistoryItem* webkit_web_history_item_new_with_core_item(WebCore::HistoryItem* item)
+WebKitWebHistoryItem* webkit_web_history_item_new_with_core_item(PassRefPtr<WebCore::HistoryItem> historyItem)
{
- WebKitWebHistoryItem* webHistoryItem = kit(item);
-
- if (webHistoryItem)
- g_object_ref(webHistoryItem);
- else {
- webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL));
- WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
-
- priv->historyItem = item;
- webkit_history_item_add(webHistoryItem, priv->historyItem.get());
- }
-
- return webHistoryItem;
+ return kit(historyItem);
}
@@ -300,8 +286,9 @@ WebKitWebHistoryItem* webkit_web_history_item_new()
WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL));
WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
- priv->historyItem = WebCore::HistoryItem::create();
- webkit_history_item_add(webHistoryItem, priv->historyItem.get());
+ RefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create();
+ priv->historyItem = item.release().releaseRef();
+ webkit_history_item_add(webHistoryItem, priv->historyItem);
return webHistoryItem;
}
@@ -323,8 +310,9 @@ WebKitWebHistoryItem* webkit_web_history_item_new_with_data(const gchar* uri, co
WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL));
WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
- priv->historyItem = WebCore::HistoryItem::create(historyUri, historyTitle, 0);
- webkit_history_item_add(webHistoryItem, priv->historyItem.get());
+ RefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create(historyUri, historyTitle, 0);
+ priv->historyItem = item.release().releaseRef();
+ webkit_history_item_add(webHistoryItem, priv->historyItem);
return webHistoryItem;
}
@@ -341,7 +329,7 @@ G_CONST_RETURN gchar* webkit_web_history_item_get_title(WebKitWebHistoryItem* we
WebCore::HistoryItem* item = core(webHistoryItem);
- g_return_val_if_fail(item != NULL, NULL);
+ g_return_val_if_fail(item, NULL);
WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
priv->title = item->title().utf8();
@@ -363,7 +351,7 @@ G_CONST_RETURN gchar* webkit_web_history_item_get_alternate_title(WebKitWebHisto
WebCore::HistoryItem* item = core(webHistoryItem);
- g_return_val_if_fail(item != NULL, NULL);
+ g_return_val_if_fail(item, NULL);
WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
priv->alternateTitle = item->alternateTitle().utf8();
@@ -403,7 +391,7 @@ G_CONST_RETURN gchar* webkit_web_history_item_get_uri(WebKitWebHistoryItem* webH
WebCore::HistoryItem* item = core(WEBKIT_WEB_HISTORY_ITEM(webHistoryItem));
- g_return_val_if_fail(item != NULL, NULL);
+ g_return_val_if_fail(item, NULL);
WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
priv->uri = item->urlString().utf8();
@@ -425,7 +413,7 @@ G_CONST_RETURN gchar* webkit_web_history_item_get_original_uri(WebKitWebHistoryI
WebCore::HistoryItem* item = core(WEBKIT_WEB_HISTORY_ITEM(webHistoryItem));
- g_return_val_if_fail(item != NULL, NULL);
+ g_return_val_if_fail(item, NULL);
WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
priv->originalUri = item->originalURLString().utf8();
@@ -447,31 +435,84 @@ gdouble webkit_web_history_item_get_last_visited_time(WebKitWebHistoryItem* webH
WebCore::HistoryItem* item = core(WEBKIT_WEB_HISTORY_ITEM(webHistoryItem));
- g_return_val_if_fail(item != NULL, 0);
+ g_return_val_if_fail(item, 0);
return item->lastVisitedTime();
}
+/* private methods */
+
+G_CONST_RETURN gchar* webkit_web_history_item_get_target(WebKitWebHistoryItem* webHistoryItem)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL);
+
+ WebCore::HistoryItem* item = core(webHistoryItem);
+
+ g_return_val_if_fail(item, NULL);
+
+ WebCore::CString t = item->target().utf8();
+ return g_strdup(t.data());
+}
+
+gboolean webkit_web_history_item_is_target_item(WebKitWebHistoryItem* webHistoryItem)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), false);
+
+ WebCore::HistoryItem* item = core(webHistoryItem);
+
+ g_return_val_if_fail(item, false);
+
+ return item->isTargetItem();
+}
+
+GList* webkit_web_history_item_get_children(WebKitWebHistoryItem* webHistoryItem)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL);
+
+ WebCore::HistoryItem* item = core(webHistoryItem);
+
+ g_return_val_if_fail(item, NULL);
+
+ const WebCore::HistoryItemVector& children = item->children();
+ if (!children.size())
+ return NULL;
+
+ unsigned size = children.size();
+ GList* kids = NULL;
+ for (unsigned i = 0; i < size; ++i)
+ kids = g_list_prepend(kids, kit(children[i].get()));
+
+ return g_list_reverse(kids);
+}
+
} /* end extern "C" */
WebCore::HistoryItem* WebKit::core(WebKitWebHistoryItem* webHistoryItem)
{
g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL);
- WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
- WTF::RefPtr<WebCore::HistoryItem> historyItem = priv->historyItem;
-
- return historyItem ? historyItem.get() : 0;
+ return webHistoryItem->priv->historyItem;
}
-WebKitWebHistoryItem* WebKit::kit(WebCore::HistoryItem* historyItem)
+WebKitWebHistoryItem* WebKit::kit(PassRefPtr<WebCore::HistoryItem> historyItem)
{
- g_return_val_if_fail(historyItem != NULL, NULL);
+ g_return_val_if_fail(historyItem, NULL);
+
+ RefPtr<WebCore::HistoryItem> item = historyItem;
WebKitWebHistoryItem* webHistoryItem;
GHashTable* table = webkit_history_items();
- webHistoryItem = (WebKitWebHistoryItem*) g_hash_table_lookup(table, historyItem);
+ webHistoryItem = (WebKitWebHistoryItem*) g_hash_table_lookup(table, item.get());
+
+ if (!webHistoryItem) {
+ webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL));
+ WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv;
+
+ priv->historyItem = item.release().releaseRef();
+ webkit_history_item_add(webHistoryItem, priv->historyItem);
+ }
+
return webHistoryItem;
}