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

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

Issue 1651313002: Merge to XFA: Tidy up CPDF_DocEnvironment::JS_* methods (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 10 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/fsdk_mgr.h ('k') | no next file » | 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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "fpdfsdk/include/fsdk_mgr.h" 10 #include "fpdfsdk/include/fsdk_mgr.h"
(...skipping 10 matching lines...) Expand all
21 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" 21 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
22 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" 22 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h"
23 #endif // PDF_ENABLE_XFA 23 #endif // PDF_ENABLE_XFA
24 24
25 #if _FX_OS_ == _FX_ANDROID_ 25 #if _FX_OS_ == _FX_ANDROID_
26 #include "time.h" 26 #include "time.h"
27 #else 27 #else
28 #include <ctime> 28 #include <ctime>
29 #endif 29 #endif
30 30
31 namespace {
32
33 int CharSet2CP(int charset) {
34 if (charset == 128)
35 return 932;
36 if (charset == 134)
37 return 936;
38 if (charset == 129)
39 return 949;
40 if (charset == 136)
41 return 950;
42 return 0;
43 }
44
45 } // namespace
46
47 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) {
48 return reinterpret_cast<FPDF_WIDESTRING>(
49 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength()));
50 }
51
31 class CFX_SystemHandler : public IFX_SystemHandler { 52 class CFX_SystemHandler : public IFX_SystemHandler {
32 public: 53 public:
33 explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) 54 explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv)
34 : m_pEnv(pEnv), m_nCharSet(-1) {} 55 : m_pEnv(pEnv), m_nCharSet(-1) {}
35 ~CFX_SystemHandler() override {} 56 ~CFX_SystemHandler() override {}
36 57
37 public: 58 public:
38 // IFX_SystemHandler 59 // IFX_SystemHandler
39 void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override; 60 void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override;
40 void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) override; 61 void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) override;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 183 }
163 184
164 for (int i = 0; i < nSize; ++i) { 185 for (int i = 0; i < nSize; ++i) {
165 if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName)) 186 if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
166 return TRUE; 187 return TRUE;
167 } 188 }
168 189
169 return FALSE; 190 return FALSE;
170 } 191 }
171 192
172 static int CharSet2CP(int charset) {
173 if (charset == 128)
174 return 932;
175 if (charset == 134)
176 return 936;
177 if (charset == 129)
178 return 949;
179 if (charset == 136)
180 return 950;
181 return 0;
182 }
183 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( 193 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(
184 CPDF_Document* pDoc, 194 CPDF_Document* pDoc,
185 CFX_ByteString sFontFaceName, 195 CFX_ByteString sFontFaceName,
186 uint8_t nCharset) { 196 uint8_t nCharset) {
187 if (pDoc) { 197 if (pDoc) {
188 CFX_Font* pFXFont = new CFX_Font(); 198 CFX_Font* pFXFont = new CFX_Font();
189 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), 199 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset),
190 FALSE); 200 FALSE);
191 CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); 201 CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE);
192 delete pFXFont; 202 delete pFXFont;
(...skipping 26 matching lines...) Expand all
219 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); 229 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
220 if (pProvider->m_pEnvList.GetSize() == 0) 230 if (pProvider->m_pEnvList.GetSize() == 0)
221 pProvider->SetJavaScriptInitialized(FALSE); 231 pProvider->SetJavaScriptInitialized(FALSE);
222 #endif // PDF_ENABLE_XFA 232 #endif // PDF_ENABLE_XFA
223 } 233 }
224 234
225 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, 235 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg,
226 const FX_WCHAR* Title, 236 const FX_WCHAR* Title,
227 FX_UINT Type, 237 FX_UINT Type,
228 FX_UINT Icon) { 238 FX_UINT Icon) {
229 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { 239 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
230 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); 240 !m_pInfo->m_pJsPlatform->app_alert) {
231 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); 241 return -1;
232 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
233 FPDF_WIDESTRING pTitle =
234 (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
235 int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg,
236 pTitle, Type, Icon);
237 bsMsg.ReleaseBuffer();
238 bsTitle.ReleaseBuffer();
239 return ret;
240 } 242 }
241 return -1; 243 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
244 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
245 return m_pInfo->m_pJsPlatform->app_alert(
246 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg),
247 AsFPDFWideString(&bsTitle), Type, Icon);
242 } 248 }
243 249
244 int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, 250 int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question,
245 const FX_WCHAR* Title, 251 const FX_WCHAR* Title,
246 const FX_WCHAR* Default, 252 const FX_WCHAR* Default,
247 const FX_WCHAR* cLabel, 253 const FX_WCHAR* cLabel,
248 FPDF_BOOL bPassword, 254 FPDF_BOOL bPassword,
249 void* response, 255 void* response,
250 int length) { 256 int length) {
251 if (m_pInfo && m_pInfo->m_pJsPlatform && 257 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
252 m_pInfo->m_pJsPlatform->app_response) { 258 !m_pInfo->m_pJsPlatform->app_response) {
253 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); 259 return -1;
254 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
255 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
256 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
257 FPDF_WIDESTRING pQuestion =
258 (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength());
259 FPDF_WIDESTRING pTitle =
260 (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
261 FPDF_WIDESTRING pDefault =
262 (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength());
263 FPDF_WIDESTRING pLabel =
264 (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength());
265 int ret = m_pInfo->m_pJsPlatform->app_response(
266 m_pInfo->m_pJsPlatform, pQuestion, pTitle, pDefault, pLabel, bPassword,
267 response, length);
268 bsQuestion.ReleaseBuffer();
269 bsTitle.ReleaseBuffer();
270 bsDefault.ReleaseBuffer();
271 bsLabel.ReleaseBuffer();
272 return ret;
273 } 260 }
274 return -1; 261 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode();
262 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
263 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
264 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
265 return m_pInfo->m_pJsPlatform->app_response(
266 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion),
267 AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault),
268 AsFPDFWideString(&bsLabel), bPassword, response, length);
269 }
270
271 void CPDFDoc_Environment::JS_appBeep(int nType) {
272 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
273 !m_pInfo->m_pJsPlatform->app_beep) {
274 return;
275 }
276 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
275 } 277 }
276 278
277 CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { 279 CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() {
278 if (!m_pInfo || !m_pInfo->m_pJsPlatform || 280 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
279 !m_pInfo->m_pJsPlatform->Field_browse) { 281 !m_pInfo->m_pJsPlatform->Field_browse) {
280 return L""; 282 return CFX_WideString();
281 } 283 }
282
283 const int nRequiredLen = 284 const int nRequiredLen =
284 m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); 285 m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0);
285 if (nRequiredLen <= 0) 286 if (nRequiredLen <= 0)
286 return L""; 287 return CFX_WideString();
287 288
288 std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); 289 std::unique_ptr<char[]> pBuff(new char[nRequiredLen]);
289 memset(pBuff.get(), 0, nRequiredLen); 290 memset(pBuff.get(), 0, nRequiredLen);
290 const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( 291 const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(
291 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); 292 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen);
292 if (nActualLen <= 0 || nActualLen > nRequiredLen) 293 if (nActualLen <= 0 || nActualLen > nRequiredLen)
293 return L""; 294 return CFX_WideString();
294 295
295 CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); 296 return CFX_WideString::FromLocal(CFX_ByteString(pBuff.get(), nActualLen));
296 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
297 return wsRet;
298 } 297 }
299 298
300 CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { 299 CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() {
301 if (!m_pInfo || !m_pInfo->m_pJsPlatform || 300 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
302 !m_pInfo->m_pJsPlatform->Doc_getFilePath) { 301 !m_pInfo->m_pJsPlatform->Doc_getFilePath) {
303 return L""; 302 return CFX_WideString();
304 } 303 }
305
306 const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( 304 const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
307 m_pInfo->m_pJsPlatform, nullptr, 0); 305 m_pInfo->m_pJsPlatform, nullptr, 0);
308 if (nRequiredLen <= 0) 306 if (nRequiredLen <= 0)
309 return L""; 307 return CFX_WideString();
310 308
311 std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); 309 std::unique_ptr<char[]> pBuff(new char[nRequiredLen]);
312 memset(pBuff.get(), 0, nRequiredLen); 310 memset(pBuff.get(), 0, nRequiredLen);
313 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( 311 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
314 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); 312 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen);
315 if (nActualLen <= 0 || nActualLen > nRequiredLen) 313 if (nActualLen <= 0 || nActualLen > nRequiredLen)
316 return L""; 314 return CFX_WideString();
317 315
318 CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); 316 return CFX_WideString::FromLocal(CFX_ByteString(pBuff.get(), nActualLen));
319 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
320 return wsRet;
321 } 317 }
322 318
323 void CPDFDoc_Environment::JS_docSubmitForm(void* formData, 319 void CPDFDoc_Environment::JS_docSubmitForm(void* formData,
324 int length, 320 int length,
325 const FX_WCHAR* URL) { 321 const FX_WCHAR* URL) {
326 if (m_pInfo && m_pInfo->m_pJsPlatform && 322 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
327 m_pInfo->m_pJsPlatform->Doc_submitForm) { 323 !m_pInfo->m_pJsPlatform->Doc_submitForm) {
328 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); 324 return;
329 FPDF_WIDESTRING pDestination =
330 (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength());
331 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData,
332 length, pDestination);
333 bsDestination.ReleaseBuffer();
334 } 325 }
326 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
327 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData,
328 length,
329 AsFPDFWideString(&bsDestination));
335 } 330 }
336 331
337 void CPDFDoc_Environment::JS_docmailForm(void* mailData, 332 void CPDFDoc_Environment::JS_docmailForm(void* mailData,
338 int length, 333 int length,
339 FPDF_BOOL bUI, 334 FPDF_BOOL bUI,
340 const FX_WCHAR* To, 335 const FX_WCHAR* To,
341 const FX_WCHAR* Subject, 336 const FX_WCHAR* Subject,
342 const FX_WCHAR* CC, 337 const FX_WCHAR* CC,
343 const FX_WCHAR* BCC, 338 const FX_WCHAR* BCC,
344 const FX_WCHAR* Msg) { 339 const FX_WCHAR* Msg) {
345 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) { 340 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
346 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); 341 !m_pInfo->m_pJsPlatform->Doc_mail) {
347 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); 342 return;
348 CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode();
349 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
350 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
351 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
352 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
353 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
354 FPDF_WIDESTRING pSubject =
355 (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
356 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
357 m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length,
358 bUI, pTo, pSubject, pCC, pBcc, pMsg);
359 bsTo.ReleaseBuffer();
360 bsCC.ReleaseBuffer();
361 bsBcc.ReleaseBuffer();
362 bsSubject.ReleaseBuffer();
363 bsMsg.ReleaseBuffer();
364 } 343 }
344 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
345 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
346 CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode();
347 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
348 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
349 m_pInfo->m_pJsPlatform->Doc_mail(
350 m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo),
351 AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC),
352 AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg));
353 }
354
355 void CPDFDoc_Environment::JS_docprint(FPDF_BOOL bUI,
356 int nStart,
357 int nEnd,
358 FPDF_BOOL bSilent,
359 FPDF_BOOL bShrinkToFit,
360 FPDF_BOOL bPrintAsImage,
361 FPDF_BOOL bReverse,
362 FPDF_BOOL bAnnotations) {
363 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
364 !m_pInfo->m_pJsPlatform->Doc_print) {
365 return;
366 }
367 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd,
368 bSilent, bShrinkToFit, bPrintAsImage,
369 bReverse, bAnnotations);
370 }
371
372 void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) {
373 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
374 !m_pInfo->m_pJsPlatform->Doc_gotoPage) {
375 return;
376 }
377 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
365 } 378 }
366 379
367 IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { 380 IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() {
368 if (!IsJSInitiated()) 381 if (!IsJSInitiated())
369 return NULL; 382 return NULL;
370 if (!m_pJSRuntime) 383 if (!m_pJSRuntime)
371 m_pJSRuntime.reset(IJS_Runtime::Create(this)); 384 m_pJSRuntime.reset(IJS_Runtime::Create(this));
372 return m_pJSRuntime.get(); 385 return m_pJSRuntime.get();
373 } 386 }
374 387
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); 1192 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1180 if (!pFocusAnnot) 1193 if (!pFocusAnnot)
1181 return nullptr; 1194 return nullptr;
1182 1195
1183 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { 1196 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
1184 if (pAnnot == pFocusAnnot) 1197 if (pAnnot == pFocusAnnot)
1185 return pAnnot; 1198 return pAnnot;
1186 } 1199 }
1187 return nullptr; 1200 return nullptr;
1188 } 1201 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/fsdk_mgr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698