Mark more CPDF_Objects as const in action and bookmark code.

Change-Id: Ib5f4cdb9c7f9c33561028a85029649ba68f4a6e5
Reviewed-on: https://pdfium-review.googlesource.com/32912
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index 4ac86fe..4a89a7d 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -22,7 +22,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;
 
@@ -76,7 +76,7 @@
     return CPDF_FileSpec(pFile).GetFileName();
 
   if (type == "Launch") {
-    CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win");
+    const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win");
     if (pWinDict) {
       return WideString::FromLocal(
           pWinDict->GetStringFor(pdfium::stream::kF).AsStringView());
@@ -94,7 +94,7 @@
 
   csURI = m_pDict->GetStringFor("URI");
   const CPDF_Dictionary* pRoot = pDoc->GetRoot();
-  CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
+  const CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
   if (pURI) {
     auto result = csURI.Find(":");
     if (!result.has_value() || result.value() == 0)
diff --git a/core/fpdfdoc/cpdf_action.h b/core/fpdfdoc/cpdf_action.h
index 1d9b722..43bf123 100644
--- a/core/fpdfdoc/cpdf_action.h
+++ b/core/fpdfdoc/cpdf_action.h
@@ -37,11 +37,11 @@
     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() const { return m_pDict.Get(); }
+  const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
   ActionType GetType() const;
   CPDF_Dest GetDest(CPDF_Document* pDoc) const;
   WideString GetFilePath() const;
@@ -54,7 +54,7 @@
   CPDF_Action GetSubAction(size_t iIndex) const;
 
  private:
-  UnownedPtr<CPDF_Dictionary> const m_pDict;
+  UnownedPtr<const CPDF_Dictionary> const m_pDict;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_ACTION_H_
diff --git a/core/fpdfdoc/cpdf_actionfields.cpp b/core/fpdfdoc/cpdf_actionfields.cpp
index cee256d..89636bf 100644
--- a/core/fpdfdoc/cpdf_actionfields.cpp
+++ b/core/fpdfdoc/cpdf_actionfields.cpp
@@ -19,12 +19,12 @@
   if (!m_pAction)
     return 0;
 
-  CPDF_Dictionary* pDict = m_pAction->GetDict();
+  const CPDF_Dictionary* pDict = m_pAction->GetDict();
   if (!pDict)
     return 0;
 
   ByteString csType = pDict->GetStringFor("S");
-  CPDF_Object* pFields = nullptr;
+  const CPDF_Object* pFields;
   if (csType == "Hide")
     pFields = pDict->GetDirectObjectFor("T");
   else
@@ -36,22 +36,21 @@
     return 1;
   if (pFields->IsString())
     return 1;
-  if (CPDF_Array* pArray = pFields->AsArray())
-    return pArray->GetCount();
-  return 0;
+  const CPDF_Array* pArray = pFields->AsArray();
+  return pArray ? pArray->GetCount() : 0;
 }
 
-std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const {
-  std::vector<CPDF_Object*> fields;
+std::vector<const CPDF_Object*> CPDF_ActionFields::GetAllFields() const {
+  std::vector<const CPDF_Object*> fields;
   if (!m_pAction)
     return fields;
 
-  CPDF_Dictionary* pDict = m_pAction->GetDict();
+  const CPDF_Dictionary* pDict = m_pAction->GetDict();
   if (!pDict)
     return fields;
 
   ByteString csType = pDict->GetStringFor("S");
-  CPDF_Object* pFields;
+  const CPDF_Object* pFields;
   if (csType == "Hide")
     pFields = pDict->GetDirectObjectFor("T");
   else
@@ -62,9 +61,9 @@
 
   if (pFields->IsDictionary() || pFields->IsString()) {
     fields.push_back(pFields);
-  } else if (CPDF_Array* pArray = pFields->AsArray()) {
+  } else if (const CPDF_Array* pArray = pFields->AsArray()) {
     for (size_t i = 0; i < pArray->GetCount(); ++i) {
-      CPDF_Object* pObj = pArray->GetDirectObjectAt(i);
+      const CPDF_Object* pObj = pArray->GetDirectObjectAt(i);
       if (pObj)
         fields.push_back(pObj);
     }
@@ -72,16 +71,16 @@
   return fields;
 }
 
-CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const {
+const CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const {
   if (!m_pAction)
     return nullptr;
 
-  CPDF_Dictionary* pDict = m_pAction->GetDict();
+  const CPDF_Dictionary* pDict = m_pAction->GetDict();
   if (!pDict)
     return nullptr;
 
   ByteString csType = pDict->GetStringFor("S");
-  CPDF_Object* pFields = nullptr;
+  const CPDF_Object* pFields;
   if (csType == "Hide")
     pFields = pDict->GetDirectObjectFor("T");
   else
@@ -90,11 +89,11 @@
   if (!pFields)
     return nullptr;
 
-  CPDF_Object* pFindObj = nullptr;
+  const CPDF_Object* pFindObj = nullptr;
   if (pFields->IsDictionary() || pFields->IsString()) {
     if (iIndex == 0)
       pFindObj = pFields;
-  } else if (CPDF_Array* pArray = pFields->AsArray()) {
+  } else if (const CPDF_Array* pArray = pFields->AsArray()) {
     pFindObj = pArray->GetDirectObjectAt(iIndex);
   }
   return pFindObj;
diff --git a/core/fpdfdoc/cpdf_actionfields.h b/core/fpdfdoc/cpdf_actionfields.h
index 83c70f6..affc03c 100644
--- a/core/fpdfdoc/cpdf_actionfields.h
+++ b/core/fpdfdoc/cpdf_actionfields.h
@@ -22,8 +22,8 @@
   ~CPDF_ActionFields();
 
   size_t GetFieldsCount() const;
-  std::vector<CPDF_Object*> GetAllFields() const;
-  CPDF_Object* GetField(size_t iIndex) const;
+  std::vector<const CPDF_Object*> GetAllFields() const;
+  const CPDF_Object* GetField(size_t iIndex) const;
 
  private:
   UnownedPtr<const CPDF_Action> const m_pAction;
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index dc2e8ac..5734e19 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -64,7 +64,7 @@
 CPDF_Stream* FPDFDOC_GetAnnotAPInternal(const CPDF_Dictionary* pAnnotDict,
                                         CPDF_Annot::AppearanceMode eMode,
                                         bool bFallbackToNormal) {
-  CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP");
+  const CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP");
   if (!pAP)
     return nullptr;
 
@@ -90,7 +90,7 @@
   if (as.IsEmpty()) {
     ByteString value = pAnnotDict->GetStringFor("V");
     if (value.IsEmpty()) {
-      CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent");
+      const CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent");
       value = pParentDict ? pParentDict->GetStringFor("V") : ByteString();
     }
     as = (!value.IsEmpty() && pDict->KeyExist(value)) ? value : "Off";
@@ -230,11 +230,12 @@
 // static
 CFX_FloatRect CPDF_Annot::BoundingRectFromQuadPoints(
     const CPDF_Dictionary* pAnnotDict) {
-  CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints");
+  CFX_FloatRect ret;
+  const CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints");
   if (!pArray)
-    return CFX_FloatRect();
+    return ret;
 
-  CFX_FloatRect ret = RectFromQuadPointsArray(pArray, 0);
+  ret = RectFromQuadPointsArray(pArray, 0);
   size_t nQuadPointCount = QuadPointCount(pArray);
   for (size_t i = 1; i < nQuadPointCount; ++i) {
     CFX_FloatRect rect = RectFromQuadPointsArray(pArray, i);
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 77a2d0c..e364a72 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -129,7 +129,7 @@
     return;
 
   const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
-  CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+  const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
   bool bRegenerateAP = pAcroForm && pAcroForm->GetBooleanFor("NeedAppearances");
   for (size_t i = 0; i < pAnnots->GetCount(); ++i) {
     CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i));
diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp
index 5f8997d..3237580 100644
--- a/core/fpdfdoc/cpdf_bookmark.cpp
+++ b/core/fpdfdoc/cpdf_bookmark.cpp
@@ -24,7 +24,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() {}
 
@@ -32,7 +32,7 @@
   if (!m_pDict)
     return kBlackBGR;
 
-  CPDF_Array* pColor = m_pDict->GetArrayFor("C");
+  const CPDF_Array* pColor = m_pDict->GetArrayFor("C");
   if (!pColor)
     return kBlackBGR;
 
diff --git a/core/fpdfdoc/cpdf_bookmark.h b/core/fpdfdoc/cpdf_bookmark.h
index 60c86dd..ff31af1 100644
--- a/core/fpdfdoc/cpdf_bookmark.h
+++ b/core/fpdfdoc/cpdf_bookmark.h
@@ -19,10 +19,10 @@
  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() const { return m_pDict.Get(); }
+  const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
   uint32_t GetColorRef() const;
   uint32_t GetFontStyle() const;
   WideString GetTitle() const;
@@ -30,7 +30,7 @@
   CPDF_Action GetAction() const;
 
  private:
-  UnownedPtr<CPDF_Dictionary> m_pDict;
+  UnownedPtr<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 33c9f3d..3b178f0 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.cpp
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -14,7 +14,7 @@
 
 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(
     const CPDF_Bookmark& parent) const {
-  CPDF_Dictionary* pParentDict = parent.GetDict();
+  const CPDF_Dictionary* pParentDict = parent.GetDict();
   if (pParentDict)
     return CPDF_Bookmark(pParentDict->GetDictFor("First"));
 
@@ -22,17 +22,17 @@
   if (!pRoot)
     return CPDF_Bookmark();
 
-  CPDF_Dictionary* pOutlines = pRoot->GetDictFor("Outlines");
+  const CPDF_Dictionary* pOutlines = pRoot->GetDictFor("Outlines");
   return pOutlines ? CPDF_Bookmark(pOutlines->GetDictFor("First"))
                    : CPDF_Bookmark();
 }
 
 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(
     const 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_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index bfc39b0..acad073 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -64,7 +64,7 @@
   if (pAttr)
     return pAttr;
 
-  CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent");
+  const CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent");
   return pParent ? FPDF_GetFieldAttr(pParent, name, nLevel + 1) : nullptr;
 }
 
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index 0c548d8..83df36b 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -690,7 +690,7 @@
   if (!pResDict)
     return csTmp;
 
-  CPDF_Dictionary* pDict = pResDict->GetDictFor(csType);
+  const CPDF_Dictionary* pDict = pResDict->GetDictFor(csType);
   if (!pDict)
     return csTmp;
 
@@ -963,8 +963,8 @@
   return m_pFormDict && m_pFormDict->GetArrayFor("XFA");
 }
 
-void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
-  const CPDF_Dictionary* pPageDict = pPage->GetFormDict();
+void CPDF_InterForm::FixPageFields(CPDF_Page* pPage) {
+  CPDF_Dictionary* pPageDict = pPage->GetFormDict();
   if (!pPageDict)
     return;
 
diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h
index 2f60bf7..796c336 100644
--- a/core/fpdfdoc/cpdf_interform.h
+++ b/core/fpdfdoc/cpdf_interform.h
@@ -87,7 +87,7 @@
 
   void SetFormNotify(IPDF_FormNotify* pNotify);
   bool HasXFAForm() const;
-  void FixPageFields(const CPDF_Page* pPage);
+  void FixPageFields(CPDF_Page* pPage);
 
   IPDF_FormNotify* GetFormNotify() const { return m_pFormNotify.Get(); }
   CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
diff --git a/core/fpdfdoc/cpdf_numbertree.cpp b/core/fpdfdoc/cpdf_numbertree.cpp
index 952fb4e..74aeb67 100644
--- a/core/fpdfdoc/cpdf_numbertree.cpp
+++ b/core/fpdfdoc/cpdf_numbertree.cpp
@@ -11,13 +11,13 @@
 
 namespace {
 
-CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) {
-  CPDF_Array* pLimits = pNode->GetArrayFor("Limits");
+const CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) {
+  const CPDF_Array* pLimits = pNode->GetArrayFor("Limits");
   if (pLimits &&
       (num < pLimits->GetIntegerAt(0) || num > pLimits->GetIntegerAt(1))) {
     return nullptr;
   }
-  CPDF_Array* pNumbers = pNode->GetArrayFor("Nums");
+  const CPDF_Array* pNumbers = pNode->GetArrayFor("Nums");
   if (pNumbers) {
     for (size_t i = 0; i < pNumbers->GetCount() / 2; i++) {
       int index = pNumbers->GetIntegerAt(i * 2);
@@ -29,16 +29,16 @@
     return nullptr;
   }
 
-  CPDF_Array* pKids = pNode->GetArrayFor("Kids");
+  const CPDF_Array* pKids = pNode->GetArrayFor("Kids");
   if (!pKids)
     return nullptr;
 
   for (size_t i = 0; i < pKids->GetCount(); i++) {
-    CPDF_Dictionary* pKid = pKids->GetDictAt(i);
+    const CPDF_Dictionary* pKid = pKids->GetDictAt(i);
     if (!pKid)
       continue;
 
-    CPDF_Object* pFound = SearchNumberNode(pKid, num);
+    const CPDF_Object* pFound = SearchNumberNode(pKid, num);
     if (pFound)
       return pFound;
   }
@@ -47,10 +47,11 @@
 
 }  // namespace
 
-CPDF_NumberTree::CPDF_NumberTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {}
+CPDF_NumberTree::CPDF_NumberTree(const CPDF_Dictionary* pRoot)
+    : m_pRoot(pRoot) {}
 
 CPDF_NumberTree::~CPDF_NumberTree() {}
 
-CPDF_Object* CPDF_NumberTree::LookupValue(int num) const {
+const CPDF_Object* CPDF_NumberTree::LookupValue(int num) const {
   return SearchNumberNode(m_pRoot.Get(), num);
 }
diff --git a/core/fpdfdoc/cpdf_numbertree.h b/core/fpdfdoc/cpdf_numbertree.h
index 47c40b9..1c65fd2 100644
--- a/core/fpdfdoc/cpdf_numbertree.h
+++ b/core/fpdfdoc/cpdf_numbertree.h
@@ -14,13 +14,13 @@
 
 class CPDF_NumberTree {
  public:
-  explicit CPDF_NumberTree(CPDF_Dictionary* pRoot);
+  explicit CPDF_NumberTree(const CPDF_Dictionary* pRoot);
   ~CPDF_NumberTree();
 
-  CPDF_Object* LookupValue(int num) const;
+  const CPDF_Object* LookupValue(int num) const;
 
  protected:
-  UnownedPtr<CPDF_Dictionary> const m_pRoot;
+  UnownedPtr<const CPDF_Dictionary> const m_pRoot;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_NUMBERTREE_H_
diff --git a/core/fpdfdoc/cpdf_occontext.cpp b/core/fpdfdoc/cpdf_occontext.cpp
index e596909..192a254 100644
--- a/core/fpdfdoc/cpdf_occontext.cpp
+++ b/core/fpdfdoc/cpdf_occontext.cpp
@@ -150,9 +150,9 @@
     return true;
 
   ByteString csState = GetUsageTypeString(m_eUsageType);
-  CPDF_Dictionary* pUsage = pOCGDict->GetDictFor("Usage");
+  const CPDF_Dictionary* pUsage = pOCGDict->GetDictFor("Usage");
   if (pUsage) {
-    CPDF_Dictionary* pState = pUsage->GetDictFor(csState);
+    const CPDF_Dictionary* pState = pUsage->GetDictFor(csState);
     if (pState) {
       ByteString csFind = csState + "State";
       if (pState->KeyExist(csFind))
@@ -192,18 +192,18 @@
   return true;
 }
 
-bool CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, int nLevel) {
+bool CPDF_OCContext::GetOCGVE(const CPDF_Array* pExpression, int nLevel) {
   if (nLevel > 32 || !pExpression)
     return false;
 
   ByteString csOperator = pExpression->GetStringAt(0);
   if (csOperator == "Not") {
-    CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1);
+    const CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1);
     if (!pOCGObj)
       return false;
-    if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
+    if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
       return !GetOCGVisible(pDict);
-    if (CPDF_Array* pArray = pOCGObj->AsArray())
+    if (const CPDF_Array* pArray = pOCGObj->AsArray())
       return !GetOCGVE(pArray, nLevel + 1);
     return false;
   }
@@ -213,14 +213,14 @@
 
   bool bValue = false;
   for (size_t i = 1; i < pExpression->GetCount(); i++) {
-    CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1);
+    const CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1);
     if (!pOCGObj)
       continue;
 
     bool bItem = false;
-    if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
+    if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
       bItem = GetOCGVisible(pDict);
-    else if (CPDF_Array* pArray = pOCGObj->AsArray())
+    else if (const CPDF_Array* pArray = pOCGObj->AsArray())
       bItem = GetOCGVE(pArray, nLevel + 1);
 
     if (i == 1) {
@@ -237,7 +237,7 @@
 }
 
 bool CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict) {
-  CPDF_Array* pVE = pOCMDDict->GetArrayFor("VE");
+  const CPDF_Array* pVE = pOCMDDict->GetArrayFor("VE");
   if (pVE)
     return GetOCGVE(pVE, 0);
 
diff --git a/core/fpdfdoc/cpdf_occontext.h b/core/fpdfdoc/cpdf_occontext.h
index c47b933..6776361 100644
--- a/core/fpdfdoc/cpdf_occontext.h
+++ b/core/fpdfdoc/cpdf_occontext.h
@@ -35,7 +35,7 @@
                               const CPDF_Dictionary* pOCGDict) const;
   bool LoadOCGState(const CPDF_Dictionary* pOCGDict) const;
   bool GetOCGVisible(const CPDF_Dictionary* pOCGDict);
-  bool GetOCGVE(CPDF_Array* pExpression, int nLevel);
+  bool GetOCGVE(const CPDF_Array* pExpression, int nLevel);
   bool LoadOCMDState(const CPDF_Dictionary* pOCMDDict);
 
   UnownedPtr<CPDF_Document> const m_pDocument;
diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp
index f06e401..e6a7780 100644
--- a/core/fpdfdoc/cpdf_pagelabel.cpp
+++ b/core/fpdfdoc/cpdf_pagelabel.cpp
@@ -89,12 +89,12 @@
   if (!pPDFRoot)
     return {};
 
-  CPDF_Dictionary* pLabels = pPDFRoot->GetDictFor("PageLabels");
+  const CPDF_Dictionary* pLabels = pPDFRoot->GetDictFor("PageLabels");
   if (!pLabels)
     return {};
 
   CPDF_NumberTree numberTree(pLabels);
-  CPDF_Object* pValue = nullptr;
+  const CPDF_Object* pValue = nullptr;
   int n = nPage;
   while (n >= 0) {
     pValue = numberTree.LookupValue(n);
@@ -106,7 +106,7 @@
   WideString label;
   if (pValue) {
     pValue = pValue->GetDirect();
-    if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) {
+    if (const CPDF_Dictionary* pLabel = pValue->AsDictionary()) {
       if (pLabel->KeyExist("P"))
         label += pLabel->GetUnicodeTextFor("P");
 
diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp
index 13985b8..ed5c8c7 100644
--- a/core/fpdfdoc/cpdf_structelement.cpp
+++ b/core/fpdfdoc/cpdf_structelement.cpp
@@ -17,7 +17,6 @@
 
 CPDF_StructKid::CPDF_StructKid()
     : m_Type(Invalid),
-      m_pDict(nullptr),
       m_PageObjNum(0),
       m_RefObjNum(0),
       m_ContentId(0) {}
@@ -28,7 +27,7 @@
 
 CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree,
                                        CPDF_StructElement* pParent,
-                                       CPDF_Dictionary* pDict)
+                                       const CPDF_Dictionary* pDict)
     : m_pTree(pTree),
       m_pParent(pParent),
       m_pDict(pDict),
@@ -54,10 +53,10 @@
              : nullptr;
 }
 
-void CPDF_StructElement::LoadKids(CPDF_Dictionary* pDict) {
-  CPDF_Object* pObj = pDict->GetObjectFor("Pg");
+void CPDF_StructElement::LoadKids(const CPDF_Dictionary* pDict) {
+  const CPDF_Object* pObj = pDict->GetObjectFor("Pg");
   uint32_t PageObjNum = 0;
-  if (CPDF_Reference* pRef = ToReference(pObj))
+  if (const CPDF_Reference* pRef = ToReference(pObj))
     PageObjNum = pRef->GetRefObjNum();
 
   CPDF_Object* pKids = pDict->GetDirectObjectFor("K");
diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h
index 51ee93b..2586d9c 100644
--- a/core/fpdfdoc/cpdf_structelement.h
+++ b/core/fpdfdoc/cpdf_structelement.h
@@ -28,7 +28,7 @@
   enum { Invalid, Element, PageContent, StreamContent, Object } m_Type;
 
   RetainPtr<CPDF_StructElement> m_pElement;      // For Element.
-  UnownedPtr<CPDF_Dictionary> m_pDict;           // For Element.
+  UnownedPtr<const 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.
@@ -41,7 +41,7 @@
 
   const ByteString& GetType() const { return m_Type; }
   const ByteString& GetTitle() const { return m_Title; }
-  CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
+  const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
 
   size_t CountKids() const;
   CPDF_StructElement* GetKidIfElement(size_t index) const;
@@ -50,15 +50,15 @@
  private:
   CPDF_StructElement(CPDF_StructTree* pTree,
                      CPDF_StructElement* pParent,
-                     CPDF_Dictionary* pDict);
+                     const CPDF_Dictionary* pDict);
   ~CPDF_StructElement() override;
 
-  void LoadKids(CPDF_Dictionary* pDict);
+  void LoadKids(const CPDF_Dictionary* pDict);
   void LoadKid(uint32_t PageObjNum, CPDF_Object* pObj, CPDF_StructKid* pKid);
 
   UnownedPtr<CPDF_StructTree> const m_pTree;
   UnownedPtr<CPDF_StructElement> const m_pParent;
-  UnownedPtr<CPDF_Dictionary> const m_pDict;
+  UnownedPtr<const CPDF_Dictionary> const m_pDict;
   ByteString m_Type;
   ByteString m_Title;
   std::vector<CPDF_StructKid> m_Kids;
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index 97db691..1e4d08a 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -61,7 +61,7 @@
 
   m_Kids.clear();
   m_Kids.resize(dwKids);
-  CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree");
+  const CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree");
   if (!pParentTree)
     return;
 
@@ -70,20 +70,20 @@
   if (parents_id < 0)
     return;
 
-  CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id));
+  const CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id));
   if (!pParentArray)
     return;
 
-  std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>> element_map;
+  StructElementMap element_map;
   for (size_t i = 0; i < pParentArray->GetCount(); i++) {
-    if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i))
+    if (const CPDF_Dictionary* pParent = pParentArray->GetDictAt(i))
       AddPageNode(pParent, &element_map, 0);
   }
 }
 
 RetainPtr<CPDF_StructElement> CPDF_StructTree::AddPageNode(
-    CPDF_Dictionary* pDict,
-    std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>* map,
+    const CPDF_Dictionary* pDict,
+    StructElementMap* map,
     int nLevel) {
   static constexpr int kStructTreeMaxRecursion = 32;
   if (nLevel > kStructTreeMaxRecursion)
@@ -95,7 +95,7 @@
 
   auto pElement = pdfium::MakeRetain<CPDF_StructElement>(this, nullptr, pDict);
   (*map)[pDict] = pElement;
-  CPDF_Dictionary* pParent = pDict->GetDictFor("P");
+  const CPDF_Dictionary* pParent = pDict->GetDictFor("P");
   if (!pParent || pParent->GetStringFor("Type") == "StructTreeRoot") {
     if (!AddTopLevelNode(pDict, pElement))
       map->erase(pDict);
@@ -117,7 +117,7 @@
 }
 
 bool CPDF_StructTree::AddTopLevelNode(
-    CPDF_Dictionary* pDict,
+    const CPDF_Dictionary* pDict,
     const RetainPtr<CPDF_StructElement>& pElement) {
   CPDF_Object* pObj = m_pTreeRoot->GetDirectObjectFor("K");
   if (!pObj)
diff --git a/core/fpdfdoc/cpdf_structtree.h b/core/fpdfdoc/cpdf_structtree.h
index 99342fb..13bf148 100644
--- a/core/fpdfdoc/cpdf_structtree.h
+++ b/core/fpdfdoc/cpdf_structtree.h
@@ -34,12 +34,14 @@
   const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot.Get(); }
 
  private:
+  using StructElementMap =
+      std::map<const CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>;
+
   void LoadPageTree(const CPDF_Dictionary* pPageDict);
-  RetainPtr<CPDF_StructElement> AddPageNode(
-      CPDF_Dictionary* pElement,
-      std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>* map,
-      int nLevel);
-  bool AddTopLevelNode(CPDF_Dictionary* pDict,
+  RetainPtr<CPDF_StructElement> AddPageNode(const CPDF_Dictionary* pElement,
+                                            StructElementMap* map,
+                                            int nLevel);
+  bool AddTopLevelNode(const CPDF_Dictionary* pDict,
                        const RetainPtr<CPDF_StructElement>& pElement);
 
   UnownedPtr<const CPDF_Dictionary> const m_pTreeRoot;
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index aaf8661..6164062 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -25,8 +25,9 @@
 
 CPVT_FontMap::~CPVT_FontMap() {}
 
+// static
 CPDF_Font* CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
-                                            const CPDF_Dictionary* pResDict,
+                                            CPDF_Dictionary* pResDict,
                                             ByteString* sSysFontAlias) {
   if (!pDoc || !pResDict)
     return nullptr;
diff --git a/core/fpdfdoc/cpvt_fontmap.h b/core/fpdfdoc/cpvt_fontmap.h
index a0b94cf..f1a2775 100644
--- a/core/fpdfdoc/cpvt_fontmap.h
+++ b/core/fpdfdoc/cpvt_fontmap.h
@@ -35,7 +35,7 @@
   int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override;
 
   static CPDF_Font* GetAnnotSysPDFFont(CPDF_Document* pDoc,
-                                       const CPDF_Dictionary* pResDict,
+                                       CPDF_Dictionary* pResDict,
                                        ByteString* sSysFontAlias);
 
  private:
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 22f7c8f..e395fbf 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -313,12 +313,12 @@
 }
 
 float GetBorderWidth(const CPDF_Dictionary& pAnnotDict) {
-  if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) {
+  if (const CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) {
     if (pBorderStyleDict->KeyExist("W"))
       return pBorderStyleDict->GetNumberFor("W");
   }
 
-  if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) {
+  if (const CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) {
     if (pBorderArray->GetCount() > 2)
       return pBorderArray->GetNumberAt(2);
   }
@@ -326,13 +326,13 @@
   return 1;
 }
 
-CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) {
-  if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) {
+const CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) {
+  if (const CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) {
     if (pBorderStyleDict->GetStringFor("S") == "D")
       return pBorderStyleDict->GetArrayFor("D");
   }
 
-  if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) {
+  if (const CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) {
     if (pBorderArray->GetCount() == 4)
       return pBorderArray->GetArrayAt(3);
   }
@@ -341,7 +341,7 @@
 }
 
 ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) {
-  CPDF_Array* pDashArray = GetDashArray(pAnnotDict);
+  const CPDF_Array* pDashArray = GetDashArray(pAnnotDict);
   if (!pDashArray || pDashArray->IsEmpty())
     return ByteString();
 
@@ -907,11 +907,11 @@
 void CPVT_GenerateAP::GenerateFormAP(Type type,
                                      CPDF_Document* pDoc,
                                      CPDF_Dictionary* pAnnotDict) {
-  const CPDF_Dictionary* pRootDict = pDoc->GetRoot();
+  CPDF_Dictionary* pRootDict = pDoc->GetRoot();
   if (!pRootDict)
     return;
 
-  const CPDF_Dictionary* pFormDict = pRootDict->GetDictFor("AcroForm");
+  CPDF_Dictionary* pFormDict = pRootDict->GetDictFor("AcroForm");
   if (!pFormDict)
     return;
 
diff --git a/fpdfsdk/cpdfsdk_actionhandler.cpp b/fpdfsdk/cpdfsdk_actionhandler.cpp
index 660b09c..d7bcd7f 100644
--- a/fpdfsdk/cpdfsdk_actionhandler.cpp
+++ b/fpdfsdk/cpdfsdk_actionhandler.cpp
@@ -23,7 +23,7 @@
 bool CPDFSDK_ActionHandler::DoAction_DocOpen(
     const CPDF_Action& action,
     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteDocumentOpenAction(action, pFormFillEnv, &visited);
 }
 
@@ -64,7 +64,7 @@
     const CPDF_Action& action,
     enum CPDF_AAction::AActionType eType,
     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited);
 }
 
@@ -72,7 +72,7 @@
     const CPDF_Action& action,
     enum CPDF_AAction::AActionType eType,
     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited);
 }
 
@@ -81,7 +81,7 @@
     const CPDF_Action& action,
     CPDF_AAction::AActionType type,
     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteBookMark(action, pFormFillEnv, pBookMark, &visited);
 }
 
@@ -90,14 +90,14 @@
     CPDF_AAction::AActionType type,
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
     CPDFSDK_Annot* pScreen) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteScreenAction(action, type, pFormFillEnv, pScreen, &visited);
 }
 
 bool CPDFSDK_ActionHandler::DoAction_Link(
     const CPDF_Action& action,
     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteLinkAction(action, pFormFillEnv, &visited);
 }
 
@@ -107,7 +107,7 @@
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
     CPDF_FormField* pFormField,
     CPDFSDK_FieldAction* data) {
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return ExecuteFieldAction(action, type, pFormFillEnv, pFormField, data,
                             &visited);
 }
@@ -115,8 +115,8 @@
 bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
     const CPDF_Action& action,
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
-    std::set<CPDF_Dictionary*>* visited) {
-  CPDF_Dictionary* pDict = action.GetDict();
+    std::set<const CPDF_Dictionary*>* visited) {
+  const CPDF_Dictionary* pDict = action.GetDict();
   if (pdfium::ContainsKey(*visited, pDict))
     return false;
 
@@ -145,8 +145,8 @@
 bool CPDFSDK_ActionHandler::ExecuteLinkAction(
     const CPDF_Action& action,
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
-    std::set<CPDF_Dictionary*>* visited) {
-  CPDF_Dictionary* pDict = action.GetDict();
+    std::set<const CPDF_Dictionary*>* visited) {
+  const CPDF_Dictionary* pDict = action.GetDict();
   if (pdfium::ContainsKey(*visited, pDict))
     return false;
 
@@ -175,8 +175,8 @@
     const CPDF_Action& action,
     CPDF_AAction::AActionType type,
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
-    std::set<CPDF_Dictionary*>* visited) {
-  CPDF_Dictionary* pDict = action.GetDict();
+    std::set<const CPDF_Dictionary*>* visited) {
+  const CPDF_Dictionary* pDict = action.GetDict();
   if (pdfium::ContainsKey(*visited, pDict))
     return false;
 
@@ -220,8 +220,8 @@
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
     CPDF_FormField* pFormField,
     CPDFSDK_FieldAction* data,
-    std::set<CPDF_Dictionary*>* visited) {
-  CPDF_Dictionary* pDict = action.GetDict();
+    std::set<const CPDF_Dictionary*>* visited) {
+  const CPDF_Dictionary* pDict = action.GetDict();
   if (pdfium::ContainsKey(*visited, pDict))
     return false;
 
@@ -256,8 +256,8 @@
     CPDF_AAction::AActionType type,
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
     CPDFSDK_Annot* pScreen,
-    std::set<CPDF_Dictionary*>* visited) {
-  CPDF_Dictionary* pDict = action.GetDict();
+    std::set<const CPDF_Dictionary*>* visited) {
+  const CPDF_Dictionary* pDict = action.GetDict();
   if (pdfium::ContainsKey(*visited, pDict))
     return false;
 
@@ -282,8 +282,8 @@
     const CPDF_Action& action,
     CPDFSDK_FormFillEnvironment* pFormFillEnv,
     CPDF_Bookmark* pBookmark,
-    std::set<CPDF_Dictionary*>* visited) {
-  CPDF_Dictionary* pDict = action.GetDict();
+    std::set<const CPDF_Dictionary*>* visited) {
+  const CPDF_Dictionary* pDict = action.GetDict();
   if (pdfium::ContainsKey(*visited, pDict))
     return false;
 
diff --git a/fpdfsdk/cpdfsdk_actionhandler.h b/fpdfsdk/cpdfsdk_actionhandler.h
index 78d3e22..a144504 100644
--- a/fpdfsdk/cpdfsdk_actionhandler.h
+++ b/fpdfsdk/cpdfsdk_actionhandler.h
@@ -68,29 +68,29 @@
 
   bool ExecuteDocumentOpenAction(const CPDF_Action& action,
                                  CPDFSDK_FormFillEnvironment* pFormFillEnv,
-                                 std::set<CPDF_Dictionary*>* visited);
+                                 std::set<const CPDF_Dictionary*>* visited);
   bool ExecuteDocumentPageAction(const CPDF_Action& action,
                                  CPDF_AAction::AActionType type,
                                  CPDFSDK_FormFillEnvironment* pFormFillEnv,
-                                 std::set<CPDF_Dictionary*>* visited);
+                                 std::set<const CPDF_Dictionary*>* visited);
   bool ExecuteFieldAction(const CPDF_Action& action,
                           CPDF_AAction::AActionType type,
                           CPDFSDK_FormFillEnvironment* pFormFillEnv,
                           CPDF_FormField* pFormField,
                           CPDFSDK_FieldAction* data,
-                          std::set<CPDF_Dictionary*>* visited);
+                          std::set<const CPDF_Dictionary*>* visited);
   bool ExecuteScreenAction(const CPDF_Action& action,
                            CPDF_AAction::AActionType type,
                            CPDFSDK_FormFillEnvironment* pFormFillEnv,
                            CPDFSDK_Annot* pScreen,
-                           std::set<CPDF_Dictionary*>* visited);
+                           std::set<const CPDF_Dictionary*>* visited);
   bool ExecuteBookMark(const CPDF_Action& action,
                        CPDFSDK_FormFillEnvironment* pFormFillEnv,
                        CPDF_Bookmark* pBookmark,
-                       std::set<CPDF_Dictionary*>* visited);
+                       std::set<const CPDF_Dictionary*>* visited);
   bool ExecuteLinkAction(const CPDF_Action& action,
                          CPDFSDK_FormFillEnvironment* pFormFillEnv,
-                         std::set<CPDF_Dictionary*>* visited);
+                         std::set<const CPDF_Dictionary*>* visited);
 
   void DoAction_NoJs(const CPDF_Action& action,
                      CPDFSDK_FormFillEnvironment* pFormFillEnv);
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 87ba9e2..eb91bcf 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -224,14 +224,15 @@
       return;
     }
     if (pRootDict->KeyExist("Names")) {
-      CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names");
+      const CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names");
       if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) {
         RaiseUnSupportError(FPDF_UNSP_DOC_ATTACHMENT);
         return;
       }
       if (pNameDict && pNameDict->KeyExist("JavaScript")) {
-        CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript");
-        CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayFor("Names") : nullptr;
+        const CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript");
+        const CPDF_Array* pArray =
+            pJSDict ? pJSDict->GetArrayFor("Names") : nullptr;
         if (pArray) {
           for (size_t i = 0; i < pArray->GetCount(); i++) {
             ByteString cbStr = pArray->GetStringAt(i);
@@ -384,7 +385,12 @@
   return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top);
 }
 
-CPDF_Array* GetQuadPointsArrayFromDictionary(const CPDF_Dictionary* dict) {
+const CPDF_Array* GetQuadPointsArrayFromDictionary(
+    const CPDF_Dictionary* dict) {
+  return dict ? dict->GetArrayFor("QuadPoints") : nullptr;
+}
+
+CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) {
   return dict ? dict->GetArrayFor("QuadPoints") : nullptr;
 }
 
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index d93ecfc..10f44e4 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -64,11 +64,11 @@
 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
 
 // Conversions to/from incomplete FPDF_ API types.
-inline FPDF_ACTION FPDFActionFromCPDFDictionary(CPDF_Dictionary* action) {
+inline FPDF_ACTION FPDFActionFromCPDFDictionary(const CPDF_Dictionary* action) {
   return reinterpret_cast<FPDF_ACTION>(action);
 }
-inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
-  return reinterpret_cast<CPDF_Dictionary*>(action);
+inline const CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
+  return reinterpret_cast<const CPDF_Dictionary*>(action);
 }
 
 inline FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext(
@@ -94,11 +94,13 @@
   return reinterpret_cast<CFX_DIBitmap*>(bitmap);
 }
 
-inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(CPDF_Dictionary* bookmark) {
+inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(
+    const CPDF_Dictionary* bookmark) {
   return reinterpret_cast<FPDF_BOOKMARK>(bookmark);
 }
-inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
-  return reinterpret_cast<CPDF_Dictionary*>(bookmark);
+inline const CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(
+    FPDF_BOOKMARK bookmark) {
+  return reinterpret_cast<const CPDF_Dictionary*>(bookmark);
 }
 
 inline FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath* path) {
@@ -220,7 +222,8 @@
     FPDF_FILEHANDLER* pFileHandler);
 #endif  // PDF_ENABLE_XFA
 
-CPDF_Array* GetQuadPointsArrayFromDictionary(const CPDF_Dictionary* dict);
+const CPDF_Array* GetQuadPointsArrayFromDictionary(const CPDF_Dictionary* dict);
+CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict);
 CPDF_Array* AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict);
 bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index);
 bool GetQuadPointsAtIndex(const CPDF_Array* array,
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index b37562c..638b4df 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -412,7 +412,7 @@
   ASSERT(action.GetDict());
 
   CPDF_ActionFields af(&action);
-  std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
+  std::vector<const CPDF_Object*> fieldObjects = af.GetAllFields();
   std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
 
   bool bHide = action.GetHideStatus();
@@ -446,11 +446,11 @@
   if (sDestination.IsEmpty())
     return false;
 
-  CPDF_Dictionary* pActionDict = action.GetDict();
+  const CPDF_Dictionary* pActionDict = action.GetDict();
   if (pActionDict->KeyExist("Fields")) {
     CPDF_ActionFields af(&action);
     uint32_t dwFlags = action.GetFlags();
-    std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
+    std::vector<const CPDF_Object*> fieldObjects = af.GetAllFields();
     std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
     if (!fields.empty()) {
       bool bIncludeOrExclude = !(dwFlags & 0x01);
@@ -590,7 +590,7 @@
 void CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {
   ASSERT(action.GetDict());
 
-  CPDF_Dictionary* pActionDict = action.GetDict();
+  const CPDF_Dictionary* pActionDict = action.GetDict();
   if (!pActionDict->KeyExist("Fields")) {
     m_pInterForm->ResetForm(true);
     return;
@@ -599,15 +599,15 @@
   CPDF_ActionFields af(&action);
   uint32_t dwFlags = action.GetFlags();
 
-  std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
+  std::vector<const CPDF_Object*> fieldObjects = af.GetAllFields();
   std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
   m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true);
 }
 
 std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects(
-    const std::vector<CPDF_Object*>& objects) const {
+    const std::vector<const CPDF_Object*>& objects) const {
   std::vector<CPDF_FormField*> fields;
-  for (CPDF_Object* pObject : objects) {
+  for (const CPDF_Object* pObject : objects) {
     if (!pObject || !pObject->IsString())
       continue;
 
diff --git a/fpdfsdk/cpdfsdk_interform.h b/fpdfsdk/cpdfsdk_interform.h
index 6195ee9..bb6d7fc 100644
--- a/fpdfsdk/cpdfsdk_interform.h
+++ b/fpdfsdk/cpdfsdk_interform.h
@@ -80,7 +80,7 @@
   void DoAction_ResetForm(const CPDF_Action& action);
 
   std::vector<CPDF_FormField*> GetFieldFromObjects(
-      const std::vector<CPDF_Object*>& objects) const;
+      const std::vector<const CPDF_Object*>& objects) const;
   bool IsValidField(CPDF_Dictionary* pFieldDict);
   bool SubmitFields(const WideString& csDestination,
                     const std::vector<CPDF_FormField*>& fields,
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp
index 3bb89fc..6b62227 100644
--- a/fpdfsdk/fpdf_doc.cpp
+++ b/fpdfsdk/fpdf_doc.cpp
@@ -26,7 +26,7 @@
 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree,
                            CPDF_Bookmark bookmark,
                            const WideString& title,
-                           std::set<CPDF_Dictionary*>* visited) {
+                           std::set<const CPDF_Dictionary*>* visited) {
   // Return if already checked to avoid circular calling.
   if (pdfium::ContainsKey(*visited, bookmark.GetDict()))
     return CPDF_Bookmark();
@@ -107,7 +107,7 @@
   CPDF_BookmarkTree tree(pDoc);
   size_t len = WideString::WStringLength(title);
   WideString encodedTitle = WideString::FromUTF16LE(title, len);
-  std::set<CPDF_Dictionary*> visited;
+  std::set<const CPDF_Dictionary*> visited;
   return FPDFBookmarkFromCPDFDictionary(
       FindBookmark(tree, CPDF_Bookmark(), encodedTitle, &visited).GetDict());
 }
diff --git a/public/fpdfview.h b/public/fpdfview.h
index 66813d8..a3017b4 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -35,11 +35,11 @@
 #define FPDF_OBJECT_REFERENCE 9
 
 // PDF types - use incomplete types for type safety.
-typedef struct fpdf_action_t__* FPDF_ACTION;
+typedef const struct fpdf_action_t__* FPDF_ACTION;
 typedef struct fpdf_annotation_t__* FPDF_ANNOTATION;
 typedef struct fpdf_attachment_t__* FPDF_ATTACHMENT;
 typedef struct fpdf_bitmap_t__* FPDF_BITMAP;
-typedef struct fpdf_bookmark_t__* FPDF_BOOKMARK;
+typedef const struct fpdf_bookmark_t__* FPDF_BOOKMARK;
 typedef struct fpdf_clippath_t__* FPDF_CLIPPATH;
 typedef struct fpdf_dest_t__* FPDF_DEST;
 typedef struct fpdf_document_t__* FPDF_DOCUMENT;