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. |
| 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 Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 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 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 38 | CPDFDoc_Environment * GetReaderApp(){return m_pApp;} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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;} |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 51 | v8::Isolate* GetIsolate(){return m_isolate;}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | void SetIsolate(v8::Isolate* isolate){m_isolate = isolate;} |
| 53 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 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); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | protected: |
| 60 | CFX_ArrayTemplate<CJS_Context *> m_ContextArray; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 61 | CPDFDoc_Environment * m_pApp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | CPDFSDK_Document * m_pDocument; |
| 63 | FX_BOOL m_bBlocking; |
| 64 | CJS_FieldEvent* m_pFieldEventPath; |
| 65 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 66 | v8::Isolate* m_isolate; |
| 67 | v8::Persistent<v8::Context> m_context; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | FX_BOOL m_bRegistered; |
| 69 | }; |
| 70 | |
| 71 | #endif //_JS_RUNTIME_H_ |
| 72 | |