blob: b174a8d76e53707c36dcca477f9e711a5c3bda1f [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez37458412015-10-06 11:33:46 -07007#ifndef FPDFSDK_SRC_JAVASCRIPT_JS_GLOBALDATA_H_
8#define FPDFSDK_SRC_JAVASCRIPT_JS_GLOBALDATA_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez9a3f8122015-04-07 15:35:48 -070010#include "../../../core/include/fxcrt/fx_basic.h"
11
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012#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
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
18class CJS_KeyValue;
Tom Sepez9a3f8122015-04-07 15:35:48 -070019class CPDFDoc_Environment;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021class CJS_GlobalVariableArray {
22 public:
23 CJS_GlobalVariableArray();
24 virtual ~CJS_GlobalVariableArray();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 void Add(CJS_KeyValue* p);
27 int Count() const;
28 CJS_KeyValue* GetAt(int index) const;
29 void Copy(const CJS_GlobalVariableArray& array);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 void Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 private:
34 CFX_ArrayTemplate<CJS_KeyValue*> array;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035};
36
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037class CJS_KeyValue {
38 public:
39 CJS_KeyValue() {}
40 virtual ~CJS_KeyValue() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 CFX_ByteString sKey;
43 int nType; // 0:int 1:bool 2:string 3:obj
44 double dData;
45 bool bData;
46 CFX_ByteString sData;
47 CJS_GlobalVariableArray objData;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048};
49
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050class CJS_GlobalData_Element {
51 public:
52 CJS_GlobalData_Element() {}
53 virtual ~CJS_GlobalData_Element() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 CJS_KeyValue data;
56 FX_BOOL bPersistent;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057};
58
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059class CJS_GlobalData {
60 public:
Tom Sepezf4583622015-09-14 15:06:53 -070061 static CJS_GlobalData* GetRetainedInstance(CPDFDoc_Environment* pApp);
62 void Release();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 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);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 FX_BOOL SetGlobalVariablePersistent(const FX_CHAR* propname,
73 FX_BOOL bPersistent);
74 FX_BOOL DeleteGlobalVariable(const FX_CHAR* propname);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070075
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 int32_t GetSize() const;
77 CJS_GlobalData_Element* GetAt(int index) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 private:
Tom Sepezf4583622015-09-14 15:06:53 -070080 static CJS_GlobalData* g_Instance;
81
82 CJS_GlobalData(CPDFDoc_Environment* pApp);
83 ~CJS_GlobalData();
84
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 void LoadGlobalPersistentVariables();
86 void SaveGlobalPersisitentVariables();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 CJS_GlobalData_Element* GetGlobalVariable(const FX_CHAR* propname);
89 int FindGlobalVariable(const FX_CHAR* propname);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 void LoadFileBuffer(const FX_WCHAR* sFilePath,
92 uint8_t*& pBuffer,
93 int32_t& nLength);
94 void WriteFileBuffer(const FX_WCHAR* sFilePath,
95 const FX_CHAR* pBuffer,
96 int32_t nLength);
97 void MakeByteString(const CFX_ByteString& name,
98 CJS_KeyValue* pData,
99 CFX_BinaryBuf& sData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 private:
Tom Sepezf4583622015-09-14 15:06:53 -0700102 size_t m_RefCount;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 CFX_ArrayTemplate<CJS_GlobalData_Element*> m_arrayGlobalData;
104 CFX_WideString m_sFilePath;
105 CPDFDoc_Environment* m_pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106};
107
Tom Sepez37458412015-10-06 11:33:46 -0700108#endif // FPDFSDK_SRC_JAVASCRIPT_JS_GLOBALDATA_H_