blob: 293b98acf6dd4fb262673e907889afac09eccdfc [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
Tom Sepezd6ae2af2017-02-16 11:49:55 -080017class CJS_EventContext;
Tom Sepez371c87f2015-08-13 16:56:19 -070018class CJS_Object;
dsinclair735606d2016-10-05 15:47:02 -070019class CPDFSDK_FormFillEnvironment;
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 Sepez797ca5c2017-05-25 12:03:18 -070026 CJS_Object* GetJSObject() const { return m_pJSObject.Get(); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 protected:
Dan Sinclairaee0db02017-09-21 16:53:58 -040029 UnownedPtr<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);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
Tom Sepez116e4ad2015-09-21 09:22:05 -070042 v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Tom Sepez371c87f2015-08-13 16:56:19 -070044 // Takes ownership of |pObj|.
45 void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); }
46 CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047
tsepeze1e7bd02016-08-08 13:03:16 -070048 v8::Isolate* GetIsolate() const { return m_pIsolate; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049
50 protected:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080051 std::unique_ptr<CJS_EmbedObj> m_pEmbedObj;
Tom Sepez116e4ad2015-09-21 09:22:05 -070052 v8::Global<v8::Object> m_pV8Object;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 v8::Isolate* m_pIsolate;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054};
55
Tom Sepez19922bb2015-05-28 13:23:12 -070056
Dan Sinclairf766ad22016-03-14 13:51:24 -040057#endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_