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

Side by Side Diff: fpdfsdk/fpdfxfa/cpdfxfa_app.cpp

Issue 2412903004: Revert of Make the CPDFXFA_App non-global (Closed)
Patch Set: Created 4 years, 2 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/fpdfxfa/cpdfxfa_app.h ('k') | fpdfsdk/fpdfxfa/cpdfxfa_document.h » ('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 "fpdfsdk/fpdfxfa/cpdfxfa_app.h" 7 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" 11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
12 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" 12 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
13 #include "fpdfsdk/fsdk_define.h" 13 #include "fpdfsdk/fsdk_define.h"
14 #include "fxjs/fxjs_v8.h"
15 #include "third_party/base/ptr_util.h" 14 #include "third_party/base/ptr_util.h"
15 #include "xfa/fxbarcode/BC_Library.h"
16 #include "xfa/fxfa/xfa_ffapp.h" 16 #include "xfa/fxfa/xfa_ffapp.h"
17 #include "xfa/fxfa/xfa_fontmgr.h" 17 #include "xfa/fxfa/xfa_fontmgr.h"
18 18
19 CPDFXFA_App::CPDFXFA_App() : m_pIsolate(nullptr) { 19 namespace {
20 // TODO(dsinclair): How do we 'release' the isolate? 20
21 FXJS_GetIsolate(&m_pIsolate); 21 CPDFXFA_App* g_pApp = nullptr;
22
23 } // namespace
24
25 CPDFXFA_App* CPDFXFA_App::GetInstance() {
26 if (!g_pApp) {
27 g_pApp = new CPDFXFA_App();
28 }
29 return g_pApp;
30 }
31
32 void CPDFXFA_App::ReleaseInstance() {
33 delete g_pApp;
34 g_pApp = nullptr;
35 }
36
37 CPDFXFA_App::CPDFXFA_App()
38 : m_bJavaScriptInitialized(FALSE), m_pIsolate(nullptr) {
39 m_pFormFillEnvList.RemoveAll();
40 }
41
42 CPDFXFA_App::~CPDFXFA_App() {
43 FXJSE_Runtime_Release(m_pIsolate);
44 m_pIsolate = nullptr;
45
46 FXJSE_Finalize();
47 BC_Library_Destory();
48 }
49
50 FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) {
51 BC_Library_Init();
52 FXJSE_Initialize();
53
54 m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own();
55 if (!m_pIsolate)
56 return FALSE;
22 57
23 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); 58 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this);
24 m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>()); 59 m_pXFAApp->SetDefaultFontMgr(
60 std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr));
61
62 return TRUE;
25 } 63 }
26 64
27 CPDFXFA_App::~CPDFXFA_App() {} 65 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
66 if (!pFormFillEnv)
67 return FALSE;
68
69 m_pFormFillEnvList.Add(pFormFillEnv);
70 return TRUE;
71 }
72
73 FX_BOOL CPDFXFA_App::RemoveFormFillEnv(
74 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
75 if (!pFormFillEnv)
76 return FALSE;
77
78 int nFind = m_pFormFillEnvList.Find(pFormFillEnv);
79 if (nFind != -1) {
80 m_pFormFillEnvList.RemoveAt(nFind);
81 return TRUE;
82 }
83
84 return FALSE;
85 }
28 86
29 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { 87 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) {
30 if (m_pFormFillEnv) 88 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
31 wsName = m_pFormFillEnv->FFI_GetAppName(); 89 if (pFormFillEnv)
90 wsName = pFormFillEnv->FFI_GetAppName();
32 } 91 }
33 92
34 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { 93 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) {
35 if (m_pFormFillEnv) 94 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
36 wsLanguage = m_pFormFillEnv->GetLanguage(); 95 if (pFormFillEnv)
96 wsLanguage = pFormFillEnv->GetLanguage();
37 } 97 }
38 98
39 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { 99 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) {
40 if (m_pFormFillEnv) { 100 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
41 wsPlatform = m_pFormFillEnv->GetPlatform(); 101 if (pFormFillEnv) {
102 wsPlatform = pFormFillEnv->GetPlatform();
42 } 103 }
43 } 104 }
44 105
45 void CPDFXFA_App::Beep(uint32_t dwType) { 106 void CPDFXFA_App::Beep(uint32_t dwType) {
46 if (m_pFormFillEnv) 107 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
47 m_pFormFillEnv->JS_appBeep(dwType); 108 if (pFormFillEnv)
109 pFormFillEnv->JS_appBeep(dwType);
48 } 110 }
49 111
50 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, 112 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
51 const CFX_WideString& wsTitle, 113 const CFX_WideString& wsTitle,
52 uint32_t dwIconType, 114 uint32_t dwIconType,
53 uint32_t dwButtonType) { 115 uint32_t dwButtonType) {
54 if (!m_pFormFillEnv) 116 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
117 if (!pFormFillEnv)
55 return -1; 118 return -1;
56 119
57 uint32_t iconType = 0; 120 uint32_t iconType = 0;
58 int iButtonType = 0; 121 int iButtonType = 0;
59 switch (dwIconType) { 122 switch (dwIconType) {
60 case XFA_MBICON_Error: 123 case XFA_MBICON_Error:
61 iconType |= 0; 124 iconType |= 0;
62 break; 125 break;
63 case XFA_MBICON_Warning: 126 case XFA_MBICON_Warning:
64 iconType |= 1; 127 iconType |= 1;
(...skipping 12 matching lines...) Expand all
77 case XFA_MB_OKCancel: 140 case XFA_MB_OKCancel:
78 iButtonType |= 1; 141 iButtonType |= 1;
79 break; 142 break;
80 case XFA_MB_YesNo: 143 case XFA_MB_YesNo:
81 iButtonType |= 2; 144 iButtonType |= 2;
82 break; 145 break;
83 case XFA_MB_YesNoCancel: 146 case XFA_MB_YesNoCancel:
84 iButtonType |= 3; 147 iButtonType |= 3;
85 break; 148 break;
86 } 149 }
87 int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), 150 int32_t iRet = pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(),
88 iButtonType, iconType); 151 iButtonType, iconType);
89 switch (iRet) { 152 switch (iRet) {
90 case 1: 153 case 1:
91 return XFA_IDOK; 154 return XFA_IDOK;
92 case 2: 155 case 2:
93 return XFA_IDCancel; 156 return XFA_IDCancel;
94 case 3: 157 case 3:
95 return XFA_IDNo; 158 return XFA_IDNo;
96 case 4: 159 case 4:
97 return XFA_IDYes; 160 return XFA_IDYes;
98 } 161 }
99 return XFA_IDYes; 162 return XFA_IDYes;
100 } 163 }
101 164
102 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, 165 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion,
103 const CFX_WideString& wsTitle, 166 const CFX_WideString& wsTitle,
104 const CFX_WideString& wsDefaultAnswer, 167 const CFX_WideString& wsDefaultAnswer,
105 FX_BOOL bMark) { 168 FX_BOOL bMark) {
106 CFX_WideString wsAnswer; 169 CFX_WideString wsAnswer;
107 if (!m_pFormFillEnv) 170 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
108 return wsAnswer; 171 if (pFormFillEnv) {
109 172 int nLength = 2048;
110 int nLength = 2048; 173 char* pBuff = new char[nLength];
111 char* pBuff = new char[nLength]; 174 nLength = pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
112 nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
113 wsDefaultAnswer.c_str(), nullptr, 175 wsDefaultAnswer.c_str(), nullptr,
114 bMark, pBuff, nLength); 176 bMark, pBuff, nLength);
115 if (nLength > 0) { 177 if (nLength > 0) {
116 nLength = nLength > 2046 ? 2046 : nLength; 178 nLength = nLength > 2046 ? 2046 : nLength;
117 pBuff[nLength] = 0; 179 pBuff[nLength] = 0;
118 pBuff[nLength + 1] = 0; 180 pBuff[nLength + 1] = 0;
119 wsAnswer = CFX_WideString::FromUTF16LE( 181 wsAnswer = CFX_WideString::FromUTF16LE(
120 reinterpret_cast<const unsigned short*>(pBuff), 182 reinterpret_cast<const unsigned short*>(pBuff),
121 nLength / sizeof(unsigned short)); 183 nLength / sizeof(unsigned short));
184 }
185 delete[] pBuff;
122 } 186 }
123 delete[] pBuff;
124 return wsAnswer; 187 return wsAnswer;
125 } 188 }
126 189
127 IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { 190 IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) {
128 return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str()) 191 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
129 : nullptr; 192 return pFormFillEnv ? pFormFillEnv->DownloadFromURL(wsURL.c_str()) : nullptr;
130 } 193 }
131 194
132 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, 195 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
133 const CFX_WideString& wsData, 196 const CFX_WideString& wsData,
134 const CFX_WideString& wsContentType, 197 const CFX_WideString& wsContentType,
135 const CFX_WideString& wsEncode, 198 const CFX_WideString& wsEncode,
136 const CFX_WideString& wsHeader, 199 const CFX_WideString& wsHeader,
137 CFX_WideString& wsResponse) { 200 CFX_WideString& wsResponse) {
138 if (!m_pFormFillEnv) 201 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
202 if (!pFormFillEnv)
139 return FALSE; 203 return FALSE;
140 204
141 wsResponse = m_pFormFillEnv->PostRequestURL( 205 wsResponse = pFormFillEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(),
142 wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(), 206 wsContentType.c_str(),
143 wsHeader.c_str()); 207 wsEncode.c_str(), wsHeader.c_str());
144 return TRUE; 208 return TRUE;
145 } 209 }
146 210
147 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, 211 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL,
148 const CFX_WideString& wsData, 212 const CFX_WideString& wsData,
149 const CFX_WideString& wsEncode) { 213 const CFX_WideString& wsEncode) {
150 return m_pFormFillEnv && 214 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
151 m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), 215 return pFormFillEnv &&
152 wsEncode.c_str()); 216 pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(),
217 wsEncode.c_str());
153 } 218 }
154 219
155 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { 220 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
156 switch (iStringID) { 221 switch (iStringID) {
157 case XFA_IDS_ValidateFailed: 222 case XFA_IDS_ValidateFailed:
158 wsString = L"%s validation failed"; 223 wsString = L"%s validation failed";
159 return; 224 return;
160 case XFA_IDS_CalcOverride: 225 case XFA_IDS_CalcOverride:
161 wsString = L"Calculate Override"; 226 wsString = L"Calculate Override";
162 return; 227 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 L"%s, click Ignore."; 309 L"%s, click Ignore.";
245 return; 310 return;
246 case XFA_IDS_ValidateError: 311 case XFA_IDS_ValidateError:
247 wsString = L"The value you entered for %s is invalid."; 312 wsString = L"The value you entered for %s is invalid.";
248 return; 313 return;
249 } 314 }
250 } 315 }
251 316
252 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { 317 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() {
253 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; 318 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr;
254 if (m_pFormFillEnv) 319 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
255 pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv); 320 if (pFormFillEnv)
321 pAdapter = new CXFA_FWLAdapterTimerMgr(pFormFillEnv);
256 return pAdapter; 322 return pAdapter;
257 } 323 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfxfa/cpdfxfa_app.h ('k') | fpdfsdk/fpdfxfa/cpdfxfa_document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698