summaryrefslogtreecommitdiff
path: root/fpdfsdk/formfiller/cffl_formfiller.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-25 23:25:58 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-25 23:25:58 +0000
commit6fe32f898af3eea875fd01a6d18f719d17dd72f3 (patch)
treef63a1a03d3fffc3e4e765442df9805b526660765 /fpdfsdk/formfiller/cffl_formfiller.cpp
parented7da31f67e93c8923669ad496126aa005a8d3a2 (diff)
downloadpdfium-6fe32f898af3eea875fd01a6d18f719d17dd72f3.tar.xz
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 <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/formfiller/cffl_formfiller.cpp')
-rw-r--r--fpdfsdk/formfiller/cffl_formfiller.cpp35
1 files changed, 14 insertions, 21 deletions
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<CFFL_PrivateData> pData;
- {
- auto it = m_Maps.begin();
- std::unique_ptr<CPWL_Wnd> pWnd = std::move(it->second);
- pData.reset(static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()));
- m_Maps.erase(it);
- pWnd->InvalidateProvider(this);
- pWnd->Destroy();
- }
+ auto it = m_Maps.begin();
+ std::unique_ptr<CPWL_Wnd> 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<CFFL_PrivateData*>(pWnd->GetAttachedData());
+ const auto* pPrivateData =
+ static_cast<const CFFL_PrivateData*>(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<CFFL_PrivateData> pData;
- {
- std::unique_ptr<CPWL_Wnd> pWnd = std::move(it->second);
- m_Maps.erase(it);
- pData.reset(static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()));
- pWnd->Destroy();
- }
+ std::unique_ptr<CPWL_Wnd> 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<CFFL_PrivateData*>(pAttached);
+ const auto* pPrivateData = static_cast<const CFFL_PrivateData*>(pAttached);
if (!pPrivateData || !pPrivateData->pPageView)
return mt;