2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/xml_reader_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/notreached.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_stream.h"
|
2020-07-08 19:23:29 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Static functions
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefXmlReader> CefXmlReader::Create(CefRefPtr<CefStreamReader> stream,
|
|
|
|
EncodingType encodingType,
|
|
|
|
const CefString& URI) {
|
|
|
|
CefRefPtr<CefXmlReaderImpl> impl(new CefXmlReaderImpl());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!impl->Initialize(stream, encodingType, URI)) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return impl.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// CefXmlReaderImpl
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlInputReadCallback:
|
|
|
|
* @context: an Input context
|
|
|
|
* @buffer: the buffer to store data read
|
|
|
|
* @len: the length of the buffer in bytes
|
|
|
|
*
|
|
|
|
* Callback used in the I/O Input API to read the resource
|
|
|
|
*
|
|
|
|
* Returns the number of bytes read or -1 in case of error
|
|
|
|
*/
|
2017-05-17 11:29:28 +02:00
|
|
|
int XMLCALL xml_read_callback(void* context, char* buffer, int len) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefStreamReader> reader(static_cast<CefStreamReader*>(context));
|
|
|
|
return reader->Read(buffer, 1, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlTextReaderErrorFunc:
|
|
|
|
* @arg: the user argument
|
|
|
|
* @msg: the message
|
|
|
|
* @severity: the severity of the error
|
|
|
|
* @locator: a locator indicating where the error occured
|
|
|
|
*
|
|
|
|
* Signature of an error callback from a reader parser
|
|
|
|
*/
|
2017-05-17 11:29:28 +02:00
|
|
|
void XMLCALL xml_error_callback(void* arg,
|
|
|
|
const char* msg,
|
2012-04-03 03:34:16 +02:00
|
|
|
xmlParserSeverities severity,
|
|
|
|
xmlTextReaderLocatorPtr locator) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!msg) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string error_str(msg);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!error_str.empty() && error_str[error_str.length() - 1] == '\n') {
|
2017-05-17 11:29:28 +02:00
|
|
|
error_str.resize(error_str.length() - 1);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << error_str << ", line " << xmlTextReaderLocatorLineNumber(locator);
|
|
|
|
|
|
|
|
LOG(INFO) << ss.str();
|
|
|
|
|
|
|
|
CefRefPtr<CefXmlReaderImpl> impl(static_cast<CefXmlReaderImpl*>(arg));
|
|
|
|
impl->AppendError(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlStructuredErrorFunc:
|
|
|
|
* @userData: user provided data for the error callback
|
|
|
|
* @error: the error being raised.
|
|
|
|
*
|
|
|
|
* Signature of the function to use when there is an error and
|
|
|
|
* the module handles the new error reporting mechanism.
|
|
|
|
*/
|
2023-12-06 21:16:15 +01:00
|
|
|
void XMLCALL xml_structured_error_callback(void* userData,
|
|
|
|
const xmlError* error) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!error->message) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string error_str(error->message);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!error_str.empty() && error_str[error_str.length() - 1] == '\n') {
|
2017-05-17 11:29:28 +02:00
|
|
|
error_str.resize(error_str.length() - 1);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << error_str << ", line " << error->line;
|
|
|
|
|
|
|
|
LOG(INFO) << ss.str();
|
|
|
|
|
|
|
|
CefRefPtr<CefXmlReaderImpl> impl(static_cast<CefXmlReaderImpl*>(userData));
|
|
|
|
impl->AppendError(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString xmlCharToString(const xmlChar* xmlStr, bool free) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!xmlStr) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
const char* str = reinterpret_cast<const char*>(xmlStr);
|
|
|
|
CefString wstr = std::string(str);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (free) {
|
2012-04-03 03:34:16 +02:00
|
|
|
xmlFree(const_cast<xmlChar*>(xmlStr));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return wstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefXmlReaderImpl::CefXmlReaderImpl()
|
2024-01-20 23:48:57 +01:00
|
|
|
: supported_thread_id_(base::PlatformThread::CurrentId()) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefXmlReaderImpl::~CefXmlReaderImpl() {
|
2020-01-15 14:36:24 +01:00
|
|
|
if (reader_ != nullptr) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!VerifyContext()) {
|
|
|
|
// Close() is supposed to be called directly. We'll try to free the reader
|
|
|
|
// now on the wrong thread but there's no guarantee this call won't crash.
|
|
|
|
xmlFreeTextReader(reader_);
|
|
|
|
} else {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::Initialize(CefRefPtr<CefStreamReader> stream,
|
|
|
|
EncodingType encodingType,
|
|
|
|
const CefString& URI) {
|
|
|
|
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
|
|
|
|
switch (encodingType) {
|
|
|
|
case XML_ENCODING_UTF8:
|
|
|
|
enc = XML_CHAR_ENCODING_UTF8;
|
|
|
|
break;
|
|
|
|
case XML_ENCODING_UTF16LE:
|
|
|
|
enc = XML_CHAR_ENCODING_UTF16LE;
|
|
|
|
break;
|
|
|
|
case XML_ENCODING_UTF16BE:
|
|
|
|
enc = XML_CHAR_ENCODING_UTF16BE;
|
|
|
|
break;
|
|
|
|
case XML_ENCODING_ASCII:
|
|
|
|
enc = XML_CHAR_ENCODING_ASCII;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the input buffer.
|
|
|
|
xmlParserInputBufferPtr input_buffer = xmlAllocParserInputBuffer(enc);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!input_buffer) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
input_buffer->context = stream.get();
|
|
|
|
input_buffer->readcallback = xml_read_callback;
|
|
|
|
|
|
|
|
// Create the text reader.
|
|
|
|
std::string uriStr = URI;
|
|
|
|
reader_ = xmlNewTextReader(input_buffer, uriStr.c_str());
|
|
|
|
if (!reader_) {
|
|
|
|
// Free the input buffer.
|
|
|
|
xmlFreeParserInputBuffer(input_buffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep a reference to the stream.
|
|
|
|
stream_ = stream;
|
|
|
|
|
|
|
|
// Register the error callbacks.
|
|
|
|
xmlTextReaderSetErrorHandler(reader_, xml_error_callback, this);
|
2017-05-17 11:29:28 +02:00
|
|
|
xmlTextReaderSetStructuredErrorHandler(reader_, xml_structured_error_callback,
|
|
|
|
this);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToNextNode() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderRead(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::Close() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// The input buffer will be freed automatically.
|
|
|
|
xmlFreeTextReader(reader_);
|
2020-01-15 14:36:24 +01:00
|
|
|
reader_ = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::HasError() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return !error_buf_.str().empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetError() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return error_buf_.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefXmlReader::NodeType CefXmlReaderImpl::GetType() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return XML_NODE_UNSUPPORTED;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
switch (xmlTextReaderNodeType(reader_)) {
|
|
|
|
case XML_READER_TYPE_ELEMENT:
|
|
|
|
return XML_NODE_ELEMENT_START;
|
|
|
|
case XML_READER_TYPE_END_ELEMENT:
|
|
|
|
return XML_NODE_ELEMENT_END;
|
|
|
|
case XML_READER_TYPE_ATTRIBUTE:
|
|
|
|
return XML_NODE_ATTRIBUTE;
|
|
|
|
case XML_READER_TYPE_TEXT:
|
|
|
|
return XML_NODE_TEXT;
|
|
|
|
case XML_READER_TYPE_SIGNIFICANT_WHITESPACE:
|
|
|
|
case XML_READER_TYPE_WHITESPACE:
|
|
|
|
return XML_NODE_WHITESPACE;
|
|
|
|
case XML_READER_TYPE_CDATA:
|
|
|
|
return XML_NODE_CDATA;
|
|
|
|
case XML_READER_TYPE_ENTITY_REFERENCE:
|
|
|
|
return XML_NODE_ENTITY_REFERENCE;
|
|
|
|
case XML_READER_TYPE_PROCESSING_INSTRUCTION:
|
|
|
|
return XML_NODE_PROCESSING_INSTRUCTION;
|
|
|
|
case XML_READER_TYPE_COMMENT:
|
|
|
|
return XML_NODE_COMMENT;
|
|
|
|
case XML_READER_TYPE_DOCUMENT_TYPE:
|
|
|
|
return XML_NODE_DOCUMENT_TYPE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return XML_NODE_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefXmlReaderImpl::GetDepth() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return -1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderDepth(reader_);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetLocalName() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderConstLocalName(reader_), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetPrefix() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderConstPrefix(reader_), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetQualifiedName() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderConstName(reader_), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetNamespaceURI() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderConstNamespaceUri(reader_), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetBaseURI() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderConstBaseUri(reader_), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetXmlLang() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderConstXmlLang(reader_), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::IsEmptyElement() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderIsEmptyElement(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::HasValue() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (xmlTextReaderNodeType(reader_) == XML_READER_TYPE_ENTITY_REFERENCE) {
|
|
|
|
// Provide special handling to return entity reference values.
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return xmlTextReaderHasValue(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetValue() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (xmlTextReaderNodeType(reader_) == XML_READER_TYPE_ENTITY_REFERENCE) {
|
|
|
|
// Provide special handling to return entity reference values.
|
|
|
|
xmlNodePtr node = xmlTextReaderCurrentNode(reader_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (node->content != nullptr) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return xmlCharToString(node->content, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
|
|
|
} else {
|
|
|
|
return xmlCharToString(xmlTextReaderConstValue(reader_), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::HasAttributes() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderHasAttributes(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefXmlReaderImpl::GetAttributeCount() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderAttributeCount(reader_);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetAttribute(int index) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderGetAttributeNo(reader_, index), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetAttribute(const CefString& qualifiedName) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string qualifiedNameStr = qualifiedName;
|
2017-05-17 11:29:28 +02:00
|
|
|
return xmlCharToString(
|
|
|
|
xmlTextReaderGetAttribute(reader_, BAD_CAST qualifiedNameStr.c_str()),
|
|
|
|
true);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetAttribute(const CefString& localName,
|
|
|
|
const CefString& namespaceURI) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string localNameStr = localName;
|
|
|
|
std::string namespaceURIStr = namespaceURI;
|
2017-05-17 11:29:28 +02:00
|
|
|
return xmlCharToString(
|
|
|
|
xmlTextReaderGetAttributeNs(reader_, BAD_CAST localNameStr.c_str(),
|
|
|
|
BAD_CAST namespaceURIStr.c_str()),
|
|
|
|
true);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetInnerXml() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderReadInnerXml(reader_), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefXmlReaderImpl::GetOuterXml() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlCharToString(xmlTextReaderReadOuterXml(reader_), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefXmlReaderImpl::GetLineNumber() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return -1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderGetParserLineNumber(reader_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToAttribute(int index) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderMoveToAttributeNo(reader_, index) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToAttribute(const CefString& qualifiedName) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string qualifiedNameStr = qualifiedName;
|
|
|
|
return xmlTextReaderMoveToAttribute(reader_,
|
2017-05-17 11:29:28 +02:00
|
|
|
BAD_CAST qualifiedNameStr.c_str()) == 1
|
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToAttribute(const CefString& localName,
|
|
|
|
const CefString& namespaceURI) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string localNameStr = localName;
|
|
|
|
std::string namespaceURIStr = namespaceURI;
|
2017-05-17 11:29:28 +02:00
|
|
|
return xmlTextReaderMoveToAttributeNs(reader_, BAD_CAST localNameStr.c_str(),
|
|
|
|
BAD_CAST namespaceURIStr.c_str()) == 1
|
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToFirstAttribute() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderMoveToFirstAttribute(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToNextAttribute() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderMoveToNextAttribute(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::MoveToCarryingElement() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return xmlTextReaderMoveToElement(reader_) == 1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefXmlReaderImpl::AppendError(const CefString& error_str) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!error_buf_.str().empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
error_buf_ << L"\n";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-01-28 00:13:12 +01:00
|
|
|
error_buf_ << error_str.ToString();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefXmlReaderImpl::VerifyContext() {
|
|
|
|
if (base::PlatformThread::CurrentId() != supported_thread_id_) {
|
|
|
|
// This object should only be accessed from the thread that created it.
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return (reader_ != nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|