Return retained object from CPDF_FormControl::GetWidgetDict()

-- Renamed method from GetWidget() for clarity.
-- Avoid assignment in conditional.

Change-Id: Ib4182ace67488b2f4d334e3c097a3224dc0ee720
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/99090
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_formcontrol.h b/core/fpdfdoc/cpdf_formcontrol.h
index e6a0f15..6f276a0 100644
--- a/core/fpdfdoc/cpdf_formcontrol.h
+++ b/core/fpdfdoc/cpdf_formcontrol.h
@@ -41,7 +41,9 @@
 
   CPDF_FormField::Type GetType() const { return m_pField->GetType(); }
   CPDF_FormField* GetField() const { return m_pField.Get(); }
-  const CPDF_Dictionary* GetWidget() const { return m_pWidgetDict.Get(); }
+  RetainPtr<const CPDF_Dictionary> GetWidgetDict() const {
+    return m_pWidgetDict;
+  }
   CFX_FloatRect GetRect() const;
 
   ByteString GetCheckedAPState() const;
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 7a0554d..8d5fec6 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -405,7 +405,7 @@
     if (!pControl)
       continue;
 
-    const CPDF_Dictionary* pWidgetDict = pControl->GetWidget();
+    RetainPtr<const CPDF_Dictionary> pWidgetDict = pControl->GetWidgetDict();
     if (pWidgetDict->KeyExist("MaxLen"))
       return pWidgetDict->GetIntegerFor("MaxLen");
   }
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp
index 0d19f1c..091a019 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.cpp
+++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -129,12 +129,11 @@
   if (pWidget)
     return pWidget;
 
-  const CPDF_Dictionary* pControlDict = pControl->GetWidget();
   CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
   CPDFSDK_PageView* pPage = nullptr;
-
-  if (RetainPtr<const CPDF_Dictionary> pPageDict =
-          pControlDict->GetDictFor("P")) {
+  RetainPtr<const CPDF_Dictionary> pControlDict = pControl->GetWidgetDict();
+  RetainPtr<const CPDF_Dictionary> pPageDict = pControlDict->GetDictFor("P");
+  if (pPageDict) {
     int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
     if (nPageIndex >= 0)
       pPage = m_pFormFillEnv->GetPageViewAtIndex(nPageIndex);