Home | History | Annotate | Download | only in javascript
      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 class CJS_FieldEvent
     11 {
     12 public:
     13 	CFX_WideString		sTargetName;
     14 	JS_EVENT_T			eEventType;
     15 	CJS_FieldEvent*		pNext;
     16 };
     17 
     18 class CJS_Runtime : public IFXJS_Runtime
     19 {
     20 public:
     21 	CJS_Runtime(CPDFDoc_Environment * pApp);
     22 	virtual ~CJS_Runtime();
     23 
     24 	virtual IFXJS_Context *					NewContext();
     25 	virtual void							ReleaseContext(IFXJS_Context * pContext);
     26 	virtual IFXJS_Context*					GetCurrentContext();
     27 
     28 	virtual void							SetReaderDocument(CPDFSDK_Document *pReaderDoc);
     29 	virtual CPDFSDK_Document *				GetReaderDocument(){return m_pDocument;}
     30 
     31 	virtual void							GetObjectNames(CFX_WideStringArray& array);
     32 	virtual void							GetObjectConsts(const CFX_WideString& swObjName, CFX_WideStringArray& array);
     33 	virtual void							GetObjectProps(const CFX_WideString& swObjName, CFX_WideStringArray& array);
     34 	virtual void							GetObjectMethods(const CFX_WideString& swObjName, CFX_WideStringArray& array);
     35 
     36 	virtual void							Exit();
     37 	virtual void							Enter();
     38 	virtual FX_BOOL							IsEntered();
     39 
     40 	CPDFDoc_Environment *							GetReaderApp(){return m_pApp;}
     41 
     42 	FX_BOOL									InitJSObjects();
     43 
     44 	FX_BOOL									AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType);
     45 	void									RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType);
     46 	void									RemoveEventsInLoop(CJS_FieldEvent* pStart);
     47 
     48 	void									BeginBlock(){m_bBlocking = TRUE;}
     49 	void									EndBlock(){m_bBlocking = FALSE;}
     50 	FX_BOOL									IsBlocking(){return m_bBlocking;}
     51 
     52 	operator								IJS_Runtime*() {return (IJS_Runtime*)m_isolate;}
     53 	v8::Isolate*								GetIsolate(){return m_isolate;};
     54 	void									SetIsolate(v8::Isolate* isolate){m_isolate = isolate;}
     55 
     56 	v8::Handle<v8::Context>							NewJSContext();
     57 protected:
     58 	CFX_ArrayTemplate<CJS_Context *>		m_ContextArray;
     59 	CPDFDoc_Environment *							m_pApp;
     60 	CPDFSDK_Document *						m_pDocument;
     61 	FX_BOOL									m_bBlocking;
     62 	CJS_FieldEvent*							m_pFieldEventPath;
     63 
     64 	v8::Isolate*								m_isolate;
     65 	v8::Persistent<v8::Context>						m_context;
     66 	FX_BOOL									m_bRegistered;
     67 };
     68 
     69 #endif //_JS_RUNTIME_H_
     70 
     71