Fix some unowned ptr exclusions in core/fxcrt/{xml,css}

Convert T* pointers to another smart pointer type as flagged by
the compiler plugin. Then fix one lifetime issue thus uncovered,
since the parser can outlive the document in some cases.

Change-Id: Ie9eaa77696d47817a7af0a47c80946e289611734
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107150
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp
index 4abdba4..89b6852 100644
--- a/core/fxcrt/css/cfx_cssrulecollection.cpp
+++ b/core/fxcrt/css/cfx_cssrulecollection.cpp
@@ -44,3 +44,5 @@
 CFX_CSSRuleCollection::Data::Data(CFX_CSSSelector* pSel,
                                   CFX_CSSDeclaration* pDecl)
     : pSelector(pSel), pDeclaration(pDecl) {}
+
+CFX_CSSRuleCollection::Data::~Data() = default;
diff --git a/core/fxcrt/css/cfx_cssrulecollection.h b/core/fxcrt/css/cfx_cssrulecollection.h
index b5f09ad..125fdd2 100644
--- a/core/fxcrt/css/cfx_cssrulecollection.h
+++ b/core/fxcrt/css/cfx_cssrulecollection.h
@@ -11,6 +11,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/unowned_ptr.h"
 #include "core/fxcrt/widestring.h"
 
 class CFX_CSSDeclaration;
@@ -23,9 +24,10 @@
   class Data {
    public:
     Data(CFX_CSSSelector* pSel, CFX_CSSDeclaration* pDecl);
+    ~Data();
 
-    CFX_CSSSelector* const pSelector;
-    CFX_CSSDeclaration* const pDeclaration;
+    UnownedPtr<CFX_CSSSelector> const pSelector;
+    UnownedPtr<CFX_CSSDeclaration> const pDeclaration;
   };
 
   CFX_CSSRuleCollection();
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index d3129b6..6ca9ea4 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -13,6 +13,7 @@
 #include <stack>
 #include <utility>
 
+#include "core/fxcrt/autorestorer.h"
 #include "core/fxcrt/cfx_seekablestreamproxy.h"
 #include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_codepage.h"
@@ -84,8 +85,8 @@
 
 std::unique_ptr<CFX_XMLDocument> CFX_XMLParser::Parse() {
   auto doc = std::make_unique<CFX_XMLDocument>();
+  AutoRestorer<UnownedPtr<CFX_XMLNode>> restorer(&current_node_);
   current_node_ = doc->GetRoot();
-
   return DoSyntaxParse(doc.get()) ? std::move(doc) : nullptr;
 }
 
diff --git a/core/fxcrt/xml/cfx_xmlparser.h b/core/fxcrt/xml/cfx_xmlparser.h
index 7a30b7c..268c9f2 100644
--- a/core/fxcrt/xml/cfx_xmlparser.h
+++ b/core/fxcrt/xml/cfx_xmlparser.h
@@ -11,6 +11,7 @@
 
 #include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/retain_ptr.h"
+#include "core/fxcrt/unowned_ptr.h"
 #include "core/fxcrt/widestring.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
 
@@ -53,7 +54,7 @@
   void ProcessTextChar(wchar_t ch);
   void ProcessTargetData();
 
-  CFX_XMLNode* current_node_ = nullptr;
+  UnownedPtr<CFX_XMLNode> current_node_;
   RetainPtr<CFX_SeekableStreamProxy> stream_;
   DataVector<wchar_t> current_text_;
   size_t xml_plane_size_ = 1024;