bool HTMLTreeBuilderSimulator::simulate(const CompactHTMLToken& token, HTMLTokenizer* tokenizer) { if (token.type() == HTMLToken::StartTag) { const HTMLIdentifier& tagName = token.data(); if (threadSafeMatch(tagName, SVGNames::svgTag)) m_namespaceStack.append(SVG); if (threadSafeMatch(tagName, MathMLNames::mathTag)) m_namespaceStack.append(MathML); if (inForeignContent() && tokenExitsForeignContent(token)) m_namespaceStack.removeLast(); if ((m_namespaceStack.last() == SVG && tokenExitsSVG(token)) || (m_namespaceStack.last() == MathML && tokenExitsMath(token))) m_namespaceStack.append(HTML); if (!inForeignContent()) { // FIXME: This is just a copy of Tokenizer::updateStateFor which uses threadSafeMatches. if (threadSafeHTMLNamesMatch(tagName, textareaTag) || threadSafeHTMLNamesMatch(tagName, titleTag)) tokenizer->setState(HTMLTokenizer::RCDATAState); else if (threadSafeHTMLNamesMatch(tagName, plaintextTag)) tokenizer->setState(HTMLTokenizer::PLAINTEXTState); else if (threadSafeHTMLNamesMatch(tagName, scriptTag)) tokenizer->setState(HTMLTokenizer::ScriptDataState); else if (threadSafeHTMLNamesMatch(tagName, styleTag) || threadSafeHTMLNamesMatch(tagName, iframeTag) || threadSafeHTMLNamesMatch(tagName, xmpTag) || (threadSafeHTMLNamesMatch(tagName, noembedTag) && m_options.pluginsEnabled) || threadSafeHTMLNamesMatch(tagName, noframesTag) || (threadSafeHTMLNamesMatch(tagName, noscriptTag) && m_options.scriptEnabled)) tokenizer->setState(HTMLTokenizer::RAWTEXTState); } } if (token.type() == HTMLToken::EndTag) { const HTMLIdentifier& tagName = token.data(); if ((m_namespaceStack.last() == SVG && threadSafeMatch(tagName, SVGNames::svgTag)) || (m_namespaceStack.last() == MathML && threadSafeMatch(tagName, MathMLNames::mathTag)) || (m_namespaceStack.contains(SVG) && m_namespaceStack.last() == HTML && tokenExitsSVG(token)) || (m_namespaceStack.contains(MathML) && m_namespaceStack.last() == HTML && tokenExitsMath(token))) m_namespaceStack.removeLast(); if (threadSafeHTMLNamesMatch(tagName, scriptTag)) { if (!inForeignContent()) tokenizer->setState(HTMLTokenizer::DataState); return false; } } // FIXME: Also setForceNullCharacterReplacement when in text mode. tokenizer->setForceNullCharacterReplacement(inForeignContent()); tokenizer->setShouldAllowCDATA(inForeignContent()); return true; }
bool BackgroundHTMLParser::simulateTreeBuilder(const CompactHTMLToken& token) { if (token.type() == HTMLTokenTypes::StartTag) { const String& tagName = token.data(); if (threadSafeMatch(tagName, SVGNames::svgTag) || threadSafeMatch(tagName, MathMLNames::mathTag)) m_inForeignContent = true; // FIXME: This is just a copy of Tokenizer::updateStateFor which uses threadSafeMatches. if (threadSafeMatch(tagName, textareaTag) || threadSafeMatch(tagName, titleTag)) m_tokenizer->setState(HTMLTokenizerState::RCDATAState); else if (threadSafeMatch(tagName, plaintextTag)) m_tokenizer->setState(HTMLTokenizerState::PLAINTEXTState); else if (threadSafeMatch(tagName, scriptTag)) m_tokenizer->setState(HTMLTokenizerState::ScriptDataState); else if (threadSafeMatch(tagName, styleTag) || threadSafeMatch(tagName, iframeTag) || threadSafeMatch(tagName, xmpTag) || (threadSafeMatch(tagName, noembedTag) && m_options.pluginsEnabled) || threadSafeMatch(tagName, noframesTag) || (threadSafeMatch(tagName, noscriptTag) && m_options.scriptEnabled)) m_tokenizer->setState(HTMLTokenizerState::RAWTEXTState); } if (token.type() == HTMLTokenTypes::EndTag) { const String& tagName = token.data(); if (threadSafeMatch(tagName, SVGNames::svgTag) || threadSafeMatch(tagName, MathMLNames::mathTag)) m_inForeignContent = false; if (threadSafeMatch(tagName, scriptTag)) return false; } // FIXME: Need to set setForceNullCharacterReplacement based on m_inForeignContent as well. m_tokenizer->setShouldAllowCDATA(m_inForeignContent); return true; }