From cedaa557316a3f5c436814e69d67f19795f471d7 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 24 Aug 2016 11:12:19 -0700 Subject: Flip document and parser ownership This Cl switches the ownership between the parser and the document. Previously the parser owned the document and we'd jump through hoops during cleanup to delete the right object. This Cl flips the ownership so the document owns the parser and simplifies the cleanup logic where needed. BUG=pdfium:565 Review-Url: https://codereview.chromium.org/2275773003 --- fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp') diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index 605e53c32a..d4c43c5706 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -45,10 +45,10 @@ extern void SetLastError(int err); extern int GetLastError(); #endif -CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, +CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr pPDFDoc, CPDFXFA_App* pProvider) : m_iDocType(DOCTYPE_PDF), - m_pPDFDoc(pPDFDoc), + m_pPDFDoc(std::move(pPDFDoc)), m_pXFADocView(nullptr), m_pApp(pProvider), m_pJSContext(nullptr), @@ -70,16 +70,6 @@ CPDFXFA_Document::~CPDFXFA_Document() { } if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); - // |m_pSDKDoc| has to be released before |pParser| and |m_pPDFDoc| since it - // needs to access them to kill focused annotations. - m_pSDKDoc.reset(); - if (m_pPDFDoc) { - CPDF_Parser* pParser = m_pPDFDoc->GetParser(); - if (pParser) - delete pParser; - else - delete m_pPDFDoc; - } m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; } @@ -96,7 +86,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() { if (!pApp) return FALSE; - m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc)); + m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc.get())); if (!m_pXFADoc) { SetLastError(FPDF_ERR_XFALOAD); return FALSE; -- cgit v1.2.3