Convert to CFX_UnownedPtr, part 5

Change-Id: Ibdb20fca7e4daae9d61286df4801ac02faf3b281
Reviewed-on: https://pdfium-review.googlesource.com/5831
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index 5ecdb48..b3808bd 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -136,6 +136,8 @@
 
 }  // namespace
 
+CPDF_NameTree::CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {}
+
 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc,
                              const CFX_ByteString& category)
     : m_pRoot(nullptr) {
@@ -150,8 +152,10 @@
   m_pRoot = pNames->GetDictFor(category);
 }
 
+CPDF_NameTree::~CPDF_NameTree() {}
+
 size_t CPDF_NameTree::GetCount() const {
-  return m_pRoot ? ::CountNames(m_pRoot) : 0;
+  return m_pRoot ? ::CountNames(m_pRoot.Get()) : 0;
 }
 
 int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const {
@@ -159,7 +163,7 @@
     return -1;
 
   size_t nIndex = 0;
-  if (!SearchNameNode(m_pRoot, csName, nIndex, nullptr))
+  if (!SearchNameNode(m_pRoot.Get(), csName, nIndex, nullptr))
     return -1;
   return nIndex;
 }
@@ -171,7 +175,7 @@
     return nullptr;
 
   size_t nCurIndex = 0;
-  return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, nullptr);
+  return SearchNameNode(m_pRoot.Get(), nIndex, nCurIndex, csName, nullptr);
 }
 
 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const {
@@ -179,7 +183,7 @@
     return nullptr;
 
   size_t nIndex = 0;
-  return SearchNameNode(m_pRoot, csName, nIndex, nullptr);
+  return SearchNameNode(m_pRoot.Get(), csName, nIndex, nullptr);
 }
 
 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
diff --git a/core/fpdfdoc/cpdf_nametree.h b/core/fpdfdoc/cpdf_nametree.h
index 7a792ae..69000f3 100644
--- a/core/fpdfdoc/cpdf_nametree.h
+++ b/core/fpdfdoc/cpdf_nametree.h
@@ -7,6 +7,7 @@
 #ifndef CORE_FPDFDOC_CPDF_NAMETREE_H_
 #define CORE_FPDFDOC_CPDF_NAMETREE_H_
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_string.h"
 
 class CPDF_Array;
@@ -16,8 +17,9 @@
 
 class CPDF_NameTree {
  public:
-  explicit CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {}
+  explicit CPDF_NameTree(CPDF_Dictionary* pRoot);
   CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteString& category);
+  ~CPDF_NameTree();
 
   CPDF_Object* LookupValueAndName(int nIndex, CFX_ByteString* csName) const;
   CPDF_Object* LookupValue(const CFX_ByteString& csName) const;
@@ -25,10 +27,10 @@
 
   int GetIndex(const CFX_ByteString& csName) const;
   size_t GetCount() const;
-  CPDF_Dictionary* GetRoot() const { return m_pRoot; }
+  CPDF_Dictionary* GetRoot() const { return m_pRoot.Get(); }
 
  private:
-  CPDF_Dictionary* m_pRoot;
+  CFX_UnownedPtr<CPDF_Dictionary> m_pRoot;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_NAMETREE_H_
diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h
index c65363d..d8820a1 100644
--- a/core/fpdfdoc/cpdf_structelement.h
+++ b/core/fpdfdoc/cpdf_structelement.h
@@ -10,6 +10,7 @@
 #include <vector>
 
 #include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxge/fx_dib.h"
 
@@ -27,7 +28,7 @@
   enum { Invalid, Element, PageContent, StreamContent, Object } m_Type;
 
   CFX_RetainPtr<CPDF_StructElement> m_pElement;  // For Element.
-  CPDF_Dictionary* m_pDict;                      // For Element.
+  CFX_UnownedPtr<CPDF_Dictionary> m_pDict;       // For Element.
   uint32_t m_PageObjNum;  // For PageContent, StreamContent, Object.
   uint32_t m_RefObjNum;   // For StreamContent, Object.
   uint32_t m_ContentId;   // For PageContent, StreamContent.
diff --git a/core/fpdfdoc/cpdf_structtree.h b/core/fpdfdoc/cpdf_structtree.h
index aa30f80..037512a 100644
--- a/core/fpdfdoc/cpdf_structtree.h
+++ b/core/fpdfdoc/cpdf_structtree.h
@@ -12,6 +12,7 @@
 #include <vector>
 
 #include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 
 class CPDF_Dictionary;
 class CPDF_Document;
@@ -28,9 +29,9 @@
 
   int CountTopElements() const;
   CPDF_StructElement* GetTopElement(int i) const;
-  const CPDF_Dictionary* GetRoleMap() const { return m_pRoleMap; }
-  const CPDF_Dictionary* GetPage() const { return m_pPage; }
-  const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot; }
+  const CPDF_Dictionary* GetRoleMap() const { return m_pRoleMap.Get(); }
+  const CPDF_Dictionary* GetPage() const { return m_pPage.Get(); }
+  const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot.Get(); }
 
  private:
   void LoadPageTree(const CPDF_Dictionary* pPageDict);
@@ -41,9 +42,9 @@
   bool AddTopLevelNode(CPDF_Dictionary* pDict,
                        const CFX_RetainPtr<CPDF_StructElement>& pElement);
 
-  const CPDF_Dictionary* const m_pTreeRoot;
-  const CPDF_Dictionary* const m_pRoleMap;
-  const CPDF_Dictionary* m_pPage;
+  CFX_UnownedPtr<const CPDF_Dictionary> const m_pTreeRoot;
+  CFX_UnownedPtr<const CPDF_Dictionary> const m_pRoleMap;
+  CFX_UnownedPtr<const CPDF_Dictionary> m_pPage;
   std::vector<CFX_RetainPtr<CPDF_StructElement>> m_Kids;
 };
 
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index c6e1a85..0edabd1 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -21,9 +21,7 @@
     : m_pDocument(pDoc),
       m_pResDict(pResDict),
       m_pDefFont(pDefFont),
-      m_sDefFontAlias(sDefFontAlias),
-      m_pSysFont(nullptr),
-      m_sSysFontAlias() {}
+      m_sDefFontAlias(sDefFontAlias) {}
 
 CPVT_FontMap::~CPVT_FontMap() {}
 
@@ -49,13 +47,13 @@
 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
   switch (nFontIndex) {
     case 0:
-      return m_pDefFont;
+      return m_pDefFont.Get();
     case 1:
       if (!m_pSysFont) {
-        m_pSysFont =
-            GetAnnotSysPDFFont(m_pDocument, m_pResDict, &m_sSysFontAlias);
+        m_pSysFont = GetAnnotSysPDFFont(m_pDocument.Get(), m_pResDict.Get(),
+                                        &m_sSysFontAlias);
       }
-      return m_pSysFont;
+      return m_pSysFont.Get();
     default:
       return nullptr;
   }
@@ -67,8 +65,8 @@
       return m_sDefFontAlias;
     case 1:
       if (!m_pSysFont) {
-        m_pSysFont =
-            GetAnnotSysPDFFont(m_pDocument, m_pResDict, &m_sSysFontAlias);
+        m_pSysFont = GetAnnotSysPDFFont(m_pDocument.Get(), m_pResDict.Get(),
+                                        &m_sSysFontAlias);
       }
       return m_sSysFontAlias;
     default:
diff --git a/core/fpdfdoc/cpvt_fontmap.h b/core/fpdfdoc/cpvt_fontmap.h
index 6080010..da69463 100644
--- a/core/fpdfdoc/cpvt_fontmap.h
+++ b/core/fpdfdoc/cpvt_fontmap.h
@@ -10,6 +10,7 @@
 #include <stdint.h>
 
 #include "core/fpdfdoc/ipvt_fontmap.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_string.h"
 
 class CPDF_Document;
@@ -38,11 +39,11 @@
                                        CFX_ByteString* sSysFontAlias);
 
  private:
-  CPDF_Document* const m_pDocument;
-  const CPDF_Dictionary* const m_pResDict;
-  CPDF_Font* const m_pDefFont;
+  CFX_UnownedPtr<CPDF_Document> const m_pDocument;
+  CFX_UnownedPtr<CPDF_Dictionary> const m_pResDict;
+  CFX_UnownedPtr<CPDF_Font> const m_pDefFont;
+  CFX_UnownedPtr<CPDF_Font> m_pSysFont;
   const CFX_ByteString m_sDefFontAlias;
-  CPDF_Font* m_pSysFont;
   CFX_ByteString m_sSysFontAlias;
 };
 
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 5a39281..7a493c0 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -248,10 +248,10 @@
       continue;
     }
     if (!pCurObj)
-      pCurObj = info_curchar.m_pTextObj;
+      pCurObj = info_curchar.m_pTextObj.Get();
     if (pCurObj != info_curchar.m_pTextObj) {
       rectArray.push_back(rect);
-      pCurObj = info_curchar.m_pTextObj;
+      pCurObj = info_curchar.m_pTextObj.Get();
       bFlagNewRect = true;
     }
     if (bFlagNewRect) {
@@ -1250,7 +1250,7 @@
   FindPreviousTextObject();
   TextOrientation WritingMode = GetTextObjectWritingMode(pObj);
   if (WritingMode == TextOrientation::Unknown)
-    WritingMode = GetTextObjectWritingMode(m_pPreTextObj);
+    WritingMode = GetTextObjectWritingMode(m_pPreTextObj.Get());
 
   CFX_FloatRect this_rect = pObj->GetRect();
   CFX_FloatRect prev_rect = m_pPreTextObj->GetRect();
diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h
index d7e29ed..a183106 100644
--- a/core/fpdftext/cpdf_textpage.h
+++ b/core/fpdftext/cpdf_textpage.h
@@ -11,6 +11,7 @@
 #include <vector>
 
 #include "core/fpdfapi/page/cpdf_pageobjectlist.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_basic.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
@@ -57,7 +58,7 @@
   float m_FontSize;
   CFX_PointF m_Origin;
   CFX_FloatRect m_CharBox;
-  CPDF_TextObject* m_pTextObj;
+  CFX_UnownedPtr<CPDF_TextObject> m_pTextObj;
   CFX_Matrix m_Matrix;
 };
 
@@ -78,7 +79,7 @@
   int32_t m_Flag;
   CFX_PointF m_Origin;
   CFX_FloatRect m_CharBox;
-  CPDF_TextObject* m_pTextObj;
+  CFX_UnownedPtr<CPDF_TextObject> m_pTextObj;
   CFX_Matrix m_Matrix;
 };
 
@@ -162,14 +163,14 @@
                      const CPDF_Font* pFont,
                      int nItems) const;
 
-  const CPDF_Page* const m_pPage;
+  CFX_UnownedPtr<const CPDF_Page> const m_pPage;
   std::vector<uint16_t> m_CharIndex;
   std::deque<PAGECHAR_INFO> m_CharList;
   std::deque<PAGECHAR_INFO> m_TempCharList;
   CFX_WideTextBuf m_TextBuf;
   CFX_WideTextBuf m_TempTextBuf;
   const FPDFText_Direction m_parserflag;
-  CPDF_TextObject* m_pPreTextObj;
+  CFX_UnownedPtr<CPDF_TextObject> m_pPreTextObj;
   CFX_Matrix m_perMatrix;
   bool m_bIsParsed;
   CFX_Matrix m_DisplayMatrix;
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index a4f4a6e..058c293 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -237,7 +237,7 @@
     m_IsFind = false;
     return m_IsFind;
   }
-  CPDF_TextPageFind findEngine(m_pTextPage);
+  CPDF_TextPageFind findEngine(m_pTextPage.Get());
   bool ret = findEngine.FindFirst(m_findWhat, m_flags);
   if (!ret) {
     m_IsFind = false;
diff --git a/core/fpdftext/cpdf_textpagefind.h b/core/fpdftext/cpdf_textpagefind.h
index dd50901..ed06206 100644
--- a/core/fpdftext/cpdf_textpagefind.h
+++ b/core/fpdftext/cpdf_textpagefind.h
@@ -9,6 +9,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/cfx_unowned_ptr.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
@@ -40,7 +41,7 @@
 
  private:
   std::vector<uint16_t> m_CharIndex;
-  const CPDF_TextPage* m_pTextPage;
+  CFX_UnownedPtr<const CPDF_TextPage> m_pTextPage;
   CFX_WideString m_strText;
   CFX_WideString m_findWhat;
   int m_flags;