Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 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 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ |
| 8 | #define FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 9 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 10 | #include <memory> |
Tom Sepez | 5535ac7 | 2017-01-27 12:11:38 -0800 | [diff] [blame] | 11 | #include <vector> |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 12 | |
dsinclair | bec7692 | 2016-09-29 16:52:30 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 14 | #include "xfa/fxfa/xfa_ffdoc.h" |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 15 | |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 16 | class CJS_Runtime; |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 17 | class CPDFSDK_FormFillEnvironment; |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 18 | class CPDFXFA_Page; |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 19 | class CXFA_FFDocHandler; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame^] | 20 | class IJS_EventContext; |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 21 | class IJS_Runtime; |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 22 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 23 | enum LoadStatus { |
| 24 | FXFA_LOADSTATUS_PRELOAD = 0, |
| 25 | FXFA_LOADSTATUS_LOADING, |
| 26 | FXFA_LOADSTATUS_LOADED, |
| 27 | FXFA_LOADSTATUS_CLOSING, |
| 28 | FXFA_LOADSTATUS_CLOSED |
| 29 | }; |
| 30 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 31 | class CPDFXFA_Context : public IXFA_AppProvider { |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 32 | public: |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 33 | explicit CPDFXFA_Context(std::unique_ptr<CPDF_Document> pPDFDoc); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 34 | ~CPDFXFA_Context() override; |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 35 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 36 | bool LoadXFADoc(); |
dsinclair | cedaa55 | 2016-08-24 11:12:19 -0700 | [diff] [blame] | 37 | CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } |
weili | 2d5b020 | 2016-08-03 11:06:49 -0700 | [diff] [blame] | 38 | CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 39 | CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 40 | int GetDocType() const { return m_iDocType; } |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 41 | v8::Isolate* GetJSERuntime() const; |
| 42 | CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } |
Tom Sepez | 744da70 | 2016-03-15 12:43:09 -0700 | [diff] [blame] | 43 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 44 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; } |
dsinclair | 8837c91 | 2016-11-01 11:22:37 -0700 | [diff] [blame] | 45 | void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 46 | |
Tom Sepez | 744da70 | 2016-03-15 12:43:09 -0700 | [diff] [blame] | 47 | void DeletePage(int page_index); |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 48 | int GetPageCount() const; |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 49 | |
dsinclair | 9f206f0 | 2016-09-20 12:17:42 -0700 | [diff] [blame] | 50 | CPDFXFA_Page* GetXFAPage(int page_index); |
| 51 | CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const; |
| 52 | |
| 53 | void RemovePage(CPDFXFA_Page* page); |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 54 | |
dsinclair | 89f8fa8 | 2016-09-14 06:11:08 -0700 | [diff] [blame] | 55 | void ClearChangeMark(); |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 56 | |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 57 | // IFXA_AppProvider: |
Dan Sinclair | c8fd331 | 2017-01-02 17:17:02 -0500 | [diff] [blame] | 58 | CFX_WideString GetLanguage() override; |
| 59 | CFX_WideString GetPlatform() override; |
| 60 | CFX_WideString GetAppName() override; |
| 61 | CFX_WideString GetAppTitle() const override; |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 62 | |
| 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, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 71 | bool bMark) override; |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 72 | CFX_RetainPtr<IFX_SeekableReadStream> DownloadURL( |
| 73 | const CFX_WideString& wsURL) override; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 74 | 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; |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 83 | |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 84 | IFWL_AdapterTimerMgr* GetTimerMgr() override; |
| 85 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 86 | protected: |
| 87 | friend class CPDFXFA_DocEnvironment; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 88 | |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 89 | int GetOriginalPageCount() const { return m_nPageCount; } |
| 90 | void SetOriginalPageCount(int count) { |
| 91 | m_nPageCount = count; |
Tom Sepez | 5535ac7 | 2017-01-27 12:11:38 -0800 | [diff] [blame] | 92 | m_XFAPageList.resize(count); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | LoadStatus GetLoadStatus() const { return m_nLoadStatus; } |
Tom Sepez | 5535ac7 | 2017-01-27 12:11:38 -0800 | [diff] [blame] | 96 | std::vector<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 97 | |
| 98 | private: |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 99 | void CloseXFADoc(); |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 100 | |
| 101 | int m_iDocType; |
dsinclair | cedaa55 | 2016-08-24 11:12:19 -0700 | [diff] [blame] | 102 | |
dsinclair | cedaa55 | 2016-08-24 11:12:19 -0700 | [diff] [blame] | 103 | std::unique_ptr<CPDF_Document> m_pPDFDoc; |
weili | 2d5b020 | 2016-08-03 11:06:49 -0700 | [diff] [blame] | 104 | std::unique_ptr<CXFA_FFDoc> m_pXFADoc; |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 105 | CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned. |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 106 | CXFA_FFDocView* m_pXFADocView; // not owned. |
dsinclair | 25ec646 | 2016-11-02 12:37:12 -0700 | [diff] [blame] | 107 | std::unique_ptr<CXFA_FFApp> m_pXFAApp; |
| 108 | std::unique_ptr<CJS_Runtime> m_pRuntime; |
Tom Sepez | 5535ac7 | 2017-01-27 12:11:38 -0800 | [diff] [blame] | 109 | std::vector<CPDFXFA_Page*> m_XFAPageList; |
jinming_wang | a1cef70 | 2016-03-18 16:35:40 +0800 | [diff] [blame] | 110 | LoadStatus m_nLoadStatus; |
| 111 | int m_nPageCount; |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 112 | |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 113 | // Must be destroyed before |m_pFormFillEnv|. |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 114 | CPDFXFA_DocEnvironment m_DocEnv; |
Lei Zhang | 9429368 | 2016-01-27 18:27:56 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 117 | #endif // FPDFSDK_FPDFXFA_CPDFXFA_CONTEXT_H_ |