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 | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/include/fsdk_define.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/javascript/cjs_runtime.h" |
dsinclair | b3f2467 | 2016-07-12 10:42:14 -0700 | [diff] [blame] | 15 | #include "fxjs/include/fxjs_v8.h" |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 16 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | class CJS_Context; |
Tom Sepez | 371c87f | 2015-08-13 16:56:19 -0700 | [diff] [blame] | 18 | class CJS_Object; |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 19 | class CPDFDoc_Environment; |
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 | 371c87f | 2015-08-13 16:56:19 -0700 | [diff] [blame] | 26 | CJS_Object* GetJSObject() const { return m_pJSObject; } |
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 | int MsgBox(CPDFDoc_Environment* pApp, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | const FX_WCHAR* swMsg, |
Lei Zhang | d607f5b | 2015-10-05 17:06:09 -0700 | [diff] [blame] | 30 | const FX_WCHAR* swTitle, |
31 | FX_UINT nType, | ||||
32 | FX_UINT nIcon); | ||||
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | protected: |
36 | CJS_Object* m_pJSObject; | ||||
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | }; |
38 | |||||
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | class CJS_Object { |
40 | public: | ||||
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 41 | explicit CJS_Object(v8::Local<v8::Object> pObject); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 42 | virtual ~CJS_Object(); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 43 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | void MakeWeak(); |
45 | void Dispose(); | ||||
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 47 | virtual void InitInstance(IJS_Runtime* pIRuntime); |
48 | virtual void ExitInstance(); | ||||
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 50 | 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] | 51 | |
Tom Sepez | 371c87f | 2015-08-13 16:56:19 -0700 | [diff] [blame] | 52 | // Takes ownership of |pObj|. |
53 | void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); } | ||||
54 | CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); } | ||||
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | v8::Isolate* GetIsolate() { return m_pIsolate; } |
59 | |||||
60 | protected: | ||||
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 61 | std::unique_ptr<CJS_EmbedObj> m_pEmbedObj; |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 62 | v8::Global<v8::Object> m_pV8Object; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | v8::Isolate* m_pIsolate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | }; |
65 | |||||
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 66 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 67 | #endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ |