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_formfiller.cpp | 35 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'fpdfsdk/formfiller/cffl_formfiller.cpp') diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 8e9d0c7d65..dace98a8c1 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -28,15 +28,11 @@ CFFL_FormFiller::~CFFL_FormFiller() { void CFFL_FormFiller::DestroyWindows() { while (!m_Maps.empty()) { - std::unique_ptr pData; - { - auto it = m_Maps.begin(); - std::unique_ptr pWnd = std::move(it->second); - pData.reset(static_cast(pWnd->GetAttachedData())); - m_Maps.erase(it); - pWnd->InvalidateProvider(this); - pWnd->Destroy(); - } + auto it = m_Maps.begin(); + std::unique_ptr pWnd = std::move(it->second); + m_Maps.erase(it); + pWnd->InvalidateProvider(this); + pWnd->Destroy(); } } @@ -395,8 +391,7 @@ CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, pPrivateData->pPageView = pPageView; pPrivateData->nWidgetAppearanceAge = m_pWidget->GetAppearanceAge(); pPrivateData->nWidgetValueAge = 0; - cp.pAttachedData = pPrivateData.release(); - m_Maps[pPageView] = NewPDFWindow(cp); + m_Maps[pPageView] = NewPDFWindow(cp, std::move(pPrivateData)); return m_Maps[pPageView].get(); } @@ -404,7 +399,8 @@ CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, if (!bNew) return pWnd; - auto* pPrivateData = static_cast(pWnd->GetAttachedData()); + const auto* pPrivateData = + static_cast(pWnd->GetAttachedData()); if (pPrivateData->nWidgetAppearanceAge == m_pWidget->GetAppearanceAge()) return pWnd; @@ -417,18 +413,15 @@ void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { if (it == m_Maps.end()) return; - std::unique_ptr pData; - { - std::unique_ptr pWnd = std::move(it->second); - m_Maps.erase(it); - pData.reset(static_cast(pWnd->GetAttachedData())); - pWnd->Destroy(); - } + std::unique_ptr pWnd = std::move(it->second); + m_Maps.erase(it); + pWnd->Destroy(); } -CFX_Matrix CFFL_FormFiller::GetWindowMatrix(CPWL_Wnd::PrivateData* pAttached) { +CFX_Matrix CFFL_FormFiller::GetWindowMatrix( + const CPWL_Wnd::PrivateData* pAttached) { CFX_Matrix mt; - auto* pPrivateData = static_cast(pAttached); + const auto* pPrivateData = static_cast(pAttached); if (!pPrivateData || !pPrivateData->pPageView) return mt; -- cgit v1.2.3