blob: 586e12d5be4550d22830f56e5c4334354095eeaf [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
Tom Sepez940967d2017-05-18 12:32:20 -070013#include "core/fxcrt/cfx_observable.h"
Tom Sepezcc205132017-05-16 14:01:47 -070014#include "core/fxcrt/cfx_unowned_ptr.h"
15#include "core/fxcrt/fx_system.h"
dsinclairbec76922016-09-29 16:52:30 -070016#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
Tom Sepez9792f162017-05-16 14:11:30 -070017#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040018#include "xfa/fxfa/cxfa_ffdoc.h"
weili625ad662016-06-15 11:21:33 -070019
dsinclair25ec6462016-11-02 12:37:12 -070020class CJS_Runtime;
dsinclair735606d2016-10-05 15:47:02 -070021class CPDFSDK_FormFillEnvironment;
dsinclairdf4bc592016-03-31 20:34:43 -070022class CXFA_FFDocHandler;
Tom Sepezd6ae2af2017-02-16 11:49:55 -080023class IJS_EventContext;
dsinclair79db6092016-09-14 07:27:21 -070024class IJS_Runtime;
Lei Zhang94293682016-01-27 18:27:56 -080025
dsinclaira440bb32016-09-14 07:01:54 -070026enum LoadStatus {
27 FXFA_LOADSTATUS_PRELOAD = 0,
28 FXFA_LOADSTATUS_LOADING,
29 FXFA_LOADSTATUS_LOADED,
30 FXFA_LOADSTATUS_CLOSING,
31 FXFA_LOADSTATUS_CLOSED
32};
33
dsinclair521b7502016-11-02 13:02:28 -070034class CPDFXFA_Context : public IXFA_AppProvider {
Lei Zhang94293682016-01-27 18:27:56 -080035 public:
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050036 explicit CPDFXFA_Context(std::unique_ptr<CPDF_Document> pPDFDoc);
dsinclair521b7502016-11-02 13:02:28 -070037 ~CPDFXFA_Context() override;
Lei Zhang94293682016-01-27 18:27:56 -080038
tsepez4cf55152016-11-02 14:37:54 -070039 bool LoadXFADoc();
dsinclaircedaa552016-08-24 11:12:19 -070040 CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); }
weili2d5b0202016-08-03 11:06:49 -070041 CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); }
Tom Sepezcc205132017-05-16 14:01:47 -070042 CXFA_FFDocView* GetXFADocView() { return m_pXFADocView.Get(); }
Dan Sinclaircdba7472017-03-23 09:17:10 -040043 XFA_DocType GetDocType() const { return m_iDocType; }
dsinclair25ec6462016-11-02 12:37:12 -070044 v8::Isolate* GetJSERuntime() const;
45 CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); }
Tom Sepez744da702016-03-15 12:43:09 -070046
Tom Sepezcc205132017-05-16 14:01:47 -070047 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
48 return m_pFormFillEnv.Get();
49 }
dsinclair8837c912016-11-01 11:22:37 -070050 void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
dsinclaira939bfe2016-09-22 13:18:45 -070051
dsinclair9f206f02016-09-20 12:17:42 -070052 int GetPageCount() const;
Tom Sepez9792f162017-05-16 14:11:30 -070053 void DeletePage(int page_index);
54 CFX_RetainPtr<CPDFXFA_Page> GetXFAPage(int page_index);
55 CFX_RetainPtr<CPDFXFA_Page> GetXFAPage(CXFA_FFPageView* pPage) const;
dsinclair89f8fa82016-09-14 06:11:08 -070056 void ClearChangeMark();
Lei Zhang94293682016-01-27 18:27:56 -080057
dsinclair25ec6462016-11-02 12:37:12 -070058 // IFXA_AppProvider:
Dan Sinclairc8fd3312017-01-02 17:17:02 -050059 CFX_WideString GetLanguage() override;
60 CFX_WideString GetPlatform() override;
61 CFX_WideString GetAppName() override;
62 CFX_WideString GetAppTitle() const override;
dsinclair25ec6462016-11-02 12:37:12 -070063
64 void Beep(uint32_t dwType) override;
65 int32_t MsgBox(const CFX_WideString& wsMessage,
66 const CFX_WideString& wsTitle,
67 uint32_t dwIconType,
68 uint32_t dwButtonType) override;
69 CFX_WideString Response(const CFX_WideString& wsQuestion,
70 const CFX_WideString& wsTitle,
71 const CFX_WideString& wsDefaultAnswer,
tsepez4cf55152016-11-02 14:37:54 -070072 bool bMark) override;
tsepez833619b2016-12-07 09:21:17 -080073 CFX_RetainPtr<IFX_SeekableReadStream> DownloadURL(
74 const CFX_WideString& wsURL) override;
tsepez4cf55152016-11-02 14:37:54 -070075 bool PostRequestURL(const CFX_WideString& wsURL,
76 const CFX_WideString& wsData,
77 const CFX_WideString& wsContentType,
78 const CFX_WideString& wsEncode,
79 const CFX_WideString& wsHeader,
80 CFX_WideString& wsResponse) override;
81 bool PutRequestURL(const CFX_WideString& wsURL,
82 const CFX_WideString& wsData,
83 const CFX_WideString& wsEncode) override;
dsinclair25ec6462016-11-02 12:37:12 -070084
dsinclair25ec6462016-11-02 12:37:12 -070085 IFWL_AdapterTimerMgr* GetTimerMgr() override;
86
dsinclaira440bb32016-09-14 07:01:54 -070087 protected:
88 friend class CPDFXFA_DocEnvironment;
dsinclair221caf62016-04-04 12:08:40 -070089
dsinclaira440bb32016-09-14 07:01:54 -070090 int GetOriginalPageCount() const { return m_nPageCount; }
91 void SetOriginalPageCount(int count) {
92 m_nPageCount = count;
Tom Sepez5535ac72017-01-27 12:11:38 -080093 m_XFAPageList.resize(count);
dsinclaira440bb32016-09-14 07:01:54 -070094 }
95
96 LoadStatus GetLoadStatus() const { return m_nLoadStatus; }
Tom Sepez9792f162017-05-16 14:11:30 -070097 std::vector<CFX_RetainPtr<CPDFXFA_Page>>* GetXFAPageList() {
98 return &m_XFAPageList;
99 }
dsinclaira440bb32016-09-14 07:01:54 -0700100
101 private:
dsinclair25ec6462016-11-02 12:37:12 -0700102 void CloseXFADoc();
Lei Zhang94293682016-01-27 18:27:56 -0800103
Dan Sinclaircdba7472017-03-23 09:17:10 -0400104 XFA_DocType m_iDocType;
dsinclaircedaa552016-08-24 11:12:19 -0700105 std::unique_ptr<CPDF_Document> m_pPDFDoc;
weili2d5b0202016-08-03 11:06:49 -0700106 std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
Tom Sepez940967d2017-05-18 12:32:20 -0700107 CFX_Observable<CPDFSDK_FormFillEnvironment>::ObservedPtr m_pFormFillEnv;
Tom Sepezcc205132017-05-16 14:01:47 -0700108 CFX_UnownedPtr<CXFA_FFDocView> m_pXFADocView;
dsinclair25ec6462016-11-02 12:37:12 -0700109 std::unique_ptr<CXFA_FFApp> m_pXFAApp;
110 std::unique_ptr<CJS_Runtime> m_pRuntime;
Tom Sepez9792f162017-05-16 14:11:30 -0700111 std::vector<CFX_RetainPtr<CPDFXFA_Page>> m_XFAPageList;
jinming_wanga1cef702016-03-18 16:35:40 +0800112 LoadStatus m_nLoadStatus;
113 int m_nPageCount;
dsinclaira440bb32016-09-14 07:01:54 -0700114
dsinclair655fcca2016-10-11 13:53:37 -0700115 // Must be destroyed before |m_pFormFillEnv|.
dsinclaira440bb32016-09-14 07:01:54 -0700116 CPDFXFA_DocEnvironment m_DocEnv;
Lei Zhang94293682016-01-27 18:27:56 -0800117};
118
dsinclair521b7502016-11-02 13:02:28 -0700119#endif // FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_