John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame^] | 7 | #ifndef FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ |
| 8 | #define FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Lei Zhang | a688a04 | 2015-11-09 13:57:49 -0800 | [diff] [blame] | 10 | #include "core/include/fxcrt/fx_basic.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 11 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
| 18 | class CJS_KeyValue; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 19 | class CPDFDoc_Environment; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | class CJS_GlobalVariableArray { |
| 22 | public: |
| 23 | CJS_GlobalVariableArray(); |
| 24 | virtual ~CJS_GlobalVariableArray(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | void Empty(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | private: |
| 34 | CFX_ArrayTemplate<CJS_KeyValue*> array; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 37 | class CJS_KeyValue { |
| 38 | public: |
| 39 | CJS_KeyValue() {} |
| 40 | virtual ~CJS_KeyValue() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 41 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | class CJS_GlobalData_Element { |
| 51 | public: |
| 52 | CJS_GlobalData_Element() {} |
| 53 | virtual ~CJS_GlobalData_Element() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | CJS_KeyValue data; |
| 56 | FX_BOOL bPersistent; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | class CJS_GlobalData { |
| 60 | public: |
Tom Sepez | f458362 | 2015-09-14 15:06:53 -0700 | [diff] [blame] | 61 | static CJS_GlobalData* GetRetainedInstance(CPDFDoc_Environment* pApp); |
| 62 | void Release(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | FX_BOOL SetGlobalVariablePersistent(const FX_CHAR* propname, |
| 73 | FX_BOOL bPersistent); |
| 74 | FX_BOOL DeleteGlobalVariable(const FX_CHAR* propname); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | int32_t GetSize() const; |
| 77 | CJS_GlobalData_Element* GetAt(int index) const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | private: |
Tom Sepez | f458362 | 2015-09-14 15:06:53 -0700 | [diff] [blame] | 80 | static CJS_GlobalData* g_Instance; |
| 81 | |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 82 | CJS_GlobalData(); |
Tom Sepez | f458362 | 2015-09-14 15:06:53 -0700 | [diff] [blame] | 83 | ~CJS_GlobalData(); |
| 84 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | void LoadGlobalPersistentVariables(); |
| 86 | void SaveGlobalPersisitentVariables(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 87 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | CJS_GlobalData_Element* GetGlobalVariable(const FX_CHAR* propname); |
| 89 | int FindGlobalVariable(const FX_CHAR* propname); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | |
Tom Sepez | f458362 | 2015-09-14 15:06:53 -0700 | [diff] [blame] | 101 | size_t m_RefCount; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | CFX_ArrayTemplate<CJS_GlobalData_Element*> m_arrayGlobalData; |
| 103 | CFX_WideString m_sFilePath; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame^] | 106 | #endif // FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ |