1 // Copyright 2016 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.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FXJS_IJS_RUNTIME_H_
8 #define FXJS_IJS_RUNTIME_H_
9 
10 #include "core/fxcrt/fx_string.h"
11 #include "core/fxcrt/fx_system.h"
12 
13 #ifdef PDF_ENABLE_XFA
14 #include "fxjs/fxjse.h"
15 #endif  // PDF_ENABLE_XFA
16 
17 class CPDFSDK_FormFillEnvironment;
18 class IJS_EventContext;
19 
20 // Owns the FJXS objects needed to actually execute JS.
21 class IJS_Runtime {
22  public:
23   static void Initialize(unsigned int slot, void* isolate);
24   static void Destroy();
25   static IJS_Runtime* Create(CPDFSDK_FormFillEnvironment* pFormFillEnv);
~IJS_Runtime()26   virtual ~IJS_Runtime() {}
27 
28   virtual IJS_EventContext* NewEventContext() = 0;
29   virtual void ReleaseEventContext(IJS_EventContext* pContext) = 0;
30   virtual CPDFSDK_FormFillEnvironment* GetFormFillEnv() const = 0;
31   virtual int ExecuteScript(const WideString& script, WideString* info) = 0;
32 
33 #ifdef PDF_ENABLE_XFA
34   virtual bool GetValueByName(const ByteStringView& utf8Name,
35                               CFXJSE_Value* pValue) = 0;
36   virtual bool SetValueByName(const ByteStringView& utf8Name,
37                               CFXJSE_Value* pValue) = 0;
38 #endif  // PDF_ENABLE_XFA
39 
40  protected:
IJS_Runtime()41   IJS_Runtime() {}
42 };
43 
44 #endif  // FXJS_IJS_RUNTIME_H_
45