diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/xml/parser/XMLDocumentParser.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/xml/parser/XMLDocumentParser.h')
-rw-r--r-- | Source/WebCore/xml/parser/XMLDocumentParser.h | 232 |
1 files changed, 113 insertions, 119 deletions
diff --git a/Source/WebCore/xml/parser/XMLDocumentParser.h b/Source/WebCore/xml/parser/XMLDocumentParser.h index 7b7e22038..161fd5db8 100644 --- a/Source/WebCore/xml/parser/XMLDocumentParser.h +++ b/Source/WebCore/xml/parser/XMLDocumentParser.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2000 Peter Kelly (pmk@post.com) - * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2005-2016 Apple Inc. All rights reserved. * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) @@ -22,180 +22,174 @@ * */ -#ifndef XMLDocumentParser_h -#define XMLDocumentParser_h +#pragma once -#include "CachedResourceClient.h" -#include "CachedResourceHandle.h" #include "FragmentScriptingPermission.h" +#include "PendingScriptClient.h" #include "ScriptableDocumentParser.h" #include "SegmentedString.h" #include "XMLErrors.h" +#include <libxml/tree.h> +#include <libxml/xmlstring.h> #include <wtf/HashMap.h> #include <wtf/text/AtomicStringHash.h> #include <wtf/text/CString.h> -#include <libxml/tree.h> -#include <libxml/xmlstring.h> - namespace WebCore { class ContainerNode; -class CachedScript; class CachedResourceLoader; class DocumentFragment; -class Document; class Element; class FrameView; class PendingCallbacks; class Text; - class XMLParserContext : public RefCounted<XMLParserContext> { - public: - static PassRefPtr<XMLParserContext> createMemoryParser(xmlSAXHandlerPtr, void* userData, const CString& chunk); - static PassRefPtr<XMLParserContext> createStringParser(xmlSAXHandlerPtr, void* userData); - ~XMLParserContext(); - xmlParserCtxtPtr context() const { return m_context; } +class XMLParserContext : public RefCounted<XMLParserContext> { +public: + static RefPtr<XMLParserContext> createMemoryParser(xmlSAXHandlerPtr, void* userData, const CString& chunk); + static Ref<XMLParserContext> createStringParser(xmlSAXHandlerPtr, void* userData); + ~XMLParserContext(); + xmlParserCtxtPtr context() const { return m_context; } + +private: + XMLParserContext(xmlParserCtxtPtr context) + : m_context(context) + { + } + xmlParserCtxtPtr m_context; +}; + +class XMLDocumentParser final : public ScriptableDocumentParser, public PendingScriptClient { + WTF_MAKE_FAST_ALLOCATED; +public: + static Ref<XMLDocumentParser> create(Document& document, FrameView* view) + { + return adoptRef(*new XMLDocumentParser(document, view)); + } + static Ref<XMLDocumentParser> create(DocumentFragment& fragment, Element* element, ParserContentPolicy parserContentPolicy) + { + return adoptRef(*new XMLDocumentParser(fragment, element, parserContentPolicy)); + } - private: - XMLParserContext(xmlParserCtxtPtr context) - : m_context(context) - { - } - xmlParserCtxtPtr m_context; - }; + ~XMLDocumentParser(); - class XMLDocumentParser : public ScriptableDocumentParser, public CachedResourceClient { - WTF_MAKE_FAST_ALLOCATED; - public: - static PassRefPtr<XMLDocumentParser> create(Document& document, FrameView* view) - { - return adoptRef(new XMLDocumentParser(document, view)); - } - static PassRefPtr<XMLDocumentParser> create(DocumentFragment& fragment, Element* element, ParserContentPolicy parserContentPolicy) - { - return adoptRef(new XMLDocumentParser(fragment, element, parserContentPolicy)); - } + // Exposed for callbacks: + void handleError(XMLErrors::ErrorType, const char* message, TextPosition); - ~XMLDocumentParser(); + void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; } + bool isXHTMLDocument() const { return m_isXHTMLDocument; } - // Exposed for callbacks: - void handleError(XMLErrors::ErrorType, const char* message, TextPosition); + static bool parseDocumentFragment(const String&, DocumentFragment&, Element* parent = nullptr, ParserContentPolicy = AllowScriptingContent); - void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; } - bool isXHTMLDocument() const { return m_isXHTMLDocument; } + // Used by XMLHttpRequest to check if the responseXML was well formed. + bool wellFormed() const final { return !m_sawError; } - static bool parseDocumentFragment(const String&, DocumentFragment&, Element* parent = 0, ParserContentPolicy = AllowScriptingContent); + static bool supportsXMLVersion(const String&); - // Used by the XMLHttpRequest to check if the responseXML was well formed. - virtual bool wellFormed() const { return !m_sawError; } +private: + explicit XMLDocumentParser(Document&, FrameView* = nullptr); + XMLDocumentParser(DocumentFragment&, Element*, ParserContentPolicy); - TextPosition textPosition() const; + void insert(SegmentedString&&) final; + void append(RefPtr<StringImpl>&&) final; + void finish() final; + bool isWaitingForScripts() const final; + void stopParsing() final; + void detach() final; - static bool supportsXMLVersion(const String&); + TextPosition textPosition() const final; + bool shouldAssociateConsoleMessagesWithTextPosition() const final; - private: - XMLDocumentParser(Document&, FrameView* = 0); - XMLDocumentParser(DocumentFragment&, Element*, ParserContentPolicy); + void notifyFinished(PendingScript&) final; - // From DocumentParser - virtual void insert(const SegmentedString&); - virtual void append(PassRefPtr<StringImpl>); - virtual void finish(); - virtual bool isWaitingForScripts() const; - virtual void stopParsing(); - virtual void detach(); + void end(); - // from CachedResourceClient - virtual void notifyFinished(CachedResource*); + void pauseParsing(); + void resumeParsing(); - void end(); + bool appendFragmentSource(const String&); - void pauseParsing(); - void resumeParsing(); +public: + // Callbacks from parser SAX, and other functions needed inside + // the parser implementation, but outside this class. - bool appendFragmentSource(const String&); + void error(XMLErrors::ErrorType, const char* message, va_list args) WTF_ATTRIBUTE_PRINTF(3, 0); + void startElementNs(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, + int numNamespaces, const xmlChar** namespaces, + int numAttributes, int numDefaulted, const xmlChar** libxmlAttributes); + void endElementNs(); + void characters(const xmlChar*, int length); + void processingInstruction(const xmlChar* target, const xmlChar* data); + void cdataBlock(const xmlChar*, int length); + void comment(const xmlChar*); + void startDocument(const xmlChar* version, const xmlChar* encoding, int standalone); + void internalSubset(const xmlChar* name, const xmlChar* externalID, const xmlChar* systemID); + void endDocument(); -public: - // callbacks from parser SAX - void error(XMLErrors::ErrorType, const char* message, va_list args) WTF_ATTRIBUTE_PRINTF(3, 0); - void startElementNs(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, int nb_namespaces, - const xmlChar** namespaces, int nb_attributes, int nb_defaulted, const xmlChar** libxmlAttributes); - void endElementNs(); - void characters(const xmlChar* s, int len); - void processingInstruction(const xmlChar* target, const xmlChar* data); - void cdataBlock(const xmlChar* s, int len); - void comment(const xmlChar* s); - void startDocument(const xmlChar* version, const xmlChar* encoding, int standalone); - void internalSubset(const xmlChar* name, const xmlChar* externalID, const xmlChar* systemID); - void endDocument(); + bool isParsingEntityDeclaration() const { return m_isParsingEntityDeclaration; } + void setIsParsingEntityDeclaration(bool value) { m_isParsingEntityDeclaration = value; } - bool isParsingEntityDeclaration() const { return m_isParsingEntityDeclaration; } - void setIsParsingEntityDeclaration(bool value) { m_isParsingEntityDeclaration = value; } + int depthTriggeringEntityExpansion() const { return m_depthTriggeringEntityExpansion; } + void setDepthTriggeringEntityExpansion(int depth) { m_depthTriggeringEntityExpansion = depth; } - int depthTriggeringEntityExpansion() const { return m_depthTriggeringEntityExpansion; } - void setDepthTriggeringEntityExpansion(int depth) { m_depthTriggeringEntityExpansion = depth; } +private: + void initializeParserContext(const CString& chunk = CString()); - private: - void initializeParserContext(const CString& chunk = CString()); + void pushCurrentNode(ContainerNode*); + void popCurrentNode(); + void clearCurrentNodeStack(); - void pushCurrentNode(ContainerNode*); - void popCurrentNode(); - void clearCurrentNodeStack(); + void insertErrorMessageBlock(); - void insertErrorMessageBlock(); + void createLeafTextNode(); + bool updateLeafTextNode(); - void enterText(); - void exitText(); + void doWrite(const String&); + void doEnd(); - void doWrite(const String&); - void doEnd(); + xmlParserCtxtPtr context() const { return m_context ? m_context->context() : nullptr; }; - FrameView* m_view; + FrameView* m_view { nullptr }; - SegmentedString m_originalSourceForTransform; + SegmentedString m_originalSourceForTransform; - xmlParserCtxtPtr context() const { return m_context ? m_context->context() : 0; }; - RefPtr<XMLParserContext> m_context; - std::unique_ptr<PendingCallbacks> m_pendingCallbacks; - Vector<xmlChar> m_bufferedText; - int m_depthTriggeringEntityExpansion; - bool m_isParsingEntityDeclaration; + RefPtr<XMLParserContext> m_context; + std::unique_ptr<PendingCallbacks> m_pendingCallbacks; + Vector<xmlChar> m_bufferedText; + int m_depthTriggeringEntityExpansion { -1 }; + bool m_isParsingEntityDeclaration { false }; - ContainerNode* m_currentNode; - Vector<ContainerNode*> m_currentNodeStack; + ContainerNode* m_currentNode { nullptr }; + Vector<ContainerNode*> m_currentNodeStack; - RefPtr<Text> m_leafTextNode; + RefPtr<Text> m_leafTextNode; - bool m_sawError; - bool m_sawCSS; - bool m_sawXSLTransform; - bool m_sawFirstElement; - bool m_isXHTMLDocument; - bool m_parserPaused; - bool m_requestingScript; - bool m_finishCalled; + bool m_sawError { false }; + bool m_sawCSS { false }; + bool m_sawXSLTransform { false }; + bool m_sawFirstElement { false }; + bool m_isXHTMLDocument { false }; + bool m_parserPaused { false }; + bool m_requestingScript { false }; + bool m_finishCalled { false }; - std::unique_ptr<XMLErrors> m_xmlErrors; + std::unique_ptr<XMLErrors> m_xmlErrors; - CachedResourceHandle<CachedScript> m_pendingScript; - RefPtr<Element> m_scriptElement; - TextPosition m_scriptStartPosition; + RefPtr<PendingScript> m_pendingScript; + TextPosition m_scriptStartPosition; - bool m_parsingFragment; - AtomicString m_defaultNamespaceURI; + bool m_parsingFragment { false }; + AtomicString m_defaultNamespaceURI; - typedef HashMap<AtomicString, AtomicString> PrefixForNamespaceMap; - PrefixForNamespaceMap m_prefixToNamespaceMap; - SegmentedString m_pendingSrc; - }; + HashMap<AtomicString, AtomicString> m_prefixToNamespaceMap; + SegmentedString m_pendingSrc; +}; #if ENABLE(XSLT) -void* xmlDocPtrForString(CachedResourceLoader*, const String& source, const String& url); +xmlDocPtr xmlDocPtrForString(CachedResourceLoader&, const String& source, const String& url); #endif HashMap<String, String> parseAttributes(const String&, bool& attrsOK); } // namespace WebCore - -#endif // XMLDocumentParser_h |