1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
/*
* Copyright (C) 2008 Jan Michael C. Alonzo
* Copyright (C) 2009 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "webkitwebbackforwardlist.h"
#include "webkitprivate.h"
#include "webkitwebhistoryitem.h"
#include "webkitwebview.h"
#include <glib.h>
#include "BackForwardList.h"
#include "HistoryItem.h"
/**
* SECTION:webkitwebbackforwardlist
* @short_description: The history of a #WebKitWebView
* @see_also: #WebKitWebView, #WebKitWebHistoryItem
*
* <informalexample><programlisting>
* /<!-- -->* Get the WebKitWebBackForwardList from the WebKitWebView *<!-- -->/
* WebKitWebBackForwardList *back_forward_list = webkit_web_view_get_back_forward_list (my_web_view);
* WebKitWebHistoryItem *item = webkit_web_back_forward_list_get_current_item (back_forward_list);
*
* /<!-- -->* Do something with a WebKitWebHistoryItem *<!-- -->/
* g_print("%p", item);
*
* /<!-- -->* Control some parameters *<!-- -->/
* WebKitWebBackForwardList *back_forward_list = webkit_web_view_get_back_forward_list (my_web_view);
* webkit_web_back_forward_list_set_limit (back_forward_list, 30);
* </programlisting></informalexample>
*
*/
using namespace WebKit;
struct _WebKitWebBackForwardListPrivate {
WebCore::BackForwardList* backForwardList;
gboolean disposed;
};
#define WEBKIT_WEB_BACK_FORWARD_LIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, WebKitWebBackForwardListPrivate))
G_DEFINE_TYPE(WebKitWebBackForwardList, webkit_web_back_forward_list, G_TYPE_OBJECT);
static void webkit_web_back_forward_list_dispose(GObject* object)
{
WebKitWebBackForwardList* list = WEBKIT_WEB_BACK_FORWARD_LIST(object);
WebCore::BackForwardList* backForwardList = core(list);
WebKitWebBackForwardListPrivate* priv = list->priv;
if (!priv->disposed) {
priv->disposed = true;
WebCore::HistoryItemVector items = backForwardList->entries();
GHashTable* table = webkit_history_items();
for (unsigned i = 0; i < items.size(); i++)
g_hash_table_remove(table, items[i].get());
}
G_OBJECT_CLASS(webkit_web_back_forward_list_parent_class)->dispose(object);
}
static void webkit_web_back_forward_list_class_init(WebKitWebBackForwardListClass* klass)
{
GObjectClass* object_class = G_OBJECT_CLASS(klass);
object_class->dispose = webkit_web_back_forward_list_dispose;
webkit_init();
g_type_class_add_private(klass, sizeof(WebKitWebBackForwardListPrivate));
}
static void webkit_web_back_forward_list_init(WebKitWebBackForwardList* webBackForwardList)
{
webBackForwardList->priv = WEBKIT_WEB_BACK_FORWARD_LIST_GET_PRIVATE(webBackForwardList);
}
/**
* webkit_web_back_forward_list_new_with_web_view:
* @web_view: the back forward list's #WebKitWebView
*
* Creates an instance of the back forward list with a controlling #WebKitWebView
*
* Return value: a #WebKitWebBackForwardList
*/
WebKitWebBackForwardList* webkit_web_back_forward_list_new_with_web_view(WebKitWebView* webView)
{
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
WebKitWebBackForwardList* webBackForwardList;
webBackForwardList = WEBKIT_WEB_BACK_FORWARD_LIST(g_object_new(WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, NULL));
WebKitWebBackForwardListPrivate* priv = webBackForwardList->priv;
priv->backForwardList = core(webView)->backForwardList();
priv->backForwardList->setEnabled(TRUE);
return webBackForwardList;
}
/**
* webkit_web_back_forward_list_go_forward:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Steps forward in the back forward list
*/
void webkit_web_back_forward_list_go_forward(WebKitWebBackForwardList* webBackForwardList)
{
g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList));
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (backForwardList->enabled())
backForwardList->goForward();
}
/**
* webkit_web_back_forward_list_go_back:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Steps backward in the back forward list
*/
void webkit_web_back_forward_list_go_back(WebKitWebBackForwardList* webBackForwardList)
{
g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList));
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (backForwardList->enabled())
backForwardList->goBack();
}
/**
* webkit_web_back_forward_list_contains_item:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @history_item: the #WebKitWebHistoryItem to check
*
* Checks if @web_history_item is in the back forward list
*
* Return: %TRUE if @web_history_item is in the back forward list, %FALSE if it doesn't
*/
gboolean webkit_web_back_forward_list_contains_item(WebKitWebBackForwardList* webBackForwardList, WebKitWebHistoryItem* webHistoryItem)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), FALSE);
g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), FALSE);
WebCore::HistoryItem* historyItem = core(webHistoryItem);
g_return_val_if_fail(historyItem != NULL, FALSE);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
return (backForwardList->enabled() ? backForwardList->containsItem(historyItem) : FALSE);
}
/**
* webkit_web_back_forward_list_go_to_item:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @history_item: the #WebKitWebHistoryItem to go to
*
* Go to the specified @web_history_item in the back forward list
*/
void webkit_web_back_forward_list_go_to_item(WebKitWebBackForwardList* webBackForwardList, WebKitWebHistoryItem* webHistoryItem)
{
g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList));
g_return_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem));
WebCore::HistoryItem* historyItem = core(webHistoryItem);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (backForwardList->enabled() && historyItem)
backForwardList->goToItem(historyItem);
}
/**
* webkit_web_back_forward_list_get_forward_list_with_limit:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @limit: the number of items to retrieve
*
* Returns a list of items that succeed the current item, limited by @limit
*
* Return value: a #GList of items succeeding the current item, limited by @limit
*/
GList* webkit_web_back_forward_list_get_forward_list_with_limit(WebKitWebBackForwardList* webBackForwardList, gint limit)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return NULL;
WebCore::HistoryItemVector items;
GList* forwardItems = { 0 };
backForwardList->forwardListWithLimit(limit, items);
for (unsigned i = 0; i < items.size(); i++) {
WebKitWebHistoryItem* webHistoryItem = kit(items[i]);
forwardItems = g_list_prepend(forwardItems, webHistoryItem);
}
return forwardItems;
}
/**
* webkit_web_back_forward_list_get_back_list_with_limit:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @limit: the number of items to retrieve
*
* Returns a list of items that precede the current item, limited by @limit
*
* Return value: a #GList of items preceding the current item, limited by @limit
*/
GList* webkit_web_back_forward_list_get_back_list_with_limit(WebKitWebBackForwardList* webBackForwardList, gint limit)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return NULL;
WebCore::HistoryItemVector items;
GList* backItems = { 0 };
backForwardList->backListWithLimit(limit, items);
for (unsigned i = 0; i < items.size(); i++) {
WebKitWebHistoryItem* webHistoryItem = kit(items[i]);
backItems = g_list_prepend(backItems, webHistoryItem);
}
return backItems;
}
/**
* webkit_web_back_forward_list_get_back_item:
* @web_back_forward_list: a #WebBackForwardList
*
* Returns the item that precedes the current item
*
* Return value: the #WebKitWebHistoryItem preceding the current item
*/
WebKitWebHistoryItem* webkit_web_back_forward_list_get_back_item(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return NULL;
WebCore::HistoryItem* historyItem = backForwardList->backItem();
return (historyItem ? kit(historyItem) : NULL);
}
/**
* webkit_web_back_forward_list_get_current_item:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Returns the current item.
*
* Returns a NULL value if the back forward list is empty
*
* Return value: a #WebKitWebHistoryItem
*/
WebKitWebHistoryItem* webkit_web_back_forward_list_get_current_item(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return NULL;
WebCore::HistoryItem* historyItem = backForwardList->currentItem();
return (historyItem ? kit(historyItem) : NULL);
}
/**
* webkit_web_back_forward_list_get_forward_item:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Returns the item that succeeds the current item.
*
* Returns a NULL value if there nothing that succeeds the current item
*
* Return value: a #WebKitWebHistoryItem
*/
WebKitWebHistoryItem* webkit_web_back_forward_list_get_forward_item(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return NULL;
WebCore::HistoryItem* historyItem = backForwardList->forwardItem();
return (historyItem ? kit(historyItem) : NULL);
}
/**
* webkit_web_back_forward_list_get_nth_item:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @index: the index of the item
*
* Returns the item at a given index relative to the current item.
*
* Return value: the #WebKitWebHistoryItem located at the specified index relative to the current item
*/
WebKitWebHistoryItem* webkit_web_back_forward_list_get_nth_item(WebKitWebBackForwardList* webBackForwardList, gint index)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList)
return NULL;
WebCore::HistoryItem* historyItem = backForwardList->itemAtIndex(index);
return (historyItem ? kit(historyItem) : NULL);
}
/**
* webkit_web_back_forward_list_get_back_length:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Returns the number of items that preced the current item.
*
* Return value: a #gint corresponding to the number of items preceding the current item
*/
gint webkit_web_back_forward_list_get_back_length(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), 0);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return 0;
return backForwardList->backListCount();
}
/**
* webkit_web_back_forward_list_get_forward_length:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Returns the number of items that succeed the current item.
*
* Return value: a #gint corresponding to the nuber of items succeeding the current item
*/
gint webkit_web_back_forward_list_get_forward_length(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), 0);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return 0;
return backForwardList->forwardListCount();
}
/**
* webkit_web_back_forward_list_get_limit:
* @web_back_forward_list: a #WebKitWebBackForwardList
*
* Returns the maximum limit of the back forward list.
*
* Return value: a #gint indicating the number of #WebHistoryItem the back forward list can hold
*/
gint webkit_web_back_forward_list_get_limit(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), 0);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (!backForwardList || !backForwardList->enabled())
return 0;
return backForwardList->capacity();
}
/**
* webkit_web_back_forward_list_set_limit:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @limit: the limit to set the back forward list to
*
* Sets the maximum limit of the back forward list. If the back forward list
* exceeds its capacity, items will be removed everytime a new item has been
* added.
*/
void webkit_web_back_forward_list_set_limit(WebKitWebBackForwardList* webBackForwardList, gint limit)
{
g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList));
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
if (backForwardList)
backForwardList->setCapacity(limit);
}
/**
* webkit_web_back_forward_list_add_item:
* @web_back_forward_list: a #WebKitWebBackForwardList
* @history_item: the #WebKitWebHistoryItem to add
*
* Adds the item to the #WebKitWebBackForwardList.
*
* The @webBackForwardList will add a reference to the @webHistoryItem, so you
* don't need to keep a reference once you've added it to the list.
*
* Since: 1.1.1
*/
void webkit_web_back_forward_list_add_item(WebKitWebBackForwardList *webBackForwardList, WebKitWebHistoryItem *webHistoryItem)
{
g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList));
g_object_ref(webHistoryItem);
WebCore::BackForwardList* backForwardList = core(webBackForwardList);
WebCore::HistoryItem* historyItem = core(webHistoryItem);
backForwardList->addItem(historyItem);
}
WebCore::BackForwardList* WebKit::core(WebKitWebBackForwardList* webBackForwardList)
{
g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL);
return webBackForwardList->priv ? webBackForwardList->priv->backForwardList : 0;
}
|