diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-05-16 14:11:30 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-16 21:51:53 +0000 |
commit | 9792f16f3ef27a1e0c7f0526cc69637a158e3010 (patch) | |
tree | 861baddf94e96d7de9bc2c2b27409872d56ebcee /fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | |
parent | cc205131b021ebded854958973f445ed121da1b8 (diff) | |
download | pdfium-9792f16f3ef27a1e0c7f0526cc69637a158e3010.tar.xz |
Properly ref-count CPDFXFA_Page
Change-Id: Ibd1ebe4191f61e20d815de7f1a1094d78b72e6a7
Reviewed-on: https://pdfium-review.googlesource.com/5391
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfxfa/cpdfxfa_context.cpp')
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 93ecab0d08..1b69ff45b9 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -152,34 +152,30 @@ int CPDFXFA_Context::GetPageCount() const { } } -CPDFXFA_Page* CPDFXFA_Context::GetXFAPage(int page_index) { +CFX_RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetXFAPage(int page_index) { if (page_index < 0) return nullptr; - CPDFXFA_Page* pPage = nullptr; - int nCount = pdfium::CollectionSize<int>(m_XFAPageList); - if (nCount > 0 && page_index < nCount) { - pPage = m_XFAPageList[page_index]; - if (pPage) { - pPage->Retain(); - return pPage; - } + if (pdfium::IndexInBounds(m_XFAPageList, page_index)) { + if (m_XFAPageList[page_index]) + return m_XFAPageList[page_index]; } else { m_nPageCount = GetPageCount(); m_XFAPageList.resize(m_nPageCount); } - pPage = new CPDFXFA_Page(this, page_index); - if (!pPage->LoadPage()) { - pPage->Release(); + auto pPage = pdfium::MakeRetain<CPDFXFA_Page>(this, page_index); + if (!pPage->LoadPage()) return nullptr; - } + if (pdfium::IndexInBounds(m_XFAPageList, page_index)) m_XFAPageList[page_index] = pPage; + return pPage; } -CPDFXFA_Page* CPDFXFA_Context::GetXFAPage(CXFA_FFPageView* pPage) const { +CFX_RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetXFAPage( + CXFA_FFPageView* pPage) const { if (!pPage) return nullptr; @@ -189,7 +185,7 @@ CPDFXFA_Page* CPDFXFA_Context::GetXFAPage(CXFA_FFPageView* pPage) const { if (m_iDocType != XFA_DocType::Dynamic) return nullptr; - for (CPDFXFA_Page* pTempPage : m_XFAPageList) { + for (auto& pTempPage : m_XFAPageList) { if (pTempPage && pTempPage->GetXFAPageView() == pPage) return pTempPage; } @@ -203,17 +199,8 @@ void CPDFXFA_Context::DeletePage(int page_index) { if (m_pPDFDoc) m_pPDFDoc->DeletePage(page_index); - if (!pdfium::IndexInBounds(m_XFAPageList, page_index)) - return; - - if (CPDFXFA_Page* pPage = m_XFAPageList[page_index]) - pPage->Release(); -} - -void CPDFXFA_Context::RemovePage(CPDFXFA_Page* page) { - int page_index = page->GetPageIndex(); if (pdfium::IndexInBounds(m_XFAPageList, page_index)) - m_XFAPageList[page_index] = nullptr; + m_XFAPageList[page_index].Reset(); } void CPDFXFA_Context::ClearChangeMark() { |