Remove unreachable code paths in cxfa_document_parser.cpp

- UserPacketLoader() is a no-op.
- FindAttributeWithNS() is always called with a valid element and
  the default bMatchAsNSPrefix argument.
- Remove out parameter from FindAttributeWithNS() in favor of
  Optional<> while we're at it.

Change-Id: I9eb65b714b637677b3045ea20491fecf64d8e839
Reviewed-on: https://pdfium-review.googlesource.com/c/48410
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index 1ab2c21..ace9bb4 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -23,6 +23,7 @@
 #include "core/fxcrt/xml/cfx_xmltext.h"
 #include "fxjs/xfa/cjx_object.h"
 #include "third_party/base/logging.h"
+#include "third_party/base/optional.h"
 #include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/parser/cxfa_document.h"
 #include "xfa/fxfa/parser/cxfa_node.h"
@@ -100,14 +101,9 @@
   return true;
 }
 
-bool FindAttributeWithNS(CFX_XMLElement* pElement,
-                         WideStringView wsLocalAttributeName,
-                         WideStringView wsNamespaceURIPrefix,
-                         WideString& wsValue,
-                         bool bMatchNSAsPrefix = false) {
-  if (!pElement)
-    return false;
-
+Optional<WideString> FindAttributeWithNS(CFX_XMLElement* pElement,
+                                         WideStringView wsLocalAttributeName,
+                                         WideStringView wsNamespaceURIPrefix) {
   WideString wsAttrNS;
   for (auto it : pElement->GetAttributes()) {
     auto pos = it.first.Find(L':', 0);
@@ -122,24 +118,14 @@
       }
       wsNSPrefix = it.first.Left(pos.value());
     }
-
     if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNSPrefix,
-                                                    &wsAttrNS)) {
+                                                    &wsAttrNS) ||
+        wsAttrNS != wsNamespaceURIPrefix) {
       continue;
     }
-    if (bMatchNSAsPrefix) {
-      if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) !=
-          wsNamespaceURIPrefix) {
-        continue;
-      }
-    } else {
-      if (wsAttrNS != wsNamespaceURIPrefix)
-        continue;
-    }
-    wsValue = it.second;
-    return true;
+    return it.second;
   }
-  return false;
+  return {};
 }
 
 CFX_XMLNode* GetDataSetsFromXDP(CFX_XMLNode* pXMLDocumentNode) {
@@ -659,18 +645,10 @@
 
   WideString wsName = ToXMLElement(pXMLDocumentNode)->GetLocalTagName();
   pNode->JSObject()->SetCData(XFA_Attribute::Name, wsName, false, false);
-  if (!UserPacketLoader(pNode, pXMLDocumentNode))
-    return nullptr;
-
   pNode->SetXMLMappingNode(pXMLDocumentNode);
   return pNode;
 }
 
-CXFA_Node* CXFA_DocumentParser::UserPacketLoader(CXFA_Node* pXFANode,
-                                                 CFX_XMLNode* pXMLDoc) {
-  return pXFANode;
-}
-
 CXFA_Node* CXFA_DocumentParser::DataLoader(CXFA_Node* pXFANode,
                                            CFX_XMLNode* pXMLDoc,
                                            bool bDoTransform) {
@@ -842,24 +820,22 @@
 
         XFA_Element eNodeType = XFA_Element::DataModel;
         if (eNodeType == XFA_Element::DataModel) {
-          WideString wsDataNodeAttr;
-          if (FindAttributeWithNS(pXMLElement, L"dataNode",
-                                  L"http://www.xfa.org/schema/xfa-data/1.0/",
-                                  wsDataNodeAttr)) {
-            if (wsDataNodeAttr.EqualsASCII("dataGroup"))
+          Optional<WideString> wsDataNodeAttr =
+              FindAttributeWithNS(pXMLElement, L"dataNode",
+                                  L"http://www.xfa.org/schema/xfa-data/1.0/");
+          if (wsDataNodeAttr.has_value()) {
+            if (wsDataNodeAttr.value().EqualsASCII("dataGroup"))
               eNodeType = XFA_Element::DataGroup;
-            else if (wsDataNodeAttr.EqualsASCII("dataValue"))
+            else if (wsDataNodeAttr.value().EqualsASCII("dataValue"))
               eNodeType = XFA_Element::DataValue;
           }
         }
-        WideString wsContentType;
         if (eNodeType == XFA_Element::DataModel) {
-          if (FindAttributeWithNS(pXMLElement, L"contentType",
-                                  L"http://www.xfa.org/schema/xfa-data/1.0/",
-                                  wsContentType)) {
-            if (!wsContentType.IsEmpty())
-              eNodeType = XFA_Element::DataValue;
-          }
+          Optional<WideString> wsContentType =
+              FindAttributeWithNS(pXMLElement, L"contentType",
+                                  L"http://www.xfa.org/schema/xfa-data/1.0/");
+          if (wsContentType.has_value() && !wsContentType.value().IsEmpty())
+            eNodeType = XFA_Element::DataValue;
         }
         if (eNodeType == XFA_Element::DataModel) {
           for (CFX_XMLNode* pXMLDataChild = pXMLElement->GetFirstChild();
diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h
index 28b8d61..ad8d56c 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.h
+++ b/xfa/fxfa/parser/cxfa_document_parser.h
@@ -59,7 +59,6 @@
   CXFA_Node* DataLoader(CXFA_Node* pXFANode,
                         CFX_XMLNode* pXMLDoc,
                         bool bDoTransform);
-  CXFA_Node* UserPacketLoader(CXFA_Node* pXFANode, CFX_XMLNode* pXMLDoc);
   void ParseContentNode(CXFA_Node* pXFANode,
                         CFX_XMLNode* pXMLNode,
                         XFA_PacketType ePacketID);