blob: 039e24b63eeaf0474c58fca0910ee1b39f5f6904 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair64376be2016-03-31 20:03:24 -07007#ifndef FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_
8#define FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Dan Sinclair3ebd1212016-03-09 09:59:23 -050010#include <map>
tsepez41a53ad2016-03-28 16:59:30 -070011#include <memory>
Dan Sinclairf766ad22016-03-14 13:51:24 -040012#include <set>
Tom Sepez5d0e8432015-09-22 15:50:03 -070013#include <utility>
Tom Sepez4237aed2015-11-10 15:19:17 -080014#include <vector>
Tom Sepez5d0e8432015-09-22 15:50:03 -070015
dsinclaira52ab742016-09-29 13:59:29 -070016#include "core/fxcrt/cfx_observable.h"
17#include "core/fxcrt/fx_basic.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040018#include "fpdfsdk/javascript/JS_EventHandler.h"
dsinclair64376be2016-03-31 20:03:24 -070019#include "fpdfsdk/javascript/ijs_runtime.h"
dsinclair43554682016-09-29 17:29:48 -070020#include "fxjs/fxjs_v8.h"
Tom Sepez9a3f8122015-04-07 15:35:48 -070021
Tom Sepezd6ae2af2017-02-16 11:49:55 -080022class CJS_EventContext;
Tom Sepez9a3f8122015-04-07 15:35:48 -070023
tsepez8832fbf2016-09-08 10:25:55 -070024class CJS_Runtime : public IJS_Runtime,
25 public CFXJS_Engine,
26 public CFX_Observable<CJS_Runtime> {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 public:
Tom Sepez5d0e8432015-09-22 15:50:03 -070028 using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>;
29
tsepezb4694242016-08-15 16:44:55 -070030 static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate);
Tom Sepez67fd5df2015-10-08 12:24:19 -070031
dsinclair82e17672016-10-11 12:38:01 -070032 explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv);
Lei Zhang2b1a2d52015-08-14 22:16:22 -070033 ~CJS_Runtime() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Tom Sepezba038bc2015-10-08 12:03:00 -070035 // IJS_Runtime
Tom Sepezd6ae2af2017-02-16 11:49:55 -080036 IJS_EventContext* NewEventContext() override;
37 void ReleaseEventContext(IJS_EventContext* pContext) override;
dsinclair82e17672016-10-11 12:38:01 -070038 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override;
tsepezb4694242016-08-15 16:44:55 -070039 int ExecuteScript(const CFX_WideString& script,
40 CFX_WideString* info) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
Tom Sepezb1670b52017-02-16 17:01:00 -080042 CJS_EventContext* GetCurrentEventContext() const;
43
Tom Sepez5d0e8432015-09-22 15:50:03 -070044 // 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-Malek3f3b45c2014-05-23 17:28:10 -070047
tsepez4cf55152016-11-02 14:37:54 -070048 void BeginBlock() { m_bBlocking = true; }
49 void EndBlock() { m_bBlocking = false; }
50 bool IsBlocking() const { return m_bBlocking; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Tom Sepez51da0932015-11-25 16:05:49 -080052#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -070053 bool GetValueByName(const CFX_ByteStringC& utf8Name,
54 CFXJSE_Value* pValue) override;
55 bool SetValueByName(const CFX_ByteStringC& utf8Name,
56 CFXJSE_Value* pValue) override;
Tom Sepez40e9ff32015-11-30 12:39:54 -080057#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -070058
Tom Sepez570875c2015-09-11 08:35:03 -070059 private:
Tom Sepez142165e2015-09-11 13:21:50 -070060 void DefineJSObjects();
dsinclair82e17672016-10-11 12:38:01 -070061 void SetFormFillEnvToDocument();
Tom Sepez570875c2015-09-11 08:35:03 -070062
Tom Sepezd6ae2af2017-02-16 11:49:55 -080063 std::vector<std::unique_ptr<CJS_EventContext>> m_EventContextArray;
dsinclair82e17672016-10-11 12:38:01 -070064 CPDFSDK_FormFillEnvironment* const m_pFormFillEnv;
tsepeza4941912016-08-15 11:40:12 -070065 bool m_bBlocking;
Jochen Eisinger29007842015-08-05 09:02:13 +020066 bool m_isolateManaged;
tsepeza4941912016-08-15 11:40:12 -070067 std::set<FieldEvent> m_FieldEventSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068};
69
dsinclair64376be2016-03-31 20:03:24 -070070#endif // FPDFSDK_JAVASCRIPT_CJS_RUNTIME_H_