• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_
8 #define FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_basic.h"
14 #include "fpdfsdk/javascript/JS_KeyValue.h"
15 
16 class CPDFSDK_FormFillEnvironment;
17 
18 class CJS_GlobalData_Element {
19  public:
CJS_GlobalData_Element()20   CJS_GlobalData_Element() {}
~CJS_GlobalData_Element()21   ~CJS_GlobalData_Element() {}
22 
23   CJS_KeyValue data;
24   bool bPersistent;
25 };
26 
27 class CJS_GlobalData {
28  public:
29   static CJS_GlobalData* GetRetainedInstance(CPDFSDK_FormFillEnvironment* pApp);
30   void Release();
31 
32   void SetGlobalVariableNumber(const CFX_ByteString& propname, double dData);
33   void SetGlobalVariableBoolean(const CFX_ByteString& propname, bool bData);
34   void SetGlobalVariableString(const CFX_ByteString& propname,
35                                const CFX_ByteString& sData);
36   void SetGlobalVariableObject(const CFX_ByteString& propname,
37                                const CJS_GlobalVariableArray& array);
38   void SetGlobalVariableNull(const CFX_ByteString& propname);
39   bool SetGlobalVariablePersistent(const CFX_ByteString& propname,
40                                    bool bPersistent);
41   bool DeleteGlobalVariable(const CFX_ByteString& propname);
42 
43   int32_t GetSize() const;
44   CJS_GlobalData_Element* GetAt(int index) const;
45 
46  private:
47   using iterator =
48       std::vector<std::unique_ptr<CJS_GlobalData_Element>>::iterator;
49   using const_iterator =
50       std::vector<std::unique_ptr<CJS_GlobalData_Element>>::const_iterator;
51 
52   CJS_GlobalData();
53   ~CJS_GlobalData();
54 
55   void LoadGlobalPersistentVariables();
56   void SaveGlobalPersisitentVariables();
57 
58   CJS_GlobalData_Element* GetGlobalVariable(const CFX_ByteString& sPropname);
59   iterator FindGlobalVariable(const CFX_ByteString& sPropname);
60   const_iterator FindGlobalVariable(const CFX_ByteString& sPropname) const;
61 
62   void LoadFileBuffer(const FX_WCHAR* sFilePath,
63                       uint8_t*& pBuffer,
64                       int32_t& nLength);
65   void WriteFileBuffer(const FX_WCHAR* sFilePath,
66                        const FX_CHAR* pBuffer,
67                        int32_t nLength);
68   void MakeByteString(const CFX_ByteString& name,
69                       CJS_KeyValue* pData,
70                       CFX_BinaryBuf& sData);
71 
72   size_t m_RefCount;
73   std::vector<std::unique_ptr<CJS_GlobalData_Element>> m_arrayGlobalData;
74   CFX_WideString m_sFilePath;
75 };
76 
77 #endif  // FPDFSDK_JAVASCRIPT_JS_GLOBALDATA_H_
78