#include "config.h"
#include "CachedPage.h"
#include "CachedFramePlatformData.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameView.h"
#include <wtf/RefCountedLeakCounter.h>
#if ENABLE(SVG)
#include "SVGDocumentExtensions.h"
#endif
namespace WebCore {
#ifndef NDEBUG
static WTF::RefCountedLeakCounter& cachedFrameCounter()
{
DEFINE_STATIC_LOCAL(WTF::RefCountedLeakCounter, counter, ("CachedFrame"));
return counter;
}
#endif
CachedFrame::CachedFrame(Frame* frame)
: m_document(frame->document())
, m_documentLoader(frame->loader()->documentLoader())
, m_view(frame->view())
, m_mousePressNode(frame->eventHandler()->mousePressNode())
, m_URL(frame->loader()->url())
, m_cachedFrameScriptData(frame)
{
#ifndef NDEBUG
cachedFrameCounter().increment();
#endif
m_document->documentWillBecomeInactive();
frame->clearTimers();
m_document->setInPageCache(true);
}
CachedFrame::~CachedFrame()
{
#ifndef NDEBUG
cachedFrameCounter().decrement();
#endif
clear();
}
void CachedFrame::restore(Frame* frame)
{
ASSERT(m_document->view() == m_view);
m_cachedFrameScriptData.restore(frame);
#if ENABLE(SVG)
if (m_document && m_document->svgExtensions())
m_document->accessSVGExtensions()->unpauseAnimations();
#endif
frame->animation()->resumeAnimations(m_document.get());
frame->eventHandler()->setMousePressNode(mousePressNode());
}
void CachedFrame::clear()
{
if (!m_document)
return;
if (m_cachedFramePlatformData)
m_cachedFramePlatformData->clear();
ASSERT(m_view);
ASSERT(m_document->frame() == m_view->frame());
if (m_document->inPageCache()) {
Frame::clearTimers(m_view.get(), m_document.get());
m_document->setInPageCache(false);
m_document->detach();
m_document->removeAllEventListenersFromAllNodes();
m_view->clearFrame();
}
ASSERT(!m_document->inPageCache());
m_document = 0;
m_view = 0;
m_mousePressNode = 0;
m_URL = KURL();
m_cachedFramePlatformData.clear();
m_cachedFrameScriptData.clear();
}
void CachedFrame::setCachedFramePlatformData(CachedFramePlatformData* data)
{
m_cachedFramePlatformData.set(data);
}
CachedFramePlatformData* CachedFrame::cachedFramePlatformData()
{
return m_cachedFramePlatformData.get();
}
}