1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/src/foxitlib.h"
8 #include "xfa/src/fxfa/src/common/xfa_common.h"
9 #include "xfa_ffdochandler.h"
10 #include "xfa_ffdoc.h"
CXFA_FFDocHandler()11 CXFA_FFDocHandler::CXFA_FFDocHandler() {}
~CXFA_FFDocHandler()12 CXFA_FFDocHandler::~CXFA_FFDocHandler() {}
ReleaseDoc(IXFA_Doc * hDoc)13 void CXFA_FFDocHandler::ReleaseDoc(IXFA_Doc* hDoc) {
14 delete hDoc; // virtual dtor.
15 }
GetDocProvider(IXFA_Doc * hDoc)16 IXFA_DocProvider* CXFA_FFDocHandler::GetDocProvider(IXFA_Doc* hDoc) {
17 return static_cast<CXFA_FFDoc*>(hDoc)->GetDocProvider();
18 }
GetDocType(IXFA_Doc * hDoc)19 FX_DWORD CXFA_FFDocHandler::GetDocType(IXFA_Doc* hDoc) {
20 return static_cast<CXFA_FFDoc*>(hDoc)->GetDocType();
21 }
StartLoad(IXFA_Doc * hDoc)22 int32_t CXFA_FFDocHandler::StartLoad(IXFA_Doc* hDoc) {
23 return static_cast<CXFA_FFDoc*>(hDoc)->StartLoad();
24 }
DoLoad(IXFA_Doc * hDoc,IFX_Pause * pPause)25 int32_t CXFA_FFDocHandler::DoLoad(IXFA_Doc* hDoc, IFX_Pause* pPause) {
26 return static_cast<CXFA_FFDoc*>(hDoc)->DoLoad(pPause);
27 }
StopLoad(IXFA_Doc * hDoc)28 void CXFA_FFDocHandler::StopLoad(IXFA_Doc* hDoc) {
29 static_cast<CXFA_FFDoc*>(hDoc)->StopLoad();
30 }
31
CreateDocView(IXFA_Doc * hDoc,FX_DWORD dwView)32 IXFA_DocView* CXFA_FFDocHandler::CreateDocView(IXFA_Doc* hDoc,
33 FX_DWORD dwView) {
34 return static_cast<CXFA_FFDoc*>(hDoc)->CreateDocView(dwView);
35 }
CountPackages(IXFA_Doc * hDoc)36 int32_t CXFA_FFDocHandler::CountPackages(IXFA_Doc* hDoc) {
37 return 0;
38 }
GetPackageName(IXFA_Doc * hDoc,int32_t iPackage,CFX_WideStringC & wsPackage)39 void CXFA_FFDocHandler::GetPackageName(IXFA_Doc* hDoc,
40 int32_t iPackage,
41 CFX_WideStringC& wsPackage) {}
GetPackageData(IXFA_Doc * hDoc,const CFX_WideStringC & wsPackage)42 IFDE_XMLElement* CXFA_FFDocHandler::GetPackageData(
43 IXFA_Doc* hDoc,
44 const CFX_WideStringC& wsPackage) {
45 return static_cast<CXFA_FFDoc*>(hDoc)->GetPackageData(wsPackage);
46 }
SavePackage(IXFA_Doc * hDoc,const CFX_WideStringC & wsPackage,IFX_FileWrite * pFile,IXFA_ChecksumContext * pCSContext)47 FX_BOOL CXFA_FFDocHandler::SavePackage(IXFA_Doc* hDoc,
48 const CFX_WideStringC& wsPackage,
49 IFX_FileWrite* pFile,
50 IXFA_ChecksumContext* pCSContext) {
51 return static_cast<CXFA_FFDoc*>(hDoc)
52 ->SavePackage(wsPackage, pFile, pCSContext);
53 }
CloseDoc(IXFA_Doc * hDoc)54 FX_BOOL CXFA_FFDocHandler::CloseDoc(IXFA_Doc* hDoc) {
55 return static_cast<CXFA_FFDoc*>(hDoc)->CloseDoc();
56 }
57
ImportData(IXFA_Doc * hDoc,IFX_FileRead * pStream,FX_BOOL bXDP)58 FX_BOOL CXFA_FFDocHandler::ImportData(IXFA_Doc* hDoc,
59 IFX_FileRead* pStream,
60 FX_BOOL bXDP) {
61 return static_cast<CXFA_FFDoc*>(hDoc)->ImportData(pStream, bXDP);
62 }
SetJSERuntime(IXFA_Doc * hDoc,FXJSE_HRUNTIME hRuntime)63 void CXFA_FFDocHandler::SetJSERuntime(IXFA_Doc* hDoc, FXJSE_HRUNTIME hRuntime) {
64 static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc()->InitScriptContext(hRuntime);
65 }
GetXFAScriptObject(IXFA_Doc * hDoc)66 FXJSE_HVALUE CXFA_FFDocHandler::GetXFAScriptObject(IXFA_Doc* hDoc) {
67 CXFA_Document* pXFADoc = static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc();
68 if (!pXFADoc) {
69 return NULL;
70 }
71 IXFA_ScriptContext* pScriptContext = pXFADoc->GetScriptContext();
72 if (!pScriptContext) {
73 return NULL;
74 }
75 return pScriptContext->GetJSValueFromMap(pXFADoc->GetRoot());
76 }
GetRestoreState(IXFA_Doc * hDoc)77 XFA_ATTRIBUTEENUM CXFA_FFDocHandler::GetRestoreState(IXFA_Doc* hDoc) {
78 CXFA_Document* pXFADoc = static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc();
79 if (!pXFADoc) {
80 return XFA_ATTRIBUTEENUM_Unknown;
81 }
82 CXFA_Node* pForm = (CXFA_Node*)pXFADoc->GetXFANode(XFA_HASHCODE_Form);
83 if (!pForm) {
84 return XFA_ATTRIBUTEENUM_Unknown;
85 }
86 CXFA_Node* pSubForm = pForm->GetFirstChildByClass(XFA_ELEMENT_Subform);
87 if (!pSubForm) {
88 return XFA_ATTRIBUTEENUM_Unknown;
89 }
90 return pSubForm->GetEnum(XFA_ATTRIBUTE_RestoreState);
91 }
RunDocScript(IXFA_Doc * hDoc,XFA_SCRIPTTYPE eScriptType,const CFX_WideStringC & wsScript,FXJSE_HVALUE hRetValue,FXJSE_HVALUE hThisObject)92 FX_BOOL CXFA_FFDocHandler::RunDocScript(IXFA_Doc* hDoc,
93 XFA_SCRIPTTYPE eScriptType,
94 const CFX_WideStringC& wsScript,
95 FXJSE_HVALUE hRetValue,
96 FXJSE_HVALUE hThisObject) {
97 CXFA_Document* pXFADoc = static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc();
98 if (!pXFADoc) {
99 return FALSE;
100 }
101 IXFA_ScriptContext* pScriptContext = pXFADoc->GetScriptContext();
102 if (!pScriptContext) {
103 return FALSE;
104 }
105 return pScriptContext->RunScript(
106 (XFA_SCRIPTLANGTYPE)eScriptType, wsScript, hRetValue,
107 hThisObject ? (CXFA_Object*)FXJSE_Value_ToObject(hThisObject, NULL)
108 : NULL);
109 }
110