From 521b7508dfe8ab93975eeb9f4ef8068012c4dbd8 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 2 Nov 2016 13:02:28 -0700 Subject: Rename CPDFXFA_Document to CPDFXFA_Context The CPDFXFA_Document class isn't a document, it contains documents. Renamed to make the purpose a bit clearer. Review-Url: https://codereview.chromium.org/2469813004 --- fpdfsdk/cpdfsdk_annot.cpp | 2 +- fpdfsdk/cpdfsdk_baannothandler.cpp | 2 +- fpdfsdk/cpdfsdk_formfillenvironment.h | 2 +- fpdfsdk/cpdfsdk_interform.cpp | 2 +- fpdfsdk/cpdfsdk_pageview.cpp | 12 +- fpdfsdk/cpdfsdk_widget.cpp | 40 +-- fpdfsdk/cpdfsdk_widgethandler.cpp | 6 +- fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 10 +- fpdfsdk/fpdf_ext.cpp | 2 +- fpdfsdk/fpdfdoc_unittest.cpp | 10 +- fpdfsdk/fpdfeditpage.cpp | 4 +- fpdfsdk/fpdfformfill.cpp | 64 ++-- fpdfsdk/fpdfsave.cpp | 56 ++-- fpdfsdk/fpdftext.cpp | 6 +- fpdfsdk/fpdfview.cpp | 8 +- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 460 +++++++++++++++++++++++++++++ fpdfsdk/fpdfxfa/cpdfxfa_context.h | 116 ++++++++ fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 255 ++++++++-------- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h | 6 +- fpdfsdk/fpdfxfa/cpdfxfa_document.cpp | 460 ----------------------------- fpdfsdk/fpdfxfa/cpdfxfa_document.h | 116 -------- fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 34 +-- fpdfsdk/fpdfxfa/cpdfxfa_page.h | 8 +- fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h | 2 +- fpdfsdk/fsdk_define.h | 4 +- fpdfsdk/javascript/app.cpp | 6 +- 26 files changed, 845 insertions(+), 848 deletions(-) create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_context.cpp create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_context.h delete mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_document.cpp delete mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_document.h (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_annot.cpp b/fpdfsdk/cpdfsdk_annot.cpp index aa545373d4..4e62d93cc1 100644 --- a/fpdfsdk/cpdfsdk_annot.cpp +++ b/fpdfsdk/cpdfsdk_annot.cpp @@ -12,7 +12,7 @@ #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #endif // PDF_ENABLE_XFA namespace { diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp index 96fa5c607e..581af1baf9 100644 --- a/fpdfsdk/cpdfsdk_baannothandler.cpp +++ b/fpdfsdk/cpdfsdk_baannothandler.cpp @@ -18,7 +18,7 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #endif // PDF_ENABLE_XFA namespace { diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index 4cdbda3f7c..283c06a7df 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -109,7 +109,7 @@ class CPDFSDK_FormFillEnvironment return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr; } - CPDFXFA_Document* GetXFADocument() const { return m_pUnderlyingDoc; } + CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc; } void ResetXFADocument() { m_pUnderlyingDoc = nullptr; } int GetPageViewCount() const { return m_pageMap.size(); } diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 81836f7923..a8024faaea 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -37,7 +37,7 @@ #ifdef PDF_ENABLE_XFA #include "fpdfsdk/cpdfsdk_xfawidget.h" -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/xfa_ffdocview.h" diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index 348f2d1fab..5a384d5f1f 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -94,7 +94,7 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, if (!pPage) return; - if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { + if (pPage->GetContext()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { CFX_Graphics gs; gs.Create(pDevice); CFX_RectF rectClip; @@ -191,8 +191,8 @@ FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { if (!pAnnot) return FALSE; CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); - if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && - pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) + if (!pPage || (pPage->GetContext()->GetDocType() != DOCTYPE_STATIC_XFA && + pPage->GetContext()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) return FALSE; if (GetFocusAnnot() == pAnnot) @@ -214,7 +214,7 @@ FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { if (m_page) { #ifdef PDF_ENABLE_XFA - return m_page->GetDocument()->GetPDFDoc(); + return m_page->GetContext()->GetPDFDoc(); #else // PDF_ENABLE_XFA return m_page->m_pDocument; #endif // PDF_ENABLE_XFA @@ -398,7 +398,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { #ifdef PDF_ENABLE_XFA CFX_RetainPtr protector(m_page); - if (m_pFormFillEnv->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { + if (m_pFormFillEnv->GetXFAContext()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { CXFA_FFPageView* pageView = m_page->GetXFAPageView(); std::unique_ptr pWidgetHander( pageView->CreateWidgetIterator( @@ -460,7 +460,7 @@ int CPDFSDK_PageView::GetPageIndex() const { return -1; #ifdef PDF_ENABLE_XFA - int nDocType = m_page->GetDocument()->GetDocType(); + int nDocType = m_page->GetContext()->GetDocType(); switch (nDocType) { case DOCTYPE_DYNAMIC_XFA: { CXFA_FFPageView* pPageView = m_page->GetXFAPageView(); diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index e1624a08b5..4ef636b1e3 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -30,7 +30,7 @@ #include "fpdfsdk/pdfwindow/PWL_Utils.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/fxfa_widget.h" #include "xfa/fxfa/xfa_ffdocview.h" @@ -68,10 +68,10 @@ CPDFSDK_Widget::~CPDFSDK_Widget() {} #ifdef PDF_ENABLE_XFA CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); + if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { if (!m_hMixXFAWidget) { - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { + if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) { CFX_WideString sName; if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { sName = GetAnnotName(); @@ -92,9 +92,9 @@ CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { } CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); + if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { + if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) { CFX_WideString sName = GetName(); if (!sName.IsEmpty()) return pDocView->GetWidgetByName(sName, nullptr); @@ -105,10 +105,10 @@ CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { } CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); + if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { if (!m_pWidgetHandler) { - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) + if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) m_pWidgetHandler = pDocView->GetWidgetHandler(); } return m_pWidgetHandler; @@ -219,7 +219,7 @@ FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView) { - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); CXFA_FFWidget* hWidget = GetMixXFAWidget(); if (!hWidget) @@ -266,7 +266,7 @@ FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, param.m_pTarget = pAcc; int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) + if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) pDocView->UpdateDocView(); return nRet == XFA_EVENTERROR_Success; @@ -322,8 +322,8 @@ void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { } void CPDFSDK_Widget::SynchronizeXFAValue() { - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); - CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); + CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); if (!pXFADocView) return; @@ -336,8 +336,8 @@ void CPDFSDK_Widget::SynchronizeXFAValue() { } void CPDFSDK_Widget::SynchronizeXFAItems() { - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); - CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); + CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); if (!pXFADocView) return; @@ -502,8 +502,8 @@ int CPDFSDK_Widget::GetFieldType() const { FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { #ifdef PDF_ENABLE_XFA - CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); - int nDocType = pDoc->GetDocType(); + CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); + int nDocType = pContext->GetDocType(); if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) return TRUE; #endif // PDF_ENABLE_XFA @@ -1826,7 +1826,7 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); #ifdef PDF_ENABLE_XFA - CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); + CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); @@ -1854,7 +1854,7 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, param.m_pTarget = pAcc; int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) + if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) pDocView->UpdateDocView(); if (nRet == XFA_EVENTERROR_Success) diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp index daa97b4dba..715faa9c35 100644 --- a/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -20,7 +20,7 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #endif // PDF_ENABLE_XFA CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler( @@ -239,8 +239,8 @@ void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - CPDFXFA_Document* pDoc = pPageView->GetFormFillEnv()->GetXFADocument(); - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { + CPDFXFA_Context* pContext = pPageView->GetFormFillEnv()->GetXFAContext(); + if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) pWidget->ResetAppearance(FALSE); } diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index c20b5f4984..2262450b94 100644 --- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -12,7 +12,7 @@ #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_xfawidget.h" -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "xfa/fwl/core/fwl_widgethit.h" #include "xfa/fwl/core/ifwl_app.h" #include "xfa/fxfa/fxfa_basic.h" @@ -110,11 +110,11 @@ FX_BOOL CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView, if (!pFormFillEnv) return FALSE; - CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); - if (!pDoc) + CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); + if (!pContext) return FALSE; - CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); + CXFA_FFDocView* pDocView = pContext->GetXFADocView(); if (!pDocView) return FALSE; @@ -335,7 +335,7 @@ CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler( if (!pFormFillEnv) return nullptr; - CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); + CPDFXFA_Context* pDoc = pFormFillEnv->GetXFAContext(); if (!pDoc) return nullptr; diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp index 6b0a3861f9..8f9c94d5fc 100644 --- a/fpdfsdk/fpdf_ext.cpp +++ b/fpdfsdk/fpdf_ext.cpp @@ -21,7 +21,7 @@ #include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #endif // PDF_ENABLE_XFA FX_BOOL FPDF_UnSupportError(int nError) { diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp index 7ac8ce62d5..408d2fa0d8 100644 --- a/fpdfsdk/fpdfdoc_unittest.cpp +++ b/fpdfsdk/fpdfdoc_unittest.cpp @@ -19,7 +19,7 @@ #include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #endif // PDF_ENABLE_XFA class CPDF_TestDocument : public CPDF_Document { @@ -31,10 +31,10 @@ class CPDF_TestDocument : public CPDF_Document { }; #ifdef PDF_ENABLE_XFA -class CPDF_TestXFADocument : public CPDFXFA_Document { +class CPDF_TestXFAContext : public CPDFXFA_Context { public: - CPDF_TestXFADocument() - : CPDFXFA_Document(pdfium::MakeUnique()) {} + CPDF_TestXFAContext() + : CPDFXFA_Context(pdfium::MakeUnique()) {} void SetRoot(CPDF_Dictionary* root) { reinterpret_cast(GetPDFDoc())->SetRoot(root); @@ -42,7 +42,7 @@ class CPDF_TestXFADocument : public CPDFXFA_Document { CPDF_IndirectObjectHolder* GetHolder() { return GetPDFDoc(); } }; -using CPDF_TestPdfDocument = CPDF_TestXFADocument; +using CPDF_TestPdfDocument = CPDF_TestXFAContext; #else // PDF_ENABLE_XFA using CPDF_TestPdfDocument = CPDF_TestDocument; #endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 3f56d90ec0..be9ae67be4 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -29,7 +29,7 @@ #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #endif // PDF_ENABLE_XFA @@ -121,7 +121,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pPage = - new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); + new CPDFXFA_Page(static_cast(document), page_index); pPage->LoadPDFPage(pPageDict); #else // PDF_ENABLE_XFA CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 7a884c719d..25324e3855 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -27,7 +27,7 @@ #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #include "xfa/fxfa/xfa_ffdocview.h" #include "xfa/fxfa/xfa_ffpageview.h" @@ -86,10 +86,10 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, return; #ifdef PDF_ENABLE_XFA - CPDFXFA_Document* pDocument = pPage->GetDocument(); - if (!pDocument) + CPDFXFA_Context* pContext = pPage->GetContext(); + if (!pContext) return; - CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); + CPDF_Document* pPDFDoc = pContext->GetPDFDoc(); if (!pPDFDoc) return; CPDFSDK_FormFillEnvironment* pFormFillEnv = @@ -245,7 +245,7 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, return nullptr; #ifdef PDF_ENABLE_XFA - // If the CPDFXFA_Document has a FormFillEnvironment already then we've done + // If the CPDFXFA_Context has a FormFillEnvironment already then we've done // this and can just return the old Env. Otherwise, we'll end up setting a new // environment into the XFADocument and, that could get weird. if (pDocument->GetFormFillEnv()) @@ -276,8 +276,8 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { pFormFillEnv->ClearAllFocusedAnnots(); // If the document was closed first, it's possible the XFA document // is now a nullptr. - if (pFormFillEnv->GetXFADocument()) - pFormFillEnv->GetXFADocument()->SetFormFillEnv(nullptr); + if (pFormFillEnv->GetXFAContext()) + pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr); #endif // PDF_ENABLE_XFA delete pFormFillEnv; @@ -425,21 +425,22 @@ DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; static_cast(hWidget)->Undo(); } + DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) { if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; static_cast(hWidget)->Redo(); @@ -450,13 +451,14 @@ DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; static_cast(hWidget)->SelectAll(); } + DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, @@ -464,9 +466,9 @@ DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; CFX_WideString wsCpText; @@ -496,9 +498,9 @@ DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; CFX_WideString wsCpText; @@ -528,9 +530,9 @@ DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); @@ -546,9 +548,9 @@ FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; CFX_PointF ptPopup; @@ -567,9 +569,9 @@ FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, if (!hWidget || !document) return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && - pDocument->GetDocType() != XFA_DOCTYPE_Static) + CPDFXFA_Context* pContext = static_cast(document); + if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && + pContext->GetDocType() != XFA_DOCTYPE_Static) return; std::vector* sSuggestWords = new std::vector; diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index 9676e4473e..257f1fc0fc 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -19,7 +19,7 @@ #include "public/fpdf_edit.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" #include "public/fpdf_formfill.h" #include "xfa/fxfa/cxfa_eventparam.h" @@ -75,21 +75,21 @@ void CFX_IFileWrite::Release() { namespace { #ifdef PDF_ENABLE_XFA -bool SaveXFADocumentData(CPDFXFA_Document* pDocument, +bool SaveXFADocumentData(CPDFXFA_Context* pContext, std::vector* fileList) { - if (!pDocument) + if (!pContext) return false; - if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - pDocument->GetDocType() != DOCTYPE_STATIC_XFA) + if (pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && + pContext->GetDocType() != DOCTYPE_STATIC_XFA) return true; - CXFA_FFDocView* pXFADocView = pDocument->GetXFADocView(); + CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); if (!pXFADocView) return true; - CPDF_Document* pPDFDocument = pDocument->GetPDFDoc(); - if (!pDocument) + CPDF_Document* pPDFDocument = pContext->GetPDFDoc(); + if (!pPDFDocument) return false; CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); @@ -124,8 +124,8 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, else if (pPDFObj->GetString() == "template") iTemplate = i + 1; } - std::unique_ptr pContext(new CXFA_ChecksumContext); - pContext->StartChecksum(); + std::unique_ptr pChecksum(new CXFA_ChecksumContext); + pChecksum->StartChecksum(); // template if (iTemplate > -1) { @@ -135,7 +135,7 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, uint8_t* pData = (uint8_t*)streamAcc.GetData(); uint32_t dwSize2 = streamAcc.GetSize(); ScopedFileStream pTemplate(FX_CreateMemoryStream(pData, dwSize2)); - pContext->UpdateChecksum(pTemplate.get()); + pChecksum->UpdateChecksum(pTemplate.get()); } CPDF_Stream* pFormStream = nullptr; CPDF_Stream* pDataSetsStream = nullptr; @@ -172,8 +172,8 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, pDsfileWrite.get(), nullptr) && pDsfileWrite->GetSize() > 0) { // Datasets - pContext->UpdateChecksum(pDsfileWrite.get()); - pContext->FinishChecksum(); + pChecksum->UpdateChecksum(pDsfileWrite.get()); + pChecksum->FinishChecksum(); CPDF_Dictionary* pDataDict = new CPDF_Dictionary(pPDFDocument->GetByteStringPool()); if (iDataSetsIndex != -1) { @@ -196,7 +196,7 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, { ScopedFileStream pfileWrite(FX_CreateMemoryStream()); if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), - pContext.get()) && + pChecksum.get()) && pfileWrite->GetSize() > 0) { CPDF_Dictionary* pDataDict = new CPDF_Dictionary(pPDFDocument->GetByteStringPool()); @@ -219,15 +219,15 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, return true; } -bool SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { - if (!pDocument) +bool SendPostSaveToXFADoc(CPDFXFA_Context* pContext) { + if (!pContext) return false; - if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - pDocument->GetDocType() != DOCTYPE_STATIC_XFA) + if (pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && + pContext->GetDocType() != DOCTYPE_STATIC_XFA) return true; - CXFA_FFDocView* pXFADocView = pDocument->GetXFADocView(); + CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); if (!pXFADocView) return false; @@ -240,17 +240,17 @@ bool SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); } pXFADocView->UpdateDocView(); - pDocument->ClearChangeMark(); + pContext->ClearChangeMark(); return true; } -bool SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, +bool SendPreSaveToXFADoc(CPDFXFA_Context* pContext, std::vector* fileList) { - if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - pDocument->GetDocType() != DOCTYPE_STATIC_XFA) + if (pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && + pContext->GetDocType() != DOCTYPE_STATIC_XFA) return true; - CXFA_FFDocView* pXFADocView = pDocument->GetXFADocView(); + CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); if (!pXFADocView) return true; @@ -263,7 +263,7 @@ bool SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); } pXFADocView->UpdateDocView(); - return SaveXFADocumentData(pDocument, fileList); + return SaveXFADocumentData(pContext, fileList); } #endif // PDF_ENABLE_XFA @@ -277,9 +277,9 @@ bool FPDF_Doc_Save(FPDF_DOCUMENT document, return 0; #ifdef PDF_ENABLE_XFA - CPDFXFA_Document* pDoc = static_cast(document); + CPDFXFA_Context* pContext = static_cast(document); std::vector fileList; - SendPreSaveToXFADoc(pDoc, &fileList); + SendPreSaveToXFADoc(pContext, &fileList); #endif // PDF_ENABLE_XFA if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) @@ -297,7 +297,7 @@ bool FPDF_Doc_Save(FPDF_DOCUMENT document, pStreamWrite->Init(pFileWrite); bool bRet = FileMaker.Create(pStreamWrite, flags); #ifdef PDF_ENABLE_XFA - SendPostSaveToXFADoc(pDoc); + SendPostSaveToXFADoc(pContext); #endif // PDF_ENABLE_XFA pStreamWrite->Release(); return bRet; diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp index 4282350786..6f3f45329e 100644 --- a/fpdfsdk/fpdftext.cpp +++ b/fpdfsdk/fpdftext.cpp @@ -16,7 +16,7 @@ #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #endif // PDF_ENABLE_XFA @@ -47,8 +47,8 @@ DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page) { #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; - CPDFXFA_Document* pDoc = pPage->GetDocument(); - CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc()); + CPDFXFA_Context* pContext = pPage->GetContext(); + CPDF_ViewerPreferences viewRef(pContext->GetPDFDoc()); #else // PDF_ENABLE_XFA CPDF_ViewerPreferences viewRef(pPDFPage->m_pDocument); #endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index d7ddab8a97..5d3dfd824a 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -37,7 +37,7 @@ #include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" #include "public/fpdf_formfill.h" @@ -71,7 +71,7 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { #ifdef PDF_ENABLE_XFA return doc ? FPDFDocumentFromUnderlying( - new CPDFXFA_Document(pdfium::WrapUnique(doc))) + new CPDFXFA_Context(pdfium::WrapUnique(doc))) : nullptr; #else // PDF_ENABLE_XFA return FPDFDocumentFromUnderlying(doc); @@ -352,7 +352,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, return FALSE; CPDF_Document* pdfDoc = - (static_cast(document))->GetPDFDoc(); + (static_cast(document))->GetPDFDoc(); if (!pdfDoc) return FALSE; @@ -374,7 +374,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, } DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { - return document && (static_cast(document))->LoadXFADoc(); + return document && (static_cast(document))->LoadXFADoc(); } #endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp new file mode 100644 index 0000000000..739e16959f --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -0,0 +1,460 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" + +#include "core/fpdfapi/parser/cpdf_document.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_interform.h" +#include "fpdfsdk/cpdfsdk_pageview.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" +#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" +#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/javascript/cjs_runtime.h" +#include "fpdfsdk/javascript/ijs_runtime.h" +#include "public/fpdf_formfill.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/xfa_ffapp.h" +#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/xfa_ffdocview.h" +#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/xfa_ffwidgethandler.h" +#include "xfa/fxfa/xfa_fontmgr.h" + +#ifndef _WIN32 +extern void SetLastError(int err); +extern int GetLastError(); +#endif + +CPDFXFA_Context::CPDFXFA_Context(std::unique_ptr pPDFDoc) + : m_iDocType(DOCTYPE_PDF), + m_pPDFDoc(std::move(pPDFDoc)), + m_pFormFillEnv(nullptr), + m_pXFADocView(nullptr), + m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), + m_nPageCount(0), + m_DocEnv(this) { + m_pXFAApp = pdfium::MakeUnique(this); + m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique()); +} + +CPDFXFA_Context::~CPDFXFA_Context() { + m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; + + // Must happen before we remove the form fill environment. + CloseXFADoc(); + + if (m_pFormFillEnv) { + m_pFormFillEnv->ClearAllFocusedAnnots(); + // Once we're deleted the FormFillEnvironment will point at a bad underlying + // doc so we need to reset it ... + m_pFormFillEnv->ResetXFADocument(); + m_pFormFillEnv = nullptr; + } + + m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; +} + +void CPDFXFA_Context::CloseXFADoc() { + if (!m_pXFADoc) + return; + m_pXFADoc->CloseDoc(); + m_pXFADoc.reset(); + m_pXFADocView = nullptr; +} + +void CPDFXFA_Context::SetFormFillEnv( + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + // The layout data can have pointers back into the script context. That + // context will be different if the form fill environment closes, so, force + // the layout data to clear. + if (m_pXFADoc && m_pXFADoc->GetXFADoc()) + m_pXFADoc->GetXFADoc()->ClearLayoutData(); + + m_pFormFillEnv = pFormFillEnv; +} + +FX_BOOL CPDFXFA_Context::LoadXFADoc() { + m_nLoadStatus = FXFA_LOADSTATUS_LOADING; + + if (!m_pPDFDoc) + return FALSE; + + m_XFAPageList.RemoveAll(); + + CXFA_FFApp* pApp = GetXFAApp(); + if (!pApp) + return FALSE; + + m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); + if (!m_pXFADoc) { + SetLastError(FPDF_ERR_XFALOAD); + return FALSE; + } + + CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); + if (!pDocHandler) { + SetLastError(FPDF_ERR_XFALOAD); + return FALSE; + } + + m_pXFADoc->StartLoad(); + int iStatus = m_pXFADoc->DoLoad(nullptr); + if (iStatus != XFA_PARSESTATUS_Done) { + CloseXFADoc(); + SetLastError(FPDF_ERR_XFALOAD); + return FALSE; + } + m_pXFADoc->StopLoad(); + m_pXFADoc->GetXFADoc()->InitScriptContext(GetJSERuntime()); + + if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) + m_iDocType = DOCTYPE_DYNAMIC_XFA; + else + m_iDocType = DOCTYPE_STATIC_XFA; + + m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); + if (m_pXFADocView->StartLayout() < 0) { + CloseXFADoc(); + SetLastError(FPDF_ERR_XFALAYOUT); + return FALSE; + } + + m_pXFADocView->DoLayout(nullptr); + m_pXFADocView->StopLayout(); + m_nLoadStatus = FXFA_LOADSTATUS_LOADED; + + return TRUE; +} + +int CPDFXFA_Context::GetPageCount() const { + if (!m_pPDFDoc && !m_pXFADoc) + return 0; + + switch (m_iDocType) { + case DOCTYPE_PDF: + case DOCTYPE_STATIC_XFA: + if (m_pPDFDoc) + return m_pPDFDoc->GetPageCount(); + case DOCTYPE_DYNAMIC_XFA: + if (m_pXFADoc) + return m_pXFADocView->CountPageViews(); + default: + return 0; + } +} + +CPDFXFA_Page* CPDFXFA_Context::GetXFAPage(int page_index) { + if (page_index < 0) + return nullptr; + + CPDFXFA_Page* pPage = nullptr; + int nCount = m_XFAPageList.GetSize(); + if (nCount > 0 && page_index < nCount) { + pPage = m_XFAPageList.GetAt(page_index); + if (pPage) + pPage->Retain(); + } else { + m_nPageCount = GetPageCount(); + m_XFAPageList.SetSize(m_nPageCount); + } + if (pPage) + return pPage; + + pPage = new CPDFXFA_Page(this, page_index); + if (!pPage->LoadPage()) { + pPage->Release(); + return nullptr; + } + m_XFAPageList.SetAt(page_index, pPage); + return pPage; +} + +CPDFXFA_Page* CPDFXFA_Context::GetXFAPage(CXFA_FFPageView* pPage) const { + if (!pPage) + return nullptr; + + if (!m_pXFADoc) + return nullptr; + + if (m_iDocType != DOCTYPE_DYNAMIC_XFA) + return nullptr; + + int nSize = m_XFAPageList.GetSize(); + for (int i = 0; i < nSize; i++) { + CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i); + if (!pTempPage) + continue; + if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage) + return pTempPage; + } + + return nullptr; +} + +void CPDFXFA_Context::DeletePage(int page_index) { + // Delete from the document first because, if GetPage was never called for + // this |page_index| then |m_XFAPageList| may have size < |page_index| even + // if it's a valid page in the document. + if (m_pPDFDoc) + m_pPDFDoc->DeletePage(page_index); + + if (page_index < 0 || page_index >= m_XFAPageList.GetSize()) + return; + + if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index)) + pPage->Release(); +} + +void CPDFXFA_Context::RemovePage(CPDFXFA_Page* page) { + m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); +} + +void CPDFXFA_Context::ClearChangeMark() { + if (m_pFormFillEnv) + m_pFormFillEnv->ClearChangeMark(); +} + +v8::Isolate* CPDFXFA_Context::GetJSERuntime() const { + if (!m_pFormFillEnv) + return nullptr; + + // XFA requires V8, if we have V8 then we have a CJS_Runtime and not the stub. + CJS_Runtime* runtime = + static_cast(m_pFormFillEnv->GetJSRuntime()); + return runtime->GetIsolate(); +} + +void CPDFXFA_Context::GetAppName(CFX_WideString& wsName) { + if (m_pFormFillEnv) + wsName = m_pFormFillEnv->FFI_GetAppName(); +} + +void CPDFXFA_Context::GetLanguage(CFX_WideString& wsLanguage) { + if (m_pFormFillEnv) + wsLanguage = m_pFormFillEnv->GetLanguage(); +} + +void CPDFXFA_Context::GetPlatform(CFX_WideString& wsPlatform) { + if (m_pFormFillEnv) + wsPlatform = m_pFormFillEnv->GetPlatform(); +} + +void CPDFXFA_Context::Beep(uint32_t dwType) { + if (m_pFormFillEnv) + m_pFormFillEnv->JS_appBeep(dwType); +} + +int32_t CPDFXFA_Context::MsgBox(const CFX_WideString& wsMessage, + const CFX_WideString& wsTitle, + uint32_t dwIconType, + uint32_t dwButtonType) { + if (!m_pFormFillEnv) + return -1; + + uint32_t iconType = 0; + int iButtonType = 0; + switch (dwIconType) { + case XFA_MBICON_Error: + iconType |= 0; + break; + case XFA_MBICON_Warning: + iconType |= 1; + break; + case XFA_MBICON_Question: + iconType |= 2; + break; + case XFA_MBICON_Status: + iconType |= 3; + break; + } + switch (dwButtonType) { + case XFA_MB_OK: + iButtonType |= 0; + break; + case XFA_MB_OKCancel: + iButtonType |= 1; + break; + case XFA_MB_YesNo: + iButtonType |= 2; + break; + case XFA_MB_YesNoCancel: + iButtonType |= 3; + break; + } + int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), + iButtonType, iconType); + switch (iRet) { + case 1: + return XFA_IDOK; + case 2: + return XFA_IDCancel; + case 3: + return XFA_IDNo; + case 4: + return XFA_IDYes; + } + return XFA_IDYes; +} + +CFX_WideString CPDFXFA_Context::Response(const CFX_WideString& wsQuestion, + const CFX_WideString& wsTitle, + const CFX_WideString& wsDefaultAnswer, + FX_BOOL bMark) { + CFX_WideString wsAnswer; + if (!m_pFormFillEnv) + return wsAnswer; + + int nLength = 2048; + char* pBuff = new char[nLength]; + nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), + wsDefaultAnswer.c_str(), nullptr, + bMark, pBuff, nLength); + if (nLength > 0) { + nLength = nLength > 2046 ? 2046 : nLength; + pBuff[nLength] = 0; + pBuff[nLength + 1] = 0; + wsAnswer = CFX_WideString::FromUTF16LE( + reinterpret_cast(pBuff), + nLength / sizeof(unsigned short)); + } + delete[] pBuff; + return wsAnswer; +} + +IFX_SeekableReadStream* CPDFXFA_Context::DownloadURL( + const CFX_WideString& wsURL) { + return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str()) + : nullptr; +} + +FX_BOOL CPDFXFA_Context::PostRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsContentType, + const CFX_WideString& wsEncode, + const CFX_WideString& wsHeader, + CFX_WideString& wsResponse) { + if (!m_pFormFillEnv) + return FALSE; + + wsResponse = m_pFormFillEnv->PostRequestURL( + wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(), + wsHeader.c_str()); + return TRUE; +} + +FX_BOOL CPDFXFA_Context::PutRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsEncode) { + return m_pFormFillEnv && + m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), + wsEncode.c_str()); +} + +void CPDFXFA_Context::LoadString(int32_t iStringID, CFX_WideString& wsString) { + switch (iStringID) { + case XFA_IDS_ValidateFailed: + wsString = L"%s validation failed"; + return; + case XFA_IDS_CalcOverride: + wsString = L"Calculate Override"; + return; + case XFA_IDS_ModifyField: + wsString = L"Are you sure you want to modify this field?"; + return; + case XFA_IDS_NotModifyField: + wsString = L"You are not allowed to modify this field."; + return; + case XFA_IDS_AppName: + wsString = L"pdfium"; + return; + case XFA_IDS_Unable_TO_SET: + wsString = L"Unable to set "; + return; + case XFA_IDS_INVAlID_PROP_SET: + wsString = L"Invalid property set operation."; + return; + case XFA_IDS_NOT_DEFAUL_VALUE: + wsString = L" doesn't have a default property."; + return; + case XFA_IDS_UNABLE_SET_LANGUAGE: + wsString = L"Unable to set language value."; + return; + case XFA_IDS_UNABLE_SET_NUMPAGES: + wsString = L"Unable to set numPages value."; + return; + case XFA_IDS_UNABLE_SET_PLATFORM: + wsString = L"Unable to set platform value."; + return; + case XFA_IDS_UNABLE_SET_VARIATION: + wsString = L"Unable to set variation value."; + return; + case XFA_IDS_UNABLE_SET_VERSION: + wsString = L"Unable to set version value."; + return; + case XFA_IDS_UNABLE_SET_READY: + wsString = L"Unable to set ready value."; + return; + case XFA_IDS_COMPILER_ERROR: + wsString = L"Compiler error."; + return; + case XFA_IDS_DIVIDE_ZERO: + wsString = L"Divide by zero."; + return; + case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT: + wsString = + L"An attempt was made to reference property '%s' of a non-object in " + L"SOM expression %s."; + return; + case XFA_IDS_INDEX_OUT_OF_BOUNDS: + wsString = L"Index value is out of bounds."; + return; + case XFA_IDS_INCORRECT_NUMBER_OF_METHOD: + wsString = L"Incorrect number of parameters calling method '%s'."; + return; + case XFA_IDS_ARGUMENT_MISMATCH: + wsString = L"Argument mismatch in property or function argument."; + return; + case XFA_IDS_NOT_HAVE_PROPERTY: + wsString = L"'%s' doesn't have property '%s'."; + return; + case XFA_IDS_VIOLATE_BOUNDARY: + wsString = + L"The element [%s] has violated its allowable number of occurrences."; + return; + case XFA_IDS_SERVER_DENY: + wsString = L"Server does not permit."; + return; + case XFA_IDS_ValidateLimit: + wsString = + L"Message limit exceeded. Remaining %d validation errors not " + L"reported."; + return; + case XFA_IDS_ValidateNullWarning: + wsString = + L"%s cannot be blank. To ignore validations for %s, click Ignore."; + return; + case XFA_IDS_ValidateNullError: + wsString = L"%s cannot be blank."; + return; + case XFA_IDS_ValidateWarning: + wsString = + L"The value you entered for %s is invalid. To ignore validations for " + L"%s, click Ignore."; + return; + case XFA_IDS_ValidateError: + wsString = L"The value you entered for %s is invalid."; + return; + } +} + +IFWL_AdapterTimerMgr* CPDFXFA_Context::GetTimerMgr() { + CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; + if (m_pFormFillEnv) + pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv); + return pAdapter; +} diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/fpdfsdk/fpdfxfa/cpdfxfa_context.h new file mode 100644 index 0000000000..02588e3fad --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.h @@ -0,0 +1,116 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ +#define FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ + +#include + +#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" +#include "xfa/fxfa/xfa_ffdoc.h" + +class CJS_Runtime; +class CPDFSDK_FormFillEnvironment; +class CPDFXFA_Page; +class CXFA_FFDocHandler; +class IJS_Runtime; +class IJS_Context; + +enum LoadStatus { + FXFA_LOADSTATUS_PRELOAD = 0, + FXFA_LOADSTATUS_LOADING, + FXFA_LOADSTATUS_LOADED, + FXFA_LOADSTATUS_CLOSING, + FXFA_LOADSTATUS_CLOSED +}; + +class CPDFXFA_Context : public IXFA_AppProvider { + public: + CPDFXFA_Context(std::unique_ptr pPDFDoc); + ~CPDFXFA_Context() override; + + FX_BOOL LoadXFADoc(); + CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } + CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } + CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } + int GetDocType() const { return m_iDocType; } + v8::Isolate* GetJSERuntime() const; + CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } + + CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; } + void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); + + void DeletePage(int page_index); + int GetPageCount() const; + + CPDFXFA_Page* GetXFAPage(int page_index); + CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const; + + void RemovePage(CPDFXFA_Page* page); + + void ClearChangeMark(); + + // IFXA_AppProvider: + void GetLanguage(CFX_WideString& wsLanguage) override; + void GetPlatform(CFX_WideString& wsPlatform) override; + void GetAppName(CFX_WideString& wsName) override; + + void Beep(uint32_t dwType) override; + int32_t MsgBox(const CFX_WideString& wsMessage, + const CFX_WideString& wsTitle, + uint32_t dwIconType, + uint32_t dwButtonType) override; + CFX_WideString Response(const CFX_WideString& wsQuestion, + const CFX_WideString& wsTitle, + const CFX_WideString& wsDefaultAnswer, + FX_BOOL bMark) override; + IFX_SeekableReadStream* DownloadURL(const CFX_WideString& wsURL) override; + FX_BOOL PostRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsContentType, + const CFX_WideString& wsEncode, + const CFX_WideString& wsHeader, + CFX_WideString& wsResponse) override; + FX_BOOL PutRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsEncode) override; + + void LoadString(int32_t iStringID, CFX_WideString& wsString) override; + IFWL_AdapterTimerMgr* GetTimerMgr() override; + + protected: + friend class CPDFXFA_DocEnvironment; + + int GetOriginalPageCount() const { return m_nPageCount; } + void SetOriginalPageCount(int count) { + m_nPageCount = count; + m_XFAPageList.SetSize(count); + } + + LoadStatus GetLoadStatus() const { return m_nLoadStatus; } + + CFX_ArrayTemplate* GetXFAPageList() { return &m_XFAPageList; } + + private: + void CloseXFADoc(); + + int m_iDocType; + + std::unique_ptr m_pPDFDoc; + std::unique_ptr m_pXFADoc; + CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned. + CXFA_FFDocView* m_pXFADocView; // not owned. + std::unique_ptr m_pXFAApp; + std::unique_ptr m_pRuntime; + CFX_ArrayTemplate m_XFAPageList; + LoadStatus m_nLoadStatus; + int m_nPageCount; + + // Must be destroyed before |m_pFormFillEnv|. + CPDFXFA_DocEnvironment m_DocEnv; +}; + +#endif // FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index a5efd50adb..34a0a56364 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -12,7 +12,7 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #include "fpdfsdk/javascript/ijs_runtime.h" #include "xfa/fxfa/xfa_ffdocview.h" @@ -34,35 +34,35 @@ #define FXFA_PDF 0x10000000 #define FXFA_XFA_ALL 0x01111111 -CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Document* doc) - : m_pDocument(doc), m_pJSContext(nullptr) { - ASSERT(m_pDocument); +CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Context* pContext) + : m_pContext(pContext), m_pJSContext(nullptr) { + ASSERT(m_pContext); } CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() { - if (m_pJSContext && m_pDocument->GetFormFillEnv()) - m_pDocument->GetFormFillEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); + if (m_pJSContext && m_pContext->GetFormFillEnv()) + m_pContext->GetFormFillEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); } void CPDFXFA_DocEnvironment::SetChangeMark(CXFA_FFDoc* hDoc) { - if (hDoc == m_pDocument->GetXFADoc() && m_pDocument->GetFormFillEnv()) - m_pDocument->GetFormFillEnv()->SetChangeMark(); + if (hDoc == m_pContext->GetXFADoc() && m_pContext->GetFormFillEnv()) + m_pContext->GetFormFillEnv()->SetChangeMark(); } void CPDFXFA_DocEnvironment::InvalidateRect(CXFA_FFPageView* pPageView, const CFX_RectF& rt, uint32_t dwFlags /* = 0 */) { - if (!m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (!m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return; - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA) return; - CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pPageView); + CPDFXFA_Page* pPage = m_pContext->GetXFAPage(pPageView); if (!pPage) return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; @@ -74,15 +74,15 @@ void CPDFXFA_DocEnvironment::InvalidateRect(CXFA_FFPageView* pPageView, void CPDFXFA_DocEnvironment::DisplayCaret(CXFA_FFWidget* hWidget, FX_BOOL bVisible, const CFX_RectF* pRtAnchor) { - if (!hWidget || !pRtAnchor || !m_pDocument->GetXFADoc() || - !m_pDocument->GetFormFillEnv() || !m_pDocument->GetXFADocView()) + if (!hWidget || !pRtAnchor || !m_pContext->GetXFADoc() || + !m_pContext->GetFormFillEnv() || !m_pContext->GetXFADocView()) return; - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA) return; CXFA_FFWidgetHandler* pWidgetHandler = - m_pDocument->GetXFADocView()->GetWidgetHandler(); + m_pContext->GetXFADocView()->GetWidgetHandler(); if (!pWidgetHandler) return; @@ -90,11 +90,11 @@ void CPDFXFA_DocEnvironment::DisplayCaret(CXFA_FFWidget* hWidget, if (!pPageView) return; - CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pPageView); + CPDFXFA_Page* pPage = m_pContext->GetXFAPage(pPageView); if (!pPage) return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; @@ -115,13 +115,13 @@ FX_BOOL CPDFXFA_DocEnvironment::GetPopupPos(CXFA_FFWidget* hWidget, if (!pXFAPageView) return FALSE; - CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pXFAPageView); + CPDFXFA_Page* pPage = m_pContext->GetXFAPage(pXFAPageView); if (!pPage) return FALSE; CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); int nRotate = pWidgetAcc->GetRotate(); - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return FALSE; @@ -228,11 +228,11 @@ FX_BOOL CPDFXFA_DocEnvironment::PopupMenu(CXFA_FFWidget* hWidget, if (!pXFAPageView) return FALSE; - CPDFXFA_Page* pPage = m_pDocument->GetXFAPage(pXFAPageView); + CPDFXFA_Page* pPage = m_pContext->GetXFAPage(pXFAPageView); if (!pPage) return FALSE; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return FALSE; @@ -255,91 +255,89 @@ FX_BOOL CPDFXFA_DocEnvironment::PopupMenu(CXFA_FFWidget* hWidget, void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) { - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; - if (m_pDocument->GetLoadStatus() == FXFA_LOADSTATUS_LOADING || - m_pDocument->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING || + if (m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_LOADING || + m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING || XFA_PAGEVIEWEVENT_StopLayout != dwFlags) return; - int nNewCount = m_pDocument->GetPageCount(); - if (nNewCount == m_pDocument->GetOriginalPageCount()) + int nNewCount = m_pContext->GetPageCount(); + if (nNewCount == m_pContext->GetOriginalPageCount()) return; - CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); + CXFA_FFDocView* pXFADocView = m_pContext->GetXFADocView(); if (!pXFADocView) return; - for (int iPageIter = 0; iPageIter < m_pDocument->GetOriginalPageCount(); + for (int iPageIter = 0; iPageIter < m_pContext->GetOriginalPageCount(); iPageIter++) { - CPDFXFA_Page* pPage = m_pDocument->GetXFAPageList()->GetAt(iPageIter); + CPDFXFA_Page* pPage = m_pContext->GetXFAPageList()->GetAt(iPageIter); if (!pPage) continue; - m_pDocument->GetFormFillEnv()->RemovePageView(pPage); + m_pContext->GetFormFillEnv()->RemovePageView(pPage); pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); } - int flag = (nNewCount < m_pDocument->GetOriginalPageCount()) + int flag = (nNewCount < m_pContext->GetOriginalPageCount()) ? FXFA_PAGEVIEWEVENT_POSTREMOVED : FXFA_PAGEVIEWEVENT_POSTADDED; - int count = FXSYS_abs(nNewCount - m_pDocument->GetOriginalPageCount()); - m_pDocument->SetOriginalPageCount(nNewCount); + int count = FXSYS_abs(nNewCount - m_pContext->GetOriginalPageCount()); + m_pContext->SetOriginalPageCount(nNewCount); pFormFillEnv->PageEvent(count, flag); } void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget, CXFA_WidgetAcc* pWidgetData) { - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget) return; CXFA_FFPageView* pPageView = hWidget->GetPageView(); if (!pPageView) return; - CPDFXFA_Page* pXFAPage = m_pDocument->GetXFAPage(pPageView); + CPDFXFA_Page* pXFAPage = m_pContext->GetXFAPage(pPageView); if (!pXFAPage) return; - m_pDocument->GetFormFillEnv() - ->GetPageView(pXFAPage, true) - ->AddAnnot(hWidget); + m_pContext->GetFormFillEnv()->GetPageView(pXFAPage, true)->AddAnnot(hWidget); } void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget, CXFA_WidgetAcc* pWidgetData) { - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget) return; CXFA_FFPageView* pPageView = hWidget->GetPageView(); if (!pPageView) return; - CPDFXFA_Page* pXFAPage = m_pDocument->GetXFAPage(pPageView); + CPDFXFA_Page* pXFAPage = m_pContext->GetXFAPage(pPageView); if (!pXFAPage) return; CPDFSDK_PageView* pSdkPageView = - m_pDocument->GetFormFillEnv()->GetPageView(pXFAPage, true); + m_pContext->GetFormFillEnv()->GetPageView(pXFAPage, true); if (CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget)) pSdkPageView->DeleteAnnot(pAnnot); } int32_t CPDFXFA_DocEnvironment::CountPages(CXFA_FFDoc* hDoc) { - if (hDoc == m_pDocument->GetXFADoc() && m_pDocument->GetFormFillEnv()) - return m_pDocument->GetPageCount(); + if (hDoc == m_pContext->GetXFADoc() && m_pContext->GetFormFillEnv()) + return m_pContext->GetPageCount(); return 0; } int32_t CPDFXFA_DocEnvironment::GetCurrentPage(CXFA_FFDoc* hDoc) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return -1; - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA) return -1; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return -1; @@ -348,23 +346,23 @@ int32_t CPDFXFA_DocEnvironment::GetCurrentPage(CXFA_FFDoc* hDoc) { void CPDFXFA_DocEnvironment::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv() || - m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || - iCurPage >= m_pDocument->GetFormFillEnv()->GetPageCount()) { + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv() || + m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || + iCurPage >= m_pContext->GetFormFillEnv()->GetPageCount()) { return; } - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; pFormFillEnv->SetCurrentPage(this, iCurPage); } FX_BOOL CPDFXFA_DocEnvironment::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return FALSE; - if (m_pDocument->GetFormFillEnv()->GetInterForm()) { - return m_pDocument->GetFormFillEnv() + if (m_pContext->GetFormFillEnv()->GetInterForm()) { + return m_pContext->GetFormFillEnv() ->GetInterForm() ->IsXfaCalculateEnabled(); } @@ -373,21 +371,19 @@ FX_BOOL CPDFXFA_DocEnvironment::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { void CPDFXFA_DocEnvironment::SetCalculationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return; - if (m_pDocument->GetFormFillEnv()->GetInterForm()) { - m_pDocument->GetFormFillEnv() - ->GetInterForm() - ->XfaEnableCalculate(bEnabled); + if (m_pContext->GetFormFillEnv()->GetInterForm()) { + m_pContext->GetFormFillEnv()->GetInterForm()->XfaEnableCalculate(bEnabled); } } void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetPDFDoc()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetPDFDoc()) return; - CPDF_Dictionary* pInfoDict = m_pDocument->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo(); if (!pInfoDict) return; @@ -398,25 +394,25 @@ void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, void CPDFXFA_DocEnvironment::SetTitle(CXFA_FFDoc* hDoc, const CFX_WideString& wsTitle) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetPDFDoc()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetPDFDoc()) return; - if (CPDF_Dictionary* pInfoDict = m_pDocument->GetPDFDoc()->GetInfo()) + if (CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo()) pInfoDict->SetFor("Title", new CPDF_String(wsTitle)); } void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, const CFX_WideString& wsFilePath, FX_BOOL bXDP) { - if (hDoc != m_pDocument->GetXFADoc()) + if (hDoc != m_pContext->GetXFADoc()) return; - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) { + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && + m_pContext->GetDocType() != DOCTYPE_STATIC_XFA) { return; } - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; @@ -445,13 +441,13 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, content = "\r\n"; fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), content.GetLength()); - m_pDocument->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data, - &fileWrite, nullptr); + m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data, + &fileWrite, nullptr); } else if (fileType == FXFA_SAVEAS_XDP) { - if (!m_pDocument->GetPDFDoc()) + if (!m_pContext->GetPDFDoc()) return; - CPDF_Dictionary* pRoot = m_pDocument->GetPDFDoc()->GetRoot(); + CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); if (!pRoot) return; @@ -476,12 +472,12 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, if (!pStream) continue; if (pPrePDFObj->GetString() == "form") { - m_pDocument->GetXFADocView()->GetDoc()->SavePackage( - XFA_HASHCODE_Form, &fileWrite, nullptr); + m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Form, + &fileWrite, nullptr); continue; } if (pPrePDFObj->GetString() == "datasets") { - m_pDocument->GetXFADocView()->GetDoc()->SavePackage( + m_pContext->GetXFADocView()->GetDoc()->SavePackage( XFA_HASHCODE_Datasets, &fileWrite, nullptr); continue; } @@ -509,13 +505,13 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc, const CFX_WideString& bsURL) { - if (hDoc != m_pDocument->GetXFADoc()) + if (hDoc != m_pContext->GetXFADoc()) return; - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA) return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; @@ -524,10 +520,10 @@ void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc, } FX_BOOL CPDFXFA_DocEnvironment::IsValidationsEnabled(CXFA_FFDoc* hDoc) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return FALSE; - if (m_pDocument->GetFormFillEnv()->GetInterForm()) { - return m_pDocument->GetFormFillEnv() + if (m_pContext->GetFormFillEnv()->GetInterForm()) { + return m_pContext->GetFormFillEnv() ->GetInterForm() ->IsXfaValidationsEnabled(); } @@ -536,35 +532,34 @@ FX_BOOL CPDFXFA_DocEnvironment::IsValidationsEnabled(CXFA_FFDoc* hDoc) { void CPDFXFA_DocEnvironment::SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return; - if (m_pDocument->GetFormFillEnv()->GetInterForm()) { - m_pDocument->GetFormFillEnv() - ->GetInterForm() - ->XfaSetValidationsEnabled(bEnabled); + if (m_pContext->GetFormFillEnv()->GetInterForm()) { + m_pContext->GetFormFillEnv()->GetInterForm()->XfaSetValidationsEnabled( + bEnabled); } } void CPDFXFA_DocEnvironment::SetFocusWidget(CXFA_FFDoc* hDoc, CXFA_FFWidget* hWidget) { - if (hDoc != m_pDocument->GetXFADoc()) + if (hDoc != m_pContext->GetXFADoc()) return; if (!hWidget) { CPDFSDK_Annot::ObservedPtr pNull; - m_pDocument->GetFormFillEnv()->SetFocusAnnot(&pNull); + m_pContext->GetFormFillEnv()->SetFocusAnnot(&pNull); return; } - int pageViewCount = m_pDocument->GetFormFillEnv()->GetPageViewCount(); + int pageViewCount = m_pContext->GetFormFillEnv()->GetPageViewCount(); for (int i = 0; i < pageViewCount; i++) { - CPDFSDK_PageView* pPageView = m_pDocument->GetFormFillEnv()->GetPageView(i); + CPDFSDK_PageView* pPageView = m_pContext->GetFormFillEnv()->GetPageView(i); if (!pPageView) continue; CPDFSDK_Annot::ObservedPtr pAnnot(pPageView->GetAnnotByXFAWidget(hWidget)); if (pAnnot) { - m_pDocument->GetFormFillEnv()->SetFocusAnnot(&pAnnot); + m_pContext->GetFormFillEnv()->SetFocusAnnot(&pAnnot); break; } } @@ -574,10 +569,10 @@ void CPDFXFA_DocEnvironment::Print(CXFA_FFDoc* hDoc, int32_t nStartPage, int32_t nEndPage, uint32_t dwOptions) { - if (hDoc != m_pDocument->GetXFADoc()) + if (hDoc != m_pContext->GetXFADoc()) return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv || !pFormFillEnv->GetFormFillInfo() || !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform || !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print) { @@ -593,10 +588,10 @@ void CPDFXFA_DocEnvironment::Print(CXFA_FFDoc* hDoc, } FX_ARGB CPDFXFA_DocEnvironment::GetHighlightColor(CXFA_FFDoc* hDoc) { - if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) + if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return 0; - CPDFSDK_InterForm* pInterForm = m_pDocument->GetFormFillEnv()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pContext->GetFormFillEnv()->GetInterForm(); if (!pInterForm) return 0; @@ -613,21 +608,21 @@ FX_BOOL CPDFXFA_DocEnvironment::NotifySubmit(FX_BOOL bPrevOrPost) { } FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) { + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && + m_pContext->GetDocType() != DOCTYPE_STATIC_XFA) { return TRUE; } - if (!m_pDocument->GetXFADocView()) + if (!m_pContext->GetXFADocView()) return TRUE; CXFA_FFWidgetHandler* pWidgetHandler = - m_pDocument->GetXFADocView()->GetWidgetHandler(); + m_pContext->GetXFADocView()->GetWidgetHandler(); if (!pWidgetHandler) return TRUE; std::unique_ptr pWidgetAccIterator( - m_pDocument->GetXFADocView()->CreateWidgetAccIterator()); + m_pContext->GetXFADocView()->CreateWidgetAccIterator()); if (pWidgetAccIterator) { CXFA_EventParam Param; Param.m_eType = XFA_EVENT_PreSubmit; @@ -636,7 +631,7 @@ FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { } pWidgetAccIterator.reset( - m_pDocument->GetXFADocView()->CreateWidgetAccIterator()); + m_pContext->GetXFADocView()->CreateWidgetAccIterator()); if (!pWidgetAccIterator) return TRUE; @@ -645,7 +640,7 @@ FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { while (pWidgetAcc) { int fRet = pWidgetAcc->ProcessValidate(-1); if (fRet == XFA_EVENTERROR_Error) { - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return FALSE; @@ -660,26 +655,26 @@ FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { } pWidgetAcc = pWidgetAccIterator->MoveToNext(); } - m_pDocument->GetXFADocView()->UpdateDocView(); + m_pContext->GetXFADocView()->UpdateDocView(); return TRUE; } void CPDFXFA_DocEnvironment::OnAfterNotifySubmit() { - if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) + if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && + m_pContext->GetDocType() != DOCTYPE_STATIC_XFA) return; - if (!m_pDocument->GetXFADocView()) + if (!m_pContext->GetXFADocView()) return; CXFA_FFWidgetHandler* pWidgetHandler = - m_pDocument->GetXFADocView()->GetWidgetHandler(); + m_pContext->GetXFADocView()->GetWidgetHandler(); if (!pWidgetHandler) return; std::unique_ptr pWidgetAccIterator( - m_pDocument->GetXFADocView()->CreateWidgetAccIterator()); + m_pContext->GetXFADocView()->CreateWidgetAccIterator()); if (!pWidgetAccIterator) return; @@ -690,15 +685,15 @@ void CPDFXFA_DocEnvironment::OnAfterNotifySubmit() { pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); pWidgetAcc = pWidgetAccIterator->MoveToNext(); } - m_pDocument->GetXFADocView()->UpdateDocView(); + m_pContext->GetXFADocView()->UpdateDocView(); } FX_BOOL CPDFXFA_DocEnvironment::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { - if (!NotifySubmit(TRUE) || !m_pDocument->GetXFADocView()) + if (!NotifySubmit(TRUE) || !m_pContext->GetXFADocView()) return FALSE; - m_pDocument->GetXFADocView()->UpdateDocView(); + m_pContext->GetXFADocView()->UpdateDocView(); FX_BOOL ret = SubmitDataInternal(hDoc, submit); NotifySubmit(FALSE); return ret; @@ -707,7 +702,7 @@ FX_BOOL CPDFXFA_DocEnvironment::SubmitData(CXFA_FFDoc* hDoc, IFX_SeekableReadStream* CPDFXFA_DocEnvironment::OpenLinkedFile( CXFA_FFDoc* hDoc, const CFX_WideString& wsLink) { - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return nullptr; @@ -726,11 +721,11 @@ FX_BOOL CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, int fileType, FPDF_DWORD encodeType, FPDF_DWORD flag) { - if (!m_pDocument->GetXFADocView()) + if (!m_pContext->GetXFADocView()) return FALSE; CFX_ByteString content; - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return FALSE; @@ -738,8 +733,8 @@ FX_BOOL CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, if (fileType == FXFA_SAVEAS_XML) { const char kContent[] = "\r\n"; fileStream.WriteBlock(kContent, 0, strlen(kContent)); - m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, &fileStream, - nullptr); + m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, &fileStream, + nullptr); return TRUE; } @@ -750,12 +745,12 @@ FX_BOOL CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; } - if (!m_pDocument->GetPDFDoc()) { + if (!m_pContext->GetPDFDoc()) { fileStream.Flush(); return FALSE; } - CPDF_Dictionary* pRoot = m_pDocument->GetPDFDoc()->GetRoot(); + CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); if (!pRoot) { fileStream.Flush(); return FALSE; @@ -800,11 +795,11 @@ FX_BOOL CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) continue; if (pPrePDFObj->GetString() == "form") { - m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, &fileStream, - nullptr); + m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, &fileStream, + nullptr); } else if (pPrePDFObj->GetString() == "datasets") { - m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, &fileStream, - nullptr); + m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, &fileStream, + nullptr); } else { // PDF,creator. } @@ -901,7 +896,7 @@ FX_BOOL CPDFXFA_DocEnvironment::MailToInfo(CFX_WideString& csURL, FX_BOOL CPDFXFA_DocEnvironment::SubmitDataInternal(CXFA_FFDoc* hDoc, CXFA_Submit submit) { - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return FALSE; @@ -1002,12 +997,12 @@ FX_BOOL CPDFXFA_DocEnvironment::SetGlobalProperty( CXFA_FFDoc* hDoc, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { - if (hDoc != m_pDocument->GetXFADoc()) + if (hDoc != m_pContext->GetXFADoc()) return FALSE; - if (m_pDocument->GetFormFillEnv() && - m_pDocument->GetFormFillEnv()->GetJSRuntime()) { - return m_pDocument->GetFormFillEnv()->GetJSRuntime()->SetValueByName( + if (m_pContext->GetFormFillEnv() && + m_pContext->GetFormFillEnv()->GetJSRuntime()) { + return m_pContext->GetFormFillEnv()->GetJSRuntime()->SetValueByName( szPropName, pValue); } return FALSE; @@ -1017,14 +1012,14 @@ FX_BOOL CPDFXFA_DocEnvironment::GetGlobalProperty( CXFA_FFDoc* hDoc, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { - if (hDoc != m_pDocument->GetXFADoc()) + if (hDoc != m_pContext->GetXFADoc()) return FALSE; - if (!m_pDocument->GetFormFillEnv() || - !m_pDocument->GetFormFillEnv()->GetJSRuntime()) { + if (!m_pContext->GetFormFillEnv() || + !m_pContext->GetFormFillEnv()->GetJSRuntime()) { return FALSE; } - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!m_pJSContext) m_pJSContext = pFormFillEnv->GetJSRuntime()->NewContext(); diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h index 999d44586c..6056e22b79 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h @@ -10,12 +10,12 @@ #include "public/fpdfview.h" #include "xfa/fxfa/fxfa.h" -class CPDFXFA_Document; +class CPDFXFA_Context; class IJS_Context; class CPDFXFA_DocEnvironment : public IXFA_DocEnvironment { public: - CPDFXFA_DocEnvironment(CPDFXFA_Document*); + CPDFXFA_DocEnvironment(CPDFXFA_Context*); ~CPDFXFA_DocEnvironment() override; // IXFA_DocEnvironment @@ -105,7 +105,7 @@ class CPDFXFA_DocEnvironment : public IXFA_DocEnvironment { FPDF_DWORD flag); void ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag); - CPDFXFA_Document* const m_pDocument; // Not owned; + CPDFXFA_Context* const m_pContext; // Not owned; IJS_Context* m_pJSContext; }; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp deleted file mode 100644 index 0b840e4641..0000000000 --- a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp +++ /dev/null @@ -1,460 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" - -#include "core/fpdfapi/parser/cpdf_document.h" -#include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/cpdfsdk_interform.h" -#include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" -#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" -#include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/javascript/cjs_runtime.h" -#include "fpdfsdk/javascript/ijs_runtime.h" -#include "public/fpdf_formfill.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidgethandler.h" -#include "xfa/fxfa/xfa_fontmgr.h" - -#ifndef _WIN32 -extern void SetLastError(int err); -extern int GetLastError(); -#endif - -CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr pPDFDoc) - : m_iDocType(DOCTYPE_PDF), - m_pPDFDoc(std::move(pPDFDoc)), - m_pFormFillEnv(nullptr), - m_pXFADocView(nullptr), - m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), - m_nPageCount(0), - m_DocEnv(this) { - m_pXFAApp = pdfium::MakeUnique(this); - m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique()); -} - -CPDFXFA_Document::~CPDFXFA_Document() { - m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; - - // Must happen before we remove the form fill environment. - CloseXFADoc(); - - if (m_pFormFillEnv) { - m_pFormFillEnv->ClearAllFocusedAnnots(); - // Once we're deleted the FormFillEnvironment will point at a bad underlying - // doc so we need to reset it ... - m_pFormFillEnv->ResetXFADocument(); - m_pFormFillEnv = nullptr; - } - - m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; -} - -void CPDFXFA_Document::CloseXFADoc() { - if (!m_pXFADoc) - return; - m_pXFADoc->CloseDoc(); - m_pXFADoc.reset(); - m_pXFADocView = nullptr; -} - -void CPDFXFA_Document::SetFormFillEnv( - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - // The layout data can have pointers back into the script context. That - // context will be different if the form fill environment closes, so, force - // the layout data to clear. - if (m_pXFADoc && m_pXFADoc->GetXFADoc()) - m_pXFADoc->GetXFADoc()->ClearLayoutData(); - - m_pFormFillEnv = pFormFillEnv; -} - -FX_BOOL CPDFXFA_Document::LoadXFADoc() { - m_nLoadStatus = FXFA_LOADSTATUS_LOADING; - - if (!m_pPDFDoc) - return FALSE; - - m_XFAPageList.RemoveAll(); - - CXFA_FFApp* pApp = GetXFAApp(); - if (!pApp) - return FALSE; - - m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); - if (!m_pXFADoc) { - SetLastError(FPDF_ERR_XFALOAD); - return FALSE; - } - - CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); - if (!pDocHandler) { - SetLastError(FPDF_ERR_XFALOAD); - return FALSE; - } - - m_pXFADoc->StartLoad(); - int iStatus = m_pXFADoc->DoLoad(nullptr); - if (iStatus != XFA_PARSESTATUS_Done) { - CloseXFADoc(); - SetLastError(FPDF_ERR_XFALOAD); - return FALSE; - } - m_pXFADoc->StopLoad(); - m_pXFADoc->GetXFADoc()->InitScriptContext(GetJSERuntime()); - - if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) - m_iDocType = DOCTYPE_DYNAMIC_XFA; - else - m_iDocType = DOCTYPE_STATIC_XFA; - - m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); - if (m_pXFADocView->StartLayout() < 0) { - CloseXFADoc(); - SetLastError(FPDF_ERR_XFALAYOUT); - return FALSE; - } - - m_pXFADocView->DoLayout(nullptr); - m_pXFADocView->StopLayout(); - m_nLoadStatus = FXFA_LOADSTATUS_LOADED; - - return TRUE; -} - -int CPDFXFA_Document::GetPageCount() const { - if (!m_pPDFDoc && !m_pXFADoc) - return 0; - - switch (m_iDocType) { - case DOCTYPE_PDF: - case DOCTYPE_STATIC_XFA: - if (m_pPDFDoc) - return m_pPDFDoc->GetPageCount(); - case DOCTYPE_DYNAMIC_XFA: - if (m_pXFADoc) - return m_pXFADocView->CountPageViews(); - default: - return 0; - } -} - -CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(int page_index) { - if (page_index < 0) - return nullptr; - - CPDFXFA_Page* pPage = nullptr; - int nCount = m_XFAPageList.GetSize(); - if (nCount > 0 && page_index < nCount) { - pPage = m_XFAPageList.GetAt(page_index); - if (pPage) - pPage->Retain(); - } else { - m_nPageCount = GetPageCount(); - m_XFAPageList.SetSize(m_nPageCount); - } - if (pPage) - return pPage; - - pPage = new CPDFXFA_Page(this, page_index); - if (!pPage->LoadPage()) { - pPage->Release(); - return nullptr; - } - m_XFAPageList.SetAt(page_index, pPage); - return pPage; -} - -CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(CXFA_FFPageView* pPage) const { - if (!pPage) - return nullptr; - - if (!m_pXFADoc) - return nullptr; - - if (m_iDocType != DOCTYPE_DYNAMIC_XFA) - return nullptr; - - int nSize = m_XFAPageList.GetSize(); - for (int i = 0; i < nSize; i++) { - CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i); - if (!pTempPage) - continue; - if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage) - return pTempPage; - } - - return nullptr; -} - -void CPDFXFA_Document::DeletePage(int page_index) { - // Delete from the document first because, if GetPage was never called for - // this |page_index| then |m_XFAPageList| may have size < |page_index| even - // if it's a valid page in the document. - if (m_pPDFDoc) - m_pPDFDoc->DeletePage(page_index); - - if (page_index < 0 || page_index >= m_XFAPageList.GetSize()) - return; - - if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index)) - pPage->Release(); -} - -void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { - m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); -} - -void CPDFXFA_Document::ClearChangeMark() { - if (m_pFormFillEnv) - m_pFormFillEnv->ClearChangeMark(); -} - -v8::Isolate* CPDFXFA_Document::GetJSERuntime() const { - if (!m_pFormFillEnv) - return nullptr; - - // XFA requires V8, if we have V8 then we have a CJS_Runtime and not the stub. - CJS_Runtime* runtime = - static_cast(m_pFormFillEnv->GetJSRuntime()); - return runtime->GetIsolate(); -} - -void CPDFXFA_Document::GetAppName(CFX_WideString& wsName) { - if (m_pFormFillEnv) - wsName = m_pFormFillEnv->FFI_GetAppName(); -} - -void CPDFXFA_Document::GetLanguage(CFX_WideString& wsLanguage) { - if (m_pFormFillEnv) - wsLanguage = m_pFormFillEnv->GetLanguage(); -} - -void CPDFXFA_Document::GetPlatform(CFX_WideString& wsPlatform) { - if (m_pFormFillEnv) - wsPlatform = m_pFormFillEnv->GetPlatform(); -} - -void CPDFXFA_Document::Beep(uint32_t dwType) { - if (m_pFormFillEnv) - m_pFormFillEnv->JS_appBeep(dwType); -} - -int32_t CPDFXFA_Document::MsgBox(const CFX_WideString& wsMessage, - const CFX_WideString& wsTitle, - uint32_t dwIconType, - uint32_t dwButtonType) { - if (!m_pFormFillEnv) - return -1; - - uint32_t iconType = 0; - int iButtonType = 0; - switch (dwIconType) { - case XFA_MBICON_Error: - iconType |= 0; - break; - case XFA_MBICON_Warning: - iconType |= 1; - break; - case XFA_MBICON_Question: - iconType |= 2; - break; - case XFA_MBICON_Status: - iconType |= 3; - break; - } - switch (dwButtonType) { - case XFA_MB_OK: - iButtonType |= 0; - break; - case XFA_MB_OKCancel: - iButtonType |= 1; - break; - case XFA_MB_YesNo: - iButtonType |= 2; - break; - case XFA_MB_YesNoCancel: - iButtonType |= 3; - break; - } - int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), - iButtonType, iconType); - switch (iRet) { - case 1: - return XFA_IDOK; - case 2: - return XFA_IDCancel; - case 3: - return XFA_IDNo; - case 4: - return XFA_IDYes; - } - return XFA_IDYes; -} - -CFX_WideString CPDFXFA_Document::Response(const CFX_WideString& wsQuestion, - const CFX_WideString& wsTitle, - const CFX_WideString& wsDefaultAnswer, - FX_BOOL bMark) { - CFX_WideString wsAnswer; - if (!m_pFormFillEnv) - return wsAnswer; - - int nLength = 2048; - char* pBuff = new char[nLength]; - nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), - wsDefaultAnswer.c_str(), nullptr, - bMark, pBuff, nLength); - if (nLength > 0) { - nLength = nLength > 2046 ? 2046 : nLength; - pBuff[nLength] = 0; - pBuff[nLength + 1] = 0; - wsAnswer = CFX_WideString::FromUTF16LE( - reinterpret_cast(pBuff), - nLength / sizeof(unsigned short)); - } - delete[] pBuff; - return wsAnswer; -} - -IFX_SeekableReadStream* CPDFXFA_Document::DownloadURL( - const CFX_WideString& wsURL) { - return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str()) - : nullptr; -} - -FX_BOOL CPDFXFA_Document::PostRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsContentType, - const CFX_WideString& wsEncode, - const CFX_WideString& wsHeader, - CFX_WideString& wsResponse) { - if (!m_pFormFillEnv) - return FALSE; - - wsResponse = m_pFormFillEnv->PostRequestURL( - wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(), - wsHeader.c_str()); - return TRUE; -} - -FX_BOOL CPDFXFA_Document::PutRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsEncode) { - return m_pFormFillEnv && - m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), - wsEncode.c_str()); -} - -void CPDFXFA_Document::LoadString(int32_t iStringID, CFX_WideString& wsString) { - switch (iStringID) { - case XFA_IDS_ValidateFailed: - wsString = L"%s validation failed"; - return; - case XFA_IDS_CalcOverride: - wsString = L"Calculate Override"; - return; - case XFA_IDS_ModifyField: - wsString = L"Are you sure you want to modify this field?"; - return; - case XFA_IDS_NotModifyField: - wsString = L"You are not allowed to modify this field."; - return; - case XFA_IDS_AppName: - wsString = L"pdfium"; - return; - case XFA_IDS_Unable_TO_SET: - wsString = L"Unable to set "; - return; - case XFA_IDS_INVAlID_PROP_SET: - wsString = L"Invalid property set operation."; - return; - case XFA_IDS_NOT_DEFAUL_VALUE: - wsString = L" doesn't have a default property."; - return; - case XFA_IDS_UNABLE_SET_LANGUAGE: - wsString = L"Unable to set language value."; - return; - case XFA_IDS_UNABLE_SET_NUMPAGES: - wsString = L"Unable to set numPages value."; - return; - case XFA_IDS_UNABLE_SET_PLATFORM: - wsString = L"Unable to set platform value."; - return; - case XFA_IDS_UNABLE_SET_VARIATION: - wsString = L"Unable to set variation value."; - return; - case XFA_IDS_UNABLE_SET_VERSION: - wsString = L"Unable to set version value."; - return; - case XFA_IDS_UNABLE_SET_READY: - wsString = L"Unable to set ready value."; - return; - case XFA_IDS_COMPILER_ERROR: - wsString = L"Compiler error."; - return; - case XFA_IDS_DIVIDE_ZERO: - wsString = L"Divide by zero."; - return; - case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT: - wsString = - L"An attempt was made to reference property '%s' of a non-object in " - L"SOM expression %s."; - return; - case XFA_IDS_INDEX_OUT_OF_BOUNDS: - wsString = L"Index value is out of bounds."; - return; - case XFA_IDS_INCORRECT_NUMBER_OF_METHOD: - wsString = L"Incorrect number of parameters calling method '%s'."; - return; - case XFA_IDS_ARGUMENT_MISMATCH: - wsString = L"Argument mismatch in property or function argument."; - return; - case XFA_IDS_NOT_HAVE_PROPERTY: - wsString = L"'%s' doesn't have property '%s'."; - return; - case XFA_IDS_VIOLATE_BOUNDARY: - wsString = - L"The element [%s] has violated its allowable number of occurrences."; - return; - case XFA_IDS_SERVER_DENY: - wsString = L"Server does not permit."; - return; - case XFA_IDS_ValidateLimit: - wsString = - L"Message limit exceeded. Remaining %d validation errors not " - L"reported."; - return; - case XFA_IDS_ValidateNullWarning: - wsString = - L"%s cannot be blank. To ignore validations for %s, click Ignore."; - return; - case XFA_IDS_ValidateNullError: - wsString = L"%s cannot be blank."; - return; - case XFA_IDS_ValidateWarning: - wsString = - L"The value you entered for %s is invalid. To ignore validations for " - L"%s, click Ignore."; - return; - case XFA_IDS_ValidateError: - wsString = L"The value you entered for %s is invalid."; - return; - } -} - -IFWL_AdapterTimerMgr* CPDFXFA_Document::GetTimerMgr() { - CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; - if (m_pFormFillEnv) - pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv); - return pAdapter; -} diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.h b/fpdfsdk/fpdfxfa/cpdfxfa_document.h deleted file mode 100644 index ab0d757e71..0000000000 --- a/fpdfsdk/fpdfxfa/cpdfxfa_document.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_ -#define FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_ - -#include - -#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" -#include "xfa/fxfa/xfa_ffdoc.h" - -class CJS_Runtime; -class CPDFSDK_FormFillEnvironment; -class CPDFXFA_Page; -class CXFA_FFDocHandler; -class IJS_Runtime; -class IJS_Context; - -enum LoadStatus { - FXFA_LOADSTATUS_PRELOAD = 0, - FXFA_LOADSTATUS_LOADING, - FXFA_LOADSTATUS_LOADED, - FXFA_LOADSTATUS_CLOSING, - FXFA_LOADSTATUS_CLOSED -}; - -class CPDFXFA_Document : public IXFA_AppProvider { - public: - CPDFXFA_Document(std::unique_ptr pPDFDoc); - ~CPDFXFA_Document() override; - - FX_BOOL LoadXFADoc(); - CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } - CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } - CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } - int GetDocType() const { return m_iDocType; } - v8::Isolate* GetJSERuntime() const; - CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } - - CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; } - void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); - - void DeletePage(int page_index); - int GetPageCount() const; - - CPDFXFA_Page* GetXFAPage(int page_index); - CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const; - - void RemovePage(CPDFXFA_Page* page); - - void ClearChangeMark(); - - // IFXA_AppProvider: - void GetLanguage(CFX_WideString& wsLanguage) override; - void GetPlatform(CFX_WideString& wsPlatform) override; - void GetAppName(CFX_WideString& wsName) override; - - void Beep(uint32_t dwType) override; - int32_t MsgBox(const CFX_WideString& wsMessage, - const CFX_WideString& wsTitle, - uint32_t dwIconType, - uint32_t dwButtonType) override; - CFX_WideString Response(const CFX_WideString& wsQuestion, - const CFX_WideString& wsTitle, - const CFX_WideString& wsDefaultAnswer, - FX_BOOL bMark) override; - IFX_SeekableReadStream* DownloadURL(const CFX_WideString& wsURL) override; - FX_BOOL PostRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsContentType, - const CFX_WideString& wsEncode, - const CFX_WideString& wsHeader, - CFX_WideString& wsResponse) override; - FX_BOOL PutRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsEncode) override; - - void LoadString(int32_t iStringID, CFX_WideString& wsString) override; - IFWL_AdapterTimerMgr* GetTimerMgr() override; - - protected: - friend class CPDFXFA_DocEnvironment; - - int GetOriginalPageCount() const { return m_nPageCount; } - void SetOriginalPageCount(int count) { - m_nPageCount = count; - m_XFAPageList.SetSize(count); - } - - LoadStatus GetLoadStatus() const { return m_nLoadStatus; } - - CFX_ArrayTemplate* GetXFAPageList() { return &m_XFAPageList; } - - private: - void CloseXFADoc(); - - int m_iDocType; - - std::unique_ptr m_pPDFDoc; - std::unique_ptr m_pXFADoc; - CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned. - CXFA_FFDocView* m_pXFADocView; // not owned. - std::unique_ptr m_pXFAApp; - std::unique_ptr m_pRuntime; - CFX_ArrayTemplate m_XFAPageList; - LoadStatus m_nLoadStatus; - int m_nPageCount; - - // Must be destroyed before |m_pFormFillEnv|. - CPDFXFA_DocEnvironment m_DocEnv; -}; - -#endif // FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_ diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 00cff3e28a..96ffd0b90e 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -8,7 +8,7 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_document.h" -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" @@ -16,22 +16,22 @@ #include "xfa/fxfa/xfa_ffdocview.h" #include "xfa/fxfa/xfa_ffpageview.h" -CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) +CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Context* pContext, int page_index) : m_pXFAPageView(nullptr), - m_pDocument(pDoc), + m_pContext(pContext), m_iPageIndex(page_index), m_iRef(1) {} CPDFXFA_Page::~CPDFXFA_Page() { - if (m_pDocument) - m_pDocument->RemovePage(this); + if (m_pContext) + m_pContext->RemovePage(this); } FX_BOOL CPDFXFA_Page::LoadPDFPage() { - if (!m_pDocument) + if (!m_pContext) return FALSE; - CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); + CPDF_Document* pPDFDoc = m_pContext->GetPDFDoc(); if (!pPDFDoc) return FALSE; @@ -47,14 +47,14 @@ FX_BOOL CPDFXFA_Page::LoadPDFPage() { } FX_BOOL CPDFXFA_Page::LoadXFAPageView() { - if (!m_pDocument) + if (!m_pContext) return FALSE; - CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); + CXFA_FFDoc* pXFADoc = m_pContext->GetXFADoc(); if (!pXFADoc) return FALSE; - CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); + CXFA_FFDocView* pXFADocView = m_pContext->GetXFADocView(); if (!pXFADocView) return FALSE; @@ -67,10 +67,10 @@ FX_BOOL CPDFXFA_Page::LoadXFAPageView() { } FX_BOOL CPDFXFA_Page::LoadPage() { - if (!m_pDocument || m_iPageIndex < 0) + if (!m_pContext || m_iPageIndex < 0) return FALSE; - int iDocType = m_pDocument->GetDocType(); + int iDocType = m_pContext->GetDocType(); switch (iDocType) { case DOCTYPE_PDF: case DOCTYPE_STATIC_XFA: { @@ -85,11 +85,11 @@ FX_BOOL CPDFXFA_Page::LoadPage() { } FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { - if (!m_pDocument || m_iPageIndex < 0 || !pageDict) + if (!m_pContext || m_iPageIndex < 0 || !pageDict) return FALSE; m_pPDFPage = - pdfium::MakeUnique(m_pDocument->GetPDFDoc(), pageDict, true); + pdfium::MakeUnique(m_pContext->GetPDFDoc(), pageDict, true); m_pPDFPage->ParseContent(); return TRUE; } @@ -98,7 +98,7 @@ FX_FLOAT CPDFXFA_Page::GetPageWidth() const { if (!m_pPDFPage && !m_pXFAPageView) return 0.0f; - int nDocType = m_pDocument->GetDocType(); + int nDocType = m_pContext->GetDocType(); switch (nDocType) { case DOCTYPE_DYNAMIC_XFA: { if (m_pXFAPageView) { @@ -123,7 +123,7 @@ FX_FLOAT CPDFXFA_Page::GetPageHeight() const { if (!m_pPDFPage && !m_pXFAPageView) return 0.0f; - int nDocType = m_pDocument->GetDocType(); + int nDocType = m_pContext->GetDocType(); switch (nDocType) { case DOCTYPE_PDF: case DOCTYPE_STATIC_XFA: { @@ -203,7 +203,7 @@ void CPDFXFA_Page::GetDisplayMatrix(CFX_Matrix& matrix, if (!m_pPDFPage && !m_pXFAPageView) return; - int nDocType = m_pDocument->GetDocType(); + int nDocType = m_pContext->GetDocType(); switch (nDocType) { case DOCTYPE_DYNAMIC_XFA: { if (m_pXFAPageView) { diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h index 80a183f807..81f0a305c9 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -12,14 +12,14 @@ #include "core/fxcrt/fx_system.h" class CFX_Matrix; -class CPDFXFA_Document; +class CPDFXFA_Context; class CPDF_Dictionary; class CPDF_Page; class CXFA_FFPageView; class CPDFXFA_Page { public: - CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index); + CPDFXFA_Page(CPDFXFA_Context* pContext, int page_index); void Retain() { m_iRef++; } void Release() { @@ -29,7 +29,7 @@ class CPDFXFA_Page { FX_BOOL LoadPage(); FX_BOOL LoadPDFPage(CPDF_Dictionary* pageDict); - CPDFXFA_Document* GetDocument() const { return m_pDocument; } + CPDFXFA_Context* GetContext() const { return m_pContext; } int GetPageIndex() const { return m_iPageIndex; } CPDF_Page* GetPDFPage() const { return m_pPDFPage.get(); } CXFA_FFPageView* GetXFAPageView() const { return m_pXFAPageView; } @@ -77,7 +77,7 @@ class CPDFXFA_Page { private: std::unique_ptr m_pPDFPage; CXFA_FFPageView* m_pXFAPageView; - CPDFXFA_Document* const m_pDocument; + CPDFXFA_Context* const m_pContext; const int m_iPageIndex; int m_iRef; }; diff --git a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h index 092148f4f2..ee4b404a5c 100644 --- a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h +++ b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h @@ -9,7 +9,7 @@ #include -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "xfa/fwl/core/ifwl_adaptertimermgr.h" struct CFWL_TimerInfo; diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h index aeb42d2d11..e5a287fac6 100644 --- a/fpdfsdk/fsdk_define.h +++ b/fpdfsdk/fsdk_define.h @@ -12,7 +12,7 @@ #include "public/fpdfview.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #endif // PDF_ENABLE_XFA #ifdef _WIN32 @@ -71,7 +71,7 @@ class CFPDF_FileStream : public IFX_SeekableStream { using UnderlyingDocumentType = CPDF_Document; using UnderlyingPageType = CPDF_Page; #else // PDF_ENABLE_XFA -using UnderlyingDocumentType = CPDFXFA_Document; +using UnderlyingDocumentType = CPDFXFA_Context; using UnderlyingPageType = CPDFXFA_Page; #endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 394f49e143..4d79e41f7a 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -291,9 +291,9 @@ FX_BOOL app::viewerVersion(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; #ifdef PDF_ENABLE_XFA - CJS_Context* pContext = (CJS_Context*)cc; - CPDFXFA_Document* pDoc = pContext->GetFormFillEnv()->GetXFADocument(); - if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) { + CJS_Context* pJSContext = static_cast(cc); + CPDFXFA_Context* pXFAContext = pJSContext->GetFormFillEnv()->GetXFAContext(); + if (pXFAContext->GetDocType() == 1 || pXFAContext->GetDocType() == 2) { vp << JS_NUM_VIEWERVERSION_XFA; return TRUE; } -- cgit v1.2.3