• 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 FXJS_CJS_GLOBAL_H_
8 #define FXJS_CJS_GLOBAL_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "fxjs/cfx_keyvalue.h"
15 #include "fxjs/cjs_object.h"
16 #include "fxjs/cjs_result.h"
17 
18 class CFX_GlobalData;
19 
20 class CJS_Global final : public CJS_Object {
21  public:
22   static int GetObjDefnID();
23   static void DefineJSObjects(CFXJS_Engine* pEngine);
24   static void DefineAllProperties(CFXJS_Engine* pEngine);
25 
26   static void queryprop_static(
27       v8::Local<v8::Name> property,
28       const v8::PropertyCallbackInfo<v8::Integer>& info);
29   static void getprop_static(v8::Local<v8::Name> property,
30                              const v8::PropertyCallbackInfo<v8::Value>& info);
31   static void putprop_static(v8::Local<v8::Name> property,
32                              v8::Local<v8::Value> value,
33                              const v8::PropertyCallbackInfo<v8::Value>& info);
34   static void delprop_static(v8::Local<v8::Name> property,
35                              const v8::PropertyCallbackInfo<v8::Boolean>& info);
36 
37   static void setPersistent_static(
38       const v8::FunctionCallbackInfo<v8::Value>& info);
39 
40   CJS_Global(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
41   ~CJS_Global() override;
42 
43   CJS_Result DelProperty(CJS_Runtime* pRuntime, const wchar_t* propname);
44 
45   CJS_Result setPersistent(CJS_Runtime* pRuntime,
46                            const std::vector<v8::Local<v8::Value>>& params);
47   CJS_Result QueryProperty(const wchar_t* propname);
48   CJS_Result GetProperty(CJS_Runtime* pRuntime, const wchar_t* propname);
49   CJS_Result SetProperty(CJS_Runtime* pRuntime,
50                          const wchar_t* propname,
51                          v8::Local<v8::Value> vp);
52 
53  private:
54   struct JSGlobalData : public CFX_Value {
55    public:
56     JSGlobalData();
57     ~JSGlobalData();
58 
59     v8::Global<v8::Object> pData;
60     bool bPersistent = false;
61     bool bDeleted = false;
62   };
63 
64   static int ObjDefnID;
65   static const JSMethodSpec MethodSpecs[];
66 
67   void UpdateGlobalPersistentVariables();
68   void CommitGlobalPersisitentVariables(CJS_Runtime* pRuntime);
69   void DestroyGlobalPersisitentVariables();
70   CJS_Result SetGlobalVariables(const ByteString& propname,
71                                 CFX_Value::DataType nType,
72                                 double dData,
73                                 bool bData,
74                                 const ByteString& sData,
75                                 v8::Local<v8::Object> pData,
76                                 bool bDefaultPersistent);
77   void ObjectToArray(CJS_Runtime* pRuntime,
78                      v8::Local<v8::Object> pObj,
79                      std::vector<std::unique_ptr<CFX_KeyValue>>* pArray);
80   void PutObjectProperty(v8::Local<v8::Object> obj, CFX_KeyValue* pData);
81 
82   std::map<ByteString, std::unique_ptr<JSGlobalData>> m_MapGlobal;
83   WideString m_sFilePath;
84   CFX_GlobalData* m_pGlobalData;
85   ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
86 };
87 
88 #endif  // FXJS_CJS_GLOBAL_H_
89