blob: ca402347f883679345265175b0540b320c365ce5 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
dsinclair16280242016-07-21 12:03:47 -07007#ifndef XFA_FXFA_PARSER_CXFA_DOCUMENT_H_
8#define XFA_FXFA_PARSER_CXFA_DOCUMENT_H_
Dan Sinclair1770c022016-03-14 14:14:16 -04009
tsepez6bb3b892017-01-05 12:18:41 -080010#include <map>
Tom Sepez742fa8c2017-03-21 17:08:48 -070011#include <memory>
Tom Sepezf8a94392017-03-14 12:13:22 -070012#include <vector>
tsepez6bb3b892017-01-05 12:18:41 -080013
Tom Sepez1a3e1862018-08-21 22:56:37 +000014#include "core/fxcrt/unowned_ptr.h"
dsinclair5b493092016-09-29 20:20:24 -070015#include "xfa/fxfa/fxfa.h"
Dan Sinclairec1843d2017-03-28 16:04:41 -040016#include "xfa/fxfa/parser/cxfa_localemgr.h"
Dan Sinclair80bf5822018-02-13 20:55:03 +000017#include "xfa/fxfa/parser/cxfa_nodeowner.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040018
Dan Sinclair1770c022016-03-14 14:14:16 -040019enum XFA_VERSION {
20 XFA_VERSION_UNKNOWN = 0,
21 XFA_VERSION_200 = 200,
22 XFA_VERSION_202 = 202,
23 XFA_VERSION_204 = 204,
24 XFA_VERSION_205 = 205,
25 XFA_VERSION_206 = 206,
26 XFA_VERSION_207 = 207,
27 XFA_VERSION_208 = 208,
28 XFA_VERSION_300 = 300,
29 XFA_VERSION_301 = 301,
30 XFA_VERSION_303 = 303,
31 XFA_VERSION_306 = 306,
32 XFA_VERSION_DEFAULT = XFA_VERSION_303,
33 XFA_VERSION_MIN = 200,
34 XFA_VERSION_MAX = 400,
35};
36
dsinclaireea31b72016-07-19 10:27:12 -070037enum XFA_DocFlag {
38 XFA_DOCFLAG_StrictScoping = 0x0001,
39 XFA_DOCFLAG_HasInteractive = 0x0002,
40 XFA_DOCFLAG_Interactive = 0x0004,
41 XFA_DOCFLAG_Scripting = 0x0008
Dan Sinclair1770c022016-03-14 14:14:16 -040042};
Dan Sinclair1770c022016-03-14 14:14:16 -040043
Dan Sinclair472bb7f2017-11-06 18:17:41 +000044class CFXJSE_Engine;
Dan Sinclaire9f7db92018-06-05 18:24:12 +000045class CJS_Runtime;
Dan Sinclair1770c022016-03-14 14:14:16 -040046class CScript_DataWindow;
47class CScript_EventPseudoModel;
48class CScript_HostPseudoModel;
Dan Sinclair1770c022016-03-14 14:14:16 -040049class CScript_LayoutPseudoModel;
Tom Sepezfb256062018-02-01 19:23:03 +000050class CScript_LogPseudoModel;
Dan Sinclair1770c022016-03-14 14:14:16 -040051class CScript_SignaturePseudoModel;
Dan Sinclair472bb7f2017-11-06 18:17:41 +000052class CXFA_FFNotify;
dsinclaireea31b72016-07-19 10:27:12 -070053class CXFA_Node;
Dan Sinclair472bb7f2017-11-06 18:17:41 +000054class CXFA_Object;
weili47bcd4c2016-06-16 08:00:06 -070055
Tom Sepez55865452018-08-27 20:18:04 +000056class CXFA_Document final : public CXFA_NodeOwner {
Dan Sinclair1770c022016-03-14 14:14:16 -040057 public:
Tom Sepez9010e562019-06-11 16:59:51 +000058 class LayoutProcessorIface {
59 public:
60 LayoutProcessorIface();
61 virtual ~LayoutProcessorIface();
62 virtual void SetForceRelayout(bool enable) = 0;
63
64 void SetDocument(CXFA_Document* pDocument) { m_pDocument = pDocument; }
65 CXFA_Document* GetDocument() const { return m_pDocument.Get(); }
66
67 private:
68 UnownedPtr<CXFA_Document> m_pDocument;
69 };
70
71 CXFA_Document(CXFA_FFNotify* notify,
72 std::unique_ptr<LayoutProcessorIface> pLayout);
Dan Sinclair80bf5822018-02-13 20:55:03 +000073 ~CXFA_Document() override;
Dan Sinclair8853b7f2018-02-13 19:00:27 +000074
Tom Sepez7e4877f2019-04-05 21:32:36 +000075 bool HasScriptContext() const { return !!m_pScriptContext; }
Dan Sinclaire9f7db92018-06-05 18:24:12 +000076 CFXJSE_Engine* InitScriptContext(CJS_Runtime* fxjs_runtime);
Tom Sepez7e4877f2019-04-05 21:32:36 +000077
78 // Only safe to call in situations where the context is known to exist,
79 // and always returns non-NULL in those situations. In other words, we have
80 // to call InitScriptContext() first to avoid a situation where the context
81 // won't have an isolate set into it.
Tom Sepezad7d5862019-02-06 23:02:03 +000082 CFXJSE_Engine* GetScriptContext() const;
dsinclaireea31b72016-07-19 10:27:12 -070083
Dan Sinclair9c112f92018-02-13 21:27:44 +000084 CXFA_FFNotify* GetNotify() const { return notify_.Get(); }
Lei Zhang5822da72018-07-30 17:46:18 +000085 CXFA_LocaleMgr* GetLocaleMgr();
dsinclaircbfef572016-05-18 13:16:12 -070086 CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash);
Tom Sepez1ab27572018-12-14 20:31:31 +000087 CXFA_Node* GetNodeByID(CXFA_Node* pRoot, WideStringView wsID) const;
Tom Sepez1a3e1862018-08-21 22:56:37 +000088 CXFA_Node* GetNotBindNode(
89 const std::vector<UnownedPtr<CXFA_Object>>& arrayNodes) const;
dsinclaireea31b72016-07-19 10:27:12 -070090
Tom Sepez9010e562019-06-11 16:59:51 +000091 LayoutProcessorIface* GetLayoutProcessor() const {
92 return m_pLayoutProcessor.get();
93 }
Tom Sepezad7d5862019-02-06 23:02:03 +000094
95 CXFA_Node* GetRoot() const { return m_pRootNode; }
Dan Sinclair80bf5822018-02-13 20:55:03 +000096 void SetRoot(CXFA_Node* pNewRoot) { m_pRootNode = pNewRoot; }
dsinclaireea31b72016-07-19 10:27:12 -070097
Dan Sinclaird8d6f552018-02-14 15:44:21 +000098 bool HasFlag(uint32_t dwFlag) const {
99 return (m_dwDocFlags & dwFlag) == dwFlag;
100 }
tsepezd19e9122016-11-02 15:43:18 -0700101 void SetFlag(uint32_t dwFlag, bool bOn);
dsinclaireea31b72016-07-19 10:27:12 -0700102
tsepezd19e9122016-11-02 15:43:18 -0700103 bool IsInteractive();
Dan Sinclair1770c022016-03-14 14:14:16 -0400104 XFA_VERSION GetCurVersionMode() { return m_eCurVersionMode; }
Ryan Harrison275e2602017-09-18 14:23:18 -0400105 XFA_VERSION RecognizeXFAVersionNumber(const WideString& wsTemplateNS);
Henrique Nakashima36b20592018-07-24 20:25:45 +0000106 FormType GetFormType() const;
dsinclaireea31b72016-07-19 10:27:12 -0700107
Dan Sinclairc40c5aa2017-11-30 21:29:11 +0000108 CXFA_Node* CreateNode(XFA_PacketType packet, XFA_Element eElement);
dsinclaireea31b72016-07-19 10:27:12 -0700109
Dan Sinclair1770c022016-03-14 14:14:16 -0400110 void DoProtoMerge();
Dan Sinclair1770c022016-03-14 14:14:16 -0400111 void DoDataMerge();
tsepezd19e9122016-11-02 15:43:18 -0700112 void DoDataRemerge(bool bDoDataMerge);
Dan Sinclair1770c022016-03-14 14:14:16 -0400113 CXFA_Node* DataMerge_CopyContainer(CXFA_Node* pTemplateNode,
114 CXFA_Node* pFormNode,
115 CXFA_Node* pDataScope,
tsepezd19e9122016-11-02 15:43:18 -0700116 bool bOneInstance,
117 bool bDataMerge,
118 bool bUpLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400119 void DataMerge_UpdateBindingRelations(CXFA_Node* pFormUpdateRoot);
dsinclaireea31b72016-07-19 10:27:12 -0700120
Dan Sinclair1770c022016-03-14 14:14:16 -0400121 void ClearLayoutData();
122
Dan Sinclair5a552532018-04-05 19:05:11 +0000123 CXFA_Node* GetGlobalBinding(uint32_t dwNameHash);
124 void RegisterGlobalBinding(uint32_t dwNameHash, CXFA_Node* pDataNode);
Tom Sepeze7731b32019-06-14 23:46:44 +0000125 void SetPendingNodesUnusedAndUnbound();
Dan Sinclair5a552532018-04-05 19:05:11 +0000126
Tom Sepezf8a94392017-03-14 12:13:22 -0700127 std::vector<CXFA_Node*> m_pPendingPageSet;
Dan Sinclair1770c022016-03-14 14:14:16 -0400128
Dan Sinclair25d2ad42017-03-23 15:19:44 -0400129 private:
Tom Sepez69873e92019-02-04 19:42:39 +0000130 UnownedPtr<CXFA_FFNotify> const notify_;
Tom Sepez9010e562019-06-11 16:59:51 +0000131 CXFA_Node* m_pRootNode = nullptr;
Dan Sinclair5a552532018-04-05 19:05:11 +0000132 std::map<uint32_t, CXFA_Node*> m_rgGlobalBinding;
Dan Sinclair3fff90a2017-11-01 13:12:39 +0000133 std::unique_ptr<CFXJSE_Engine> m_pScriptContext;
Tom Sepez9010e562019-06-11 16:59:51 +0000134 std::unique_ptr<LayoutProcessorIface> m_pLayoutProcessor;
Lei Zhang5822da72018-07-30 17:46:18 +0000135 std::unique_ptr<CXFA_LocaleMgr> m_pLocaleMgr;
Tom Sepez742fa8c2017-03-21 17:08:48 -0700136 std::unique_ptr<CScript_DataWindow> m_pScriptDataWindow;
137 std::unique_ptr<CScript_EventPseudoModel> m_pScriptEvent;
138 std::unique_ptr<CScript_HostPseudoModel> m_pScriptHost;
139 std::unique_ptr<CScript_LogPseudoModel> m_pScriptLog;
140 std::unique_ptr<CScript_LayoutPseudoModel> m_pScriptLayout;
141 std::unique_ptr<CScript_SignaturePseudoModel> m_pScriptSignature;
Tom Sepez9010e562019-06-11 16:59:51 +0000142 XFA_VERSION m_eCurVersionMode = XFA_VERSION_DEFAULT;
143 uint32_t m_dwDocFlags = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400144};
145
dsinclair16280242016-07-21 12:03:47 -0700146#endif // XFA_FXFA_PARSER_CXFA_DOCUMENT_H_