Return unique_ptr<> from IPDF_StructTree

Delete some dead code in the process.

Review-Url: https://codereview.chromium.org/2585873002
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp
index 10c573b..39feaee 100644
--- a/core/fpdfdoc/doc_tagged.cpp
+++ b/core/fpdfdoc/doc_tagged.cpp
@@ -5,6 +5,8 @@
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include <map>
+#include <memory>
+#include <utility>
 
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -16,6 +18,7 @@
 #include "core/fpdfdoc/cpdf_numbertree.h"
 #include "core/fpdfdoc/fpdf_tagged.h"
 #include "core/fpdfdoc/tagged_int.h"
+#include "third_party/base/ptr_util.h"
 
 namespace {
 
@@ -30,24 +33,15 @@
 }  // namespace
 
 // static
-IPDF_StructTree* IPDF_StructTree::LoadPage(const CPDF_Document* pDoc,
-                                           const CPDF_Dictionary* pPageDict) {
+std::unique_ptr<IPDF_StructTree> IPDF_StructTree::LoadPage(
+    const CPDF_Document* pDoc,
+    const CPDF_Dictionary* pPageDict) {
   if (!IsTagged(pDoc))
     return nullptr;
 
-  CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc);
+  auto pTree = pdfium::MakeUnique<CPDF_StructTreeImpl>(pDoc);
   pTree->LoadPageTree(pPageDict);
-  return pTree;
-}
-
-// static.
-IPDF_StructTree* IPDF_StructTree::LoadDoc(const CPDF_Document* pDoc) {
-  if (!IsTagged(pDoc))
-    return nullptr;
-
-  CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc);
-  pTree->LoadDocTree();
-  return pTree;
+  return std::move(pTree);
 }
 
 CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc)
@@ -65,31 +59,6 @@
   return m_Kids[i].Get();
 }
 
-void CPDF_StructTreeImpl::LoadDocTree() {
-  m_pPage = nullptr;
-  if (!m_pTreeRoot)
-    return;
-
-  CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectFor("K");
-  if (!pKids)
-    return;
-
-  if (CPDF_Dictionary* pDict = pKids->AsDictionary()) {
-    m_Kids.push_back(CFX_RetainPtr<CPDF_StructElementImpl>(
-        new CPDF_StructElementImpl(this, nullptr, pDict)));
-    return;
-  }
-
-  CPDF_Array* pArray = pKids->AsArray();
-  if (!pArray)
-    return;
-
-  for (size_t i = 0; i < pArray->GetCount(); i++) {
-    m_Kids.push_back(CFX_RetainPtr<CPDF_StructElementImpl>(
-        new CPDF_StructElementImpl(this, nullptr, pArray->GetDictAt(i))));
-  }
-}
-
 void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
   m_pPage = pPageDict;
   if (!m_pTreeRoot)
diff --git a/core/fpdfdoc/fpdf_tagged.h b/core/fpdfdoc/fpdf_tagged.h
index 716e6267..aa697ca 100644
--- a/core/fpdfdoc/fpdf_tagged.h
+++ b/core/fpdfdoc/fpdf_tagged.h
@@ -7,6 +7,8 @@
 #ifndef CORE_FPDFDOC_FPDF_TAGGED_H_
 #define CORE_FPDFDOC_FPDF_TAGGED_H_
 
+#include <memory>
+
 #include "core/fxge/fx_dib.h"
 
 class CPDF_Dictionary;
@@ -15,9 +17,9 @@
 
 class IPDF_StructTree {
  public:
-  static IPDF_StructTree* LoadDoc(const CPDF_Document* pDoc);
-  static IPDF_StructTree* LoadPage(const CPDF_Document* pDoc,
-                                   const CPDF_Dictionary* pPageDict);
+  static std::unique_ptr<IPDF_StructTree> LoadPage(
+      const CPDF_Document* pDoc,
+      const CPDF_Dictionary* pPageDict);
 
   virtual ~IPDF_StructTree() {}
 
diff --git a/core/fpdfdoc/tagged_int.h b/core/fpdfdoc/tagged_int.h
index 43e43f1..03f1c40 100644
--- a/core/fpdfdoc/tagged_int.h
+++ b/core/fpdfdoc/tagged_int.h
@@ -26,7 +26,6 @@
   int CountTopElements() const override;
   IPDF_StructElement* GetTopElement(int i) const override;
 
-  void LoadDocTree();
   void LoadPageTree(const CPDF_Dictionary* pPageDict);
   CPDF_StructElementImpl* AddPageNode(
       CPDF_Dictionary* pElement,
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index 541c46b..9bc1df6 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -25,7 +25,8 @@
   CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
   if (!pPage)
     return nullptr;
-  return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict);
+  return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict)
+      .release();
 }
 
 DLLEXPORT void STDCALL FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) {