1 /*
2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4 * Copyright (c) 2009, Google Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "config.h"
29 #include "BackForwardList.h"
30
31 #include "HistoryItem.h"
32 #include "Logging.h"
33
34 namespace WebCore {
35
36 static const unsigned DefaultCapacity = 100;
37 static const unsigned NoCurrentItemIndex = UINT_MAX;
38
BackForwardList(Page * page)39 BackForwardList::BackForwardList(Page* page)
40 : m_page(page)
41 , m_client(0)
42 , m_capacity(DefaultCapacity)
43 , m_closed(true)
44 , m_enabled(true)
45 {
46 }
47
~BackForwardList()48 BackForwardList::~BackForwardList()
49 {
50 ASSERT(m_closed);
51 }
52
addItem(PassRefPtr<HistoryItem> prpItem)53 void BackForwardList::addItem(PassRefPtr<HistoryItem> prpItem)
54 {
55 ASSERT(prpItem);
56 if (m_capacity == 0 || !m_enabled)
57 return;
58
59 m_client->addItem(prpItem);
60 }
61
goToItem(HistoryItem * item)62 void BackForwardList::goToItem(HistoryItem* item)
63 {
64 m_client->goToItem(item);
65 }
66
backItem()67 HistoryItem* BackForwardList::backItem()
68 {
69 ASSERT_NOT_REACHED();
70 return 0;
71 }
72
forwardItem()73 HistoryItem* BackForwardList::forwardItem()
74 {
75 ASSERT_NOT_REACHED();
76 return 0;
77 }
78
currentItem()79 HistoryItem* BackForwardList::currentItem()
80 {
81 return m_client->currentItem();
82 }
83
capacity()84 int BackForwardList::capacity()
85 {
86 return m_capacity;
87 }
88
setCapacity(int size)89 void BackForwardList::setCapacity(int size)
90 {
91 m_capacity = size;
92 }
93
enabled()94 bool BackForwardList::enabled()
95 {
96 return m_enabled;
97 }
98
setEnabled(bool enabled)99 void BackForwardList::setEnabled(bool enabled)
100 {
101 m_enabled = enabled;
102 if (!enabled) {
103 int capacity = m_capacity;
104 setCapacity(0);
105 setCapacity(capacity);
106 }
107 }
108
backListCount()109 int BackForwardList::backListCount()
110 {
111 return m_client->backListCount();
112 }
113
forwardListCount()114 int BackForwardList::forwardListCount()
115 {
116 return m_client->forwardListCount();
117 }
118
itemAtIndex(int index)119 HistoryItem* BackForwardList::itemAtIndex(int index)
120 {
121 return m_client->itemAtIndex(index);
122 }
123
entries()124 HistoryItemVector& BackForwardList::entries()
125 {
126 static HistoryItemVector noEntries;
127 return noEntries;
128 }
129
close()130 void BackForwardList::close()
131 {
132 if (m_client)
133 m_client->close();
134 m_page = 0;
135 m_closed = true;
136 }
137
closed()138 bool BackForwardList::closed()
139 {
140 return m_closed;
141 }
142
143 } // namespace WebCore
144