blob: 86d49713a8db797ebac262f873e4f4d72d854780 [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.
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
Tom Sepez9a3f8122015-04-07 15:35:48 -070010#include "../../../core/include/fxcrt/fx_basic.h"
11#include "../jsapi/fxjs_v8.h"
12#include "IJavaScript.h"
13#include "JS_EventHandler.h"
14
15class CJS_Context;
16
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017class CJS_FieldEvent
18{
19public:
20 CFX_WideString sTargetName;
21 JS_EVENT_T eEventType;
22 CJS_FieldEvent* pNext;
23};
24
25class CJS_Runtime : public IFXJS_Runtime
26{
27public:
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
Bo Xufdc00a72014-10-28 23:03:33 -070038 CPDFDoc_Environment * GetReaderApp(){return m_pApp;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
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;}
Bo Xufdc00a72014-10-28 23:03:33 -070051 v8::Isolate* GetIsolate(){return m_isolate;};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052 void SetIsolate(v8::Isolate* isolate){m_isolate = isolate;}
53
Bo Xufdc00a72014-10-28 23:03:33 -070054 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);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059protected:
60 CFX_ArrayTemplate<CJS_Context *> m_ContextArray;
Bo Xufdc00a72014-10-28 23:03:33 -070061 CPDFDoc_Environment * m_pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062 CPDFSDK_Document * m_pDocument;
63 FX_BOOL m_bBlocking;
64 CJS_FieldEvent* m_pFieldEventPath;
65
Bo Xufdc00a72014-10-28 23:03:33 -070066 v8::Isolate* m_isolate;
67 v8::Persistent<v8::Context> m_context;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068 FX_BOOL m_bRegistered;
69};
70
71#endif //_JS_RUNTIME_H_
72