2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitDLL.h"
28 #include "WebBackForwardList.h"
32 #include "WebPreferences.h"
34 #include <WebCore/BackForwardListImpl.h>
35 #include <WebCore/COMPtr.h>
36 #include <WebCore/HistoryItem.h>
39 using namespace WebCore;
41 // WebBackForwardList ----------------------------------------------------------------
43 // FIXME: Instead of this we could just create a class derived from BackForwardListImpl
44 // with a pointer to a WebBackForwardList in it.
45 static HashMap<BackForwardListImpl*, WebBackForwardList*>& backForwardListWrappers()
47 static HashMap<BackForwardListImpl*, WebBackForwardList*> staticBackForwardListWrappers;
48 return staticBackForwardListWrappers;
51 WebBackForwardList::WebBackForwardList(PassRefPtr<BackForwardListImpl> backForwardList)
53 , m_backForwardList(backForwardList)
55 ASSERT(!backForwardListWrappers().contains(m_backForwardList.get()));
56 backForwardListWrappers().set(m_backForwardList.get(), this);
59 gClassNameCount.add("WebBackForwardList");
62 WebBackForwardList::~WebBackForwardList()
64 ASSERT(m_backForwardList->closed());
66 ASSERT(backForwardListWrappers().contains(m_backForwardList.get()));
67 backForwardListWrappers().remove(m_backForwardList.get());
70 gClassNameCount.remove("WebBackForwardList");
73 WebBackForwardList* WebBackForwardList::createInstance(PassRefPtr<BackForwardListImpl> backForwardList)
75 WebBackForwardList* instance;
77 instance = backForwardListWrappers().get(backForwardList.get());
80 instance = new WebBackForwardList(backForwardList);
86 // IUnknown -------------------------------------------------------------------
88 HRESULT STDMETHODCALLTYPE WebBackForwardList::QueryInterface(REFIID riid, void** ppvObject)
91 if (IsEqualGUID(riid, IID_IUnknown))
92 *ppvObject = static_cast<IWebBackForwardList*>(this);
93 else if (IsEqualGUID(riid, IID_IWebBackForwardList))
94 *ppvObject = static_cast<IWebBackForwardList*>(this);
95 else if (IsEqualGUID(riid, IID_IWebBackForwardListPrivate))
96 *ppvObject = static_cast<IWebBackForwardListPrivate*>(this);
104 ULONG STDMETHODCALLTYPE WebBackForwardList::AddRef(void)
109 ULONG STDMETHODCALLTYPE WebBackForwardList::Release(void)
111 ULONG newRef = --m_refCount;
118 // IWebBackForwardList ---------------------------------------------------------
120 HRESULT STDMETHODCALLTYPE WebBackForwardList::addItem(
121 /* [in] */ IWebHistoryItem* item)
123 COMPtr<WebHistoryItem> webHistoryItem;
125 if (!item || FAILED(item->QueryInterface(&webHistoryItem)))
128 m_backForwardList->addItem(webHistoryItem->historyItem());
132 HRESULT STDMETHODCALLTYPE WebBackForwardList::goBack( void)
134 m_backForwardList->goBack();
138 HRESULT STDMETHODCALLTYPE WebBackForwardList::goForward( void)
140 m_backForwardList->goForward();
144 HRESULT STDMETHODCALLTYPE WebBackForwardList::goToItem(
145 /* [in] */ IWebHistoryItem* item)
147 COMPtr<WebHistoryItem> webHistoryItem;
149 if (!item || FAILED(item->QueryInterface(&webHistoryItem)))
152 m_backForwardList->goToItem(webHistoryItem->historyItem());
156 HRESULT STDMETHODCALLTYPE WebBackForwardList::backItem(
157 /* [retval][out] */ IWebHistoryItem** item)
162 HistoryItem* historyItem = m_backForwardList->backItem();
167 *item = WebHistoryItem::createInstance(historyItem);
171 HRESULT STDMETHODCALLTYPE WebBackForwardList::currentItem(
172 /* [retval][out] */ IWebHistoryItem** item)
177 HistoryItem* historyItem = m_backForwardList->currentItem();
182 *item = WebHistoryItem::createInstance(historyItem);
186 HRESULT STDMETHODCALLTYPE WebBackForwardList::forwardItem(
187 /* [retval][out] */ IWebHistoryItem** item)
192 HistoryItem* historyItem = m_backForwardList->forwardItem();
197 *item = WebHistoryItem::createInstance(historyItem);
201 HRESULT STDMETHODCALLTYPE WebBackForwardList::backListWithLimit(
202 /* [in] */ int limit,
203 /* [out] */ int* listCount,
204 /* [retval][out] */ IWebHistoryItem** list)
206 HistoryItemVector historyItemVector;
207 m_backForwardList->backListWithLimit(limit, historyItemVector);
209 *listCount = static_cast<int>(historyItemVector.size());
212 for (unsigned i = 0; i < historyItemVector.size(); i++)
213 list[i] = WebHistoryItem::createInstance(historyItemVector[i].get());
218 HRESULT STDMETHODCALLTYPE WebBackForwardList::forwardListWithLimit(
219 /* [in] */ int limit,
220 /* [out] */ int* listCount,
221 /* [retval][out] */ IWebHistoryItem** list)
223 HistoryItemVector historyItemVector;
224 m_backForwardList->forwardListWithLimit(limit, historyItemVector);
226 *listCount = static_cast<int>(historyItemVector.size());
229 for (unsigned i = 0; i < historyItemVector.size(); i++)
230 list[i] = WebHistoryItem::createInstance(historyItemVector[i].get());
235 HRESULT STDMETHODCALLTYPE WebBackForwardList::capacity(
236 /* [retval][out] */ int* result)
238 *result = (int)m_backForwardList->capacity();
242 HRESULT STDMETHODCALLTYPE WebBackForwardList::setCapacity(
248 m_backForwardList->setCapacity(size);
252 HRESULT STDMETHODCALLTYPE WebBackForwardList::backListCount(
253 /* [retval][out] */ int* count)
255 *count = m_backForwardList->backListCount();
259 HRESULT STDMETHODCALLTYPE WebBackForwardList::forwardListCount(
260 /* [retval][out] */ int* count)
262 *count = m_backForwardList->forwardListCount();
266 HRESULT STDMETHODCALLTYPE WebBackForwardList::containsItem(
267 /* [in] */ IWebHistoryItem* item,
268 /* [retval][out] */ BOOL* result)
270 COMPtr<WebHistoryItem> webHistoryItem;
272 if (!item || FAILED(item->QueryInterface(&webHistoryItem)))
275 *result = m_backForwardList->containsItem(webHistoryItem->historyItem());
279 HRESULT STDMETHODCALLTYPE WebBackForwardList::itemAtIndex(
280 /* [in] */ int index,
281 /* [retval][out] */ IWebHistoryItem** item)
286 HistoryItem* historyItem = m_backForwardList->itemAtIndex(index);
291 *item = WebHistoryItem::createInstance(historyItem);
295 // IWebBackForwardListPrivate --------------------------------------------------------
297 HRESULT STDMETHODCALLTYPE WebBackForwardList::removeItem(
298 /* [in] */ IWebHistoryItem* item)
300 COMPtr<WebHistoryItem> webHistoryItem;
302 if (!item || FAILED(item->QueryInterface(&webHistoryItem)))
305 m_backForwardList->removeItem(webHistoryItem->historyItem());