2
Copyright (C) 2009-2010 ProFUSION embedded systems
3
Copyright (C) 2009-2010 Samsung Electronics
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
22
#include "ewk_history.h"
24
#include "BackForwardListImpl.h"
25
#include "CairoUtilitiesEfl.h"
26
#include "HistoryItem.h"
27
#include "IconDatabaseBase.h"
31
#include "PageGroup.h"
32
#include "ewk_history_private.h"
33
#include "ewk_private.h"
35
#include <eina_safety_checks.h>
36
#include <wtf/text/CString.h>
39
WebCore::BackForwardListImpl* core;
42
#define EWK_HISTORY_CORE_GET_OR_RETURN(history, core_, ...) \
44
CRITICAL("history is NULL."); \
47
if (!(history)->core) { \
48
CRITICAL("history->core is NULL."); \
51
if (!(history)->core->enabled()) { \
52
ERR("history->core is disabled!."); \
55
WebCore::BackForwardListImpl* core_ = (history)->core
58
struct _Ewk_History_Item {
59
WebCore::HistoryItem* core;
62
const char* alternateTitle;
64
const char* originalUri;
67
#define EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core_, ...) \
69
CRITICAL("item is NULL."); \
72
if (!(item)->core) { \
73
CRITICAL("item->core is NULL."); \
76
WebCore::HistoryItem* core_ = (item)->core
78
static inline Eina_List* _ewk_history_item_list_get(const WebCore::HistoryItemVector& coreItems)
80
Eina_List* result = 0;
83
size = coreItems.size();
84
for (unsigned int i = 0; i < size; i++) {
85
Ewk_History_Item* item = ewk_history_item_new_from_core(coreItems[i].get());
87
result = eina_list_append(result, item);
93
Eina_Bool ewk_history_clear(Ewk_History* history)
95
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, false);
97
WebCore::Page* page = core->page();
98
if (page && page->groupPtr())
99
page->groupPtr()->removeVisitedLinks();
101
const int limit = ewk_history_limit_get(history);
102
ewk_history_limit_set(history, 0);
103
ewk_history_limit_set(history, limit);
108
Eina_Bool ewk_history_forward(Ewk_History* history)
110
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, false);
111
if (core->forwardListCount() < 1)
117
Eina_Bool ewk_history_back(Ewk_History* history)
119
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, false);
120
if (core->backListCount() < 1)
126
Eina_Bool ewk_history_history_item_add(Ewk_History* history, const Ewk_History_Item* item)
128
EWK_HISTORY_CORE_GET_OR_RETURN(history, history_core, false);
129
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, item_core, false);
130
history_core->addItem(item_core);
134
Eina_Bool ewk_history_history_item_set(Ewk_History* history, const Ewk_History_Item* item)
136
EWK_HISTORY_CORE_GET_OR_RETURN(history, history_core, false);
137
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, item_core, false);
138
history_core->goToItem(item_core);
142
Ewk_History_Item* ewk_history_history_item_back_get(const Ewk_History* history)
144
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
145
return ewk_history_item_new_from_core(core->backItem());
148
Ewk_History_Item* ewk_history_history_item_current_get(const Ewk_History* history)
150
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
151
WebCore::HistoryItem* currentItem = core->currentItem();
153
return ewk_history_item_new_from_core(currentItem);
157
Ewk_History_Item* ewk_history_history_item_forward_get(const Ewk_History* history)
159
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
160
return ewk_history_item_new_from_core(core->forwardItem());
163
Ewk_History_Item* ewk_history_history_item_nth_get(const Ewk_History* history, int index)
165
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
166
return ewk_history_item_new_from_core(core->itemAtIndex(index));
169
Eina_Bool ewk_history_history_item_contains(const Ewk_History* history, const Ewk_History_Item* item)
171
EWK_HISTORY_CORE_GET_OR_RETURN(history, history_core, false);
172
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, item_core, false);
173
return history_core->containsItem(item_core);
176
Eina_List* ewk_history_forward_list_get(const Ewk_History* history)
178
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
179
WebCore::HistoryItemVector items;
180
int limit = core->forwardListCount();
181
core->forwardListWithLimit(limit, items);
182
return _ewk_history_item_list_get(items);
185
Eina_List* ewk_history_forward_list_get_with_limit(const Ewk_History* history, int limit)
187
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
188
WebCore::HistoryItemVector items;
189
core->forwardListWithLimit(limit, items);
190
return _ewk_history_item_list_get(items);
193
int ewk_history_forward_list_length(const Ewk_History* history)
195
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
196
return core->forwardListCount();
199
Eina_List* ewk_history_back_list_get(const Ewk_History* history)
201
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
202
WebCore::HistoryItemVector items;
203
int limit = core->backListCount();
204
core->backListWithLimit(limit, items);
205
return _ewk_history_item_list_get(items);
208
Eina_List* ewk_history_back_list_get_with_limit(const Ewk_History* history, int limit)
210
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
211
WebCore::HistoryItemVector items;
212
core->backListWithLimit(limit, items);
213
return _ewk_history_item_list_get(items);
216
int ewk_history_back_list_length(const Ewk_History* history)
218
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
219
return core->backListCount();
222
int ewk_history_limit_get(Ewk_History* history)
224
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, 0);
225
return core->capacity();
228
Eina_Bool ewk_history_limit_set(const Ewk_History* history, int limit)
230
EWK_HISTORY_CORE_GET_OR_RETURN(history, core, false);
231
core->setCapacity(limit);
235
Ewk_History_Item* ewk_history_item_new_from_core(WebCore::HistoryItem* core)
237
Ewk_History_Item* item;
240
ERR("WebCore::HistoryItem is NULL.");
246
item = new Ewk_History_Item;
247
memset(item, 0, sizeof(*item));
253
Ewk_History_Item* ewk_history_item_new(const char* uri, const char* title)
255
WTF::String historyUri = WTF::String::fromUTF8(uri);
256
WTF::String historyTitle = WTF::String::fromUTF8(title);
257
WTF::RefPtr<WebCore::HistoryItem> core = WebCore::HistoryItem::create(historyUri, historyTitle, 0);
258
Ewk_History_Item* item = ewk_history_item_new_from_core(core.release().leakRef());
262
static inline void _ewk_history_item_free(Ewk_History_Item* item, WebCore::HistoryItem* core)
268
void ewk_history_item_free(Ewk_History_Item* item)
270
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core);
271
_ewk_history_item_free(item, core);
274
void ewk_history_item_list_free(Eina_List* history_items)
277
EINA_LIST_FREE(history_items, deleteItem) {
278
Ewk_History_Item* item = (Ewk_History_Item*)deleteItem;
279
_ewk_history_item_free(item, item->core);
283
const char* ewk_history_item_title_get(const Ewk_History_Item* item)
285
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
286
// hide the following optimzation from outside
287
Ewk_History_Item* historyItem = const_cast<Ewk_History_Item*>(item);
288
eina_stringshare_replace(&historyItem->title, core->title().utf8().data());
289
return historyItem->title;
292
const char* ewk_history_item_title_alternate_get(const Ewk_History_Item* item)
294
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
295
// hide the following optimzation from outside
296
Ewk_History_Item* historyItem = const_cast<Ewk_History_Item*>(item);
297
eina_stringshare_replace(&historyItem->alternateTitle,
298
core->alternateTitle().utf8().data());
299
return historyItem->alternateTitle;
302
void ewk_history_item_title_alternate_set(Ewk_History_Item* item, const char* title)
304
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core);
305
if (!eina_stringshare_replace(&item->alternateTitle, title))
307
core->setAlternateTitle(WTF::String::fromUTF8(title));
310
const char* ewk_history_item_uri_get(const Ewk_History_Item* item)
312
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
313
// hide the following optimzation from outside
314
Ewk_History_Item* historyItem = const_cast<Ewk_History_Item*>((item));
315
eina_stringshare_replace(&historyItem->uri, core->urlString().utf8().data());
316
return historyItem->uri;
319
const char* ewk_history_item_uri_original_get(const Ewk_History_Item* item)
321
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
322
// hide the following optimzation from outside
323
Ewk_History_Item* historyItem = const_cast<Ewk_History_Item*>(item);
324
eina_stringshare_replace(&historyItem->originalUri,
325
core->originalURLString().utf8().data());
326
return historyItem->originalUri;
329
double ewk_history_item_time_last_visited_get(const Ewk_History_Item* item)
331
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0.0);
332
return core->lastVisitedTime();
335
cairo_surface_t* ewk_history_item_icon_surface_get(const Ewk_History_Item* item)
337
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
339
WebCore::NativeImagePtr icon = WebCore::iconDatabase().synchronousNativeIconForPageURL(core->url(), WebCore::IntSize(16, 16));
341
ERR("icon is NULL.");
343
return icon ? icon->surface() : 0;
346
Evas_Object* ewk_history_item_icon_object_add(const Ewk_History_Item* item, Evas* canvas)
348
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
349
EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
351
WebCore::NativeImagePtr icon = WebCore::iconDatabase().synchronousNativeIconForPageURL(core->url(), WebCore::IntSize(16, 16));
353
ERR("icon is NULL.");
357
cairo_surface_t* surface = icon->surface();
358
return surface ? WebCore::evasObjectFromCairoImageSurface(canvas, surface).leakRef() : 0;
361
Eina_Bool ewk_history_item_page_cache_exists(const Ewk_History_Item* item)
363
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, false);
364
return core->isInPageCache();
367
int ewk_history_item_visit_count(const Ewk_History_Item* item)
369
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, 0);
370
return core->visitCount();
373
Eina_Bool ewk_history_item_visit_last_failed(const Ewk_History_Item* item)
375
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(item, core, true);
376
return core->lastVisitWasFailure();
380
/* internal methods ****************************************************/
384
* Creates history for given view. Called internally by ewk_view and
385
* should never be called from outside.
387
* @param core WebCore::BackForwardListImpl instance to use internally.
389
* @return newly allocated history instance or @c NULL on errors.
391
Ewk_History* ewk_history_new(WebCore::BackForwardListImpl* core)
393
Ewk_History* history;
394
EINA_SAFETY_ON_NULL_RETURN_VAL(core, 0);
395
DBG("core=%p", core);
397
history = new Ewk_History;
398
history->core = core;
407
* Destroys previously allocated history instance. This is called
408
* automatically by ewk_view and should never be called from outside.
410
* @param history instance to free
412
void ewk_history_free(Ewk_History* history)
414
DBG("history=%p", history);
415
history->core->deref();
419
namespace EWKPrivate {
421
WebCore::HistoryItem* coreHistoryItem(const Ewk_History_Item* ewkHistoryItem)
423
EWK_HISTORY_ITEM_CORE_GET_OR_RETURN(ewkHistoryItem, core, 0);
427
} // namespace EWKPrivate