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_OBJECT_H_ 8 #define FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ 9 10 #include <map> 11 #include <memory> 12 13 #include "fpdfsdk/fsdk_define.h" 14 #include "fpdfsdk/javascript/cjs_runtime.h" 15 #include "fxjs/fxjs_v8.h" 16 17 class CJS_EventContext; 18 class CJS_Object; 19 class CPDFSDK_FormFillEnvironment; 20 21 class CJS_EmbedObj { 22 public: 23 explicit CJS_EmbedObj(CJS_Object* pJSObject); 24 virtual ~CJS_EmbedObj(); 25 GetJSObject()26 CJS_Object* GetJSObject() const { return m_pJSObject; } 27 28 protected: 29 CJS_Object* const m_pJSObject; 30 }; 31 32 class CJS_Object { 33 public: 34 explicit CJS_Object(v8::Local<v8::Object> pObject); 35 virtual ~CJS_Object(); 36 37 void MakeWeak(); 38 void Dispose(); 39 40 virtual void InitInstance(IJS_Runtime* pIRuntime); 41 ToV8Object()42 v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); } 43 44 // Takes ownership of |pObj|. SetEmbedObject(CJS_EmbedObj * pObj)45 void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); } GetEmbedObject()46 CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); } 47 GetIsolate()48 v8::Isolate* GetIsolate() const { return m_pIsolate; } 49 50 protected: 51 std::unique_ptr<CJS_EmbedObj> m_pEmbedObj; 52 v8::Global<v8::Object> m_pV8Object; 53 v8::Isolate* m_pIsolate; 54 }; 55 56 57 #endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ 58