HTMLViewSourceParser.cpp [plain text]
#include "config.h"
#include "HTMLViewSourceParser.h"
#include "HTMLDocumentParser.h"
#include "HTMLNames.h"
#include "HTMLParserOptions.h"
#include "HTMLViewSourceDocument.h"
namespace WebCore {
HTMLViewSourceParser::HTMLViewSourceParser(HTMLViewSourceDocument* document)
: DecodedDataDocumentParser(document)
, m_tokenizer(HTMLTokenizer::create(HTMLParserOptions(document)))
{
}
HTMLViewSourceParser::~HTMLViewSourceParser()
{
}
void HTMLViewSourceParser::insert(const SegmentedString&)
{
ASSERT_NOT_REACHED();
}
void HTMLViewSourceParser::pumpTokenizer()
{
while (true) {
m_sourceTracker.start(m_input.current(), m_tokenizer.get(), m_token);
if (!m_tokenizer->nextToken(m_input.current(), m_token))
break;
m_sourceTracker.end(m_input.current(), m_tokenizer.get(), m_token);
document()->addSource(sourceForToken(), m_token);
updateTokenizerState();
m_token.clear();
}
}
void HTMLViewSourceParser::append(PassRefPtr<StringImpl> input)
{
m_input.appendToEnd(String(input));
pumpTokenizer();
}
String HTMLViewSourceParser::sourceForToken()
{
return m_sourceTracker.sourceForToken(m_token);
}
void HTMLViewSourceParser::updateTokenizerState()
{
if (m_token.type() != HTMLToken::StartTag)
return;
m_tokenizer->updateStateFor(AtomicString(m_token.name()));
}
void HTMLViewSourceParser::finish()
{
if (!m_input.haveSeenEndOfFile())
m_input.markEndOfFile();
pumpTokenizer();
document()->finishedParsing();
}
}