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 #include "../../include/javascript/JavaScript.h"
      8 #include "../../include/javascript/IJavaScript.h"
      9 #include "../../include/javascript/JS_Define.h"
     10 #include "../../include/javascript/JS_Object.h"
     11 // #include "../../include/javascript/JS_MsgBox.h"
     12 // #include "../../include/javascript/JS_ResMgr.h"
     13 #include "../../include/javascript/JS_Context.h"
     14 
     15 int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
     16 {
     17 	int nRet = 0;
     18 
     19 	if(pApp)
     20 	{
     21 		CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
     22 		if(pDoc)
     23 			pDoc->KillFocusAnnot();
     24 		nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
     25 	}
     26 
     27 	return nRet;
     28 }
     29 
     30 CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)
     31 {
     32 	if (CJS_Context* pContext = (CJS_Context *)cc)
     33 	{
     34 		if (pContext->GetReaderDocument())
     35 			return NULL;
     36 	}
     37 	return NULL;
     38 }
     39 
     40 /* ---------------------------------  CJS_EmbedObj --------------------------------- */
     41 
     42 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) :
     43 	m_pJSObject(pJSObject)
     44 {
     45 }
     46 
     47 CJS_EmbedObj::~CJS_EmbedObj()
     48 {
     49 	m_pJSObject = NULL;
     50 
     51 }
     52 
     53 CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)
     54 {
     55 	return FXJS_GetPageView(cc);
     56 }
     57 
     58 int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon)
     59 {
     60 	return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
     61 }
     62 
     63 void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
     64 {
     65 	CJS_Object::Alert(pContext, swMsg);
     66 }
     67 
     68 CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
     69 {
     70 	CJS_Timer* pTimer = new CJS_Timer(this,pApp);
     71 	pTimer->SetJSTimer(nElapse);
     72 
     73 	return pTimer;
     74 }
     75 
     76 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
     77 {
     78 	ASSERT(pTimer != NULL);
     79 	pTimer->KillJSTimer();
     80 	delete pTimer;
     81 }
     82 
     83 FX_BOOL	CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc)
     84 {
     85 	ASSERT(cc != NULL);
     86 
     87 	return TRUE;
     88 }
     89 
     90 /* ---------------------------------  CJS_Object --------------------------------- */
     91 void  FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)
     92 {
     93 	CJS_Object* pJSObj  = data.GetParameter();
     94 	if(pJSObj)
     95 	{
     96 		pJSObj->ExitInstance();
     97 		delete pJSObj;
     98 	}
     99 	v8::Local<v8::Object> obj = data.GetValue();
    100 	JS_FreePrivate(obj);
    101 }
    102 
    103 CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
    104 {
    105 	v8::Local<v8::Context> context = pObject->CreationContext();
    106 	m_pIsolate = context->GetIsolate();
    107 	m_pObject.Reset(m_pIsolate, pObject);
    108 };
    109 
    110 CJS_Object::~CJS_Object(void)
    111 {
    112 	delete m_pEmbedObj;
    113 	m_pEmbedObj = NULL;
    114 
    115 	m_pObject.Reset();
    116 };
    117 
    118 void	CJS_Object::MakeWeak()
    119 {
    120 	m_pObject.SetWeak(this, FreeObject);
    121 }
    122 
    123 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
    124 {
    125 	return FXJS_GetPageView(cc);
    126 }
    127 
    128 int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
    129 {
    130 	return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
    131 }
    132 
    133 void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
    134 {
    135 	ASSERT(pContext != NULL);
    136 
    137 	if (pContext->IsMsgBoxEnabled())
    138 	{
    139 		CPDFDoc_Environment* pApp = pContext->GetReaderApp();
    140 		if(pApp)
    141 			pApp->JS_appAlert(swMsg, NULL, 0, 3);
    142 	}
    143 }
    144 
    145 
    146