#include "config.h"
#include "CachedPage.h"
#include "CachedFramePlatformData.h"
#include "CString.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameLoaderClient.h"
#include "FrameView.h"
#include "Logging.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())
{
#ifndef NDEBUG
cachedFrameCounter().increment();
#endif
ASSERT(m_document);
ASSERT(m_documentLoader);
ASSERT(m_view);
m_document->suspendActiveDOMObjects();
m_cachedFrameScriptData.set(new ScriptCachedFrameData(frame));
m_view->detachCustomScrollbars();
m_document->documentWillBecomeInactive();
frame->clearTimers();
m_document->setInPageCache(true);
frame->loader()->client()->savePlatformDataToCachedFrame(this);
for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling())
m_childFrames.append(CachedFrame::create(child));
LOG(PageCache, "Finished creating CachedFrame with url %s and documentloader %p\n", m_url.string().utf8().data(), m_documentLoader.get());
}
CachedFrame::~CachedFrame()
{
#ifndef NDEBUG
cachedFrameCounter().decrement();
#endif
clear();
}
void CachedFrame::restore()
{
ASSERT(m_document->view() == m_view);
Frame* frame = m_view->frame();
m_cachedFrameScriptData->restore(frame);
#if ENABLE(SVG)
if (m_document->svgExtensions())
m_document->accessSVGExtensions()->unpauseAnimations();
#endif
frame->animation()->resumeAnimations(m_document.get());
frame->eventHandler()->setMousePressNode(mousePressNode());
m_document->resumeActiveDOMObjects();
frame->script()->updatePlatformScriptObjects();
}
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->removeAllEventListeners();
m_document->setInPageCache(false);
m_document->detach();
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();
}
}