This source file includes following definitions.
- m_doneChecking
- processMeta
- checkForMetaCharset
#include "config.h"
#include "core/html/parser/HTMLMetaCharsetParser.h"
#include "HTMLNames.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/parser/HTMLParserOptions.h"
#include "core/html/parser/HTMLTokenizer.h"
#include "wtf/text/TextEncodingRegistry.h"
#include "wtf/text/WTFString.h"
using namespace WTF;
namespace WebCore {
using namespace HTMLNames;
HTMLMetaCharsetParser::HTMLMetaCharsetParser()
: m_tokenizer(HTMLTokenizer::create(HTMLParserOptions(0)))
, m_assumedCodec(newTextCodec(Latin1Encoding()))
, m_inHeadSection(true)
, m_doneChecking(false)
{
}
HTMLMetaCharsetParser::~HTMLMetaCharsetParser()
{
}
bool HTMLMetaCharsetParser::processMeta()
{
const HTMLToken::AttributeList& tokenAttributes = m_token.attributes();
HTMLAttributeList attributes;
for (HTMLToken::AttributeList::const_iterator iter = tokenAttributes.begin(); iter != tokenAttributes.end(); ++iter) {
String attributeName = attemptStaticStringCreation(iter->name, Likely8Bit);
String attributeValue = StringImpl::create8BitIfPossible(iter->value);
attributes.append(std::make_pair(attributeName, attributeValue));
}
m_encoding = encodingFromMetaAttributes(attributes);
return m_encoding.isValid();
}
static const int bytesToCheckUnconditionally = 1024;
bool HTMLMetaCharsetParser::checkForMetaCharset(const char* data, size_t length)
{
if (m_doneChecking)
return true;
ASSERT(!m_encoding.isValid());
m_input.append(SegmentedString(m_assumedCodec->decode(data, length)));
while (m_tokenizer->nextToken(m_input, m_token)) {
bool end = m_token.type() == HTMLToken::EndTag;
if (end || m_token.type() == HTMLToken::StartTag) {
String tagName = attemptStaticStringCreation(m_token.name(), Likely8Bit);
if (!end) {
m_tokenizer->updateStateFor(tagName);
if (threadSafeMatch(tagName, metaTag) && processMeta()) {
m_doneChecking = true;
return true;
}
}
if (!threadSafeMatch(tagName, scriptTag) && !threadSafeMatch(tagName, noscriptTag)
&& !threadSafeMatch(tagName, styleTag) && !threadSafeMatch(tagName, linkTag)
&& !threadSafeMatch(tagName, metaTag) && !threadSafeMatch(tagName, objectTag)
&& !threadSafeMatch(tagName, titleTag) && !threadSafeMatch(tagName, baseTag)
&& (end || !threadSafeMatch(tagName, htmlTag)) && (end || !threadSafeMatch(tagName, headTag))) {
m_inHeadSection = false;
}
}
if (!m_inHeadSection && m_input.numberOfCharactersConsumed() >= bytesToCheckUnconditionally) {
m_doneChecking = true;
return true;
}
m_token.clear();
}
return false;
}
}