summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-07-16 11:09:12 -0700
committerTom Sepez <tsepez@chromium.org>2015-07-16 11:09:12 -0700
commitfb07e2843dad0774d5842c2b08e7792164efc14a (patch)
tree4583acca1bdcf5b60fad79af0b9fa405f192c5d8 /fpdfsdk/src/javascript
parentcc8b4d8763151f51c9fe71ce9b64b2a0d7ddcc88 (diff)
downloadpdfium-fb07e2843dad0774d5842c2b08e7792164efc14a.tar.xz
Tidy up CPDFDOC_Environment.
- untabify as encountered. - Only put single-statement method in .h file, move more complex methods to .cpp (counting an if without braces as a single statement, killing braces as needed). - Move invariant arguments to constructor and make corresponding members const. - Make all members private and add accessor methods. - Make existing accessor methods const where possible. - Kill meaningless asserts. - Add helper functions in place of duplicate code. - Rename GetCurrentDoc() to GetSDKDocument(), since the class has two document members, one of CPDF_Document and one of CPDFSDK_Document, making it clear which one you get. - Simplify some logic with early returns. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1235393002 .
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp92
-rw-r--r--fpdfsdk/src/javascript/app.cpp104
-rw-r--r--fpdfsdk/src/javascript/global.cpp14
3 files changed, 79 insertions, 131 deletions
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index bd40fc05c0..7a1b150ad8 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -8,8 +8,6 @@
#include "../../include/javascript/IJavaScript.h"
#include "../../include/javascript/JS_Define.h"
#include "../../include/javascript/JS_Object.h"
-// #include "../../include/javascript/JS_MsgBox.h"
-// #include "../../include/javascript/JS_ResMgr.h"
#include "../../include/javascript/JS_Context.h"
JS_TIMER_MAPARRAY& GetTimeMap()
@@ -21,106 +19,102 @@ JS_TIMER_MAPARRAY& GetTimeMap()
int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon)
{
- int nRet = 0;
+ if (!pApp)
+ return 0;
- if(pApp)
- {
- CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
- if(pDoc)
- pDoc->KillFocusAnnot();
- nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
- }
+ if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
+ pDoc->KillFocusAnnot();
- return nRet;
+ return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
}
CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)
{
- if (CJS_Context* pContext = (CJS_Context *)cc)
- {
- if (pContext->GetReaderDocument())
- return NULL;
- }
- return NULL;
+ if (CJS_Context* pContext = (CJS_Context *)cc)
+ {
+ if (pContext->GetReaderDocument())
+ return NULL;
+ }
+ return NULL;
}
/* --------------------------------- CJS_EmbedObj --------------------------------- */
CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) :
- m_pJSObject(pJSObject)
+ m_pJSObject(pJSObject)
{
}
CJS_EmbedObj::~CJS_EmbedObj()
{
- m_pJSObject = NULL;
+ m_pJSObject = NULL;
}
CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)
{
- return FXJS_GetPageView(cc);
+ return FXJS_GetPageView(cc);
}
int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,const FX_WCHAR* swMsg,const FX_WCHAR* swTitle,FX_UINT nType,FX_UINT nIcon)
{
- return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
+ return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
}
void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg)
{
- CJS_Object::Alert(pContext, swMsg);
+ CJS_Object::Alert(pContext, swMsg);
}
CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
{
- CJS_Timer* pTimer = new CJS_Timer(this,pApp);
- pTimer->SetJSTimer(nElapse);
+ CJS_Timer* pTimer = new CJS_Timer(this,pApp);
+ pTimer->SetJSTimer(nElapse);
- return pTimer;
+ return pTimer;
}
void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
{
- ASSERT(pTimer != NULL);
- pTimer->KillJSTimer();
- delete pTimer;
+ ASSERT(pTimer != NULL);
+ pTimer->KillJSTimer();
+ delete pTimer;
}
/* --------------------------------- CJS_Object --------------------------------- */
void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data)
{
- CJS_Object* pJSObj = data.GetParameter();
+ CJS_Object* pJSObj = data.GetParameter();
pJSObj->ExitInstance();
delete pJSObj;
- JS_FreePrivate(data.GetInternalField(0));
+ JS_FreePrivate(data.GetInternalField(0));
}
void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data)
{
- CJS_Object* pJSObj = data.GetParameter();
+ CJS_Object* pJSObj = data.GetParameter();
pJSObj->Dispose();
data.SetSecondPassCallback(FreeObject);
}
CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
{
- v8::Local<v8::Context> context = pObject->CreationContext();
- m_pIsolate = context->GetIsolate();
- m_pObject.Reset(m_pIsolate, pObject);
+ v8::Local<v8::Context> context = pObject->CreationContext();
+ m_pIsolate = context->GetIsolate();
+ m_pObject.Reset(m_pIsolate, pObject);
};
CJS_Object::~CJS_Object(void)
{
- delete m_pEmbedObj;
- m_pEmbedObj = NULL;
+ delete m_pEmbedObj;
+ m_pEmbedObj = NULL;
- m_pObject.Reset();
+ m_pObject.Reset();
};
-void CJS_Object::MakeWeak()
+void CJS_Object::MakeWeak()
{
- m_pObject.SetWeak(
+ m_pObject.SetWeak(
this, DisposeObject, v8::WeakCallbackType::kInternalFields);
}
@@ -131,24 +125,22 @@ void CJS_Object::Dispose()
CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
{
- return FXJS_GetPageView(cc);
+ return FXJS_GetPageView(cc);
}
int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon)
{
- return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
+ return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
}
void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg)
{
- ASSERT(pContext != NULL);
+ ASSERT(pContext != NULL);
- if (pContext->IsMsgBoxEnabled())
- {
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- if(pApp)
- pApp->JS_appAlert(swMsg, NULL, 0, 3);
- }
+ if (pContext->IsMsgBoxEnabled())
+ {
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ if(pApp)
+ pApp->JS_appAlert(swMsg, NULL, 0, 3);
+ }
}
-
-
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 31e313179e..af329655fd 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -119,10 +119,10 @@ END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_App,app)
-app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
- m_bCalculate(true),
- m_bRuntimeHighLight(false)
-// m_pMenuHead(NULL)
+app::app(CJS_Object * pJSObject)
+ : CJS_EmbedObj(pJSObject),
+ m_bCalculate(true),
+ m_bRuntimeHighLight(false)
{
}
@@ -136,60 +136,37 @@ app::~app(void)
FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsGetting())
- {
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
-
- CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
-
-// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
-// {
- CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
- if (pDoc)
- {
- CJS_Document * pJSDocument = NULL;
-
- if (pDoc == pCurDoc)
- {
- JSFXObject pObj = JS_GetThisObj(*pRuntime);
-
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
- {
- pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
- }
- }
- else
- {
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
- pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
- ASSERT(pJSDocument != NULL);
-
-
- // pDocument->AttachDoc(pDoc);
- }
+ if (!vp.IsGetting())
+ return FALSE;
- aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
- }
- // }
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
+ CJS_Array aDocs(pRuntime->GetIsolate());
+ if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
+ {
+ CJS_Document* pJSDocument = NULL;
+ if (pDoc == pCurDoc)
+ {
+ JSFXObject pObj = JS_GetThisObj(*pRuntime);
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
+ pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+ }
+ else
+ {
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
+ pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+ ASSERT(pJSDocument != NULL);
+ }
+ aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
+ }
+ if (aDocs.GetLength() > 0)
+ vp << aDocs;
+ else
+ vp.SetNull();
- if (aDocs.GetLength() > 0)
- vp << aDocs;
- else
- vp.SetNull();
- return TRUE;
- }
- return FALSE;
+ return TRUE;
}
FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
@@ -201,27 +178,16 @@ FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr
m_bCalculate = (FX_BOOL)bVP;
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
CJS_Array aDocs(pRuntime->GetIsolate());
- if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
- {
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
- ASSERT(pInterForm != NULL);
- pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
- }
+ if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
+ pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
}
else
{
vp << (bool)m_bCalculate;
}
-
return TRUE;
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index cddc919f75..6eea290f68 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -117,24 +117,14 @@ global_alternate::global_alternate(CJS_Object* pJSObject)
global_alternate::~global_alternate(void)
{
- ASSERT(m_pApp != NULL);
-
-// CommitGlobalPersisitentVariables();
DestroyGlobalPersisitentVariables();
-
- CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
- ASSERT(pFactory);
-
- pFactory->ReleaseGlobalData();
+ m_pApp->GetRuntimeFactory()->ReleaseGlobalData();
}
void global_alternate::Initial(CPDFDoc_Environment* pApp)
{
m_pApp = pApp;
-
- CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
- ASSERT(pFactory);
- m_pGlobalData = pFactory->NewGlobalData(pApp);
+ m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp);
UpdateGlobalPersistentVariables();
}