blob: 9a2a517fb5aba65142a7371cd30cf79e676bba9f [file] [log] [blame]
Lei Zhang94293682016-01-27 18:27:56 -08001// 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
dsinclair521b7502016-11-02 13:02:28 -07007#ifndef FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_
8#define FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_
Lei Zhang94293682016-01-27 18:27:56 -08009
dsinclaira440bb32016-09-14 07:01:54 -070010#include <memory>
Tom Sepez5535ac72017-01-27 12:11:38 -080011#include <vector>
dsinclaira440bb32016-09-14 07:01:54 -070012
dsinclairbec76922016-09-29 16:52:30 -070013#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
dsinclair5b493092016-09-29 20:20:24 -070014#include "xfa/fxfa/xfa_ffdoc.h"
weili625ad662016-06-15 11:21:33 -070015
dsinclair25ec6462016-11-02 12:37:12 -070016class CJS_Runtime;
dsinclair735606d2016-10-05 15:47:02 -070017class CPDFSDK_FormFillEnvironment;
Lei Zhang94293682016-01-27 18:27:56 -080018class CPDFXFA_Page;
dsinclairdf4bc592016-03-31 20:34:43 -070019class CXFA_FFDocHandler;
Tom Sepezd6ae2af2017-02-16 11:49:55 -080020class IJS_EventContext;
dsinclair79db6092016-09-14 07:27:21 -070021class IJS_Runtime;
Lei Zhang94293682016-01-27 18:27:56 -080022
dsinclaira440bb32016-09-14 07:01:54 -070023enum LoadStatus {
24 FXFA_LOADSTATUS_PRELOAD = 0,
25 FXFA_LOADSTATUS_LOADING,
26 FXFA_LOADSTATUS_LOADED,
27 FXFA_LOADSTATUS_CLOSING,
28 FXFA_LOADSTATUS_CLOSED
29};
30
dsinclair521b7502016-11-02 13:02:28 -070031class CPDFXFA_Context : public IXFA_AppProvider {
Lei Zhang94293682016-01-27 18:27:56 -080032 public:
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050033 explicit CPDFXFA_Context(std::unique_ptr<CPDF_Document> pPDFDoc);
dsinclair521b7502016-11-02 13:02:28 -070034 ~CPDFXFA_Context() override;
Lei Zhang94293682016-01-27 18:27:56 -080035
tsepez4cf55152016-11-02 14:37:54 -070036 bool LoadXFADoc();
dsinclaircedaa552016-08-24 11:12:19 -070037 CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); }
weili2d5b0202016-08-03 11:06:49 -070038 CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); }
dsinclairdf4bc592016-03-31 20:34:43 -070039 CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; }
dsinclair9f206f02016-09-20 12:17:42 -070040 int GetDocType() const { return m_iDocType; }
dsinclair25ec6462016-11-02 12:37:12 -070041 v8::Isolate* GetJSERuntime() const;
42 CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); }
Tom Sepez744da702016-03-15 12:43:09 -070043
dsinclair655fcca2016-10-11 13:53:37 -070044 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
dsinclair8837c912016-11-01 11:22:37 -070045 void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
dsinclaira939bfe2016-09-22 13:18:45 -070046
Tom Sepez744da702016-03-15 12:43:09 -070047 void DeletePage(int page_index);
dsinclair9f206f02016-09-20 12:17:42 -070048 int GetPageCount() const;
Lei Zhang94293682016-01-27 18:27:56 -080049
dsinclair9f206f02016-09-20 12:17:42 -070050 CPDFXFA_Page* GetXFAPage(int page_index);
51 CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const;
52
53 void RemovePage(CPDFXFA_Page* page);
Lei Zhang94293682016-01-27 18:27:56 -080054
dsinclair89f8fa82016-09-14 06:11:08 -070055 void ClearChangeMark();
Lei Zhang94293682016-01-27 18:27:56 -080056
dsinclair25ec6462016-11-02 12:37:12 -070057 // IFXA_AppProvider:
Dan Sinclairc8fd3312017-01-02 17:17:02 -050058 CFX_WideString GetLanguage() override;
59 CFX_WideString GetPlatform() override;
60 CFX_WideString GetAppName() override;
61 CFX_WideString GetAppTitle() const override;
dsinclair25ec6462016-11-02 12:37:12 -070062
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,
tsepez4cf55152016-11-02 14:37:54 -070071 bool bMark) override;
tsepez833619b2016-12-07 09:21:17 -080072 CFX_RetainPtr<IFX_SeekableReadStream> DownloadURL(
73 const CFX_WideString& wsURL) override;
tsepez4cf55152016-11-02 14:37:54 -070074 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;
dsinclair25ec6462016-11-02 12:37:12 -070083
dsinclair25ec6462016-11-02 12:37:12 -070084 IFWL_AdapterTimerMgr* GetTimerMgr() override;
85
dsinclaira440bb32016-09-14 07:01:54 -070086 protected:
87 friend class CPDFXFA_DocEnvironment;
dsinclair221caf62016-04-04 12:08:40 -070088
dsinclaira440bb32016-09-14 07:01:54 -070089 int GetOriginalPageCount() const { return m_nPageCount; }
90 void SetOriginalPageCount(int count) {
91 m_nPageCount = count;
Tom Sepez5535ac72017-01-27 12:11:38 -080092 m_XFAPageList.resize(count);
dsinclaira440bb32016-09-14 07:01:54 -070093 }
94
95 LoadStatus GetLoadStatus() const { return m_nLoadStatus; }
Tom Sepez5535ac72017-01-27 12:11:38 -080096 std::vector<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; }
dsinclaira440bb32016-09-14 07:01:54 -070097
98 private:
dsinclair25ec6462016-11-02 12:37:12 -070099 void CloseXFADoc();
Lei Zhang94293682016-01-27 18:27:56 -0800100
101 int m_iDocType;
dsinclaircedaa552016-08-24 11:12:19 -0700102
dsinclaircedaa552016-08-24 11:12:19 -0700103 std::unique_ptr<CPDF_Document> m_pPDFDoc;
weili2d5b0202016-08-03 11:06:49 -0700104 std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
dsinclair655fcca2016-10-11 13:53:37 -0700105 CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned.
dsinclair521b7502016-11-02 13:02:28 -0700106 CXFA_FFDocView* m_pXFADocView; // not owned.
dsinclair25ec6462016-11-02 12:37:12 -0700107 std::unique_ptr<CXFA_FFApp> m_pXFAApp;
108 std::unique_ptr<CJS_Runtime> m_pRuntime;
Tom Sepez5535ac72017-01-27 12:11:38 -0800109 std::vector<CPDFXFA_Page*> m_XFAPageList;
jinming_wanga1cef702016-03-18 16:35:40 +0800110 LoadStatus m_nLoadStatus;
111 int m_nPageCount;
dsinclaira440bb32016-09-14 07:01:54 -0700112
dsinclair655fcca2016-10-11 13:53:37 -0700113 // Must be destroyed before |m_pFormFillEnv|.
dsinclaira440bb32016-09-14 07:01:54 -0700114 CPDFXFA_DocEnvironment m_DocEnv;
Lei Zhang94293682016-01-27 18:27:56 -0800115};
116
dsinclair521b7502016-11-02 13:02:28 -0700117#endif // FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_