Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: fpdfsdk/src/fsdk_mgr.cpp

Issue 1360523004: Remove CJS_RuntimeFactory (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/include/javascript/IJavaScript.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../public/fpdf_ext.h" 7 #include "../../public/fpdf_ext.h"
8 #include "../../third_party/base/nonstd_unique_ptr.h" 8 #include "../../third_party/base/nonstd_unique_ptr.h"
9 #include "../include/fsdk_define.h" 9 #include "../include/fsdk_define.h"
10 #include "../include/fsdk_mgr.h" 10 #include "../include/fsdk_mgr.h"
11 #include "../include/formfiller/FFL_FormFiller.h" 11 #include "../include/formfiller/FFL_FormFiller.h"
12 #include "../include/javascript/IJavaScript.h" 12 #include "../include/javascript/IJavaScript.h"
13 #include "../include/javascript/JS_Runtime.h"
13 14
14 #if _FX_OS_ == _FX_ANDROID_ 15 #if _FX_OS_ == _FX_ANDROID_
15 #include "time.h" 16 #include "time.h"
16 #else 17 #else
17 #include <ctime> 18 #include <ctime>
18 #endif 19 #endif
19 20
20 class CFX_SystemHandler : public IFX_SystemHandler { 21 class CFX_SystemHandler : public IFX_SystemHandler {
21 public: 22 public:
22 CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv), m_nCharSet(-1) {} 23 CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv), m_nCharSet(-1) {}
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); 197 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
197 } 198 }
198 void CFX_SystemHandler::KillTimer(int32_t nID) { 199 void CFX_SystemHandler::KillTimer(int32_t nID) {
199 m_pEnv->FFI_KillTimer(nID); 200 m_pEnv->FFI_KillTimer(nID);
200 } 201 }
201 202
202 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { 203 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() {
203 return m_pEnv->FFI_GetLocalTime(); 204 return m_pEnv->FFI_GetLocalTime();
204 } 205 }
205 206
206 CJS_RuntimeFactory* GetJSRuntimeFactory() {
207 static CJS_RuntimeFactory s_JSRuntimeFactory;
208 return &s_JSRuntimeFactory;
209 }
210
211 CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc, 207 CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc,
212 FPDF_FORMFILLINFO* pFFinfo) 208 FPDF_FORMFILLINFO* pFFinfo)
213 : m_pAnnotHandlerMgr(NULL), 209 : m_pAnnotHandlerMgr(NULL),
214 m_pActionHandler(NULL), 210 m_pActionHandler(NULL),
215 m_pJSRuntime(NULL), 211 m_pJSRuntime(NULL),
216 m_pInfo(pFFinfo), 212 m_pInfo(pFFinfo),
217 m_pSDKDoc(NULL), 213 m_pSDKDoc(NULL),
218 m_pPDFDoc(pDoc), 214 m_pPDFDoc(pDoc),
219 m_pIFormFiller(NULL) { 215 m_pIFormFiller(NULL) {
220 m_pSysHandler = new CFX_SystemHandler(this); 216 m_pSysHandler = new CFX_SystemHandler(this);
221 m_pJSRuntimeFactory = GetJSRuntimeFactory();
222 m_pJSRuntimeFactory->AddRef();
Tom Sepez 2015/09/21 22:12:16 Yep, we're ref-counting a static object here :).
223 } 217 }
224 218
225 CPDFDoc_Environment::~CPDFDoc_Environment() { 219 CPDFDoc_Environment::~CPDFDoc_Environment() {
226 delete m_pIFormFiller; 220 delete m_pIFormFiller;
227 m_pIFormFiller = NULL; 221 m_pIFormFiller = NULL;
228 if (m_pJSRuntime && m_pJSRuntimeFactory)
229 m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);
230 m_pJSRuntimeFactory->Release();
231 222
223 delete m_pJSRuntime;
Lei Zhang 2015/09/21 23:16:05 Can we convert |m_pJSRuntime| to a unique_ptr whil
Tom Sepez 2015/09/21 23:28:52 Done.
232 delete m_pSysHandler; 224 delete m_pSysHandler;
233 m_pSysHandler = NULL; 225 m_pSysHandler = NULL;
234 226
235 delete m_pAnnotHandlerMgr; 227 delete m_pAnnotHandlerMgr;
236 m_pAnnotHandlerMgr = NULL; 228 m_pAnnotHandlerMgr = NULL;
237 delete m_pActionHandler; 229 delete m_pActionHandler;
238 m_pActionHandler = NULL; 230 m_pActionHandler = NULL;
239 } 231 }
240 232
241 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, 233 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 bsBcc.ReleaseBuffer(); 369 bsBcc.ReleaseBuffer();
378 bsSubject.ReleaseBuffer(); 370 bsSubject.ReleaseBuffer();
379 bsMsg.ReleaseBuffer(); 371 bsMsg.ReleaseBuffer();
380 } 372 }
381 } 373 }
382 374
383 IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { 375 IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() {
384 if (!IsJSInitiated()) 376 if (!IsJSInitiated())
385 return NULL; 377 return NULL;
386 if (!m_pJSRuntime) 378 if (!m_pJSRuntime)
387 m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this); 379 m_pJSRuntime = new CJS_Runtime(this);
388 return m_pJSRuntime; 380 return m_pJSRuntime;
389 } 381 }
390 382
391 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { 383 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() {
392 if (!m_pAnnotHandlerMgr) 384 if (!m_pAnnotHandlerMgr)
393 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); 385 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
394 return m_pAnnotHandlerMgr; 386 return m_pAnnotHandlerMgr;
395 } 387 }
396 388
397 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { 389 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() {
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 if (!pFocusAnnot) 990 if (!pFocusAnnot)
999 return NULL; 991 return NULL;
1000 992
1001 for (int i = 0; i < m_fxAnnotArray.GetSize(); i++) { 993 for (int i = 0; i < m_fxAnnotArray.GetSize(); i++) {
1002 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); 994 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1003 if (pAnnot == pFocusAnnot) 995 if (pAnnot == pFocusAnnot)
1004 return pAnnot; 996 return pAnnot;
1005 } 997 }
1006 return NULL; 998 return NULL;
1007 } 999 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/IJavaScript.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698