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