From 44d83f3f0b90f4c53ca42115d4f1ed614b25c3a7 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 16 May 2016 14:10:22 -0700 Subject: Use CFX_RetainPtr<> to refcount CPDFXFA_Page Review-Url: https://codereview.chromium.org/1984693002 --- fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 2 +- fpdfsdk/fpdfxfa/fpdfxfa_page.cpp | 9 +-------- fpdfsdk/fpdfxfa/include/fpdfxfa_page.h | 7 +++++-- fpdfsdk/fsdk_mgr.cpp | 5 ++--- 4 files changed, 9 insertions(+), 14 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index 4d2a559a39..7a9d074624 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -160,7 +160,7 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { if (nCount > 0 && page_index < nCount) { pPage = m_XFAPageList.GetAt(page_index); if (pPage) - pPage->AddRef(); + pPage->Retain(); } else { m_nPageCount = GetPageCount(); m_XFAPageList.SetSize(m_nPageCount); diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp index 22c8f995f2..8dbbf4e07c 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp @@ -21,16 +21,9 @@ CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) m_iPageIndex(page_index), m_iRef(1) {} -CPDFXFA_Page::~CPDFXFA_Page() {} - -void CPDFXFA_Page::Release() { - if (--m_iRef > 0) - return; - +CPDFXFA_Page::~CPDFXFA_Page() { if (m_pDocument) m_pDocument->RemovePage(this); - - delete this; } FX_BOOL CPDFXFA_Page::LoadPDFPage() { diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h index 0f278912d6..2e08f580ed 100644 --- a/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h +++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h @@ -22,8 +22,11 @@ class CPDFXFA_Page { public: CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index); - void AddRef() { m_iRef++; } - void Release(); + void Retain() { m_iRef++; } + void Release() { + if (--m_iRef <= 0) + delete this; + } FX_BOOL LoadPage(); FX_BOOL LoadPDFPage(CPDF_Dictionary* pageDict); diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp index 2d641783f9..95a08a740c 100644 --- a/fpdfsdk/fsdk_mgr.cpp +++ b/fpdfsdk/fsdk_mgr.cpp @@ -12,6 +12,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fxcrt/include/cfx_retain_ptr.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/javascript/ijs_runtime.h" @@ -902,7 +903,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { SetLock(TRUE); #ifdef PDF_ENABLE_XFA - m_page->AddRef(); + CFX_RetainPtr protector(m_page); if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { CXFA_FFPageView* pageView = m_page->GetXFAPageView(); std::unique_ptr pWidgetHander( @@ -911,7 +912,6 @@ void CPDFSDK_PageView::LoadFXAnnots() { XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType)); if (!pWidgetHander) { - m_page->Release(); SetLock(FALSE); return; } @@ -944,7 +944,6 @@ void CPDFSDK_PageView::LoadFXAnnots() { pAnnotHandlerMgr->Annot_OnLoad(pAnnot); } } - m_page->Release(); #else // PDF_ENABLE_XFA for (size_t i = 0; i < nCount; ++i) { CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); -- cgit v1.2.3