summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-26 19:34:26 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-26 19:34:26 +0000
commitc9171e16d9d4477501d326d8d456fdc03e0f832e (patch)
tree89a91af4803e820b2e7f8c6e9901915c3415d72c
parentea360af9048e7083107f9e27f8967351df241f70 (diff)
downloadpdfium-c9171e16d9d4477501d326d8d456fdc03e0f832e.tar.xz
Use moar ToXMLElement() in place of static_cast<>.
Introduces checks in a few new places, but mainly just consolidates checking/casting logic. Change-Id: I634a03060d254db099972c6978249992367e146c Reviewed-on: https://pdfium-review.googlesource.com/38900 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fpdfdoc/cpdf_metadata.cpp8
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.cpp7
-rw-r--r--core/fxcrt/xml/cfx_xmlelement_unittest.cpp4
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp15
-rw-r--r--fxjs/xfa/cjx_object.cpp17
-rw-r--r--fxjs/xfa/cjx_packet.cpp50
-rw-r--r--xfa/fxfa/cxfa_textlayout.cpp18
-rw-r--r--xfa/fxfa/cxfa_textparser.cpp70
-rw-r--r--xfa/fxfa/cxfa_textprovider.cpp9
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp16
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_document_parser.cpp58
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp14
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.cpp30
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp7
16 files changed, 142 insertions, 190 deletions
diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp
index 323de4ffcf..5ef7312752 100644
--- a/core/fpdfdoc/cpdf_metadata.cpp
+++ b/core/fpdfdoc/cpdf_metadata.cpp
@@ -49,11 +49,9 @@ void CheckForSharedFormInternal(CFX_XMLElement* element,
for (auto* child = element->GetFirstChild(); child;
child = child->GetNextSibling()) {
- if (child->GetType() != FX_XMLNODE_Element)
- continue;
-
- CheckForSharedFormInternal(static_cast<CFX_XMLElement*>(child),
- unsupported);
+ CFX_XMLElement* pElement = ToXMLElement(child);
+ if (pElement)
+ CheckForSharedFormInternal(pElement, unsupported);
}
}
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index 74351b8c58..4bb4eae1bd 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -125,11 +125,8 @@ CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed(
CFX_XMLElement* CFX_XMLElement::GetNthChildNamed(const WideStringView& name,
size_t idx) const {
for (auto* child = GetFirstChild(); child; child = child->GetNextSibling()) {
- if (child->GetType() != FX_XMLNODE_Element)
- continue;
-
- CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child);
- if (elem->name_ != name)
+ CFX_XMLElement* elem = ToXMLElement(child);
+ if (!elem || elem->name_ != name)
continue;
if (idx == 0)
return elem;
diff --git a/core/fxcrt/xml/cfx_xmlelement_unittest.cpp b/core/fxcrt/xml/cfx_xmlelement_unittest.cpp
index 1e53ef3dd7..dfc60a10c3 100644
--- a/core/fxcrt/xml/cfx_xmlelement_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement_unittest.cpp
@@ -73,7 +73,6 @@ TEST(CFX_XMLElementTest, Attributes) {
TEST(CFX_XMLElementTest, Clone) {
CFX_XMLDocument doc;
-
CFX_XMLElement node(L"test:node");
node.SetAttribute(L"first", L"one");
node.SetAttribute(L"second", L"two");
@@ -87,10 +86,9 @@ TEST(CFX_XMLElementTest, Clone) {
CFX_XMLNode* clone = node.Clone(&doc);
EXPECT_TRUE(clone != nullptr);
-
ASSERT_EQ(FX_XMLNODE_Element, clone->GetType());
- CFX_XMLElement* inst = static_cast<CFX_XMLElement*>(clone);
+ CFX_XMLElement* inst = ToXMLElement(clone);
EXPECT_EQ(L"test:node", inst->GetName());
EXPECT_EQ(L"node", inst->GetLocalTagName());
EXPECT_EQ(L"test", inst->GetNamespacePrefix());
diff --git a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
index 74ef87e344..b25a18be9c 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
@@ -132,7 +132,7 @@ TEST(CFX_XMLInstructionTest, ParseAndReSaveInnerInstruction) {
ASSERT_TRUE(root->GetFirstChild() != nullptr);
ASSERT_TRUE(root->GetFirstChild()->GetType() == FX_XMLNODE_Element);
- CFX_XMLElement* node = static_cast<CFX_XMLElement*>(root->GetFirstChild());
+ CFX_XMLElement* node = ToXMLElement(root->GetFirstChild());
EXPECT_EQ(L"node", node->GetName());
CFX_XMLInstruction* instruction = nullptr;
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 268774a10f..dd28cf8adc 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -262,11 +262,10 @@ bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
current_buffer_idx++;
current_parser_state = FDE_XmlSyntaxState::AttriName;
- if (current_node_ &&
- current_node_->GetType() == FX_XMLNODE_Element) {
- static_cast<CFX_XMLElement*>(current_node_)
- ->SetAttribute(current_attribute_name, GetTextData());
- }
+ CFX_XMLElement* elem = ToXMLElement(current_node_);
+ if (elem)
+ elem->SetAttribute(current_attribute_name, GetTextData());
+
current_attribute_name.clear();
} else {
ProcessTextChar(ch);
@@ -311,13 +310,13 @@ bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
node_type_stack.pop();
current_parser_state = FDE_XmlSyntaxState::Text;
- if (current_node_->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* element = ToXMLElement(current_node_);
+ if (!element)
return false;
WideString element_name = GetTextData();
if (element_name.GetLength() > 0 &&
- element_name !=
- static_cast<CFX_XMLElement*>(current_node_)->GetName()) {
+ element_name != element->GetName()) {
return false;
}
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 1c0454d425..6984c3a998 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -806,30 +806,31 @@ Optional<WideString> CJX_Object::TryNamespace() {
if (ToNode(GetXFAObject())->IsModelNode() ||
ToNode(GetXFAObject())->GetElementType() == XFA_Element::Packet) {
CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode();
- if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* element = ToXMLElement(pXMLNode);
+ if (!element)
return {};
- return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()};
+ return {element->GetNamespaceURI()};
}
if (ToNode(GetXFAObject())->GetPacketType() != XFA_PacketType::Datasets)
return ToNode(GetXFAObject())->GetModelNode()->JSObject()->TryNamespace();
CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode();
- if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* element = ToXMLElement(pXMLNode);
+ if (!element)
return {};
if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::DataValue &&
GetEnum(XFA_Attribute::Contains) == XFA_AttributeEnum::MetaData) {
WideString wsNamespace;
- bool ret = XFA_FDEExtension_ResolveNamespaceQualifier(
- static_cast<CFX_XMLElement*>(pXMLNode),
- GetCData(XFA_Attribute::QualifiedName), &wsNamespace);
- if (!ret)
+ if (!XFA_FDEExtension_ResolveNamespaceQualifier(
+ element, GetCData(XFA_Attribute::QualifiedName), &wsNamespace)) {
return {};
+ }
return {wsNamespace};
}
- return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()};
+ return {element->GetNamespaceURI()};
}
std::pair<CXFA_Node*, int32_t> CJX_Object::GetPropertyInternal(
diff --git a/fxjs/xfa/cjx_packet.cpp b/fxjs/xfa/cjx_packet.cpp
index b27cfbadfb..2288de4c8d 100644
--- a/fxjs/xfa/cjx_packet.cpp
+++ b/fxjs/xfa/cjx_packet.cpp
@@ -35,11 +35,10 @@ CJS_Return CJX_Packet::getAttribute(
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
WideString attributeValue;
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- attributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetAttribute(
- runtime->ToWideString(params[0]));
- }
+ CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
+ if (element)
+ attributeValue = element->GetAttribute(runtime->ToWideString(params[0]));
+
return CJS_Return(
runtime->NewString(attributeValue.UTF8Encode().AsStringView()));
}
@@ -50,10 +49,10 @@ CJS_Return CJX_Packet::setAttribute(
if (params.size() != 2)
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- static_cast<CFX_XMLElement*>(pXMLNode)->SetAttribute(
- runtime->ToWideString(params[1]), runtime->ToWideString(params[0]));
+ CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
+ if (element) {
+ element->SetAttribute(runtime->ToWideString(params[1]),
+ runtime->ToWideString(params[0]));
}
return CJS_Return(runtime->NewNull());
}
@@ -64,12 +63,11 @@ CJS_Return CJX_Packet::removeAttribute(
if (params.size() != 1)
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
+ CFX_XMLElement* pElement = ToXMLElement(GetXFANode()->GetXMLMappingNode());
+ if (pElement) {
WideString name = runtime->ToWideString(params[0]);
- CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
- if (pXMLElement->HasAttribute(name))
- pXMLElement->RemoveAttribute(name);
+ if (pElement->HasAttribute(name))
+ pElement->RemoveAttribute(name);
}
return CJS_Return(runtime->NewNull());
}
@@ -77,25 +75,23 @@ CJS_Return CJX_Packet::removeAttribute(
void CJX_Packet::content(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
+ CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
if (bSetting) {
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- auto* text = GetXFANode()
- ->GetDocument()
- ->GetNotify()
- ->GetHDOC()
- ->GetXMLDocument()
- ->CreateNode<CFX_XMLText>(pValue->ToWideString());
- pXMLNode->AppendChild(text);
+ if (element) {
+ element->AppendChild(
+ GetXFANode()
+ ->GetDocument()
+ ->GetNotify()
+ ->GetHDOC()
+ ->GetXMLDocument()
+ ->CreateNode<CFX_XMLText>(pValue->ToWideString()));
}
return;
}
WideString wsTextData;
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
- wsTextData = pXMLElement->GetTextData();
- }
+ if (element)
+ wsTextData = element->GetTextData();
pValue->SetString(wsTextData.UTF8Encode().AsStringView());
}
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index 32a1b393a6..8bf955bd32 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -77,19 +77,17 @@ CFX_XMLNode* CXFA_TextLayout::GetXMLContainerNode() {
if (!pXMLRoot)
return nullptr;
- CFX_XMLNode* pXMLContainer = nullptr;
for (CFX_XMLNode* pXMLChild = pXMLRoot->GetFirstChild(); pXMLChild;
pXMLChild = pXMLChild->GetNextSibling()) {
- if (pXMLChild->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLChild);
- WideString wsTag = pXMLElement->GetLocalTagName();
- if (wsTag == L"body" || wsTag == L"html") {
- pXMLContainer = pXMLChild;
- break;
- }
- }
+ CFX_XMLElement* pXMLElement = ToXMLElement(pXMLChild);
+ if (!pXMLElement)
+ continue;
+ WideString wsTag = pXMLElement->GetLocalTagName();
+ if (wsTag == L"body" || wsTag == L"html")
+ return pXMLChild;
}
- return pXMLContainer;
+
+ return nullptr;
}
std::unique_ptr<CFX_RTFBreak> CXFA_TextLayout::CreateBreak(bool bDefault) {
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp
index f0a6dd2af1..c60b774051 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -276,18 +276,18 @@ bool CXFA_TextParser::TagValidate(const WideString& wsName) const {
std::unique_ptr<CXFA_TextParser::TagProvider> CXFA_TextParser::ParseTagInfo(
CFX_XMLNode* pXMLNode) {
auto tagProvider = pdfium::MakeUnique<TagProvider>();
-
- WideString wsName;
- if (pXMLNode->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
- wsName = pXMLElement->GetLocalTagName();
+ CFX_XMLElement* pXMLElement = ToXMLElement(pXMLNode);
+ if (pXMLElement) {
+ WideString wsName = pXMLElement->GetLocalTagName();
tagProvider->SetTagName(wsName);
tagProvider->m_bTagAvailable = TagValidate(wsName);
-
WideString wsValue = pXMLElement->GetAttribute(L"style");
if (!wsValue.IsEmpty())
tagProvider->SetAttribute(L"style", wsValue);
- } else if (pXMLNode->GetType() == FX_XMLNODE_Text) {
+
+ return tagProvider;
+ }
+ if (pXMLNode->GetType() == FX_XMLNODE_Text) {
tagProvider->m_bTagAvailable = true;
tagProvider->m_bContent = true;
}
@@ -502,38 +502,38 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider,
if (!pXMLNode)
return false;
- bool bRet = false;
- if (pXMLNode->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pElement = static_cast<CFX_XMLElement*>(pXMLNode);
- WideString wsAttr = pElement->GetAttribute(L"xfa:embed");
- if (wsAttr.IsEmpty())
- return false;
- if (wsAttr[0] == L'#')
- wsAttr.Delete(0);
-
- WideString ws = pElement->GetAttribute(L"xfa:embedType");
- if (ws.IsEmpty())
- ws = L"som";
- else
- ws.MakeLower();
+ CFX_XMLElement* pElement = ToXMLElement(pXMLNode);
+ if (!pElement)
+ return false;
+
+ WideString wsAttr = pElement->GetAttribute(L"xfa:embed");
+ if (wsAttr.IsEmpty())
+ return false;
- bool bURI = (ws == L"uri");
- if (!bURI && ws != L"som")
- return false;
+ if (wsAttr[0] == L'#')
+ wsAttr.Delete(0);
- ws = pElement->GetAttribute(L"xfa:embedMode");
- if (ws.IsEmpty())
- ws = L"formatted";
- else
- ws.MakeLower();
+ WideString ws = pElement->GetAttribute(L"xfa:embedType");
+ if (ws.IsEmpty())
+ ws = L"som";
+ else
+ ws.MakeLower();
- bool bRaw = (ws == L"raw");
- if (!bRaw && ws != L"formatted")
- return false;
+ bool bURI = (ws == L"uri");
+ if (!bURI && ws != L"som")
+ return false;
- bRet = pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue);
- }
- return bRet;
+ ws = pElement->GetAttribute(L"xfa:embedMode");
+ if (ws.IsEmpty())
+ ws = L"formatted";
+ else
+ ws.MakeLower();
+
+ bool bRaw = (ws == L"raw");
+ if (!bRaw && ws != L"formatted")
+ return false;
+
+ return pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue);
}
CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap(
diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp
index 60c52942ed..ba48cd8490 100644
--- a/xfa/fxfa/cxfa_textprovider.cpp
+++ b/xfa/fxfa/cxfa_textprovider.cpp
@@ -61,13 +61,12 @@ CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) {
if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) {
CXFA_Node* pBind = m_pNode->GetBindData();
CFX_XMLNode* pXMLNode = pBind->GetXMLMappingNode();
- ASSERT(pXMLNode);
for (CFX_XMLNode* pXMLChild = pXMLNode->GetFirstChild(); pXMLChild;
pXMLChild = pXMLChild->GetNextSibling()) {
- if (pXMLChild->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pElement = static_cast<CFX_XMLElement*>(pXMLChild);
- if (XFA_RecognizeRichText(pElement))
- bRichText = true;
+ CFX_XMLElement* pElement = ToXMLElement(pXMLChild);
+ if (pElement && XFA_RecognizeRichText(pElement)) {
+ bRichText = true;
+ break;
}
}
return pBind;
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index eb3e04afd8..820d3546f7 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -38,9 +38,8 @@ bool CXFA_DataExporter::Export(const RetainPtr<IFX_SeekableStream>& pStream,
break;
}
case XFA_PacketType::Datasets: {
- CFX_XMLElement* pElement =
- static_cast<CFX_XMLElement*>(pNode->GetXMLMappingNode());
- if (!pElement || pElement->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* pElement = ToXMLElement(pNode->GetXMLMappingNode());
+ if (!pElement)
return false;
CXFA_Node* pDataNode = pNode->GetFirstChild();
@@ -54,9 +53,8 @@ bool CXFA_DataExporter::Export(const RetainPtr<IFX_SeekableStream>& pStream,
break;
case XFA_PacketType::Template:
default: {
- CFX_XMLElement* pElement =
- static_cast<CFX_XMLElement*>(pNode->GetXMLMappingNode());
- if (!pElement || pElement->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* pElement = ToXMLElement(pNode->GetXMLMappingNode());
+ if (!pElement)
return false;
pElement->Save(pStream);
@@ -75,9 +73,8 @@ bool CXFA_DataExporter::Export(const RetainPtr<IFX_SeekableStream>& pStream,
break;
}
}
- CFX_XMLElement* pElement =
- static_cast<CFX_XMLElement*>(pExportNode->GetXMLMappingNode());
- if (!pElement || pElement->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* pElement = ToXMLElement(pExportNode->GetXMLMappingNode());
+ if (!pElement)
return false;
XFA_DataExporter_DealWithDataGroupNode(pExportNode);
@@ -85,6 +82,5 @@ bool CXFA_DataExporter::Export(const RetainPtr<IFX_SeekableStream>& pStream,
L"http://www.xfa.org/schema/xfa-data/1.0/");
pElement->Save(pStream);
pElement->RemoveAttribute(L"xmlns:xfa");
-
return true;
}
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 3e8046677a..3b086faf69 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -510,9 +510,8 @@ void CreateDataBinding(CXFA_Node* pFormNode,
wsHref = image->GetHref();
}
CFX_XMLElement* pXMLDataElement =
- static_cast<CFX_XMLElement*>(pDataNode->GetXMLMappingNode());
+ ToXMLElement(pDataNode->GetXMLMappingNode());
ASSERT(pXMLDataElement);
-
pDataNode->JSObject()->SetAttributeValue(
wsValue, pFormNode->GetFormatDataValue(wsValue), false, false);
pDataNode->JSObject()->SetCData(XFA_Attribute::ContentType,
@@ -656,9 +655,7 @@ void CreateDataBinding(CXFA_Node* pFormNode,
CXFA_Image* image = defValue ? defValue->GetImageIfExists() : nullptr;
if (image) {
CFX_XMLElement* pXMLDataElement =
- static_cast<CFX_XMLElement*>(pDataNode->GetXMLMappingNode());
- ASSERT(pXMLDataElement);
-
+ ToXMLElement(pDataNode->GetXMLMappingNode());
WideString wsContentType =
pXMLDataElement->GetAttribute(L"xfa:contentType");
if (!wsContentType.IsEmpty()) {
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index b126d8267f..34955829e9 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -115,10 +115,10 @@ bool MatchNodeName(CFX_XMLNode* pNode,
const WideStringView& wsLocalTagName,
const WideStringView& wsNamespaceURIPrefix,
uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) {
- if (!pNode || pNode->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* pElement = ToXMLElement(pNode);
+ if (!pElement)
return false;
- CFX_XMLElement* pElement = static_cast<CFX_XMLElement*>(pNode);
WideString wsNodeStr = pElement->GetLocalTagName();
if (wsNodeStr != wsLocalTagName)
return false;
@@ -449,7 +449,7 @@ CXFA_Node* CXFA_DocumentParser::ParseAsXDPPacket_XDP(
m_pRootNode = pXFARootNode;
pXFARootNode->JSObject()->SetCData(XFA_Attribute::Name, L"xfa", false, false);
- CFX_XMLElement* pElement = static_cast<CFX_XMLElement*>(pXMLDocumentNode);
+ CFX_XMLElement* pElement = ToXMLElement(pXMLDocumentNode);
for (auto it : pElement->GetAttributes()) {
if (it.first == L"uuid")
pXFARootNode->JSObject()->SetCData(XFA_Attribute::Uuid, it.second, false,
@@ -483,12 +483,10 @@ CXFA_Node* CXFA_DocumentParser::ParseAsXDPPacket_XDP(
CFX_XMLNode* pXMLTemplateDOMRoot = nullptr;
for (CFX_XMLNode* pChildItem = pXMLDocumentNode->GetFirstChild(); pChildItem;
pChildItem = pChildItem->GetNextSibling()) {
- if (!pChildItem || pChildItem->GetType() != FX_XMLNODE_Element)
- continue;
- if (pChildItem == pXMLConfigDOMRoot)
+ CFX_XMLElement* pElement = ToXMLElement(pChildItem);
+ if (!pElement || pElement == pXMLConfigDOMRoot)
continue;
- CFX_XMLElement* pElement = static_cast<CFX_XMLElement*>(pChildItem);
WideString wsPacketName = pElement->GetLocalTagName();
const PacketInfo* pPacketInfo =
GetPacketByName(wsPacketName.AsStringView());
@@ -591,8 +589,7 @@ CXFA_Node* CXFA_DocumentParser::ParseAsXDPPacket_Template(
pNode->JSObject()->SetCData(XFA_Attribute::Name, packet->name, false, false);
- CFX_XMLElement* pXMLDocumentElement =
- static_cast<CFX_XMLElement*>(pXMLDocumentNode);
+ CFX_XMLElement* pXMLDocumentElement = ToXMLElement(pXMLDocumentNode);
WideString wsNamespaceURI = pXMLDocumentElement->GetNamespaceURI();
if (wsNamespaceURI.IsEmpty())
wsNamespaceURI = pXMLDocumentElement->GetAttribute(L"xmlns:xfa");
@@ -661,8 +658,7 @@ CXFA_Node* CXFA_DocumentParser::ParseAsXDPPacket_Data(
CFX_XMLNode* pDataXMLNode = nullptr;
if (MatchNodeName(pXMLDocumentNode, L"data", packet->uri, packet->flags)) {
- static_cast<CFX_XMLElement*>(pXMLDocumentNode)
- ->RemoveAttribute(L"xmlns:xfa");
+ ToXMLElement(pXMLDocumentNode)->RemoveAttribute(L"xmlns:xfa");
pDataXMLNode = pXMLDocumentNode;
} else {
auto* pDataElement = xml_doc_->CreateNode<CFX_XMLElement>(L"xfa:data");
@@ -686,8 +682,7 @@ CXFA_Node* CXFA_DocumentParser::ParseAsXDPPacket_Data(
if (!pNode)
return nullptr;
- WideString wsLocalName =
- static_cast<CFX_XMLElement*>(pDataXMLNode)->GetLocalTagName();
+ WideString wsLocalName = ToXMLElement(pDataXMLNode)->GetLocalTagName();
pNode->JSObject()->SetCData(XFA_Attribute::Name, wsLocalName, false, false);
if (!DataLoader(pNode, pDataXMLNode, true))
return nullptr;
@@ -742,8 +737,7 @@ CXFA_Node* CXFA_DocumentParser::ParseAsXDPPacket_User(
if (!pNode)
return nullptr;
- WideString wsName =
- static_cast<CFX_XMLElement*>(pXMLDocumentNode)->GetLocalTagName();
+ WideString wsName = ToXMLElement(pXMLDocumentNode)->GetLocalTagName();
pNode->JSObject()->SetCData(XFA_Attribute::Name, wsName, false, false);
if (!UserPacketLoader(pNode, pXMLDocumentNode))
return nullptr;
@@ -875,20 +869,18 @@ void CXFA_DocumentParser::ParseContentNode(CXFA_Node* pXFANode,
if (eNodeType == FX_XMLNODE_Instruction)
continue;
+ CFX_XMLElement* pElement = ToXMLElement(pXMLChild);
if (element == XFA_Element::SharpxHTML) {
- if (eNodeType != FX_XMLNODE_Element)
+ if (!pElement)
break;
-
- if (XFA_RecognizeRichText(static_cast<CFX_XMLElement*>(pXMLChild)))
- wsValue +=
- GetPlainTextFromRichText(static_cast<CFX_XMLElement*>(pXMLChild));
+ if (XFA_RecognizeRichText(pElement))
+ wsValue += GetPlainTextFromRichText(pElement);
} else if (element == XFA_Element::Sharpxml) {
- if (eNodeType != FX_XMLNODE_Element)
+ if (!pElement)
break;
-
- ConvertXMLToPlainText(static_cast<CFX_XMLElement*>(pXMLChild), wsValue);
+ ConvertXMLToPlainText(pElement, wsValue);
} else {
- if (eNodeType == FX_XMLNODE_Element)
+ if (pElement)
break;
if (eNodeType == FX_XMLNODE_Text || eNodeType == FX_XMLNODE_CharData)
wsValue = static_cast<CFX_XMLText*>(pXMLChild)->GetText();
@@ -951,12 +943,10 @@ void CXFA_DocumentParser::ParseDataGroup(CXFA_Node* pXFANode,
if (eNodeType == XFA_Element::DataModel) {
for (CFX_XMLNode* pXMLDataChild = pXMLElement->GetFirstChild();
pXMLDataChild; pXMLDataChild = pXMLDataChild->GetNextSibling()) {
- if (pXMLDataChild->GetType() == FX_XMLNODE_Element) {
- if (!XFA_RecognizeRichText(
- static_cast<CFX_XMLElement*>(pXMLDataChild))) {
- eNodeType = XFA_Element::DataGroup;
- break;
- }
+ CFX_XMLElement* pElement = ToXMLElement(pXMLDataChild);
+ if (pElement && !XFA_RecognizeRichText(pElement)) {
+ eNodeType = XFA_Element::DataGroup;
+ break;
}
}
}
@@ -1063,9 +1053,8 @@ void CXFA_DocumentParser::ParseDataValue(CXFA_Node* pXFANode,
pXMLCurValueNode = pXMLChild;
wsCurValueTextBuf << wsText;
- } else if (XFA_RecognizeRichText(static_cast<CFX_XMLElement*>(pXMLChild))) {
- WideString wsText =
- GetPlainTextFromRichText(static_cast<CFX_XMLElement*>(pXMLChild));
+ } else if (XFA_RecognizeRichText(ToXMLElement(pXMLChild))) {
+ WideString wsText = GetPlainTextFromRichText(ToXMLElement(pXMLChild));
if (!pXMLCurValueNode)
pXMLCurValueNode = pXMLChild;
@@ -1097,8 +1086,7 @@ void CXFA_DocumentParser::ParseDataValue(CXFA_Node* pXFANode,
if (!pXFAChild)
return;
- WideString wsNodeStr =
- static_cast<CFX_XMLElement*>(pXMLChild)->GetLocalTagName();
+ WideString wsNodeStr = ToXMLElement(pXMLChild)->GetLocalTagName();
pXFAChild->JSObject()->SetCData(XFA_Attribute::Name, wsNodeStr, false,
false);
ParseDataValue(pXFAChild, pXMLChild, ePacketID);
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 363af54028..9fdea14cae 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1259,11 +1259,9 @@ void CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
return;
}
- ASSERT(pNode->xml_node_.Get() == xml_node_.Get() &&
- xml_node_->GetType() == FX_XMLNODE_Element);
- if (pNode->xml_node_->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pXMLElement =
- static_cast<CFX_XMLElement*>(pNode->xml_node_.Get());
+ ASSERT(pNode->xml_node_.Get() == xml_node_.Get());
+ CFX_XMLElement* pXMLElement = ToXMLElement(pNode->xml_node_.Get());
+ if (pXMLElement) {
WideString wsAttributeName =
pNode->JSObject()->GetCData(XFA_Attribute::QualifiedName);
pXMLElement->RemoveAttribute(wsAttributeName);
@@ -4700,10 +4698,10 @@ bool CXFA_Node::PresenceRequiresSpace() const {
}
void CXFA_Node::SetToXML(const WideString& value) {
- auto* elem = static_cast<CFX_XMLElement*>(GetXMLMappingNode());
- FX_XMLNODETYPE eXMLType = elem->GetType();
- switch (eXMLType) {
+ auto* pNode = GetXMLMappingNode();
+ switch (pNode->GetType()) {
case FX_XMLNODE_Element: {
+ auto* elem = static_cast<CFX_XMLElement*>(pNode);
if (IsAttributeInXML()) {
elem->SetAttribute(JSObject()->GetCData(XFA_Attribute::QualifiedName),
value);
diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp
index 1922b31d7e..e4858e907e 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale.cpp
+++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp
@@ -41,17 +41,15 @@ std::unique_ptr<CXFA_XMLLocale> CXFA_XMLLocale::Create(
CFX_XMLElement* locale = nullptr;
for (auto* child = doc->GetRoot()->GetFirstChild(); child;
child = child->GetNextSibling()) {
- if (child->GetType() != FX_XMLNODE_Element)
- continue;
-
- CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child);
- if (elem->GetName() == L"locale") {
+ CFX_XMLElement* elem = ToXMLElement(child);
+ if (elem && elem->GetName() == L"locale") {
locale = elem;
break;
}
}
if (!locale)
return nullptr;
+
return pdfium::MakeUnique<CXFA_XMLLocale>(std::move(doc), locale);
}
@@ -129,11 +127,8 @@ WideString CXFA_XMLLocale::GetCalendarSymbol(const WideStringView& symbol,
CFX_XMLElement* name_child = nullptr;
for (auto* name = child->GetFirstChild(); name;
name = name->GetNextSibling()) {
- if (name->GetType() != FX_XMLNODE_Element)
- continue;
-
- auto* elem = static_cast<CFX_XMLElement*>(name);
- if (elem->GetName() != pstrSymbolNames)
+ CFX_XMLElement* elem = ToXMLElement(name);
+ if (!elem || elem->GetName() != pstrSymbolNames)
continue;
WideString abbr = elem->GetAttribute(L"abbr");
@@ -213,16 +208,11 @@ WideString CXFA_XMLLocale::GetPattern(CFX_XMLElement* patterns,
const WideStringView& wsName) const {
for (auto* child = patterns->GetFirstChild(); child;
child = child->GetNextSibling()) {
- if (child->GetType() != FX_XMLNODE_Element)
- continue;
-
- CFX_XMLElement* pattern = static_cast<CFX_XMLElement*>(child);
- if (pattern->GetName() != bsTag)
- continue;
- if (pattern->GetAttribute(L"name") != wsName)
- continue;
-
- return pattern->GetTextData();
+ CFX_XMLElement* pattern = ToXMLElement(child);
+ if (pattern && pattern->GetName() == bsTag &&
+ pattern->GetAttribute(L"name") == wsName) {
+ return pattern->GetTextData();
+ }
}
return L"";
}
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index 54cca88409..1331a43756 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -470,11 +470,8 @@ bool XFA_FDEExtension_ResolveNamespaceQualifier(CFX_XMLElement* pNode,
}
for (CFX_XMLNode* pParent = pNode; pParent != pFakeRoot;
pParent = pParent->GetParent()) {
- if (pParent->GetType() != FX_XMLNODE_Element)
- continue;
-
- auto* pElement = static_cast<CFX_XMLElement*>(pParent);
- if (pElement->HasAttribute(wsNSAttribute)) {
+ CFX_XMLElement* pElement = ToXMLElement(pParent);
+ if (pElement && pElement->HasAttribute(wsNSAttribute)) {
*wsNamespaceURI = pElement->GetAttribute(wsNSAttribute);
return true;
}