#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/xml/parser/xml_document_parser.h"
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlversion.h>
#include <libxslt/xslt.h>
#include <algorithm>
#include <memory>
#include "base/auto_reset.h"
#include "base/numerics/safe_conversions.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/cdata_section.h"
#include "third_party/blink/renderer/core/dom/comment.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_fragment.h"
#include "third_party/blink/renderer/core/dom/document_parser_timing.h"
#include "third_party/blink/renderer/core/dom/document_type.h"
#include "third_party/blink/renderer/core/dom/processing_instruction.h"
#include "third_party/blink/renderer/core/dom/throw_on_dynamic_markup_insertion_count_incrementer.h"
#include "third_party/blink/renderer/core/dom/transform_source.h"
#include "third_party/blink/renderer/core/dom/xml_document.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/html/custom/ce_reactions_scope.h"
#include "third_party/blink/renderer/core/html/html_html_element.h"
#include "third_party/blink/renderer/core/html/html_template_element.h"
#include "third_party/blink/renderer/core/html/parser/html_construction_site.h"
#include "third_party/blink/renderer/core/html/parser/html_entity_parser.h"
#include "third_party/blink/renderer/core/html/parser/text_resource_decoder.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/core/loader/image_loader.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/xml/document_xml_tree_viewer.h"
#include "third_party/blink/renderer/core/xml/document_xslt.h"
#include "third_party/blink/renderer/core/xml/parser/shared_buffer_reader.h"
#include "third_party/blink/renderer/core/xml/parser/xml_document_parser_scope.h"
#include "third_party/blink/renderer/core/xml/parser/xml_parser_input.h"
#include "third_party/blink/renderer/core/xmlns_names.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/raw_resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_error.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_response.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/utf8.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h"
namespace blink {
static const unsigned kMaxXMLTreeDepth = …;
static inline String ToString(const xmlChar* string, size_t length) { … }
static inline String ToString(const xmlChar* string) { … }
static inline AtomicString ToAtomicString(const xmlChar* string,
size_t length) { … }
static inline AtomicString ToAtomicString(const xmlChar* string) { … }
static inline bool HasNoStyleInformation(Document* document) { … }
class PendingStartElementNSCallback final
: public XMLDocumentParser::PendingCallback { … };
class PendingEndElementNSCallback final
: public XMLDocumentParser::PendingCallback { … };
class PendingCharactersCallback final
: public XMLDocumentParser::PendingCallback { … };
class PendingProcessingInstructionCallback final
: public XMLDocumentParser::PendingCallback { … };
class PendingCDATABlockCallback final
: public XMLDocumentParser::PendingCallback { … };
class PendingCommentCallback final : public XMLDocumentParser::PendingCallback { … };
class PendingInternalSubsetCallback final
: public XMLDocumentParser::PendingCallback { … };
class PendingErrorCallback final : public XMLDocumentParser::PendingCallback { … };
void XMLDocumentParser::PushCurrentNode(ContainerNode* n) { … }
void XMLDocumentParser::PopCurrentNode() { … }
void XMLDocumentParser::ClearCurrentNodeStack() { … }
void XMLDocumentParser::Append(const String& input_source) { … }
void XMLDocumentParser::HandleError(XMLErrors::ErrorType type,
const char* formatted_message,
TextPosition position) { … }
void XMLDocumentParser::CreateLeafTextNodeIfNeeded() { … }
bool XMLDocumentParser::UpdateLeafTextNode() { … }
void XMLDocumentParser::Detach() { … }
void XMLDocumentParser::end() { … }
void XMLDocumentParser::Finish() { … }
void XMLDocumentParser::InsertErrorMessageBlock() { … }
bool XMLDocumentParser::IsWaitingForScripts() const { … }
void XMLDocumentParser::PauseParsing() { … }
bool XMLDocumentParser::ParseDocumentFragment(
const String& chunk,
DocumentFragment* fragment,
Element* context_element,
ParserContentPolicy parser_content_policy,
ExceptionState* exception_state) { … }
static int g_global_descriptor = …;
static int MatchFunc(const char*) { … }
static inline void SetAttributes(
Element* element,
Vector<Attribute, kAttributePrealloc>& attribute_vector,
ParserContentPolicy parser_content_policy) { … }
static void SwitchEncoding(xmlParserCtxtPtr ctxt, bool is_8bit) { … }
static void ParseChunk(xmlParserCtxtPtr ctxt, const String& chunk) { … }
static void FinishParsing(xmlParserCtxtPtr ctxt) { … }
#define xmlParseChunk …
static bool IsLibxmlDefaultCatalogFile(const String& url_string) { … }
static bool ShouldAllowExternalLoad(const KURL& url) { … }
static void* OpenFunc(const char* uri) { … }
static int ReadFunc(void* context, char* buffer, int len) { … }
static int WriteFunc(void*, const char*, int) { … }
static int CloseFunc(void* context) { … }
static void ErrorFunc(void*, const char*, ...) { … }
static void InitializeLibXMLIfNecessary() { … }
scoped_refptr<XMLParserContext> XMLParserContext::CreateStringParser(
xmlSAXHandlerPtr handlers,
void* user_data) { … }
scoped_refptr<XMLParserContext> XMLParserContext::CreateMemoryParser(
xmlSAXHandlerPtr handlers,
void* user_data,
const std::string& chunk) { … }
bool XMLDocumentParser::SupportsXMLVersion(const String& version) { … }
XMLDocumentParser::XMLDocumentParser(Document& document,
LocalFrameView* frame_view)
: … { … }
XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment,
Element* parent_element,
ParserContentPolicy parser_content_policy)
: … { … }
XMLParserContext::~XMLParserContext() { … }
XMLDocumentParser::~XMLDocumentParser() = default;
void XMLDocumentParser::Trace(Visitor* visitor) const { … }
void XMLDocumentParser::DoWrite(const String& parse_string) { … }
struct xmlSAX2Namespace { … };
static inline void HandleNamespaceAttributes(
Vector<Attribute, kAttributePrealloc>& prefixed_attributes,
const xmlChar** libxml_namespaces,
int nb_namespaces,
ExceptionState& exception_state) { … }
struct xmlSAX2Attributes { … };
static inline void HandleElementAttributes(
Vector<Attribute, kAttributePrealloc>& prefixed_attributes,
const xmlChar** libxml_attributes,
int nb_attributes,
const HashMap<AtomicString, AtomicString>& initial_prefix_to_namespace_map,
ExceptionState& exception_state) { … }
void XMLDocumentParser::StartElementNs(const AtomicString& local_name,
const AtomicString& prefix,
const AtomicString& uri,
int nb_namespaces,
const xmlChar** libxml_namespaces,
int nb_attributes,
int nb_defaulted,
const xmlChar** libxml_attributes) { … }
void XMLDocumentParser::EndElementNs() { … }
void XMLDocumentParser::NotifyScriptExecuted() { … }
void XMLDocumentParser::SetScriptStartPosition(TextPosition text_position) { … }
void XMLDocumentParser::Characters(const xmlChar* chars, int length) { … }
void XMLDocumentParser::GetError(XMLErrors::ErrorType type,
const char* message,
va_list args) { … }
void XMLDocumentParser::GetProcessingInstruction(const String& target,
const String& data) { … }
void XMLDocumentParser::CdataBlock(const String& text) { … }
void XMLDocumentParser::Comment(const String& text) { … }
enum StandaloneInfo { … };
void XMLDocumentParser::StartDocument(const String& version,
const String& encoding,
int standalone) { … }
void XMLDocumentParser::EndDocument() { … }
void XMLDocumentParser::InternalSubset(const String& name,
const String& external_id,
const String& system_id) { … }
static inline XMLDocumentParser* GetParser(void* closure) { … }
static void StartElementNsHandler(void* closure,
const xmlChar* local_name,
const xmlChar* prefix,
const xmlChar* uri,
int nb_namespaces,
const xmlChar** namespaces,
int nb_attributes,
int nb_defaulted,
const xmlChar** libxml_attributes) { … }
static void EndElementNsHandler(void* closure,
const xmlChar*,
const xmlChar*,
const xmlChar*) { … }
static void CharactersHandler(void* closure, const xmlChar* chars, int length) { … }
static void ProcessingInstructionHandler(void* closure,
const xmlChar* target,
const xmlChar* data) { … }
static void CdataBlockHandler(void* closure, const xmlChar* text, int length) { … }
static void CommentHandler(void* closure, const xmlChar* text) { … }
PRINTF_FORMAT(2, 3)
static void WarningHandler(void* closure, const char* message, ...) { … }
PRINTF_FORMAT(2, 3)
static void NormalErrorHandler(void* closure, const char* message, ...) { … }
static xmlChar g_shared_xhtml_entity_result[9] = …;
static xmlEntityPtr SharedXHTMLEntity() { … }
static size_t ConvertUTF16EntityToUTF8(const UChar* utf16_entity,
size_t number_of_code_units,
char* target,
size_t target_size) { … }
static xmlEntityPtr GetXHTMLEntity(const xmlChar* name) { … }
static xmlEntityPtr GetEntityHandler(void* closure, const xmlChar* name) { … }
static void StartDocumentHandler(void* closure) { … }
static void EndDocumentHandler(void* closure) { … }
static void InternalSubsetHandler(void* closure,
const xmlChar* name,
const xmlChar* external_id,
const xmlChar* system_id) { … }
static void ExternalSubsetHandler(void* closure,
const xmlChar*,
const xmlChar* external_id,
const xmlChar*) { … }
static void IgnorableWhitespaceHandler(void*, const xmlChar*, int) { … }
void XMLDocumentParser::InitializeParserContext(const std::string& chunk) { … }
void XMLDocumentParser::DoEnd() { … }
xmlDocPtr XmlDocPtrForString(Document* document,
const String& source,
const String& url) { … }
OrdinalNumber XMLDocumentParser::LineNumber() const { … }
OrdinalNumber XMLDocumentParser::ColumnNumber() const { … }
TextPosition XMLDocumentParser::GetTextPosition() const { … }
void XMLDocumentParser::StopParsing() { … }
void XMLDocumentParser::ResumeParsing() { … }
bool XMLDocumentParser::AppendFragmentSource(const String& chunk) { … }
void XMLDocumentParser::DidAddPendingParserBlockingStylesheet() { … }
void XMLDocumentParser::DidLoadAllPendingParserBlockingStylesheets() { … }
void XMLDocumentParser::CheckIfBlockingStyleSheetAdded() { … }
void XMLDocumentParser::ExecuteScriptsWaitingForResources() { … }
struct AttributeParseState { … };
static void AttributesStartElementNsHandler(void* closure,
const xmlChar* xml_local_name,
const xmlChar* ,
const xmlChar* ,
int ,
const xmlChar** ,
int nb_attributes,
int ,
const xmlChar** libxml_attributes) { … }
HashMap<String, String> ParseAttributes(const String& string, bool& attrs_ok) { … }
#undef xmlParseChunk
}