Remove trailing whitespaces in fpdfsdk.
[pdfium.git] / fpdfsdk / include / javascript / JS_GlobalData.h
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:
41         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:
55         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(const FX_CHAR* propname, double dData);
70         void                                                            SetGlobalVariableBoolean(const FX_CHAR* propname, bool bData);
71         void                                                            SetGlobalVariableString(const FX_CHAR* propname, const CFX_ByteString& sData);
72         void                                                            SetGlobalVariableObject(const FX_CHAR* propname, const CJS_GlobalVariableArray& array);
73         void                                                            SetGlobalVariableNull(const FX_CHAR* propname);
74
75         FX_BOOL                                                         SetGlobalVariablePersistent(const FX_CHAR* propname, FX_BOOL bPersistent);
76         FX_BOOL                                                         DeleteGlobalVariable(const FX_CHAR* propname);
77
78         int32_t                                                 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(const FX_CHAR* propname);
86         int                                                                     FindGlobalVariable(const FX_CHAR* propname);
87
88         void                                                            LoadFileBuffer(const FX_WCHAR* sFilePath, uint8_t*& pBuffer, int32_t& nLength);
89         void                                                            WriteFileBuffer(const FX_WCHAR* sFilePath, const FX_CHAR* pBuffer, int32_t 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_