From 6fe32f898af3eea875fd01a6d18f719d17dd72f3 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 25 Oct 2018 23:25:58 +0000 Subject: Make CPWL_Wnd own its pAttachedData. This requires moving it out of CreateParams, since that must be a copyable struct, and implies that currently there is some questionable sharing going on. To resolve this, introduce a Clone() method so that each window gets its own copy. Make GetAttachedData() return a const pointer, so that callers can't free it behind our back. Tidy initializations along the way. Change-Id: Iadc97688b4692bf4fafefe8cff88af88672f7110 Reviewed-on: https://pdfium-review.googlesource.com/c/44590 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 32 +++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'fpdfsdk/formfiller/cffl_interactiveformfiller.cpp') diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index c712610dcc..b578a440b7 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -570,12 +570,12 @@ void CFFL_InteractiveFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { } void CFFL_InteractiveFormFiller::QueryWherePopup( - CPWL_Wnd::PrivateData* pAttached, + const CPWL_Wnd::PrivateData* pAttached, float fPopupMin, float fPopupMax, bool* bBottom, float* fPopupRet) { - auto* pData = static_cast(pAttached); + auto* pData = static_cast(pAttached); CPDFSDK_Widget* pWidget = pData->pWidget; CPDF_Page* pPage = pWidget->GetPDFPage(); @@ -795,10 +795,9 @@ bool CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot, } bool CFFL_InteractiveFormFiller::OnPopupPreOpen( - CPWL_Wnd::PrivateData* pAttached, + const CPWL_Wnd::PrivateData* pAttached, uint32_t nFlag) { - auto* pData = static_cast(pAttached); - ASSERT(pData); + auto* pData = static_cast(pAttached); ASSERT(pData->pWidget); CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); @@ -806,10 +805,9 @@ bool CFFL_InteractiveFormFiller::OnPopupPreOpen( } bool CFFL_InteractiveFormFiller::OnPopupPostOpen( - CPWL_Wnd::PrivateData* pAttached, + const CPWL_Wnd::PrivateData* pAttached, uint32_t nFlag) { - auto* pData = static_cast(pAttached); - ASSERT(pData); + auto* pData = static_cast(pAttached); ASSERT(pData->pWidget); CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); @@ -885,7 +883,7 @@ bool CFFL_InteractiveFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, } std::pair CFFL_InteractiveFormFiller::OnBeforeKeyStroke( - CPWL_Wnd::PrivateData* pAttached, + const CPWL_Wnd::PrivateData* pAttached, WideString& strChange, const WideString& strChangeEx, int nSelStart, @@ -893,7 +891,8 @@ std::pair CFFL_InteractiveFormFiller::OnBeforeKeyStroke( bool bKeyDown, uint32_t nFlag) { // Copy the private data since the window owning it may not survive. - CFFL_PrivateData privateData = *static_cast(pAttached); + CFFL_PrivateData privateData = + *static_cast(pAttached); ASSERT(privateData.pWidget); CFFL_FormFiller* pFormFiller = GetFormFiller(privateData.pWidget, false); @@ -949,7 +948,8 @@ std::pair CFFL_InteractiveFormFiller::OnBeforeKeyStroke( privateData.pPageView, nValueAge == privateData.pWidget->GetValueAge()); if (!pWnd) return {true, true}; - privateData = *static_cast(pWnd->GetAttachedData()); + privateData = + *static_cast(pWnd->GetAttachedData()); bExit = true; } if (fa.bRC) { @@ -964,3 +964,13 @@ std::pair CFFL_InteractiveFormFiller::OnBeforeKeyStroke( pFormFiller->CommitData(privateData.pPageView, nFlag); return {false, true}; } + +CFFL_PrivateData::CFFL_PrivateData() = default; + +CFFL_PrivateData::CFFL_PrivateData(const CFFL_PrivateData& that) = default; + +CFFL_PrivateData::~CFFL_PrivateData() = default; + +std::unique_ptr CFFL_PrivateData::Clone() const { + return pdfium::MakeUnique(*this); +} -- cgit v1.2.3