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 | |
Tom Sepez | d2cc1b9 | 2015-04-30 15:19:03 -0700 | [diff] [blame] | 18 | class CJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 19 | void* Allocate(size_t length) override; |
| 20 | void* AllocateUninitialized(size_t length) override; |
| 21 | void Free(void* data, size_t length) override; |
Tom Sepez | d2cc1b9 | 2015-04-30 15:19:03 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | class CJS_FieldEvent { |
| 25 | public: |
| 26 | CFX_WideString sTargetName; |
| 27 | JS_EVENT_T eEventType; |
| 28 | CJS_FieldEvent* pNext; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | class CJS_Runtime : public IFXJS_Runtime { |
| 32 | public: |
| 33 | CJS_Runtime(CPDFDoc_Environment* pApp); |
| 34 | virtual ~CJS_Runtime(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | virtual IFXJS_Context* NewContext(); |
| 37 | virtual void ReleaseContext(IFXJS_Context* pContext); |
| 38 | virtual IFXJS_Context* GetCurrentContext(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc); |
| 41 | virtual CPDFSDK_Document* GetReaderDocument() { return m_pDocument; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | CPDFDoc_Environment* GetReaderApp() { return m_pApp; } |
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 | FX_BOOL InitJSObjects(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | FX_BOOL AddEventToLoop(const CFX_WideString& sTargetName, |
| 48 | JS_EVENT_T eEventType); |
| 49 | void RemoveEventInLoop(const CFX_WideString& sTargetName, |
| 50 | JS_EVENT_T eEventType); |
| 51 | void RemoveEventsInLoop(CJS_FieldEvent* pStart); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | void BeginBlock() { m_bBlocking = TRUE; } |
| 54 | void EndBlock() { m_bBlocking = FALSE; } |
| 55 | FX_BOOL IsBlocking() { return m_bBlocking; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | operator IJS_Runtime*() { return (IJS_Runtime*)m_isolate; } |
| 58 | v8::Isolate* GetIsolate() { return m_isolate; }; |
| 59 | void SetIsolate(v8::Isolate* isolate) { m_isolate = isolate; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | v8::Local<v8::Context> NewJSContext(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, |
| 64 | FXJSE_HVALUE hValue); |
| 65 | virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, |
| 66 | FXJSE_HVALUE hValue); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 67 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | protected: |
| 69 | CFX_ArrayTemplate<CJS_Context*> m_ContextArray; |
| 70 | CPDFDoc_Environment* m_pApp; |
| 71 | CPDFSDK_Document* m_pDocument; |
| 72 | FX_BOOL m_bBlocking; |
| 73 | CJS_FieldEvent* m_pFieldEventPath; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | v8::Isolate* m_isolate; |
Jochen Eisinger | 2900784 | 2015-08-05 09:02:13 +0200 | [diff] [blame^] | 76 | bool m_isolateManaged; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | nonstd::unique_ptr<CJS_ArrayBufferAllocator> m_pArrayBufferAllocator; |
| 78 | v8::Global<v8::Context> m_context; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 81 | #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_ |