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 #ifndef FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ 8 #define FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" 14 #include "xfa/fxfa/xfa_ffdoc.h" 15 16 class CJS_Runtime; 17 class CPDFSDK_FormFillEnvironment; 18 class CPDFXFA_Page; 19 class CXFA_FFDocHandler; 20 class IJS_EventContext; 21 class IJS_Runtime; 22 23 enum LoadStatus { 24 FXFA_LOADSTATUS_PRELOAD = 0, 25 FXFA_LOADSTATUS_LOADING, 26 FXFA_LOADSTATUS_LOADED, 27 FXFA_LOADSTATUS_CLOSING, 28 FXFA_LOADSTATUS_CLOSED 29 }; 30 31 class CPDFXFA_Context : public IXFA_AppProvider { 32 public: 33 explicit CPDFXFA_Context(std::unique_ptr<CPDF_Document> pPDFDoc); 34 ~CPDFXFA_Context() override; 35 36 bool LoadXFADoc(); GetPDFDoc()37 CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } GetXFADoc()38 CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } GetXFADocView()39 CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } GetDocType()40 int GetDocType() const { return m_iDocType; } 41 v8::Isolate* GetJSERuntime() const; GetXFAApp()42 CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } 43 GetFormFillEnv()44 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; } 45 void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); 46 47 void DeletePage(int page_index); 48 int GetPageCount() const; 49 50 CPDFXFA_Page* GetXFAPage(int page_index); 51 CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const; 52 53 void RemovePage(CPDFXFA_Page* page); 54 55 void ClearChangeMark(); 56 57 // IFXA_AppProvider: 58 CFX_WideString GetLanguage() override; 59 CFX_WideString GetPlatform() override; 60 CFX_WideString GetAppName() override; 61 CFX_WideString GetAppTitle() const override; 62 63 void Beep(uint32_t dwType) override; 64 int32_t MsgBox(const CFX_WideString& wsMessage, 65 const CFX_WideString& wsTitle, 66 uint32_t dwIconType, 67 uint32_t dwButtonType) override; 68 CFX_WideString Response(const CFX_WideString& wsQuestion, 69 const CFX_WideString& wsTitle, 70 const CFX_WideString& wsDefaultAnswer, 71 bool bMark) override; 72 CFX_RetainPtr<IFX_SeekableReadStream> DownloadURL( 73 const CFX_WideString& wsURL) override; 74 bool PostRequestURL(const CFX_WideString& wsURL, 75 const CFX_WideString& wsData, 76 const CFX_WideString& wsContentType, 77 const CFX_WideString& wsEncode, 78 const CFX_WideString& wsHeader, 79 CFX_WideString& wsResponse) override; 80 bool PutRequestURL(const CFX_WideString& wsURL, 81 const CFX_WideString& wsData, 82 const CFX_WideString& wsEncode) override; 83 84 IFWL_AdapterTimerMgr* GetTimerMgr() override; 85 86 protected: 87 friend class CPDFXFA_DocEnvironment; 88 GetOriginalPageCount()89 int GetOriginalPageCount() const { return m_nPageCount; } SetOriginalPageCount(int count)90 void SetOriginalPageCount(int count) { 91 m_nPageCount = count; 92 m_XFAPageList.resize(count); 93 } 94 GetLoadStatus()95 LoadStatus GetLoadStatus() const { return m_nLoadStatus; } GetXFAPageList()96 std::vector<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; } 97 98 private: 99 void CloseXFADoc(); 100 101 int m_iDocType; 102 103 std::unique_ptr<CPDF_Document> m_pPDFDoc; 104 std::unique_ptr<CXFA_FFDoc> m_pXFADoc; 105 CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned. 106 CXFA_FFDocView* m_pXFADocView; // not owned. 107 std::unique_ptr<CXFA_FFApp> m_pXFAApp; 108 std::unique_ptr<CJS_Runtime> m_pRuntime; 109 std::vector<CPDFXFA_Page*> m_XFAPageList; 110 LoadStatus m_nLoadStatus; 111 int m_nPageCount; 112 113 // Must be destroyed before |m_pFormFillEnv|. 114 CPDFXFA_DocEnvironment m_DocEnv; 115 }; 116 117 #endif // FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ 118