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 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 7 | #ifndef FXJS_CJS_RUNTIME_H_ |
| 8 | #define FXJS_CJS_RUNTIME_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 11 | #include <set> |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 12 | #include <utility> |
Tom Sepez | 4237aed | 2015-11-10 15:19:17 -0800 | [diff] [blame] | 13 | #include <vector> |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 14 | |
Tom Sepez | 27c350f | 2019-06-11 23:52:35 +0000 | [diff] [blame] | 15 | #include "core/fxcrt/observed_ptr.h" |
Tom Sepez | 24374a6 | 2019-08-07 21:26:02 +0000 | [diff] [blame] | 16 | #include "core/fxcrt/timerhandler_iface.h" |
Tom Sepez | b7c7df6 | 2018-02-09 19:08:59 +0000 | [diff] [blame] | 17 | #include "fxjs/cfxjs_engine.h" |
Tom Sepez | 7dbb85b | 2019-06-11 19:49:00 +0000 | [diff] [blame] | 18 | #include "fxjs/cjs_eventrecorder.h" |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 19 | #include "fxjs/ijs_runtime.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 20 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 21 | class CJS_EventContext; |
Tom Sepez | 24374a6 | 2019-08-07 21:26:02 +0000 | [diff] [blame] | 22 | class CPDFSDK_FormFillEnvironment; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 23 | |
Tom Sepez | 5586545 | 2018-08-27 20:18:04 +0000 | [diff] [blame] | 24 | class CJS_Runtime final : public IJS_Runtime, |
| 25 | public CFXJS_Engine, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 26 | public Observable { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | public: |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 28 | using FieldEvent = std::pair<WideString, JS_EVENT_T>; |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 29 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 30 | explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 31 | ~CJS_Runtime() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Tom Sepez | fe8d4e3 | 2019-08-15 20:15:08 +0000 | [diff] [blame] | 33 | // IJS_Runtime: |
| 34 | CJS_Runtime* AsCJSRuntime() override; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 35 | IJS_EventContext* NewEventContext() override; |
| 36 | void ReleaseEventContext(IJS_EventContext* pContext) override; |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 37 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override; |
Dan Sinclair | dc5d88b | 2018-05-17 13:53:52 +0000 | [diff] [blame] | 38 | Optional<IJS_Runtime::JS_Error> ExecuteScript( |
| 39 | const WideString& script) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 41 | CJS_EventContext* GetCurrentEventContext() const; |
Tom Sepez | 24374a6 | 2019-08-07 21:26:02 +0000 | [diff] [blame] | 42 | TimerHandlerIface* GetTimerHandler() const; |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 43 | |
Tom Sepez | 5d0e843 | 2015-09-22 15:50:03 -0700 | [diff] [blame] | 44 | // Returns true if the event isn't already found in the set. |
| 45 | bool AddEventToSet(const FieldEvent& event); |
| 46 | void RemoveEventFromSet(const FieldEvent& event); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 48 | void BeginBlock() { m_bBlocking = true; } |
| 49 | void EndBlock() { m_bBlocking = false; } |
| 50 | bool IsBlocking() const { return m_bBlocking; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 51 | |
Dan Sinclair | e85107b | 2017-10-24 15:29:22 -0400 | [diff] [blame] | 52 | // Attempt to convert the |value| into a number. If successful the number |
| 53 | // value will be returned, otherwise |value| is returned. |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 54 | v8::Local<v8::Value> MaybeCoerceToNumber(v8::Local<v8::Value> value); |
Dan Sinclair | e85107b | 2017-10-24 15:29:22 -0400 | [diff] [blame] | 55 | |
Tom Sepez | c839ac7 | 2018-12-14 20:34:11 +0000 | [diff] [blame] | 56 | bool GetValueByNameFromGlobalObject(ByteStringView utf8Name, |
Tom Sepez | fe8d4e3 | 2019-08-15 20:15:08 +0000 | [diff] [blame] | 57 | v8::Local<v8::Value>* pValue); |
Tom Sepez | c839ac7 | 2018-12-14 20:34:11 +0000 | [diff] [blame] | 58 | bool SetValueByNameInGlobalObject(ByteStringView utf8Name, |
Tom Sepez | fe8d4e3 | 2019-08-15 20:15:08 +0000 | [diff] [blame] | 59 | v8::Local<v8::Value> pValue); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 60 | |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 61 | private: |
Tom Sepez | 142165e | 2015-09-11 13:21:50 -0700 | [diff] [blame] | 62 | void DefineJSObjects(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 63 | void SetFormFillEnvToDocument(); |
Tom Sepez | 570875c | 2015-09-11 08:35:03 -0700 | [diff] [blame] | 64 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 65 | std::vector<std::unique_ptr<CJS_EventContext>> m_EventContextArray; |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 66 | ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv; |
Lei Zhang | d5f4279 | 2018-08-29 23:18:08 +0000 | [diff] [blame] | 67 | bool m_bBlocking = false; |
| 68 | bool m_isolateManaged = false; |
tsepez | a494191 | 2016-08-15 11:40:12 -0700 | [diff] [blame] | 69 | std::set<FieldEvent> m_FieldEventSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 72 | #endif // FXJS_CJS_RUNTIME_H_ |