| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ |
| 8 #define FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ | 8 #define FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/fxcrt/include/fx_basic.h" | 13 #include "core/fxcrt/include/fx_basic.h" |
| 14 #include "fpdfsdk/javascript/JS_KeyValue.h" |
| 14 | 15 |
| 15 #define JS_GLOBALDATA_TYPE_NUMBER 0 | |
| 16 #define JS_GLOBALDATA_TYPE_BOOLEAN 1 | |
| 17 #define JS_GLOBALDATA_TYPE_STRING 2 | |
| 18 #define JS_GLOBALDATA_TYPE_OBJECT 3 | |
| 19 #define JS_GLOBALDATA_TYPE_NULL 4 | |
| 20 | |
| 21 class CJS_KeyValue; | |
| 22 class CPDFDoc_Environment; | 16 class CPDFDoc_Environment; |
| 23 | 17 |
| 24 class CJS_GlobalVariableArray { | |
| 25 public: | |
| 26 CJS_GlobalVariableArray(); | |
| 27 virtual ~CJS_GlobalVariableArray(); | |
| 28 | |
| 29 void Add(CJS_KeyValue* p); | |
| 30 int Count() const; | |
| 31 CJS_KeyValue* GetAt(int index) const; | |
| 32 void Copy(const CJS_GlobalVariableArray& array); | |
| 33 | |
| 34 void Empty(); | |
| 35 | |
| 36 private: | |
| 37 CFX_ArrayTemplate<CJS_KeyValue*> m_Array; | |
| 38 }; | |
| 39 | |
| 40 class CJS_KeyValue { | |
| 41 public: | |
| 42 CJS_KeyValue(); | |
| 43 virtual ~CJS_KeyValue(); | |
| 44 | |
| 45 CFX_ByteString sKey; | |
| 46 int nType; // 0:int 1:bool 2:string 3:obj | |
| 47 double dData; | |
| 48 bool bData; | |
| 49 CFX_ByteString sData; | |
| 50 CJS_GlobalVariableArray objData; | |
| 51 }; | |
| 52 | |
| 53 class CJS_GlobalData_Element { | 18 class CJS_GlobalData_Element { |
| 54 public: | 19 public: |
| 55 CJS_GlobalData_Element() {} | 20 CJS_GlobalData_Element() {} |
| 56 virtual ~CJS_GlobalData_Element() {} | 21 ~CJS_GlobalData_Element() {} |
| 57 | 22 |
| 58 CJS_KeyValue data; | 23 CJS_KeyValue data; |
| 59 FX_BOOL bPersistent; | 24 FX_BOOL bPersistent; |
| 60 }; | 25 }; |
| 61 | 26 |
| 62 class CJS_GlobalData { | 27 class CJS_GlobalData { |
| 63 public: | 28 public: |
| 64 static CJS_GlobalData* GetRetainedInstance(CPDFDoc_Environment* pApp); | 29 static CJS_GlobalData* GetRetainedInstance(CPDFDoc_Environment* pApp); |
| 65 void Release(); | 30 void Release(); |
| 66 | 31 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 | 42 |
| 78 int32_t GetSize() const; | 43 int32_t GetSize() const; |
| 79 CJS_GlobalData_Element* GetAt(int index) const; | 44 CJS_GlobalData_Element* GetAt(int index) const; |
| 80 | 45 |
| 81 private: | 46 private: |
| 82 using iterator = | 47 using iterator = |
| 83 std::vector<std::unique_ptr<CJS_GlobalData_Element>>::iterator; | 48 std::vector<std::unique_ptr<CJS_GlobalData_Element>>::iterator; |
| 84 using const_iterator = | 49 using const_iterator = |
| 85 std::vector<std::unique_ptr<CJS_GlobalData_Element>>::const_iterator; | 50 std::vector<std::unique_ptr<CJS_GlobalData_Element>>::const_iterator; |
| 86 | 51 |
| 87 static CJS_GlobalData* g_Instance; | |
| 88 | |
| 89 CJS_GlobalData(); | 52 CJS_GlobalData(); |
| 90 ~CJS_GlobalData(); | 53 ~CJS_GlobalData(); |
| 91 | 54 |
| 92 void LoadGlobalPersistentVariables(); | 55 void LoadGlobalPersistentVariables(); |
| 93 void SaveGlobalPersisitentVariables(); | 56 void SaveGlobalPersisitentVariables(); |
| 94 | 57 |
| 95 CJS_GlobalData_Element* GetGlobalVariable(const CFX_ByteString& sPropname); | 58 CJS_GlobalData_Element* GetGlobalVariable(const CFX_ByteString& sPropname); |
| 96 iterator FindGlobalVariable(const CFX_ByteString& sPropname); | 59 iterator FindGlobalVariable(const CFX_ByteString& sPropname); |
| 97 const_iterator FindGlobalVariable(const CFX_ByteString& sPropname) const; | 60 const_iterator FindGlobalVariable(const CFX_ByteString& sPropname) const; |
| 98 | 61 |
| 99 void LoadFileBuffer(const FX_WCHAR* sFilePath, | 62 void LoadFileBuffer(const FX_WCHAR* sFilePath, |
| 100 uint8_t*& pBuffer, | 63 uint8_t*& pBuffer, |
| 101 int32_t& nLength); | 64 int32_t& nLength); |
| 102 void WriteFileBuffer(const FX_WCHAR* sFilePath, | 65 void WriteFileBuffer(const FX_WCHAR* sFilePath, |
| 103 const FX_CHAR* pBuffer, | 66 const FX_CHAR* pBuffer, |
| 104 int32_t nLength); | 67 int32_t nLength); |
| 105 void MakeByteString(const CFX_ByteString& name, | 68 void MakeByteString(const CFX_ByteString& name, |
| 106 CJS_KeyValue* pData, | 69 CJS_KeyValue* pData, |
| 107 CFX_BinaryBuf& sData); | 70 CFX_BinaryBuf& sData); |
| 108 | 71 |
| 109 size_t m_RefCount; | 72 size_t m_RefCount; |
| 110 std::vector<std::unique_ptr<CJS_GlobalData_Element>> m_arrayGlobalData; | 73 std::vector<std::unique_ptr<CJS_GlobalData_Element>> m_arrayGlobalData; |
| 111 CFX_WideString m_sFilePath; | 74 CFX_WideString m_sFilePath; |
| 112 }; | 75 }; |
| 113 | 76 |
| 114 #endif // FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ | 77 #endif // FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_ |
| OLD | NEW |