From 940967de0b588d3abb9cba5822ae5f5c5fe05017 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 18 May 2017 12:32:20 -0700 Subject: Use Unowned/Observed pointers between doc and FF onwership hierarchies. See the explanation in CPDFSDK_FormFillEnvironment.h Change-Id: I52feb25fb358831233a636e3ead5aa70e98c5baa Reviewed-on: https://pdfium-review.googlesource.com/5658 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fpdfsdk/cpdfsdk_formfillenvironment.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'fpdfsdk/cpdfsdk_formfillenvironment.h') diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index 5aead04191..0462426e0f 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -29,6 +29,17 @@ class CPDFSDK_InterForm; class CPDFSDK_PageView; class IJS_Runtime; +// The CPDFSDK_FormFillEnvironment is "owned" by the embedder across the +// C API as a FPDF_FormHandle, and may pop out of existence at any time, +// so long as the associated embedder-owned FPDF_Document outlives it. +// Pointers from objects in the FPDF_Document ownership hierarchy should +// be ObservedPtr<> so as to clear themselves when the embedder "exits" +// the form fill environment. Pointers from objects in this ownership +// heirarcy to objects in the FPDF_Document ownership hierarcy should be +// UnownedPtr<>, as should pointers from objects in this ownership +// hierarcy back to the form fill environment itself, so as to flag any +// lingering lifetime issues via the memory tools. + class CPDFSDK_FormFillEnvironment : public CFX_Observable { public: @@ -95,7 +106,7 @@ class CPDFSDK_FormFillEnvironment int sizeOfArray); UnderlyingDocumentType* GetUnderlyingDocument() const { - return m_pUnderlyingDoc; + return m_pUnderlyingDoc.Get(); } #ifdef PDF_ENABLE_XFA @@ -103,7 +114,7 @@ class CPDFSDK_FormFillEnvironment return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr; } - CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc; } + CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc.Get(); } void ResetXFADocument() { m_pUnderlyingDoc = nullptr; } int GetPageViewCount() const { return m_PageMap.size(); } @@ -154,7 +165,7 @@ class CPDFSDK_FormFillEnvironment void PageEvent(int iPageCount, uint32_t dwEventType) const; #else // PDF_ENABLE_XFA - CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc; } + CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc.Get(); } #endif // PDF_ENABLE_XFA int JS_appAlert(const wchar_t* Msg, @@ -203,14 +214,14 @@ class CPDFSDK_FormFillEnvironment CPDFSDK_InterForm* GetInterForm(); // Creates if not present. private: + FPDF_FORMFILLINFO* const m_pInfo; std::unique_ptr m_pAnnotHandlerMgr; std::unique_ptr m_pActionHandler; std::unique_ptr m_pJSRuntime; - FPDF_FORMFILLINFO* const m_pInfo; std::map> m_PageMap; std::unique_ptr m_pInterForm; CPDFSDK_Annot::ObservedPtr m_pFocusAnnot; - UnderlyingDocumentType* m_pUnderlyingDoc; + CFX_UnownedPtr m_pUnderlyingDoc; std::unique_ptr m_pFormFiller; std::unique_ptr m_pSysHandler; bool m_bChangeMask; -- cgit v1.2.3