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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [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 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |
| 8 | #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | d2cc1b9 | 2015-04-30 15:19:03 -0700 | [diff] [blame] | 10 | #include "../../../third_party/base/nonstd_unique_ptr.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 11 | #include "../../../core/include/fxcrt/fx_basic.h" |
| 12 | #include "../jsapi/fxjs_v8.h" |
| 13 | #include "IJavaScript.h" |
| 14 | #include "JS_EventHandler.h" |
| 15 | |
| 16 | class CJS_Context; |
| 17 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 18 | class CJS_FieldEvent { |
| 19 | public: |
| 20 | CFX_WideString sTargetName; |
| 21 | JS_EVENT_T eEventType; |
| 22 | CJS_FieldEvent* pNext; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | class CJS_Runtime : public IFXJS_Runtime { |
| 26 | public: |
Tom Sepez | 7d0fcbf | 2015-09-15 15:30:34 -0700 | [diff] [blame^] | 27 | explicit CJS_Runtime(CPDFDoc_Environment* pApp); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 28 | ~CJS_Runtime() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 29 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 30 | // IFXJS_Runtime |
| 31 | IFXJS_Context* NewContext() override; |
| 32 | void ReleaseContext(IFXJS_Context* pContext) override; |
| 33 | IFXJS_Context* GetCurrentContext() override; |
| 34 | void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; |
| 35 | CPDFSDK_Document* GetReaderDocument() override { return m_pDocument; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 37 | CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | FX_BOOL AddEventToLoop(const CFX_WideString& sTargetName, |
| 40 | JS_EVENT_T eEventType); |
| 41 | void RemoveEventInLoop(const CFX_WideString& sTargetName, |
| 42 | JS_EVENT_T eEventType); |
| 43 | void RemoveEventsInLoop(CJS_FieldEvent* pStart); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | void BeginBlock() { m_bBlocking = TRUE; } |
| 46 | void EndBlock() { m_bBlocking = FALSE; } |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 47 | FX_BOOL IsBlocking() const { return m_bBlocking; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 49 | v8::Isolate* GetIsolate() const { return m_isolate; } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | v8::Local<v8::Context> NewJSContext(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, |
| 53 | FXJSE_HVALUE hValue); |
| 54 | virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, |
| 55 | FXJSE_HVALUE hValue); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 56 | |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 57 | private: |
Tom Sepez | 142165e | 2015-09-11 13:21:50 -0700 | [diff] [blame] | 58 | void DefineJSObjects(); |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | CFX_ArrayTemplate<CJS_Context*> m_ContextArray; |
| 61 | CPDFDoc_Environment* m_pApp; |
| 62 | CPDFSDK_Document* m_pDocument; |
| 63 | FX_BOOL m_bBlocking; |
| 64 | CJS_FieldEvent* m_pFieldEventPath; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | v8::Isolate* m_isolate; |
Jochen Eisinger | 2900784 | 2015-08-05 09:02:13 +0200 | [diff] [blame] | 66 | bool m_isolateManaged; |
Tom Sepez | 7d0fcbf | 2015-09-15 15:30:34 -0700 | [diff] [blame^] | 67 | nonstd::unique_ptr<JS_ArrayBufferAllocator> m_pArrayBufferAllocator; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | v8::Global<v8::Context> m_context; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 71 | #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |