UnownedPtrs<> should ideally be const, part 1.

Mutating an object through an unowned reference is an anti-pattern
which abounds in PDFium. Make some of the easy-to-fix cases const.

Change-Id: I58aaac77d51073c10988728dacf60ea058fa1a29
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79730
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h
index eee1257..22745f0 100644
--- a/core/fpdfapi/page/cpdf_colorspace.h
+++ b/core/fpdfapi/page/cpdf_colorspace.h
@@ -75,7 +75,7 @@
   static bool IsValidIccComponents(int components);
 
   const CPDF_Array* GetArray() const { return m_pArray.Get(); }
-  CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
+  const CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
 
   // Should only be called if this colorspace is not a pattern.
   std::vector<float> CreateBufAndSetDefaultColor() const;
@@ -128,7 +128,7 @@
   // components count.
   void SetComponentsForStockCS(uint32_t nComponents);
 
-  UnownedPtr<CPDF_Document> const m_pDocument;
+  UnownedPtr<const CPDF_Document> const m_pDocument;
   RetainPtr<const CPDF_Array> m_pArray;
   const int m_Family;
   uint32_t m_dwStdConversion = 0;
diff --git a/core/fpdfapi/page/cpdf_textstate.h b/core/fpdfapi/page/cpdf_textstate.h
index a9e968e..f51d8f0 100644
--- a/core/fpdfapi/page/cpdf_textstate.h
+++ b/core/fpdfapi/page/cpdf_textstate.h
@@ -70,7 +70,7 @@
     float GetFontSizeH() const;
 
     RetainPtr<CPDF_Font> m_pFont;
-    UnownedPtr<CPDF_Document> m_pDocument;
+    UnownedPtr<const CPDF_Document> m_pDocument;
     float m_FontSize = 1.0f;
     float m_CharSpace = 0.0f;
     float m_WordSpace = 0.0f;
diff --git a/core/fpdfapi/page/cpdf_transferfunc.cpp b/core/fpdfapi/page/cpdf_transferfunc.cpp
index 86184a9..15d77d5 100644
--- a/core/fpdfapi/page/cpdf_transferfunc.cpp
+++ b/core/fpdfapi/page/cpdf_transferfunc.cpp
@@ -14,7 +14,7 @@
 #include "third_party/base/check_op.h"
 
 CPDF_TransferFunc::CPDF_TransferFunc(
-    CPDF_Document* pDoc,
+    const CPDF_Document* pDoc,
     bool bIdentify,
     std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r,
     std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g,
diff --git a/core/fpdfapi/page/cpdf_transferfunc.h b/core/fpdfapi/page/cpdf_transferfunc.h
index 4cb69b5..28dd6c1 100644
--- a/core/fpdfapi/page/cpdf_transferfunc.h
+++ b/core/fpdfapi/page/cpdf_transferfunc.h
@@ -38,14 +38,14 @@
   bool GetIdentity() const { return m_bIdentity; }
 
  private:
-  CPDF_TransferFunc(CPDF_Document* pDoc,
+  CPDF_TransferFunc(const CPDF_Document* pDoc,
                     bool bIdentify,
                     std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r,
                     std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g,
                     std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_b);
   ~CPDF_TransferFunc() override;
 
-  UnownedPtr<CPDF_Document> const m_pPDFDoc;
+  UnownedPtr<const CPDF_Document> const m_pPDFDoc;
   const bool m_bIdentity;
   const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesR;
   const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesG;
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
index 2c32805..2a0fe42 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
@@ -49,7 +49,7 @@
                                     uint32_t gennum,
                                     pdfium::span<const uint8_t> source,
                                     uint8_t* dest_buf,
-                                    uint32_t& dest_size) {
+                                    uint32_t& dest_size) const {
   if (m_Cipher == FXCIPHER_NONE) {
     memcpy(dest_buf, source.data(), source.size());
     return;
@@ -374,7 +374,7 @@
                                         uint32_t gennum,
                                         pdfium::span<const uint8_t> source,
                                         uint8_t* dest_buf,
-                                        uint32_t& dest_size) {
+                                        uint32_t& dest_size) const {
   CryptBlock(true, objnum, gennum, source, dest_buf, dest_size);
   return true;
 }
@@ -399,7 +399,7 @@
 
 void CPDF_CryptoHandler::PopulateKey(uint32_t objnum,
                                      uint32_t gennum,
-                                     uint8_t* key) {
+                                     uint8_t* key) const {
   memcpy(key, m_EncryptKey, m_KeyLen);
   key[m_KeyLen + 0] = (uint8_t)objnum;
   key[m_KeyLen + 1] = (uint8_t)(objnum >> 8);
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.h b/core/fpdfapi/parser/cpdf_crypto_handler.h
index a816058..47b278a 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.h
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.h
@@ -34,7 +34,7 @@
                       uint32_t gennum,
                       pdfium::span<const uint8_t> source,
                       uint8_t* dest_buf,
-                      uint32_t& dest_size);
+                      uint32_t& dest_size) const;
 
   bool IsCipherAES() const;
 
@@ -47,13 +47,13 @@
                      CFX_BinaryBuf& dest_buf);
   bool DecryptFinish(void* context, CFX_BinaryBuf& dest_buf);
 
-  void PopulateKey(uint32_t objnum, uint32_t gennum, uint8_t* key);
+  void PopulateKey(uint32_t objnum, uint32_t gennum, uint8_t* key) const;
   void CryptBlock(bool bEncrypt,
                   uint32_t objnum,
                   uint32_t gennum,
                   pdfium::span<const uint8_t> source,
                   uint8_t* dest_buf,
-                  uint32_t& dest_size);
+                  uint32_t& dest_size) const;
   void* CryptStart(uint32_t objnum, uint32_t gennum, bool bEncrypt);
   bool CryptStream(void* context,
                    pdfium::span<const uint8_t> source,
diff --git a/core/fpdfapi/parser/cpdf_encryptor.cpp b/core/fpdfapi/parser/cpdf_encryptor.cpp
index d8193d9..8895e5b 100644
--- a/core/fpdfapi/parser/cpdf_encryptor.cpp
+++ b/core/fpdfapi/parser/cpdf_encryptor.cpp
@@ -9,7 +9,7 @@
 #include "core/fpdfapi/parser/cpdf_crypto_handler.h"
 #include "third_party/base/check.h"
 
-CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler, int objnum)
+CPDF_Encryptor::CPDF_Encryptor(const CPDF_CryptoHandler* pHandler, int objnum)
     : m_pHandler(pHandler), m_ObjNum(objnum) {
   DCHECK(m_pHandler);
 }
diff --git a/core/fpdfapi/parser/cpdf_encryptor.h b/core/fpdfapi/parser/cpdf_encryptor.h
index d23af8a..bdb6245 100644
--- a/core/fpdfapi/parser/cpdf_encryptor.h
+++ b/core/fpdfapi/parser/cpdf_encryptor.h
@@ -19,14 +19,14 @@
 
 class CPDF_Encryptor {
  public:
-  CPDF_Encryptor(CPDF_CryptoHandler* pHandler, int objnum);
+  CPDF_Encryptor(const CPDF_CryptoHandler* pHandler, int objnum);
   ~CPDF_Encryptor();
 
   std::vector<uint8_t, FxAllocAllocator<uint8_t>> Encrypt(
       pdfium::span<const uint8_t> src_data) const;
 
  private:
-  UnownedPtr<CPDF_CryptoHandler> const m_pHandler;
+  UnownedPtr<const CPDF_CryptoHandler> const m_pHandler;
   const int m_ObjNum;
 };
 
diff --git a/core/fpdfapi/render/cpdf_imageloader.cpp b/core/fpdfapi/render/cpdf_imageloader.cpp
index 0609776..bb198e7 100644
--- a/core/fpdfapi/render/cpdf_imageloader.cpp
+++ b/core/fpdfapi/render/cpdf_imageloader.cpp
@@ -21,7 +21,7 @@
 
 CPDF_ImageLoader::~CPDF_ImageLoader() = default;
 
-bool CPDF_ImageLoader::Start(CPDF_ImageObject* pImage,
+bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
                              const CPDF_RenderStatus* pRenderStatus,
                              bool bStdCS) {
   m_pCache = pRenderStatus->GetContext()->GetPageCache();
diff --git a/core/fpdfapi/render/cpdf_imageloader.h b/core/fpdfapi/render/cpdf_imageloader.h
index d3de6c3..aa8b885 100644
--- a/core/fpdfapi/render/cpdf_imageloader.h
+++ b/core/fpdfapi/render/cpdf_imageloader.h
@@ -22,7 +22,7 @@
   CPDF_ImageLoader();
   ~CPDF_ImageLoader();
 
-  bool Start(CPDF_ImageObject* pImage,
+  bool Start(const CPDF_ImageObject* pImage,
              const CPDF_RenderStatus* pRenderStatus,
              bool bStdCS);
   bool Continue(PauseIndicatorIface* pPause, CPDF_RenderStatus* pRenderStatus);
@@ -42,7 +42,7 @@
   RetainPtr<CFX_DIBBase> m_pBitmap;
   RetainPtr<CFX_DIBBase> m_pMask;
   UnownedPtr<CPDF_PageRenderCache> m_pCache;
-  UnownedPtr<CPDF_ImageObject> m_pImageObject;
+  UnownedPtr<const CPDF_ImageObject> m_pImageObject;
 };
 
 #endif  // CORE_FPDFAPI_RENDER_CPDF_IMAGELOADER_H_
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 7b38765..46296ef 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -187,7 +187,7 @@
   CPDF_RenderOptions m_Options;
   RetainPtr<const CPDF_Dictionary> m_pFormResource;
   RetainPtr<CPDF_Dictionary> m_pPageResource;
-  std::vector<UnownedPtr<CPDF_Type3Font>> m_Type3FontCache;
+  std::vector<UnownedPtr<const CPDF_Type3Font>> m_Type3FontCache;
   UnownedPtr<CPDF_RenderContext> const m_pContext;
   UnownedPtr<CFX_RenderDevice> const m_pDevice;
   CFX_Matrix m_DeviceMatrix;
@@ -196,6 +196,7 @@
   UnownedPtr<const CPDF_PageObject> m_pStopObj;
   CPDF_GraphicStates m_InitialStates;
   std::unique_ptr<CPDF_ImageRenderer> m_pImageRenderer;
+  UnownedPtr<const CPDF_Type3Char> m_pType3Char;
   CPDF_Transparency m_Transparency;
   bool m_bStopped = false;
   bool m_bPrint = false;
@@ -203,7 +204,6 @@
   bool m_bStdCS = false;
   bool m_bLoadMask = false;
   uint32_t m_GroupFamily = 0;
-  UnownedPtr<CPDF_Type3Char> m_pType3Char;
   FX_ARGB m_T3FillColor = 0;
   BlendMode m_curBlend = BlendMode::kNormal;
 };
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp
index 175e925..b92f9bd 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.cpp
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -9,7 +9,8 @@
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
 
-CPDF_BookmarkTree::CPDF_BookmarkTree(CPDF_Document* doc) : document_(doc) {}
+CPDF_BookmarkTree::CPDF_BookmarkTree(const CPDF_Document* doc)
+    : document_(doc) {}
 
 CPDF_BookmarkTree::~CPDF_BookmarkTree() = default;
 
diff --git a/core/fpdfdoc/cpdf_bookmarktree.h b/core/fpdfdoc/cpdf_bookmarktree.h
index 6cadbb7..ba2d523 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.h
+++ b/core/fpdfdoc/cpdf_bookmarktree.h
@@ -14,14 +14,14 @@
 
 class CPDF_BookmarkTree {
  public:
-  explicit CPDF_BookmarkTree(CPDF_Document* doc);
+  explicit CPDF_BookmarkTree(const CPDF_Document* doc);
   ~CPDF_BookmarkTree();
 
   CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const;
   CPDF_Bookmark GetNextSibling(const CPDF_Bookmark& bookmark) const;
 
  private:
-  UnownedPtr<CPDF_Document> const document_;
+  UnownedPtr<const CPDF_Document> const document_;
 };
 
 #endif  // CORE_FPDFDOC_CPDF_BOOKMARKTREE_H_
diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp
index 7040c6c..040e6fd 100644
--- a/core/fpdfdoc/cpdf_structelement.cpp
+++ b/core/fpdfdoc/cpdf_structelement.cpp
@@ -39,8 +39,8 @@
 
 CPDF_StructKid::~CPDF_StructKid() = default;
 
-CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree,
-                                       CPDF_StructElement* pParent,
+CPDF_StructElement::CPDF_StructElement(const CPDF_StructTree* pTree,
+                                       const CPDF_StructElement* pParent,
                                        const CPDF_Dictionary* pDict)
     : m_pTree(pTree),
       m_pParent(pParent),
diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h
index eecaeaa..f1fa94a 100644
--- a/core/fpdfdoc/cpdf_structelement.h
+++ b/core/fpdfdoc/cpdf_structelement.h
@@ -50,8 +50,8 @@
   std::vector<CPDF_StructKid>* GetKids() { return &m_Kids; }
 
  private:
-  CPDF_StructElement(CPDF_StructTree* pTree,
-                     CPDF_StructElement* pParent,
+  CPDF_StructElement(const CPDF_StructTree* pTree,
+                     const CPDF_StructElement* pParent,
                      const CPDF_Dictionary* pDict);
   ~CPDF_StructElement() override;
 
@@ -60,8 +60,8 @@
                const CPDF_Object* pKidObj,
                CPDF_StructKid* pKid);
 
-  UnownedPtr<CPDF_StructTree> const m_pTree;
-  UnownedPtr<CPDF_StructElement> const m_pParent;
+  UnownedPtr<const CPDF_StructTree> const m_pTree;
+  UnownedPtr<const CPDF_StructElement> const m_pParent;
   RetainPtr<const CPDF_Dictionary> const m_pDict;
   const ByteString m_Type;
   std::vector<CPDF_StructKid> m_Kids;
diff --git a/core/fpdfdoc/cpvt_variabletext.cpp b/core/fpdfdoc/cpvt_variabletext.cpp
index f658a17..20beaff1 100644
--- a/core/fpdfdoc/cpvt_variabletext.cpp
+++ b/core/fpdfdoc/cpvt_variabletext.cpp
@@ -572,7 +572,7 @@
   return m_rcPlate;
 }
 
-float CPVT_VariableText::GetWordFontSize() {
+float CPVT_VariableText::GetWordFontSize() const {
   return GetFontSize();
 }
 
@@ -581,12 +581,12 @@
                                       uint16_t SubWord,
                                       float fCharSpace,
                                       float fFontSize,
-                                      float fWordTail) {
+                                      float fWordTail) const {
   return GetCharWidth(nFontIndex, Word, SubWord) * fFontSize * kFontScale +
          fCharSpace + fWordTail;
 }
 
-float CPVT_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) {
+float CPVT_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) const {
   return GetWordWidth(WordInfo.nFontIndex, WordInfo.Word, GetSubWord(),
                       GetCharSpace(), GetWordFontSize(), WordInfo.fWordTail);
 }
@@ -599,31 +599,33 @@
   return GetFontDescent(GetDefaultFontIndex(), GetFontSize());
 }
 
-float CPVT_VariableText::GetFontAscent(int32_t nFontIndex, float fFontSize) {
+float CPVT_VariableText::GetFontAscent(int32_t nFontIndex,
+                                       float fFontSize) const {
   float ascent = m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0;
   return ascent * fFontSize * kFontScale;
 }
 
-float CPVT_VariableText::GetFontDescent(int32_t nFontIndex, float fFontSize) {
+float CPVT_VariableText::GetFontDescent(int32_t nFontIndex,
+                                        float fFontSize) const {
   float descent = m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0;
   return descent * fFontSize * kFontScale;
 }
 
 float CPVT_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo,
-                                       float fFontSize) {
+                                       float fFontSize) const {
   return GetFontAscent(WordInfo.nFontIndex, fFontSize);
 }
 
 float CPVT_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo,
-                                        float fFontSize) {
+                                        float fFontSize) const {
   return GetFontDescent(WordInfo.nFontIndex, fFontSize);
 }
 
-float CPVT_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo) {
+float CPVT_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo) const {
   return GetFontAscent(WordInfo.nFontIndex, GetWordFontSize());
 }
 
-float CPVT_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo) {
+float CPVT_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo) const {
   return GetFontDescent(WordInfo.nFontIndex, GetWordFontSize());
 }
 
@@ -838,7 +840,7 @@
 
 int CPVT_VariableText::GetCharWidth(int32_t nFontIndex,
                                     uint16_t Word,
-                                    uint16_t SubWord) {
+                                    uint16_t SubWord) const {
   if (!m_pVTProvider)
     return 0;
   uint16_t word = SubWord ? SubWord : Word;
diff --git a/core/fpdfdoc/cpvt_variabletext.h b/core/fpdfdoc/cpvt_variabletext.h
index db9675b..70d3f51 100644
--- a/core/fpdfdoc/cpvt_variabletext.h
+++ b/core/fpdfdoc/cpvt_variabletext.h
@@ -44,7 +44,7 @@
 
    private:
     CPVT_WordPlace m_CurPos;
-    UnownedPtr<CPVT_VariableText> const m_pVT;
+    UnownedPtr<const CPVT_VariableText> const m_pVT;
   };
 
   class Provider {
@@ -141,28 +141,28 @@
   CFX_FloatRect InToOut(const CPVT_FloatRect& rect) const;
   CPVT_FloatRect OutToIn(const CFX_FloatRect& rect) const;
 
-  float GetFontAscent(int32_t nFontIndex, float fFontSize);
-  float GetFontDescent(int32_t nFontIndex, float fFontSize);
+  float GetFontAscent(int32_t nFontIndex, float fFontSize) const;
+  float GetFontDescent(int32_t nFontIndex, float fFontSize) const;
   int32_t GetDefaultFontIndex();
   float GetLineLeading();
   int32_t GetAlignment();
-  float GetWordWidth(const CPVT_WordInfo& WordInfo);
+  float GetWordWidth(const CPVT_WordInfo& WordInfo) const;
   float GetWordWidth(int32_t nFontIndex,
                      uint16_t Word,
                      uint16_t SubWord,
                      float fCharSpace,
                      float fFontSize,
-                     float fWordTail);
-  float GetWordAscent(const CPVT_WordInfo& WordInfo);
-  float GetWordDescent(const CPVT_WordInfo& WordInfo);
-  float GetWordAscent(const CPVT_WordInfo& WordInfo, float fFontSize);
-  float GetWordDescent(const CPVT_WordInfo& WordInfo, float fFontSize);
+                     float fWordTail) const;
+  float GetWordAscent(const CPVT_WordInfo& WordInfo) const;
+  float GetWordDescent(const CPVT_WordInfo& WordInfo) const;
+  float GetWordAscent(const CPVT_WordInfo& WordInfo, float fFontSize) const;
+  float GetWordDescent(const CPVT_WordInfo& WordInfo, float fFontSize) const;
   float GetLineAscent();
   float GetLineDescent();
   float GetLineIndent();
 
  private:
-  int GetCharWidth(int32_t nFontIndex, uint16_t Word, uint16_t SubWord);
+  int GetCharWidth(int32_t nFontIndex, uint16_t Word, uint16_t SubWord) const;
   int32_t GetWordFontIndex(uint16_t word, int32_t charset, int32_t nFontIndex);
 
   CPVT_WordPlace AddSection(const CPVT_WordPlace& place);
@@ -170,7 +170,7 @@
                          const CPVT_LineInfo& lineinfo);
   CPVT_WordPlace AddWord(const CPVT_WordPlace& place,
                          const CPVT_WordInfo& wordinfo);
-  float GetWordFontSize();
+  float GetWordFontSize() const;
 
   void ClearSectionRightWords(const CPVT_WordPlace& place);
 
@@ -198,8 +198,8 @@
   float m_fCharSpace = 0.0f;
   float m_fFontSize = 0.0f;
   std::vector<std::unique_ptr<CPVT_Section>> m_SectionArray;
-  UnownedPtr<CPVT_VariableText::Provider> m_pVTProvider;
-  std::unique_ptr<CPVT_VariableText::Iterator> m_pVTIterator;
+  UnownedPtr<Provider> m_pVTProvider;
+  std::unique_ptr<Iterator> m_pVTIterator;
   CFX_FloatRect m_rcPlate;
   CPVT_FloatRect m_rcContent;
 };
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index 2f5038d..7d20a55 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -54,7 +54,7 @@
 
 }  // namespace
 
-CFX_BmpDecompressor::CFX_BmpDecompressor(CFX_BmpContext* context)
+CFX_BmpDecompressor::CFX_BmpDecompressor(const CFX_BmpContext* context)
     : context_(context) {}
 
 CFX_BmpDecompressor::~CFX_BmpDecompressor() = default;
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.h b/core/fxcodec/bmp/cfx_bmpdecompressor.h
index e85c805..7e39d33 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.h
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.h
@@ -23,7 +23,7 @@
 
 class CFX_BmpDecompressor {
  public:
-  explicit CFX_BmpDecompressor(CFX_BmpContext* context);
+  explicit CFX_BmpDecompressor(const CFX_BmpContext* context);
   ~CFX_BmpDecompressor();
 
   BmpDecoder::Status DecodeImage();
@@ -65,7 +65,7 @@
   bool ValidateFlag() const;
   bool SetHeight(int32_t signed_height);
 
-  UnownedPtr<CFX_BmpContext> const context_;
+  UnownedPtr<const CFX_BmpContext> const context_;
   std::vector<uint8_t, FxAllocAllocator<uint8_t>> out_row_buffer_;
   std::vector<uint32_t> palette_;
   uint32_t header_offset_ = 0;
diff --git a/core/fxge/cfx_unicodeencoding.cpp b/core/fxge/cfx_unicodeencoding.cpp
index d87b0b6..2e07cc1 100644
--- a/core/fxge/cfx_unicodeencoding.cpp
+++ b/core/fxge/cfx_unicodeencoding.cpp
@@ -12,7 +12,8 @@
 #include "core/fxge/fx_font.h"
 #include "core/fxge/fx_freetype.h"
 
-CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) {}
+CFX_UnicodeEncoding::CFX_UnicodeEncoding(const CFX_Font* pFont)
+    : m_pFont(pFont) {}
 
 CFX_UnicodeEncoding::~CFX_UnicodeEncoding() = default;
 
diff --git a/core/fxge/cfx_unicodeencoding.h b/core/fxge/cfx_unicodeencoding.h
index a730dc9..57e2c19 100644
--- a/core/fxge/cfx_unicodeencoding.h
+++ b/core/fxge/cfx_unicodeencoding.h
@@ -15,13 +15,13 @@
 
 class CFX_UnicodeEncoding {
  public:
-  explicit CFX_UnicodeEncoding(CFX_Font* pFont);
+  explicit CFX_UnicodeEncoding(const CFX_Font* pFont);
   virtual ~CFX_UnicodeEncoding();
 
   virtual uint32_t GlyphFromCharCode(uint32_t charcode);
 
  protected:
-  UnownedPtr<CFX_Font> const m_pFont;
+  UnownedPtr<const CFX_Font> const m_pFont;
 };
 
 #endif  // CORE_FXGE_CFX_UNICODEENCODING_H_
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 1520b46..6affdae 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -33,7 +33,7 @@
 
 class CPWL_MsgControl final : public Observable {
  public:
-  explicit CPWL_MsgControl(CPWL_Wnd* pWnd) : m_pCreatedWnd(pWnd) {}
+  explicit CPWL_MsgControl(const CPWL_Wnd* pWnd) : m_pCreatedWnd(pWnd) {}
   ~CPWL_MsgControl() = default;
 
   bool IsWndCreated(const CPWL_Wnd* pWnd) const {
@@ -91,13 +91,13 @@
 
   void ReleaseCapture() { m_MousePaths.clear(); }
 
-  CPWL_Wnd* GetFocusedWindow() const { return m_pMainKeyboardWnd.Get(); }
+  const CPWL_Wnd* GetFocusedWindow() const { return m_pMainKeyboardWnd.Get(); }
 
  private:
   std::vector<UnownedPtr<CPWL_Wnd>> m_MousePaths;
   std::vector<UnownedPtr<CPWL_Wnd>> m_KeyboardPaths;
-  UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
-  UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
+  UnownedPtr<const CPWL_Wnd> m_pCreatedWnd;
+  UnownedPtr<const CPWL_Wnd> m_pMainKeyboardWnd;
 };
 
 // static