2
* Copyright (C) 2009 Google 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 are
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above
11
* copyright notice, this list of conditions and the following disclaimer
12
* in the documentation and/or other materials provided with the
14
* * Neither the name of Google Inc. nor the names of its
15
* contributors may be used to endorse or promote products derived from
16
* this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
#include "BackForwardListChromium.h"
34
#include "HistoryItem.h"
35
#include "WebViewClient.h"
36
#include "WebViewImpl.h"
37
#include <wtf/text/StringConcatenate.h>
39
using namespace WebCore;
43
const char backForwardNavigationScheme[] = "chrome-back-forward";
45
PassRefPtr<BackForwardListChromium> BackForwardListChromium::create(WebViewImpl* webView)
47
return adoptRef(new BackForwardListChromium(webView));
50
BackForwardListChromium::BackForwardListChromium(WebViewImpl* webView)
55
BackForwardListChromium::~BackForwardListChromium()
59
void BackForwardListChromium::addItem(PassRefPtr<HistoryItem> item)
63
// If WebCore adds a new HistoryItem, it means this is a new navigation (ie,
64
// not a reload or back/forward).
65
m_webView->observeNewNavigation();
67
if (m_webView->client())
68
m_webView->client()->didAddHistoryItem();
71
void BackForwardListChromium::goToItem(HistoryItem* item)
75
if (m_pendingHistoryItem == item)
76
m_pendingHistoryItem = 0;
79
HistoryItem* BackForwardListChromium::itemAtIndex(int index)
81
if (!m_webView->client())
85
return m_currentItem.get();
87
if (index > forwardListCount() || -index > backListCount())
90
// Since we don't keep the entire back/forward list, we have no way to
91
// properly implement this method. We return a dummy entry instead that we
92
// intercept in our FrameLoaderClient implementation in case WebCore asks
93
// to navigate to this HistoryItem.
95
// FIXME: We should change WebCore to handle history.{back,forward,go}
96
// differently. It should perhaps just ask the FrameLoaderClient to
97
// perform those navigations.
99
String urlString = makeString(backForwardNavigationScheme, "://go/", String::number(index));
100
m_pendingHistoryItem = HistoryItem::create(urlString, String(), 0);
101
return m_pendingHistoryItem.get();
104
int BackForwardListChromium::backListCount()
106
if (!m_webView->client())
109
return m_webView->client()->historyBackListCount();
112
int BackForwardListChromium::forwardListCount()
114
if (!m_webView->client())
117
return m_webView->client()->historyForwardListCount();
120
bool BackForwardListChromium::isActive()
122
return m_webView->client();
125
void BackForwardListChromium::close()
128
m_pendingHistoryItem = 0;
131
} // namespace WebKit