Create string tightly when retrive string from cbhm callback event
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_history.cpp
1 /*
2    Copyright (C) 2012 Samsung Electronics
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "ewk_history.h"
22
23 #if OS(TIZEN)
24 #include "WKAPICast.h"
25 #include "WKArray.h"
26 #include "WKBackForwardList.h"
27 #include "WKBackForwardListItem.h"
28 #include "WKRetainPtr.h"
29 #include "ewk_history_private.h"
30 #include <wtf/text/CString.h>
31
32 using namespace WebKit;
33
34 struct _Ewk_History {
35     WKBackForwardListRef wkBackForwardList;
36
37     Ewk_History_Item* item;
38 };
39
40 struct _Ewk_History_Item {
41     WKRetainPtr<WKBackForwardListItemRef> itemRef;
42
43     CString uri;
44     CString title;
45 };
46
47 Ewk_History* ewkHistoryCreate(WKBackForwardListRef wkBackForwardList)
48 {
49     EINA_SAFETY_ON_NULL_RETURN_VAL(wkBackForwardList, 0);
50
51     Ewk_History* history = new Ewk_History;
52
53     history->wkBackForwardList = wkBackForwardList;
54     history->item = 0;
55
56     return history;
57 }
58
59 int ewk_history_back_list_length_get(Ewk_History* history)
60 {
61     EINA_SAFETY_ON_NULL_RETURN_VAL(history, 0);
62
63     return WKBackForwardListGetBackListCount(history->wkBackForwardList);
64 }
65
66 int ewk_history_forward_list_length_get(Ewk_History* history)
67 {
68     EINA_SAFETY_ON_NULL_RETURN_VAL(history, 0);
69
70     return WKBackForwardListGetForwardListCount(history->wkBackForwardList);
71 }
72
73 Ewk_History_Item* ewk_history_nth_item_get(Ewk_History* history, int index)
74 {
75     EINA_SAFETY_ON_NULL_RETURN_VAL(history, 0);
76
77     if (history->item)
78         delete history->item;
79
80     WKBackForwardListItemRef itemRef = WKBackForwardListGetItemAtIndex(history->wkBackForwardList, index);
81     if (!itemRef)
82         return 0;
83
84     history->item = new Ewk_History_Item;
85     history->item->itemRef = itemRef;
86
87     return history->item;
88 }
89
90 const char* ewk_history_item_uri_get(Ewk_History_Item* item)
91 {
92     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
93
94     WKRetainPtr<WKURLRef> wkURI(AdoptWK, WKBackForwardListItemCopyURL(item->itemRef.get()));
95
96     if (toImpl(wkURI.get())->string().isEmpty())
97         return 0;
98
99     item->uri = toImpl(wkURI.get())->string().utf8();
100     return item->uri.data();
101 }
102
103 const char* ewk_history_item_title_get(Ewk_History_Item* item)
104 {
105     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
106
107     WKRetainPtr<WKStringRef> wkTitle(AdoptWK, WKBackForwardListItemCopyTitle(item->itemRef.get()));
108
109     if (toImpl(wkTitle.get())->string().isEmpty())
110         return 0;
111
112     item->title = toImpl(wkTitle.get())->string().utf8();
113     return item->title.data();
114 }
115
116 void ewk_history_free(Ewk_History* history)
117 {
118     EINA_SAFETY_ON_NULL_RETURN(history);
119
120     if (history->item)
121         delete history->item;
122
123     delete history;
124 }
125
126 Eina_List* ewk_history_back_list_get(Ewk_History* history)
127 {
128     return 0;
129 }
130
131 Eina_List* ewk_history_forward_list_get(Ewk_History* history)
132 {
133     return 0;
134 }
135
136 void ewk_history_item_list_free(Eina_List* items)
137 {
138     return;
139 }
140 #endif // #if OS(TIZEN)