This source file includes following definitions.
- didSeeScript
- m_isSuspendedWithActiveTimer
- continueNextChunkTimerFired
- checkForYieldBeforeScript
- scheduleForResume
- suspend
- resume
#include "config.h"
#include "core/html/parser/HTMLParserScheduler.h"
#include "core/dom/Document.h"
#include "core/html/parser/HTMLDocumentParser.h"
#include "core/frame/FrameView.h"
namespace WebCore {
const int HTMLParserScheduler::parserChunkSize = 4096;
const double HTMLParserScheduler::parserTimeLimit = 0.2;
ActiveParserSession::ActiveParserSession(Document* document)
: m_document(document)
{
if (!m_document)
return;
m_document->incrementActiveParserCount();
}
ActiveParserSession::~ActiveParserSession()
{
if (!m_document)
return;
m_document->decrementActiveParserCount();
}
PumpSession::PumpSession(unsigned& nestingLevel, Document* document)
: NestingLevelIncrementer(nestingLevel)
, ActiveParserSession(document)
, processedTokens(INT_MAX)
, startTime(0)
, needsYield(false)
, didSeeScript(false)
{
}
PumpSession::~PumpSession()
{
}
HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser)
: m_parser(parser)
, m_continueNextChunkTimer(this, &HTMLParserScheduler::continueNextChunkTimerFired)
, m_isSuspendedWithActiveTimer(false)
{
}
HTMLParserScheduler::~HTMLParserScheduler()
{
m_continueNextChunkTimer.stop();
}
void HTMLParserScheduler::continueNextChunkTimerFired(Timer<HTMLParserScheduler>* timer)
{
ASSERT_UNUSED(timer, timer == &m_continueNextChunkTimer);
m_parser->resumeParsingAfterYield();
}
void HTMLParserScheduler::checkForYieldBeforeScript(PumpSession& session)
{
Document* document = m_parser->document();
bool needsFirstPaint = document->view() && !document->view()->hasEverPainted();
if (needsFirstPaint && document->shouldParserYieldAgressivelyBeforeScriptExecution())
session.needsYield = true;
session.didSeeScript = true;
}
void HTMLParserScheduler::scheduleForResume()
{
m_continueNextChunkTimer.startOneShot(0, FROM_HERE);
}
void HTMLParserScheduler::suspend()
{
ASSERT(!m_isSuspendedWithActiveTimer);
if (!m_continueNextChunkTimer.isActive())
return;
m_isSuspendedWithActiveTimer = true;
m_continueNextChunkTimer.stop();
}
void HTMLParserScheduler::resume()
{
ASSERT(!m_continueNextChunkTimer.isActive());
if (!m_isSuspendedWithActiveTimer)
return;
m_isSuspendedWithActiveTimer = false;
m_continueNextChunkTimer.startOneShot(0, FROM_HERE);
}
}