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

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

Issue 2424993002: Merge CPDFXFA_App into CPDFXFA_Document. (Closed)
Patch Set: Move check Created 4 years, 1 month 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
(Empty)
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 "fpdfsdk/fpdfxfa/cpdfxfa_app.h"
8
9 #include <memory>
10
11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
12 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
13 #include "fpdfsdk/fsdk_define.h"
14 #include "fpdfsdk/javascript/cjs_runtime.h"
15 #include "fxjs/fxjs_v8.h"
16 #include "xfa/fxfa/xfa_ffapp.h"
17 #include "xfa/fxfa/xfa_fontmgr.h"
18
19 CPDFXFA_App::CPDFXFA_App() {
20 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this);
21 m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>());
22 }
23
24 CPDFXFA_App::~CPDFXFA_App() {}
25
26 v8::Isolate* CPDFXFA_App::GetJSERuntime() const {
27 if (!m_pFormFillEnv)
28 return nullptr;
29
30 // XFA requires V8, if we have V8 then we have a CJS_Runtime and not the stub.
31 CJS_Runtime* runtime =
32 static_cast<CJS_Runtime*>(m_pFormFillEnv->GetJSRuntime());
33 return runtime->GetIsolate();
34 }
35
36 void CPDFXFA_App::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
37 m_pFormFillEnv = pFormFillEnv;
38 }
39
40 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) {
41 if (m_pFormFillEnv)
42 wsName = m_pFormFillEnv->FFI_GetAppName();
43 }
44
45 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) {
46 if (m_pFormFillEnv)
47 wsLanguage = m_pFormFillEnv->GetLanguage();
48 }
49
50 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) {
51 if (m_pFormFillEnv) {
52 wsPlatform = m_pFormFillEnv->GetPlatform();
53 }
54 }
55
56 void CPDFXFA_App::Beep(uint32_t dwType) {
57 if (m_pFormFillEnv)
58 m_pFormFillEnv->JS_appBeep(dwType);
59 }
60
61 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
62 const CFX_WideString& wsTitle,
63 uint32_t dwIconType,
64 uint32_t dwButtonType) {
65 if (!m_pFormFillEnv)
66 return -1;
67
68 uint32_t iconType = 0;
69 int iButtonType = 0;
70 switch (dwIconType) {
71 case XFA_MBICON_Error:
72 iconType |= 0;
73 break;
74 case XFA_MBICON_Warning:
75 iconType |= 1;
76 break;
77 case XFA_MBICON_Question:
78 iconType |= 2;
79 break;
80 case XFA_MBICON_Status:
81 iconType |= 3;
82 break;
83 }
84 switch (dwButtonType) {
85 case XFA_MB_OK:
86 iButtonType |= 0;
87 break;
88 case XFA_MB_OKCancel:
89 iButtonType |= 1;
90 break;
91 case XFA_MB_YesNo:
92 iButtonType |= 2;
93 break;
94 case XFA_MB_YesNoCancel:
95 iButtonType |= 3;
96 break;
97 }
98 int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(),
99 iButtonType, iconType);
100 switch (iRet) {
101 case 1:
102 return XFA_IDOK;
103 case 2:
104 return XFA_IDCancel;
105 case 3:
106 return XFA_IDNo;
107 case 4:
108 return XFA_IDYes;
109 }
110 return XFA_IDYes;
111 }
112
113 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion,
114 const CFX_WideString& wsTitle,
115 const CFX_WideString& wsDefaultAnswer,
116 FX_BOOL bMark) {
117 CFX_WideString wsAnswer;
118 if (!m_pFormFillEnv)
119 return wsAnswer;
120
121 int nLength = 2048;
122 char* pBuff = new char[nLength];
123 nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
124 wsDefaultAnswer.c_str(), nullptr,
125 bMark, pBuff, nLength);
126 if (nLength > 0) {
127 nLength = nLength > 2046 ? 2046 : nLength;
128 pBuff[nLength] = 0;
129 pBuff[nLength + 1] = 0;
130 wsAnswer = CFX_WideString::FromUTF16LE(
131 reinterpret_cast<const unsigned short*>(pBuff),
132 nLength / sizeof(unsigned short));
133 }
134 delete[] pBuff;
135 return wsAnswer;
136 }
137
138 IFX_SeekableReadStream* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) {
139 return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str())
140 : nullptr;
141 }
142
143 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
144 const CFX_WideString& wsData,
145 const CFX_WideString& wsContentType,
146 const CFX_WideString& wsEncode,
147 const CFX_WideString& wsHeader,
148 CFX_WideString& wsResponse) {
149 if (!m_pFormFillEnv)
150 return FALSE;
151
152 wsResponse = m_pFormFillEnv->PostRequestURL(
153 wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(),
154 wsHeader.c_str());
155 return TRUE;
156 }
157
158 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL,
159 const CFX_WideString& wsData,
160 const CFX_WideString& wsEncode) {
161 return m_pFormFillEnv &&
162 m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(),
163 wsEncode.c_str());
164 }
165
166 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
167 switch (iStringID) {
168 case XFA_IDS_ValidateFailed:
169 wsString = L"%s validation failed";
170 return;
171 case XFA_IDS_CalcOverride:
172 wsString = L"Calculate Override";
173 return;
174 case XFA_IDS_ModifyField:
175 wsString = L"Are you sure you want to modify this field?";
176 return;
177 case XFA_IDS_NotModifyField:
178 wsString = L"You are not allowed to modify this field.";
179 return;
180 case XFA_IDS_AppName:
181 wsString = L"pdfium";
182 return;
183 case XFA_IDS_Unable_TO_SET:
184 wsString = L"Unable to set ";
185 return;
186 case XFA_IDS_INVAlID_PROP_SET:
187 wsString = L"Invalid property set operation.";
188 return;
189 case XFA_IDS_NOT_DEFAUL_VALUE:
190 wsString = L" doesn't have a default property.";
191 return;
192 case XFA_IDS_UNABLE_SET_LANGUAGE:
193 wsString = L"Unable to set language value.";
194 return;
195 case XFA_IDS_UNABLE_SET_NUMPAGES:
196 wsString = L"Unable to set numPages value.";
197 return;
198 case XFA_IDS_UNABLE_SET_PLATFORM:
199 wsString = L"Unable to set platform value.";
200 return;
201 case XFA_IDS_UNABLE_SET_VARIATION:
202 wsString = L"Unable to set variation value.";
203 return;
204 case XFA_IDS_UNABLE_SET_VERSION:
205 wsString = L"Unable to set version value.";
206 return;
207 case XFA_IDS_UNABLE_SET_READY:
208 wsString = L"Unable to set ready value.";
209 return;
210 case XFA_IDS_COMPILER_ERROR:
211 wsString = L"Compiler error.";
212 return;
213 case XFA_IDS_DIVIDE_ZERO:
214 wsString = L"Divide by zero.";
215 return;
216 case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT:
217 wsString =
218 L"An attempt was made to reference property '%s' of a non-object in "
219 L"SOM expression %s.";
220 return;
221 case XFA_IDS_INDEX_OUT_OF_BOUNDS:
222 wsString = L"Index value is out of bounds.";
223 return;
224 case XFA_IDS_INCORRECT_NUMBER_OF_METHOD:
225 wsString = L"Incorrect number of parameters calling method '%s'.";
226 return;
227 case XFA_IDS_ARGUMENT_MISMATCH:
228 wsString = L"Argument mismatch in property or function argument.";
229 return;
230 case XFA_IDS_NOT_HAVE_PROPERTY:
231 wsString = L"'%s' doesn't have property '%s'.";
232 return;
233 case XFA_IDS_VIOLATE_BOUNDARY:
234 wsString =
235 L"The element [%s] has violated its allowable number of occurrences.";
236 return;
237 case XFA_IDS_SERVER_DENY:
238 wsString = L"Server does not permit.";
239 return;
240 case XFA_IDS_ValidateLimit:
241 wsString =
242 L"Message limit exceeded. Remaining %d validation errors not "
243 L"reported.";
244 return;
245 case XFA_IDS_ValidateNullWarning:
246 wsString =
247 L"%s cannot be blank. To ignore validations for %s, click Ignore.";
248 return;
249 case XFA_IDS_ValidateNullError:
250 wsString = L"%s cannot be blank.";
251 return;
252 case XFA_IDS_ValidateWarning:
253 wsString =
254 L"The value you entered for %s is invalid. To ignore validations for "
255 L"%s, click Ignore.";
256 return;
257 case XFA_IDS_ValidateError:
258 wsString = L"The value you entered for %s is invalid.";
259 return;
260 }
261 }
262
263 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() {
264 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr;
265 if (m_pFormFillEnv)
266 pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv);
267 return pAdapter;
268 }
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