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 FPDFXFA_APP_H_
8 #define FPDFXFA_APP_H_
9 
10 #include "xfa/include/fxfa/fxfa.h"
11 
12 class IFXJS_Runtime;
13 
14 class CPDFXFA_App : public IXFA_AppProvider {
15  public:
16   static CPDFXFA_App* GetInstance();
17   static void ReleaseInstance();
18 
19   CPDFXFA_App();
20   ~CPDFXFA_App() override;
21 
22   FX_BOOL Initialize();
GetXFAApp()23   IXFA_App* GetXFAApp() { return m_pXFAApp; }
24 
25   FX_BOOL AddFormFillEnv(CPDFDoc_Environment* pEnv);
26   FX_BOOL RemoveFormFillEnv(CPDFDoc_Environment* pEnv);
27 
IsJavaScriptInitialized()28   FX_BOOL IsJavaScriptInitialized() const { return m_bJavaScriptInitialized; }
SetJavaScriptInitialized(FX_BOOL bInitialized)29   void SetJavaScriptInitialized(FX_BOOL bInitialized) {
30     m_bJavaScriptInitialized = bInitialized;
31   }
32 
GetJSERuntime()33   FXJSE_HRUNTIME GetJSERuntime() const { return m_hJSERuntime; }
34 
35   // IFXA_AppProvider:
36   void GetAppType(CFX_WideString& wsAppType) override;
37   void SetAppType(const CFX_WideStringC& wsAppType) override;
38 
39   void GetLanguage(CFX_WideString& wsLanguage) override;
40   void GetPlatform(CFX_WideString& wsPlatform) override;
41   void GetVariation(CFX_WideString& wsVariation) override;
42   void GetVersion(CFX_WideString& wsVersion) override;
GetFoxitVersion(CFX_WideString & wsFoxitVersion)43   void GetFoxitVersion(CFX_WideString& wsFoxitVersion) override {
44     wsFoxitVersion = L"7.0";
45   }
46 
47   void GetAppName(CFX_WideString& wsName) override;
GetFoxitAppName(CFX_WideString & wsFoxitName)48   void GetFoxitAppName(CFX_WideString& wsFoxitName) override {
49     wsFoxitName = L"Foxit";
50   }
51 
52   void Beep(FX_DWORD dwType) override;
53   int32_t MsgBox(const CFX_WideStringC& wsMessage,
54                  const CFX_WideStringC& wsTitle,
55                  FX_DWORD dwIconType,
56                  FX_DWORD dwButtonType) override;
57   void Response(CFX_WideString& wsAnswer,
58                 const CFX_WideStringC& wsQuestion,
59                 const CFX_WideStringC& wsTitle,
60                 const CFX_WideStringC& wsDefaultAnswer,
61                 FX_BOOL bMark) override;
62 
63   int32_t GetDocumentCountInBatch() override;
64   int32_t GetCurDocumentInBatch() override;
65 
66   IFX_FileRead* DownloadURL(const CFX_WideStringC& wsURL) override;
67   FX_BOOL PostRequestURL(const CFX_WideStringC& wsURL,
68                          const CFX_WideStringC& wsData,
69                          const CFX_WideStringC& wsContentType,
70                          const CFX_WideStringC& wsEncode,
71                          const CFX_WideStringC& wsHeader,
72                          CFX_WideString& wsResponse) override;
73   FX_BOOL PutRequestURL(const CFX_WideStringC& wsURL,
74                         const CFX_WideStringC& wsData,
75                         const CFX_WideStringC& wsEncode) override;
76 
77   void LoadString(int32_t iStringID, CFX_WideString& wsString) override;
78   FX_BOOL ShowFileDialog(const CFX_WideStringC& wsTitle,
79                          const CFX_WideStringC& wsFilter,
80                          CFX_WideStringArray& wsPathArr,
81                          FX_BOOL bOpen) override;
82   IFWL_AdapterTimerMgr* GetTimerMgr() override;
83 
84   CFX_ArrayTemplate<CPDFDoc_Environment*> m_pEnvList;
85 
86  protected:
87   static CPDFXFA_App* g_pApp;
88 
89   FX_BOOL m_bJavaScriptInitialized;
90   IXFA_App* m_pXFAApp;
91   IXFA_FontMgr* m_pFontMgr;
92   FXJSE_HRUNTIME m_hJSERuntime;
93   IFXJS_Runtime* m_pJSRuntime;
94   CFX_WideString m_csAppType;
95 };
96 
97 #endif  // FPDFXFA_APP_H_
98