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" 11 CXFA_FFDocHandler::CXFA_FFDocHandler() {} 12 CXFA_FFDocHandler::~CXFA_FFDocHandler() {} 13 void CXFA_FFDocHandler::ReleaseDoc(IXFA_Doc* hDoc) { 14 delete hDoc; // virtual dtor. 15 } 16 IXFA_DocProvider* CXFA_FFDocHandler::GetDocProvider(IXFA_Doc* hDoc) { 17 return static_cast<CXFA_FFDoc*>(hDoc)->GetDocProvider(); 18 } 19 FX_DWORD CXFA_FFDocHandler::GetDocType(IXFA_Doc* hDoc) { 20 return static_cast<CXFA_FFDoc*>(hDoc)->GetDocType(); 21 } 22 int32_t CXFA_FFDocHandler::StartLoad(IXFA_Doc* hDoc) { 23 return static_cast<CXFA_FFDoc*>(hDoc)->StartLoad(); 24 } 25 int32_t CXFA_FFDocHandler::DoLoad(IXFA_Doc* hDoc, IFX_Pause* pPause) { 26 return static_cast<CXFA_FFDoc*>(hDoc)->DoLoad(pPause); 27 } 28 void CXFA_FFDocHandler::StopLoad(IXFA_Doc* hDoc) { 29 static_cast<CXFA_FFDoc*>(hDoc)->StopLoad(); 30 } 31 32 IXFA_DocView* CXFA_FFDocHandler::CreateDocView(IXFA_Doc* hDoc, 33 FX_DWORD dwView) { 34 return static_cast<CXFA_FFDoc*>(hDoc)->CreateDocView(dwView); 35 } 36 int32_t CXFA_FFDocHandler::CountPackages(IXFA_Doc* hDoc) { 37 return 0; 38 } 39 void CXFA_FFDocHandler::GetPackageName(IXFA_Doc* hDoc, 40 int32_t iPackage, 41 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 } 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 } 54 FX_BOOL CXFA_FFDocHandler::CloseDoc(IXFA_Doc* hDoc) { 55 return static_cast<CXFA_FFDoc*>(hDoc)->CloseDoc(); 56 } 57 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 } 63 void CXFA_FFDocHandler::SetJSERuntime(IXFA_Doc* hDoc, FXJSE_HRUNTIME hRuntime) { 64 static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc()->InitScriptContext(hRuntime); 65 } 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 } 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 } 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