blob: 1f619181f336d583e786e9538af4d5051c5cd389 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#ifndef FPDFSDK_JAVASCRIPT_JS_OBJECT_H_
8#define FPDFSDK_JAVASCRIPT_JS_OBJECT_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez2ebc33e2015-08-13 16:07:29 -070010#include <map>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011#include <memory>
Tom Sepez2ebc33e2015-08-13 16:07:29 -070012
dsinclair114e46a2016-09-29 17:18:21 -070013#include "fpdfsdk/fsdk_define.h"
dsinclair64376be2016-03-31 20:03:24 -070014#include "fpdfsdk/javascript/cjs_runtime.h"
dsinclair43554682016-09-29 17:29:48 -070015#include "fxjs/fxjs_v8.h"
Tom Sepez3a832662015-03-02 12:59:05 -080016
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017class CJS_Context;
Tom Sepez371c87f2015-08-13 16:56:19 -070018class CJS_Object;
dsinclair79db6092016-09-14 07:27:21 -070019class CPDFSDK_Environment;
tsepez8ca63de2016-08-05 17:12:27 -070020
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021class CJS_EmbedObj {
22 public:
Tom Sepez371c87f2015-08-13 16:56:19 -070023 explicit CJS_EmbedObj(CJS_Object* pJSObject);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024 virtual ~CJS_EmbedObj();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Tom Sepez371c87f2015-08-13 16:56:19 -070026 CJS_Object* GetJSObject() const { return m_pJSObject; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 protected:
tsepezf3dc8c62016-08-10 06:29:29 -070029 CJS_Object* const m_pJSObject;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030};
31
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032class CJS_Object {
33 public:
Tom Sepez808a99e2015-09-10 12:28:37 -070034 explicit CJS_Object(v8::Local<v8::Object> pObject);
Lei Zhang2b1a2d52015-08-14 22:16:22 -070035 virtual ~CJS_Object();
Tom Sepezc6ab1722015-02-05 15:27:25 -080036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 void MakeWeak();
38 void Dispose();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
weili625ad662016-06-15 11:21:33 -070040 virtual void InitInstance(IJS_Runtime* pIRuntime);
41 virtual void ExitInstance();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Tom Sepez116e4ad2015-09-21 09:22:05 -070043 v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Tom Sepez371c87f2015-08-13 16:56:19 -070045 // Takes ownership of |pObj|.
46 void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); }
47 CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048
tsepeze1e7bd02016-08-08 13:03:16 -070049 v8::Isolate* GetIsolate() const { return m_pIsolate; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050
51 protected:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080052 std::unique_ptr<CJS_EmbedObj> m_pEmbedObj;
Tom Sepez116e4ad2015-09-21 09:22:05 -070053 v8::Global<v8::Object> m_pV8Object;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 v8::Isolate* m_pIsolate;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055};
56
Tom Sepez19922bb2015-05-28 13:23:12 -070057
Dan Sinclairf766ad22016-03-14 13:51:24 -040058#endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_