summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-09-14 07:01:54 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-14 07:01:54 -0700
commita440bb3f11f42b7a22624e9771dd8d9c57075f06 (patch)
treec3dfde4e22bb2a2c4413e55d11dc89daaa1a3fb2
parentf2662c4a0bdfbe52d961ab4d2ff9a448323c3af9 (diff)
downloadpdfium-a440bb3f11f42b7a22624e9771dd8d9c57075f06.tar.xz
Split CPDFXFA_Document apart
[DO NOT COMMIT] This CL renames IXFA_DocProvider to IXFA_DocEnvironment to better describe the purpose. Then, CPDFXFA_Document has all of the IXFA_DocEnvironment methods removed and placed in CPDFXFA_DocEnvironment. The CPDFXFA_Document then has a CPDFXFA_DocEnvironment. This splits the code related to the document apart from the XFA callback methods to work with that document. Review-Url: https://codereview.chromium.org/2328573002
-rw-r--r--BUILD.gn2
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp1023
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp978
-rw-r--r--fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h114
-rw-r--r--fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h143
-rw-r--r--xfa/fwl/basewidget/fwl_editimp.cpp9
-rw-r--r--xfa/fxfa/app/xfa_ffapp.cpp8
-rw-r--r--xfa/fxfa/app/xfa_ffchoicelist.cpp2
-rw-r--r--xfa/fxfa/app/xfa_ffdoc.cpp4
-rw-r--r--xfa/fxfa/app/xfa_ffdocview.cpp26
-rw-r--r--xfa/fxfa/app/xfa_fffield.cpp2
-rw-r--r--xfa/fxfa/app/xfa_ffnotify.cpp12
-rw-r--r--xfa/fxfa/app/xfa_ffnotify.h2
-rw-r--r--xfa/fxfa/app/xfa_fftext.cpp2
-rw-r--r--xfa/fxfa/app/xfa_fftextedit.cpp4
-rw-r--r--xfa/fxfa/app/xfa_ffwidget.cpp10
-rw-r--r--xfa/fxfa/app/xfa_ffwidgetacc.cpp2
-rw-r--r--xfa/fxfa/app/xfa_ffwidgethandler.cpp10
-rw-r--r--xfa/fxfa/app/xfa_fwladapter.cpp2
-rw-r--r--xfa/fxfa/include/fxfa.h6
-rw-r--r--xfa/fxfa/include/xfa_ffapp.h5
-rw-r--r--xfa/fxfa/include/xfa_ffdoc.h6
-rw-r--r--xfa/fxfa/parser/cscript_hostpseudomodel.cpp39
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp8
24 files changed, 1255 insertions, 1164 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 4f356ee671..bdefb73dd4 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1049,10 +1049,12 @@ if (pdf_enable_v8) {
if (pdf_enable_xfa) {
static_library("fpdfxfa") {
sources = [
+ "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp",
"fpdfsdk/fpdfxfa/fpdfxfa_app.cpp",
"fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp",
"fpdfsdk/fpdfxfa/fpdfxfa_page.cpp",
"fpdfsdk/fpdfxfa/fpdfxfa_util.cpp",
+ "fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h",
"fpdfsdk/fpdfxfa/include/fpdfxfa_app.h",
"fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h",
"fpdfsdk/fpdfxfa/include/fpdfxfa_page.h",
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
new file mode 100644
index 0000000000..56eb3fccc6
--- /dev/null
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -0,0 +1,1023 @@
+// Copyright 2016 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/include/cpdfxfa_docenvironment.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
+#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
+#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
+#include "fpdfsdk/include/cpdfdoc_environment.h"
+#include "fpdfsdk/include/cpdfsdk_document.h"
+#include "fpdfsdk/include/cpdfsdk_interform.h"
+#include "fpdfsdk/include/cpdfsdk_pageview.h"
+#include "fpdfsdk/javascript/ijs_runtime.h"
+#include "xfa/fxfa/include/xfa_ffdocview.h"
+#include "xfa/fxfa/include/xfa_ffwidget.h"
+#include "xfa/fxfa/include/xfa_ffwidgethandler.h"
+
+#define IDS_XFA_Validate_Input \
+ "At least one required field was empty. Please fill in the required " \
+ "fields\r\n(highlighted) before continuing."
+
+// submit
+#define FXFA_CONFIG 0x00000001
+#define FXFA_TEMPLATE 0x00000010
+#define FXFA_LOCALESET 0x00000100
+#define FXFA_DATASETS 0x00001000
+#define FXFA_XMPMETA 0x00010000
+#define FXFA_XFDF 0x00100000
+#define FXFA_FORM 0x01000000
+#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() {
+ if (m_pJSContext && m_pDocument->GetSDKDoc() &&
+ m_pDocument->GetSDKDoc()->GetEnv())
+ m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime()->ReleaseContext(
+ m_pJSContext);
+}
+
+void CPDFXFA_DocEnvironment::SetChangeMark(CXFA_FFDoc* hDoc) {
+ if (hDoc == m_pDocument->GetXFADoc() && m_pDocument->GetSDKDoc())
+ m_pDocument->GetSDKDoc()->SetChangeMark();
+}
+
+void CPDFXFA_DocEnvironment::InvalidateRect(CXFA_FFPageView* pPageView,
+ const CFX_RectF& rt,
+ uint32_t dwFlags /* = 0 */) {
+ if (!m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return;
+
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA)
+ return;
+
+ CPDFXFA_Page* pPage = m_pDocument->GetPage(pPageView);
+ if (!pPage)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return;
+
+ CFX_FloatRect rcPage = CFX_FloatRect::FromCFXRectF(rt);
+ pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom,
+ rcPage.right, rcPage.top);
+}
+
+void CPDFXFA_DocEnvironment::DisplayCaret(CXFA_FFWidget* hWidget,
+ FX_BOOL bVisible,
+ const CFX_RectF* pRtAnchor) {
+ if (!hWidget || !pRtAnchor || !m_pDocument->GetXFADoc() ||
+ !m_pDocument->GetSDKDoc() || !m_pDocument->GetXFADocView())
+ return;
+
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA)
+ return;
+
+ CXFA_FFWidgetHandler* pWidgetHandler =
+ m_pDocument->GetXFADocView()->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return;
+
+ CXFA_FFPageView* pPageView = hWidget->GetPageView();
+ if (!pPageView)
+ return;
+
+ CPDFXFA_Page* pPage = m_pDocument->GetPage(pPageView);
+ if (!pPage)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return;
+
+ CFX_FloatRect rcCaret = CFX_FloatRect::FromCFXRectF(*pRtAnchor);
+ pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top,
+ rcCaret.right, rcCaret.bottom);
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::GetPopupPos(CXFA_FFWidget* hWidget,
+ FX_FLOAT fMinPopup,
+ FX_FLOAT fMaxPopup,
+ const CFX_RectF& rtAnchor,
+ CFX_RectF& rtPopup) {
+ if (!hWidget)
+ return FALSE;
+
+ CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
+ if (!pXFAPageView)
+ return FALSE;
+
+ CPDFXFA_Page* pPage = m_pDocument->GetPage(pXFAPageView);
+ if (!pPage)
+ return FALSE;
+
+ CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
+ int nRotate = pWidgetAcc->GetRotate();
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return FALSE;
+
+ FS_RECTF pageViewRect = {0.0f, 0.0f, 0.0f, 0.0f};
+ pEnv->FFI_GetPageViewRect(pPage, pageViewRect);
+
+ int t1;
+ int t2;
+ CFX_FloatRect rcAnchor = CFX_FloatRect::FromCFXRectF(rtAnchor);
+ switch (nRotate) {
+ case 90: {
+ t1 = (int)(pageViewRect.right - rcAnchor.right);
+ t2 = (int)(rcAnchor.left - pageViewRect.left);
+ if (rcAnchor.bottom < pageViewRect.bottom)
+ rtPopup.left += rcAnchor.bottom - pageViewRect.bottom;
+ break;
+ }
+ case 180: {
+ t2 = (int)(pageViewRect.top - rcAnchor.top);
+ t1 = (int)(rcAnchor.bottom - pageViewRect.bottom);
+ if (rcAnchor.left < pageViewRect.left)
+ rtPopup.left += rcAnchor.left - pageViewRect.left;
+ break;
+ }
+ case 270: {
+ t1 = (int)(rcAnchor.left - pageViewRect.left);
+ t2 = (int)(pageViewRect.right - rcAnchor.right);
+ if (rcAnchor.top > pageViewRect.top)
+ rtPopup.left -= rcAnchor.top - pageViewRect.top;
+ break;
+ }
+ case 0:
+ default: {
+ t1 = (int)(pageViewRect.top - rcAnchor.top);
+ t2 = (int)(rcAnchor.bottom - pageViewRect.bottom);
+ if (rcAnchor.right > pageViewRect.right)
+ rtPopup.left -= rcAnchor.right - pageViewRect.right;
+ break;
+ }
+ }
+
+ int t;
+ uint32_t dwPos;
+ if (t1 <= 0 && t2 <= 0)
+ return FALSE;
+ if (t1 <= 0) {
+ t = t2;
+ dwPos = 1;
+ } else if (t2 <= 0) {
+ t = t1;
+ dwPos = 0;
+ } else if (t1 > t2) {
+ t = t1;
+ dwPos = 0;
+ } else {
+ t = t2;
+ dwPos = 1;
+ }
+
+ FX_FLOAT fPopupHeight;
+ if (t < fMinPopup)
+ fPopupHeight = fMinPopup;
+ else if (t > fMaxPopup)
+ fPopupHeight = fMaxPopup;
+ else
+ fPopupHeight = static_cast<FX_FLOAT>(t);
+
+ switch (nRotate) {
+ case 0:
+ case 180: {
+ if (dwPos == 0) {
+ rtPopup.top = rtAnchor.height;
+ rtPopup.height = fPopupHeight;
+ } else {
+ rtPopup.top = -fPopupHeight;
+ rtPopup.height = fPopupHeight;
+ }
+ break;
+ }
+ case 90:
+ case 270: {
+ if (dwPos == 0) {
+ rtPopup.top = rtAnchor.width;
+ rtPopup.height = fPopupHeight;
+ } else {
+ rtPopup.top = -fPopupHeight;
+ rtPopup.height = fPopupHeight;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::PopupMenu(CXFA_FFWidget* hWidget,
+ CFX_PointF ptPopup) {
+ if (!hWidget)
+ return FALSE;
+
+ CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
+ if (!pXFAPageView)
+ return FALSE;
+
+ CPDFXFA_Page* pPage = m_pDocument->GetPage(pXFAPageView);
+ if (!pPage)
+ return FALSE;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return FALSE;
+
+ int menuFlag = 0;
+ if (hWidget->CanUndo())
+ menuFlag |= FXFA_MENU_UNDO;
+ if (hWidget->CanRedo())
+ menuFlag |= FXFA_MENU_REDO;
+ if (hWidget->CanPaste())
+ menuFlag |= FXFA_MENU_PASTE;
+ if (hWidget->CanCopy())
+ menuFlag |= FXFA_MENU_COPY;
+ if (hWidget->CanCut())
+ menuFlag |= FXFA_MENU_CUT;
+ if (hWidget->CanSelectAll())
+ menuFlag |= FXFA_MENU_SELECTALL;
+
+ return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, nullptr);
+}
+
+void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView,
+ uint32_t dwFlags) {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return;
+
+ if (m_pDocument->GetLoadStatus() == FXFA_LOADSTATUS_LOADING ||
+ m_pDocument->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING ||
+ XFA_PAGEVIEWEVENT_StopLayout != dwFlags)
+ return;
+
+ int nNewCount = m_pDocument->GetPageCount();
+ if (nNewCount == m_pDocument->GetOriginalPageCount())
+ return;
+
+ CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView();
+ if (!pXFADocView)
+ return;
+
+ for (int iPageIter = 0; iPageIter < m_pDocument->GetOriginalPageCount();
+ iPageIter++) {
+ CPDFXFA_Page* pPage = m_pDocument->GetXFAPageList()->GetAt(iPageIter);
+ if (!pPage)
+ continue;
+
+ m_pDocument->GetSDKDoc()->RemovePageView(pPage);
+ pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter));
+ }
+
+ int flag = (nNewCount < m_pDocument->GetOriginalPageCount())
+ ? FXFA_PAGEVIEWEVENT_POSTREMOVED
+ : FXFA_PAGEVIEWEVENT_POSTADDED;
+ int count = FXSYS_abs(nNewCount - m_pDocument->GetOriginalPageCount());
+ m_pDocument->SetOriginalPageCount(nNewCount);
+ pEnv->FFI_PageEvent(count, flag);
+}
+
+void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget,
+ CXFA_WidgetAcc* pWidgetData) {
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget)
+ return;
+
+ CXFA_FFPageView* pPageView = hWidget->GetPageView();
+ if (!pPageView)
+ return;
+
+ CPDFXFA_Page* pXFAPage = m_pDocument->GetPage(pPageView);
+ if (!pXFAPage)
+ return;
+
+ m_pDocument->GetSDKDoc()->GetPageView(pXFAPage, true)->AddAnnot(hWidget);
+}
+
+void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget,
+ CXFA_WidgetAcc* pWidgetData) {
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || !hWidget)
+ return;
+
+ CXFA_FFPageView* pPageView = hWidget->GetPageView();
+ if (!pPageView)
+ return;
+
+ CPDFXFA_Page* pXFAPage = m_pDocument->GetPage(pPageView);
+ if (!pXFAPage)
+ return;
+
+ CPDFSDK_PageView* pSdkPageView =
+ m_pDocument->GetSDKDoc()->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->GetSDKDoc())
+ return m_pDocument->GetPageCount();
+ return 0;
+}
+
+int32_t CPDFXFA_DocEnvironment::GetCurrentPage(CXFA_FFDoc* hDoc) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return -1;
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA)
+ return -1;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return -1;
+
+ return pEnv->FFI_GetCurrentPageIndex(this);
+}
+
+void CPDFXFA_DocEnvironment::SetCurrentPage(CXFA_FFDoc* hDoc,
+ int32_t iCurPage) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc() ||
+ m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 ||
+ iCurPage >= m_pDocument->GetSDKDoc()->GetPageCount()) {
+ return;
+ }
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return;
+ pEnv->FFI_SetCurrentPage(this, iCurPage);
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::IsCalculationsEnabled(CXFA_FFDoc* hDoc) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return FALSE;
+ if (m_pDocument->GetSDKDoc()->GetInterForm())
+ return m_pDocument->GetSDKDoc()->GetInterForm()->IsXfaCalculateEnabled();
+ return FALSE;
+}
+
+void CPDFXFA_DocEnvironment::SetCalculationsEnabled(CXFA_FFDoc* hDoc,
+ FX_BOOL bEnabled) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return;
+ if (m_pDocument->GetSDKDoc()->GetInterForm())
+ m_pDocument->GetSDKDoc()->GetInterForm()->XfaEnableCalculate(bEnabled);
+}
+
+void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc,
+ CFX_WideString& wsTitle) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetPDFDoc())
+ return;
+
+ CPDF_Dictionary* pInfoDict = m_pDocument->GetPDFDoc()->GetInfo();
+ if (!pInfoDict)
+ return;
+
+ CFX_ByteString csTitle = pInfoDict->GetStringBy("Title");
+ wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength()));
+ csTitle.ReleaseBuffer(csTitle.GetLength());
+}
+
+void CPDFXFA_DocEnvironment::SetTitle(CXFA_FFDoc* hDoc,
+ const CFX_WideString& wsTitle) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetPDFDoc())
+ return;
+
+ if (CPDF_Dictionary* pInfoDict = m_pDocument->GetPDFDoc()->GetInfo())
+ pInfoDict->SetAt("Title", new CPDF_String(wsTitle));
+}
+
+void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc,
+ const CFX_WideString& wsFilePath,
+ FX_BOOL bXDP) {
+ if (hDoc != m_pDocument->GetXFADoc())
+ return;
+
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA &&
+ m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return;
+
+ int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML;
+ CFX_ByteString bs = wsFilePath.UTF16LE_Encode();
+ if (wsFilePath.IsEmpty()) {
+ if (!pEnv->GetFormFillInfo() || !pEnv->GetFormFillInfo()->m_pJsPlatform)
+ return;
+
+ CFX_WideString filepath = pEnv->JS_fieldBrowse();
+ bs = filepath.UTF16LE_Encode();
+ }
+ int len = bs.GetLength();
+ FPDF_FILEHANDLER* pFileHandler =
+ pEnv->FFI_OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML,
+ (FPDF_WIDESTRING)bs.GetBuffer(len), "wb");
+ bs.ReleaseBuffer(len);
+ if (!pFileHandler)
+ return;
+
+ CFPDF_FileStream fileWrite(pFileHandler);
+ CFX_ByteString content;
+ if (fileType == FXFA_SAVEAS_XML) {
+ content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
+ fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(),
+ content.GetLength());
+ m_pDocument->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data,
+ &fileWrite, nullptr);
+ } else if (fileType == FXFA_SAVEAS_XDP) {
+ if (!m_pDocument->GetPDFDoc())
+ return;
+
+ CPDF_Dictionary* pRoot = m_pDocument->GetPDFDoc()->GetRoot();
+ if (!pRoot)
+ return;
+
+ CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
+ if (!pAcroForm)
+ return;
+
+ CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA"));
+ if (!pArray)
+ return;
+
+ int size = pArray->GetCount();
+ for (int i = 1; i < size; i += 2) {
+ CPDF_Object* pPDFObj = pArray->GetObjectAt(i);
+ CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1);
+ if (!pPrePDFObj->IsString())
+ continue;
+ if (!pPDFObj->IsReference())
+ continue;
+
+ CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect());
+ if (!pStream)
+ continue;
+ if (pPrePDFObj->GetString() == "form") {
+ m_pDocument->GetXFADocView()->GetDoc()->SavePackage(
+ XFA_HASHCODE_Form, &fileWrite, nullptr);
+ continue;
+ }
+ if (pPrePDFObj->GetString() == "datasets") {
+ m_pDocument->GetXFADocView()->GetDoc()->SavePackage(
+ XFA_HASHCODE_Datasets, &fileWrite, nullptr);
+ continue;
+ }
+ if (i == size - 1) {
+ CFX_WideString wPath = CFX_WideString::FromUTF16LE(
+ reinterpret_cast<const unsigned short*>(bs.c_str()),
+ bs.GetLength() / sizeof(unsigned short));
+ CFX_ByteString bPath = wPath.UTF8Encode();
+ const char* szFormat =
+ "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
+ content.Format(szFormat, bPath.c_str());
+ fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(),
+ content.GetLength());
+ }
+ std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc);
+ pAcc->LoadAllData(pStream);
+ fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(),
+ pAcc->GetSize());
+ }
+ }
+ if (!fileWrite.Flush()) {
+ // Ignoring flush error.
+ }
+}
+
+void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc,
+ const CFX_WideString& bsURL,
+ FX_BOOL bAppend) {
+ if (hDoc != m_pDocument->GetXFADoc())
+ return;
+
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return;
+
+ CFX_WideStringC str(bsURL.c_str());
+
+ pEnv->FFI_GotoURL(this, str, bAppend);
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::IsValidationsEnabled(CXFA_FFDoc* hDoc) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return FALSE;
+ if (m_pDocument->GetSDKDoc()->GetInterForm())
+ return m_pDocument->GetSDKDoc()->GetInterForm()->IsXfaValidationsEnabled();
+ return TRUE;
+}
+
+void CPDFXFA_DocEnvironment::SetValidationsEnabled(CXFA_FFDoc* hDoc,
+ FX_BOOL bEnabled) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return;
+ if (m_pDocument->GetSDKDoc()->GetInterForm())
+ m_pDocument->GetSDKDoc()->GetInterForm()->XfaSetValidationsEnabled(
+ bEnabled);
+}
+
+void CPDFXFA_DocEnvironment::SetFocusWidget(CXFA_FFDoc* hDoc,
+ CXFA_FFWidget* hWidget) {
+ if (hDoc != m_pDocument->GetXFADoc())
+ return;
+
+ if (!hWidget) {
+ m_pDocument->GetSDKDoc()->SetFocusAnnot(nullptr);
+ return;
+ }
+
+ int pageViewCount = m_pDocument->GetSDKDoc()->GetPageViewCount();
+ for (int i = 0; i < pageViewCount; i++) {
+ CPDFSDK_PageView* pPageView = m_pDocument->GetSDKDoc()->GetPageView(i);
+ if (!pPageView)
+ continue;
+
+ CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget);
+ if (pAnnot) {
+ m_pDocument->GetSDKDoc()->SetFocusAnnot(pAnnot);
+ break;
+ }
+ }
+}
+
+void CPDFXFA_DocEnvironment::Print(CXFA_FFDoc* hDoc,
+ int32_t nStartPage,
+ int32_t nEndPage,
+ uint32_t dwOptions) {
+ if (hDoc != m_pDocument->GetXFADoc())
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv || !pEnv->GetFormFillInfo() ||
+ !pEnv->GetFormFillInfo()->m_pJsPlatform ||
+ !pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print) {
+ return;
+ }
+
+ pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print(
+ pEnv->GetFormFillInfo()->m_pJsPlatform,
+ dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage,
+ dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage,
+ dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder,
+ dwOptions & XFA_PRINTOPT_PrintAnnot);
+}
+
+FX_ARGB CPDFXFA_DocEnvironment::GetHighlightColor(CXFA_FFDoc* hDoc) {
+ if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetSDKDoc())
+ return 0;
+
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetSDKDoc()->GetInterForm();
+ if (!pInterForm)
+ return 0;
+
+ return ArgbEncode(pInterForm->GetHighlightAlpha(),
+ pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA));
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::NotifySubmit(FX_BOOL bPrevOrPost) {
+ if (bPrevOrPost)
+ return OnBeforeNotifySubmit();
+
+ OnAfterNotifySubmit();
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() {
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA &&
+ m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
+ return TRUE;
+
+ if (!m_pDocument->GetXFADocView())
+ return TRUE;
+
+ CXFA_FFWidgetHandler* pWidgetHandler =
+ m_pDocument->GetXFADocView()->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return TRUE;
+
+ std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator(
+ m_pDocument->GetXFADocView()->CreateWidgetAccIterator());
+ if (pWidgetAccIterator) {
+ CXFA_EventParam Param;
+ Param.m_eType = XFA_EVENT_PreSubmit;
+ while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext())
+ pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
+ }
+
+ pWidgetAccIterator.reset(
+ m_pDocument->GetXFADocView()->CreateWidgetAccIterator());
+ if (!pWidgetAccIterator)
+ return TRUE;
+
+ CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while (pWidgetAcc) {
+ int fRet = pWidgetAcc->ProcessValidate(-1);
+ if (fRet == XFA_EVENTERROR_Error) {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return FALSE;
+
+ CFX_WideString ws;
+ ws.FromLocal(IDS_XFA_Validate_Input);
+ CFX_ByteString bs = ws.UTF16LE_Encode();
+ int len = bs.GetLength();
+ pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"",
+ 0, 1);
+ bs.ReleaseBuffer(len);
+ return FALSE;
+ }
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ m_pDocument->GetXFADocView()->UpdateDocView();
+
+ return TRUE;
+}
+
+void CPDFXFA_DocEnvironment::OnAfterNotifySubmit() {
+ if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA &&
+ m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
+ return;
+
+ if (!m_pDocument->GetXFADocView())
+ return;
+
+ CXFA_FFWidgetHandler* pWidgetHandler =
+ m_pDocument->GetXFADocView()->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return;
+
+ std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator(
+ m_pDocument->GetXFADocView()->CreateWidgetAccIterator());
+ if (!pWidgetAccIterator)
+ return;
+
+ CXFA_EventParam Param;
+ Param.m_eType = XFA_EVENT_PostSubmit;
+ CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while (pWidgetAcc) {
+ pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ m_pDocument->GetXFADocView()->UpdateDocView();
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::SubmitData(CXFA_FFDoc* hDoc,
+ CXFA_Submit submit) {
+ if (!NotifySubmit(TRUE) || !m_pDocument->GetXFADocView())
+ return FALSE;
+
+ m_pDocument->GetXFADocView()->UpdateDocView();
+ FX_BOOL ret = SubmitDataInternal(hDoc, submit);
+ NotifySubmit(FALSE);
+ return ret;
+}
+
+IFX_FileRead* CPDFXFA_DocEnvironment::OpenLinkedFile(
+ CXFA_FFDoc* hDoc,
+ const CFX_WideString& wsLink) {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return FALSE;
+
+ CFX_ByteString bs = wsLink.UTF16LE_Encode();
+ int len = bs.GetLength();
+ FPDF_FILEHANDLER* pFileHandler =
+ pEnv->FFI_OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb");
+ bs.ReleaseBuffer(len);
+
+ if (!pFileHandler)
+ return nullptr;
+ return new CFPDF_FileStream(pFileHandler);
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler,
+ int fileType,
+ FPDF_DWORD encodeType,
+ FPDF_DWORD flag) {
+ if (!m_pDocument->GetXFADocView())
+ return FALSE;
+
+ CFX_ByteString content;
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return FALSE;
+
+ CFPDF_FileStream fileStream(pFileHandler);
+ if (fileType == FXFA_SAVEAS_XML) {
+ const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
+ fileStream.WriteBlock(kContent, 0, strlen(kContent));
+ m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, &fileStream,
+ nullptr);
+ return TRUE;
+ }
+
+ if (fileType != FXFA_SAVEAS_XDP)
+ return TRUE;
+
+ if (!flag) {
+ flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
+ FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
+ }
+ if (!m_pDocument->GetPDFDoc()) {
+ fileStream.Flush();
+ return FALSE;
+ }
+
+ CPDF_Dictionary* pRoot = m_pDocument->GetPDFDoc()->GetRoot();
+ if (!pRoot) {
+ fileStream.Flush();
+ return FALSE;
+ }
+
+ CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
+ if (!pAcroForm) {
+ fileStream.Flush();
+ return FALSE;
+ }
+
+ CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA"));
+ if (!pArray) {
+ fileStream.Flush();
+ return FALSE;
+ }
+
+ int size = pArray->GetCount();
+ for (int i = 1; i < size; i += 2) {
+ CPDF_Object* pPDFObj = pArray->GetObjectAt(i);
+ CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1);
+ if (!pPrePDFObj->IsString())
+ continue;
+ if (!pPDFObj->IsReference())
+ continue;
+
+ CPDF_Object* pDirectObj = pPDFObj->GetDirect();
+ if (!pDirectObj->IsStream())
+ continue;
+ if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG))
+ continue;
+ if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE))
+ continue;
+ if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET))
+ continue;
+ if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS))
+ continue;
+ if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA))
+ continue;
+ if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF))
+ continue;
+ if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM))
+ continue;
+ if (pPrePDFObj->GetString() == "form") {
+ m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, &fileStream,
+ nullptr);
+ } else if (pPrePDFObj->GetString() == "datasets") {
+ m_pDocument->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, &fileStream,
+ nullptr);
+ } else {
+ // PDF,creator.
+ }
+ }
+ return TRUE;
+}
+
+void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent,
+ FPDF_DWORD& flag) {
+ if (csSrcContent.Find(L" config ", 0) != -1)
+ flag |= FXFA_CONFIG;
+ if (csSrcContent.Find(L" template ", 0) != -1)
+ flag |= FXFA_TEMPLATE;
+ if (csSrcContent.Find(L" localeSet ", 0) != -1)
+ flag |= FXFA_LOCALESET;
+ if (csSrcContent.Find(L" datasets ", 0) != -1)
+ flag |= FXFA_DATASETS;
+ if (csSrcContent.Find(L" xmpmeta ", 0) != -1)
+ flag |= FXFA_XMPMETA;
+ if (csSrcContent.Find(L" xfdf ", 0) != -1)
+ flag |= FXFA_XFDF;
+ if (csSrcContent.Find(L" form ", 0) != -1)
+ flag |= FXFA_FORM;
+ if (flag == 0) {
+ flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
+ FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
+ }
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::MailToInfo(CFX_WideString& csURL,
+ CFX_WideString& csToAddress,
+ CFX_WideString& csCCAddress,
+ CFX_WideString& csBCCAddress,
+ CFX_WideString& csSubject,
+ CFX_WideString& csMsg) {
+ CFX_WideString srcURL = csURL;
+ srcURL.TrimLeft();
+ if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0)
+ return FALSE;
+
+ int pos = srcURL.Find(L'?', 0);
+ CFX_WideString tmp;
+ if (pos == -1) {
+ pos = srcURL.Find(L'@', 0);
+ if (pos == -1)
+ return FALSE;
+
+ tmp = srcURL.Right(csURL.GetLength() - 7);
+ } else {
+ tmp = srcURL.Left(pos);
+ tmp = tmp.Right(tmp.GetLength() - 7);
+ }
+ tmp.TrimLeft();
+ tmp.TrimRight();
+
+ csToAddress = tmp;
+
+ srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1));
+ while (!srcURL.IsEmpty()) {
+ srcURL.TrimLeft();
+ srcURL.TrimRight();
+ pos = srcURL.Find(L'&', 0);
+
+ tmp = (pos == -1) ? srcURL : srcURL.Left(pos);
+ tmp.TrimLeft();
+ tmp.TrimRight();
+ if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) {
+ tmp = tmp.Right(tmp.GetLength() - 3);
+ if (!csCCAddress.IsEmpty())
+ csCCAddress += L';';
+ csCCAddress += tmp;
+ } else if (tmp.GetLength() >= 4 &&
+ tmp.Left(4).CompareNoCase(L"bcc=") == 0) {
+ tmp = tmp.Right(tmp.GetLength() - 4);
+ if (!csBCCAddress.IsEmpty())
+ csBCCAddress += L';';
+ csBCCAddress += tmp;
+ } else if (tmp.GetLength() >= 8 &&
+ tmp.Left(8).CompareNoCase(L"subject=") == 0) {
+ tmp = tmp.Right(tmp.GetLength() - 8);
+ csSubject += tmp;
+ } else if (tmp.GetLength() >= 5 &&
+ tmp.Left(5).CompareNoCase(L"body=") == 0) {
+ tmp = tmp.Right(tmp.GetLength() - 5);
+ csMsg += tmp;
+ }
+ srcURL = (pos == -1) ? L"" : srcURL.Right(csURL.GetLength() - (pos + 1));
+ }
+ csToAddress.Replace(L",", L";");
+ csCCAddress.Replace(L",", L";");
+ csBCCAddress.Replace(L",", L";");
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::SubmitDataInternal(CXFA_FFDoc* hDoc,
+ CXFA_Submit submit) {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetSDKDoc()->GetEnv();
+ if (!pEnv)
+ return FALSE;
+
+ CFX_WideStringC csURLC;
+ submit.GetSubmitTarget(csURLC);
+ CFX_WideString csURL(csURLC);
+ if (csURL.IsEmpty()) {
+ CFX_WideString ws;
+ ws.FromLocal("Submit cancelled.");
+ CFX_ByteString bs = ws.UTF16LE_Encode();
+ int len = bs.GetLength();
+ pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", 0,
+ 4);
+ bs.ReleaseBuffer(len);
+ return FALSE;
+ }
+
+ FPDF_BOOL bRet = TRUE;
+ FPDF_FILEHANDLER* pFileHandler = nullptr;
+ int fileFlag = -1;
+ switch (submit.GetSubmitFormat()) {
+ case XFA_ATTRIBUTEENUM_Xdp: {
+ CFX_WideStringC csContentC;
+ submit.GetSubmitXDPContent(csContentC);
+ CFX_WideString csContent;
+ csContent = csContentC;
+ csContent.TrimLeft();
+ csContent.TrimRight();
+ CFX_WideString space;
+ space.FromLocal(" ");
+ csContent = space + csContent + space;
+ FPDF_DWORD flag = 0;
+ if (submit.IsSubmitEmbedPDF())
+ flag |= FXFA_PDF;
+
+ ToXFAContentFlags(csContent, flag);
+ pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb");
+ fileFlag = FXFA_SAVEAS_XDP;
+ ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag);
+ break;
+ }
+ case XFA_ATTRIBUTEENUM_Xml:
+ pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb");
+ fileFlag = FXFA_SAVEAS_XML;
+ ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL);
+ break;
+ case XFA_ATTRIBUTEENUM_Pdf:
+ break;
+ case XFA_ATTRIBUTEENUM_Urlencoded:
+ pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb");
+ fileFlag = FXFA_SAVEAS_XML;
+ ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL);
+ break;
+ default:
+ return false;
+ }
+ if (!pFileHandler)
+ return FALSE;
+ if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) {
+ CFX_WideString csToAddress;
+ CFX_WideString csCCAddress;
+ CFX_WideString csBCCAddress;
+ CFX_WideString csSubject;
+ CFX_WideString csMsg;
+ bRet = MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject,
+ csMsg);
+ if (!bRet)
+ return FALSE;
+
+ CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode();
+ CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode();
+ CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode();
+ CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode();
+ CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode();
+ FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
+ FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
+ FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
+ FPDF_WIDESTRING pSubject =
+ (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
+ FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
+ pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg);
+ bsTo.ReleaseBuffer();
+ bsCC.ReleaseBuffer();
+ bsBcc.ReleaseBuffer();
+ bsSubject.ReleaseBuffer();
+ bsMsg.ReleaseBuffer();
+ } else {
+ // HTTP or FTP
+ CFX_WideString ws;
+ CFX_ByteString bs = csURL.UTF16LE_Encode();
+ int len = bs.GetLength();
+ pEnv->FFI_UploadTo(pFileHandler, fileFlag,
+ (FPDF_WIDESTRING)bs.GetBuffer(len));
+ bs.ReleaseBuffer(len);
+ }
+ return bRet;
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::SetGlobalProperty(
+ CXFA_FFDoc* hDoc,
+ const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* pValue) {
+ if (hDoc != m_pDocument->GetXFADoc())
+ return FALSE;
+
+ if (m_pDocument->GetSDKDoc() &&
+ m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime())
+ return m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime()->SetValueByName(
+ szPropName, pValue);
+ return FALSE;
+}
+
+FX_BOOL CPDFXFA_DocEnvironment::GetGlobalProperty(
+ CXFA_FFDoc* hDoc,
+ const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* pValue) {
+ if (hDoc != m_pDocument->GetXFADoc())
+ return FALSE;
+ if (!m_pDocument->GetSDKDoc() ||
+ !m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime())
+ return FALSE;
+
+ if (!m_pJSContext) {
+ m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime()->SetReaderDocument(
+ m_pDocument->GetSDKDoc());
+ m_pJSContext =
+ m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime()->NewContext();
+ }
+
+ return m_pDocument->GetSDKDoc()->GetEnv()->GetJSRuntime()->GetValueByName(
+ szPropName, pValue);
+}
diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
index 57de222e1c..6c691e6c9b 100644
--- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
+++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
@@ -6,10 +6,7 @@
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h"
@@ -25,24 +22,8 @@
#include "xfa/fxfa/include/xfa_ffdoc.h"
#include "xfa/fxfa/include/xfa_ffdocview.h"
#include "xfa/fxfa/include/xfa_ffpageview.h"
-#include "xfa/fxfa/include/xfa_ffwidget.h"
#include "xfa/fxfa/include/xfa_ffwidgethandler.h"
-#define IDS_XFA_Validate_Input \
- "At least one required field was empty. Please fill in the required " \
- "fields\r\n(highlighted) before continuing."
-
-// submit
-#define FXFA_CONFIG 0x00000001
-#define FXFA_TEMPLATE 0x00000010
-#define FXFA_LOCALESET 0x00000100
-#define FXFA_DATASETS 0x00001000
-#define FXFA_XMPMETA 0x00010000
-#define FXFA_XFDF 0x00100000
-#define FXFA_FORM 0x01000000
-#define FXFA_PDF 0x10000000
-#define FXFA_XFA_ALL 0x01111111
-
#ifndef _WIN32
extern void SetLastError(int err);
extern int GetLastError();
@@ -54,9 +35,9 @@ CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
m_pPDFDoc(std::move(pPDFDoc)),
m_pXFADocView(nullptr),
m_pApp(pProvider),
- m_pJSContext(nullptr),
m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD),
- m_nPageCount(0) {}
+ m_nPageCount(0),
+ m_DocEnv(this) {}
CPDFXFA_Document::~CPDFXFA_Document() {
m_nLoadStatus = FXFA_LOADSTATUS_CLOSING;
@@ -70,8 +51,6 @@ CPDFXFA_Document::~CPDFXFA_Document() {
}
m_pXFADoc.reset();
}
- if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv())
- m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext);
m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
}
@@ -88,7 +67,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() {
if (!pApp)
return FALSE;
- m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc.get()));
+ m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get()));
if (!m_pXFADoc) {
SetLastError(FPDF_ERR_XFALOAD);
return FALSE;
@@ -219,958 +198,7 @@ CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument(
return m_pSDKDoc.get();
}
-void CPDFXFA_Document::SetChangeMark(CXFA_FFDoc* hDoc) {
- if (hDoc == m_pXFADoc.get() && m_pSDKDoc)
- m_pSDKDoc->SetChangeMark();
-}
-
-void CPDFXFA_Document::InvalidateRect(CXFA_FFPageView* pPageView,
- const CFX_RectF& rt,
- uint32_t dwFlags /* = 0 */) {
- if (!m_pXFADoc || !m_pSDKDoc)
- return;
-
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
- return;
-
- CPDFXFA_Page* pPage = GetPage(pPageView);
- if (!pPage)
- return;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return;
-
- CFX_FloatRect rcPage = CFX_FloatRect::FromCFXRectF(rt);
- pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom,
- rcPage.right, rcPage.top);
-}
-
-void CPDFXFA_Document::DisplayCaret(CXFA_FFWidget* hWidget,
- FX_BOOL bVisible,
- const CFX_RectF* pRtAnchor) {
- if (!hWidget || !pRtAnchor || !m_pXFADoc || !m_pSDKDoc || !m_pXFADocView)
- return;
-
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
- return;
-
- CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
- if (!pWidgetHandler)
- return;
-
- CXFA_FFPageView* pPageView = hWidget->GetPageView();
- if (!pPageView)
- return;
-
- CPDFXFA_Page* pPage = GetPage(pPageView);
- if (!pPage)
- return;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return;
-
- CFX_FloatRect rcCaret = CFX_FloatRect::FromCFXRectF(*pRtAnchor);
- pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top,
- rcCaret.right, rcCaret.bottom);
-}
-
-FX_BOOL CPDFXFA_Document::GetPopupPos(CXFA_FFWidget* hWidget,
- FX_FLOAT fMinPopup,
- FX_FLOAT fMaxPopup,
- const CFX_RectF& rtAnchor,
- CFX_RectF& rtPopup) {
- if (!hWidget)
- return FALSE;
-
- CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
- if (!pXFAPageView)
- return FALSE;
-
- CPDFXFA_Page* pPage = GetPage(pXFAPageView);
- if (!pPage)
- return FALSE;
-
- CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
- int nRotate = pWidgetAcc->GetRotate();
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return FALSE;
-
- FS_RECTF pageViewRect = {0.0f, 0.0f, 0.0f, 0.0f};
- pEnv->FFI_GetPageViewRect(pPage, pageViewRect);
-
- int t1;
- int t2;
- CFX_FloatRect rcAnchor = CFX_FloatRect::FromCFXRectF(rtAnchor);
- switch (nRotate) {
- case 90: {
- t1 = (int)(pageViewRect.right - rcAnchor.right);
- t2 = (int)(rcAnchor.left - pageViewRect.left);
- if (rcAnchor.bottom < pageViewRect.bottom)
- rtPopup.left += rcAnchor.bottom - pageViewRect.bottom;
- break;
- }
- case 180: {
- t2 = (int)(pageViewRect.top - rcAnchor.top);
- t1 = (int)(rcAnchor.bottom - pageViewRect.bottom);
- if (rcAnchor.left < pageViewRect.left)
- rtPopup.left += rcAnchor.left - pageViewRect.left;
- break;
- }
- case 270: {
- t1 = (int)(rcAnchor.left - pageViewRect.left);
- t2 = (int)(pageViewRect.right - rcAnchor.right);
- if (rcAnchor.top > pageViewRect.top)
- rtPopup.left -= rcAnchor.top - pageViewRect.top;
- break;
- }
- case 0:
- default: {
- t1 = (int)(pageViewRect.top - rcAnchor.top);
- t2 = (int)(rcAnchor.bottom - pageViewRect.bottom);
- if (rcAnchor.right > pageViewRect.right)
- rtPopup.left -= rcAnchor.right - pageViewRect.right;
- break;
- }
- }
-
- int t;
- uint32_t dwPos;
- if (t1 <= 0 && t2 <= 0)
- return FALSE;
- if (t1 <= 0) {
- t = t2;
- dwPos = 1;
- } else if (t2 <= 0) {
- t = t1;
- dwPos = 0;
- } else if (t1 > t2) {
- t = t1;
- dwPos = 0;
- } else {
- t = t2;
- dwPos = 1;
- }
-
- FX_FLOAT fPopupHeight;
- if (t < fMinPopup)
- fPopupHeight = fMinPopup;
- else if (t > fMaxPopup)
- fPopupHeight = fMaxPopup;
- else
- fPopupHeight = static_cast<FX_FLOAT>(t);
-
- switch (nRotate) {
- case 0:
- case 180: {
- if (dwPos == 0) {
- rtPopup.top = rtAnchor.height;
- rtPopup.height = fPopupHeight;
- } else {
- rtPopup.top = -fPopupHeight;
- rtPopup.height = fPopupHeight;
- }
- break;
- }
- case 90:
- case 270: {
- if (dwPos == 0) {
- rtPopup.top = rtAnchor.width;
- rtPopup.height = fPopupHeight;
- } else {
- rtPopup.top = -fPopupHeight;
- rtPopup.height = fPopupHeight;
- }
- break;
- }
- default:
- break;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFXFA_Document::PopupMenu(CXFA_FFWidget* hWidget,
- CFX_PointF ptPopup) {
- if (!hWidget)
- return FALSE;
-
- CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
- if (!pXFAPageView)
- return FALSE;
-
- CPDFXFA_Page* pPage = GetPage(pXFAPageView);
- if (!pPage)
- return FALSE;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return FALSE;
-
- int menuFlag = 0;
- if (hWidget->CanUndo())
- menuFlag |= FXFA_MENU_UNDO;
- if (hWidget->CanRedo())
- menuFlag |= FXFA_MENU_REDO;
- if (hWidget->CanPaste())
- menuFlag |= FXFA_MENU_PASTE;
- if (hWidget->CanCopy())
- menuFlag |= FXFA_MENU_COPY;
- if (hWidget->CanCut())
- menuFlag |= FXFA_MENU_CUT;
- if (hWidget->CanSelectAll())
- menuFlag |= FXFA_MENU_SELECTALL;
-
- return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, nullptr);
-}
-
-void CPDFXFA_Document::PageViewEvent(CXFA_FFPageView* pPageView,
- uint32_t dwFlags) {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return;
-
- if (m_nLoadStatus == FXFA_LOADSTATUS_LOADING ||
- m_nLoadStatus == FXFA_LOADSTATUS_CLOSING ||
- XFA_PAGEVIEWEVENT_StopLayout != dwFlags)
- return;
-
- int nNewCount = GetPageCount();
- if (nNewCount == m_nPageCount)
- return;
-
- CXFA_FFDocView* pXFADocView = GetXFADocView();
- if (!pXFADocView)
- return;
-
- for (int iPageIter = 0; iPageIter < m_nPageCount; iPageIter++) {
- CPDFXFA_Page* pPage = m_XFAPageList.GetAt(iPageIter);
- if (!pPage)
- continue;
-
- m_pSDKDoc->RemovePageView(pPage);
- pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter));
- }
-
- int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED
- : FXFA_PAGEVIEWEVENT_POSTADDED;
- int count = FXSYS_abs(nNewCount - m_nPageCount);
- m_nPageCount = nNewCount;
- m_XFAPageList.SetSize(nNewCount);
- pEnv->FFI_PageEvent(count, flag);
-}
-
-void CPDFXFA_Document::WidgetPostAdd(CXFA_FFWidget* hWidget,
- CXFA_WidgetAcc* pWidgetData) {
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget)
- return;
-
- CXFA_FFPageView* pPageView = hWidget->GetPageView();
- if (!pPageView)
- return;
-
- CPDFXFA_Page* pXFAPage = GetPage(pPageView);
- if (!pXFAPage)
- return;
-
- m_pSDKDoc->GetPageView(pXFAPage, true)->AddAnnot(hWidget);
-}
-
-void CPDFXFA_Document::WidgetPreRemove(CXFA_FFWidget* hWidget,
- CXFA_WidgetAcc* pWidgetData) {
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget)
- return;
-
- CXFA_FFPageView* pPageView = hWidget->GetPageView();
- if (!pPageView)
- return;
-
- CPDFXFA_Page* pXFAPage = GetPage(pPageView);
- if (!pXFAPage)
- return;
-
- CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage, true);
- if (CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget))
- pSdkPageView->DeleteAnnot(pAnnot);
-}
-
-int32_t CPDFXFA_Document::CountPages(CXFA_FFDoc* hDoc) {
- if (hDoc == m_pXFADoc.get() && m_pSDKDoc)
- return GetPageCount();
- return 0;
-}
-
-int32_t CPDFXFA_Document::GetCurrentPage(CXFA_FFDoc* hDoc) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc)
- return -1;
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
- return -1;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return -1;
-
- return pEnv->FFI_GetCurrentPageIndex(this);
-}
-
-void CPDFXFA_Document::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc ||
- m_iDocType != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 ||
- iCurPage >= m_pSDKDoc->GetPageCount()) {
- return;
- }
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return;
- pEnv->FFI_SetCurrentPage(this, iCurPage);
-}
-
-FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(CXFA_FFDoc* hDoc) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc)
- return FALSE;
- if (m_pSDKDoc->GetInterForm())
- return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled();
- return FALSE;
-}
-
-void CPDFXFA_Document::SetCalculationsEnabled(CXFA_FFDoc* hDoc,
- FX_BOOL bEnabled) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc)
- return;
- if (m_pSDKDoc->GetInterForm())
- m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled);
-}
-
-void CPDFXFA_Document::GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) {
- if (hDoc != m_pXFADoc.get() || !m_pPDFDoc)
- return;
-
- CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo();
- if (!pInfoDict)
- return;
-
- CFX_ByteString csTitle = pInfoDict->GetStringBy("Title");
- wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength()));
- csTitle.ReleaseBuffer(csTitle.GetLength());
-}
-
-void CPDFXFA_Document::SetTitle(CXFA_FFDoc* hDoc,
- const CFX_WideString& wsTitle) {
- if (hDoc != m_pXFADoc.get() || !m_pPDFDoc)
- return;
-
- if (CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo())
- pInfoDict->SetAt("Title", new CPDF_String(wsTitle));
-}
-
-void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc,
- const CFX_WideString& wsFilePath,
- FX_BOOL bXDP) {
- if (hDoc != m_pXFADoc.get())
- return;
-
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
- return;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return;
-
- int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML;
- CFX_ByteString bs = wsFilePath.UTF16LE_Encode();
- if (wsFilePath.IsEmpty()) {
- if (!pEnv->GetFormFillInfo() || !pEnv->GetFormFillInfo()->m_pJsPlatform)
- return;
-
- CFX_WideString filepath = pEnv->JS_fieldBrowse();
- bs = filepath.UTF16LE_Encode();
- }
- int len = bs.GetLength();
- FPDF_FILEHANDLER* pFileHandler =
- pEnv->FFI_OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML,
- (FPDF_WIDESTRING)bs.GetBuffer(len), "wb");
- bs.ReleaseBuffer(len);
- if (!pFileHandler)
- return;
-
- CFPDF_FileStream fileWrite(pFileHandler);
- CFX_ByteString content;
- if (fileType == FXFA_SAVEAS_XML) {
- content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
- fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(),
- content.GetLength());
- m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite,
- nullptr);
- } else if (fileType == FXFA_SAVEAS_XDP) {
- if (!m_pPDFDoc)
- return;
-
- CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
- if (!pRoot)
- return;
-
- CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
- if (!pAcroForm)
- return;
-
- CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA"));
- if (!pArray)
- return;
-
- int size = pArray->GetCount();
- for (int i = 1; i < size; i += 2) {
- CPDF_Object* pPDFObj = pArray->GetObjectAt(i);
- CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1);
- if (!pPrePDFObj->IsString())
- continue;
- if (!pPDFObj->IsReference())
- continue;
-
- CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect());
- if (!pStream)
- continue;
- if (pPrePDFObj->GetString() == "form") {
- m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, &fileWrite,
- nullptr);
- continue;
- }
- if (pPrePDFObj->GetString() == "datasets") {
- m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, &fileWrite,
- nullptr);
- continue;
- }
- if (i == size - 1) {
- CFX_WideString wPath = CFX_WideString::FromUTF16LE(
- reinterpret_cast<const unsigned short*>(bs.c_str()),
- bs.GetLength() / sizeof(unsigned short));
- CFX_ByteString bPath = wPath.UTF8Encode();
- const char* szFormat =
- "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
- content.Format(szFormat, bPath.c_str());
- fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(),
- content.GetLength());
- }
- std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc);
- pAcc->LoadAllData(pStream);
- fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(),
- pAcc->GetSize());
- }
- }
- if (!fileWrite.Flush()) {
- // Ignoring flush error.
- }
-}
-
-void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc,
- const CFX_WideString& bsURL,
- FX_BOOL bAppend) {
- if (hDoc != m_pXFADoc.get())
- return;
-
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
- return;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return;
-
- CFX_WideStringC str(bsURL.c_str());
-
- pEnv->FFI_GotoURL(this, str, bAppend);
-}
-
-FX_BOOL CPDFXFA_Document::IsValidationsEnabled(CXFA_FFDoc* hDoc) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc)
- return FALSE;
- if (m_pSDKDoc->GetInterForm())
- return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled();
- return TRUE;
-}
-
-void CPDFXFA_Document::SetValidationsEnabled(CXFA_FFDoc* hDoc,
- FX_BOOL bEnabled) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc)
- return;
- if (m_pSDKDoc->GetInterForm())
- m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled);
-}
-
-void CPDFXFA_Document::SetFocusWidget(CXFA_FFDoc* hDoc,
- CXFA_FFWidget* hWidget) {
- if (hDoc != m_pXFADoc.get())
- return;
-
- if (!hWidget) {
- m_pSDKDoc->SetFocusAnnot(nullptr);
- return;
- }
-
- int pageViewCount = m_pSDKDoc->GetPageViewCount();
- for (int i = 0; i < pageViewCount; i++) {
- CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i);
- if (!pPageView)
- continue;
-
- CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget);
- if (pAnnot) {
- m_pSDKDoc->SetFocusAnnot(pAnnot);
- break;
- }
- }
-}
-
-void CPDFXFA_Document::Print(CXFA_FFDoc* hDoc,
- int32_t nStartPage,
- int32_t nEndPage,
- uint32_t dwOptions) {
- if (hDoc != m_pXFADoc.get())
- return;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv || !pEnv->GetFormFillInfo() ||
- !pEnv->GetFormFillInfo()->m_pJsPlatform ||
- !pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print) {
- return;
- }
-
- pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print(
- pEnv->GetFormFillInfo()->m_pJsPlatform,
- dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage,
- dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage,
- dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder,
- dwOptions & XFA_PRINTOPT_PrintAnnot);
-}
-
-FX_ARGB CPDFXFA_Document::GetHighlightColor(CXFA_FFDoc* hDoc) {
- if (hDoc != m_pXFADoc.get() || !m_pSDKDoc)
- return 0;
-
- CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm();
- if (!pInterForm)
- return 0;
-
- return ArgbEncode(pInterForm->GetHighlightAlpha(),
- pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA));
-}
-
-FX_BOOL CPDFXFA_Document::NotifySubmit(FX_BOOL bPrevOrPost) {
- if (bPrevOrPost)
- return OnBeforeNotifySubmit();
-
- OnAfterNotifySubmit();
- return TRUE;
-}
-
-FX_BOOL CPDFXFA_Document::OnBeforeNotifySubmit() {
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
- return TRUE;
-
- if (!m_pXFADocView)
- return TRUE;
-
- CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
- if (!pWidgetHandler)
- return TRUE;
-
- std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator(
- m_pXFADocView->CreateWidgetAccIterator());
- if (pWidgetAccIterator) {
- CXFA_EventParam Param;
- Param.m_eType = XFA_EVENT_PreSubmit;
- while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext())
- pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
- }
-
- pWidgetAccIterator.reset(m_pXFADocView->CreateWidgetAccIterator());
- if (!pWidgetAccIterator)
- return TRUE;
-
- CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
- pWidgetAcc = pWidgetAccIterator->MoveToNext();
- while (pWidgetAcc) {
- int fRet = pWidgetAcc->ProcessValidate(-1);
- if (fRet == XFA_EVENTERROR_Error) {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return FALSE;
-
- CFX_WideString ws;
- ws.FromLocal(IDS_XFA_Validate_Input);
- CFX_ByteString bs = ws.UTF16LE_Encode();
- int len = bs.GetLength();
- pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"",
- 0, 1);
- bs.ReleaseBuffer(len);
- return FALSE;
- }
- pWidgetAcc = pWidgetAccIterator->MoveToNext();
- }
- m_pXFADocView->UpdateDocView();
-
- return TRUE;
-}
-
-void CPDFXFA_Document::OnAfterNotifySubmit() {
- if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
- return;
-
- if (!m_pXFADocView)
- return;
-
- CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
- if (!pWidgetHandler)
- return;
-
- std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator(
- m_pXFADocView->CreateWidgetAccIterator());
- if (!pWidgetAccIterator)
- return;
-
- CXFA_EventParam Param;
- Param.m_eType = XFA_EVENT_PostSubmit;
- CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
- while (pWidgetAcc) {
- pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
- pWidgetAcc = pWidgetAccIterator->MoveToNext();
- }
- m_pXFADocView->UpdateDocView();
-}
-
-FX_BOOL CPDFXFA_Document::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) {
- if (!NotifySubmit(TRUE) || !m_pXFADocView)
- return FALSE;
-
- m_pXFADocView->UpdateDocView();
- FX_BOOL ret = SubmitDataInternal(hDoc, submit);
- NotifySubmit(FALSE);
- return ret;
-}
-
-IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(CXFA_FFDoc* hDoc,
- const CFX_WideString& wsLink) {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return FALSE;
-
- CFX_ByteString bs = wsLink.UTF16LE_Encode();
- int len = bs.GetLength();
- FPDF_FILEHANDLER* pFileHandler =
- pEnv->FFI_OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb");
- bs.ReleaseBuffer(len);
-
- if (!pFileHandler)
- return nullptr;
- return new CFPDF_FileStream(pFileHandler);
-}
-
-FX_BOOL CPDFXFA_Document::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler,
- int fileType,
- FPDF_DWORD encodeType,
- FPDF_DWORD flag) {
- if (!m_pXFADocView)
- return FALSE;
-
- CFX_ByteString content;
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return FALSE;
-
- CFPDF_FileStream fileStream(pFileHandler);
- if (fileType == FXFA_SAVEAS_XML) {
- const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
- fileStream.WriteBlock(kContent, 0, strlen(kContent));
- m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr);
- return TRUE;
- }
-
- if (fileType != FXFA_SAVEAS_XDP)
- return TRUE;
-
- if (!flag) {
- flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
- FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
- }
- if (!m_pPDFDoc) {
- fileStream.Flush();
- return FALSE;
- }
-
- CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
- if (!pRoot) {
- fileStream.Flush();
- return FALSE;
- }
-
- CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
- if (!pAcroForm) {
- fileStream.Flush();
- return FALSE;
- }
-
- CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA"));
- if (!pArray) {
- fileStream.Flush();
- return FALSE;
- }
-
- int size = pArray->GetCount();
- for (int i = 1; i < size; i += 2) {
- CPDF_Object* pPDFObj = pArray->GetObjectAt(i);
- CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1);
- if (!pPrePDFObj->IsString())
- continue;
- if (!pPDFObj->IsReference())
- continue;
-
- CPDF_Object* pDirectObj = pPDFObj->GetDirect();
- if (!pDirectObj->IsStream())
- continue;
- if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG))
- continue;
- if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE))
- continue;
- if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET))
- continue;
- if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS))
- continue;
- if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA))
- continue;
- if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF))
- continue;
- if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM))
- continue;
- if (pPrePDFObj->GetString() == "form") {
- m_pXFADoc->SavePackage(XFA_HASHCODE_Form, &fileStream, nullptr);
- } else if (pPrePDFObj->GetString() == "datasets") {
- m_pXFADoc->SavePackage(XFA_HASHCODE_Datasets, &fileStream, nullptr);
- } else {
- // PDF,creator.
- }
- }
- return TRUE;
-}
-
void CPDFXFA_Document::ClearChangeMark() {
if (m_pSDKDoc)
m_pSDKDoc->ClearChangeMark();
}
-
-void CPDFXFA_Document::ToXFAContentFlags(CFX_WideString csSrcContent,
- FPDF_DWORD& flag) {
- if (csSrcContent.Find(L" config ", 0) != -1)
- flag |= FXFA_CONFIG;
- if (csSrcContent.Find(L" template ", 0) != -1)
- flag |= FXFA_TEMPLATE;
- if (csSrcContent.Find(L" localeSet ", 0) != -1)
- flag |= FXFA_LOCALESET;
- if (csSrcContent.Find(L" datasets ", 0) != -1)
- flag |= FXFA_DATASETS;
- if (csSrcContent.Find(L" xmpmeta ", 0) != -1)
- flag |= FXFA_XMPMETA;
- if (csSrcContent.Find(L" xfdf ", 0) != -1)
- flag |= FXFA_XFDF;
- if (csSrcContent.Find(L" form ", 0) != -1)
- flag |= FXFA_FORM;
- if (flag == 0) {
- flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
- FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
- }
-}
-
-FX_BOOL CPDFXFA_Document::MailToInfo(CFX_WideString& csURL,
- CFX_WideString& csToAddress,
- CFX_WideString& csCCAddress,
- CFX_WideString& csBCCAddress,
- CFX_WideString& csSubject,
- CFX_WideString& csMsg) {
- CFX_WideString srcURL = csURL;
- srcURL.TrimLeft();
- if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0)
- return FALSE;
-
- int pos = srcURL.Find(L'?', 0);
- CFX_WideString tmp;
- if (pos == -1) {
- pos = srcURL.Find(L'@', 0);
- if (pos == -1)
- return FALSE;
-
- tmp = srcURL.Right(csURL.GetLength() - 7);
- } else {
- tmp = srcURL.Left(pos);
- tmp = tmp.Right(tmp.GetLength() - 7);
- }
- tmp.TrimLeft();
- tmp.TrimRight();
-
- csToAddress = tmp;
-
- srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1));
- while (!srcURL.IsEmpty()) {
- srcURL.TrimLeft();
- srcURL.TrimRight();
- pos = srcURL.Find(L'&', 0);
-
- tmp = (pos == -1) ? srcURL : srcURL.Left(pos);
- tmp.TrimLeft();
- tmp.TrimRight();
- if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) {
- tmp = tmp.Right(tmp.GetLength() - 3);
- if (!csCCAddress.IsEmpty())
- csCCAddress += L';';
- csCCAddress += tmp;
- } else if (tmp.GetLength() >= 4 &&
- tmp.Left(4).CompareNoCase(L"bcc=") == 0) {
- tmp = tmp.Right(tmp.GetLength() - 4);
- if (!csBCCAddress.IsEmpty())
- csBCCAddress += L';';
- csBCCAddress += tmp;
- } else if (tmp.GetLength() >= 8 &&
- tmp.Left(8).CompareNoCase(L"subject=") == 0) {
- tmp = tmp.Right(tmp.GetLength() - 8);
- csSubject += tmp;
- } else if (tmp.GetLength() >= 5 &&
- tmp.Left(5).CompareNoCase(L"body=") == 0) {
- tmp = tmp.Right(tmp.GetLength() - 5);
- csMsg += tmp;
- }
- srcURL = (pos == -1) ? L"" : srcURL.Right(csURL.GetLength() - (pos + 1));
- }
- csToAddress.Replace(L",", L";");
- csCCAddress.Replace(L",", L";");
- csBCCAddress.Replace(L",", L";");
- return TRUE;
-}
-
-FX_BOOL CPDFXFA_Document::SubmitDataInternal(CXFA_FFDoc* hDoc,
- CXFA_Submit submit) {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (!pEnv)
- return FALSE;
-
- CFX_WideStringC csURLC;
- submit.GetSubmitTarget(csURLC);
- CFX_WideString csURL(csURLC);
- if (csURL.IsEmpty()) {
- CFX_WideString ws;
- ws.FromLocal("Submit cancelled.");
- CFX_ByteString bs = ws.UTF16LE_Encode();
- int len = bs.GetLength();
- pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", 0,
- 4);
- bs.ReleaseBuffer(len);
- return FALSE;
- }
-
- FPDF_BOOL bRet = TRUE;
- FPDF_FILEHANDLER* pFileHandler = nullptr;
- int fileFlag = -1;
- switch (submit.GetSubmitFormat()) {
- case XFA_ATTRIBUTEENUM_Xdp: {
- CFX_WideStringC csContentC;
- submit.GetSubmitXDPContent(csContentC);
- CFX_WideString csContent;
- csContent = csContentC;
- csContent.TrimLeft();
- csContent.TrimRight();
- CFX_WideString space;
- space.FromLocal(" ");
- csContent = space + csContent + space;
- FPDF_DWORD flag = 0;
- if (submit.IsSubmitEmbedPDF())
- flag |= FXFA_PDF;
-
- ToXFAContentFlags(csContent, flag);
- pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb");
- fileFlag = FXFA_SAVEAS_XDP;
- ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag);
- break;
- }
- case XFA_ATTRIBUTEENUM_Xml:
- pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb");
- fileFlag = FXFA_SAVEAS_XML;
- ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL);
- break;
- case XFA_ATTRIBUTEENUM_Pdf:
- break;
- case XFA_ATTRIBUTEENUM_Urlencoded:
- pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb");
- fileFlag = FXFA_SAVEAS_XML;
- ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL);
- break;
- default:
- return false;
- }
- if (!pFileHandler)
- return FALSE;
- if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) {
- CFX_WideString csToAddress;
- CFX_WideString csCCAddress;
- CFX_WideString csBCCAddress;
- CFX_WideString csSubject;
- CFX_WideString csMsg;
- bRet = MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject,
- csMsg);
- if (!bRet)
- return FALSE;
-
- CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode();
- CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode();
- CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode();
- CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode();
- CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode();
- FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
- FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
- FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
- FPDF_WIDESTRING pSubject =
- (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
- FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
- pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg);
- bsTo.ReleaseBuffer();
- bsCC.ReleaseBuffer();
- bsBcc.ReleaseBuffer();
- bsSubject.ReleaseBuffer();
- bsMsg.ReleaseBuffer();
- } else {
- // HTTP or FTP
- CFX_WideString ws;
- CFX_ByteString bs = csURL.UTF16LE_Encode();
- int len = bs.GetLength();
- pEnv->FFI_UploadTo(pFileHandler, fileFlag,
- (FPDF_WIDESTRING)bs.GetBuffer(len));
- bs.ReleaseBuffer(len);
- }
- return bRet;
-}
-
-FX_BOOL CPDFXFA_Document::SetGlobalProperty(CXFA_FFDoc* hDoc,
- const CFX_ByteStringC& szPropName,
- CFXJSE_Value* pValue) {
- if (hDoc != m_pXFADoc.get())
- return FALSE;
-
- if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime())
- return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetValueByName(szPropName,
- pValue);
- return FALSE;
-}
-
-FX_BOOL CPDFXFA_Document::GetGlobalProperty(CXFA_FFDoc* hDoc,
- const CFX_ByteStringC& szPropName,
- CFXJSE_Value* pValue) {
- if (hDoc != m_pXFADoc.get())
- return FALSE;
- if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime())
- return FALSE;
-
- if (!m_pJSContext) {
- m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get());
- m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext();
- }
-
- return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(szPropName,
- pValue);
-}
diff --git a/fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h b/fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h
new file mode 100644
index 0000000000..f6a538f816
--- /dev/null
+++ b/fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h
@@ -0,0 +1,114 @@
+// Copyright 2016 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_INCLUDE_CPDFXFA_DOCENVIRONMENT_H_
+#define FPDFSDK_FPDFXFA_INCLUDE_CPDFXFA_DOCENVIRONMENT_H_
+
+#include "public/fpdfview.h"
+#include "xfa/fxfa/include/fxfa.h"
+
+class CPDFXFA_Document;
+class IJS_Context;
+
+class CPDFXFA_DocEnvironment : public IXFA_DocEnvironment {
+ public:
+ CPDFXFA_DocEnvironment(CPDFXFA_Document*);
+ ~CPDFXFA_DocEnvironment() override;
+
+ // IXFA_DocEnvironment
+ void SetChangeMark(CXFA_FFDoc* hDoc) override;
+ // used in dynamic xfa, dwFlags refer to XFA_INVALIDATE_XXX macros.
+ void InvalidateRect(CXFA_FFPageView* pPageView,
+ const CFX_RectF& rt,
+ uint32_t dwFlags) override;
+ // show or hide caret
+ void DisplayCaret(CXFA_FFWidget* hWidget,
+ FX_BOOL bVisible,
+ const CFX_RectF* pRtAnchor) override;
+ // dwPos: (0:bottom 1:top)
+ FX_BOOL GetPopupPos(CXFA_FFWidget* hWidget,
+ FX_FLOAT fMinPopup,
+ FX_FLOAT fMaxPopup,
+ const CFX_RectF& rtAnchor,
+ CFX_RectF& rtPopup) override;
+ FX_BOOL PopupMenu(CXFA_FFWidget* hWidget, CFX_PointF ptPopup) override;
+
+ // dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing
+ void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) override;
+ void WidgetPostAdd(CXFA_FFWidget* hWidget,
+ CXFA_WidgetAcc* pWidgetData) override;
+ void WidgetPreRemove(CXFA_FFWidget* hWidget,
+ CXFA_WidgetAcc* pWidgetData) override;
+
+ // Host method
+ int32_t CountPages(CXFA_FFDoc* hDoc) override;
+ int32_t GetCurrentPage(CXFA_FFDoc* hDoc) override;
+ void SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) override;
+ FX_BOOL IsCalculationsEnabled(CXFA_FFDoc* hDoc) override;
+ void SetCalculationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) override;
+ void GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) override;
+ void SetTitle(CXFA_FFDoc* hDoc, const CFX_WideString& wsTitle) override;
+ void ExportData(CXFA_FFDoc* hDoc,
+ const CFX_WideString& wsFilePath,
+ FX_BOOL bXDP) override;
+ void GotoURL(CXFA_FFDoc* hDoc,
+ const CFX_WideString& bsURL,
+ FX_BOOL bAppend) override;
+ FX_BOOL IsValidationsEnabled(CXFA_FFDoc* hDoc) override;
+ void SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) override;
+ void SetFocusWidget(CXFA_FFDoc* hDoc, CXFA_FFWidget* hWidget) override;
+ void Print(CXFA_FFDoc* hDoc,
+ int32_t nStartPage,
+ int32_t nEndPage,
+ uint32_t dwOptions) override;
+ FX_ARGB GetHighlightColor(CXFA_FFDoc* hDoc) override;
+
+ /**
+ *Submit data to email, http, ftp.
+ * @param[in] hDoc The document handler.
+ * @param[in] eFormat Determines the format in which the data will be
+ *submitted. XFA_ATTRIBUTEENUM_Xdp, XFA_ATTRIBUTEENUM_Xml...
+ * @param[in] wsTarget The URL to which the data will be submitted.
+ * @param[in] eEncoding The encoding of text content.
+ * @param[in] pXDPContent Controls what subset of the data is submitted, used
+ *only when the format property is xdp.
+ * @param[in] bEmbedPDF, specifies whether PDF is embedded in the submitted
+ *content or not.
+ */
+ FX_BOOL SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) override;
+
+ FX_BOOL GetGlobalProperty(CXFA_FFDoc* hDoc,
+ const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* pValue) override;
+ FX_BOOL SetGlobalProperty(CXFA_FFDoc* hDoc,
+ const CFX_ByteStringC& szPropName,
+ CFXJSE_Value* pValue) override;
+
+ IFX_FileRead* OpenLinkedFile(CXFA_FFDoc* hDoc,
+ const CFX_WideString& wsLink) override;
+
+ private:
+ FX_BOOL OnBeforeNotifySubmit();
+ void OnAfterNotifySubmit();
+ FX_BOOL NotifySubmit(FX_BOOL bPrevOrPost);
+ FX_BOOL SubmitDataInternal(CXFA_FFDoc* hDoc, CXFA_Submit submit);
+ FX_BOOL MailToInfo(CFX_WideString& csURL,
+ CFX_WideString& csToAddress,
+ CFX_WideString& csCCAddress,
+ CFX_WideString& csBCCAddress,
+ CFX_WideString& csSubject,
+ CFX_WideString& csMsg);
+ FX_BOOL ExportSubmitFile(FPDF_FILEHANDLER* ppFileHandler,
+ int fileType,
+ FPDF_DWORD encodeType,
+ FPDF_DWORD flag);
+ void ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag);
+
+ CPDFXFA_Document* const m_pDocument; // Not owned;
+ IJS_Context* m_pJSContext;
+};
+
+#endif // FPDFSDK_FPDFXFA_INCLUDE_CPDFXFA_DOCENVIRONMENT_H_
diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h
index 31f3706b72..acced2c434 100644
--- a/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h
+++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h
@@ -7,29 +7,30 @@
#ifndef FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_
#define FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_
-#include "xfa/fxfa/include/xfa_ffdoc.h"
-
#include <memory>
-#include <vector>
-#include "public/fpdfview.h"
-#include "xfa/fxfa/include/fxfa.h"
-#include "xfa/fxfa/include/xfa_ffdochandler.h"
+#include "fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h"
+#include "xfa/fxfa/include/xfa_ffdoc.h"
class CPDFXFA_App;
-class CPDFXFA_Document;
class CPDFXFA_Page;
class CPDFSDK_Document;
class CPDFDoc_Environment;
-class IJS_Runtime;
-class IJS_Context;
class CXFA_FFDocHandler;
-class CPDFXFA_Document : public IXFA_DocProvider {
+enum LoadStatus {
+ FXFA_LOADSTATUS_PRELOAD = 0,
+ FXFA_LOADSTATUS_LOADING,
+ FXFA_LOADSTATUS_LOADED,
+ FXFA_LOADSTATUS_CLOSING,
+ FXFA_LOADSTATUS_CLOSED
+};
+
+class CPDFXFA_Document {
public:
CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
CPDFXFA_App* pProvider);
- ~CPDFXFA_Document() override;
+ ~CPDFXFA_Document();
FX_BOOL LoadXFADoc();
CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); }
@@ -38,6 +39,7 @@ class CPDFXFA_Document : public IXFA_DocProvider {
int GetPageCount();
CPDFXFA_Page* GetPage(int page_index);
+ CPDFXFA_Page* GetPage(CXFA_FFPageView* pPage);
void DeletePage(int page_index);
void RemovePage(CPDFXFA_Page* page);
@@ -45,89 +47,23 @@ class CPDFXFA_Document : public IXFA_DocProvider {
CPDFSDK_Document* GetSDKDocument(CPDFDoc_Environment* pFormFillEnv);
- // IXFA_DocProvider
- void SetChangeMark(CXFA_FFDoc* hDoc) override;
- // used in dynamic xfa, dwFlags refer to XFA_INVALIDATE_XXX macros.
- void InvalidateRect(CXFA_FFPageView* pPageView,
- const CFX_RectF& rt,
- uint32_t dwFlags) override;
- // show or hide caret
- void DisplayCaret(CXFA_FFWidget* hWidget,
- FX_BOOL bVisible,
- const CFX_RectF* pRtAnchor) override;
- // dwPos: (0:bottom 1:top)
- FX_BOOL GetPopupPos(CXFA_FFWidget* hWidget,
- FX_FLOAT fMinPopup,
- FX_FLOAT fMaxPopup,
- const CFX_RectF& rtAnchor,
- CFX_RectF& rtPopup) override;
- FX_BOOL PopupMenu(CXFA_FFWidget* hWidget, CFX_PointF ptPopup) override;
-
- // dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing
- void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) override;
- void WidgetPostAdd(CXFA_FFWidget* hWidget,
- CXFA_WidgetAcc* pWidgetData) override;
- void WidgetPreRemove(CXFA_FFWidget* hWidget,
- CXFA_WidgetAcc* pWidgetData) override;
-
- // Host method
- int32_t CountPages(CXFA_FFDoc* hDoc) override;
- int32_t GetCurrentPage(CXFA_FFDoc* hDoc) override;
- void SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) override;
- FX_BOOL IsCalculationsEnabled(CXFA_FFDoc* hDoc) override;
- void SetCalculationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) override;
- void GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) override;
- void SetTitle(CXFA_FFDoc* hDoc, const CFX_WideString& wsTitle) override;
- void ExportData(CXFA_FFDoc* hDoc,
- const CFX_WideString& wsFilePath,
- FX_BOOL bXDP) override;
- void GotoURL(CXFA_FFDoc* hDoc,
- const CFX_WideString& bsURL,
- FX_BOOL bAppend) override;
- FX_BOOL IsValidationsEnabled(CXFA_FFDoc* hDoc) override;
- void SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) override;
- void SetFocusWidget(CXFA_FFDoc* hDoc, CXFA_FFWidget* hWidget) override;
- void Print(CXFA_FFDoc* hDoc,
- int32_t nStartPage,
- int32_t nEndPage,
- uint32_t dwOptions) override;
- FX_ARGB GetHighlightColor(CXFA_FFDoc* hDoc) override;
-
- /**
- *Submit data to email, http, ftp.
- * @param[in] hDoc The document handler.
- * @param[in] eFormat Determines the format in which the data will be
- *submitted. XFA_ATTRIBUTEENUM_Xdp, XFA_ATTRIBUTEENUM_Xml...
- * @param[in] wsTarget The URL to which the data will be submitted.
- * @param[in] eEncoding The encoding of text content.
- * @param[in] pXDPContent Controls what subset of the data is submitted, used
- *only when the format property is xdp.
- * @param[in] bEmbedPDF, specifies whether PDF is embedded in the submitted
- *content or not.
- */
- FX_BOOL SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) override;
-
- FX_BOOL GetGlobalProperty(CXFA_FFDoc* hDoc,
- const CFX_ByteStringC& szPropName,
- CFXJSE_Value* pValue) override;
- FX_BOOL SetGlobalProperty(CXFA_FFDoc* hDoc,
- const CFX_ByteStringC& szPropName,
- CFXJSE_Value* pValue) override;
-
- IFX_FileRead* OpenLinkedFile(CXFA_FFDoc* hDoc,
- const CFX_WideString& wsLink) override;
-
void ClearChangeMark();
- private:
- enum LoadStatus {
- FXFA_LOADSTATUS_PRELOAD = 0,
- FXFA_LOADSTATUS_LOADING,
- FXFA_LOADSTATUS_LOADED,
- FXFA_LOADSTATUS_CLOSING,
- FXFA_LOADSTATUS_CLOSED
- };
+ protected:
+ friend class CPDFXFA_DocEnvironment;
+
+ CPDFSDK_Document* GetSDKDoc() { return m_pSDKDoc.get(); }
+ 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<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; }
+ private:
void CloseXFADoc(CXFA_FFDocHandler* pDoc) {
if (pDoc) {
m_pXFADoc->CloseDoc();
@@ -136,36 +72,21 @@ class CPDFXFA_Document : public IXFA_DocProvider {
}
}
- CPDFXFA_Page* GetPage(CXFA_FFPageView* pPage);
- FX_BOOL OnBeforeNotifySubmit();
- void OnAfterNotifySubmit();
- FX_BOOL NotifySubmit(FX_BOOL bPrevOrPost);
- FX_BOOL SubmitDataInternal(CXFA_FFDoc* hDoc, CXFA_Submit submit);
- FX_BOOL MailToInfo(CFX_WideString& csURL,
- CFX_WideString& csToAddress,
- CFX_WideString& csCCAddress,
- CFX_WideString& csBCCAddress,
- CFX_WideString& csSubject,
- CFX_WideString& csMsg);
- FX_BOOL ExportSubmitFile(FPDF_FILEHANDLER* ppFileHandler,
- int fileType,
- FPDF_DWORD encodeType,
- FPDF_DWORD flag);
- void ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag);
-
int m_iDocType;
- // |m_pSDKDoc| has to be released before |m_pPDFDoc| since it needs to access
- // it to kill focused annotations.
std::unique_ptr<CPDF_Document> m_pPDFDoc;
+ // |m_pSDKDoc| must be destroyed before |m_pPDFDoc| since it needs to access
+ // it to kill focused annotations.
std::unique_ptr<CPDFSDK_Document> m_pSDKDoc;
std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
CXFA_FFDocView* m_pXFADocView; // not owned.
CPDFXFA_App* const m_pApp;
- IJS_Context* m_pJSContext;
CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList;
LoadStatus m_nLoadStatus;
int m_nPageCount;
+
+ // Must be destroy before |m_pSDKDoc|.
+ CPDFXFA_DocEnvironment m_DocEnv;
};
#endif // FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_
diff --git a/xfa/fwl/basewidget/fwl_editimp.cpp b/xfa/fwl/basewidget/fwl_editimp.cpp
index 104054f4e1..93f5dd8ac6 100644
--- a/xfa/fwl/basewidget/fwl_editimp.cpp
+++ b/xfa/fwl/basewidget/fwl_editimp.cpp
@@ -1640,8 +1640,9 @@ FX_BOOL FWL_ShowCaret(IFWL_Widget* pWidget,
if (!pXFAWidget)
return FALSE;
- IXFA_DocProvider* pDocProvider = pXFAWidget->GetDoc()->GetDocProvider();
- if (!pDocProvider)
+ IXFA_DocEnvironment* pDocEnvironment =
+ pXFAWidget->GetDoc()->GetDocEnvironment();
+ if (!pDocEnvironment)
return FALSE;
if (bVisible) {
@@ -1649,10 +1650,10 @@ FX_BOOL FWL_ShowCaret(IFWL_Widget* pWidget,
pXFAWidget->GetRotateMatrix(mt);
CFX_RectF rt(*pRtAnchor);
mt.TransformRect(rt);
- pDocProvider->DisplayCaret(pXFAWidget, bVisible, &rt);
+ pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt);
return TRUE;
}
- pDocProvider->DisplayCaret(pXFAWidget, bVisible, pRtAnchor);
+ pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor);
return TRUE;
}
diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp
index 18e2d76552..9e86c3aa68 100644
--- a/xfa/fxfa/app/xfa_ffapp.cpp
+++ b/xfa/fxfa/app/xfa_ffapp.cpp
@@ -96,20 +96,20 @@ CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() {
return m_pDocHandler.get();
}
-CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider,
+CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
IFX_FileRead* pStream,
FX_BOOL bTakeOverFile) {
- std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pProvider));
+ std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pDocEnvironment));
FX_BOOL bSuccess = pDoc->OpenDoc(pStream, bTakeOverFile);
return bSuccess ? pDoc.release() : nullptr;
}
-CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider,
+CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
CPDF_Document* pPDFDoc) {
if (!pPDFDoc)
return nullptr;
- std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pProvider));
+ std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pDocEnvironment));
FX_BOOL bSuccess = pDoc->OpenDoc(pPDFDoc);
return bSuccess ? pDoc.release() : nullptr;
}
diff --git a/xfa/fxfa/app/xfa_ffchoicelist.cpp b/xfa/fxfa/app/xfa_ffchoicelist.cpp
index e6cb1090ad..94090d6123 100644
--- a/xfa/fxfa/app/xfa_ffchoicelist.cpp
+++ b/xfa/fxfa/app/xfa_ffchoicelist.cpp
@@ -287,7 +287,7 @@ FX_BOOL CXFA_FFComboBox::OnRButtonUp(uint32_t dwFlags,
if (!CXFA_FFField::OnRButtonUp(dwFlags, fx, fy))
return FALSE;
- GetDoc()->GetDocProvider()->PopupMenu(this, CFX_PointF(fx, fy));
+ GetDoc()->GetDocEnvironment()->PopupMenu(this, CFX_PointF(fx, fy));
return TRUE;
}
FX_BOOL CXFA_FFComboBox::OnKillFocus(CXFA_FFWidget* pNewWidget) {
diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp
index 1aed9c640e..14c4f2d2b4 100644
--- a/xfa/fxfa/app/xfa_ffdoc.cpp
+++ b/xfa/fxfa/app/xfa_ffdoc.cpp
@@ -147,8 +147,8 @@ int32_t Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) {
} // namespace
-CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocProvider* pDocProvider)
- : m_pDocProvider(pDocProvider),
+CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment)
+ : m_pDocEnvironment(pDocEnvironment),
m_pDocumentParser(nullptr),
m_pStream(nullptr),
m_pApp(pApp),
diff --git a/xfa/fxfa/app/xfa_ffdocview.cpp b/xfa/fxfa/app/xfa_ffdocview.cpp
index 0efdef6db1..7dff9d44f4 100644
--- a/xfa/fxfa/app/xfa_ffdocview.cpp
+++ b/xfa/fxfa/app/xfa_ffdocview.cpp
@@ -250,7 +250,7 @@ void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) {
}
}
if (bChanged) {
- m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
+ m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc);
}
}
int32_t CXFA_FFDocView::ProcessWidgetEvent(CXFA_EventParam* pParam,
@@ -387,7 +387,7 @@ void CXFA_FFDocView::SetFocusWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) {
if (SetFocus(pNewFocus)) {
m_pFocusAcc = pWidgetAcc;
if (m_iStatus == XFA_DOCVIEW_LAYOUTSTATUS_End) {
- m_pDoc->GetDocProvider()->SetFocusWidget(m_pDoc, m_pFocusWidget);
+ m_pDoc->GetDocEnvironment()->SetFocusWidget(m_pDoc, m_pFocusWidget);
}
}
}
@@ -412,7 +412,7 @@ static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView,
return pWidgetAcc->ProcessCalculate();
case XFA_EVENT_Validate:
if (((CXFA_FFDoc*)pDocView->GetDoc())
- ->GetDocProvider()
+ ->GetDocEnvironment()
->IsValidationsEnabled(pDocView->GetDoc())) {
return pWidgetAcc->ProcessValidate(0x01);
}
@@ -526,7 +526,7 @@ CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName(
void CXFA_FFDocView::OnPageEvent(CXFA_ContainerLayoutItem* pSender,
uint32_t dwEvent) {
CXFA_FFPageView* pFFPageView = static_cast<CXFA_FFPageView*>(pSender);
- m_pDoc->GetDocProvider()->PageViewEvent(pFFPageView, dwEvent);
+ m_pDoc->GetDocEnvironment()->PageViewEvent(pFFPageView, dwEvent);
}
void CXFA_FFDocView::LockUpdate() {
@@ -560,7 +560,7 @@ void CXFA_FFDocView::AddInvalidateRect(CXFA_FFPageView* pPageView,
void CXFA_FFDocView::RunInvalidate() {
for (const auto& pair : m_mapPageInvalidate)
- m_pDoc->GetDocProvider()->InvalidateRect(pair.first, *pair.second, 0);
+ m_pDoc->GetDocEnvironment()->InvalidateRect(pair.first, *pair.second, 0);
m_mapPageInvalidate.clear();
}
@@ -572,13 +572,13 @@ FX_BOOL CXFA_FFDocView::RunLayout() {
m_pXFADocLayout->DoLayout();
UnlockUpdate();
m_bInLayoutStatus = FALSE;
- m_pDoc->GetDocProvider()->PageViewEvent(nullptr,
- XFA_PAGEVIEWEVENT_StopLayout);
+ m_pDoc->GetDocEnvironment()->PageViewEvent(nullptr,
+ XFA_PAGEVIEWEVENT_StopLayout);
return TRUE;
}
m_bInLayoutStatus = FALSE;
- m_pDoc->GetDocProvider()->PageViewEvent(nullptr,
- XFA_PAGEVIEWEVENT_StopLayout);
+ m_pDoc->GetDocEnvironment()->PageViewEvent(nullptr,
+ XFA_PAGEVIEWEVENT_StopLayout);
UnlockUpdate();
return FALSE;
}
@@ -671,7 +671,7 @@ void CXFA_FFDocView::RunCalculateRecursive(int32_t& iIndex) {
}
}
int32_t CXFA_FFDocView::RunCalculateWidgets() {
- if (!m_pDoc->GetDocProvider()->IsCalculationsEnabled(m_pDoc)) {
+ if (!m_pDoc->GetDocEnvironment()->IsCalculationsEnabled(m_pDoc)) {
return XFA_EVENTERROR_Disabled;
}
int32_t iCounts = m_CalculateAccs.GetSize();
@@ -696,7 +696,7 @@ FX_BOOL CXFA_FFDocView::InitCalculate(CXFA_Node* pNode) {
return TRUE;
}
FX_BOOL CXFA_FFDocView::InitValidate(CXFA_Node* pNode) {
- if (!m_pDoc->GetDocProvider()->IsValidationsEnabled(m_pDoc)) {
+ if (!m_pDoc->GetDocEnvironment()->IsValidationsEnabled(m_pDoc)) {
return FALSE;
}
ExecEventActivityByDeepFirst(pNode, XFA_EVENT_Validate, FALSE, TRUE, nullptr);
@@ -704,7 +704,7 @@ FX_BOOL CXFA_FFDocView::InitValidate(CXFA_Node* pNode) {
return TRUE;
}
FX_BOOL CXFA_FFDocView::RunValidate() {
- if (!m_pDoc->GetDocProvider()->IsValidationsEnabled(m_pDoc)) {
+ if (!m_pDoc->GetDocEnvironment()->IsValidationsEnabled(m_pDoc)) {
return FALSE;
}
int32_t iCounts = m_ValidateAccs.GetSize();
@@ -798,7 +798,7 @@ void CXFA_FFDocView::SetChangeMark() {
if (m_iStatus < XFA_DOCVIEW_LAYOUTSTATUS_End) {
return;
}
- m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
+ m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc);
}
CXFA_Node* CXFA_FFDocView::GetRootSubform() {
CXFA_Node* pFormPacketNode =
diff --git a/xfa/fxfa/app/xfa_fffield.cpp b/xfa/fxfa/app/xfa_fffield.cpp
index 3274477005..b1a6b5f915 100644
--- a/xfa/fxfa/app/xfa_fffield.cpp
+++ b/xfa/fxfa/app/xfa_fffield.cpp
@@ -83,7 +83,7 @@ void CXFA_FFField::DrawHighlight(CFX_Graphics* pGS,
if ((dwStatus & XFA_WidgetStatus_Highlight) &&
m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open) {
CXFA_FFDoc* pDoc = GetDoc();
- CFX_Color crHighlight(pDoc->GetDocProvider()->GetHighlightColor(pDoc));
+ CFX_Color crHighlight(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc));
pGS->SetFillColor(&crHighlight);
CFX_Path path;
path.Create();
diff --git a/xfa/fxfa/app/xfa_ffnotify.cpp b/xfa/fxfa/app/xfa_ffnotify.cpp
index 09003f023c..859de5ca39 100644
--- a/xfa/fxfa/app/xfa_ffnotify.cpp
+++ b/xfa/fxfa/app/xfa_ffnotify.cpp
@@ -238,8 +238,8 @@ void CXFA_FFNotify::AddCalcValidate(CXFA_Node* pNode) {
CXFA_FFDoc* CXFA_FFNotify::GetHDOC() {
return m_pDoc;
}
-IXFA_DocProvider* CXFA_FFNotify::GetDocProvider() {
- return m_pDoc->GetDocProvider();
+IXFA_DocEnvironment* CXFA_FFNotify::GetDocEnvironment() const {
+ return m_pDoc->GetDocEnvironment();
}
IXFA_AppProvider* CXFA_FFNotify::GetAppProvider() {
return m_pDoc->GetApp()->GetAppProvider();
@@ -444,7 +444,7 @@ void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) {
!(pDocView->m_bInLayoutStatus) &&
(pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
if (bLayoutReady)
- m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
+ m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc);
}
void CXFA_FFNotify::OnChildRemoved() {
@@ -456,7 +456,7 @@ void CXFA_FFNotify::OnChildRemoved() {
!(pDocView->m_bInLayoutStatus) &&
(pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
if (bLayoutReady)
- m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
+ m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc);
}
void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout,
@@ -480,7 +480,7 @@ void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout,
(dwStatus & (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) ==
(XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) {
pWidget->SetPageView(pNewPageView);
- m_pDoc->GetDocProvider()->WidgetPostAdd(pWidget, pWidget->GetDataAcc());
+ m_pDoc->GetDocEnvironment()->WidgetPostAdd(pWidget, pWidget->GetDataAcc());
}
if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End ||
!(dwStatus & XFA_WidgetStatus_Visible)) {
@@ -508,6 +508,6 @@ void CXFA_FFNotify::OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout,
return;
pDocView->DeleteLayoutItem(pWidget);
- m_pDoc->GetDocProvider()->WidgetPreRemove(pWidget, pWidget->GetDataAcc());
+ m_pDoc->GetDocEnvironment()->WidgetPreRemove(pWidget, pWidget->GetDataAcc());
pWidget->AddInvalidateRect(nullptr);
}
diff --git a/xfa/fxfa/app/xfa_ffnotify.h b/xfa/fxfa/app/xfa_ffnotify.h
index ef34afb7b8..fae683c29e 100644
--- a/xfa/fxfa/app/xfa_ffnotify.h
+++ b/xfa/fxfa/app/xfa_ffnotify.h
@@ -57,7 +57,7 @@ class CXFA_FFNotify {
CXFA_WidgetAcc* pExclude = nullptr);
void AddCalcValidate(CXFA_Node* pNode);
CXFA_FFDoc* GetHDOC();
- IXFA_DocProvider* GetDocProvider();
+ IXFA_DocEnvironment* GetDocEnvironment() const;
IXFA_AppProvider* GetAppProvider();
CXFA_FFWidgetHandler* GetWidgetHandler();
CXFA_FFWidget* GetHWidget(CXFA_LayoutItem* pLayoutItem);
diff --git a/xfa/fxfa/app/xfa_fftext.cpp b/xfa/fxfa/app/xfa_fftext.cpp
index 3e5b3df8e9..2e5bb6420d 100644
--- a/xfa/fxfa/app/xfa_fftext.cpp
+++ b/xfa/fxfa/app/xfa_fftext.cpp
@@ -135,7 +135,7 @@ FX_BOOL CXFA_FFText::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
return FALSE;
}
CXFA_FFDoc* pDoc = GetDoc();
- pDoc->GetDocProvider()->GotoURL(pDoc, wsURLContent, FALSE);
+ pDoc->GetDocEnvironment()->GotoURL(pDoc, wsURLContent, FALSE);
return TRUE;
}
FWL_WidgetHit CXFA_FFText::OnHitTest(FX_FLOAT fx, FX_FLOAT fy) {
diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp
index 8418da4a81..1dc11adbef 100644
--- a/xfa/fxfa/app/xfa_fftextedit.cpp
+++ b/xfa/fxfa/app/xfa_fftextedit.cpp
@@ -146,7 +146,7 @@ FX_BOOL CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags,
if (!CXFA_FFField::OnRButtonUp(dwFlags, fx, fy))
return FALSE;
- GetDoc()->GetDocProvider()->PopupMenu(this, CFX_PointF(fx, fy));
+ GetDoc()->GetDocEnvironment()->PopupMenu(this, CFX_PointF(fx, fy));
return TRUE;
}
FX_BOOL CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) {
@@ -772,7 +772,7 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(IFWL_Widget* pWidget,
CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget;
pDateTime->SetEditText(wsDate);
pDateTime->Update();
- GetDoc()->GetDocProvider()->SetFocusWidget(GetDoc(), nullptr);
+ GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr);
CXFA_EventParam eParam;
eParam.m_eType = XFA_EVENT_Change;
eParam.m_pTarget = m_pDataAcc;
diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp
index e8de02d7bd..d71783b275 100644
--- a/xfa/fxfa/app/xfa_ffwidget.cpp
+++ b/xfa/fxfa/app/xfa_ffwidget.cpp
@@ -153,11 +153,11 @@ void CXFA_FFWidget::InvalidateWidget(const CFX_RectF* pRect) {
CFX_RectF rtWidget;
GetBBox(rtWidget, XFA_WidgetStatus_Focused);
rtWidget.Inflate(2, 2);
- GetDoc()->GetDocProvider()->InvalidateRect(m_pPageView, rtWidget,
- XFA_INVALIDATE_CurrentPage);
+ GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, rtWidget,
+ XFA_INVALIDATE_CurrentPage);
} else {
- GetDoc()->GetDocProvider()->InvalidateRect(m_pPageView, *pRect,
- XFA_INVALIDATE_CurrentPage);
+ GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, *pRect,
+ XFA_INVALIDATE_CurrentPage);
}
}
void CXFA_FFWidget::AddInvalidateRect(const CFX_RectF* pRect) {
@@ -1083,7 +1083,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
return pBitmap;
}
}
- pImageFileRead = pDoc->GetDocProvider()->OpenLinkedFile(pDoc, wsURL);
+ pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL);
}
if (!pImageFileRead) {
FX_Free(pImageBuffer);
diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp
index 075f2aa548..592074f916 100644
--- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp
+++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp
@@ -334,7 +334,7 @@ int32_t CXFA_WidgetAcc::ProcessEvent(CXFA_Event& event,
break;
case XFA_Element::Submit: {
CXFA_Submit submit = event.GetSubmit();
- return GetDoc()->GetDocProvider()->SubmitData(GetDoc(), submit);
+ return GetDoc()->GetDocEnvironment()->SubmitData(GetDoc(), submit);
}
default:
break;
diff --git a/xfa/fxfa/app/xfa_ffwidgethandler.cpp b/xfa/fxfa/app/xfa_ffwidgethandler.cpp
index 7d3da448bf..1c8e5f793b 100644
--- a/xfa/fxfa/app/xfa_ffwidgethandler.cpp
+++ b/xfa/fxfa/app/xfa_ffwidgethandler.cpp
@@ -46,8 +46,8 @@ FX_BOOL CXFA_FFWidgetHandler::OnLButtonDown(CXFA_FFWidget* hWidget,
hWidget->Rotate2Normal(fx, fy);
FX_BOOL bRet = hWidget->OnLButtonDown(dwFlags, fx, fy);
if (bRet && m_pDocView->SetFocus(hWidget)) {
- m_pDocView->GetDoc()->GetDocProvider()->SetFocusWidget(m_pDocView->GetDoc(),
- hWidget);
+ m_pDocView->GetDoc()->GetDocEnvironment()->SetFocusWidget(
+ m_pDocView->GetDoc(), hWidget);
}
m_pDocView->UnlockUpdate();
m_pDocView->UpdateDocView();
@@ -105,8 +105,8 @@ FX_BOOL CXFA_FFWidgetHandler::OnRButtonDown(CXFA_FFWidget* hWidget,
hWidget->Rotate2Normal(fx, fy);
FX_BOOL bRet = hWidget->OnRButtonDown(dwFlags, fx, fy);
if (bRet && m_pDocView->SetFocus(hWidget)) {
- m_pDocView->GetDoc()->GetDocProvider()->SetFocusWidget(m_pDocView->GetDoc(),
- hWidget);
+ m_pDocView->GetDoc()->GetDocEnvironment()->SetFocusWidget(
+ m_pDocView->GetDoc(), hWidget);
}
m_pDocView->RunInvalidate();
return bRet;
@@ -225,7 +225,7 @@ int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_WidgetAcc* pWidgetAcc,
case XFA_EVENT_Calculate:
return pWidgetAcc->ProcessCalculate();
case XFA_EVENT_Validate:
- if (m_pDocView->GetDoc()->GetDocProvider()->IsValidationsEnabled(
+ if (m_pDocView->GetDoc()->GetDocEnvironment()->IsValidationsEnabled(
m_pDocView->GetDoc())) {
return pWidgetAcc->ProcessValidate();
}
diff --git a/xfa/fxfa/app/xfa_fwladapter.cpp b/xfa/fxfa/app/xfa_fwladapter.cpp
index ea63d84dfb..b0b5f4bc32 100644
--- a/xfa/fxfa/app/xfa_fwladapter.cpp
+++ b/xfa/fxfa/app/xfa_fwladapter.cpp
@@ -38,7 +38,7 @@ FX_BOOL CXFA_FWLAdapterWidgetMgr::GetPopupPos(IFWL_Widget* pWidget,
pFFWidget->GetRotateMatrix(mt);
CFX_RectF rtRotateAnchor(rtAnchor);
mt.TransformRect(rtRotateAnchor);
- pFFWidget->GetDoc()->GetDocProvider()->GetPopupPos(
+ pFFWidget->GetDoc()->GetDocEnvironment()->GetPopupPos(
pFFWidget, fMinHeight, fMaxHeight, rtRotateAnchor, rtPopup);
return TRUE;
}
diff --git a/xfa/fxfa/include/fxfa.h b/xfa/fxfa/include/fxfa.h
index e7579e23fd..fde8d0f6c6 100644
--- a/xfa/fxfa/include/fxfa.h
+++ b/xfa/fxfa/include/fxfa.h
@@ -21,7 +21,7 @@ class CXFA_NodeList;
class CXFA_WidgetAcc;
class IFWL_AdapterTimerMgr;
class IXFA_AppProvider;
-class IXFA_DocProvider;
+class IXFA_DocEnvironment;
class IXFA_WidgetAccIterator;
class IXFA_WidgetIterator;
@@ -291,9 +291,9 @@ class IXFA_AppProvider {
virtual IFWL_AdapterTimerMgr* GetTimerMgr() = 0;
};
-class IXFA_DocProvider {
+class IXFA_DocEnvironment {
public:
- virtual ~IXFA_DocProvider() {}
+ virtual ~IXFA_DocEnvironment() {}
virtual void SetChangeMark(CXFA_FFDoc* hDoc) = 0;
virtual void InvalidateRect(CXFA_FFPageView* pPageView,
diff --git a/xfa/fxfa/include/xfa_ffapp.h b/xfa/fxfa/include/xfa_ffapp.h
index 90bfcc0240..8a60ce6195 100644
--- a/xfa/fxfa/include/xfa_ffapp.h
+++ b/xfa/fxfa/include/xfa_ffapp.h
@@ -42,10 +42,11 @@ class CXFA_FFApp {
explicit CXFA_FFApp(IXFA_AppProvider* pProvider);
~CXFA_FFApp();
- CXFA_FFDoc* CreateDoc(IXFA_DocProvider* pProvider,
+ CXFA_FFDoc* CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
IFX_FileRead* pStream,
FX_BOOL bTakeOverFile);
- CXFA_FFDoc* CreateDoc(IXFA_DocProvider* pProvider, CPDF_Document* pPDFDoc);
+ CXFA_FFDoc* CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
+ CPDF_Document* pPDFDoc);
void SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr);
CXFA_FFDocHandler* GetDocHandler();
diff --git a/xfa/fxfa/include/xfa_ffdoc.h b/xfa/fxfa/include/xfa_ffdoc.h
index ddbc0049f1..927301893b 100644
--- a/xfa/fxfa/include/xfa_ffdoc.h
+++ b/xfa/fxfa/include/xfa_ffdoc.h
@@ -27,9 +27,9 @@ struct FX_IMAGEDIB_AND_DPI {
class CXFA_FFDoc {
public:
- CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocProvider* pDocProvider);
+ CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment);
~CXFA_FFDoc();
- IXFA_DocProvider* GetDocProvider() { return m_pDocProvider; }
+ IXFA_DocEnvironment* GetDocEnvironment() const { return m_pDocEnvironment; }
uint32_t GetDocType();
int32_t StartLoad();
int32_t DoLoad(IFX_Pause* pPause = nullptr);
@@ -54,7 +54,7 @@ class CXFA_FFDoc {
FX_BOOL ImportData(IFX_FileRead* pStream, FX_BOOL bXDP = TRUE);
protected:
- IXFA_DocProvider* m_pDocProvider;
+ IXFA_DocEnvironment* const m_pDocEnvironment;
std::unique_ptr<CXFA_DocumentParser> m_pDocumentParser;
IFX_FileRead* m_pStream;
CXFA_FFApp* m_pApp;
diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp
index 15f175cd49..680defc0b6 100644
--- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp
+++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp
@@ -65,11 +65,11 @@ void CScript_HostPseudoModel::CalculationsEnabled(CFXJSE_Value* pValue,
}
CXFA_FFDoc* hDoc = pNotify->GetHDOC();
if (bSetting) {
- pNotify->GetDocProvider()->SetCalculationsEnabled(hDoc,
- pValue->ToBoolean());
+ pNotify->GetDocEnvironment()->SetCalculationsEnabled(hDoc,
+ pValue->ToBoolean());
return;
}
- pValue->SetBoolean(pNotify->GetDocProvider()->IsCalculationsEnabled(hDoc));
+ pValue->SetBoolean(pNotify->GetDocEnvironment()->IsCalculationsEnabled(hDoc));
}
void CScript_HostPseudoModel::CurrentPage(CFXJSE_Value* pValue,
@@ -81,10 +81,10 @@ void CScript_HostPseudoModel::CurrentPage(CFXJSE_Value* pValue,
}
CXFA_FFDoc* hDoc = pNotify->GetHDOC();
if (bSetting) {
- pNotify->GetDocProvider()->SetCurrentPage(hDoc, pValue->ToInteger());
+ pNotify->GetDocEnvironment()->SetCurrentPage(hDoc, pValue->ToInteger());
return;
}
- pValue->SetInteger(pNotify->GetDocProvider()->GetCurrentPage(hDoc));
+ pValue->SetInteger(pNotify->GetDocEnvironment()->GetCurrentPage(hDoc));
}
void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue,
@@ -115,7 +115,7 @@ void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue,
ThrowException(XFA_IDS_UNABLE_SET_NUMPAGES);
return;
}
- pValue->SetInteger(pNotify->GetDocProvider()->CountPages(hDoc));
+ pValue->SetInteger(pNotify->GetDocEnvironment()->CountPages(hDoc));
}
void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue,
@@ -145,11 +145,11 @@ void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue,
}
CXFA_FFDoc* hDoc = pNotify->GetHDOC();
if (bSetting) {
- pNotify->GetDocProvider()->SetTitle(hDoc, pValue->ToWideString());
+ pNotify->GetDocEnvironment()->SetTitle(hDoc, pValue->ToWideString());
return;
}
CFX_WideString wsTitle;
- pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle);
+ pNotify->GetDocEnvironment()->GetTitle(hDoc, wsTitle);
pValue->SetString(FX_UTF8Encode(wsTitle).AsStringC());
}
@@ -162,10 +162,11 @@ void CScript_HostPseudoModel::ValidationsEnabled(CFXJSE_Value* pValue,
}
CXFA_FFDoc* hDoc = pNotify->GetHDOC();
if (bSetting) {
- pNotify->GetDocProvider()->SetValidationsEnabled(hDoc, pValue->ToBoolean());
+ pNotify->GetDocEnvironment()->SetValidationsEnabled(hDoc,
+ pValue->ToBoolean());
return;
}
- FX_BOOL bEnabled = pNotify->GetDocProvider()->IsValidationsEnabled(hDoc);
+ FX_BOOL bEnabled = pNotify->GetDocEnvironment()->IsValidationsEnabled(hDoc);
pValue->SetBoolean(bEnabled);
}
void CScript_HostPseudoModel::Variation(CFXJSE_Value* pValue,
@@ -238,7 +239,7 @@ void CScript_HostPseudoModel::GotoURL(CFXJSE_Arguments* pArguments) {
CFX_ByteString bsURL = pArguments->GetUTF8String(0);
wsURL = CFX_WideString::FromUTF8(bsURL.AsStringC());
}
- pNotify->GetDocProvider()->GotoURL(hDoc, wsURL, TRUE);
+ pNotify->GetDocEnvironment()->GotoURL(hDoc, wsURL, TRUE);
}
void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) {
if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
@@ -287,7 +288,7 @@ void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) {
if (!hWidget) {
return;
}
- pNotify->GetDocProvider()->SetFocusWidget(pNotify->GetHDOC(), hWidget);
+ pNotify->GetDocEnvironment()->SetFocusWidget(pNotify->GetHDOC(), hWidget);
pNotify->OpenDropDownList(hWidget);
}
void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) {
@@ -626,7 +627,7 @@ void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) {
if (bPrintAnnot) {
dwOptions |= XFA_PRINTOPT_PrintAnnot;
}
- pNotify->GetDocProvider()->Print(hDoc, nStartPage, nEndPage, dwOptions);
+ pNotify->GetDocEnvironment()->Print(hDoc, nStartPage, nEndPage, dwOptions);
}
void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) {
@@ -658,7 +659,7 @@ void CScript_HostPseudoModel::ExportData(CFXJSE_Arguments* pArguments) {
if (iLength >= 2) {
bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;
}
- pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath, bXDP);
+ pNotify->GetDocEnvironment()->ExportData(hDoc, wsFilePath, bXDP);
}
void CScript_HostPseudoModel::PageUp(CFXJSE_Arguments* pArguments) {
@@ -667,13 +668,13 @@ void CScript_HostPseudoModel::PageUp(CFXJSE_Arguments* pArguments) {
return;
}
CXFA_FFDoc* hDoc = pNotify->GetHDOC();
- int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc);
+ int32_t nCurPage = pNotify->GetDocEnvironment()->GetCurrentPage(hDoc);
int32_t nNewPage = 0;
if (nCurPage <= 1) {
return;
}
nNewPage = nCurPage - 1;
- pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage);
+ pNotify->GetDocEnvironment()->SetCurrentPage(hDoc, nNewPage);
}
void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) {
@@ -682,8 +683,8 @@ void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) {
return;
}
CXFA_FFDoc* hDoc = pNotify->GetHDOC();
- int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc);
- int32_t nPageCount = pNotify->GetDocProvider()->CountPages(hDoc);
+ int32_t nCurPage = pNotify->GetDocEnvironment()->GetCurrentPage(hDoc);
+ int32_t nPageCount = pNotify->GetDocEnvironment()->CountPages(hDoc);
if (!nPageCount || nCurPage == nPageCount) {
return;
}
@@ -693,7 +694,7 @@ void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) {
} else {
nNewPage = nCurPage + 1;
}
- pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage);
+ pNotify->GetDocEnvironment()->SetCurrentPage(hDoc, nNewPage);
}
void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) {
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
index e91e350d32..22e24c5445 100644
--- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp
+++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
@@ -203,8 +203,8 @@ void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject,
if (!pNotify) {
return;
}
- pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName,
- pValue);
+ pNotify->GetDocEnvironment()->SetGlobalProperty(pNotify->GetHDOC(),
+ szPropName, pValue);
}
FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode,
const CFX_WideStringC& propname,
@@ -279,8 +279,8 @@ void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject,
if (!pNotify) {
return;
}
- pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName,
- pValue);
+ pNotify->GetDocEnvironment()->GetGlobalProperty(pNotify->GetHDOC(),
+ szPropName, pValue);
}
void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue,
const CFX_ByteStringC& szPropName,