diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
commit | 32761a6cee1d0dee366b885b7b9c777e67885688 (patch) | |
tree | d6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/xml/parser/XMLDocumentParser.cpp | |
parent | a4e969f4965059196ca948db781e52f7cfebf19e (diff) | |
download | WebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz |
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/xml/parser/XMLDocumentParser.cpp')
-rw-r--r-- | Source/WebCore/xml/parser/XMLDocumentParser.cpp | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/Source/WebCore/xml/parser/XMLDocumentParser.cpp b/Source/WebCore/xml/parser/XMLDocumentParser.cpp index 3fd7dbbee..547ffcb05 100644 --- a/Source/WebCore/xml/parser/XMLDocumentParser.cpp +++ b/Source/WebCore/xml/parser/XMLDocumentParser.cpp @@ -44,8 +44,6 @@ #include "ResourceError.h" #include "ResourceRequest.h" #include "ResourceResponse.h" -#include "SVGNames.h" -#include "SVGStyleElement.h" #include "ScriptElement.h" #include "ScriptSourceCode.h" #include "TextResourceDecoder.h" @@ -55,6 +53,11 @@ #include <wtf/Threading.h> #include <wtf/Vector.h> +#if ENABLE(SVG) +#include "SVGNames.h" +#include "SVGStyleElement.h" +#endif + namespace WebCore { using namespace HTMLNames; @@ -88,8 +91,8 @@ void XMLDocumentParser::clearCurrentNodeStack() { if (m_currentNode && m_currentNode != document()) m_currentNode->deref(); - m_currentNode = nullptr; - m_leafTextNode = nullptr; + m_currentNode = 0; + m_leafTextNode = 0; if (m_currentNodeStack.size()) { // Aborted parsing. for (size_t i = m_currentNodeStack.size() - 1; i != 0; --i) @@ -105,9 +108,9 @@ void XMLDocumentParser::insert(const SegmentedString&) ASSERT_NOT_REACHED(); } -void XMLDocumentParser::append(RefPtr<StringImpl>&& inputSource) +void XMLDocumentParser::append(PassRefPtr<StringImpl> inputSource) { - SegmentedString source(WTFMove(inputSource)); + SegmentedString source(inputSource); if (m_sawXSLTransform || !m_sawFirstElement) m_originalSourceForTransform.append(source); @@ -121,7 +124,7 @@ void XMLDocumentParser::append(RefPtr<StringImpl>&& inputSource) doWrite(source.toString()); - // After parsing, dispatch image beforeload events. + // After parsing, go ahead and dispatch image beforeload events. ImageLoader::dispatchPendingBeforeLoadEvents(); } @@ -136,15 +139,12 @@ void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* m, Te stopParsing(); } -void XMLDocumentParser::createLeafTextNode() +void XMLDocumentParser::enterText() { - if (m_leafTextNode) - return; - ASSERT(m_bufferedText.size() == 0); ASSERT(!m_leafTextNode); m_leafTextNode = Text::create(m_currentNode->document(), ""); - m_currentNode->parserAppendChild(*m_leafTextNode); + m_currentNode->parserAppendChild(m_leafTextNode.get()); } static inline String toString(const xmlChar* string, size_t size) @@ -153,23 +153,19 @@ static inline String toString(const xmlChar* string, size_t size) } -bool XMLDocumentParser::updateLeafTextNode() +void XMLDocumentParser::exitText() { if (isStopped()) - return false; + return; if (!m_leafTextNode) - return true; - - // This operation might fire mutation event, see below. - m_leafTextNode->appendData(toString(m_bufferedText.data(), m_bufferedText.size())); - m_bufferedText = { }; + return; - m_leafTextNode = nullptr; + m_leafTextNode->appendData(toString(m_bufferedText.data(), m_bufferedText.size()), IGNORE_EXCEPTION); + Vector<xmlChar> empty; + m_bufferedText.swap(empty); - // Hence, we need to check again whether the parser is stopped, since mutation - // event handlers executed by appendData might have detached this parser. - return !isStopped(); + m_leafTextNode = 0; } void XMLDocumentParser::detach() @@ -198,7 +194,7 @@ void XMLDocumentParser::end() if (m_sawError) insertErrorMessageBlock(); else { - updateLeafTextNode(); + exitText(); document()->styleResolverChanged(RecalcStyleImmediately); } @@ -237,10 +233,10 @@ void XMLDocumentParser::notifyFinished(CachedResource* unusedResource) bool wasCanceled = m_pendingScript->wasCanceled(); m_pendingScript->removeClient(this); - m_pendingScript = nullptr; + m_pendingScript = 0; RefPtr<Element> e = m_scriptElement; - m_scriptElement = nullptr; + m_scriptElement = 0; ScriptElement* scriptElement = toScriptElementIfPossible(e.get()); ASSERT(scriptElement); @@ -255,7 +251,7 @@ void XMLDocumentParser::notifyFinished(CachedResource* unusedResource) scriptElement->dispatchLoadEvent(); } - m_scriptElement = nullptr; + m_scriptElement = 0; if (!isDetached() && !m_requestingScript) resumeParsing(); @@ -268,8 +264,6 @@ bool XMLDocumentParser::isWaitingForScripts() const void XMLDocumentParser::pauseParsing() { - ASSERT(!m_parserPaused); - if (m_parsingFragment) return; @@ -284,16 +278,17 @@ bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragm // FIXME: We need to implement the HTML5 XML Fragment parsing algorithm: // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#xml-fragment-parsing-algorithm // For now we have a hack for script/style innerHTML support: - if (contextElement && (contextElement->hasLocalName(HTMLNames::scriptTag.localName()) || contextElement->hasLocalName(HTMLNames::styleTag.localName()))) { + if (contextElement && (contextElement->hasLocalName(HTMLNames::scriptTag) || contextElement->hasLocalName(HTMLNames::styleTag))) { fragment.parserAppendChild(fragment.document().createTextNode(chunk)); return true; } RefPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, contextElement, parserContentPolicy); bool wellFormed = parser->appendFragmentSource(chunk); - // Do not call finish(). The finish() and doEnd() implementations touch the main document and loader and can cause crashes in the fragment case. + // Do not call finish(). Current finish() and doEnd() implementations touch the main Document/loader + // and can cause crashes in the fragment case. parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction. - return wellFormed; // appendFragmentSource()'s wellFormed is more permissive than Document::wellFormed(). + return wellFormed; // appendFragmentSource()'s wellFormed is more permissive than wellFormed(). } } // namespace WebCore |