1/*
2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "APIObject.h"
29#include "WebBackForwardListItem.h"
30#include "WebPageProxy.h"
31#include <WebCore/BackForwardItemIdentifier.h>
32#include <wtf/Ref.h>
33#include <wtf/Vector.h>
34
35namespace WebKit {
36
37struct BackForwardListState;
38
39class WebBackForwardList : public API::ObjectImpl<API::Object::Type::BackForwardList> {
40public:
41 static Ref<WebBackForwardList> create(WebPageProxy& page)
42 {
43 return adoptRef(*new WebBackForwardList(page));
44 }
45 void pageClosed();
46
47 virtual ~WebBackForwardList();
48
49 WebBackForwardListItem* itemForID(const WebCore::BackForwardItemIdentifier&);
50
51 void addItem(Ref<WebBackForwardListItem>&&);
52 void goToItem(WebBackForwardListItem&);
53 void removeAllItems();
54 void clear();
55
56 WebBackForwardListItem* currentItem() const;
57 WebBackForwardListItem* backItem() const;
58 WebBackForwardListItem* forwardItem() const;
59 WebBackForwardListItem* itemAtIndex(int) const;
60
61 const BackForwardListItemVector& entries() const { return m_entries; }
62
63 unsigned backListCount() const;
64 unsigned forwardListCount() const;
65
66 Ref<API::Array> backList() const;
67 Ref<API::Array> forwardList() const;
68
69 Ref<API::Array> backListAsAPIArrayWithLimit(unsigned limit) const;
70 Ref<API::Array> forwardListAsAPIArrayWithLimit(unsigned limit) const;
71
72 BackForwardListState backForwardListState(WTF::Function<bool (WebBackForwardListItem&)>&&) const;
73 void restoreFromState(BackForwardListState);
74
75 Vector<BackForwardListItemState> itemStates() const;
76 Vector<BackForwardListItemState> filteredItemStates(Function<bool(WebBackForwardListItem&)>&&) const;
77
78#if !LOG_DISABLED
79 const char* loggingString();
80#endif
81
82private:
83 explicit WebBackForwardList(WebPageProxy&);
84
85 void didRemoveItem(WebBackForwardListItem&);
86
87 WebPageProxy* m_page;
88 BackForwardListItemVector m_entries;
89 Optional<size_t> m_currentIndex;
90};
91
92} // namespace WebKit
93