Restore some const lost in 2292360.

This is possible now that RetainPtr<const Type> is implemented. Leave
public types alone, though, at the price of a couple of const_casts in
the helper functions.

Change-Id: Id74e548cf9d3bc4fcf3833e8e178548fb1c6ef2f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58270
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_aaction.cpp b/core/fpdfdoc/cpdf_aaction.cpp
index 905be7c..8284913 100644
--- a/core/fpdfdoc/cpdf_aaction.cpp
+++ b/core/fpdfdoc/cpdf_aaction.cpp
@@ -41,7 +41,7 @@
 
 }  // namespace
 
-CPDF_AAction::CPDF_AAction(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
+CPDF_AAction::CPDF_AAction(const CPDF_Dictionary* pDict) : m_pDict(pDict) {}
 
 CPDF_AAction::CPDF_AAction(const CPDF_AAction& that) = default;
 
diff --git a/core/fpdfdoc/cpdf_aaction.h b/core/fpdfdoc/cpdf_aaction.h
index 8b44153..c3c65e8 100644
--- a/core/fpdfdoc/cpdf_aaction.h
+++ b/core/fpdfdoc/cpdf_aaction.h
@@ -40,7 +40,7 @@
     kNumberOfActions  // Must be last.
   };
 
-  explicit CPDF_AAction(CPDF_Dictionary* pDict);
+  explicit CPDF_AAction(const CPDF_Dictionary* pDict);
   CPDF_AAction(const CPDF_AAction& that);
   ~CPDF_AAction();
 
@@ -51,7 +51,7 @@
   static bool IsUserClick(AActionType eType);
 
  private:
-  RetainPtr<CPDF_Dictionary> const m_pDict;
+  RetainPtr<const CPDF_Dictionary> const m_pDict;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_AACTION_H_
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index dc4f485..18e4927 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -23,7 +23,7 @@
 
 }  // namespace
 
-CPDF_Action::CPDF_Action(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
+CPDF_Action::CPDF_Action(const CPDF_Dictionary* pDict) : m_pDict(pDict) {}
 
 CPDF_Action::CPDF_Action(const CPDF_Action& that) = default;
 
@@ -49,14 +49,14 @@
   if (type != GoTo && type != GoToR)
     return CPDF_Dest();
 
-  CPDF_Object* pDest = m_pDict->GetDirectObjectFor("D");
+  const CPDF_Object* pDest = m_pDict->GetDirectObjectFor("D");
   if (!pDest)
     return CPDF_Dest();
   if (pDest->IsString() || pDest->IsName()) {
     CPDF_NameTree name_tree(pDoc, "Dests");
     return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetUnicodeText()));
   }
-  if (CPDF_Array* pArray = pDest->AsArray())
+  if (const CPDF_Array* pArray = pDest->AsArray())
     return CPDF_Dest(pArray);
 
   return CPDF_Dest();
@@ -141,10 +141,10 @@
   if (!m_pDict || !m_pDict->KeyExist("Next"))
     return CPDF_Action(nullptr);
 
-  CPDF_Object* pNext = m_pDict->GetDirectObjectFor("Next");
-  if (CPDF_Array* pArray = ToArray(pNext))
+  const CPDF_Object* pNext = m_pDict->GetDirectObjectFor("Next");
+  if (const CPDF_Array* pArray = ToArray(pNext))
     return CPDF_Action(pArray->GetDictAt(iIndex));
-  if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
+  if (const CPDF_Dictionary* pDict = ToDictionary(pNext)) {
     if (iIndex == 0)
       return CPDF_Action(pDict);
   }
diff --git a/core/fpdfdoc/cpdf_action.h b/core/fpdfdoc/cpdf_action.h
index f55c42a..ccc40aa 100644
--- a/core/fpdfdoc/cpdf_action.h
+++ b/core/fpdfdoc/cpdf_action.h
@@ -38,11 +38,10 @@
     GoTo3DView
   };
 
-  explicit CPDF_Action(CPDF_Dictionary* pDict);
+  explicit CPDF_Action(const CPDF_Dictionary* pDict);
   CPDF_Action(const CPDF_Action& that);
   ~CPDF_Action();
 
-  CPDF_Dictionary* GetDict() { return m_pDict.Get(); }
   const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
 
   ActionType GetType() const;
@@ -57,7 +56,7 @@
   CPDF_Action GetSubAction(size_t iIndex) const;
 
  private:
-  RetainPtr<CPDF_Dictionary> const m_pDict;
+  RetainPtr<const CPDF_Dictionary> const m_pDict;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_ACTION_H_
diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp
index 3a414ff..7f7958b 100644
--- a/core/fpdfdoc/cpdf_bookmark.cpp
+++ b/core/fpdfdoc/cpdf_bookmark.cpp
@@ -19,7 +19,7 @@
 
 CPDF_Bookmark::CPDF_Bookmark(const CPDF_Bookmark& that) = default;
 
-CPDF_Bookmark::CPDF_Bookmark(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
+CPDF_Bookmark::CPDF_Bookmark(const CPDF_Dictionary* pDict) : m_pDict(pDict) {}
 
 CPDF_Bookmark::~CPDF_Bookmark() = default;
 
@@ -52,7 +52,7 @@
   if (!m_pDict)
     return CPDF_Dest();
 
-  CPDF_Object* pDest = m_pDict->GetDirectObjectFor("Dest");
+  const CPDF_Object* pDest = m_pDict->GetDirectObjectFor("Dest");
   if (!pDest)
     return CPDF_Dest();
   if (pDest->IsString() || pDest->IsName()) {
@@ -60,7 +60,7 @@
     return CPDF_Dest(
         name_tree.LookupNamedDest(pDocument, pDest->GetUnicodeText()));
   }
-  if (CPDF_Array* pArray = pDest->AsArray())
+  if (const CPDF_Array* pArray = pDest->AsArray())
     return CPDF_Dest(pArray);
   return CPDF_Dest();
 }
diff --git a/core/fpdfdoc/cpdf_bookmark.h b/core/fpdfdoc/cpdf_bookmark.h
index c2de6ff..400b869 100644
--- a/core/fpdfdoc/cpdf_bookmark.h
+++ b/core/fpdfdoc/cpdf_bookmark.h
@@ -19,10 +19,9 @@
  public:
   CPDF_Bookmark();
   CPDF_Bookmark(const CPDF_Bookmark& that);
-  explicit CPDF_Bookmark(CPDF_Dictionary* pDict);
+  explicit CPDF_Bookmark(const CPDF_Dictionary* pDict);
   ~CPDF_Bookmark();
 
-  CPDF_Dictionary* GetDict() { return m_pDict.Get(); }
   const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
 
   uint32_t GetFontStyle() const;
@@ -31,7 +30,7 @@
   CPDF_Action GetAction() const;
 
  private:
-  RetainPtr<CPDF_Dictionary> m_pDict;
+  RetainPtr<const CPDF_Dictionary> m_pDict;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_BOOKMARK_H_
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp
index ce7cfef..5c4fffe 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.cpp
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -14,7 +14,7 @@
 CPDF_BookmarkTree::~CPDF_BookmarkTree() = default;
 
 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(CPDF_Bookmark* parent) const {
-  CPDF_Dictionary* pParentDict = parent->GetDict();
+  const CPDF_Dictionary* pParentDict = parent->GetDict();
   if (pParentDict)
     return CPDF_Bookmark(pParentDict->GetDictFor("First"));
 
@@ -28,10 +28,10 @@
 }
 
 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(CPDF_Bookmark* bookmark) const {
-  CPDF_Dictionary* pDict = bookmark->GetDict();
+  const CPDF_Dictionary* pDict = bookmark->GetDict();
   if (!pDict)
     return CPDF_Bookmark();
 
-  CPDF_Dictionary* pNext = pDict->GetDictFor("Next");
+  const CPDF_Dictionary* pNext = pDict->GetDictFor("Next");
   return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext);
 }
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index 511081f..601f85d 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -32,7 +32,7 @@
 
 CPDF_Dest::CPDF_Dest() {}
 
-CPDF_Dest::CPDF_Dest(CPDF_Array* pArray) : m_pArray(pArray) {}
+CPDF_Dest::CPDF_Dest(const CPDF_Array* pArray) : m_pArray(pArray) {}
 
 CPDF_Dest::CPDF_Dest(const CPDF_Dest& that) = default;
 
diff --git a/core/fpdfdoc/cpdf_dest.h b/core/fpdfdoc/cpdf_dest.h
index c1b1df3..2de1263 100644
--- a/core/fpdfdoc/cpdf_dest.h
+++ b/core/fpdfdoc/cpdf_dest.h
@@ -17,11 +17,10 @@
 class CPDF_Dest {
  public:
   CPDF_Dest();
-  explicit CPDF_Dest(CPDF_Array* pArray);
+  explicit CPDF_Dest(const CPDF_Array* pArray);
   CPDF_Dest(const CPDF_Dest& that);
   ~CPDF_Dest();
 
-  CPDF_Array* GetArray() { return m_pArray.Get(); }
   const CPDF_Array* GetArray() const { return m_pArray.Get(); }
 
   ByteString GetRemoteName() const;
@@ -41,7 +40,7 @@
               float* pZoom) const;
 
  private:
-  RetainPtr<CPDF_Array> const m_pArray;
+  RetainPtr<const CPDF_Array> const m_pArray;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_DEST_H_
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index 5d9522a..f67479f 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -56,8 +56,8 @@
 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
 
 // Conversions to/from incomplete FPDF_ API types.
-inline FPDF_ACTION FPDFActionFromCPDFDictionary(CPDF_Dictionary* action) {
-  return reinterpret_cast<FPDF_ACTION>(action);
+inline FPDF_ACTION FPDFActionFromCPDFDictionary(const CPDF_Dictionary* action) {
+  return reinterpret_cast<FPDF_ACTION>(const_cast<CPDF_Dictionary*>(action));
 }
 inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
   return reinterpret_cast<CPDF_Dictionary*>(action);
@@ -86,8 +86,10 @@
   return reinterpret_cast<CFX_DIBitmap*>(bitmap);
 }
 
-inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(CPDF_Dictionary* bookmark) {
-  return reinterpret_cast<FPDF_BOOKMARK>(bookmark);
+inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(
+    const CPDF_Dictionary* bookmark) {
+  return reinterpret_cast<FPDF_BOOKMARK>(
+      const_cast<CPDF_Dictionary*>(bookmark));
 }
 inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
   return reinterpret_cast<CPDF_Dictionary*>(bookmark);
@@ -100,8 +102,8 @@
   return reinterpret_cast<CPDF_ClipPath*>(path);
 }
 
-inline FPDF_DEST FPDFDestFromCPDFArray(CPDF_Array* dest) {
-  return reinterpret_cast<FPDF_DEST>(dest);
+inline FPDF_DEST FPDFDestFromCPDFArray(const CPDF_Array* dest) {
+  return reinterpret_cast<FPDF_DEST>(const_cast<CPDF_Array*>(dest));
 }
 inline CPDF_Array* CPDFArrayFromFPDFDest(FPDF_DEST dest) {
   return reinterpret_cast<CPDF_Array*>(dest);