• 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_INCLUDE_JAVASCRIPT_JS_GLOBALDATA_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_GLOBALDATA_H_
9 
10 #include "../../../core/include/fxcrt/fx_basic.h"
11 
12 #define JS_GLOBALDATA_TYPE_NUMBER		0
13 #define JS_GLOBALDATA_TYPE_BOOLEAN		1
14 #define JS_GLOBALDATA_TYPE_STRING		2
15 #define JS_GLOBALDATA_TYPE_OBJECT		3
16 #define JS_GLOBALDATA_TYPE_NULL			4
17 
18 class CJS_KeyValue;
19 class CPDFDoc_Environment;
20 
21 class CJS_GlobalVariableArray
22 {
23 public:
24 	CJS_GlobalVariableArray();
25 	virtual ~CJS_GlobalVariableArray();
26 
27 	void			Add(CJS_KeyValue* p);
28 	int				Count() const;
29 	CJS_KeyValue*	GetAt(int index) const;
30 	void			Copy(const CJS_GlobalVariableArray& array);
31 
32 	void			Empty();
33 
34 private:
35 	CFX_ArrayTemplate<CJS_KeyValue*> array;
36 };
37 
38 class CJS_KeyValue
39 {
40 public:
CJS_KeyValue()41 	CJS_KeyValue(){}
~CJS_KeyValue()42 	virtual ~CJS_KeyValue(){}
43 
44 	CFX_ByteString					sKey;
45 	int								nType; //0:int 1:bool 2:string 3:obj
46 	double							dData;
47 	bool							bData;
48 	CFX_ByteString					sData;
49 	CJS_GlobalVariableArray			objData;
50 };
51 
52 class CJS_GlobalData_Element
53 {
54 public:
CJS_GlobalData_Element()55 	CJS_GlobalData_Element(){}
~CJS_GlobalData_Element()56 	virtual ~CJS_GlobalData_Element(){}
57 
58 	CJS_KeyValue			data;
59 	FX_BOOL					bPersistent;
60 };
61 
62 class CJS_GlobalData
63 {
64 public:
65 	CJS_GlobalData(CPDFDoc_Environment* pApp);
66 	virtual ~CJS_GlobalData();
67 
68 public:
69 	void								SetGlobalVariableNumber(FX_LPCSTR propname, double dData);
70 	void								SetGlobalVariableBoolean(FX_LPCSTR propname, bool bData);
71 	void								SetGlobalVariableString(FX_LPCSTR propname, const CFX_ByteString& sData);
72 	void								SetGlobalVariableObject(FX_LPCSTR propname, const CJS_GlobalVariableArray& array);
73 	void								SetGlobalVariableNull(FX_LPCSTR propname);
74 
75 	FX_BOOL								SetGlobalVariablePersistent(FX_LPCSTR propname, FX_BOOL bPersistent);
76 	FX_BOOL								DeleteGlobalVariable(FX_LPCSTR propname);
77 
78 	FX_INT32							GetSize() const;
79 	CJS_GlobalData_Element*				GetAt(int index) const;
80 
81 private:
82 	void								LoadGlobalPersistentVariables();
83 	void								SaveGlobalPersisitentVariables();
84 
85 	CJS_GlobalData_Element*				GetGlobalVariable(FX_LPCSTR propname);
86 	int									FindGlobalVariable(FX_LPCSTR propname);
87 
88 	void								LoadFileBuffer(FX_LPCWSTR sFilePath, FX_LPBYTE& pBuffer, FX_INT32& nLength);
89 	void								WriteFileBuffer(FX_LPCWSTR sFilePath, FX_LPCSTR pBuffer, FX_INT32 nLength);
90 	void								MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData);
91 
92 private:
93 	CFX_ArrayTemplate<CJS_GlobalData_Element*>	m_arrayGlobalData;
94 	CFX_WideString								m_sFilePath;
95 };
96 
97 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_JS_GLOBALDATA_H_
98