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 | |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |
| 8 | #define FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 10 | #include <map> |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 11 | #include <memory> |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 12 | #include <set> |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 13 | #include <utility> |
Tom Sepez | 4237aed | 2015-11-10 15:19:17 -0800 | [diff] [blame] | 14 | #include <vector> |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 15 | |
tsepez | 8832fbf | 2016-09-08 10:25:55 -0700 | [diff] [blame] | 16 | #include "core/fxcrt/include/cfx_observable.h" |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 17 | #include "core/fxcrt/include/fx_basic.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 18 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/javascript/ijs_runtime.h" |
dsinclair | b3f2467 | 2016-07-12 10:42:14 -0700 | [diff] [blame] | 20 | #include "fxjs/include/fxjs_v8.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 21 | |
| 22 | class CJS_Context; |
| 23 | |
tsepez | 8832fbf | 2016-09-08 10:25:55 -0700 | [diff] [blame] | 24 | class CJS_Runtime : public IJS_Runtime, |
| 25 | public CFXJS_Engine, |
| 26 | public CFX_Observable<CJS_Runtime> { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | public: |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 28 | using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; |
| 29 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 30 | static CJS_Runtime* FromContext(const IJS_Context* cc); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 31 | static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 32 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 33 | explicit CJS_Runtime(CPDFSDK_Environment* pApp); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 34 | ~CJS_Runtime() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 36 | // IJS_Runtime |
| 37 | IJS_Context* NewContext() override; |
| 38 | void ReleaseContext(IJS_Context* pContext) override; |
| 39 | IJS_Context* GetCurrentContext() override; |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 40 | void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 41 | CPDFSDK_Document* GetReaderDocument() override; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 42 | int ExecuteScript(const CFX_WideString& script, |
| 43 | CFX_WideString* info) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 45 | CPDFSDK_Environment* GetReaderApp() const { return m_pApp; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 47 | // Returns true if the event isn't already found in the set. |
| 48 | bool AddEventToSet(const FieldEvent& event); |
| 49 | void RemoveEventFromSet(const FieldEvent& event); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | void BeginBlock() { m_bBlocking = TRUE; } |
| 52 | void EndBlock() { m_bBlocking = FALSE; } |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 53 | FX_BOOL IsBlocking() const { return m_bBlocking; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 55 | #ifdef PDF_ENABLE_XFA |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 56 | FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, |
| 57 | CFXJSE_Value* pValue) override; |
| 58 | FX_BOOL SetValueByName(const CFX_ByteStringC& utf8Name, |
| 59 | CFXJSE_Value* pValue) override; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 60 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 61 | |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 62 | private: |
Tom Sepez | 142165e | 2015-09-11 13:21:50 -0700 | [diff] [blame] | 63 | void DefineJSObjects(); |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 64 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 65 | std::vector<std::unique_ptr<CJS_Context>> m_ContextArray; |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 66 | CPDFSDK_Environment* const m_pApp; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | CPDFSDK_Document* m_pDocument; |
tsepez | a494191 | 2016-08-15 11:40:12 -0700 | [diff] [blame] | 68 | bool m_bBlocking; |
Jochen Eisinger | 2900784 | 2015-08-05 09:02:13 +0200 | [diff] [blame] | 69 | bool m_isolateManaged; |
tsepez | a494191 | 2016-08-15 11:40:12 -0700 | [diff] [blame] | 70 | std::set<FieldEvent> m_FieldEventSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 73 | #endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |