Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp (126570 => 126571)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp 2012-08-24 11:27:42 UTC (rev 126570)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp 2012-08-24 11:47:54 UTC (rev 126571)
@@ -84,6 +84,24 @@
return item;
}
+static inline Eina_List* createEinaList(const Ewk_Back_Forward_List* list, WKArrayRef wkList)
+{
+ if (!wkList)
+ return 0;
+
+ Eina_List* result = 0;
+
+ const size_t count = WKArrayGetSize(wkList);
+ for (size_t i = 0; i < count; ++i) {
+ WKBackForwardListItemRef wkItem = static_cast<WKBackForwardListItemRef>(WKArrayGetItemAtIndex(wkList, i));
+ Ewk_Back_Forward_List_Item* item = addItemToWrapperCache(list, wkItem);
+ ewk_back_forward_list_item_ref(item);
+ result = eina_list_append(result, item);
+ }
+
+ return result;
+}
+
Ewk_Back_Forward_List_Item* ewk_back_forward_list_current_item_get(const Ewk_Back_Forward_List* list)
{
EWK_BACK_FORWARD_LIST_WK_GET_OR_RETURN(list, wkList, 0);
@@ -121,7 +139,30 @@
return WKBackForwardListGetBackListCount(wkList) + WKBackForwardListGetForwardListCount(wkList) + currentItem;
}
+Eina_List* ewk_back_forward_list_n_back_items_copy(const Ewk_Back_Forward_List* list, int limit)
+{
+ EWK_BACK_FORWARD_LIST_WK_GET_OR_RETURN(list, wkList, 0);
+ if (limit == -1)
+ limit = WKBackForwardListGetBackListCount(wkList);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(limit >= 0, 0);
+ WKRetainPtr<WKArrayRef> backList(AdoptWK, WKBackForwardListCopyBackListWithLimit(wkList, limit));
+
+ return createEinaList(list, backList.get());
+}
+
+Eina_List* ewk_back_forward_list_n_forward_items_copy(const Ewk_Back_Forward_List* list, int limit)
+{
+ EWK_BACK_FORWARD_LIST_WK_GET_OR_RETURN(list, wkList, 0);
+
+ if (limit == -1)
+ limit = WKBackForwardListGetForwardListCount(wkList);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(limit >= 0, 0);
+ WKRetainPtr<WKArrayRef> forwardList(AdoptWK, WKBackForwardListCopyForwardListWithLimit(wkList, limit));
+
+ return createEinaList(list, forwardList.get());
+}
+
/**
* @internal
* Updates items cache.
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.h (126570 => 126571)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.h 2012-08-24 11:27:42 UTC (rev 126570)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.h 2012-08-24 11:47:54 UTC (rev 126571)
@@ -86,6 +86,68 @@
*/
EAPI unsigned ewk_back_forward_list_count(Ewk_Back_Forward_List *list);
+/**
+ * Creates the list containing the items preceding the current item limited by @a limit.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ * if @a limit is equal to @c -1 all the items preceding the current item are returned.
+ *
+ * @param list the back-forward list instance
+ * @param limit the number of items to retrieve
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ * the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ * to free the items
+ */
+EAPI Eina_List *ewk_back_forward_list_n_back_items_copy(const Ewk_Back_Forward_List *list, int limit);
+
+/**
+ * Creates the list containing the items following the current item limited by @a limit.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ * if @a limit is equal to @c -1 all the items preceding the current item are returned.
+ *
+ * @param list the back-forward list instance
+ * @param limit the number of items to retrieve
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ * the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ * to free the items
+ */
+EAPI Eina_List *ewk_back_forward_list_n_forward_items_copy(const Ewk_Back_Forward_List *list, int limit);
+
+/**
+ * Creates the list containing the items preceding the current item.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ *
+ * @param list the back-forward list instance
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ * the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ * to free the items
+ *
+ * @see ewk_back_forward_list_n_back_items_copy
+ */
+#define ewk_back_forward_list_back_items_copy(list) \
+ ewk_back_forward_list_n_back_items_copy(list, -1)
+
+/**
+ * Creates the list containing the items following the current item.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ *
+ * @param list the back-forward list instance
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ * the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ * to free the items
+ *
+ * @see ewk_back_forward_list_n_forward_items_copy
+ */
+#define ewk_back_forward_list_forward_items_copy(list) \
+ ewk_back_forward_list_n_forward_items_copy(list, -1)
+
#ifdef __cplusplus
}
#endif
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp (126570 => 126571)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp 2012-08-24 11:27:42 UTC (rev 126570)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp 2012-08-24 11:47:54 UTC (rev 126571)
@@ -41,6 +41,7 @@
static const char title1[] = "Page1";
static const char title2[] = "Page2";
+static const char title3[] = "Page3";
static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
@@ -78,6 +79,13 @@
return res;
}
+static inline void freeEinaList(Eina_List* list)
+{
+ void* data = ""
+ EINA_LIST_FREE(list, data)
+ ewk_back_forward_list_item_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
+}
+
TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)
{
const char* url = ""
@@ -181,3 +189,83 @@
EXPECT_EQ(ewk_back_forward_list_count(backForwardList), 2);
}
+
+TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_back_items_copy)
+{
+ OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
+ httpServer->run(serverCallbackNavigation);
+
+ WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1);
+ loadUrlSync(url1);
+ ASSERT_STREQ(ewk_view_title_get(webView()), title1);
+
+ WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2);
+ loadUrlSync(url2);
+ ASSERT_STREQ(ewk_view_title_get(webView()), title2);
+
+ loadUrlSync(urlFromTitle(httpServer.get(), title3));
+ ASSERT_STREQ(ewk_view_title_get(webView()), title3);
+
+ Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
+ ASSERT_TRUE(backForwardList);
+
+ Eina_List* backList = ewk_back_forward_list_n_back_items_copy(backForwardList, 1);
+ ASSERT_TRUE(backList);
+ ASSERT_EQ(eina_list_count(backList), 1);
+ checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 0)), title2, url2, url2);
+ freeEinaList(backList);
+
+ // Check '0' limit.
+ backList = ewk_back_forward_list_n_back_items_copy(backForwardList, 0);
+ ASSERT_FALSE(backList);
+
+ backList = ewk_back_forward_list_n_back_items_copy(backForwardList, -1);
+ ASSERT_TRUE(backList);
+ ASSERT_EQ(eina_list_count(backList), 2);
+ checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 0)), title1, url1, url1);
+ checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 1)), title2, url2, url2);
+ freeEinaList(backList);
+}
+
+TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_forward_items_copy)
+{
+ OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
+ httpServer->run(serverCallbackNavigation);
+
+ loadUrlSync(urlFromTitle(httpServer.get(), title1));
+ ASSERT_STREQ(ewk_view_title_get(webView()), title1);
+
+ WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2);
+ loadUrlSync(url2);
+ ASSERT_STREQ(ewk_view_title_get(webView()), title2);
+
+ WKEinaSharedString url3 = urlFromTitle(httpServer.get(), title3);
+ loadUrlSync(url3);
+ ASSERT_STREQ(ewk_view_title_get(webView()), title3);
+
+ // Go back to Page1.
+ ewk_view_back(webView());
+ waitUntilTitleChangedTo(title2);
+ ewk_view_back(webView());
+ waitUntilTitleChangedTo(title1);
+
+ Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
+ ASSERT_TRUE(backForwardList);
+
+ Eina_List* forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, 1);
+ ASSERT_TRUE(forwardList);
+ ASSERT_EQ(eina_list_count(forwardList), 1);
+ checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 0)), title2, url2, url2);
+ freeEinaList(forwardList);
+
+ // Check '0' limit.
+ forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, 0);
+ ASSERT_FALSE(forwardList);
+
+ forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, -1);
+ ASSERT_TRUE(forwardList);
+ ASSERT_EQ(eina_list_count(forwardList), 2);
+ checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 0)), title2, url2, url2);
+ checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 1)), title3, url3, url3);
+ freeEinaList(forwardList);
+}