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