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