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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_GLOBALDATA_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_GLOBALDATA_H_
10 #include "../../../core/include/fxcrt/fx_basic.h"
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
19 class CPDFDoc_Environment;
21 class CJS_GlobalVariableArray {
23 CJS_GlobalVariableArray();
24 virtual ~CJS_GlobalVariableArray();
26 void Add(CJS_KeyValue* p);
28 CJS_KeyValue* GetAt(int index) const;
29 void Copy(const CJS_GlobalVariableArray& array);
34 CFX_ArrayTemplate<CJS_KeyValue*> array;
40 virtual ~CJS_KeyValue() {}
43 int nType; // 0:int 1:bool 2:string 3:obj
47 CJS_GlobalVariableArray objData;
50 class CJS_GlobalData_Element {
52 CJS_GlobalData_Element() {}
53 virtual ~CJS_GlobalData_Element() {}
59 class CJS_GlobalData {
61 static CJS_GlobalData* GetRetainedInstance(CPDFDoc_Environment* pApp);
64 void SetGlobalVariableNumber(const FX_CHAR* propname, double dData);
65 void SetGlobalVariableBoolean(const FX_CHAR* propname, bool bData);
66 void SetGlobalVariableString(const FX_CHAR* propname,
67 const CFX_ByteString& sData);
68 void SetGlobalVariableObject(const FX_CHAR* propname,
69 const CJS_GlobalVariableArray& array);
70 void SetGlobalVariableNull(const FX_CHAR* propname);
72 FX_BOOL SetGlobalVariablePersistent(const FX_CHAR* propname,
74 FX_BOOL DeleteGlobalVariable(const FX_CHAR* propname);
76 int32_t GetSize() const;
77 CJS_GlobalData_Element* GetAt(int index) const;
80 static CJS_GlobalData* g_Instance;
82 CJS_GlobalData(CPDFDoc_Environment* pApp);
85 void LoadGlobalPersistentVariables();
86 void SaveGlobalPersisitentVariables();
88 CJS_GlobalData_Element* GetGlobalVariable(const FX_CHAR* propname);
89 int FindGlobalVariable(const FX_CHAR* propname);
91 void LoadFileBuffer(const FX_WCHAR* sFilePath,
94 void WriteFileBuffer(const FX_WCHAR* sFilePath,
95 const FX_CHAR* pBuffer,
97 void MakeByteString(const CFX_ByteString& name,
99 CFX_BinaryBuf& sData);
103 CFX_ArrayTemplate<CJS_GlobalData_Element*> m_arrayGlobalData;
104 CFX_WideString m_sFilePath;
107 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_GLOBALDATA_H_