• 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_GLOBAL_H_
8 #define FPDFSDK_JAVASCRIPT_GLOBAL_H_
9 
10 #include <map>
11 #include <vector>
12 
13 #include "fpdfsdk/javascript/JS_Define.h"
14 #include "fpdfsdk/javascript/JS_KeyValue.h"
15 
16 class CJS_GlobalData;
17 class CJS_GlobalVariableArray;
18 class CJS_KeyValue;
19 
20 struct JSGlobalData {
21   JSGlobalData();
22   ~JSGlobalData();
23 
24   JS_GlobalDataType nType;
25   double dData;
26   bool bData;
27   CFX_ByteString sData;
28   v8::Global<v8::Object> pData;
29   bool bPersistent;
30   bool bDeleted;
31 };
32 
33 class JSGlobalAlternate : public CJS_EmbedObj {
34  public:
35   explicit JSGlobalAlternate(CJS_Object* pJSObject);
36   ~JSGlobalAlternate() override;
37 
38   bool setPersistent(CJS_Runtime* pRuntime,
39                      const std::vector<CJS_Value>& params,
40                      CJS_Value& vRet,
41                      CFX_WideString& sError);
42   bool QueryProperty(const FX_WCHAR* propname);
43   bool DoProperty(CJS_Runtime* pRuntime,
44                   const FX_WCHAR* propname,
45                   CJS_PropValue& vp,
46                   CFX_WideString& sError);
47   bool DelProperty(CJS_Runtime* pRuntime,
48                    const FX_WCHAR* propname,
49                    CFX_WideString& sError);
50   void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv);
51 
52  private:
53   void UpdateGlobalPersistentVariables();
54   void CommitGlobalPersisitentVariables(CJS_Runtime* pRuntime);
55   void DestroyGlobalPersisitentVariables();
56   bool SetGlobalVariables(const CFX_ByteString& propname,
57                           JS_GlobalDataType nType,
58                           double dData,
59                           bool bData,
60                           const CFX_ByteString& sData,
61                           v8::Local<v8::Object> pData,
62                           bool bDefaultPersistent);
63   void ObjectToArray(CJS_Runtime* pRuntime,
64                      v8::Local<v8::Object> pObj,
65                      CJS_GlobalVariableArray& array);
66   void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
67 
68   std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal;
69   CFX_WideString m_sFilePath;
70   CJS_GlobalData* m_pGlobalData;
71   CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
72 };
73 
74 class CJS_Global : public CJS_Object {
75  public:
CJS_Global(v8::Local<v8::Object> pObject)76   explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
~CJS_Global()77   ~CJS_Global() override {}
78 
79   // CJS_Object
80   void InitInstance(IJS_Runtime* pIRuntime) override;
81 
82   DECLARE_SPECIAL_JS_CLASS();
83   JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
84 };
85 
86 #endif  // FPDFSDK_JAVASCRIPT_GLOBAL_H_
87