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 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 16 | #include "core/fxcrt/cfx_observable.h" |
| 17 | #include "core/fxcrt/fx_basic.h" |
Tom Sepez | 77f6d0f | 2017-02-23 12:14:10 -0800 | [diff] [blame^] | 18 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 19 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/javascript/ijs_runtime.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 21 | #include "fxjs/fxjs_v8.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 22 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 23 | class CJS_EventContext; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 24 | |
tsepez | 8832fbf | 2016-09-08 10:25:55 -0700 | [diff] [blame] | 25 | class CJS_Runtime : public IJS_Runtime, |
| 26 | public CFXJS_Engine, |
| 27 | public CFX_Observable<CJS_Runtime> { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | public: |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 29 | using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>; |
| 30 | |
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 | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 33 | explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
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 |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 37 | IJS_EventContext* NewEventContext() override; |
| 38 | void ReleaseEventContext(IJS_EventContext* pContext) override; |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 39 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 40 | int ExecuteScript(const CFX_WideString& script, |
| 41 | CFX_WideString* info) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 43 | CJS_EventContext* GetCurrentEventContext() const; |
| 44 | |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 45 | // Returns true if the event isn't already found in the set. |
| 46 | bool AddEventToSet(const FieldEvent& event); |
| 47 | void RemoveEventFromSet(const FieldEvent& event); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 49 | void BeginBlock() { m_bBlocking = true; } |
| 50 | void EndBlock() { m_bBlocking = false; } |
| 51 | bool IsBlocking() const { return m_bBlocking; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 53 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 54 | bool GetValueByName(const CFX_ByteStringC& utf8Name, |
| 55 | CFXJSE_Value* pValue) override; |
| 56 | bool SetValueByName(const CFX_ByteStringC& utf8Name, |
| 57 | CFXJSE_Value* pValue) override; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 58 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 59 | |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 60 | private: |
Tom Sepez | 142165e | 2015-09-11 13:21:50 -0700 | [diff] [blame] | 61 | void DefineJSObjects(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 62 | void SetFormFillEnvToDocument(); |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 63 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 64 | std::vector<std::unique_ptr<CJS_EventContext>> m_EventContextArray; |
Tom Sepez | 77f6d0f | 2017-02-23 12:14:10 -0800 | [diff] [blame^] | 65 | CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; |
tsepez | a494191 | 2016-08-15 11:40:12 -0700 | [diff] [blame] | 66 | bool m_bBlocking; |
Jochen Eisinger | 2900784 | 2015-08-05 09:02:13 +0200 | [diff] [blame] | 67 | bool m_isolateManaged; |
tsepez | a494191 | 2016-08-15 11:40:12 -0700 | [diff] [blame] | 68 | std::set<FieldEvent> m_FieldEventSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 71 | #endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_ |