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