Convert IPDFSDK_AnnotHandler::NewAnnot() to return std::unique_ptr.
Also rename its CPDFSDK_PageView* parameter from |pPage| to |pPageView|.
Change-Id: I5472aa50846bf27a9458cdf0c68435f7b445e96b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66394
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 2a45b0d..8bdbfc9 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -50,8 +50,9 @@
m_pXFAWidgetHandler->SetFormFillEnvironment(pFormFillEnv);
}
-CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
- CPDFSDK_PageView* pPageView) {
+std::unique_ptr<CPDFSDK_Annot> CPDFSDK_AnnotHandlerMgr::NewAnnot(
+ CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) {
ASSERT(pPageView);
return GetAnnotHandlerOfType(pAnnot->GetSubtype())
->NewAnnot(pAnnot, pPageView);
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.h b/fpdfsdk/cpdfsdk_annothandlermgr.h
index b88f613..cc3f715 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.h
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.h
@@ -36,7 +36,8 @@
void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
- CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
+ std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView);
#ifdef PDF_ENABLE_XFA
std::unique_ptr<CPDFSDK_Annot> NewXFAAnnot(CXFA_FFWidget* pAnnot,
CPDFSDK_PageView* pPageView);
diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp
index 6aa6de7..d83dfba 100644
--- a/fpdfsdk/cpdfsdk_baannothandler.cpp
+++ b/fpdfsdk/cpdfsdk_baannothandler.cpp
@@ -47,9 +47,10 @@
return false;
}
-CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
- CPDFSDK_PageView* pPage) {
- return new CPDFSDK_BAAnnot(pAnnot, pPage);
+std::unique_ptr<CPDFSDK_Annot> CPDFSDK_BAAnnotHandler::NewAnnot(
+ CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) {
+ return pdfium::MakeUnique<CPDFSDK_BAAnnot>(pAnnot, pPageView);
}
void CPDFSDK_BAAnnotHandler::ReleaseAnnot(
diff --git a/fpdfsdk/cpdfsdk_baannothandler.h b/fpdfsdk/cpdfsdk_baannothandler.h
index 295bf0d..22607bf 100644
--- a/fpdfsdk/cpdfsdk_baannothandler.h
+++ b/fpdfsdk/cpdfsdk_baannothandler.h
@@ -29,7 +29,8 @@
void SetFormFillEnvironment(
CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
bool CanAnswer(CPDFSDK_Annot* pAnnot) override;
- CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override;
+ std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) override;
void ReleaseAnnot(std::unique_ptr<CPDFSDK_Annot> pAnnot) override;
CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot) override;
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 9e4adc8..732bd49 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -512,11 +512,12 @@
for (size_t i = 0; i < nCount; ++i) {
CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
CheckForUnsupportedAnnot(pPDFAnnot);
- CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
+ std::unique_ptr<CPDFSDK_Annot> pAnnot =
+ pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
if (!pAnnot)
continue;
- m_SDKAnnotArray.push_back(pAnnot);
- pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
+ m_SDKAnnotArray.push_back(pAnnot.release());
+ pAnnotHandlerMgr->Annot_OnLoad(m_SDKAnnotArray.back());
}
}
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index 54ddfd9..f62f125 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -52,16 +52,17 @@
(dwPermissions & pdfium::access_permissions::kModifyAnnotation);
}
-CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot,
- CPDFSDK_PageView* pPage) {
+std::unique_ptr<CPDFSDK_Annot> CPDFSDK_WidgetHandler::NewAnnot(
+ CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) {
CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm();
CPDF_FormControl* pCtrl = pPDFForm->GetControlByDict(pAnnot->GetAnnotDict());
if (!pCtrl)
return nullptr;
- CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pForm);
- pForm->AddMap(pCtrl, pWidget);
+ auto pWidget = pdfium::MakeUnique<CPDFSDK_Widget>(pAnnot, pPageView, pForm);
+ pForm->AddMap(pCtrl, pWidget.get());
if (pPDFForm->NeedConstructAP())
pWidget->ResetAppearance(pdfium::nullopt, false);
return pWidget;
diff --git a/fpdfsdk/cpdfsdk_widgethandler.h b/fpdfsdk/cpdfsdk_widgethandler.h
index fa2ac94..a1fb781 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.h
+++ b/fpdfsdk/cpdfsdk_widgethandler.h
@@ -29,7 +29,8 @@
void SetFormFillEnvironment(
CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
bool CanAnswer(CPDFSDK_Annot* pAnnot) override;
- CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override;
+ std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) override;
void ReleaseAnnot(std::unique_ptr<CPDFSDK_Annot> pAnnot) override;
CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot) override;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
index 3012b0d..84f2959 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
@@ -214,16 +214,17 @@
return pWidget && pWidget->GetXFAFFWidget();
}
-CPDFSDK_Annot* CPDFXFA_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot,
- CPDFSDK_PageView* pPage) {
+std::unique_ptr<CPDFSDK_Annot> CPDFXFA_WidgetHandler::NewAnnot(
+ CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) {
return nullptr;
}
std::unique_ptr<CPDFSDK_Annot> CPDFXFA_WidgetHandler::NewAnnotForXFA(
CXFA_FFWidget* pAnnot,
- CPDFSDK_PageView* pPage) {
+ CPDFSDK_PageView* pPageView) {
CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
- return pdfium::MakeUnique<CPDFXFA_Widget>(pAnnot, pPage, pForm);
+ return pdfium::MakeUnique<CPDFXFA_Widget>(pAnnot, pPageView, pForm);
}
void CPDFXFA_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView,
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h
index e18e0ca..9f066c5 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h
@@ -31,7 +31,8 @@
void SetFormFillEnvironment(
CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
bool CanAnswer(CPDFSDK_Annot* pAnnot) override;
- CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override;
+ std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) override;
void ReleaseAnnot(std::unique_ptr<CPDFSDK_Annot> pAnnot) override;
CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot) override;
@@ -101,7 +102,7 @@
bool IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, int index) override;
std::unique_ptr<CPDFSDK_Annot> NewAnnotForXFA(CXFA_FFWidget* pAnnot,
- CPDFSDK_PageView* pPage);
+ CPDFSDK_PageView* pPageView);
bool OnXFAChangedFocus(ObservedPtr<CPDFSDK_Annot>* pOldAnnot,
ObservedPtr<CPDFSDK_Annot>* pNewAnnot);
diff --git a/fpdfsdk/ipdfsdk_annothandler.h b/fpdfsdk/ipdfsdk_annothandler.h
index 24b6ff0..d650d25 100644
--- a/fpdfsdk/ipdfsdk_annothandler.h
+++ b/fpdfsdk/ipdfsdk_annothandler.h
@@ -25,8 +25,9 @@
virtual void SetFormFillEnvironment(
CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
virtual bool CanAnswer(CPDFSDK_Annot* pAnnot) = 0;
- virtual CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot,
- CPDFSDK_PageView* pPage) = 0;
+ virtual std::unique_ptr<CPDFSDK_Annot> NewAnnot(
+ CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPageView) = 0;
virtual void ReleaseAnnot(std::unique_ptr<CPDFSDK_Annot> pAnnot) = 0;
virtual CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot) = 0;