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