Simplify ~CPDFXFA_Context(), part 2
Approximate current destruction order by re-arranging the order
of appearance of the members in the header. One change is that
we never reach the CLOSED state, but a search shows that value
is otherwise unused.
-- pack some scalars while we're at it.
-- inline the one remaining usage of CloseXFADoc()
Change-Id: I62b3fda838e44d664616441d26997e6225c01380
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71874
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 08ba40e..caad5da 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -89,24 +89,8 @@
CPDFXFA_Context::~CPDFXFA_Context() {
m_nLoadStatus = FXFA_LOADSTATUS_CLOSING;
-
- // Must happen before we remove the form fill environment.
- CloseXFADoc();
-
- if (m_pFormFillEnv) {
+ if (m_pFormFillEnv)
m_pFormFillEnv->ClearAllFocusedAnnots();
- m_pFormFillEnv.Reset();
- }
-
- m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
-}
-
-void CPDFXFA_Context::CloseXFADoc() {
- if (!m_pXFADoc)
- return;
-
- m_pXFADocView = nullptr;
- m_pXFADoc.reset();
}
void CPDFXFA_Context::SetFormFillEnv(
@@ -160,7 +144,8 @@
m_pXFADocView = m_pXFADoc->CreateDocView();
if (m_pXFADocView->StartLayout() < 0) {
- CloseXFADoc();
+ m_pXFADocView = nullptr;
+ m_pXFADoc.reset();
FXSYS_SetLastError(FPDF_ERR_XFALAYOUT);
return false;
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
index dc905a7..cca4360 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
@@ -28,7 +28,6 @@
FXFA_LOADSTATUS_LOADING,
FXFA_LOADSTATUS_LOADED,
FXFA_LOADSTATUS_CLOSING,
- FXFA_LOADSTATUS_CLOSED
};
class CPDFXFA_Context final : public CPDF_Document::Extension,
@@ -109,21 +108,23 @@
CJS_Runtime* GetCJSRuntime() const;
bool SavePackage(const RetainPtr<IFX_SeekableStream>& pStream,
XFA_HashCode code);
- void CloseXFADoc();
FormType m_FormType = FormType::kNone;
- UnownedPtr<CPDF_Document> const m_pPDFDoc;
- FXGCScopedHeap m_pGCHeap;
- std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
- ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
- UnownedPtr<CXFA_FFDocView> m_pXFADocView;
- std::unique_ptr<CXFA_FFApp> const m_pXFAApp;
- std::vector<RetainPtr<CPDFXFA_Page>> m_XFAPageList;
LoadStatus m_nLoadStatus = FXFA_LOADSTATUS_PRELOAD;
int m_nPageCount = 0;
+ // The order in which the following members are destroyed is critical.
+ UnownedPtr<CPDF_Document> const m_pPDFDoc;
+ FXGCScopedHeap m_pGCHeap;
+ ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
+ std::unique_ptr<CXFA_FFApp> const m_pXFAApp;
+ std::vector<RetainPtr<CPDFXFA_Page>> m_XFAPageList;
+
// Must be destroyed before |m_pFormFillEnv|.
CPDFXFA_DocEnvironment m_DocEnv;
+
+ std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
+ UnownedPtr<CXFA_FFDocView> m_pXFADocView;
};
#endif // FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_