Merge to XFA: Fix IWYU in formfiller/ directory.
[pdfium.git] / fpdfsdk / include / javascript / JS_Runtime.h
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.
4  
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef _JS_RUNTIME_H_
8 #define _JS_RUNTIME_H_
9
10 #include "../../../core/include/fxcrt/fx_basic.h"
11 #include "../jsapi/fxjs_v8.h"
12 #include "IJavaScript.h"
13 #include "JS_EventHandler.h"
14
15 class CJS_Context;
16
17 class CJS_FieldEvent
18 {
19 public:
20         CFX_WideString          sTargetName;
21         JS_EVENT_T                      eEventType;
22         CJS_FieldEvent*         pNext;
23 };
24
25 class CJS_Runtime : public IFXJS_Runtime
26 {
27 public:
28         CJS_Runtime(CPDFDoc_Environment * pApp);
29         virtual ~CJS_Runtime();
30
31         virtual IFXJS_Context *                                 NewContext();
32         virtual void                                                    ReleaseContext(IFXJS_Context * pContext);
33         virtual IFXJS_Context*                                  GetCurrentContext();
34
35         virtual void                                                    SetReaderDocument(CPDFSDK_Document *pReaderDoc);
36         virtual CPDFSDK_Document *                              GetReaderDocument(){return m_pDocument;}
37
38         CPDFDoc_Environment *                                   GetReaderApp(){return m_pApp;}
39
40         FX_BOOL                                                                 InitJSObjects();
41
42         FX_BOOL                                                                 AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType);
43         void                                                                    RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType);
44         void                                                                    RemoveEventsInLoop(CJS_FieldEvent* pStart);
45
46         void                                                                    BeginBlock(){m_bBlocking = TRUE;}
47         void                                                                    EndBlock(){m_bBlocking = FALSE;}
48         FX_BOOL                                                                 IsBlocking(){return m_bBlocking;}
49
50         operator                                                                IJS_Runtime*() {return (IJS_Runtime*)m_isolate;}
51         v8::Isolate*                                                    GetIsolate(){return m_isolate;};
52         void                                                                    SetIsolate(v8::Isolate* isolate){m_isolate = isolate;}
53
54         v8::Handle<v8::Context>                                 NewJSContext();
55
56
57         virtual FX_BOOL                                                 GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue);
58         virtual FX_BOOL                                                 SetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue);
59 protected:
60         CFX_ArrayTemplate<CJS_Context *>                m_ContextArray;
61         CPDFDoc_Environment *                                   m_pApp;
62         CPDFSDK_Document *                                              m_pDocument;
63         FX_BOOL                                                                 m_bBlocking;
64         CJS_FieldEvent*                                                 m_pFieldEventPath;
65
66         v8::Isolate*                                                    m_isolate;
67         v8::Persistent<v8::Context>                             m_context;
68         FX_BOOL                                                                 m_bRegistered;
69 };
70
71 #endif //_JS_RUNTIME_H_
72