John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. | ||||
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | |||||
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #ifndef FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ |
8 | #define FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ | ||||
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 2ebc33e | 2015-08-13 16:07:29 -0700 | [diff] [blame] | 10 | #include <map> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 11 | #include <memory> |
Tom Sepez | 2ebc33e | 2015-08-13 16:07:29 -0700 | [diff] [blame] | 12 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/fsdk_define.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/javascript/cjs_runtime.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 15 | #include "fxjs/fxjs_v8.h" |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 16 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 17 | class CJS_EventContext; |
Tom Sepez | 371c87f | 2015-08-13 16:56:19 -0700 | [diff] [blame] | 18 | class CJS_Object; |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 19 | class CPDFSDK_FormFillEnvironment; |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 20 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | class CJS_EmbedObj { |
22 | public: | ||||
Tom Sepez | 371c87f | 2015-08-13 16:56:19 -0700 | [diff] [blame] | 23 | explicit CJS_EmbedObj(CJS_Object* pJSObject); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | virtual ~CJS_EmbedObj(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 26 | CJS_Object* GetJSObject() const { return m_pJSObject.Get(); } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | protected: |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 29 | CFX_UnownedPtr<CJS_Object> const m_pJSObject; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | }; |
31 | |||||
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 32 | class CJS_Object { |
33 | public: | ||||
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 34 | explicit CJS_Object(v8::Local<v8::Object> pObject); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 35 | virtual ~CJS_Object(); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 36 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 37 | void MakeWeak(); |
38 | void Dispose(); | ||||
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 40 | virtual void InitInstance(IJS_Runtime* pIRuntime); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 41 | |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 42 | v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | |
Tom Sepez | 371c87f | 2015-08-13 16:56:19 -0700 | [diff] [blame] | 44 | // 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | |
tsepez | e1e7bd0 | 2016-08-08 13:03:16 -0700 | [diff] [blame] | 48 | v8::Isolate* GetIsolate() const { return m_pIsolate; } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | |
50 | protected: | ||||
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 51 | std::unique_ptr<CJS_EmbedObj> m_pEmbedObj; |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 52 | v8::Global<v8::Object> m_pV8Object; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | v8::Isolate* m_pIsolate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | }; |
55 | |||||
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 56 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 57 | #endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ |