summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-09-21 17:07:49 -0700
committerTom Sepez <tsepez@chromium.org>2015-09-21 17:07:49 -0700
commit854a7f65b70d40225a53890a68a57f5c13cf268c (patch)
tree8b4492eae70a53cf9a6d1e46e385120c319a9cb0
parent116e4addeecd2cb779b1ab590bea2d091ca12915 (diff)
downloadpdfium-854a7f65b70d40225a53890a68a57f5c13cf268c.tar.xz
Merge to XFA: Remove CJS_RuntimeFactory
New edits in: fpdfsdk/include/fpdfxfa/fpdfxfa_app.h fpdfsdk/include/javascript/IJavaScript.h fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp (cherry picked from commit bca779d0957965eb2ebfad5479e0894844749626) Original Review URL: https://codereview.chromium.org/1360523004 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1348393007 .
-rw-r--r--fpdfsdk/include/fpdfxfa/fpdfxfa_app.h4
-rw-r--r--fpdfsdk/include/fsdk_mgr.h3
-rw-r--r--fpdfsdk/include/javascript/IJavaScript.h21
-rw-r--r--fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp8
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp10
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp22
6 files changed, 6 insertions, 62 deletions
diff --git a/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h b/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h
index bf96993bd3..49825c3f7f 100644
--- a/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h
+++ b/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h
@@ -8,7 +8,6 @@
#define FPDFXFA_APP_H_
class IFXJS_Runtime;
-class CJS_RuntimeFactory;
class CPDFXFA_App : public IXFA_AppProvider {
public:
@@ -28,8 +27,6 @@ class CPDFXFA_App : public IXFA_AppProvider {
void ReleaseRuntime();
FX_BOOL InitRuntime(FX_BOOL bReset = FALSE);
- CJS_RuntimeFactory* GetRuntimeFactory() { return m_pJSRuntimeFactory; }
-
// IFXA_AppProvider:
void GetAppType(CFX_WideString& wsAppType) override;
void SetAppType(const CFX_WideStringC& wsAppType) override;
@@ -89,7 +86,6 @@ class CPDFXFA_App : public IXFA_AppProvider {
IXFA_FontMgr* m_pFontMgr;
FXJSE_HRUNTIME m_hJSERuntime;
IFXJS_Runtime* m_pJSRuntime;
- CJS_RuntimeFactory* m_pJSRuntimeFactory;
CFX_WideString m_csAppType;
};
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index c4879aa545..b76b16bd07 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -24,7 +24,6 @@
#include "javascript/IJavaScript.h"
class CFFL_IFormFiller;
-class CJS_RuntimeFactory;
class CPDFSDK_ActionHandler;
class CPDFSDK_Annot;
class CPDFSDK_Document;
@@ -469,7 +468,7 @@ class CPDFDoc_Environment final {
private:
CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
CPDFSDK_ActionHandler* m_pActionHandler;
- IFXJS_Runtime* m_pJSRuntime;
+ nonstd::unique_ptr<IFXJS_Runtime> m_pJSRuntime;
FPDF_FORMFILLINFO* const m_pInfo;
CPDFSDK_Document* m_pSDKDoc;
CPDFXFA_Document* const m_pXFADoc;
diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h
index 65dae74ab4..d15ffc237e 100644
--- a/fpdfsdk/include/javascript/IJavaScript.h
+++ b/fpdfsdk/include/javascript/IJavaScript.h
@@ -134,10 +134,11 @@ class IFXJS_Context {
class IFXJS_Runtime {
public:
+ virtual ~IFXJS_Runtime() {}
+
virtual IFXJS_Context* NewContext() = 0;
virtual void ReleaseContext(IFXJS_Context* pContext) = 0;
virtual IFXJS_Context* GetCurrentContext() = 0;
-
virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0;
virtual CPDFSDK_Document* GetReaderDocument() = 0;
@@ -146,24 +147,6 @@ class IFXJS_Runtime {
FXJSE_HVALUE hValue) = 0;
virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name,
FXJSE_HVALUE hValue) = 0;
-
- protected:
- virtual ~IFXJS_Runtime() {}
-};
-
-class CJS_RuntimeFactory {
- public:
- CJS_RuntimeFactory() : m_bInit(false), m_nRef(0) {}
- ~CJS_RuntimeFactory();
-
- IFXJS_Runtime* NewJSRuntime(CPDFDoc_Environment* pApp);
- void DeleteJSRuntime(IFXJS_Runtime* pRuntime);
- void AddRef();
- void Release();
-
- private:
- bool m_bInit;
- int m_nRef;
};
#endif // FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp
index 774ec6e4d6..dc5d0686fc 100644
--- a/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp
@@ -27,19 +27,12 @@ void CPDFXFA_App::ReleaseInstance() {
g_pApp = NULL;
}
-CJS_RuntimeFactory* g_GetJSRuntimeFactory() {
- static CJS_RuntimeFactory g_JSRuntimeFactory;
- return &g_JSRuntimeFactory;
-}
-
CPDFXFA_App::CPDFXFA_App()
: m_bInitRuntime(FALSE),
m_pXFAApp(NULL),
m_pFontMgr(NULL),
m_hJSERuntime(NULL),
m_csAppType(JS_STR_VIEWERTYPE_STANDARD) {
- m_pJSRuntimeFactory = g_GetJSRuntimeFactory();
- m_pJSRuntimeFactory->AddRef();
m_pEnvList.RemoveAll();
}
@@ -50,7 +43,6 @@ CPDFXFA_App::~CPDFXFA_App() {
delete m_pXFAApp;
m_pXFAApp = NULL;
- m_pJSRuntimeFactory->Release();
FXJSE_Runtime_Release(m_hJSERuntime);
m_hJSERuntime = NULL;
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 4a55622e57..a3e77e4514 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -13,6 +13,7 @@
#include "../include/formfiller/FFL_FormFiller.h"
#include "../include/javascript/IJavaScript.h"
#include "../include/fpdfxfa/fpdfxfa_app.h"
+#include "../include/javascript/JS_Runtime.h"
#if _FX_OS_ == _FX_ANDROID_
#include "time.h"
@@ -209,7 +210,6 @@ CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc,
FPDF_FORMFILLINFO* pFFinfo)
: m_pAnnotHandlerMgr(NULL),
m_pActionHandler(NULL),
- m_pJSRuntime(NULL),
m_pInfo(pFFinfo),
m_pSDKDoc(NULL),
m_pXFADoc(pDoc),
@@ -222,9 +222,6 @@ CPDFDoc_Environment::~CPDFDoc_Environment() {
m_pIFormFiller = NULL;
CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
- if (m_pJSRuntime && pProvider->GetRuntimeFactory())
- pProvider->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
-
if (pProvider->m_pEnvList.GetSize() == 0) {
pProvider->ReleaseRuntime();
pProvider->InitRuntime(TRUE);
@@ -386,9 +383,8 @@ IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() {
if (!IsJSInitiated())
return NULL;
if (!m_pJSRuntime)
- m_pJSRuntime =
- CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this);
- return m_pJSRuntime;
+ m_pJSRuntime.reset(new CJS_Runtime(this));
+ return m_pJSRuntime.get();
}
CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() {
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 643cefb92f..e8e48b0c07 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -29,28 +29,6 @@
#include "../../include/fpdfxfa/fpdfxfa_app.h"
#include "../../../xfa/src/fxjse/src/value.h"
-CJS_RuntimeFactory::~CJS_RuntimeFactory() {}
-
-IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) {
- m_bInit = true;
- return new CJS_Runtime(pApp);
-}
-void CJS_RuntimeFactory::AddRef() {
- m_nRef++;
-}
-void CJS_RuntimeFactory::Release() {
- if (m_bInit) {
- if (--m_nRef == 0) {
- FXJS_Release();
- m_bInit = FALSE;
- }
- }
-}
-
-void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) {
- delete (CJS_Runtime*)pRuntime;
-}
-
/* ------------------------------ CJS_Runtime ------------------------------ */
v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate);