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