#include "config.h"
#if ENABLE(WML)
#include "WMLPageState.h"
#include "HistoryItem.h"
#include "KURL.h"
#include "Page.h"
namespace WebCore {
WMLPageState::WMLPageState(Page* page)
: m_page(page)
, m_historyLength(0)
, m_activeCard(0)
, m_hasDeckAccess(false)
{
}
WMLPageState::~WMLPageState()
{
m_variables.clear();
}
void WMLPageState::reset()
{
m_variables.clear();
if (m_page)
m_page->backForwardList()->clearWmlPageHistory();
m_historyLength = 1;
}
bool WMLPageState::setNeedCheckDeckAccess(bool need)
{
if (m_hasDeckAccess && need)
return false;
m_hasDeckAccess = need;
m_accessPath = String();
m_accessDomain = String();
return true;
}
bool WMLPageState::isDeckAccessible()
{
if (!m_hasDeckAccess || !m_page || !m_page->backForwardList() || !m_page->backForwardList()->backItem())
return true;
HistoryItem* histItem = m_page->backForwardList()->backItem();
KURL url(histItem->urlString());
String prevHost = url.host();
String prevPath = url.path();
if (prevHost.isEmpty())
prevHost = "localhost";
histItem = m_page->backForwardList()->currentItem();
KURL curUrl(histItem->urlString());
String curPath = curUrl.path();
if (equalIgnoringRef(url, curUrl))
return true;
if (m_accessPath.isEmpty())
m_accessPath = "/";
else if (m_accessPath.endsWith("/") && (m_accessPath != "/"))
m_accessPath = m_accessPath.left((m_accessPath.length()-1));
if (m_accessDomain.isEmpty())
m_accessDomain = prevHost;
if (prevHost == m_accessDomain) {
if (!m_accessPath.startsWith("/")) {
int index = curPath.reverseFind('/');
if (index != -1) {
curPath = curPath.left(index + 1);
curPath += m_accessPath;
curUrl.setPath(curPath);
m_accessPath = curUrl.path();
}
}
}
if (prevPath.startsWith(m_accessPath) &&
(prevPath[m_accessPath.length()] == '/' || prevPath.length() == m_accessPath.length())) {
unsigned domainLength = m_accessDomain.length();
unsigned hostLength = prevHost.length();
return (prevHost.endsWith(m_accessDomain) && prevHost[hostLength - domainLength - 1] == '.') || hostLength == domainLength;
}
return false;
}
}
#endif